mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Formspec: draw order and clipping for all elements (#8740)
This commit is contained in:
parent
15a030ec9f
commit
5506e97ed8
14 changed files with 825 additions and 455 deletions
69
src/gui/guiBackgroundImage.cpp
Normal file
69
src/gui/guiBackgroundImage.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Part of Minetest
|
||||
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "guiBackgroundImage.h"
|
||||
#include "client/guiscalingfilter.h"
|
||||
#include "log.h"
|
||||
|
||||
GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env,
|
||||
gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
|
||||
const std::string &name, const core::rect<s32> &middle,
|
||||
ISimpleTextureSource *tsrc, bool autoclip) :
|
||||
gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
|
||||
m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip)
|
||||
{
|
||||
}
|
||||
|
||||
void GUIBackgroundImage::draw()
|
||||
{
|
||||
if (!IsVisible)
|
||||
return;
|
||||
|
||||
video::ITexture *texture = m_tsrc->getTexture(m_name);
|
||||
|
||||
if (!texture) {
|
||||
errorstream << "GUIBackgroundImage::draw() Unable to load texture:"
|
||||
<< std::endl;
|
||||
errorstream << "\t" << m_name << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
core::rect<s32> rect = AbsoluteRect;
|
||||
if (m_autoclip)
|
||||
rect.LowerRightCorner += Parent->getAbsolutePosition().getSize();
|
||||
|
||||
video::IVideoDriver *driver = Environment->getVideoDriver();
|
||||
|
||||
if (m_middle.getArea() == 0) {
|
||||
const video::SColor color(255, 255, 255, 255);
|
||||
const video::SColor colors[] = {color, color, color, color};
|
||||
draw2DImageFilterScaled(driver, texture, rect,
|
||||
core::rect<s32>(core::position2d<s32>(0, 0),
|
||||
core::dimension2di(texture->getOriginalSize())),
|
||||
nullptr, colors, true);
|
||||
} else {
|
||||
core::rect<s32> middle = m_middle;
|
||||
// `-x` is interpreted as `w - x`
|
||||
if (middle.LowerRightCorner.X < 0)
|
||||
middle.LowerRightCorner.X += texture->getOriginalSize().Width;
|
||||
if (middle.LowerRightCorner.Y < 0)
|
||||
middle.LowerRightCorner.Y += texture->getOriginalSize().Height;
|
||||
draw2DImage9Slice(driver, texture, rect, middle);
|
||||
}
|
||||
|
||||
IGUIElement::draw();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue