Unit1.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #include <system.hpp>
  5. #include <sysutils.hpp>
  6. #pragma hdrstop
  7. #include "Unit1.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "GLBaseClasses"
  11. #pragma link "GLBehaviours"
  12. #pragma link "GLBitmapFont"
  13. #pragma link "GLCadencer"
  14. #pragma link "GLCoordinates"
  15. #pragma link "GLCrossPlatform"
  16. #pragma link "GLObjects"
  17. #pragma link "GLScene"
  18. #pragma link "GLSimpleNavigation"
  19. #pragma link "GLWin32Viewer"
  20. #pragma link "GLWindowsFont"
  21. #pragma resource "*.dfm"
  22. TForm1 *Form1;
  23. TGLConsole *Console;
  24. //---------------------------------------------------------------------------
  25. __fastcall TForm1::TForm1(TComponent* Owner)
  26. : TForm(Owner)
  27. {
  28. }
  29. //---------------------------------------------------------------------------
  30. void __fastcall TForm1::OnHelloCommand(const TGLConsoleCommand *ConsoleCommand,
  31. const TGLCustomConsole *Console, TGLUserInputCommand &Command)
  32. {
  33. /// Console->AddLine("Hi, dude!"); // yet not works!
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::OnCommand(const TGLConsoleCommand *ConsoleCommand,
  37. const TGLCustomConsole *Console, TGLUserInputCommand &Command)
  38. {
  39. int i;
  40. String Str;
  41. if (Command.CommandCount == 0)
  42. exit;
  43. Command.Strings[0] = LowerCase(Command.Strings[0]);
  44. if (Command.Strings[0] == "echo")
  45. {
  46. for (i = 1; i< (Command.CommandCount - 1); i++)
  47. Str = Str + Command.Strings[i];
  48. /// Console->AddLine("You just typed: " + Str);
  49. Command.UnknownCommand = false;
  50. }
  51. else
  52. if (Command.Strings[0] == "exit")
  53. {
  54. Application->Terminate();
  55. Command.UnknownCommand = false; // user won't see it anyway, but you should
  56. // get used to puting this line in every
  57. // command you recognize :)
  58. }
  59. /// if (Command.UnknownCommand)
  60. /// Console->AddLine(" - Current supported external commands are: \r\
  61. /// echo and exit!");
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::FormCreate(TObject *Sender)
  65. {
  66. Console = (TGLConsole *)(Scene->Objects->AddNewChild(__classid(TGLConsole)));
  67. Console->Visible = false;
  68. Console->SceneViewer = Viewer;
  69. Console->Font = Font1;
  70. //optional stuff:
  71. SetGLSceneMediaDir();
  72. Console->HudSprite->Material->Texture->Image->LoadFromFile("GLScene.bmp");
  73. Console->AddLine("Console started");
  74. Console->HUDSpriteColor = clWhite;
  75. Console->FontColor = clBlue;
  76. //two ways of processing commands:
  77. //1) manual
  78. /// Console->OnCommandIssued = OnCommand;
  79. //2)using built-in objects (prefered)
  80. Console->Commands->Add()->CommandName = "hello";
  81. Console->Commands->Add()->ShortHelp = "Says hi to you too";
  82. Console->Commands->Add()->LongHelp->Add("Well, the console really does say - Hi, dude - to you, because");
  83. Console->Commands->Add()->LongHelp->Add("it is roude not to greet someone, when he says - hello - to you ;)");
  84. /// Console->Commands->Add()->OnCommand = OnHelloCommand;
  85. //register additional commands to enable auto-completion function
  86. Console->AdditionalCommands->Add("echo");
  87. Console->AdditionalCommands->Add("exit");
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  91. const double newTime)
  92. {
  93. Viewer->Invalidate();
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key)
  97. {
  98. Console->ProcessKeyPress(Key);
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
  102. {
  103. Console->ProcessKeyDown(Key);
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  107. int X, int Y)
  108. {
  109. Console->Visible = !Console->Visible;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TForm1::FormResize(TObject *Sender)
  113. {
  114. Console->RefreshHudSize();
  115. }
  116. //---------------------------------------------------------------------------
  117. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  118. {
  119. if (CheckBox1->Checked)
  120. Console->Options = Console->Options << coAutoCompleteCommandsOnKeyPress;
  121. else
  122. Console->Options = Console->Options >> coAutoCompleteCommandsOnKeyPress;
  123. Viewer->SetFocus();
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TForm1::CheckBox2Click(TObject *Sender)
  127. {
  128. if (CheckBox1->Checked)
  129. Console->Options = Console->Options << coAutoCompleteCommandsOnEnter;
  130. else
  131. Console->Options = Console->Options >> coAutoCompleteCommandsOnEnter;
  132. Viewer->SetFocus();
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TForm1::CheckBox3Click(TObject *Sender)
  136. {
  137. if (CheckBox1->Checked)
  138. Console->Options = Console->Options << coShowConsoleHelpIfUnknownCommand;
  139. else
  140. Console->Options = Console->Options >> coShowConsoleHelpIfUnknownCommand;
  141. Viewer->SetFocus();
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TForm1::Button1Click(TObject *Sender)
  145. {
  146. Console->TypedCommands->SaveToFile("saved_typed_commands.ini");
  147. Viewer->SetFocus();
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TForm1::Button2Click(TObject *Sender)
  151. {
  152. Console->ColsoleLog->SaveToFile("saved_console_output.ini");
  153. Viewer->SetFocus();
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TForm1::Button6Click(TObject *Sender)
  157. {
  158. Console->TypedCommands->LoadFromFile("saved_typed_commands.ini");
  159. Viewer->SetFocus();
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TForm1::Button7Click(TObject *Sender)
  163. {
  164. Console->ColsoleLog->LoadFromFile("saved_console_output.ini");
  165. Console->RefreshHudSize();
  166. Viewer->SetFocus();
  167. }
  168. //---------------------------------------------------------------------------