tibia-client/src/framework/ui/uibuttonskin.cpp

42 lines
1.4 KiB
C++
Raw Normal View History

2011-07-13 23:12:36 +02:00
#include <global.h>
2011-04-17 21:14:24 +02:00
#include <graphics/fonts.h>
#include <ui/uibuttonskin.h>
#include <ui/uibutton.h>
2011-04-09 21:08:43 +02:00
2011-07-13 23:12:36 +02:00
void UIButtonSkin::load(OTMLNode* node)
2011-04-11 22:06:03 +02:00
{
UIElementSkin::load(node);
2011-07-17 02:13:53 +02:00
UIButtonStateSkinPtr defaultStateSkin = loadStateSkin(node);
m_statesSkin[UIButton::ButtonUp] = defaultStateSkin;
m_statesSkin[UIButton::ButtonDown] = defaultStateSkin;
m_statesSkin[UIButton::ButtonMouseOver] = defaultStateSkin;
if(OTMLNode* cnode = node->at("down state"))
m_statesSkin[UIButton::ButtonDown] = loadStateSkin(cnode);
2011-04-11 22:06:03 +02:00
2011-07-17 02:13:53 +02:00
if(OTMLNode* cnode = node->at("hover state"))
m_statesSkin[UIButton::ButtonMouseOver] = loadStateSkin(cnode);
}
2011-04-11 22:06:03 +02:00
2011-07-17 02:13:53 +02:00
UIButtonStateSkinPtr UIButtonSkin::loadStateSkin(OTMLNode* node)
{
UIButtonStateSkinPtr stateSkin = UIButtonStateSkinPtr(new UIButtonStateSkin);
stateSkin->image = loadImage(node);
stateSkin->textTranslate = node->readAt("text translate", Point());
stateSkin->textColor = node->readAt("font color", getFontColor());
return stateSkin;
2011-04-11 22:06:03 +02:00
}
2011-04-09 21:08:43 +02:00
void UIButtonSkin::draw(UIElement *element)
{
UIButton *button = static_cast<UIButton*>(element);
2011-07-17 02:13:53 +02:00
UIButtonStateSkinPtr stateSkin = m_statesSkin[button->getState()];
2011-04-11 06:08:56 +02:00
Rect textRect = button->getRect();
2011-07-17 02:13:53 +02:00
stateSkin->image->draw(element->getRect());
textRect.translate(stateSkin->textTranslate);
2011-04-11 06:08:56 +02:00
2011-07-17 02:13:53 +02:00
getFont()->renderText(button->getText(), textRect, AlignCenter, stateSkin->textColor);
2011-04-09 21:08:43 +02:00
}