3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 GUIBox::GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
23 const core::rect<s32> &rectangle,
24 const std::array<video::SColor, 4> &colors,
25 const std::array<video::SColor, 4> &bordercolors,
26 const std::array<s32, 4> &borderwidths) :
27 gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
29 m_bordercolors(bordercolors),
30 m_borderwidths(borderwidths)
39 std::array<s32, 4> negative_borders = {0, 0, 0, 0};
40 std::array<s32, 4> positive_borders = {0, 0, 0, 0};
42 for (size_t i = 0; i <= 3; i++) {
43 if (m_borderwidths[i] > 0)
44 positive_borders[i] = m_borderwidths[i];
46 negative_borders[i] = m_borderwidths[i];
49 v2s32 upperleft = AbsoluteRect.UpperLeftCorner;
50 v2s32 lowerright = AbsoluteRect.LowerRightCorner;
52 v2s32 topleft_border = {
53 upperleft.X - positive_borders[3],
54 upperleft.Y - positive_borders[0]
56 v2s32 topleft_rect = {
57 upperleft.X - negative_borders[3],
58 upperleft.Y - negative_borders[0]
61 v2s32 lowerright_border = {
62 lowerright.X + positive_borders[1],
63 lowerright.Y + positive_borders[2]
65 v2s32 lowerright_rect = {
66 lowerright.X + negative_borders[1],
67 lowerright.Y + negative_borders[2]
70 core::rect<s32> main_rect(
77 std::array<core::rect<s32>, 4> border_rects;
79 border_rects[0] = core::rect<s32>(
86 border_rects[1] = core::rect<s32>(
93 border_rects[2] = core::rect<s32>(
100 border_rects[3] = core::rect<s32>(
107 video::IVideoDriver *driver = Environment->getVideoDriver();
109 driver->draw2DRectangle(main_rect, m_colors[0], m_colors[1], m_colors[3],
110 m_colors[2], &AbsoluteClippingRect);
112 for (size_t i = 0; i <= 3; i++)
113 driver->draw2DRectangle(m_bordercolors[i], border_rects[i],
114 &AbsoluteClippingRect);