diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CGUIToolBar.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CGUIToolBar.cpp | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIToolBar.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIToolBar.cpp new file mode 100644 index 0000000..9671c04 --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIToolBar.cpp | |||
@@ -0,0 +1,176 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CGUIToolBar.h" | ||
6 | #ifdef _IRR_COMPILE_WITH_GUI_ | ||
7 | |||
8 | #include "IGUISkin.h" | ||
9 | #include "IGUIEnvironment.h" | ||
10 | #include "IVideoDriver.h" | ||
11 | #include "IGUIButton.h" | ||
12 | #include "IGUIFont.h" | ||
13 | #include "CGUIButton.h" | ||
14 | |||
15 | namespace irr | ||
16 | { | ||
17 | namespace gui | ||
18 | { | ||
19 | |||
20 | //! constructor | ||
21 | CGUIToolBar::CGUIToolBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) | ||
22 | :IGUIToolBar(environment, parent, id, rectangle), ButtonX(5) | ||
23 | { | ||
24 | #ifdef _DEBUG | ||
25 | setDebugName("CGUIToolBar"); | ||
26 | #endif | ||
27 | |||
28 | // calculate position and find other menubars | ||
29 | s32 y = 0; | ||
30 | s32 parentwidth = 100; | ||
31 | |||
32 | if (parent) | ||
33 | { | ||
34 | parentwidth = Parent->getAbsolutePosition().getWidth(); | ||
35 | |||
36 | const core::list<IGUIElement*>& children = parent->getChildren(); | ||
37 | core::list<IGUIElement*>::ConstIterator it = children.begin(); | ||
38 | for (; it != children.end(); ++it) | ||
39 | { | ||
40 | core::rect<s32> r = (*it)->getAbsolutePosition(); | ||
41 | if (r.UpperLeftCorner.X == 0 && r.UpperLeftCorner.Y <= y && | ||
42 | r.LowerRightCorner.X == parentwidth) | ||
43 | y = r.LowerRightCorner.Y; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | core::rect<s32> rr; | ||
48 | rr.UpperLeftCorner.X = 0; | ||
49 | rr.UpperLeftCorner.Y = y; | ||
50 | s32 height = Environment->getSkin()->getSize ( EGDS_MENU_HEIGHT ); | ||
51 | |||
52 | /*IGUISkin* skin = Environment->getSkin(); | ||
53 | IGUIFont* font = skin->getFont(); | ||
54 | if (font) | ||
55 | { | ||
56 | s32 t = font->getDimension(L"A").Height + 5; | ||
57 | if (t > height) | ||
58 | height = t; | ||
59 | }*/ | ||
60 | |||
61 | rr.LowerRightCorner.X = parentwidth; | ||
62 | rr.LowerRightCorner.Y = rr.UpperLeftCorner.Y + height; | ||
63 | setRelativePosition(rr); | ||
64 | } | ||
65 | |||
66 | |||
67 | //! called if an event happened. | ||
68 | bool CGUIToolBar::OnEvent(const SEvent& event) | ||
69 | { | ||
70 | if (isEnabled()) | ||
71 | { | ||
72 | if (event.EventType == EET_MOUSE_INPUT_EVENT && | ||
73 | event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) | ||
74 | { | ||
75 | if (AbsoluteClippingRect.isPointInside(core::position2di(event.MouseInput.X, event.MouseInput.Y))) | ||
76 | return true; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | return IGUIElement::OnEvent(event); | ||
81 | } | ||
82 | |||
83 | |||
84 | //! draws the element and its children | ||
85 | void CGUIToolBar::draw() | ||
86 | { | ||
87 | if (!IsVisible) | ||
88 | return; | ||
89 | |||
90 | IGUISkin* skin = Environment->getSkin(); | ||
91 | if (!skin) | ||
92 | return; | ||
93 | |||
94 | core::rect<s32> rect = AbsoluteRect; | ||
95 | core::rect<s32>* clip = &AbsoluteClippingRect; | ||
96 | |||
97 | // draw frame | ||
98 | skin->draw3DToolBar(this, rect, clip); | ||
99 | |||
100 | IGUIElement::draw(); | ||
101 | } | ||
102 | |||
103 | |||
104 | //! Updates the absolute position. | ||
105 | void CGUIToolBar::updateAbsolutePosition() | ||
106 | { | ||
107 | if (Parent) | ||
108 | { | ||
109 | DesiredRect.UpperLeftCorner.X = 0; | ||
110 | DesiredRect.LowerRightCorner.X = Parent->getAbsolutePosition().getWidth(); | ||
111 | } | ||
112 | |||
113 | IGUIElement::updateAbsolutePosition(); | ||
114 | } | ||
115 | |||
116 | |||
117 | //! Adds a button to the tool bar | ||
118 | IGUIButton* CGUIToolBar::addButton(s32 id, const wchar_t* text,const wchar_t* tooltiptext, | ||
119 | video::ITexture* img, video::ITexture* pressed, bool isPushButton, | ||
120 | bool useAlphaChannel) | ||
121 | { | ||
122 | ButtonX += 3; | ||
123 | |||
124 | core::rect<s32> rectangle(ButtonX,2,ButtonX+1,3); | ||
125 | if ( img ) | ||
126 | { | ||
127 | const core::dimension2du &size = img->getOriginalSize(); | ||
128 | rectangle.LowerRightCorner.X = rectangle.UpperLeftCorner.X + size.Width + 8; | ||
129 | rectangle.LowerRightCorner.Y = rectangle.UpperLeftCorner.Y + size.Height + 6; | ||
130 | } | ||
131 | |||
132 | if ( text ) | ||
133 | { | ||
134 | IGUISkin* skin = Environment->getSkin(); | ||
135 | IGUIFont * font = skin->getFont(EGDF_BUTTON); | ||
136 | if ( font ) | ||
137 | { | ||
138 | core::dimension2d<u32> dim = font->getDimension(text); | ||
139 | if ( (s32)dim.Width > rectangle.getWidth() ) | ||
140 | rectangle.LowerRightCorner.X = rectangle.UpperLeftCorner.X + dim.Width + 8; | ||
141 | if ( (s32)dim.Height > rectangle.getHeight() ) | ||
142 | rectangle.LowerRightCorner.Y = rectangle.UpperLeftCorner.Y + dim.Height + 6; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | ButtonX += rectangle.getWidth(); | ||
147 | |||
148 | IGUIButton* button = new CGUIButton(Environment, this, id, rectangle); | ||
149 | button->drop(); | ||
150 | |||
151 | if (text) | ||
152 | button->setText(text); | ||
153 | |||
154 | if (tooltiptext) | ||
155 | button->setToolTipText(tooltiptext); | ||
156 | |||
157 | if (img) | ||
158 | button->setImage(img); | ||
159 | |||
160 | if (pressed) | ||
161 | button->setPressedImage(pressed); | ||
162 | |||
163 | if (isPushButton) | ||
164 | button->setIsPushButton(isPushButton); | ||
165 | |||
166 | if (useAlphaChannel) | ||
167 | button->setUseAlphaChannel(useAlphaChannel); | ||
168 | |||
169 | return button; | ||
170 | } | ||
171 | |||
172 | } // end namespace gui | ||
173 | } // end namespace irr | ||
174 | |||
175 | #endif // _IRR_COMPILE_WITH_GUI_ | ||
176 | |||