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