25 |
25 |
26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
27 |
27 |
28 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
28 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
29 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
29 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
30 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
30 procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
31 |
31 |
32 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
32 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
33 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt); |
33 procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt); |
34 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); |
34 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); |
35 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
35 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
36 |
36 |
37 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
37 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
38 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
38 function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
39 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
39 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
40 |
40 |
41 implementation |
41 implementation |
42 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug; |
42 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug; |
43 |
43 |
138 end; |
138 end; |
139 end; |
139 end; |
140 |
140 |
141 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
141 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
142 begin |
142 begin |
143 copyToXY(src, dest, 0, 0, src^.w, src^.h, destX, destY); |
143 copyToXYFromRect(src, dest, 0, 0, src^.w, src^.h, destX, destY); |
144 end; |
144 end; |
145 |
145 |
146 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
146 procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
147 var i, j, maxDest, maxSrc, iX, iY: LongInt; |
147 var i, j, maxDest, maxSrc, iX, iY: LongInt; |
148 srcPixels, destPixels: PLongWordArray; |
148 srcPixels, destPixels: PLongWordArray; |
149 r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
149 r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
150 begin |
150 begin |
151 maxDest:= (dest^.pitch div 4) * dest^.h; |
151 maxDest:= (dest^.pitch div 4) * dest^.h; |
171 end; |
171 end; |
172 end; |
172 end; |
173 |
173 |
174 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
174 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
175 begin |
175 begin |
176 DrawSprite2Surf(sprite, dest, x, y, 0); |
176 DrawSpriteFrame2Surf(sprite, dest, x, y, 0); |
177 end; |
177 end; |
178 |
178 |
179 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt); |
179 procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt); |
180 var numFramesFirstCol, row, col: LongInt; |
180 var numFramesFirstCol, row, col: LongInt; |
181 begin |
181 begin |
182 numFramesFirstCol:= SpritesData[sprite].imageHeight div SpritesData[sprite].Height; |
182 numFramesFirstCol:= SpritesData[sprite].imageHeight div SpritesData[sprite].Height; |
183 row:= Frame mod numFramesFirstCol; |
183 row:= Frame mod numFramesFirstCol; |
184 col:= Frame div numFramesFirstCol; |
184 col:= Frame div numFramesFirstCol; |
185 |
185 |
186 copyToXY(SpritesData[sprite].Surface, dest, |
186 copyToXYFromRect(SpritesData[sprite].Surface, dest, |
187 col*SpritesData[sprite].Width, |
187 col*SpritesData[sprite].Width, |
188 row*SpritesData[sprite].Height, |
188 row*SpritesData[sprite].Height, |
189 SpritesData[sprite].Width, |
189 SpritesData[sprite].Width, |
190 spritesData[sprite].Height, |
190 spritesData[sprite].Height, |
191 x,y); |
191 x,y); |
248 end; |
248 end; |
249 end; |
249 end; |
250 |
250 |
251 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
251 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
252 begin |
252 begin |
253 RenderStringTex:= RenderStringTex(s, Color, font, 0); |
253 RenderStringTex:= RenderStringTexLim(s, Color, font, 0); |
254 end; |
254 end; |
255 |
255 |
256 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
256 function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
257 var w, h: LongInt; |
257 var w, h: LongInt; |
258 finalSurface: PSDL_Surface; |
258 finalSurface: PSDL_Surface; |
259 begin |
259 begin |
260 if length(s) = 0 then s:= ' '; |
260 if length(s) = 0 then s:= ' '; |
261 font:= CheckCJKFont(s, font); |
261 font:= CheckCJKFont(s, font); |
270 |
270 |
271 WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
271 WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
272 |
272 |
273 TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
273 TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
274 |
274 |
275 RenderStringTex:= Surface2Tex(finalSurface, false); |
275 RenderStringTexLim:= Surface2Tex(finalSurface, false); |
276 |
276 |
277 SDL_FreeSurface(finalSurface); |
277 SDL_FreeSurface(finalSurface); |
278 end; |
278 end; |
279 |
279 |
280 |
280 |