fConsoleC.cpp 6.2 KB

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