24 uses SDLh, uTypes; |
24 uses SDLh, uTypes; |
25 |
25 |
26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
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); |
|
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); |
29 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
32 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
30 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
33 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
31 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); |
32 |
35 |
33 implementation |
36 implementation |
119 pixels^[j]:= tmpPixel; |
122 pixels^[j]:= tmpPixel; |
120 end; |
123 end; |
121 end; |
124 end; |
122 |
125 |
123 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
126 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
124 var srcX, srcY, i, j, maxDest: LongInt; |
127 begin |
|
128 copyToXY(src, dest, 0,0,src^.w, src^.h, destX, destY); |
|
129 end; |
|
130 |
|
131 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
|
132 var i, j, maxDest, maxSrc, iX, iY: LongInt; |
125 srcPixels, destPixels: PLongWordArray; |
133 srcPixels, destPixels: PLongWordArray; |
126 r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
134 r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
127 begin |
135 begin |
128 maxDest:= (dest^.pitch div 4) * dest^.h; |
136 maxDest:= (dest^.pitch div 4) * dest^.h; |
|
137 maxSrc:= (src^.pitch div 4) * src^.h; |
129 srcPixels:= src^.pixels; |
138 srcPixels:= src^.pixels; |
130 destPixels:= dest^.pixels; |
139 destPixels:= dest^.pixels; |
131 |
140 |
132 for srcX:= 0 to src^.w - 1 do |
141 for iX:= 0 to srcW - 1 do |
133 for srcY:= 0 to src^.h - 1 do |
142 for iY:= 0 to srcH - 1 do |
134 begin |
143 begin |
135 i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
144 i:= (destY + iY) * (dest^.pitch div 4) + (destX + iX); |
136 j:= srcY * (src^.pitch div 4) + srcX; |
145 j:= (srcY + iY) * (src^.pitch div 4) + (srcX + iX); |
137 if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then |
146 if (i < maxDest) and (j < maxSrc) and (srcPixels^[j] and AMask <> 0) then |
138 begin |
147 begin |
139 SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0); |
148 SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0); |
140 SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1); |
149 SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1); |
141 r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255; |
150 r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255; |
142 g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255; |
151 g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255; |
143 b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255; |
152 b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255; |
144 a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255; |
153 a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255; |
145 destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0); |
154 destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0); |
146 end; |
155 end; |
147 end; |
156 end; |
|
157 end; |
|
158 |
|
159 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt); |
|
160 var numFramesFirstCol, row, col: LongInt; |
|
161 begin |
|
162 numFramesFirstCol:= SpritesData[sprite].imageHeight div SpritesData[sprite].Height; |
|
163 row:= Frame mod numFramesFirstCol; |
|
164 col:= Frame div numFramesFirstCol; |
|
165 |
|
166 copyToXY(SpritesData[sprite].Surface, dest, |
|
167 col*SpritesData[sprite].Width, |
|
168 row*SpritesData[sprite].Height, |
|
169 SpritesData[sprite].Width, |
|
170 spritesData[sprite].Height, |
|
171 x,y); |
|
172 end; |
|
173 |
|
174 procedure DrawLine2Surf(dest: PSDL_Surface; x0, y0,x1,y1: LongInt; r,g,b: byte); |
|
175 var |
|
176 max: LongInt; |
|
177 dx,dy,err,e2,sx,sy: LongInt; |
|
178 yMax: LongInt; |
|
179 destPixels: PLongwordArray; |
|
180 begin |
|
181 max:= (dest^.pitch div 4) * dest^.h; |
|
182 yMax:= dest^.pitch div 4; |
|
183 destPixels:= dest^.pixels; |
|
184 |
|
185 dx:= abs(x1-x0); |
|
186 dy:= abs(y1-y0); |
|
187 if x0 < x1 then sx:= 1 else sx:= -1; |
|
188 if y0 < y1 then sy:= 1 else sy:= -1; |
|
189 err:= dx-dy; |
|
190 |
|
191 while(true) do |
|
192 begin |
|
193 destPixels^[(y0 * yMax) + x0]:= SDL_MapRGB(dest^.format, r,g,b); //But will it blend? no |
|
194 |
|
195 if (x0 = x1) and (y0 = y1) then break; |
|
196 |
|
197 e2:= 2*err; |
|
198 if e2 > -dy then |
|
199 begin |
|
200 err:= err - dy; |
|
201 x0 := x0 + sx; |
|
202 end; |
|
203 |
|
204 if e2 < dx then |
|
205 begin |
|
206 err:= err + dx; |
|
207 y0:=y0+sy |
|
208 end; |
|
209 end; |
148 end; |
210 end; |
149 |
211 |
150 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
212 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
151 var y, x, i, j: LongInt; |
213 var y, x, i, j: LongInt; |
152 srcPixels, destPixels: PLongWordArray; |
214 srcPixels, destPixels: PLongWordArray; |