Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Scale logo to fit box.

Fixes ticket:3667.
  • Loading branch information...
commit 47011db59eb0c6254ed1626c4b9c8f32ee5a289c 1 parent b256d99
Cyp authored
18  lib/ivis_opengl/pieblitfunc.cpp
@@ -283,6 +283,24 @@ void iV_DrawImageRect(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, i
283 283
 	}
284 284
 }
285 285
 
  286
+void iV_DrawImageScaled(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int w, int h)
  287
+{
  288
+	if (!assertValidImage(ImageFile, ID))
  289
+	{
  290
+		return;
  291
+	}
  292
+
  293
+	PIERECT dest;
  294
+	PIEIMAGE pieImage = makePieImage(ImageFile, ID, &dest, x, y);
  295
+	dest.w = w;
  296
+	dest.h = h;
  297
+
  298
+	pie_SetRendMode(REND_ALPHA);
  299
+	pie_SetAlphaTest(true);
  300
+
  301
+	pie_DrawImage(&pieImage, &dest);
  302
+}
  303
+
286 304
 /* FIXME: WTF is this supposed to do? Looks like some other functionality
287 305
  * was retrofitted onto something else. - Per */
288 306
 void pie_UploadDisplayBuffer()
1  lib/ivis_opengl/pieblitfunc.h
@@ -67,6 +67,7 @@ extern void pie_BoxFill(int x0,int y0, int x1, int y1, PIELIGHT colour);
67 67
 extern void iV_DrawImage(IMAGEFILE *ImageFile, UWORD ID, int x, int y);
68 68
 void iV_DrawImageTc(IMAGEFILE *imageFile, unsigned id, unsigned idTc, int x, int y, PIELIGHT colour);
69 69
 extern void iV_DrawImageRect(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, int Height);
  70
+void iV_DrawImageScaled(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int w, int h);
70 71
 
71 72
 extern void iV_TransBoxFill(float x0, float y0, float x1, float y1);
72 73
 extern void pie_UniTransBoxFill(float x0, float y0, float x1, float y1, PIELIGHT colour);
22  src/frontend.cpp
@@ -1494,7 +1494,7 @@ static void displayTitleBitmap(WZ_DECL_UNUSED WIDGET *psWidget, WZ_DECL_UNUSED U
1494 1494
 // show warzone logo
1495 1495
 static void displayLogo(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
1496 1496
 {
1497  
-	iV_DrawImage(FrontImages, IMAGE_FE_LOGO, xOffset + psWidget->x, std::max<int>(yOffset + psWidget->y, 0));
  1497
+	iV_DrawImageScaled(FrontImages, IMAGE_FE_LOGO, xOffset + psWidget->x, yOffset + psWidget->y, psWidget->width, psWidget->height);
1498 1498
 }
1499 1499
 
1500 1500
 
@@ -1678,10 +1678,22 @@ void addTopForm(void)
1678 1678
 
1679 1679
 	sFormInit.formID= FRONTEND_TOPFORM;
1680 1680
 	sFormInit.id	= FRONTEND_LOGO;
1681  
-	sFormInit.x		= sFormInit.width/2  - iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO)/2;
1682  
-	sFormInit.y		= sFormInit.height/2 - iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO)/2;
1683  
-	sFormInit.width = iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO);
1684  
-	sFormInit.height= iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO);
  1681
+	int imgW = iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO);
  1682
+	int imgH = iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO);
  1683
+	int dstW = sFormInit.width;
  1684
+	int dstH = sFormInit.height;
  1685
+	if (imgW*dstH < imgH*dstW)  // Want to set aspect ratio dstW/dstH = imgW/imgH.
  1686
+	{
  1687
+		dstW = imgW * dstH/imgH;  // Too wide.
  1688
+	}
  1689
+	else if (imgW*dstH > imgH*dstW)
  1690
+	{
  1691
+		dstH = imgH * dstW/imgW;  // Too high.
  1692
+	}
  1693
+	sFormInit.x = (sFormInit.width  - dstW)/2;
  1694
+	sFormInit.y = (sFormInit.height - dstH)/2;
  1695
+	sFormInit.width  = dstW;
  1696
+	sFormInit.height = dstH;
1685 1697
 	sFormInit.pDisplay= displayLogo;
1686 1698
 	widgAddForm(psWScreen, &sFormInit);
1687 1699
 }

0 notes on commit 47011db

Please sign in to comment.
Something went wrong with that request. Please try again.