More progress
This commit is contained in:
parent
eab6851522
commit
e1228cc6f4
|
@ -36,7 +36,8 @@ Goals:
|
||||||
Interface
|
Interface
|
||||||
|
|
||||||
Uses
|
Uses
|
||||||
SDL;
|
SDL,
|
||||||
|
SDL_TTF;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
keyENTER = #13;
|
keyENTER = #13;
|
||||||
|
@ -68,22 +69,36 @@ Type
|
||||||
End;
|
End;
|
||||||
|
|
||||||
TSDLConsole = Class
|
TSDLConsole = Class
|
||||||
|
InputEvent : pSDL_EVENT;
|
||||||
|
Screen : pSDL_SURFACE;
|
||||||
|
Font : pTTF_Font;
|
||||||
|
|
||||||
InputBuffer : Array[1..AppInputSize] of Char;
|
InputBuffer : Array[1..AppInputSize] of Char;
|
||||||
InputPos : Integer;
|
InputPos : Integer;
|
||||||
InputSize : Integer;
|
InputSize : Integer;
|
||||||
InputEvent : pSDL_EVENT;
|
|
||||||
Screen : pSDL_SURFACE;
|
|
||||||
|
|
||||||
|
CursorX : Byte;
|
||||||
|
CursorY : Byte;
|
||||||
|
TextAttr : Byte;
|
||||||
|
|
||||||
|
// INIT STUFF
|
||||||
Constructor Create (InitMode: TSDLScreenMode);
|
Constructor Create (InitMode: TSDLScreenMode);
|
||||||
Destructor Destroy; Override;
|
Destructor Destroy; Override;
|
||||||
|
|
||||||
|
// INTERNAL STUFF
|
||||||
Procedure PushInput (Ch: Char);
|
Procedure PushInput (Ch: Char);
|
||||||
Procedure PushExt (Ch: Char);
|
Procedure PushExt (Ch: Char);
|
||||||
Procedure PushStr (Str: String);
|
Procedure PushStr (Str: String);
|
||||||
Procedure ProcessEvent;
|
Procedure ProcessEvent;
|
||||||
|
|
||||||
|
// FUNCTIONAL
|
||||||
Function KeyPressed : Boolean;
|
Function KeyPressed : Boolean;
|
||||||
Function ReadKey : Char;
|
Function ReadKey : Char;
|
||||||
Procedure Delay (MS: LongInt);
|
Procedure Delay (MS: LongInt);
|
||||||
|
Procedure SetTitle (Title: String);
|
||||||
|
|
||||||
|
//NONSENSE
|
||||||
|
Procedure TestStuff;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Implementation
|
Implementation
|
||||||
|
@ -111,20 +126,33 @@ Begin
|
||||||
|
|
||||||
SDL_INIT(SDL_INIT_VIDEO);
|
SDL_INIT(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
Screen := SDL_SetVideoMode(SDLAppWindowX, SDLAppWindowY, 32, SDL_SWSURFACE);
|
Screen := SDL_SetVideoMode(SDLAppWindowX, SDLAppWindowY, 32, SDL_HWSURFACE AND SDL_FULLSCREEN);
|
||||||
|
|
||||||
If Screen = NIL Then Halt;
|
If Screen = NIL Then Halt;
|
||||||
|
|
||||||
|
If TTF_Init = -1 Then Halt;
|
||||||
|
|
||||||
|
Font := TTF_OpenFont('ASCII.ttf', 16);
|
||||||
|
|
||||||
|
If Font = NIL Then Halt;
|
||||||
|
|
||||||
New (InputEvent);
|
New (InputEvent);
|
||||||
|
|
||||||
InputSize := 0;
|
InputSize := 0;
|
||||||
InputPos := 0;
|
InputPos := 0;
|
||||||
|
CursorX := 1;
|
||||||
|
CursorY := 1;
|
||||||
|
TextAttr := 7;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Destructor TSDLConsole.Destroy;
|
Destructor TSDLConsole.Destroy;
|
||||||
Begin
|
Begin
|
||||||
Dispose (InputEvent);
|
Dispose (InputEvent);
|
||||||
|
|
||||||
|
TTF_CloseFont(Font);
|
||||||
|
|
||||||
|
TTF_Quit;
|
||||||
|
|
||||||
SDL_QUIT;
|
SDL_QUIT;
|
||||||
|
|
||||||
Inherited Destroy;
|
Inherited Destroy;
|
||||||
|
@ -188,7 +216,7 @@ Begin
|
||||||
SDLK_PAGEUP : PushExt(keyPGUP);
|
SDLK_PAGEUP : PushExt(keyPGUP);
|
||||||
SDLK_PAGEDOWN : PushExt(keyPGDN);
|
SDLK_PAGEDOWN : PushExt(keyPGDN);
|
||||||
SDLK_NUMLOCK..
|
SDLK_NUMLOCK..
|
||||||
SDLK_COMPOSE : ;
|
SDLK_COMPOSE : //ignore mod keys;
|
||||||
Else
|
Else
|
||||||
Found := False;
|
Found := False;
|
||||||
|
|
||||||
|
@ -218,14 +246,8 @@ Begin
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function TSDLConsole.KeyPressed : Boolean;
|
Function TSDLConsole.KeyPressed : Boolean;
|
||||||
Var
|
|
||||||
Queued : LongInt;
|
|
||||||
Begin
|
Begin
|
||||||
Result := False;
|
If SDL_PollEvent(InputEvent) > 0 Then
|
||||||
|
|
||||||
Queued := SDL_PollEvent(InputEvent);
|
|
||||||
|
|
||||||
If Queued > 0 Then
|
|
||||||
ProcessEvent;
|
ProcessEvent;
|
||||||
|
|
||||||
Result := InputPos <> InputSize;
|
Result := InputPos <> InputSize;
|
||||||
|
@ -254,4 +276,39 @@ Begin
|
||||||
SDL_DELAY(MS);
|
SDL_DELAY(MS);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Procedure TSDLConsole.SetTitle (Title: String);
|
||||||
|
Begin
|
||||||
|
Title := Title + #0;
|
||||||
|
|
||||||
|
SDL_WM_SetCaption(PChar(@Title[1]), PChar(@Title[1]));
|
||||||
|
End;
|
||||||
|
|
||||||
|
Procedure TSDLConsole.TestStuff;
|
||||||
|
Var
|
||||||
|
ColorFG : TSDL_Color = (R:255; G:0; B:0; Unused:0);
|
||||||
|
ColorBG : TSDL_Color = (R:0; G:0; B:0; Unused:0);
|
||||||
|
Rect : TSDL_Rect = (X:0; Y:0; W:0; H:0);
|
||||||
|
Surface : PSDL_Surface;
|
||||||
|
Text : String;
|
||||||
|
Begin
|
||||||
|
Text := #176 + '2345678901234567890123456789012345678901234567890123456789012345678901234567890';
|
||||||
|
|
||||||
|
// Surface := TTF_RenderUTF8_Solid (Font, PChar(@Text[1]), ColorFG);
|
||||||
|
Surface := TTF_RenderText_Shaded (Font, PChar(@Text[1]), ColorFG, ColorBG);
|
||||||
|
|
||||||
|
SDL_BlitSurface (Surface, NIL, Screen, @Rect);
|
||||||
|
SDL_FreeSurface (Surface);
|
||||||
|
|
||||||
|
Text := #176 + 'SDL Demo! Press Escape to quit!' + #0;
|
||||||
|
|
||||||
|
Surface := TTF_RenderText_Shaded (Font, PChar(@Text[1]), ColorFG, ColorBG);
|
||||||
|
|
||||||
|
Rect.Y := 1 * 16 + 1;
|
||||||
|
|
||||||
|
SDL_BlitSurface (Surface, NIL, Screen, @Rect);
|
||||||
|
SDL_FreeSurface (Surface);
|
||||||
|
|
||||||
|
SDL_Flip(Screen);
|
||||||
|
End;
|
||||||
|
|
||||||
End.
|
End.
|
||||||
|
|
|
@ -9,6 +9,10 @@ Var
|
||||||
Begin
|
Begin
|
||||||
Console := TSDLConsole.Create(Mode_80x25);
|
Console := TSDLConsole.Create(Mode_80x25);
|
||||||
|
|
||||||
|
Console.SetTitle('SDL TEST Program [ESC/Quit]');
|
||||||
|
|
||||||
|
Console.TestStuff;
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
Ch := Console.ReadKey;
|
Ch := Console.ReadKey;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue