hedgewars/uRenderUtils.pas
author sheepluva
Tue, 04 Feb 2014 19:45:22 +0100
changeset 10108 c68cf030eded
parent 10107 dd6541ba745e
child 10116 dd27562b6f21
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9080
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    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
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    17
 *)
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    18
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    20
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    21
unit uRenderUtils;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    22
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    23
interface
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    24
uses SDLh, uTypes;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    25
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    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
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    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
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
    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
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
    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;
10104
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
    38
function  RenderStringTexPChar(s: PChar; Color: Longword; font: THWFont): PTexture;
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
    39
function  RenderStringTexLim(s: PChar; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    40
function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    41
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    42
implementation
7063
a0326412e96a sysutils -> SysUtils
unc0rr
parents: 7013
diff changeset
    43
uses uUtils, uVariables, uConsts, uTextures, SysUtils, uDebug;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    44
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    45
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    46
var r: TSDL_Rect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    47
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    48
    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
    49
    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
    50
        SDL_FillRect(Surface, @r, 0);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    51
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    52
    BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    53
    FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    54
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    55
    r.y:= rect^.y + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    56
    r.h:= rect^.h - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    57
    SDL_FillRect(Surface, @r, BorderColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    58
    r.x:= rect^.x + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    59
    r.w:= rect^.w - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    60
    r.y:= rect^.y;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    61
    r.h:= rect^.h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    62
    SDL_FillRect(Surface, @r, BorderColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    63
    r.x:= rect^.x + 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    64
    r.y:= rect^.y + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    65
    r.w:= rect^.w - 4;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    66
    r.h:= rect^.h - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    67
    SDL_FillRect(Surface, @r, FillColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    68
    r.x:= rect^.x + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    69
    r.y:= rect^.y + 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    70
    r.w:= rect^.w - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    71
    r.h:= rect^.h - 4;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
    72
    SDL_FillRect(Surface, @r, FillColor);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    73
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
    74
(*
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    75
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
    76
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    77
    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
    78
end;*)
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    79
10105
8c5fa1d15bd5 fixing the remaining PChar issues pas2c ran into to this point, now it stops because of being unable to deal with "set of char"
sheepluva
parents: 10104
diff changeset
    80
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar; maxLength: LongWord): TSDL_Rect;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    81
var w, h: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    82
    tmpsurf: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    83
    clr: TSDL_Color;
6750
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
    84
    finalRect, textRect: TSDL_Rect;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    85
begin
10105
8c5fa1d15bd5 fixing the remaining PChar issues pas2c ran into to this point, now it stops because of being unable to deal with "set of char"
sheepluva
parents: 10104
diff changeset
    86
    TTF_SizeUTF8(Fontz[Font].Handle, s, @w, @h);
6749
6bb0cea803bd Clamp name/team name textures to avoid long team / hog name abuse. Limit width in px instead of chars to avoid unicode issues.
nemo
parents: 6700
diff changeset
    87
    if (maxLength <> 0) and (w > maxLength) then w := maxLength;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    88
    finalRect.x:= X;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    89
    finalRect.y:= Y;
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
    90
    finalRect.w:= w + cFontBorder * 2 + 4;
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
    91
    finalRect.h:= h + cFontBorder * 2;
6750
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
    92
    textRect.x:= X;
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
    93
    textRect.y:= Y;
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
    94
    textRect.w:= w;
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
    95
    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
    96
    DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    97
    clr.r:= (Color shr 16) and $FF;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    98
    clr.g:= (Color shr 8) and $FF;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    99
    clr.b:= Color and $FF;
10105
8c5fa1d15bd5 fixing the remaining PChar issues pas2c ran into to this point, now it stops because of being unable to deal with "set of char"
sheepluva
parents: 10104
diff changeset
   100
    tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr);
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
   101
    finalRect.x:= X + cFontBorder + 2;
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
   102
    finalRect.y:= Y + cFontBorder;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   103
    SDLTry(tmpsurf <> nil, true);
6750
5eb087708fbd attractiveness tweak to the text clip
nemo
parents: 6749
diff changeset
   104
    SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   105
    SDL_FreeSurface(tmpsurf);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   106
    finalRect.x:= X;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   107
    finalRect.y:= Y;
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
   108
    finalRect.w:= w + cFontBorder * 2 + 4;
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
   109
    finalRect.h:= h + cFontBorder * 2;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   110
    WriteInRoundRect:= finalRect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   111
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   112
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   113
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   114
var y, x, i, j: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   115
    tmpPixel: Longword;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   116
    pixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   117
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   118
    TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   119
    SDL_LockSurface(Surface);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   120
    pixels:= Surface^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   121
    if Vertical then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   122
    for y := 0 to (Surface^.h div 2) - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   123
        for x := 0 to Surface^.w - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   124
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   125
            i:= y * Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   126
            j:= (Surface^.h - y - 1) * Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   127
            tmpPixel:= pixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   128
            pixels^[i]:= pixels^[j];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   129
            pixels^[j]:= tmpPixel;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   130
            end
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   131
    else
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   132
    for x := 0 to (Surface^.w div 2) - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   133
        for y := 0 to Surface^.h -1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   134
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   135
            i:= y*Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   136
            j:= y*Surface^.w + (Surface^.w - x - 1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   137
            tmpPixel:= pixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   138
            pixels^[i]:= pixels^[j];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   139
            pixels^[j]:= tmpPixel;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   140
            end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   141
    SDL_UnlockSurface(Surface);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   142
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   143
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   144
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
   145
begin
7013
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
   146
    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
   147
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
   148
7013
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
   149
procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: 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
   150
var i, j, maxDest, maxSrc, iX, iY: LongInt;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   151
    srcPixels, destPixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   152
    r0, g0, b0, a0, r1, g1, b1, a1: Byte;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   153
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   154
    maxDest:= (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
   155
    maxSrc:= (src^.pitch div 4) * src^.h;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   156
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   157
    SDL_LockSurface(src);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   158
    SDL_LockSurface(dest);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   159
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   160
    srcPixels:= src^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   161
    destPixels:= dest^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   162
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
   163
    for iX:= 0 to srcW - 1 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
   164
    for iY:= 0 to srcH - 1 do
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   165
        begin
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
   166
        i:= (destY + iY) * (dest^.pitch div 4) + (destX + iX);
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
   167
        j:= (srcY  + iY) * (src^.pitch  div 4) + (srcX  + iX);
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
   168
        if (i < maxDest) and (j < maxSrc) and (srcPixels^[j] and AMask <> 0) then
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   169
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   170
            SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   171
            SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   172
            r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   173
            g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   174
            b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   175
            a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   176
            destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   177
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   178
        end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   179
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   180
    SDL_UnlockSurface(src);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   181
    SDL_UnlockSurface(dest);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   182
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   183
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   184
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
   185
begin
7013
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
   186
    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
   187
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   188
7013
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
   189
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
   190
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
   191
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
   192
    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
   193
    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
   194
    col:= Frame div numFramesFirstCol;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   195
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   196
    copyToXYFromRect(SpritesData[sprite].Surface, dest,
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   197
             col*SpritesData[sprite].Width,
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   198
             row*SpritesData[sprite].Height,
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   199
             SpritesData[sprite].Width,
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   200
             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
   201
             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
   202
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
   203
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
   204
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
   205
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
   206
    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
   207
    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
   208
    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
   209
begin
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   210
    //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
   211
    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
   212
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   213
    SDL_LockSurface(dest);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   214
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
   215
    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
   216
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
   217
    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
   218
    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
   219
    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
   220
    if y0 < y1 then sy:= 1 else sy:= -1;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9127
diff changeset
   221
    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
   222
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
    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
   224
        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
   225
        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
   226
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 (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
   228
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
        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
   230
        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
   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
            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
   233
            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
   234
            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
   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
        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
   237
            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
   238
            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
   239
            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
   240
            end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   241
        end;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   242
    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
   243
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
   244
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   245
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   246
var y, x, i, j: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   247
    srcPixels, destPixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   248
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   249
    TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   250
    TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   251
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   252
    SDL_LockSurface(src);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   253
    SDL_LockSurface(dest);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   254
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   255
    srcPixels:= src^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   256
    destPixels:= dest^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   257
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   258
    j:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   259
    for x := 0 to src^.w - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   260
        for y := 0 to src^.h - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   261
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   262
            i:= (src^.h - 1 - y) * (src^.pitch div 4) + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   263
            destPixels^[j]:= srcPixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   264
            inc(j)
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   265
            end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   266
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   267
    SDL_UnlockSurface(src);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   268
    SDL_UnlockSurface(dest);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   269
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   270
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   271
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   272
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
   273
begin
10104
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   274
    RenderStringTex:= RenderStringTexLim(Str2PChar(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
   275
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   276
10104
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   277
function RenderStringTexPChar(s: PChar; Color: Longword; font: THWFont): PTexture;
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   278
begin
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   279
    RenderStringTexPChar:= RenderStringTexLim(s, Color, font, 0);
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   280
end;
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   281
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   282
function RenderStringTexLim(s: PChar; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   283
var w, h: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   284
    finalSurface: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   285
begin
10107
dd6541ba745e whoops, lost a space
sheepluva
parents: 10106
diff changeset
   286
    if s[0] = #0 then s:= Str2PChar(' '); // conversion because pas2c ain't smart enough yet;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   287
    font:= CheckCJKFont(s, font);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   288
    w:= 0; h:= 0; // avoid compiler hints
10104
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   289
    TTF_SizeUTF8(Fontz[font].Handle, s, @w, @h);
6749
6bb0cea803bd Clamp name/team name textures to avoid long team / hog name abuse. Limit width in px instead of chars to avoid unicode issues.
nemo
parents: 6700
diff changeset
   290
    if (maxLength <> 0) and (w > maxLength) then w := maxLength;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   291
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6750
diff changeset
   292
    finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   293
            32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   294
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   295
    TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   296
6749
6bb0cea803bd Clamp name/team name textures to avoid long team / hog name abuse. Limit width in px instead of chars to avoid unicode issues.
nemo
parents: 6700
diff changeset
   297
    WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   298
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   299
    TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   300
7013
54db061b5710 Get rid of overloaded functions in uRenderUtils
unc0rr
parents: 6992
diff changeset
   301
    RenderStringTexLim:= Surface2Tex(finalSurface, false);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   302
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   303
    SDL_FreeSurface(finalSurface);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   304
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   305
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   306
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   307
function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   308
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   309
    finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   310
    rect: TSDL_Rect;
10040
koda
parents: 10015
diff changeset
   311
    chars: set of char = [#9,' ',';',':','?','!',','];
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   312
    substr: shortstring;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   313
    edge, corner, tail: TSPrite;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   314
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7546
diff changeset
   315
      case SpeechType of
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   316
        1: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   317
        edge:= sprSpeechEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   318
        corner:= sprSpeechCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   319
        tail:= sprSpeechTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   320
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   321
        2: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   322
        edge:= sprThoughtEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   323
        corner:= sprThoughtCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   324
        tail:= sprThoughtTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   325
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   326
        3: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   327
        edge:= sprShoutEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   328
        corner:= sprShoutCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   329
        tail:= sprShoutTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   330
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   331
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   332
    edgeHeight:= SpritesData[edge].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   333
    edgeWidth:= SpritesData[edge].Width;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   334
    cornerWidth:= SpritesData[corner].Width;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   335
    cornerHeight:= SpritesData[corner].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   336
    // This one screws up WrapText
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   337
    //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...';
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   338
    // This one does not
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   339
    //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... ';
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   340
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   341
    numLines:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   342
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   343
    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
   344
        s:= '...';
10104
cb0b750bd8a3 yo dawg, I herd you like PChar...
sheepluva
parents: 10040
diff changeset
   345
    font:= CheckCJKFont(Str2PChar(s), font);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   346
    w:= 0; h:= 0; // avoid compiler hints
6286
835392304f81 and while we are giving SDLh.pas all this love, let's fix the signature of one SDL_ttf calls
koda
parents: 4976
diff changeset
   347
    TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(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
   348
    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
   349
        w:= 8;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   350
    j:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   351
    if (length(s) > 20) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   352
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   353
        w:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   354
        i:= round(Sqrt(length(s)) * 2);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   355
        s:= WrapText(s, #1, chars, i);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   356
        pos:= 1; prevpos:= 0; line:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   357
    // Find the longest line for the purposes of centring the text.  Font dependant.
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   358
        while pos <= length(s) do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   359
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   360
            if (s[pos] = #1) or (pos = length(s)) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   361
                begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   362
                inc(numlines);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   363
                if s[pos] <> #1 then inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   364
                while s[prevpos+1] = ' ' do inc(prevpos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   365
                substr:= copy(s, prevpos+1, pos-prevpos-1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   366
                i:= 0; j:= 0;
6286
835392304f81 and while we are giving SDLh.pas all this love, let's fix the signature of one SDL_ttf calls
koda
parents: 4976
diff changeset
   367
                TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   368
                if i > w then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   369
                    w:= i;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   370
                prevpos:= pos;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   371
                end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   372
            inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   373
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   374
        end
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   375
    else numLines := 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   376
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   377
    textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   378
    textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   379
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   380
    textHeight:=max(textHeight,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   381
    //textWidth:=max(textWidth,SpritesData[tail].Width);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   382
    rect.x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   383
    rect.y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   384
    rect.w:= textWidth + (cornerWidth * 2);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   385
    rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   386
    //s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   387
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   388
    finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   389
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   390
    TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   391
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   392
    //////////////////////////////// CORNERS ///////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   393
    copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   394
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   395
    flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips?
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   396
    x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   397
    y:= textHeight + cornerHeight -1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   398
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   399
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   400
    flipSurface(SpritesData[corner].Surface, false);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   401
    x:= rect.w-cornerWidth-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   402
    y:= textHeight + cornerHeight -1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   403
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   404
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   405
    flipSurface(SpritesData[corner].Surface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   406
    x:= rect.w-cornerWidth-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   407
    y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   408
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   409
    flipSurface(SpritesData[corner].Surface, false); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   410
    //////////////////////////////// END CORNERS ///////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   411
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   412
    //////////////////////////////// EDGES //////////////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   413
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   414
    y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   415
    while x < rect.w-cornerWidth-1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   416
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   417
        copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   418
        inc(x,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   419
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   420
    flipSurface(SpritesData[edge].Surface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   421
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   422
    y:= textHeight + cornerHeight*2 - edgeHeight-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   423
    while x < rect.w-cornerWidth-1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   424
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   425
        copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   426
        inc(x,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   427
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   428
    flipSurface(SpritesData[edge].Surface, true); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   429
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   430
    rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   431
    x:= rect.w - edgeHeight - 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   432
    y:= cornerHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   433
    //// initially was going to rotate in place, but the SDL spec claims width/height are read only
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   434
    copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   435
    while y < textHeight + cornerHeight do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   436
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   437
        copyToXY(rotatedEdge, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   438
        inc(y,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   439
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   440
    flipSurface(rotatedEdge, false); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   441
    x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   442
    y:= cornerHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   443
    while y < textHeight + cornerHeight do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   444
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   445
        copyToXY(rotatedEdge, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   446
        inc(y,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   447
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   448
    //////////////////////////////// END EDGES //////////////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   449
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   450
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   451
    y:= textHeight + cornerHeight * 2 - edgeHeight - 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   452
    copyToXY(SpritesData[tail].Surface, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   453
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   454
    rect.x:= edgeHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   455
    rect.y:= edgeHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   456
    rect.w:= rect.w - edgeHeight * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   457
    rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   458
    i:= rect.w;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   459
    j:= rect.h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   460
    SDL_FillRect(finalSurface, @rect, cWhiteColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   461
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   462
    pos:= 1; prevpos:= 0; line:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   463
    while pos <= length(s) do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   464
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   465
        if (s[pos] = #1) or (pos = length(s)) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   466
            begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   467
            if s[pos] <> #1 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   468
                inc(pos);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   469
            while s[prevpos+1] = ' 'do
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   470
                inc(prevpos);
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   471
            substr:= copy(s, prevpos+1, pos-prevpos-1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   472
            if Length(substr) <> 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   473
                begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   474
                tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   475
                rect.x:= edgeHeight + 1 + ((i - w) div 2);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   476
                // trying to more evenly position the text, vertically
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   477
                rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   478
                SDLTry(tmpsurf <> nil, true);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   479
                SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   480
                SDL_FreeSurface(tmpsurf);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   481
                inc(line);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   482
                prevpos:= pos;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   483
                end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6286
diff changeset
   484
                end;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   485
        inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   486
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   487
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   488
    RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   489
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   490
    SDL_FreeSurface(rotatedEdge);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   491
    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
   492
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   493
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   494
4611
445d382cd401 A very very basic snow implementation
nemo
parents: 4404
diff changeset
   495
end.