author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 31 Jul 2018 01:00:27 +0200 | |
changeset 13582 | 66460d5f0d9b |
parent 13494 | 8935dcc0e130 |
child 14639 | b055360684bd |
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 |
|
11826 | 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 |
13494
8935dcc0e130
Always use SDL_Map(A)RGB in SDL_FillRect for color
Wuzzy <Wuzzy2@mail.ru>
parents:
12596
diff
changeset
|
49 |
SDL_FillRect(Surface, @r, SDL_MapRGB(Surface^.format, 0, 0, 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 |
||
11841 | 54 |
r.y:= rect^.y + cFontBorder div 2; |
55 |
r.h:= rect^.h - cFontBorder; |
|
4380 | 56 |
SDL_FillRect(Surface, @r, BorderColor); |
11841 | 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); |
|
11841 | 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); |
11841 | 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); |
11841 | 86 |
if (maxLength > 0) and (w > maxLength * HDPIScaleFactor) then w := maxLength * HDPIScaleFactor; |
4380 | 87 |
finalRect.x:= X; |
88 |
finalRect.y:= Y; |
|
11841 | 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); |
11841 | 100 |
finalRect.x:= X + cFontBorder + cFontPadding; |
6982 | 101 |
finalRect.y:= Y + cFontBorder; |
11512 | 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; |
|
11841 | 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 |
|
11537 | 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 |
|
11537 | 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 |
12103
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
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); |
12104 | 152 |
var spi, dpi, iX, iY, dX, dY, lX, lY, aT: LongInt; |
4380 | 153 |
srcPixels, destPixels: PLongWordArray; |
12104 | 154 |
rD, gD, bD, aD, rT, gT, bT: Byte; |
4380 | 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 |
||
12103
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
162 |
// what's the offset between src and dest coords? |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
163 |
dX:= destX - srcX; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
164 |
dY:= destY - srcY; |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
165 |
|
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
166 |
// let's figure out where the rectangle we can actually copy ends |
12106
2e70ef81e281
copyToXYFromRect: simplify my math (so that it actually, you know, works...)
sheepluva
parents:
12104
diff
changeset
|
167 |
lX:= min(srcX + srcW, src^.w) - 1; |
2e70ef81e281
copyToXYFromRect: simplify my math (so that it actually, you know, works...)
sheepluva
parents:
12104
diff
changeset
|
168 |
if lX + dx >= dest^.w then lX:= dest^.w - dx - 1; |
2e70ef81e281
copyToXYFromRect: simplify my math (so that it actually, you know, works...)
sheepluva
parents:
12104
diff
changeset
|
169 |
lY:= min(srcY + srcH, src^.h) - 1; |
2e70ef81e281
copyToXYFromRect: simplify my math (so that it actually, you know, works...)
sheepluva
parents:
12104
diff
changeset
|
170 |
if lY + dy >= dest^.h then lY:= dest^.h - dy - 1; |
12103
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
171 |
|
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
172 |
for iX:= srcX to lX do |
966a9739812f
copyToXYFromRect: fix pixels overflowing pixel lines in dest
sheepluva
parents:
11841
diff
changeset
|
173 |
for iY:= srcY to lY do |
4380 | 174 |
begin |
12104 | 175 |
// src pixel index |
176 |
spi:= iY * src^.w + iX; |
|
177 |
// dest pixel index |
|
178 |
dpi:= (iY + dY) * dest^.w + (iX + dX); |
|
179 |
||
180 |
// get src alpha (and set it as target alpha for now) |
|
181 |
aT:= (srcPixels^[spi] and AMask) shr AShift; |
|
182 |
||
183 |
// src pixel opaque? |
|
184 |
if aT = 255 then |
|
4380 | 185 |
begin |
12104 | 186 |
// just copy full pixel |
187 |
destPixels^[dpi]:= srcPixels^[spi]; |
|
188 |
continue; |
|
4380 | 189 |
end; |
12104 | 190 |
|
191 |
// get dst alpha (without shift for now) |
|
192 |
aD:= (destPixels^[dpi] and AMask) shr AShift; |
|
193 |
||
194 |
// dest completely transparent? |
|
195 |
if aD = 0 then |
|
196 |
begin |
|
197 |
// just copy src pixel |
|
198 |
destPixels^[dpi]:= srcPixels^[spi]; |
|
199 |
continue; |
|
200 |
end; |
|
201 |
||
202 |
// looks like some blending is necessary |
|
203 |
||
204 |
// set color of target RGB to src for now |
|
205 |
SDL_GetRGB(srcPixels^[spi], src^.format, @rT, @gT, @bT); |
|
206 |
SDL_GetRGB(destPixels^[dpi], dest^.format, @rD, @gD, @bD); |
|
207 |
// note: this is not how to correctly blend RGB, just sayin' (R,G,B are not linear...) |
|
208 |
rT:= (rD * (255 - aT) + rT * aT) div 255; |
|
209 |
gT:= (gD * (255 - aT) + gT * aT) div 255; |
|
210 |
bT:= (bD * (255 - aT) + bT * aT) div 255; |
|
211 |
aT:= aD + ((255 - LongInt(aD)) * aT div 255); |
|
212 |
||
12107
51596d30a724
fix chat SDL surfaces being in wrong color format (didn't play well with copyToXY's new quick pixel copies)
sheepluva
parents:
12106
diff
changeset
|
213 |
destPixels^[dpi]:= SDL_MapRGBA(dest^.format, rT, gT, bT, Byte(aT)); |
51596d30a724
fix chat SDL surfaces being in wrong color format (didn't play well with copyToXY's new quick pixel copies)
sheepluva
parents:
12106
diff
changeset
|
214 |
|
4380 | 215 |
end; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
216 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
217 |
SDL_UnlockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
218 |
SDL_UnlockSurface(dest); |
4380 | 219 |
end; |
220 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
221 |
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
|
222 |
begin |
12104 | 223 |
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
|
224 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
225 |
|
7013 | 226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
col:= Frame div numFramesFirstCol; |
10015 | 232 |
|
233 |
copyToXYFromRect(SpritesData[sprite].Surface, dest, |
|
234 |
col*SpritesData[sprite].Width, |
|
235 |
row*SpritesData[sprite].Height, |
|
236 |
SpritesData[sprite].Width, |
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
|
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 |
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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
begin |
6992 | 247 |
//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
|
248 |
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
|
249 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
250 |
SDL_LockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
251 |
|
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
|
252 |
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
|
253 |
|
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
if y0 < y1 then sy:= 1 else sy:= -1; |
10015 | 258 |
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
|
259 |
|
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
|
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
|
264 |
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
|
265 |
|
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
|
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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
end; |
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
278 |
end; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
|
4380 | 282 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
283 |
var y, x, i, j: LongInt; |
|
284 |
srcPixels, destPixels: PLongWordArray; |
|
285 |
begin |
|
11537 | 286 |
checkFails(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
287 |
checkFails(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
288 |
if not allOK then exit; |
|
4380 | 289 |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
290 |
SDL_LockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
291 |
SDL_LockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
292 |
|
4380 | 293 |
srcPixels:= src^.pixels; |
294 |
destPixels:= dest^.pixels; |
|
295 |
||
296 |
j:= 0; |
|
297 |
for x := 0 to src^.w - 1 do |
|
298 |
for y := 0 to src^.h - 1 do |
|
299 |
begin |
|
300 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
301 |
destPixels^[j]:= srcPixels^[i]; |
|
302 |
inc(j) |
|
303 |
end; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
304 |
|
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
305 |
SDL_UnlockSurface(src); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
306 |
SDL_UnlockSurface(dest); |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
7546
diff
changeset
|
307 |
|
4380 | 308 |
end; |
309 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
310 |
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
|
311 |
begin |
7013 | 312 |
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
|
313 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6982
diff
changeset
|
314 |
|
7013 | 315 |
function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture; |
10494 | 316 |
var w, h: Longword; |
4380 | 317 |
finalSurface: PSDL_Surface; |
318 |
begin |
|
10139 | 319 |
if cOnlyStats then |
320 |
begin |
|
321 |
RenderStringTexLim:= nil; |
|
322 |
end |
|
323 |
else |
|
324 |
begin |
|
325 |
if length(s) = 0 then s:= _S' '; |
|
326 |
font:= CheckCJKFont(s, font); |
|
327 |
w:= 0; h:= 0; // avoid compiler hints |
|
328 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h); |
|
11841 | 329 |
if (maxLength > 0) and (w > maxLength * HDPIScaleFactor) then w := maxLength * HDPIScaleFactor; |
4380 | 330 |
|
11841 | 331 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder*2 + cFontPadding*2, h + cFontBorder * 2, |
10139 | 332 |
32, RMask, GMask, BMask, AMask); |
4380 | 333 |
|
11537 | 334 |
if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
335 |
exit(nil); |
|
10139 | 336 |
|
337 |
WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); |
|
4380 | 338 |
|
12596 | 339 |
checkFails(SDL_SetColorKey(finalSurface, SDL_TRUE, 0) = 0, errmsgTransparentSet, false); |
4380 | 340 |
|
10139 | 341 |
RenderStringTexLim:= Surface2Tex(finalSurface, false); |
4380 | 342 |
|
10139 | 343 |
SDL_FreeSurface(finalSurface); |
344 |
end; |
|
4380 | 345 |
end; |
346 |
||
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
347 |
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
|
348 |
var p, l, m, r: Integer; |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
349 |
newl, skip: boolean; |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
350 |
c : char; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
351 |
begin |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
352 |
m:= Length(s); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
353 |
|
10690 | 354 |
substr:= ''; |
355 |
||
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
356 |
SetLengthA(substr, m); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
357 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
358 |
// number of chars read |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
359 |
r:= 0; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
360 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
361 |
// number of chars to be written |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
362 |
l:= 0; |
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 |
newl:= true; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
365 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
366 |
for p:= max(1, startFrom) to m do |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
367 |
begin |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
368 |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
369 |
inc(r); |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
370 |
// read char from source string |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
371 |
c:= s[p]; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
372 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
373 |
// strip empty lines, spaces and newlines on beginnings of line |
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
374 |
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
|
375 |
|
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
376 |
if (not skip) then |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
377 |
begin |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
378 |
newl:= (c = ldelim); |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
379 |
// stop if we went past the end of the line |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
380 |
if newl then |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
381 |
break; |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
382 |
|
10691
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
383 |
// copy current char to output substring |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
384 |
inc(l); |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
385 |
substr[l]:= c; |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
386 |
end; |
97f45f1374be
change speechfix implementation (no "continue" anymore
sheepluva
parents:
10690
diff
changeset
|
387 |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
388 |
end; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
389 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
390 |
inc(startFrom, r); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
391 |
|
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
392 |
SetLengthA(substr, l); |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
393 |
|
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
394 |
GetNextSpeechLine:= (l > 0); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
395 |
end; |
4380 | 396 |
|
397 |
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
|
398 |
var textWidth, textHeight, x, y, w, h, i, j, pos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
4380 | 399 |
finalSurface, tmpsurf, rotatedEdge: PSDL_Surface; |
400 |
rect: TSDL_Rect; |
|
10127 | 401 |
{$IFNDEF PAS2C} |
4611 | 402 |
chars: set of char = [#9,' ',';',':','?','!',',']; |
10127 | 403 |
{$ENDIF} |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
404 |
substr: ansistring; |
4380 | 405 |
edge, corner, tail: TSPrite; |
406 |
begin |
|
10139 | 407 |
if cOnlyStats then exit(nil); |
408 |
||
4380 | 409 |
case SpeechType of |
10142 | 410 |
1: begin |
10139 | 411 |
edge:= sprSpeechEdge; |
412 |
corner:= sprSpeechCorner; |
|
413 |
tail:= sprSpeechTail; |
|
414 |
end; |
|
10142 | 415 |
2: begin |
10139 | 416 |
edge:= sprThoughtEdge; |
417 |
corner:= sprThoughtCorner; |
|
418 |
tail:= sprThoughtTail; |
|
419 |
end; |
|
10142 | 420 |
3: begin |
10139 | 421 |
edge:= sprShoutEdge; |
422 |
corner:= sprShoutCorner; |
|
423 |
tail:= sprShoutTail; |
|
10142 | 424 |
end |
425 |
else |
|
426 |
exit(nil) |
|
4380 | 427 |
end; |
428 |
edgeHeight:= SpritesData[edge].Height; |
|
429 |
edgeWidth:= SpritesData[edge].Width; |
|
430 |
cornerWidth:= SpritesData[corner].Width; |
|
431 |
cornerHeight:= SpritesData[corner].Height; |
|
432 |
// This one screws up WrapText |
|
433 |
//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...'; |
|
434 |
// This one does not |
|
435 |
//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... '; |
|
436 |
||
437 |
numLines:= 0; |
|
438 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6286
diff
changeset
|
439 |
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
|
440 |
s:= '...'; |
4380 | 441 |
font:= CheckCJKFont(s, font); |
442 |
w:= 0; h:= 0; // avoid compiler hints |
|
10127 | 443 |
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
|
444 |
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
|
445 |
w:= 8; |
4380 | 446 |
j:= 0; |
447 |
if (length(s) > 20) then |
|
448 |
begin |
|
449 |
w:= 0; |
|
450 |
i:= round(Sqrt(length(s)) * 2); |
|
10127 | 451 |
{$IFNDEF PAS2C} |
4380 | 452 |
s:= WrapText(s, #1, chars, i); |
10127 | 453 |
{$ENDIF} |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
454 |
pos:= 1; line:= 0; |
4380 | 455 |
// 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
|
456 |
while GetNextSpeechLine(s, #1, pos, substr) do |
4380 | 457 |
begin |
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
458 |
inc(numLines); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
459 |
i:= 0; j:= 0; |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
460 |
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
|
461 |
if i > w then |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
462 |
w:= i; |
4380 | 463 |
end; |
464 |
end |
|
465 |
else numLines := 1; |
|
466 |
||
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
467 |
if numLines < 1 then |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
468 |
begin |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
469 |
s:= '...'; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
470 |
numLines:= 1; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
471 |
end; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
472 |
|
4380 | 473 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
474 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
|
475 |
||
476 |
textHeight:=max(textHeight,edgeWidth); |
|
477 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
|
478 |
rect.x:= 0; |
|
479 |
rect.y:= 0; |
|
480 |
rect.w:= textWidth + (cornerWidth * 2); |
|
481 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
482 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
|
483 |
||
484 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
|
485 |
||
11537 | 486 |
if checkFails(finalSurface <> nil, 'RenderString: fail to create surface', true) then |
487 |
exit(nil); |
|
4380 | 488 |
|
489 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
490 |
copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
|
491 |
||
492 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
493 |
x:= 0; |
|
494 |
y:= textHeight + cornerHeight -1; |
|
495 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW |
|
496 |
||
497 |
flipSurface(SpritesData[corner].Surface, false); |
|
498 |
x:= rect.w-cornerWidth-1; |
|
499 |
y:= textHeight + cornerHeight -1; |
|
500 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE |
|
501 |
||
502 |
flipSurface(SpritesData[corner].Surface, true); |
|
503 |
x:= rect.w-cornerWidth-1; |
|
504 |
y:= 0; |
|
505 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE |
|
506 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
|
507 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
508 |
||
509 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
510 |
x:= cornerWidth; |
|
511 |
y:= 0; |
|
512 |
while x < rect.w-cornerWidth-1 do |
|
513 |
begin |
|
514 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge |
|
515 |
inc(x,edgeWidth); |
|
516 |
end; |
|
517 |
flipSurface(SpritesData[edge].Surface, true); |
|
518 |
x:= cornerWidth; |
|
519 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
520 |
while x < rect.w-cornerWidth-1 do |
|
521 |
begin |
|
522 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge |
|
523 |
inc(x,edgeWidth); |
|
524 |
end; |
|
525 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
526 |
||
527 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
528 |
x:= rect.w - edgeHeight - 1; |
|
529 |
y:= cornerHeight; |
|
530 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
531 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
532 |
while y < textHeight + cornerHeight do |
|
533 |
begin |
|
534 |
copyToXY(rotatedEdge, finalSurface, x, y); |
|
535 |
inc(y,edgeWidth); |
|
536 |
end; |
|
537 |
flipSurface(rotatedEdge, false); // restore original position |
|
538 |
x:= 0; |
|
539 |
y:= cornerHeight; |
|
540 |
while y < textHeight + cornerHeight do |
|
541 |
begin |
|
542 |
copyToXY(rotatedEdge, finalSurface, x, y); |
|
543 |
inc(y,edgeWidth); |
|
544 |
end; |
|
545 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
546 |
||
547 |
x:= cornerWidth; |
|
548 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
549 |
copyToXY(SpritesData[tail].Surface, finalSurface, x, y); |
|
550 |
||
551 |
rect.x:= edgeHeight; |
|
552 |
rect.y:= edgeHeight; |
|
553 |
rect.w:= rect.w - edgeHeight * 2; |
|
554 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
555 |
i:= rect.w; |
|
556 |
j:= rect.h; |
|
13494
8935dcc0e130
Always use SDL_Map(A)RGB in SDL_FillRect for color
Wuzzy <Wuzzy2@mail.ru>
parents:
12596
diff
changeset
|
557 |
SDL_FillRect(finalSurface, @rect, SDL_MapRGB(finalSurface^.format, cWhiteColor shr 16, cWhiteColor shr 8, cWhiteColor and $FF)); |
4380 | 558 |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
559 |
pos:= 1; line:= 0; |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
560 |
while GetNextSpeechLine(s, #1, pos, substr) do |
4380 | 561 |
begin |
10689
692649e341fc
change string types of speech bubbles fix to work with pas2c
sheepluva
parents:
10687
diff
changeset
|
562 |
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
|
563 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
564 |
// trying to more evenly position the text, vertically |
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
565 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
11512 | 566 |
if not SDLCheck(tmpsurf <> nil, 'TTF_RenderUTF8_Blended', true) then |
567 |
begin |
|
568 |
SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
|
569 |
SDL_FreeSurface(tmpsurf); |
|
570 |
end; |
|
10687
2e921409b5b1
cleanup speech bubble code a little. this fixes issue 719
sheepluva
parents:
10494
diff
changeset
|
571 |
inc(line); |
4380 | 572 |
end; |
573 |
||
574 |
RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
|
575 |
||
576 |
SDL_FreeSurface(rotatedEdge); |
|
577 |
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
|
578 |
|
4380 | 579 |
end; |
580 |
||
4611 | 581 |
end. |