Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Scale logo to fit box.

Fixes ticket:3667.
  • Loading branch information...
commit 47011db59eb0c6254ed1626c4b9c8f32ee5a289c 1 parent b256d99
Cyp Cyp authored
18 lib/ivis_opengl/pieblitfunc.cpp
View
@@ -283,6 +283,24 @@ void iV_DrawImageRect(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, i
}
}
+void iV_DrawImageScaled(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int w, int h)
+{
+ if (!assertValidImage(ImageFile, ID))
+ {
+ return;
+ }
+
+ PIERECT dest;
+ PIEIMAGE pieImage = makePieImage(ImageFile, ID, &dest, x, y);
+ dest.w = w;
+ dest.h = h;
+
+ pie_SetRendMode(REND_ALPHA);
+ pie_SetAlphaTest(true);
+
+ pie_DrawImage(&pieImage, &dest);
+}
+
/* FIXME: WTF is this supposed to do? Looks like some other functionality
* was retrofitted onto something else. - Per */
void pie_UploadDisplayBuffer()
1  lib/ivis_opengl/pieblitfunc.h
View
@@ -67,6 +67,7 @@ extern void pie_BoxFill(int x0,int y0, int x1, int y1, PIELIGHT colour);
extern void iV_DrawImage(IMAGEFILE *ImageFile, UWORD ID, int x, int y);
void iV_DrawImageTc(IMAGEFILE *imageFile, unsigned id, unsigned idTc, int x, int y, PIELIGHT colour);
extern void iV_DrawImageRect(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, int Height);
+void iV_DrawImageScaled(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int w, int h);
extern void iV_TransBoxFill(float x0, float y0, float x1, float y1);
extern void pie_UniTransBoxFill(float x0, float y0, float x1, float y1, PIELIGHT colour);
22 src/frontend.cpp
View
@@ -1494,7 +1494,7 @@ static void displayTitleBitmap(WZ_DECL_UNUSED WIDGET *psWidget, WZ_DECL_UNUSED U
// show warzone logo
static void displayLogo(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{
- iV_DrawImage(FrontImages, IMAGE_FE_LOGO, xOffset + psWidget->x, std::max<int>(yOffset + psWidget->y, 0));
+ iV_DrawImageScaled(FrontImages, IMAGE_FE_LOGO, xOffset + psWidget->x, yOffset + psWidget->y, psWidget->width, psWidget->height);
}
@@ -1678,10 +1678,22 @@ void addTopForm(void)
sFormInit.formID= FRONTEND_TOPFORM;
sFormInit.id = FRONTEND_LOGO;
- sFormInit.x = sFormInit.width/2 - iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO)/2;
- sFormInit.y = sFormInit.height/2 - iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO)/2;
- sFormInit.width = iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO);
- sFormInit.height= iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO);
+ int imgW = iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO);
+ int imgH = iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO);
+ int dstW = sFormInit.width;
+ int dstH = sFormInit.height;
+ if (imgW*dstH < imgH*dstW) // Want to set aspect ratio dstW/dstH = imgW/imgH.
+ {
+ dstW = imgW * dstH/imgH; // Too wide.
+ }
+ else if (imgW*dstH > imgH*dstW)
+ {
+ dstH = imgH * dstW/imgW; // Too high.
+ }
+ sFormInit.x = (sFormInit.width - dstW)/2;
+ sFormInit.y = (sFormInit.height - dstH)/2;
+ sFormInit.width = dstW;
+ sFormInit.height = dstH;
sFormInit.pDisplay= displayLogo;
widgAddForm(psWScreen, &sFormInit);
}
Please sign in to comment.
Something went wrong with that request. Please try again.