author | sheepluva |
Sat, 03 Dec 2016 09:09:16 +0100 | |
changeset 12098 | 966a9739812f |
parent 11836 | 1d41f297b3d3 |
child 12099 | c1d83fc8e894 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10107
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*) |
18 |
||
4380 | 19 |
{$INCLUDE "options.inc"} |
4976 | 20 |
|
4380 | 21 |
unit uRenderUtils; |
22 |
||
23 |
interface |
|
24 |
uses SDLh, uTypes; |
|
25 |
||
26 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
27 |
|
4380 | 28 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
29 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
7013 | 30 |
procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
31 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
32 |
procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
7013 | 33 |
procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt); |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
34 |
procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
35 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
36 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
37 |
function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
7013 | 38 |
function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
4380 | 39 |
function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
40 |
||
41 |
implementation |
|
11821 | 42 |
uses uVariables, uConsts, uTextures, SysUtils, uUtils, uDebug; |
4380 | 43 |
|
44 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
|
45 |
var r: TSDL_Rect; |
|
46 |
begin |
|
47 |
r:= rect^; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
48 |
if Clear then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
49 |
SDL_FillRect(Surface, @r, 0); |
4380 | 50 |
|
51 |
BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
|
52 |
FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
|
53 |
||
11836 | 54 |
r.y:= rect^.y + cFontBorder div 2; |
55 |
r.h:= rect^.h - cFontBorder; |
|
4380 | 56 |
SDL_FillRect(Surface, @r, BorderColor); |
11836 | 57 |
r.x:= rect^.x + cFontBorder div 2; |
58 |
r.w:= rect^.w - cFontBorder; |
|
4380 | 59 |
r.y:= rect^.y; |
60 |
r.h:= rect^.h; |
|
61 |
SDL_FillRect(Surface, @r, BorderColor); |
|
11836 | 62 |
r.x:= rect^.x + cFontBorder; |
63 |
r.y:= rect^.y + cFontBorder div 2; |
|
64 |
r.w:= rect^.w - cFontBorder * 2; |
|
65 |
r.h:= rect^.h - cFontBorder; |
|
4380 | 66 |
SDL_FillRect(Surface, @r, FillColor); |
11836 | 67 |
r.x:= rect^.x + cFontBorder div 2; |
68 |
r.y:= rect^.y + cFontBorder; |
|
69 |
r.w:= rect^.w - cFontBorder; |
|
70 |
r.h:= rect^.h - cFontBorder * 2; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
71 |
SDL_FillRect(Surface, @r, FillColor); |
4380 | 72 |
end; |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
73 |
(* |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
74 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
75 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
76 |
WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
77 |
end;*) |
4380 | 78 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
79 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord): TSDL_Rect; |
10494 | 80 |
var w, h: Longword; |
4380 | 81 |
tmpsurf: PSDL_Surface; |
82 |
clr: TSDL_Color; |
|
6750 | 83 |
finalRect, textRect: TSDL_Rect; |
4380 | 84 |
begin |
10127 | 85 |
TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), @w, @h); |
11836 | 86 |
if (maxLength > 0) and (w > maxLength * HDPIScaleFactor) then w := maxLength * HDPIScaleFactor; |
4380 | 87 |
finalRect.x:= X; |
88 |
finalRect.y:= Y; |
|
11836 | 89 |
finalRect.w:= w + cFontBorder * 2 + cFontPadding * 2; |
6982 | 90 |
finalRect.h:= h + cFontBorder * 2; |
6750 | 91 |
textRect.x:= X; |
92 |
textRect.y:= Y; |
|
93 |
textRect.w:= w; |
|
94 |
textRect.h:= h; |
|
7546
b50556f2a0e8
This union hasn't been needed for 5 years, and makes using other headers harder.
nemo
parents:
7069
diff
changeset
|
95 |
DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true); |
4380 | 96 |
clr.r:= (Color shr 16) and $FF; |
97 |
clr.g:= (Color shr 8) and $FF; |
|
98 |
clr.b:= Color and $FF; |
|
10127 | 99 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr); |
11836 | 100 |
finalRect.x:= X + cFontBorder + cFontPadding; |
6982 | 101 |
finalRect.y:= Y + cFontBorder; |
11507 | 102 |
if SDLCheck(tmpsurf <> nil, 'TTF_RenderUTF8_Blended', true) then |
103 |
exit; |
|
6750 | 104 |
SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect); |
4380 | 105 |
SDL_FreeSurface(tmpsurf); |
106 |
finalRect.x:= X; |
|
107 |
finalRect.y:= Y; |
|
11836 | 108 |
finalRect.w:= w + cFontBorder * 2 + cFontPadding * 2; |
6982 | 109 |
finalRect.h:= h + cFontBorder * 2; |
4380 | 110 |
WriteInRoundRect:= finalRect; |
111 |
end; |
|
112 |
||
113 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
114 |
var y, x, i, j: LongInt; |
|
115 |
tmpPixel: Longword; |
|
116 |
pixels: PLongWordArray; |
|
117 |
begin |
|
11532 | 118 |
if checkFails(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true) then |
119 |
exit; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
120 |
SDL_LockSurface(Surface); |
4380 | 121 |
pixels:= Surface^.pixels; |
122 |
if Vertical then |
|
123 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
124 |
for x := 0 to Surface^.w - 1 do |
|
125 |
begin |
|
126 |
i:= y * Surface^.w + x; |
|
127 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
128 |
tmpPixel:= pixels^[i]; |
|
129 |
pixels^[i]:= pixels^[j]; |
|
130 |
pixels^[j]:= tmpPixel; |
|
131 |
end |
|
132 |
else |
|
133 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
11532 | 134 |
for y := 0 to Surface^.h - 1 do |
4380 | 135 |
begin |
136 |
i:= y*Surface^.w + x; |
|
137 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
138 |
tmpPixel:= pixels^[i]; |
|
139 |
pixels^[i]:= pixels^[j]; |
|
140 |
pixels^[j]:= tmpPixel; |
|
141 |
end; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
142 |
SDL_UnlockSurface(Surface); |
4380 | 143 |
end; |
144 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
145 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline; |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
146 |
begin |
12098
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
147 |
// copy from complete src |
7013 | 148 |
copyToXYFromRect(src, dest, 0, 0, src^.w, src^.h, destX, destY); |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
149 |
end; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
150 |
|
7013 | 151 |
procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); |
12098
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
152 |
var i, j, iX, iY, dX, dY, lX, lY: LongInt; |
4380 | 153 |
srcPixels, destPixels: PLongWordArray; |
154 |
r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
|
155 |
begin |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
156 |
SDL_LockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
157 |
SDL_LockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
158 |
|
4380 | 159 |
srcPixels:= src^.pixels; |
160 |
destPixels:= dest^.pixels; |
|
161 |
||
12098
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
162 |
// what's the offset between src and dest coords? |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
163 |
dX:= destX - srcX; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
164 |
dY:= destY - srcY; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
165 |
|
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
166 |
// let's figure out where the rectangle we can actually copy ends |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
167 |
lX:= ( min( min(srcX + srcW, src^.w), min(destX + srcW + dx, dest^.w) - dx ) ) - 1; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
168 |
lY:= ( min( min(srcY + srcH, src^.h), min(destY + srcH + dy, dest^.h) - dY ) ) - 1; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
169 |
|
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
170 |
for iX:= srcX to lX do |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
171 |
for iY:= srcY to lY do |
4380 | 172 |
begin |
12098
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
173 |
i:= (iY + dY) * dest^.w + (iX + dX); |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
174 |
j:= iY * src^.w + iX; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11836
diff
changeset
|
175 |
if srcPixels^[j] and AMask <> 0 then |
4380 | 176 |
begin |
177 |
SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0); |
|
178 |
SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1); |
|
179 |
r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255; |
|
180 |
g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255; |
|
181 |
b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255; |
|
10860
891bf0aca23e
changed/fixed alpha blending in copyToXYFromRect
sheepluva
parents:
10691
diff
changeset
|
182 |
a0:= a0 + ((255 - LongInt(a0)) * a1 div 255); |
4380 | 183 |
destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0); |
184 |
end; |
|
185 |
end; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
186 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
187 |
SDL_UnlockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
188 |
SDL_UnlockSurface(dest); |
4380 | 189 |
end; |
190 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
191 |
procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
192 |
begin |
7013 | 193 |
DrawSpriteFrame2Surf(sprite, dest, x, y, 0); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
194 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
195 |
|
7013 | 196 |
procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt); |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
197 |
var numFramesFirstCol, row, col: LongInt; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
198 |
begin |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
199 |
numFramesFirstCol:= SpritesData[sprite].imageHeight div SpritesData[sprite].Height; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
200 |
row:= Frame mod numFramesFirstCol; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
201 |
col:= Frame div numFramesFirstCol; |
10015 | 202 |
|
203 |
copyToXYFromRect(SpritesData[sprite].Surface, dest, |
|
204 |
col*SpritesData[sprite].Width, |
|
205 |
row*SpritesData[sprite].Height, |
|
206 |
SpritesData[sprite].Width, |
|
207 |
spritesData[sprite].Height, |
|
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
208 |
x,y); |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
209 |
end; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
210 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
211 |
procedure DrawLine2Surf(dest: PSDL_Surface; x0, y0,x1,y1: LongInt; r,g,b: byte); |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
212 |
var |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
213 |
dx,dy,err,e2,sx,sy: LongInt; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
214 |
yMax: LongInt; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
215 |
destPixels: PLongwordArray; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
216 |
begin |
6992 | 217 |
//max:= (dest^.pitch div 4) * dest^.h; |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
218 |
yMax:= dest^.pitch div 4; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
219 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
220 |
SDL_LockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
221 |
|
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
222 |
destPixels:= dest^.pixels; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
223 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
224 |
dx:= abs(x1-x0); |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
225 |
dy:= abs(y1-y0); |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
226 |
if x0 < x1 then sx:= 1 else sx:= -1; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
227 |
if y0 < y1 then sy:= 1 else sy:= -1; |
10015 | 228 |
err:= dx-dy; |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
229 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
230 |
while(true) do |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
231 |
begin |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
232 |
destPixels^[(y0 * yMax) + x0]:= SDL_MapRGB(dest^.format, r,g,b); //But will it blend? no |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
233 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
234 |
if (x0 = x1) and (y0 = y1) then break; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
235 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
236 |
e2:= 2*err; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
237 |
if e2 > -dy then |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
238 |
begin |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
239 |
err:= err - dy; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
240 |
x0 := x0 + sx; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
241 |
end; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
242 |
|
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
243 |
if e2 < dx then |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
244 |
begin |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
245 |
err:= err + dx; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
246 |
y0:=y0+sy |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
247 |
end; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
248 |
end; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
249 |
SDL_UnlockSurface(dest); |
6620
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
250 |
end; |
b211d0b690de
Expanded copyToXY, it doesn't copy the whole src sprite, srcX/Y to srcW/h, added DrawSprite2Surf and DrawLine2Surf
Xeli
parents:
6580
diff
changeset
|
251 |
|
4380 | 252 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
253 |
var y, x, i, j: LongInt; |
|
254 |
srcPixels, destPixels: PLongWordArray; |
|
255 |
begin |
|
11532 | 256 |
checkFails(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
257 |
checkFails(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
258 |
if not allOK then exit; |
|
4380 | 259 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
260 |
SDL_LockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
261 |
SDL_LockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
262 |
|
4380 | 263 |
srcPixels:= src^.pixels; |
264 |
destPixels:= dest^.pixels; |
|
265 |
||
266 |
j:= 0; |
|
267 |
for x := 0 to src^.w - 1 do |
|
268 |
for y := 0 to src^.h - 1 do |
|
269 |
begin |
|
270 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
271 |
destPixels^[j]:= srcPixels^[i]; |
|
272 |
inc(j) |
|
273 |
end; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
274 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
275 |
SDL_UnlockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
276 |
SDL_UnlockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
277 |
|
4380 | 278 |
end; |
279 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
280 |
function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
281 |
begin |
7013 | 282 |
RenderStringTex:= RenderStringTexLim(s, Color, font, 0); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
283 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
284 |
|
7013 | 285 |
function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
10494 | 286 |
var w, h: Longword; |
4380 | 287 |
finalSurface: PSDL_Surface; |
288 |
begin |
|
10139 | 289 |
if cOnlyStats then |
290 |
begin |
|
291 |
RenderStringTexLim:= nil; |
|
292 |
end |
|
293 |
else |
|
294 |
begin |
|
295 |
if length(s) = 0 then s:= _S' '; |
|
296 |
font:= CheckCJKFont(s, font); |
|
297 |
w:= 0; h:= 0; // avoid compiler hints |
|
298 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h); |
|
11836 | 299 |
if (maxLength > 0) and (w > maxLength * HDPIScaleFactor) then w := maxLength * HDPIScaleFactor; |
4380 | 300 |
|
11836 | 301 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder*2 + cFontPadding*2, h + cFontBorder * 2, |
10139 | 302 |
32, RMask, GMask, BMask, AMask); |
4380 | 303 |
|
11532 | 304 |
if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
305 |
exit(nil); |
|
10139 | 306 |
|
307 |
WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
|
4380 | 308 |
|
11532 | 309 |
checkFails(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, false); |
4380 | 310 |
|
10139 | 311 |
RenderStringTexLim:= Surface2Tex(finalSurface, false); |
4380 | 312 |
|
10139 | 313 |
SDL_FreeSurface(finalSurface); |
314 |
end; |
|
4380 | 315 |
end; |
316 |
||
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
317 |
function GetNextSpeechLine(s: ansistring; ldelim: char; var startFrom: LongInt; out substr: ansistring): boolean; |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
318 |
var p, l, m, r: Integer; |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
319 |
newl, skip: boolean; |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
320 |
c : char; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
321 |
begin |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
322 |
m:= Length(s); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
323 |
|
10690 | 324 |
substr:= ''; |
325 |
||
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
326 |
SetLengthA(substr, m); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
327 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
328 |
// number of chars read |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
329 |
r:= 0; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
330 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
331 |
// number of chars to be written |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
332 |
l:= 0; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
333 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
334 |
newl:= true; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
335 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
336 |
for p:= max(1, startFrom) to m do |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
337 |
begin |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
338 |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
339 |
inc(r); |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
340 |
// read char from source string |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
341 |
c:= s[p]; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
342 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
343 |
// strip empty lines, spaces and newlines on beginnings of line |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
344 |
skip:= ((newl or (p = m)) and ((c = ' ') or (c = ldelim))); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
345 |
|
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
346 |
if (not skip) then |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
347 |
begin |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
348 |
newl:= (c = ldelim); |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
349 |
// stop if we went past the end of the line |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
350 |
if newl then |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
351 |
break; |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
352 |
|
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
353 |
// copy current char to output substring |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
354 |
inc(l); |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
355 |
substr[l]:= c; |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
356 |
end; |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
357 |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
358 |
end; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
359 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
360 |
inc(startFrom, r); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
361 |
|
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
362 |
SetLengthA(substr, l); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
363 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
364 |
GetNextSpeechLine:= (l > 0); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
365 |
end; |
4380 | 366 |
|
367 |
function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
368 |
var textWidth, textHeight, x, y, w, h, i, j, pos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
4380 | 369 |
finalSurface, tmpsurf, rotatedEdge: PSDL_Surface; |
370 |
rect: TSDL_Rect; |
|
10127 | 371 |
{$IFNDEF PAS2C} |
4611 | 372 |
chars: set of char = [#9,' ',';',':','?','!',',']; |
10127 | 373 |
{$ENDIF} |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
374 |
substr: ansistring; |
4380 | 375 |
edge, corner, tail: TSPrite; |
376 |
begin |
|
10139 | 377 |
if cOnlyStats then exit(nil); |
378 |
||
4380 | 379 |
case SpeechType of |
10142 | 380 |
1: begin |
10139 | 381 |
edge:= sprSpeechEdge; |
382 |
corner:= sprSpeechCorner; |
|
383 |
tail:= sprSpeechTail; |
|
384 |
end; |
|
10142 | 385 |
2: begin |
10139 | 386 |
edge:= sprThoughtEdge; |
387 |
corner:= sprThoughtCorner; |
|
388 |
tail:= sprThoughtTail; |
|
389 |
end; |
|
10142 | 390 |
3: begin |
10139 | 391 |
edge:= sprShoutEdge; |
392 |
corner:= sprShoutCorner; |
|
393 |
tail:= sprShoutTail; |
|
10142 | 394 |
end |
395 |
else |
|
396 |
exit(nil) |
|
4380 | 397 |
end; |
398 |
edgeHeight:= SpritesData[edge].Height; |
|
399 |
edgeWidth:= SpritesData[edge].Width; |
|
400 |
cornerWidth:= SpritesData[corner].Width; |
|
401 |
cornerHeight:= SpritesData[corner].Height; |
|
402 |
// This one screws up WrapText |
|
403 |
//s:= 'This is the song that never ends. ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...'; |
|
404 |
// This one does not |
|
405 |
//s:= 'This is the song that never ends. cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... '; |
|
406 |
||
407 |
numLines:= 0; |
|
408 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
409 |
if length(s) = 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
410 |
s:= '...'; |
4380 | 411 |
font:= CheckCJKFont(s, font); |
412 |
w:= 0; h:= 0; // avoid compiler hints |
|
10127 | 413 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
414 |
if w<8 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
415 |
w:= 8; |
4380 | 416 |
j:= 0; |
417 |
if (length(s) > 20) then |
|
418 |
begin |
|
419 |
w:= 0; |
|
420 |
i:= round(Sqrt(length(s)) * 2); |
|
10127 | 421 |
{$IFNDEF PAS2C} |
4380 | 422 |
s:= WrapText(s, #1, chars, i); |
10127 | 423 |
{$ENDIF} |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
424 |
pos:= 1; line:= 0; |
4380 | 425 |
// Find the longest line for the purposes of centring the text. Font dependant. |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
426 |
while GetNextSpeechLine(s, #1, pos, substr) do |
4380 | 427 |
begin |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
428 |
inc(numLines); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
429 |
i:= 0; j:= 0; |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
430 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(substr), @i, @j); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
431 |
if i > w then |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
432 |
w:= i; |
4380 | 433 |
end; |
434 |
end |
|
435 |
else numLines := 1; |
|
436 |
||
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
437 |
if numLines < 1 then |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
438 |
begin |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
439 |
s:= '...'; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
440 |
numLines:= 1; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
441 |
end; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
442 |
|
4380 | 443 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
444 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
|
445 |
||
446 |
textHeight:=max(textHeight,edgeWidth); |
|
447 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
|
448 |
rect.x:= 0; |
|
449 |
rect.y:= 0; |
|
450 |
rect.w:= textWidth + (cornerWidth * 2); |
|
451 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
452 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
|
453 |
||
454 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
455 |
||
11532 | 456 |
if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
457 |
exit(nil); |
|
4380 | 458 |
|
459 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
460 |
copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
|
461 |
||
462 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
463 |
x:= 0; |
|
464 |
y:= textHeight + cornerHeight -1; |
|
465 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW |
|
466 |
||
467 |
flipSurface(SpritesData[corner].Surface, false); |
|
468 |
x:= rect.w-cornerWidth-1; |
|
469 |
y:= textHeight + cornerHeight -1; |
|
470 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE |
|
471 |
||
472 |
flipSurface(SpritesData[corner].Surface, true); |
|
473 |
x:= rect.w-cornerWidth-1; |
|
474 |
y:= 0; |
|
475 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE |
|
476 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
477 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
478 |
||
479 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
480 |
x:= cornerWidth; |
|
481 |
y:= 0; |
|
482 |
while x < rect.w-cornerWidth-1 do |
|
483 |
begin |
|
484 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge |
|
485 |
inc(x,edgeWidth); |
|
486 |
end; |
|
487 |
flipSurface(SpritesData[edge].Surface, true); |
|
488 |
x:= cornerWidth; |
|
489 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
490 |
while x < rect.w-cornerWidth-1 do |
|
491 |
begin |
|
492 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge |
|
493 |
inc(x,edgeWidth); |
|
494 |
end; |
|
495 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
496 |
||
497 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
498 |
x:= rect.w - edgeHeight - 1; |
|
499 |
y:= cornerHeight; |
|
500 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
501 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
502 |
while y < textHeight + cornerHeight do |
|
503 |
begin |
|
504 |
copyToXY(rotatedEdge, finalSurface, x, y); |
|
505 |
inc(y,edgeWidth); |
|
506 |
end; |
|
507 |
flipSurface(rotatedEdge, false); // restore original position |
|
508 |
x:= 0; |
|
509 |
y:= cornerHeight; |
|
510 |
while y < textHeight + cornerHeight do |
|
511 |
begin |
|
512 |
copyToXY(rotatedEdge, finalSurface, x, y); |
|
513 |
inc(y,edgeWidth); |
|
514 |
end; |
|
515 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
516 |
||
517 |
x:= cornerWidth; |
|
518 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
519 |
copyToXY(SpritesData[tail].Surface, finalSurface, x, y); |
|
520 |
||
521 |
rect.x:= edgeHeight; |
|
522 |
rect.y:= edgeHeight; |
|
523 |
rect.w:= rect.w - edgeHeight * 2; |
|
524 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
525 |
i:= rect.w; |
|
526 |
j:= rect.h; |
|
527 |
SDL_FillRect(finalSurface, @rect, cWhiteColor); |
|
528 |
||
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
529 |
pos:= 1; line:= 0; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
530 |
while GetNextSpeechLine(s, #1, pos, substr) do |
4380 | 531 |
begin |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
532 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(substr), cNearBlackColorChannels); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
533 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
534 |
// trying to more evenly position the text, vertically |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
535 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
11507 | 536 |
if not SDLCheck(tmpsurf <> nil, 'TTF_RenderUTF8_Blended', true) then |
537 |
begin |
|
538 |
SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
|
539 |
SDL_FreeSurface(tmpsurf); |
|
540 |
end; |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
541 |
inc(line); |
4380 | 542 |
end; |
543 |
||
544 |
RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
|
545 |
||
546 |
SDL_FreeSurface(rotatedEdge); |
|
547 |
SDL_FreeSurface(finalSurface); |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
548 |
|
4380 | 549 |
end; |
550 |
||
4611 | 551 |
end. |