2011-04-08 07:10:00 +02:00
|
|
|
#ifndef UIBUTTON_H
|
|
|
|
#define UIBUTTON_H
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#include "uiwidget.h"
|
2011-04-08 07:10:00 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
class UIButton : public UIWidget
|
2011-04-08 07:10:00 +02:00
|
|
|
{
|
2011-08-14 04:09:11 +02:00
|
|
|
struct ButtonStateStyle {
|
|
|
|
ImagePtr image;
|
|
|
|
Point textTranslate;
|
2011-08-20 22:30:41 +02:00
|
|
|
Color foregroundColor;
|
2011-08-14 04:09:11 +02:00
|
|
|
Color color;
|
2011-05-09 22:38:01 +02:00
|
|
|
};
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
public:
|
|
|
|
UIButton();
|
2011-04-08 11:50:26 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
static UIButtonPtr create();
|
2011-07-27 01:13:27 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
virtual void loadStyleFromOTML(const OTMLNodePtr& styleNode);
|
|
|
|
void loadStateStyle(ButtonStateStyle& stateStyle, const OTMLNodePtr& stateStyleNode);
|
|
|
|
virtual void render();
|
2011-04-09 21:07:35 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
void setOnClick(const SimpleCallback& onClick) { m_onClick = onClick; }
|
2011-04-10 22:40:44 +02:00
|
|
|
void setText(const std::string& text) { m_text = text; }
|
2011-08-14 04:09:11 +02:00
|
|
|
|
|
|
|
SimpleCallback getOnClick() const { return m_onClick; }
|
2011-05-03 00:48:41 +02:00
|
|
|
std::string getText() const { return m_text; }
|
2011-08-14 04:09:11 +02:00
|
|
|
ButtonState getState() const { return m_state; }
|
2011-04-10 22:40:44 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
UIButtonPtr asUIButton() { return std::static_pointer_cast<UIButton>(shared_from_this()); }
|
2011-04-08 11:50:26 +02:00
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
protected:
|
2011-08-14 16:09:26 +02:00
|
|
|
virtual void onHoverChange(UIHoverEvent& event);
|
|
|
|
virtual void onMousePress(UIMouseEvent& event);
|
|
|
|
virtual void onMouseRelease(UIMouseEvent& event);
|
2011-04-22 00:44:30 +02:00
|
|
|
|
2011-05-09 22:38:01 +02:00
|
|
|
ButtonState m_state;
|
2011-08-14 04:09:11 +02:00
|
|
|
ButtonStateStyle m_statesStyle[3];
|
|
|
|
SimpleCallback m_onClick;
|
|
|
|
std::string m_text;
|
2011-04-08 07:10:00 +02:00
|
|
|
};
|
|
|
|
|
2011-08-14 04:09:11 +02:00
|
|
|
#endif
|