Code:
program gui_test;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
dRez.Engine.IMGUI in '..\..\libs\dRez.Engine.IMGUI.pas',
dRez.Engine in '..\..\libs\dRez.Engine.pas';
const
cWindowWidth = 480;
cWindowHeight = 600;
cFullscreen = False;
var
Starfield: TStarfield;
Gui: TdeIMGUI;
name: string = 'Jarrod';
check1: boolean = True;
check2: Boolean = False;
check3: Boolean = False;
enable_disable: array[false .. true] of string = ('disabled', 'enabled');
volume: Single = 1;
music: TMusic;
button_status: array[0 .. 1] of string;
procedure UpdateMusicVolume(aSender: Pointer; aId: Integer; aValue: Single; aMinValue: Single; aMaxValue: Single);
begin
Music_SetVolume(aValue);
end;
procedure ButtonClicked(aSender: Pointer; aId: Integer);
var
s: string;
begin
s := '';
case aId of
0:
begin
button_status[0] :='Button 1 clicked';
button_status[1] :='';
end;
1:
begin
button_status[0] :='';
button_status[1] :='Button 2 clicked';
end;
end;
end;
begin
// open app window
Window_Open('dRez Engine - Basic GUI Demo', cWindowWidth, cWindowHeight, cFullscreen, False);
music := Music_Load(nil, 'arc/music/opus.mp3');
Music_Play(music, volume, -1);
Starfield := Starfield_Create;
gui := TdeIMGUI.Create;
//gui.SetProperty(SLIDER_SLIDER_WIDTH, 5);
// LGL game loop - until app has terminated
while not Terminated do
begin
// process events (kbd, mouse, window, etc)
ProcessEvents;
// check if app window is ready (has focus, not minimized)
if not Window_Ready then
begin
// delay for 1 millisecond (allow background tasks to run)
Delay(1);
// continue to process events
continue;
end;
// terminate on ESC
if Keyboard_Pressed(KEY_ESCAPE) then
Terminate(True);
// toggle fullscreen on F11
if Keyboard_Pressed(KEY_F11) then
Window_ToggleFullscreen;
// screenshot on F12
if Keyboard_Pressed(KEY_F12) then
Screenshot_Take;
if Keyboard_Pressed(KEY_1) then
gui.GuiAlpha := 0.1;
if Keyboard_Pressed(KEY_2) then
gui.GuiAlpha := 1.0;
Starfield_Update(Starfield, DeltaTime);
// clear background to a color
Renderer_ClearFrame(BLACK);
Starfield_Render(Starfield);
// display hud
Font_DrawFPS(ConsoleFont, 3, 3, GREEN, 12);
Font_DrawText(ConsoleFont, 3, 15, GREEN, 12, 'ESC - Quit');
Font_DrawText(ConsoleFont, 3, 30, GREEN, 12, 'F11 - Toggle Fullscreen');
Font_DrawText(ConsoleFont, 3, 45, GREEN, 12, 'F12 - Screenshot');
//Font_DrawText(ConsoleFont, 3, 60, GREEN, 12, PChar('hex - ' + gui.Test));
gui.&Label(TRect.Create(3, 100, 50, 15), 'A LABEL');
gui.Button(TRect.Create(3, 120, 70, 30), 'BUTTON 1', nil, 0, ButtonClicked);
gui.&Label(TRect.Create(80, 128, 50, 15), button_status[0]);
gui.Button(TRect.Create(3, 160, 70, 30), 'BUTTON 2', nil, 1, ButtonClicked);
gui.&Label(TRect.Create(80, 168, 50, 15), button_status[1]);
gui.TextBox(TRect.Create(3, 200, 70, 30), name, 30, true);
gui.CheckBox(TRect.Create(3, 240, 20, 20), check1);
if gui.LabelButton(TRect.Create(3, 270, 70, 30), 'LABEL BUTTON') then WarningDlg('Label Button');
gui.CheckBoxExt(TRect.Create(3, 300, 10, 10), check2, 'Item 1 (' + enable_disable[check2] + ')' );
gui.CheckBoxExt(TRect.Create(3, 320, 10, 10), check3, 'Item 2 (' + enable_disable[check3] + ')');
gui.Slider(TRect.Create(10, 340, 50, 10), volume, 0, 1, nil, 0, UpdateMusicVolume);
gui.&Label(TRect.Create(70, 340, 50, 15), 'Music Volume');
// show frame buffer
Renderer_ShowFrame;
end;
gui.Free;
Starfield_Destroy(Starfield);
Music_Destroy(music);
// close app window
Window_Close;
end.
Bookmarks