From ae7271b7259437f613f7bca0a3b71ee7ebfa9c51 Mon Sep 17 00:00:00 2001 From: DS Date: Fri, 14 Apr 2023 21:05:09 +0200 Subject: [PATCH] Fix background[] pos-offset lower-right-corner being at least (1,1) (#13320) IGUIElement has a MinSize for the RelativeRect, which is at least (1,1). This means a pos offset of (0,0) will cause a seemingly off-by-1 error at the lower right corner, and (0.1,0.1) for example will just not work on the lower right corner. Ergo, we can't use the AbsoluteRect for storing the pos offset. --- src/gui/guiBackgroundImage.cpp | 16 +++++++++++----- src/gui/guiBackgroundImage.h | 4 +++- src/gui/guiFormSpecMenu.cpp | 9 +++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/gui/guiBackgroundImage.cpp b/src/gui/guiBackgroundImage.cpp index 8d0d1c010..987287fce 100644 --- a/src/gui/guiBackgroundImage.cpp +++ b/src/gui/guiBackgroundImage.cpp @@ -22,9 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, const core::rect &rectangle, const std::string &name, const core::rect &middle, - ISimpleTextureSource *tsrc, bool autoclip) : + ISimpleTextureSource *tsrc, bool autoclip, v2s32 autoclip_offset) : gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip) + m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip), + m_autoclip_offset(autoclip_offset) { } @@ -42,9 +43,14 @@ void GUIBackgroundImage::draw() return; } - core::rect rect = AbsoluteRect; - if (m_autoclip) - rect.LowerRightCorner += Parent->getAbsoluteClippingRect().getSize(); + core::rect rect; + if (m_autoclip) { + rect = Parent->getAbsoluteClippingRect(); + rect.UpperLeftCorner -= m_autoclip_offset; + rect.LowerRightCorner += m_autoclip_offset; + } else { + rect = AbsoluteRect; + } video::IVideoDriver *driver = Environment->getVideoDriver(); diff --git a/src/gui/guiBackgroundImage.h b/src/gui/guiBackgroundImage.h index 31fbfd09c..2e51a8190 100644 --- a/src/gui/guiBackgroundImage.h +++ b/src/gui/guiBackgroundImage.h @@ -26,7 +26,8 @@ class GUIBackgroundImage : public gui::IGUIElement public: GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, const core::rect &rectangle, const std::string &name, - const core::rect &middle, ISimpleTextureSource *tsrc, bool autoclip); + const core::rect &middle, ISimpleTextureSource *tsrc, bool autoclip, + v2s32 autoclip_offset); virtual void draw() override; @@ -35,4 +36,5 @@ private: core::rect m_middle; ISimpleTextureSource *m_tsrc; bool m_autoclip; + v2s32 m_autoclip_offset; }; diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 16183211d..e48f13d25 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1101,17 +1101,18 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme 258 + m_fields.size() ); - core::rect rect; + core::rect rect{}; + v2s32 autoclip_offset{}; if (!clip) { // no auto_clip => position like normal image rect = core::rect(pos, pos + geom); } else { - // it will be auto-clipped when drawing - rect = core::rect(-pos, pos); + // element will be auto-clipped when drawing + autoclip_offset = pos; } GUIBackgroundImage *e = new GUIBackgroundImage(Environment, data->background_parent.get(), - spec.fid, rect, name, middle, m_tsrc, clip); + spec.fid, rect, name, middle, m_tsrc, clip, autoclip_offset); FATAL_ERROR_IF(!e, "Failed to create background formspec element");