Code Search for Developers
 
 
  

Unit1.pas from Sector-37 at Krugle


Show Unit1.pas syntax highlighted

{

GLConsole demo

See the interface part of GLConsole.pas for details...

}
unit Unit1;

interface

{$I GLScene.inc}

uses
  //VCL
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
  ExtCtrls,

  //GLScene
  GLTexture, GLBitmapFont, GLWindowsFont, GLScene, GLMisc, GLObjects,
  GLCadencer, GLWin32Viewer, GLBehaviours,

  //Strange components
  GLConsole, StrangeTypesAndConstants
   {$IFDEF STRANGE_INIFILE_SUPPORT}, StrangeIniObjects{$ENDIF};

type
  TForm1 = class(TForm)
    Viewer:    TGLSceneViewer;
    GLCadencer1: TGLCadencer;
    Scene: TGLScene;
    GLCamera1: TGLCamera;
    font1:     TGLWindowsBitmapFont;
    GLCube1:   TGLCube;
    GLLightSource1: TGLLightSource;
    Splitter1: TSplitter;
    Panel1:    TPanel;
    GroupBox1: TGroupBox;
    ListBox1:  TListBox;
    Splitter2: TSplitter;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Timer1: TTimer;
    Button4: TButton;
    Button5: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    procedure GLCadencer1Progress(Sender: TObject; const deltaTime, newTime: double);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: char);
    procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
    procedure ViewerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
    procedure FormResize(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure OnHelloCommand(const Sender: TGLConsoleCommand;
     const Console: TGLCustomConsole; var Command: TGLUserInputCommand);
  public
    procedure OnCommand(const Sender: TGLConsoleCommand;
     const Console: TGLCustomConsole; var Command: TGLUserInputCommand);
  end;

var
  Form1:   TForm1;
  Console: TGLConsole;

implementation


{$R *.DFM}

procedure TForm1.OnCommand(const Sender: TGLConsoleCommand;
  const Console: TGLCustomConsole; var Command: TGLUserInputCommand);
var
  I:   integer;
  str: string;
begin
  if Command.CommandCount = 0 then
    exit;
  Command.strings[0] := lowercase(Command.strings[0]);
  if Command.strings[0] = 'echo' then
  begin
    for I := 1 to Command.CommandCount - 1 do
      str := str + Command.strings[I];
    Console.AddLine('You just typed: ' + str);
    Command.UnknownCommand := False;
  end
  else
  if Command.strings[0] = 'exit' then
  begin
    Close;
    Command.UnknownCommand := False; // user won't see it anyway, but you should
                                     // get used to puting this line in every
                                     // command you recognize :)
  end;

  if Command.UnknownCommand then
    Console.AddLine(' - Current supported external commands are:' +
                    '"echo" and "exit"!');
end;


procedure TForm1.GLCadencer1Progress(Sender: TObject;
  const deltaTime, newTime: double);
begin
  Viewer.Invalidate;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Console := TGLConsole.CreateAsChild(Scene.Objects);
  Console.Visible := False;
  Console.SceneViewer := Viewer;
  Console.Font := Font1;

  //optional stuff:
  Console.HudSprite.Material.Texture.Image.LoadFromFile('GLScene.bmp');
  Console.AddLine('Console started');
  Console.HUDSpriteColor := clWhite;
  Console.FontColor := clBlue;

  //two ways of processing commands:
     //1) manual
  Console.OnCommandIssued := OnCommand;
     //2)using built-in objects (prefered)
  with Console.Commands.Add do
  begin
    CommandName := 'hello';
    ShortHelp := 'Says hi to you too';
    LongHelp.Add('Well, the console really does say "Hi, dude" to you, because');
    LongHelp.Add('it is roude not to greet someone, when he says "hello" to you ;)');
    OnCommand := OnHelloCommand;
  end;

  //register additional commands to enable auto-completion function
  with Console.AdditionalCommands do
  begin
    Add('echo');
    Add('exit');
  end;
end;


procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
  Console.ProcessKeyPress(key);
end;


procedure TForm1.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
  Console.ProcessKeyDown(key);
end;


procedure TForm1.ViewerMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: integer);
begin
  Console.Visible := not Console.Visible;
end;


procedure TForm1.FormResize(Sender: TObject);
begin
  Console.RefreshHudSize;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    Console.Options := Console.Options + [coAutoCompleteCommandsOnKeyPress]
  else
    Console.Options := Console.Options - [coAutoCompleteCommandsOnKeyPress];

  Viewer.SetFocus;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
    Console.Options := Console.Options + [coAutoCompleteCommandsOnEnter]
  else
    Console.Options := Console.Options - [coAutoCompleteCommandsOnEnter];

  Viewer.SetFocus;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  if CheckBox3.Checked then
    Console.Options := Console.Options + [coShowConsoleHelpIfUnknownCommand]
  else
    Console.Options := Console.Options - [coShowConsoleHelpIfUnknownCommand];

  Viewer.SetFocus;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Console.TypedCommands.SaveToFile('saved_typed_commands.txt');
  Viewer.SetFocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Console.ColsoleLog.SaveToFile('saved_console_output.txt');
  Viewer.SetFocus;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.SaveToIniFile('console_settings.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Caption := 'Strange Console Demo    ' + Viewer.FramesPerSecondText;
  Viewer.ResetPerformanceMonitor;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.Controls.SaveToIniFile('saved_console_controls.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.Commands.SaveToIniFile('saved_console_commands.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  Console.TypedCommands.LoadFromFile('saved_typed_commands.txt');
  Viewer.SetFocus;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  Console.ColsoleLog.LoadFromFile('saved_console_output.txt');
  Console.RefreshHudSize;
  Viewer.SetFocus;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.LoadFromIniFile('console_settings.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.Controls.LoadFromIniFile('saved_console_controls.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
{$IFDEF STRANGE_INIFILE_SUPPORT}
  Console.Commands.LoadFromIniFile('saved_console_commands.ini');
  Viewer.SetFocus;
{$ELSE}
  Viewer.SetFocus;
  Assert(False, SIF_ERROR);
{$ENDIF}
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  GLCadencer1.Enabled := False;
  Console.Destroy;
end;

procedure TForm1.OnHelloCommand(const Sender: TGLConsoleCommand;
  const Console: TGLCustomConsole;
  var Command: TGLUserInputCommand);
begin
  Console.AddLine(' - Hi, dude!');
end;

end.




See more files for this project here

Sector-37

Sector-37 (real time 3D cosmic strategy)

Project homepage: http://sourceforge.net/projects/sector37
Programming language(s): Pascal
License: lgpl21

  GLScene.bmp
  StrangeConsoleDemo.dpr
  StrangeConsoleDemo.res
  Unit1.dfm
  Unit1.pas
  _Cleanup.bat
  console_settings.ini
  saved_console_commands.ini
  saved_console_controls.ini
  saved_console_output.txt
  saved_typed_commands.txt