diff options
author | v-rob <robinsonvincent89@gmail.com> | 2020-08-19 18:14:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-19 18:14:47 -0700 |
commit | 83d0c360cc648e02650aa4d341dbf5205c1e708f (patch) | |
tree | 4defb9776d28281059da0b145df9cfeca921f489 /src/gui/guiBox.cpp | |
parent | 471497fa9198695becae26a83097ec80643b4cc5 (diff) | |
download | minetest-83d0c360cc648e02650aa4d341dbf5205c1e708f.tar.gz minetest-83d0c360cc648e02650aa4d341dbf5205c1e708f.tar.bz2 minetest-83d0c360cc648e02650aa4d341dbf5205c1e708f.zip |
Add gradients and borders to FormSpec boxes (#8676)
Diffstat (limited to 'src/gui/guiBox.cpp')
-rw-r--r-- | src/gui/guiBox.cpp | 86 |
1 files changed, 82 insertions, 4 deletions
diff --git a/src/gui/guiBox.cpp b/src/gui/guiBox.cpp index 7f329cc32..99a115daf 100644 --- a/src/gui/guiBox.cpp +++ b/src/gui/guiBox.cpp @@ -20,9 +20,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiBox.h" GUIBox::GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - const core::rect<s32> &rectangle, const video::SColor &color) : + const core::rect<s32> &rectangle, + const std::array<video::SColor, 4> &colors, + const std::array<video::SColor, 4> &bordercolors, + const std::array<s32, 4> &borderwidths) : gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), - m_color(color) + m_colors(colors), + m_bordercolors(bordercolors), + m_borderwidths(borderwidths) { } @@ -31,8 +36,81 @@ void GUIBox::draw() if (!IsVisible) return; - Environment->getVideoDriver()->draw2DRectangle(m_color, AbsoluteRect, - &AbsoluteClippingRect); + std::array<s32, 4> negative_borders = {0, 0, 0, 0}; + std::array<s32, 4> positive_borders = {0, 0, 0, 0}; + + for (size_t i = 0; i <= 3; i++) { + if (m_borderwidths[i] > 0) + positive_borders[i] = m_borderwidths[i]; + else + negative_borders[i] = m_borderwidths[i]; + } + + v2s32 upperleft = AbsoluteRect.UpperLeftCorner; + v2s32 lowerright = AbsoluteRect.LowerRightCorner; + + v2s32 topleft_border = { + upperleft.X - positive_borders[3], + upperleft.Y - positive_borders[0] + }; + v2s32 topleft_rect = { + upperleft.X - negative_borders[3], + upperleft.Y - negative_borders[0] + }; + + v2s32 lowerright_border = { + lowerright.X + positive_borders[1], + lowerright.Y + positive_borders[2] + }; + v2s32 lowerright_rect = { + lowerright.X + negative_borders[1], + lowerright.Y + negative_borders[2] + }; + + core::rect<s32> main_rect( + topleft_rect.X, + topleft_rect.Y, + lowerright_rect.X, + lowerright_rect.Y + ); + + std::array<core::rect<s32>, 4> border_rects; + + border_rects[0] = core::rect<s32>( + topleft_border.X, + topleft_border.Y, + lowerright_border.X, + topleft_rect.Y + ); + + border_rects[1] = core::rect<s32>( + lowerright_rect.X, + topleft_rect.Y, + lowerright_border.X, + lowerright_rect.Y + ); + + border_rects[2] = core::rect<s32>( + topleft_border.X, + lowerright_rect.Y, + lowerright_border.X, + lowerright_border.Y + ); + + border_rects[3] = core::rect<s32>( + topleft_border.X, + topleft_rect.Y, + topleft_rect.X, + lowerright_rect.Y + ); + + video::IVideoDriver *driver = Environment->getVideoDriver(); + + driver->draw2DRectangle(main_rect, m_colors[0], m_colors[1], m_colors[3], + m_colors[2], nullptr); + + for (size_t i = 0; i <= 3; i++) + driver->draw2DRectangle(m_bordercolors[i], border_rects[i], nullptr); IGUIElement::draw(); } |