Engine:
authorsmxx
Mon, 15 Feb 2010 14:04:29 +0000
changeset 2811 4cad87e11bf6
parent 2810 3bc9c723731d
child 2812 0a24853de796
Engine: * Reduced alt weapon box's size to 75% * Updated DrawTextureF and DrawRotatedTextureF to support multiple columns as well as custom dimensions
hedgewars/uGears.pas
hedgewars/uStore.pas
--- a/hedgewars/uGears.pas	Mon Feb 15 00:01:21 2010 +0000
+++ b/hedgewars/uGears.pas	Mon Feb 15 14:04:29 2010 +0000
@@ -110,10 +110,7 @@
                                   end;
                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
                 end;
-    ropeIconSurf: PSDL_Surface;
-    ropeIconTex: PTexture;
-    ropeIconIndex: LongInt;
-
+ 
 procedure DeleteGear(Gear: PGear); forward;
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
@@ -817,30 +814,20 @@
 	end
 end;
 
-procedure RenderAltWeapon(Gear: PGear; sx, sy: LongInt);
-var r1, r2: TSDL_Rect;
+procedure DrawAltWeapon(Gear: PGear; sx, sy: LongInt);
 begin
 with PHedgehog(Gear^.Hedgehog)^ do
 	begin
-	if ropeIconIndex <> ord(Ammo^[CurSlot, CurAmmo].AmmoType) then
-		begin
-		if ropeIconTex <> nil then
-			FreeTexture(ropeIconTex);
-		r1.x:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) shr 5) * 32;
-		r1.y:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) mod 32) * 32;
-		r1.w:= 32;
-		r1.h:= 32;
-		r2.x:= 2;
-		r2.y:= 2;
-		r2.w:= 32;
-		r2.h:= 32;
-		SDL_UpperBlit(SpritesData[sprAMAmmos].Surface, @r1, ropeIconSurf, @r2);
-		ropeIconTex:= Surface2Tex(ropeIconSurf, true);
-		ropeIconIndex:= ord(Ammo^[CurSlot, CurAmmo].AmmoType)
-		end;
-	// render the rope weapon icon (if weapon is alt useable)
-	if (ropeIconTex <> nil) and ((Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0) then
-		DrawTexture(sx + 16, sy + 16, ropeIconTex)
+	if not (((Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) and ((Gear^.State and gstAttacked) = 0)) then
+		exit;
+	
+	//r.x:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) shr 5) * 32;
+	//r.y:= ((ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1) mod 32) * 32;
+	//r.w:= 32;
+	//r.h:= 32;
+	DrawTexture(sx + 16, sy + 16, ropeIconTex);
+	//DrawFromRect(sx + 18, sy + 18, @r, SpritesData[sprAMAmmos].Texture);
+	DrawTextureF(SpritesData[sprAMAmmos].Texture, 0.75, sx + 30, sy + 30, ord(Ammo^[CurSlot, CurAmmo].AmmoType) - 1, 1, 32, 32);
 	end;
 end;
 
@@ -1013,10 +1000,10 @@
 						DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + dAngle);
 				with PHedgehog(Gear^.Hedgehog)^ do
 					if (HatTex <> nil) then
-						DrawRotatedTextureF(HatTex, 1.0, -1.0, -6.0, sx, sy, 0, i, 32,
+						DrawRotatedTextureF(HatTex, 1.0, -1.0, -6.0, sx, sy, 0, i, 32, 32,
 							i*DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + hAngle);
 				
-				RenderAltWeapon(Gear, sx, sy);
+				DrawAltWeapon(Gear, sx, sy);
 				defaultPos:= false
 				end;
 			gtBlowTorch: begin
@@ -1209,6 +1196,7 @@
 						hwRound(Gear^.Y) - 8 + WorldDy,
 						0,
 						hwSign(Gear^.dX),
+						32,
 						32);
 		end;
 
@@ -1275,6 +1263,7 @@
 				hwRound(Gear^.Y) - 8 + WorldDy,
 				(RealTicks div 128 + Gear^.Pos) mod 19,
 				hwSign(Gear^.dX),
+				32,
 				32)
 		else
 			DrawTextureF(HatTex,
@@ -1283,6 +1272,7 @@
 				hwRound(Gear^.Y) - 8 + WorldDy,
 				0,
 				hwSign(Gear^.dX)*m,
+				32,
 				32);
 	end;
 if (Gear^.State and gstHHDriven) <> 0 then
@@ -1303,7 +1293,7 @@
 	                   if (CurAmmoGear^.MsgParam and gm_Left) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 2);
 	                   if (CurAmmoGear^.MsgParam and gm_Right) <> 0 then DrawSprite(sprJetpack, sx-32, sy-32, 3);
                        if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex);
-					   RenderAltWeapon(Gear, sx, sy)
+					   DrawAltWeapon(Gear, sx, sy)
                        end;
             end;
         end
@@ -1557,10 +1547,10 @@
         gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1);
      gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle);
          gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0);
-           gtFlame: DrawTextureF(SpritesData[sprFlame].Texture, 1 / (Gear^.Tag mod 3 + 2), hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (GameTicks div 128 + LongWord(Gear^.Tag)) mod 8, 1, 8);
+           gtFlame: DrawTextureF(SpritesData[sprFlame].Texture, 2 / (Gear^.Tag mod 3 + 2), hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, (GameTicks div 128 + LongWord(Gear^.Tag)) mod 8, 1, 16, 16);
        gtParachute: begin
 					DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0);
-					RenderAltWeapon(Gear, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy)
+					DrawAltWeapon(Gear, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy)
 					end;
        gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 0)
                                      else DrawSprite(sprAirplane, hwRound(Gear^.X) - SpritesData[sprAirplane].Width div 2 + WorldDx, hwRound(Gear^.Y) - SpritesData[sprAirplane].Height div 2 + WorldDy, 1);
@@ -2147,7 +2137,6 @@
 end;
 
 procedure init_uGears;
-var r: TSDL_Rect;
 begin
 	CurAmmoGear:= nil;
 	GearsList:= nil;
@@ -2159,22 +2148,11 @@
 	
 	AllInactive:= false;
 	PrvInactive:= false;
-	
-	ropeIconSurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 36, 36, 32, RMask, GMask, BMask, AMask);
-	r.x:= 0;
-	r.y:= 0;
-	r.w:= 36;
-	r.h:= 36;
-	DrawRoundRect(@r, cWhiteColor, cNearBlackColor, ropeIconSurf, true);
 end;
 
 procedure free_uGears;
 begin
 	FreeGearsList();
-	if ropeIconTex <> nil then
-		FreeTexture(ropeIconTex);
-	if ropeIconSurf <> nil then
-		SDL_FreeSurface(ropeIconSurf);
 end;
 
 end.
--- a/hedgewars/uStore.pas	Mon Feb 15 00:01:21 2010 +0000
+++ b/hedgewars/uStore.pas	Mon Feb 15 14:04:29 2010 +0000
@@ -40,6 +40,7 @@
     numsquares : LongInt;
     ProgrTex: PTexture;
     MissionIcons: PSDL_Surface;
+    ropeIconTex: PTexture;
 
 procedure init_uStore;
 procedure free_uStore;
@@ -52,8 +53,8 @@
 procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
 procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture);
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
-procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt);
-procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
+procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
+procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
@@ -180,7 +181,7 @@
 		i: LongInt;
 		r, rr: TSDL_Rect;
 		drY: LongInt;
-		texsurf, flagsurf: PSDL_Surface;
+		texsurf, flagsurf, iconsurf: PSDL_Surface;
 	begin
 	r.x:= 0;
 	r.y:= 0;
@@ -256,7 +257,18 @@
 						end
 					end;
 		end;
-		MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
+	MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
+	iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
+	if iconsurf <> nil then
+		begin
+		r.x:= 0;
+		r.y:= 0;
+		r.w:= 28;
+		r.h:= 28;
+		DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
+		ropeIconTex:= Surface2Tex(iconsurf, false);
+		SDL_FreeSurface(iconsurf)
+		end;
 	end;
 
 	procedure MakeCrossHairs;
@@ -499,60 +511,14 @@
 glPopMatrix
 end;
 
-procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt);
-var ft, fb: GLfloat;
-	hw: LongInt;
-    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
+procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
 begin
-glPushMatrix;
-glTranslatef(X, Y, 0);
-glScalef(Scale, Scale, 1.0);
-
-if Dir < 0 then
-	hw:= - 16
-else
-	hw:= 16;
-
-ft:= Frame / Frames * Texture^.ry;
-fb:= (Frame + 1) / Frames * Texture^.ry;
-
-glBindTexture(GL_TEXTURE_2D, Texture^.id);
-
-VertexBuffer[0].X:= -hw;
-VertexBuffer[0].Y:= -16;
-VertexBuffer[1].X:= hw;
-VertexBuffer[1].Y:= -16;
-VertexBuffer[2].X:= hw;
-VertexBuffer[2].Y:= 16;
-VertexBuffer[3].X:= -hw;
-VertexBuffer[3].Y:= 16;
-
-TextureBuffer[0].X:= 0;
-TextureBuffer[0].Y:= ft;
-TextureBuffer[1].X:= Texture^.rx;
-TextureBuffer[1].Y:= ft;
-TextureBuffer[2].X:= Texture^.rx;
-TextureBuffer[2].Y:= fb;
-TextureBuffer[3].X:= 0;
-TextureBuffer[3].Y:= fb;
-
-glEnableClientState(GL_VERTEX_ARRAY);
-glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
-glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
-glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
-
-glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-glDisableClientState(GL_VERTEX_ARRAY);
-
-
-glPopMatrix
+	DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
 end;
 
-procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real);
-var ft, fb: GLfloat;
-	hw: LongInt;
+procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
+var ft, fb, fl, fr: GLfloat;
+    hw, nx, ny: LongInt;
     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
 begin
 glPushMatrix;
@@ -564,34 +530,41 @@
    glRotatef(Angle, 0, 0,  1);
 
 glTranslatef(Dir*OffsetX, OffsetY, 0);
+glScalef(Scale, Scale, 1);
+
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 if Dir < 0 then
-	hw:= - 16
+	hw:= w div -2
 else
-	hw:= 16;
+	hw:= w div 2;
+
+nx:= round(Texture^.w * Texture^.rx / w);
+ny:= round(Texture^.h * Texture^.ry / h);
 
-ft:= Frame / Frames * Texture^.ry;
-fb:= (Frame + 1) / Frames * Texture^.ry;
+ft:= ((Frame mod ny) / ny);
+fb:= (((Frame mod ny) + 1) / ny);
+fl:= ((Frame div ny) / nx) * Texture^.rx;
+fr:= (((Frame div ny) + 1) / nx);
 
 glBindTexture(GL_TEXTURE_2D, Texture^.id);
 
 VertexBuffer[0].X:= -hw;
-VertexBuffer[0].Y:= -16;
+VertexBuffer[0].Y:= w / -2;
 VertexBuffer[1].X:= hw;
-VertexBuffer[1].Y:= -16;
+VertexBuffer[1].Y:= w / -2;
 VertexBuffer[2].X:= hw;
-VertexBuffer[2].Y:= 16;
+VertexBuffer[2].Y:= w / 2;
 VertexBuffer[3].X:= -hw;
-VertexBuffer[3].Y:= 16;
+VertexBuffer[3].Y:= w / 2;
 
-TextureBuffer[0].X:= 0;
+TextureBuffer[0].X:= fl;
 TextureBuffer[0].Y:= ft;
-TextureBuffer[1].X:= Texture^.rx;
+TextureBuffer[1].X:= fr;
 TextureBuffer[1].Y:= ft;
-TextureBuffer[2].X:= Texture^.rx;
+TextureBuffer[2].X:= fr;
 TextureBuffer[2].Y:= fb;
-TextureBuffer[3].X:= 0;
+TextureBuffer[3].X:= fl;
 TextureBuffer[3].Y:= fb;
 
 glEnableClientState(GL_VERTEX_ARRAY);
@@ -824,7 +797,7 @@
     if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface)
     end;
 SDL_FreeSurface(MissionIcons);
-
+FreeTexture(ropeIconTex);
 FreeTexture(HHTexture)
 end;