From e1228cc6f4ef9c01751c6ab24c116a0bcd8ef070 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Wed, 22 Feb 2012 13:54:08 -0500 Subject: [PATCH] More progress --- mdl/m_sdlcrt.pas | 83 ++++++++++++++++++++++++++++++++++++++++-------- mdl/mdltest9.pas | 4 +++ 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/mdl/m_sdlcrt.pas b/mdl/m_sdlcrt.pas index 9ad641f..05b2cca 100644 --- a/mdl/m_sdlcrt.pas +++ b/mdl/m_sdlcrt.pas @@ -36,7 +36,8 @@ Goals: Interface Uses - SDL; + SDL, + SDL_TTF; Const keyENTER = #13; @@ -68,22 +69,36 @@ Type End; TSDLConsole = Class + InputEvent : pSDL_EVENT; + Screen : pSDL_SURFACE; + Font : pTTF_Font; + InputBuffer : Array[1..AppInputSize] of Char; InputPos : Integer; InputSize : Integer; - InputEvent : pSDL_EVENT; - Screen : pSDL_SURFACE; + CursorX : Byte; + CursorY : Byte; + TextAttr : Byte; + + // INIT STUFF Constructor Create (InitMode: TSDLScreenMode); - Destructor Destroy; Override; + Destructor Destroy; Override; + // INTERNAL STUFF Procedure PushInput (Ch: Char); Procedure PushExt (Ch: Char); Procedure PushStr (Str: String); Procedure ProcessEvent; + + // FUNCTIONAL Function KeyPressed : Boolean; Function ReadKey : Char; Procedure Delay (MS: LongInt); + Procedure SetTitle (Title: String); + + //NONSENSE + Procedure TestStuff; End; Implementation @@ -111,20 +126,33 @@ Begin 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 TTF_Init = -1 Then Halt; + + Font := TTF_OpenFont('ASCII.ttf', 16); + + If Font = NIL Then Halt; + New (InputEvent); InputSize := 0; InputPos := 0; + CursorX := 1; + CursorY := 1; + TextAttr := 7; End; Destructor TSDLConsole.Destroy; Begin Dispose (InputEvent); + TTF_CloseFont(Font); + + TTF_Quit; + SDL_QUIT; Inherited Destroy; @@ -188,7 +216,7 @@ Begin SDLK_PAGEUP : PushExt(keyPGUP); SDLK_PAGEDOWN : PushExt(keyPGDN); SDLK_NUMLOCK.. - SDLK_COMPOSE : ; + SDLK_COMPOSE : //ignore mod keys; Else Found := False; @@ -218,14 +246,8 @@ Begin End; Function TSDLConsole.KeyPressed : Boolean; -Var - Queued : LongInt; Begin - Result := False; - - Queued := SDL_PollEvent(InputEvent); - - If Queued > 0 Then + If SDL_PollEvent(InputEvent) > 0 Then ProcessEvent; Result := InputPos <> InputSize; @@ -254,4 +276,39 @@ Begin SDL_DELAY(MS); 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. diff --git a/mdl/mdltest9.pas b/mdl/mdltest9.pas index 2567976..fa261bb 100644 --- a/mdl/mdltest9.pas +++ b/mdl/mdltest9.pas @@ -9,6 +9,10 @@ Var Begin Console := TSDLConsole.Create(Mode_80x25); + Console.SetTitle('SDL TEST Program [ESC/Quit]'); + + Console.TestStuff; + Repeat Ch := Console.ReadKey;