2
0

fConsoleC.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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();
  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. TFileName Path = GetCurrentAssetPath();
  70. SetCurrentDir(Path + "\\texture");
  71. GLConsole1->HudSprite->Material->Texture->Image->LoadFromFile("GLScene.bmp");
  72. GLConsole1->AddLine("Console started");
  73. GLConsole1->HUDSpriteColor = clWhite;
  74. GLConsole1->FontColor = clBlue;
  75. //two ways of processing commands:
  76. //1) manual
  77. GLConsole1->OnCommandIssued = OnCommand;
  78. //2)using built-in objects (prefered)
  79. GLConsole1->Commands->Add()->CommandName = "hello";
  80. GLConsole1->Commands->Add()->ShortHelp = "Says hi to you too";
  81. GLConsole1->Commands->Add()->LongHelp->Add("Well, the console really does say - Hi, dude - to you, because");
  82. GLConsole1->Commands->Add()->LongHelp->Add("it is roude not to greet someone, when he says - hello - to you ;)");
  83. GLConsole1->Commands->Add()->OnCommand = OnHelloCommand;
  84. //register additional commands to enable auto-completion function
  85. GLConsole1->AdditionalCommands->Add("echo");
  86. GLConsole1->AdditionalCommands->Add("exit");
  87. // for console saved output and loading .ini files
  88. SetCurrentDir(Path + "\\script");
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  92. const double newTime)
  93. {
  94. Viewer->Invalidate();
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key)
  98. {
  99. GLConsole1->ProcessKeyPress(Key);
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
  103. {
  104. GLConsole1->ProcessKeyDown(Key);
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  108. int X, int Y)
  109. {
  110. GLConsole1->Visible = !GLConsole1->Visible;
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TForm1::FormResize(TObject *Sender)
  114. {
  115. GLConsole1->RefreshHudSize();
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  119. {
  120. if (CheckBox1->Checked)
  121. GLConsole1->Options = GLConsole1->Options << coAutoCompleteCommandsOnKeyPress;
  122. else
  123. GLConsole1->Options = GLConsole1->Options >> coAutoCompleteCommandsOnKeyPress;
  124. Viewer->SetFocus();
  125. }
  126. //---------------------------------------------------------------------------
  127. void __fastcall TForm1::CheckBox2Click(TObject *Sender)
  128. {
  129. if (CheckBox1->Checked)
  130. GLConsole1->Options = GLConsole1->Options << coAutoCompleteCommandsOnEnter;
  131. else
  132. GLConsole1->Options = GLConsole1->Options >> coAutoCompleteCommandsOnEnter;
  133. Viewer->SetFocus();
  134. }
  135. //---------------------------------------------------------------------------
  136. void __fastcall TForm1::CheckBox3Click(TObject *Sender)
  137. {
  138. if (CheckBox1->Checked)
  139. GLConsole1->Options = GLConsole1->Options << coShowConsoleHelpIfUnknownCommand;
  140. else
  141. GLConsole1->Options = GLConsole1->Options >> coShowConsoleHelpIfUnknownCommand;
  142. Viewer->SetFocus();
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TForm1::Button1Click(TObject *Sender)
  146. {
  147. GLConsole1->TypedCommands->SaveToFile("saved_typed_commands.ini");
  148. Viewer->SetFocus();
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TForm1::Button2Click(TObject *Sender)
  152. {
  153. GLConsole1->ColsoleLog->SaveToFile("saved_console_output.ini");
  154. Viewer->SetFocus();
  155. }
  156. //---------------------------------------------------------------------------
  157. void __fastcall TForm1::Button6Click(TObject *Sender)
  158. {
  159. GLConsole1->TypedCommands->LoadFromFile("saved_typed_commands.ini");
  160. Viewer->SetFocus();
  161. }
  162. //---------------------------------------------------------------------------
  163. void __fastcall TForm1::Button7Click(TObject *Sender)
  164. {
  165. GLConsole1->ColsoleLog->LoadFromFile("saved_console_output.ini");
  166. GLConsole1->RefreshHudSize();
  167. Viewer->SetFocus();
  168. }
  169. //---------------------------------------------------------------------------