hedgewars/uRender.pas
branchhedgeroid
changeset 7855 ddcdedd3330b
parent 7069 bcf9d8e64e92
child 7080 dbf43c07a507
child 8026 4a4f21070479
child 8145 6408c0ba4ba1
equal deleted inserted replaced
6350:41b0a9955c47 7855:ddcdedd3330b
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    22 
    22 
    23 interface
    23 interface
    24 
    24 
    25 uses SDLh, uTypes, GLunit, uConsts;
    25 uses SDLh, uTypes, GLunit, uConsts;
    26 
    26 
    27 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    27 procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
    28 procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    28 procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    29 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    29 procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    30 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
    30 procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    31 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    31 procedure DrawSpriteRotated     (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
    32 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    32 procedure DrawSpriteRotatedF    (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
    33 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0);
    33 
    34 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
    34 procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
    35 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
    35 procedure DrawTexture           (X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
    36 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
    36 procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    37 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
    37 procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    38 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    38 procedure DrawTextureCentered   (X, Top: LongInt; Source: PTexture);
    39 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    39 procedure DrawTextureF          (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
    40 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    40 procedure DrawTextureRotated    (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    41 procedure DrawFillRect(r: TSDL_Rect);
    41 procedure DrawTextureRotatedF   (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
    42 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
    42 
    43 procedure DrawCircle(X, Y, Radius, Width: LongInt);
    43 procedure DrawCircle            (X, Y, Radius, Width: LongInt);
    44 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    44 procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
    45 procedure Tint(r, g, b, a: Byte); inline;
    45 
    46 procedure Tint(c: Longword); inline;
    46 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    47 
    47 procedure DrawFillRect          (r: TSDL_Rect);
    48 var
    48 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    49     HHTexture: PTexture;
    49 procedure DrawScreenWidget      (widget: POnScreenWidget);
       
    50 
       
    51 procedure Tint                  (r, g, b, a: Byte); inline;
       
    52 procedure Tint                  (c: Longword); inline;
       
    53 
    50 
    54 
    51 implementation
    55 implementation
    52 uses uVariables;
    56 uses uVariables;
    53 
    57 
       
    58 var LastTint: LongWord = 0;
       
    59 
    54 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    60 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
    55 begin
    61 begin
    56 r.y:= r.y + Height * Position;
    62 r.y:= r.y + Height * Position;
    57 r.h:= Height;
    63 r.h:= Height;
    58 DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
    64 DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
    59 end;
    65 end;
    60 
    66 
    61 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    67 procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    62 begin
    68 begin
    63 DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
    69 DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
    64 end;
    70 end;
    65 
    71 
    66 procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    72 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    67 var rr: TSDL_Rect;
    73 var rr: TSDL_Rect;
    68     _l, _r, _t, _b: real;
    74     _l, _r, _t, _b: real;
    69     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
    75     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
    70 begin
    76 begin
    71 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit;
    77 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
       
    78     exit;
    72 
    79 
    73 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
    80 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
    74 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
    81 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
    75     exit;
    82     exit;
    76 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
    83 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
   104 TextureBuffer[2].X:= _r;
   111 TextureBuffer[2].X:= _r;
   105 TextureBuffer[2].Y:= _b;
   112 TextureBuffer[2].Y:= _b;
   106 TextureBuffer[3].X:= _l;
   113 TextureBuffer[3].X:= _l;
   107 TextureBuffer[3].Y:= _b;
   114 TextureBuffer[3].Y:= _b;
   108 
   115 
   109 
       
   110 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   116 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   111 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   117 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   112 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   118 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   113 end;
   119 end;
   114 
   120 
       
   121 procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
       
   122 begin
       
   123     DrawTexture(X, Y, Texture, 1.0);
       
   124 end;
   115 
   125 
   116 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   126 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   117 begin
   127 begin
   118 
   128 
   119 glPushMatrix;
   129 glPushMatrix;
   129 glPopMatrix
   139 glPopMatrix
   130 end;
   140 end;
   131 
   141 
   132 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   142 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   133 begin
   143 begin
   134     DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   144     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   135 end;
   145 end;
   136 
   146 
   137 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
   147 procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
   138 var ft, fb, fl, fr: GLfloat;
   148 var ft, fb, fl, fr: GLfloat;
   139     hw, nx, ny: LongInt;
   149     hw, nx, ny: LongInt;
   140     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   150     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
   141 begin
   151 begin
   142 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   152 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   192 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   202 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   193 
   203 
   194 glPopMatrix
   204 glPopMatrix
   195 end;
   205 end;
   196 
   206 
   197 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   207 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   198 begin
   208 begin
   199     DrawRotatedTex(SpritesData[Sprite].Texture,
   209     DrawTextureRotated(SpritesData[Sprite].Texture,
   200         SpritesData[Sprite].Width,
   210         SpritesData[Sprite].Width,
   201         SpritesData[Sprite].Height,
   211         SpritesData[Sprite].Height,
   202         X, Y, Dir, Angle)
   212         X, Y, Dir, Angle)
   203 end;
   213 end;
   204 
   214 
   205 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   215 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   206 begin
   216 begin
   207 glPushMatrix;
   217 glPushMatrix;
   208 glTranslatef(X, Y, 0);
   218 glTranslatef(X, Y, 0);
   209 
   219 
   210 if Dir < 0 then
   220 if Dir < 0 then
   211    glRotatef(Angle, 0, 0, -1)
   221     glRotatef(Angle, 0, 0, -1)
   212 else
   222 else
   213    glRotatef(Angle, 0, 0,  1);
   223     glRotatef(Angle, 0, 0,  1);
   214 if Dir < 0 then glScalef(-1.0, 1.0, 1.0);
   224 if Dir < 0 then
       
   225     glScalef(-1.0, 1.0, 1.0);
   215 
   226 
   216 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   227 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   217 
   228 
   218 glPopMatrix
   229 glPopMatrix
   219 end;
   230 end;
   220 
   231 
   221 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   232 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   222 var VertexBuffer: array [0..3] of TVertex2f;
   233 var VertexBuffer: array [0..3] of TVertex2f;
   223 begin
   234 begin
   224 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   235 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   225 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   236 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   226     exit;
   237     exit;
   229 
   240 
   230 glPushMatrix;
   241 glPushMatrix;
   231 glTranslatef(X, Y, 0);
   242 glTranslatef(X, Y, 0);
   232 
   243 
   233 if Dir < 0 then
   244 if Dir < 0 then
   234    begin
   245     begin
   235    hw:= - hw;
   246     hw:= - hw;
   236    glRotatef(Angle, 0, 0, -1);
   247     glRotatef(Angle, 0, 0, -1);
   237    end else
   248     end
   238    glRotatef(Angle, 0, 0,  1);
   249 else
   239 
   250     glRotatef(Angle, 0, 0,  1);
   240 
   251 
   241 glBindTexture(GL_TEXTURE_2D, Tex^.id);
   252 
       
   253 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   242 
   254 
   243 VertexBuffer[0].X:= -hw;
   255 VertexBuffer[0].X:= -hw;
   244 VertexBuffer[0].Y:= -hh;
   256 VertexBuffer[0].Y:= -hh;
   245 VertexBuffer[1].X:= hw;
   257 VertexBuffer[1].X:= hw;
   246 VertexBuffer[1].Y:= -hh;
   258 VertexBuffer[1].Y:= -hh;
   248 VertexBuffer[2].Y:= hh;
   260 VertexBuffer[2].Y:= hh;
   249 VertexBuffer[3].X:= -hw;
   261 VertexBuffer[3].X:= -hw;
   250 VertexBuffer[3].Y:= hh;
   262 VertexBuffer[3].Y:= hh;
   251 
   263 
   252 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   264 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   253 glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb);
   265 glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
   254 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   266 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   255 
   267 
   256 glPopMatrix
   268 glPopMatrix
   257 end;
   269 end;
   258 
   270 
   259 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
   271 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
   260 var row, col, numFramesFirstCol: LongInt;
   272 var row, col, numFramesFirstCol: LongInt;
   261 begin
   273 begin
   262 if SpritesData[Sprite].imageHeight = 0 then exit;
   274     if SpritesData[Sprite].imageHeight = 0 then
   263 numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
   275         exit;
   264 row:= Frame mod numFramesFirstCol;
   276     numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
   265 col:= Frame div numFramesFirstCol;
   277     row:= Frame mod numFramesFirstCol;
   266 DrawSprite2 (Sprite, X, Y, col, row);
   278     col:= Frame div numFramesFirstCol;
       
   279     DrawSprite(Sprite, X, Y, col, row);
       
   280 end;
       
   281 
       
   282 procedure DrawSprite(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
       
   283 var r: TSDL_Rect;
       
   284 begin
       
   285     r.x:= FrameX * SpritesData[Sprite].Width;
       
   286     r.w:= SpritesData[Sprite].Width;
       
   287     r.y:= FrameY * SpritesData[Sprite].Height;
       
   288     r.h:= SpritesData[Sprite].Height;
       
   289     DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
   267 end;
   290 end;
   268 
   291 
   269 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
   292 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
   270 var r: TSDL_Rect;
   293 var r: TSDL_Rect;
   271 begin
   294 begin
   285     r.w:= RightX - X + 1;
   308     r.w:= RightX - X + 1;
   286 
   309 
   287 dec(r.h, r.y);
   310 dec(r.h, r.y);
   288 dec(r.w, r.x);
   311 dec(r.w, r.x);
   289 
   312 
   290 DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
   313 DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
   291 end;
   314 end;
   292 
   315 
   293 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
   316 procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture);
   294 var r: TSDL_Rect;
       
   295 begin
       
   296     r.x:= FrameX * SpritesData[Sprite].Width;
       
   297     r.w:= SpritesData[Sprite].Width;
       
   298     r.y:= FrameY * SpritesData[Sprite].Height;
       
   299     r.h:= SpritesData[Sprite].Height;
       
   300     DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
       
   301 end;
       
   302 
       
   303 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
       
   304 var scale: GLfloat;
   317 var scale: GLfloat;
   305 begin
   318 begin
   306     if (Source^.w + 20) > cScreenWidth then
   319     if (Source^.w + 20) > cScreenWidth then
   307         scale:= cScreenWidth / (Source^.w + 20)
   320         scale:= cScreenWidth / (Source^.w + 20)
   308     else
   321     else
   393 end;
   406 end;
   394 
   407 
   395 
   408 
   396 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   409 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   397 const VertexBuffer: array [0..3] of TVertex2f = (
   410 const VertexBuffer: array [0..3] of TVertex2f = (
   398         (x: -16; y: -16),
   411         (X: -16; Y: -16),
   399         (x:  16; y: -16),
   412         (X:  16; Y: -16),
   400         (x:  16; y:  16),
   413         (X:  16; Y:  16),
   401         (x: -16; y:  16));
   414         (X: -16; Y:  16));
   402 var l, r, t, b: real;
   415 var l, r, t, b: real;
   403     TextureBuffer: array [0..3] of TVertex2f;
   416     TextureBuffer: array [0..3] of TVertex2f;
   404 begin
   417 begin
   405     // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   418     // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   406     if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
   419     if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
   410 
   423 
   411     t:= Pos * 32 / HHTexture^.h;
   424     t:= Pos * 32 / HHTexture^.h;
   412     b:= (Pos + 1) * 32 / HHTexture^.h;
   425     b:= (Pos + 1) * 32 / HHTexture^.h;
   413 
   426 
   414     if Dir = -1 then
   427     if Dir = -1 then
   415     begin
   428         begin
   416     l:= (Step + 1) * 32 / HHTexture^.w;
   429         l:= (Step + 1) * 32 / HHTexture^.w;
   417     r:= Step * 32 / HHTexture^.w
   430         r:= Step * 32 / HHTexture^.w
   418     end else
   431         end
   419     begin
   432     else
   420     l:= Step * 32 / HHTexture^.w;
   433         begin
   421     r:= (Step + 1) * 32 / HHTexture^.w
   434         l:= Step * 32 / HHTexture^.w;
       
   435         r:= (Step + 1) * 32 / HHTexture^.w
   422     end;
   436     end;
   423 
   437 
   424 
   438 
   425     glPushMatrix();
   439     glPushMatrix();
   426     glTranslatef(X, Y, 0);
   440     glTranslatef(X, Y, 0);
   442     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   456     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   443 
   457 
   444     glPopMatrix
   458     glPopMatrix
   445 end;
   459 end;
   446 
   460 
       
   461 procedure DrawScreenWidget(widget: POnScreenWidget);
       
   462 {$IFDEF USE_TOUCH_INTERFACE}
       
   463 var alpha: byte = $FF;
       
   464 begin
       
   465 with widget^ do
       
   466     begin
       
   467     if (fadeAnimStart <> 0) then
       
   468         begin
       
   469         if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
       
   470             fadeAnimStart:= 0
       
   471         else
       
   472             if show then 
       
   473                 alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
       
   474             else 
       
   475                 alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
       
   476         end;
       
   477 
       
   478     with moveAnim do
       
   479         if animate then
       
   480             if RealTicks > (startTime + MOVE_ANIM_TIME) then
       
   481                 begin
       
   482                 startTime:= 0;
       
   483                 animate:= false;
       
   484                 frame.x:= target.x;
       
   485                 frame.y:= target.y;
       
   486                 active.x:= active.x + (target.x - source.x);
       
   487                 active.y:= active.y + (target.y - source.y);
       
   488                 end
       
   489             else
       
   490                 begin
       
   491                 frame.x:= source.x + Round((target.x - source.x) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
       
   492                 frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
       
   493                 end;
       
   494 
       
   495     if show or (fadeAnimStart <> 0) then
       
   496         begin
       
   497         Tint($FF, $FF, $FF, alpha);
       
   498         DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
       
   499         Tint($FF, $FF, $FF, $FF);
       
   500         end;
       
   501     end;
       
   502 {$ELSE}
       
   503 begin
       
   504 widget:= widget; // avoid hint
       
   505 {$ENDIF}
       
   506 end;
   447 
   507 
   448 procedure Tint(r, g, b, a: Byte); inline;
   508 procedure Tint(r, g, b, a: Byte); inline;
   449 const 
   509 var nc, tw: Longword;
   450     lastTint: Longword = 0;
   510 begin
   451 var 
   511     nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
   452     nc, tw: Longword;
   512 
   453 begin
   513     if nc = lastTint then
   454 nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
   514         exit;
   455 
   515 
   456 if nc = lastTint then
   516     if GrayScale then
   457     exit;
   517         begin
   458 
   518         tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
   459 if cGrayScale then
   519         if tw > 255 then
   460     begin
   520             tw:= 255;
   461     tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
   521         r:= tw;
   462     if tw > 255 then tw:= 255;
   522         g:= tw;
   463     r:= tw;
   523         b:= tw
   464     g:= tw;
   524         end;
   465     b:= tw
   525 
   466     end;
   526     glColor4ub(r, g, b, a);
   467 
   527     lastTint:= nc;
   468 glColor4ub(r, g, b, a);
       
   469 lastTint:= nc;
       
   470 end;
   528 end;
   471 
   529 
   472 procedure Tint(c: Longword); inline;
   530 procedure Tint(c: Longword); inline;
   473 begin
   531 begin
   474 Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
   532     Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
   475 end;
   533 end;
   476 
   534 
   477 end.
   535 end.