27 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
27 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
28 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
28 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
29 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
29 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
30 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt = 0); |
30 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt = 0); |
31 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); |
31 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); |
32 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
32 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture; |
33 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
33 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
34 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
34 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
35 |
35 |
36 implementation |
36 implementation |
37 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug; |
37 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug; |
64 r.w:= rect^.w - 2; |
64 r.w:= rect^.w - 2; |
65 r.h:= rect^.h - 4; |
65 r.h:= rect^.h - 4; |
66 SDL_FillRect(Surface, @r, FillColor) |
66 SDL_FillRect(Surface, @r, FillColor) |
67 end; |
67 end; |
68 |
68 |
69 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect; |
69 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord = 0): TSDL_Rect; |
70 var w, h: LongInt; |
70 var w, h: LongInt; |
71 tmpsurf: PSDL_Surface; |
71 tmpsurf: PSDL_Surface; |
72 clr: TSDL_Color; |
72 clr: TSDL_Color; |
73 finalRect: TSDL_Rect; |
73 finalRect: TSDL_Rect; |
74 begin |
74 begin |
75 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h); |
75 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h); |
|
76 if (maxLength <> 0) and (w > maxLength) then w := maxLength; |
76 finalRect.x:= X; |
77 finalRect.x:= X; |
77 finalRect.y:= Y; |
78 finalRect.y:= Y; |
78 finalRect.w:= w + FontBorder * 2 + 4; |
79 finalRect.w:= w + FontBorder * 2 + 4; |
79 finalRect.h:= h + FontBorder * 2; |
80 finalRect.h:= h + FontBorder * 2; |
80 DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
81 DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
227 destPixels^[j]:= srcPixels^[i]; |
228 destPixels^[j]:= srcPixels^[i]; |
228 inc(j) |
229 inc(j) |
229 end; |
230 end; |
230 end; |
231 end; |
231 |
232 |
232 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
233 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture; |
233 var w, h: LongInt; |
234 var w, h: LongInt; |
234 finalSurface: PSDL_Surface; |
235 finalSurface: PSDL_Surface; |
235 begin |
236 begin |
236 if length(s) = 0 then s:= ' '; |
237 if length(s) = 0 then s:= ' '; |
237 font:= CheckCJKFont(s, font); |
238 font:= CheckCJKFont(s, font); |
238 w:= 0; h:= 0; // avoid compiler hints |
239 w:= 0; h:= 0; // avoid compiler hints |
239 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); |
240 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); |
|
241 if (maxLength <> 0) and (w > maxLength) then w := maxLength; |
240 |
242 |
241 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
243 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
242 32, RMask, GMask, BMask, AMask); |
244 32, RMask, GMask, BMask, AMask); |
243 |
245 |
244 TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
246 TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
245 |
247 |
246 WriteInRoundRect(finalSurface, 0, 0, Color, font, s); |
248 WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
247 |
249 |
248 TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
250 TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
249 |
251 |
250 RenderStringTex:= Surface2Tex(finalSurface, false); |
252 RenderStringTex:= Surface2Tex(finalSurface, false); |
251 |
253 |