2009-01-14 04:37:51 -08:00
|
|
|
// Copyright (C) 2002-2009 Nikolaus Gebhardt
|
2007-05-20 11:03:49 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#include "CGUIToolBar.h"
|
2007-07-25 22:30:19 -07:00
|
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
#include "IGUISkin.h"
|
|
|
|
#include "IGUIEnvironment.h"
|
|
|
|
#include "IVideoDriver.h"
|
|
|
|
#include "IGUIButton.h"
|
|
|
|
#include "IGUIFont.h"
|
|
|
|
#include "CGUIButton.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CGUIToolBar::CGUIToolBar(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
|
|
|
|
:IGUIToolBar(environment, parent, id, rectangle), ButtonX(5)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("CGUIToolBar");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// calculate position and find other menubars
|
|
|
|
s32 y = 0;
|
|
|
|
s32 parentwidth = 100;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
parentwidth = Parent->getAbsolutePosition().getWidth();
|
|
|
|
|
|
|
|
const core::list<IGUIElement*>& children = parent->getChildren();
|
2007-09-23 16:12:06 -07:00
|
|
|
core::list<IGUIElement*>::ConstIterator it = children.begin();
|
2007-05-20 11:03:49 -07:00
|
|
|
for (; it != children.end(); ++it)
|
|
|
|
{
|
|
|
|
core::rect<s32> r = (*it)->getAbsolutePosition();
|
|
|
|
if (r.UpperLeftCorner.X == 0 && r.UpperLeftCorner.Y <= y &&
|
|
|
|
r.LowerRightCorner.X == parentwidth)
|
|
|
|
y = r.LowerRightCorner.Y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
core::rect<s32> rr;
|
|
|
|
rr.UpperLeftCorner.X = 0;
|
|
|
|
rr.UpperLeftCorner.Y = y;
|
|
|
|
s32 height = Environment->getSkin()->getSize ( EGDS_MENU_HEIGHT );
|
|
|
|
|
|
|
|
/*IGUISkin* skin = Environment->getSkin();
|
|
|
|
IGUIFont* font = skin->getFont();
|
|
|
|
if (font)
|
|
|
|
{
|
|
|
|
s32 t = font->getDimension(L"A").Height + 5;
|
|
|
|
if (t > height)
|
|
|
|
height = t;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
rr.LowerRightCorner.X = parentwidth;
|
|
|
|
rr.LowerRightCorner.Y = rr.UpperLeftCorner.Y + height;
|
|
|
|
setRelativePosition(rr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-01 19:15:18 -07:00
|
|
|
//! called if an event happened.
|
2007-09-16 16:41:55 -07:00
|
|
|
bool CGUIToolBar::OnEvent(const SEvent& event)
|
2007-07-01 19:15:18 -07:00
|
|
|
{
|
2008-07-08 12:47:51 -07:00
|
|
|
if (IsEnabled)
|
2007-07-01 19:15:18 -07:00
|
|
|
{
|
2009-01-19 05:48:22 -08:00
|
|
|
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
2008-07-08 12:47:51 -07:00
|
|
|
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
|
|
|
{
|
|
|
|
if (AbsoluteClippingRect.isPointInside(core::position2di(event.MouseInput.X, event.MouseInput.Y)))
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-01 19:15:18 -07:00
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2008-07-08 12:47:51 -07:00
|
|
|
return IGUIElement::OnEvent(event);
|
2007-07-01 19:15:18 -07:00
|
|
|
}
|
2007-05-20 11:03:49 -07:00
|
|
|
|
2007-09-15 17:18:13 -07:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
//! draws the element and its children
|
|
|
|
void CGUIToolBar::draw()
|
|
|
|
{
|
|
|
|
if (!IsVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IGUISkin* skin = Environment->getSkin();
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
|
|
|
|
core::rect<s32> rect = AbsoluteRect;
|
2008-03-04 16:02:00 -08:00
|
|
|
core::rect<s32>* clip = &AbsoluteClippingRect;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
// draw frame
|
|
|
|
skin->draw3DToolBar(this, rect, clip);
|
|
|
|
|
|
|
|
IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Updates the absolute position.
|
|
|
|
void CGUIToolBar::updateAbsolutePosition()
|
|
|
|
{
|
|
|
|
if (Parent)
|
|
|
|
{
|
|
|
|
DesiredRect.UpperLeftCorner.X = 0;
|
|
|
|
DesiredRect.LowerRightCorner.X = Parent->getAbsolutePosition().getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
IGUIElement::updateAbsolutePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Adds a button to the tool bar
|
|
|
|
IGUIButton* CGUIToolBar::addButton(s32 id, const wchar_t* text,const wchar_t* tooltiptext,
|
2009-01-19 05:48:22 -08:00
|
|
|
video::ITexture* img, video::ITexture* pressed, bool isPushButton,
|
2007-05-20 11:03:49 -07:00
|
|
|
bool useAlphaChannel)
|
|
|
|
{
|
|
|
|
ButtonX += 3;
|
|
|
|
|
|
|
|
core::rect<s32> rectangle(ButtonX,2,0,0);
|
|
|
|
if ( img )
|
|
|
|
{
|
2009-01-19 05:48:22 -08:00
|
|
|
const core::dimension2du &size = img->getOriginalSize();
|
2007-05-20 11:03:49 -07:00
|
|
|
rectangle.LowerRightCorner.X = rectangle.UpperLeftCorner.X + size.Width + 8;
|
|
|
|
rectangle.LowerRightCorner.Y = rectangle.UpperLeftCorner.Y + size.Height + 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonX += rectangle.getWidth();
|
|
|
|
|
|
|
|
IGUIButton* button = new CGUIButton(Environment, this, id, rectangle);
|
|
|
|
button->drop();
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
button->setText(text);
|
|
|
|
|
|
|
|
if (tooltiptext)
|
|
|
|
button->setToolTipText(tooltiptext);
|
|
|
|
|
|
|
|
if (img)
|
|
|
|
button->setImage(img);
|
|
|
|
|
|
|
|
if (pressed)
|
|
|
|
button->setPressedImage(pressed);
|
|
|
|
|
|
|
|
if (isPushButton)
|
|
|
|
button->setIsPushButton(isPushButton);
|
|
|
|
|
|
|
|
if (useAlphaChannel)
|
|
|
|
button->setUseAlphaChannel(useAlphaChannel);
|
2009-01-19 05:48:22 -08:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
return button;
|
|
|
|
}
|
2009-01-19 05:48:22 -08:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|
2007-07-25 22:30:19 -07:00
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
2007-09-15 17:18:13 -07:00
|
|
|
|