hedgewars/uRenderUtils.pas
changeset 6986 409dd3851309
parent 6982 8d41d22a291d
child 6992 b8f3d8991e92
equal deleted inserted replaced
6985:caa41003f42c 6986:409dd3851309
    22 
    22 
    23 interface
    23 interface
    24 uses SDLh, uTypes;
    24 uses SDLh, uTypes;
    25 
    25 
    26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
    26 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
       
    27 
    27 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    28 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    28 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
    29 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline;
    29 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
    30 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
    30 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt = 0);
    31 
       
    32 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline;
       
    33 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt);
    31 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte);
    34 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte);
    32 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture;
    35 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
       
    36 
       
    37 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
       
    38 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
    33 function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
    39 function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
    34 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
       
    35 
    40 
    36 implementation
    41 implementation
    37 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug;
    42 uses uUtils, uVariables, uConsts, uTextures, sysutils, uDebug;
    38 
    43 
    39 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    44 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    63     r.y:= rect^.y + 2;
    68     r.y:= rect^.y + 2;
    64     r.w:= rect^.w - 2;
    69     r.w:= rect^.w - 2;
    65     r.h:= rect^.h - 4;
    70     r.h:= rect^.h - 4;
    66     SDL_FillRect(Surface, @r, FillColor)
    71     SDL_FillRect(Surface, @r, FillColor)
    67 end;
    72 end;
    68 
    73 (*
    69 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord = 0): TSDL_Rect;
    74 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
       
    75 begin
       
    76     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
       
    77 end;*)
       
    78 
       
    79 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord): TSDL_Rect;
    70 var w, h: LongInt;
    80 var w, h: LongInt;
    71     tmpsurf: PSDL_Surface;
    81     tmpsurf: PSDL_Surface;
    72     clr: TSDL_Color;
    82     clr: TSDL_Color;
    73     finalRect, textRect: TSDL_Rect;
    83     finalRect, textRect: TSDL_Rect;
    74 begin
    84 begin
   126             pixels^[i]:= pixels^[j];
   136             pixels^[i]:= pixels^[j];
   127             pixels^[j]:= tmpPixel;
   137             pixels^[j]:= tmpPixel;
   128             end;
   138             end;
   129 end;
   139 end;
   130 
   140 
   131 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt);
   141 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline;
   132 begin
   142 begin
   133     copyToXY(src, dest, 0,0,src^.w, src^.h, destX, destY);
   143     copyToXY(src, dest, 0, 0, src^.w, src^.h, destX, destY);
   134 end;
   144 end;
   135 
   145 
   136 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
   146 procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
   137 var i, j, maxDest, maxSrc, iX, iY: LongInt;
   147 var i, j, maxDest, maxSrc, iX, iY: LongInt;
   138     srcPixels, destPixels: PLongWordArray;
   148     srcPixels, destPixels: PLongWordArray;
   157             b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255;
   167             b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255;
   158             a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255;
   168             a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255;
   159             destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
   169             destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
   160             end;
   170             end;
   161         end;
   171         end;
       
   172 end;
       
   173 
       
   174 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline;
       
   175 begin
       
   176     DrawSprite2Surf(sprite, dest, x, y, 0);
   162 end;
   177 end;
   163 
   178 
   164 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt);
   179 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y,frame: LongInt);
   165 var numFramesFirstCol, row, col: LongInt;
   180 var numFramesFirstCol, row, col: LongInt;
   166 begin
   181 begin
   232             destPixels^[j]:= srcPixels^[i];
   247             destPixels^[j]:= srcPixels^[i];
   233             inc(j)
   248             inc(j)
   234             end;
   249             end;
   235 end;
   250 end;
   236 
   251 
   237 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture;
   252 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
       
   253 begin
       
   254     RenderStringTex:= RenderStringTex(s, Color, font, 0);
       
   255 end;
       
   256 
       
   257 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
   238 var w, h: LongInt;
   258 var w, h: LongInt;
   239     finalSurface: PSDL_Surface;
   259     finalSurface: PSDL_Surface;
   240 begin
   260 begin
   241     if length(s) = 0 then s:= ' ';
   261     if length(s) = 0 then s:= ' ';
   242     font:= CheckCJKFont(s, font);
   262     font:= CheckCJKFont(s, font);