1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "CGUIToolBar.h"
\r
6 #ifdef _IRR_COMPILE_WITH_GUI_
\r
8 #include "IGUISkin.h"
\r
9 #include "IGUIEnvironment.h"
\r
10 #include "IVideoDriver.h"
\r
11 #include "IGUIButton.h"
\r
12 #include "IGUIFont.h"
\r
13 #include "CGUIButton.h"
\r
21 CGUIToolBar::CGUIToolBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
\r
22 :IGUIToolBar(environment, parent, id, rectangle), ButtonX(5)
\r
25 setDebugName("CGUIToolBar");
\r
28 // calculate position and find other menubars
\r
30 s32 parentwidth = 100;
\r
34 parentwidth = Parent->getAbsolutePosition().getWidth();
\r
35 s32 parentheight = Parent->getAbsolutePosition().getHeight();
\r
37 for (const auto& e : parent->getChildren())
\r
39 if ( e->hasType(EGUIET_CONTEXT_MENU)
\r
40 || e->hasType(EGUIET_MENU)
\r
41 || e->hasType(EGUIET_TOOL_BAR) )
\r
43 core::rect<s32> r = e->getAbsolutePosition();
\r
44 if (r.UpperLeftCorner.X == 0 && r.UpperLeftCorner.Y <= y &&
\r
45 r.LowerRightCorner.X == parentwidth
\r
46 && parentheight > r.LowerRightCorner.Y )
\r
47 y = r.LowerRightCorner.Y;
\r
57 rr.UpperLeftCorner.X = 0;
\r
58 rr.UpperLeftCorner.Y = y;
\r
59 s32 height = Environment->getSkin()->getSize ( EGDS_MENU_HEIGHT );
\r
61 /*IGUISkin* skin = Environment->getSkin();
\r
62 IGUIFont* font = skin->getFont();
\r
65 s32 t = font->getDimension(L"A").Height + 5;
\r
70 rr.LowerRightCorner.X = parentwidth;
\r
71 rr.LowerRightCorner.Y = rr.UpperLeftCorner.Y + height;
\r
72 setRelativePosition(rr);
\r
76 //! called if an event happened.
\r
77 bool CGUIToolBar::OnEvent(const SEvent& event)
\r
81 if (event.EventType == EET_MOUSE_INPUT_EVENT &&
\r
82 event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
\r
84 if (AbsoluteClippingRect.isPointInside(core::position2di(event.MouseInput.X, event.MouseInput.Y)))
\r
89 return IGUIElement::OnEvent(event);
\r
93 //! draws the element and its children
\r
94 void CGUIToolBar::draw()
\r
99 IGUISkin* skin = Environment->getSkin();
\r
103 core::rect<s32> rect = AbsoluteRect;
\r
104 core::rect<s32>* clip = &AbsoluteClippingRect;
\r
107 skin->draw3DToolBar(this, rect, clip);
\r
109 IGUIElement::draw();
\r
113 //! Updates the absolute position.
\r
114 void CGUIToolBar::updateAbsolutePosition()
\r
118 DesiredRect.UpperLeftCorner.X = 0;
\r
119 DesiredRect.LowerRightCorner.X = Parent->getAbsolutePosition().getWidth();
\r
122 IGUIElement::updateAbsolutePosition();
\r
126 //! Adds a button to the tool bar
\r
127 IGUIButton* CGUIToolBar::addButton(s32 id, const wchar_t* text,const wchar_t* tooltiptext,
\r
128 video::ITexture* img, video::ITexture* pressed, bool isPushButton,
\r
129 bool useAlphaChannel)
\r
133 core::rect<s32> rectangle(ButtonX,2,ButtonX+1,3);
\r
136 const core::dimension2du &size = img->getOriginalSize();
\r
137 rectangle.LowerRightCorner.X = rectangle.UpperLeftCorner.X + size.Width + 8;
\r
138 rectangle.LowerRightCorner.Y = rectangle.UpperLeftCorner.Y + size.Height + 6;
\r
143 IGUISkin* skin = Environment->getSkin();
\r
144 IGUIFont * font = skin->getFont(EGDF_BUTTON);
\r
147 core::dimension2d<u32> dim = font->getDimension(text);
\r
148 if ( (s32)dim.Width > rectangle.getWidth() )
\r
149 rectangle.LowerRightCorner.X = rectangle.UpperLeftCorner.X + dim.Width + 8;
\r
150 if ( (s32)dim.Height > rectangle.getHeight() )
\r
151 rectangle.LowerRightCorner.Y = rectangle.UpperLeftCorner.Y + dim.Height + 6;
\r
155 ButtonX += rectangle.getWidth();
\r
157 IGUIButton* button = new CGUIButton(Environment, this, id, rectangle);
\r
161 button->setText(text);
\r
164 button->setToolTipText(tooltiptext);
\r
167 button->setImage(img);
\r
170 button->setPressedImage(pressed);
\r
173 button->setIsPushButton(isPushButton);
\r
175 if (useAlphaChannel)
\r
176 button->setUseAlphaChannel(useAlphaChannel);
\r
181 } // end namespace gui
\r
182 } // end namespace irr
\r
184 #endif // _IRR_COMPILE_WITH_GUI_
\r