]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/guiBox.cpp
Use "Aux1" key name consistently everywhere
[dragonfireclient.git] / src / gui / guiBox.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "guiBox.h"
21
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),
28         m_colors(colors),
29         m_bordercolors(bordercolors),
30         m_borderwidths(borderwidths)
31 {
32 }
33
34 void GUIBox::draw()
35 {
36         if (!IsVisible)
37                 return;
38
39         std::array<s32, 4> negative_borders = {0, 0, 0, 0};
40         std::array<s32, 4> positive_borders = {0, 0, 0, 0};
41
42         for (size_t i = 0; i <= 3; i++) {
43                 if (m_borderwidths[i] > 0)
44                         positive_borders[i] = m_borderwidths[i];
45                 else
46                         negative_borders[i] = m_borderwidths[i];
47         }
48
49         v2s32 upperleft = AbsoluteRect.UpperLeftCorner;
50         v2s32 lowerright = AbsoluteRect.LowerRightCorner;
51
52         v2s32 topleft_border = {
53                 upperleft.X - positive_borders[3],
54                 upperleft.Y - positive_borders[0]
55         };
56         v2s32 topleft_rect = {
57                 upperleft.X - negative_borders[3],
58                 upperleft.Y - negative_borders[0]
59         };
60
61         v2s32 lowerright_border = {
62                 lowerright.X + positive_borders[1],
63                 lowerright.Y + positive_borders[2]
64         };
65         v2s32 lowerright_rect = {
66                 lowerright.X + negative_borders[1],
67                 lowerright.Y + negative_borders[2]
68         };
69
70         core::rect<s32> main_rect(
71                 topleft_rect.X,
72                 topleft_rect.Y,
73                 lowerright_rect.X,
74                 lowerright_rect.Y
75         );
76
77         std::array<core::rect<s32>, 4> border_rects;
78
79         border_rects[0] = core::rect<s32>(
80                 topleft_border.X,
81                 topleft_border.Y,
82                 lowerright_border.X,
83                 topleft_rect.Y
84         );
85
86         border_rects[1] = core::rect<s32>(
87                 lowerright_rect.X,
88                 topleft_rect.Y,
89                 lowerright_border.X,
90                 lowerright_rect.Y
91         );
92
93         border_rects[2] = core::rect<s32>(
94                 topleft_border.X,
95                 lowerright_rect.Y,
96                 lowerright_border.X,
97                 lowerright_border.Y
98         );
99
100         border_rects[3] = core::rect<s32>(
101                 topleft_border.X,
102                 topleft_rect.Y,
103                 topleft_rect.X,
104                 lowerright_rect.Y
105         );
106
107         video::IVideoDriver *driver = Environment->getVideoDriver();
108
109         driver->draw2DRectangle(main_rect, m_colors[0], m_colors[1], m_colors[3],
110                 m_colors[2], &AbsoluteClippingRect);
111
112         for (size_t i = 0; i <= 3; i++)
113                 driver->draw2DRectangle(m_bordercolors[i], border_rects[i],
114                                 &AbsoluteClippingRect);
115
116         IGUIElement::draw();
117 }