hedgewars/uRenderUtils.pas
author Xeli
Fri, 26 Aug 2011 18:20:18 +0200
branchhedgeroid
changeset 5659 20eb5765a5d0
parent 4976 088d40d8aba2
child 6286 835392304f81
permissions -rw-r--r--
version name and api changed for Market version ss: Enter commit message. Lines beginning with 'HG:' are removed.
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
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
     3
 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
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
088d40d8aba2 Happy 2011 :)
koda
parents: 4611
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    27
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    28
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    29
function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    30
function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    31
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    32
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    33
implementation
4404
6bae4e9461aa Remove some more circular dependencies
unc0rr
parents: 4403
diff changeset
    34
uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug;
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    35
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    36
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    37
var r: TSDL_Rect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    38
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    39
    r:= rect^;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    40
    if Clear then SDL_FillRect(Surface, @r, 0);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    41
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    42
    BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    43
    FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    44
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    45
    r.y:= rect^.y + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    46
    r.h:= rect^.h - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    47
    SDL_FillRect(Surface, @r, BorderColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    48
    r.x:= rect^.x + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    49
    r.w:= rect^.w - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    50
    r.y:= rect^.y;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    51
    r.h:= rect^.h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    52
    SDL_FillRect(Surface, @r, BorderColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    53
    r.x:= rect^.x + 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    54
    r.y:= rect^.y + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    55
    r.w:= rect^.w - 4;
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, FillColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    58
    r.x:= rect^.x + 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    59
    r.y:= rect^.y + 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    60
    r.w:= rect^.w - 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    61
    r.h:= rect^.h - 4;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    62
    SDL_FillRect(Surface, @r, FillColor)
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    63
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    64
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    65
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    66
var w, h: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    67
    tmpsurf: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    68
    clr: TSDL_Color;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    69
    finalRect: TSDL_Rect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    70
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    71
    TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    72
    finalRect.x:= X;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    73
    finalRect.y:= Y;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    74
    finalRect.w:= w + FontBorder * 2 + 4;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    75
    finalRect.h:= h + FontBorder * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    76
    DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    77
    clr.r:= (Color shr 16) and $FF;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    78
    clr.g:= (Color shr 8) and $FF;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    79
    clr.b:= Color and $FF;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    80
    tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    81
    finalRect.x:= X + FontBorder + 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    82
    finalRect.y:= Y + FontBorder;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    83
    SDLTry(tmpsurf <> nil, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    84
    SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    85
    SDL_FreeSurface(tmpsurf);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    86
    finalRect.x:= X;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    87
    finalRect.y:= Y;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    88
    finalRect.w:= w + FontBorder * 2 + 4;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    89
    finalRect.h:= h + FontBorder * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    90
    WriteInRoundRect:= finalRect;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    91
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    92
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    93
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    94
var y, x, i, j: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    95
    tmpPixel: Longword;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    96
    pixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    97
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    98
    TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
    99
    pixels:= Surface^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   100
    if Vertical then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   101
    for y := 0 to (Surface^.h div 2) - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   102
        for x := 0 to Surface^.w - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   103
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   104
            i:= y * Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   105
            j:= (Surface^.h - y - 1) * Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   106
            tmpPixel:= pixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   107
            pixels^[i]:= pixels^[j];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   108
            pixels^[j]:= tmpPixel;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   109
            end
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   110
    else
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   111
    for x := 0 to (Surface^.w div 2) - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   112
        for y := 0 to Surface^.h -1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   113
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   114
            i:= y*Surface^.w + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   115
            j:= y*Surface^.w + (Surface^.w - x - 1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   116
            tmpPixel:= pixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   117
            pixels^[i]:= pixels^[j];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   118
            pixels^[j]:= tmpPixel;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   119
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   120
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   121
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   122
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   123
var srcX, srcY, i, j, maxDest: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   124
    srcPixels, destPixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   125
    r0, g0, b0, a0, r1, g1, b1, a1: Byte;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   126
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   127
    maxDest:= (dest^.pitch div 4) * dest^.h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   128
    srcPixels:= src^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   129
    destPixels:= dest^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   130
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   131
    for srcX:= 0 to src^.w - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   132
    for srcY:= 0 to src^.h - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   133
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   134
        i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   135
        j:= srcY * (src^.pitch div 4) + srcX;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   136
        if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   137
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   138
            SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   139
            SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   140
            r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   141
            g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   142
            b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   143
            a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   144
            destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   145
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   146
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   147
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   148
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   149
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
   150
var y, x, i, j: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   151
    srcPixels, destPixels: PLongWordArray;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   152
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   153
    TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   154
    TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   155
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   156
    srcPixels:= src^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   157
    destPixels:= dest^.pixels;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   158
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   159
    j:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   160
    for x := 0 to src^.w - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   161
        for y := 0 to src^.h - 1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   162
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   163
            i:= (src^.h - 1 - y) * (src^.pitch div 4) + x;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   164
            destPixels^[j]:= srcPixels^[i];
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   165
            inc(j)
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   166
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   167
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   168
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   169
function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   170
var w, h: LongInt;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   171
    finalSurface: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   172
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   173
    if length(s) = 0 then s:= ' ';
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   174
    font:= CheckCJKFont(s, font);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   175
    w:= 0; h:= 0; // avoid compiler hints
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   176
    TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   177
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   178
    finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   179
            32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   180
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   181
    TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   182
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   183
    WriteInRoundRect(finalSurface, 0, 0, Color, font, s);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   184
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   185
    TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   186
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   187
    RenderStringTex:= Surface2Tex(finalSurface, false);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   188
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   189
    SDL_FreeSurface(finalSurface);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   190
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   191
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   192
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   193
function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   194
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
   195
    finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   196
    rect: TSDL_Rect;
4611
445d382cd401 A very very basic snow implementation
nemo
parents: 4404
diff changeset
   197
    chars: set of char = [#9,' ',';',':','?','!',','];
4380
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   198
    substr: shortstring;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   199
    edge, corner, tail: TSPrite;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   200
begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   201
    case SpeechType of
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   202
        1: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   203
        edge:= sprSpeechEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   204
        corner:= sprSpeechCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   205
        tail:= sprSpeechTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   206
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   207
        2: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   208
        edge:= sprThoughtEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   209
        corner:= sprThoughtCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   210
        tail:= sprThoughtTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   211
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   212
        3: begin;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   213
        edge:= sprShoutEdge;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   214
        corner:= sprShoutCorner;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   215
        tail:= sprShoutTail;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   216
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   217
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   218
    edgeHeight:= SpritesData[edge].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   219
    edgeWidth:= SpritesData[edge].Width;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   220
    cornerWidth:= SpritesData[corner].Width;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   221
    cornerHeight:= SpritesData[corner].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   222
    // This one screws up WrapText
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   223
    //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
   224
    // This one does not
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   225
    //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
   226
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   227
    numLines:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   228
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   229
    if length(s) = 0 then s:= '...';
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   230
    font:= CheckCJKFont(s, font);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   231
    w:= 0; h:= 0; // avoid compiler hints
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   232
    TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   233
    if w<8 then w:= 8;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   234
    j:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   235
    if (length(s) > 20) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   236
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   237
        w:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   238
        i:= round(Sqrt(length(s)) * 2);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   239
        s:= WrapText(s, #1, chars, i);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   240
        pos:= 1; prevpos:= 0; line:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   241
    // Find the longest line for the purposes of centring the text.  Font dependant.
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   242
        while pos <= length(s) do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   243
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   244
            if (s[pos] = #1) or (pos = length(s)) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   245
                begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   246
                inc(numlines);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   247
                if s[pos] <> #1 then inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   248
                while s[prevpos+1] = ' ' do inc(prevpos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   249
                substr:= copy(s, prevpos+1, pos-prevpos-1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   250
                i:= 0; j:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   251
                TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   252
                if i > w then w:= i;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   253
                prevpos:= pos;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   254
                end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   255
            inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   256
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   257
        end
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   258
    else numLines := 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   259
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   260
    textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   261
    textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   262
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   263
    textHeight:=max(textHeight,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   264
    //textWidth:=max(textWidth,SpritesData[tail].Width);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   265
    rect.x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   266
    rect.y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   267
    rect.w:= textWidth + (cornerWidth * 2);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   268
    rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   269
    //s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   270
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   271
    finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   272
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   273
    TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   274
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   275
    //////////////////////////////// CORNERS ///////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   276
    copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   277
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   278
    flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips?
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   279
    x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   280
    y:= textHeight + cornerHeight -1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   281
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   282
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   283
    flipSurface(SpritesData[corner].Surface, false);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   284
    x:= rect.w-cornerWidth-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   285
    y:= textHeight + cornerHeight -1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   286
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   287
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   288
    flipSurface(SpritesData[corner].Surface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   289
    x:= rect.w-cornerWidth-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   290
    y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   291
    copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   292
    flipSurface(SpritesData[corner].Surface, false); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   293
    //////////////////////////////// END CORNERS ///////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   294
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   295
    //////////////////////////////// EDGES //////////////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   296
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   297
    y:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   298
    while x < rect.w-cornerWidth-1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   299
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   300
        copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   301
        inc(x,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   302
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   303
    flipSurface(SpritesData[edge].Surface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   304
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   305
    y:= textHeight + cornerHeight*2 - edgeHeight-1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   306
    while x < rect.w-cornerWidth-1 do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   307
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   308
        copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   309
        inc(x,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   310
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   311
    flipSurface(SpritesData[edge].Surface, true); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   312
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   313
    rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   314
    x:= rect.w - edgeHeight - 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   315
    y:= cornerHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   316
    //// initially was going to rotate in place, but the SDL spec claims width/height are read only
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   317
    copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   318
    while y < textHeight + cornerHeight do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   319
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   320
        copyToXY(rotatedEdge, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   321
        inc(y,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   322
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   323
    flipSurface(rotatedEdge, false); // restore original position
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   324
    x:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   325
    y:= cornerHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   326
    while y < textHeight + cornerHeight do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   327
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   328
        copyToXY(rotatedEdge, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   329
        inc(y,edgeWidth);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   330
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   331
    //////////////////////////////// END EDGES //////////////////////////////////////
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   332
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   333
    x:= cornerWidth;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   334
    y:= textHeight + cornerHeight * 2 - edgeHeight - 1;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   335
    copyToXY(SpritesData[tail].Surface, finalSurface, x, y);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   336
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   337
    rect.x:= edgeHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   338
    rect.y:= edgeHeight;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   339
    rect.w:= rect.w - edgeHeight * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   340
    rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   341
    i:= rect.w;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   342
    j:= rect.h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   343
    SDL_FillRect(finalSurface, @rect, cWhiteColor);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   344
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   345
    pos:= 1; prevpos:= 0; line:= 0;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   346
    while pos <= length(s) do
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   347
        begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   348
        if (s[pos] = #1) or (pos = length(s)) then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   349
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   350
            if s[pos] <> #1 then inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   351
            while s[prevpos+1] = ' 'do inc(prevpos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   352
            substr:= copy(s, prevpos+1, pos-prevpos-1);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   353
            if Length(substr) <> 0 then
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   354
            begin
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   355
            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   356
            rect.x:= edgeHeight + 1 + ((i - w) div 2);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   357
            // trying to more evenly position the text, vertically
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   358
            rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   359
            SDLTry(tmpsurf <> nil, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   360
            SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   361
            SDL_FreeSurface(tmpsurf);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   362
            inc(line);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   363
            prevpos:= pos;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   364
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   365
            end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   366
        inc(pos);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   367
        end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   368
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   369
    RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   370
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   371
    SDL_FreeSurface(rotatedEdge);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   372
    SDL_FreeSurface(finalSurface);
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   373
end;
b78638b36b89 Introduce uRenderUtils
unC0Rr
parents:
diff changeset
   374
4611
445d382cd401 A very very basic snow implementation
nemo
parents: 4404
diff changeset
   375
end.