hedgewars/uRenderUtils.pas
changeset 16001 cee831693af1
parent 15987 e8d94f84d294
child 16003 8bb07b0f50ca
--- a/hedgewars/uRenderUtils.pas	Wed Jun 28 23:41:38 2023 +0200
+++ b/hedgewars/uRenderUtils.pas	Mon Jul 24 20:02:18 2023 +0200
@@ -29,6 +29,9 @@
 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); inline;
 procedure copyToXYFromRect(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt);
 
+function GetSurfaceFrameCoordinateX(Surface: PSDL_Surface; Frame, frameWidth, frameHeight: LongInt): LongInt;
+function GetSurfaceFrameCoordinateY(Surface: PSDL_Surface; Frame, frameHeight: LongInt): LongInt;
+
 procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt); inline;
 procedure DrawSpriteFrame2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt);
 procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte);
@@ -78,6 +81,24 @@
     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
 end;*)
 
+function GetSurfaceFrameCoordinateX(Surface: PSDL_Surface; Frame, frameWidth, frameHeight: LongInt): LongInt;
+var nx, ny: LongInt;
+begin
+   nx:= Surface^.w div frameWidth; // number of horizontal frames
+   if nx = 0 then nx:= 1; // one frame is minimum
+   ny:= Surface^.h div frameHeight; // number of vertical frames
+   if ny = 0 then ny:= 1;
+   GetSurfaceFrameCoordinateX:= (Frame div ny) * frameWidth;
+end;
+
+function GetSurfaceFrameCoordinateY(Surface: PSDL_Surface; Frame, frameHeight: LongInt): LongInt;
+var ny: LongInt;
+begin
+   ny:= Surface^.h div frameHeight; // number of vertical frames
+   if ny = 0 then ny:= 1; // one frame is minimum
+   GetSurfaceFrameCoordinateY:= (Frame mod ny) * frameHeight;
+end;
+
 function IsTooDarkToRead(TextColor: LongWord): boolean; inline;
 var clr: TSDL_Color;
 begin