Skip to content

Commit 27947d8

Browse files
BlockMenkahrl
authored andcommittedSep 20, 2013
Add option to scale image to percentage values
1 parent f7ee5da commit 27947d8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed
 

‎doc/lua_api.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,10 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still
478478

479479
- image
480480
Displays an image on the HUD.
481-
- scale: The scale of the image, with 1 being the original texture size.
482-
Only the X coordinate scale is used.
481+
- scale: The scale of the image, with 1 being the original texture size.
482+
Only the X coordinate scale is used (positive values)
483+
Negative values represent that percentage of the screen it
484+
should take; e.g. x=-100 means 100% (width)
483485
- text: The name of the texture that is displayed.
484486
- alignment: The alignment of the image.
485487
- offset: offset in pixels from position.

‎src/hud.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,16 @@ void Hud::drawLuaElements() {
234234
const video::SColor color(255, 255, 255, 255);
235235
const video::SColor colors[] = {color, color, color, color};
236236
core::dimension2di imgsize(texture->getOriginalSize());
237-
core::rect<s32> rect(0, 0, imgsize.Width * e->scale.X,
238-
imgsize.Height * e->scale.X);
239-
rect += pos;
240-
v2s32 offset((e->align.X - 1.0) * ((imgsize.Width * e->scale.X) / 2),
241-
(e->align.Y - 1.0) * ((imgsize.Height * e->scale.X) / 2));
242-
rect += offset;
243-
rect += v2s32(e->offset.X, e->offset.Y);
237+
v2s32 dstsize(imgsize.Width * e->scale.X,
238+
imgsize.Height * e->scale.Y);
239+
if (e->scale.X < 0)
240+
dstsize.X = screensize.X * (e->scale.X * -0.01);
241+
if (e->scale.Y < 0)
242+
dstsize.Y = screensize.Y * (e->scale.Y * -0.01);
243+
v2s32 offset((e->align.X - 1.0) * dstsize.X / 2,
244+
(e->align.Y - 1.0) * dstsize.Y / 2);
245+
core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y);
246+
rect += pos + offset + v2s32(e->offset.X, e->offset.Y);
244247
driver->draw2DImage(texture, rect,
245248
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
246249
NULL, colors, true);

0 commit comments

Comments
 (0)
Please sign in to comment.