113 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
113 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
114 var y, x, i, j: LongInt; |
114 var y, x, i, j: LongInt; |
115 tmpPixel: Longword; |
115 tmpPixel: Longword; |
116 pixels: PLongWordArray; |
116 pixels: PLongWordArray; |
117 begin |
117 begin |
118 TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
118 if checkFails(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true) then |
|
119 exit; |
119 SDL_LockSurface(Surface); |
120 SDL_LockSurface(Surface); |
120 pixels:= Surface^.pixels; |
121 pixels:= Surface^.pixels; |
121 if Vertical then |
122 if Vertical then |
122 for y := 0 to (Surface^.h div 2) - 1 do |
123 for y := 0 to (Surface^.h div 2) - 1 do |
123 for x := 0 to Surface^.w - 1 do |
124 for x := 0 to Surface^.w - 1 do |
128 pixels^[i]:= pixels^[j]; |
129 pixels^[i]:= pixels^[j]; |
129 pixels^[j]:= tmpPixel; |
130 pixels^[j]:= tmpPixel; |
130 end |
131 end |
131 else |
132 else |
132 for x := 0 to (Surface^.w div 2) - 1 do |
133 for x := 0 to (Surface^.w div 2) - 1 do |
133 for y := 0 to Surface^.h -1 do |
134 for y := 0 to Surface^.h - 1 do |
134 begin |
135 begin |
135 i:= y*Surface^.w + x; |
136 i:= y*Surface^.w + x; |
136 j:= y*Surface^.w + (Surface^.w - x - 1); |
137 j:= y*Surface^.w + (Surface^.w - x - 1); |
137 tmpPixel:= pixels^[i]; |
138 tmpPixel:= pixels^[i]; |
138 pixels^[i]:= pixels^[j]; |
139 pixels^[i]:= pixels^[j]; |
244 |
245 |
245 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
246 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
246 var y, x, i, j: LongInt; |
247 var y, x, i, j: LongInt; |
247 srcPixels, destPixels: PLongWordArray; |
248 srcPixels, destPixels: PLongWordArray; |
248 begin |
249 begin |
249 TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
250 checkFails(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
250 TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
251 checkFails(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
252 if not allOK then exit; |
251 |
253 |
252 SDL_LockSurface(src); |
254 SDL_LockSurface(src); |
253 SDL_LockSurface(dest); |
255 SDL_LockSurface(dest); |
254 |
256 |
255 srcPixels:= src^.pixels; |
257 srcPixels:= src^.pixels; |
291 if (maxLength > 0) and (w > maxLength) then w := maxLength; |
293 if (maxLength > 0) and (w > maxLength) then w := maxLength; |
292 |
294 |
293 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2, |
295 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2, |
294 32, RMask, GMask, BMask, AMask); |
296 32, RMask, GMask, BMask, AMask); |
295 |
297 |
296 TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
298 if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
|
299 exit(nil); |
297 |
300 |
298 WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
301 WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
299 |
302 |
300 TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
303 checkFails(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, false); |
301 |
304 |
302 RenderStringTexLim:= Surface2Tex(finalSurface, false); |
305 RenderStringTexLim:= Surface2Tex(finalSurface, false); |
303 |
306 |
304 SDL_FreeSurface(finalSurface); |
307 SDL_FreeSurface(finalSurface); |
305 end; |
308 end; |
442 rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
445 rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
443 //s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
446 //s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
444 |
447 |
445 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
448 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
446 |
449 |
447 TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
450 if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
|
451 exit(nil); |
448 |
452 |
449 //////////////////////////////// CORNERS /////////////////////////////// |
453 //////////////////////////////// CORNERS /////////////////////////////// |
450 copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
454 copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
451 |
455 |
452 flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
456 flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |