mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Add option to scale image to percentage values
This commit is contained in:
parent
f7ee5da4c1
commit
27947d85f7
@ -478,8 +478,10 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still
|
|||||||
|
|
||||||
- image
|
- image
|
||||||
Displays an image on the HUD.
|
Displays an image on the HUD.
|
||||||
- scale: The scale of the image, with 1 being the original texture size.
|
- scale: The scale of the image, with 1 being the original texture size.
|
||||||
Only the X coordinate scale is used.
|
Only the X coordinate scale is used (positive values)
|
||||||
|
Negative values represent that percentage of the screen it
|
||||||
|
should take; e.g. x=-100 means 100% (width)
|
||||||
- text: The name of the texture that is displayed.
|
- text: The name of the texture that is displayed.
|
||||||
- alignment: The alignment of the image.
|
- alignment: The alignment of the image.
|
||||||
- offset: offset in pixels from position.
|
- offset: offset in pixels from position.
|
||||||
|
17
src/hud.cpp
17
src/hud.cpp
@ -234,13 +234,16 @@ void Hud::drawLuaElements() {
|
|||||||
const video::SColor color(255, 255, 255, 255);
|
const video::SColor color(255, 255, 255, 255);
|
||||||
const video::SColor colors[] = {color, color, color, color};
|
const video::SColor colors[] = {color, color, color, color};
|
||||||
core::dimension2di imgsize(texture->getOriginalSize());
|
core::dimension2di imgsize(texture->getOriginalSize());
|
||||||
core::rect<s32> rect(0, 0, imgsize.Width * e->scale.X,
|
v2s32 dstsize(imgsize.Width * e->scale.X,
|
||||||
imgsize.Height * e->scale.X);
|
imgsize.Height * e->scale.Y);
|
||||||
rect += pos;
|
if (e->scale.X < 0)
|
||||||
v2s32 offset((e->align.X - 1.0) * ((imgsize.Width * e->scale.X) / 2),
|
dstsize.X = screensize.X * (e->scale.X * -0.01);
|
||||||
(e->align.Y - 1.0) * ((imgsize.Height * e->scale.X) / 2));
|
if (e->scale.Y < 0)
|
||||||
rect += offset;
|
dstsize.Y = screensize.Y * (e->scale.Y * -0.01);
|
||||||
rect += v2s32(e->offset.X, e->offset.Y);
|
v2s32 offset((e->align.X - 1.0) * dstsize.X / 2,
|
||||||
|
(e->align.Y - 1.0) * dstsize.Y / 2);
|
||||||
|
core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y);
|
||||||
|
rect += pos + offset + v2s32(e->offset.X, e->offset.Y);
|
||||||
driver->draw2DImage(texture, rect,
|
driver->draw2DImage(texture, rect,
|
||||||
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
|
||||||
NULL, colors, true);
|
NULL, colors, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user