image class

This commit is contained in:
Eduardo Bart
2011-04-08 15:29:59 -03:00
parent 77b31e425a
commit f54ef6401d
13 changed files with 200 additions and 54 deletions

View File

@@ -27,23 +27,24 @@
#include "../font.h"
UIButton::UIButton(const std::string& text) :
m_text(text)
m_text(text),
m_state(UI::ButtonUp)
{
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png"));
m_boderedImage->setTexCoords(Rect(45,139,1,18),
Rect(130,139,1,18),
Rect(46,138,84,1),
Rect(46,157,84,1),
Rect(45,138,1,1),
Rect(130,138,1,1),
Rect(45,157,1,1),
Rect(130,157,1,1),
Rect(46,139,84,18));
m_imageButtonUp = ImagePtr(new BorderedImage("ui.png",
Rect(45,139,1,18),
Rect(130,139,1,18),
Rect(46,138,84,1),
Rect(46,157,84,1),
Rect(45,138,1,1),
Rect(130,138,1,1),
Rect(45,157,1,1),
Rect(130,157,1,1),
Rect(46,139,84,18)));
}
void UIButton::render()
{
m_boderedImage->draw(m_rect);
m_imageButtonUp->draw(m_rect);
g_fonts.get("tibia-8px-antialised")->renderText(m_text, m_rect, ALIGN_CENTER);
}

View File

@@ -36,11 +36,15 @@ public:
void render();
virtual UI::ControlType getControlType() const { return UI::Button; }
virtual UI::EControlType getControlType() const { return UI::Button; }
private:
std::string m_text;
BorderedImagePtr m_boderedImage;
UI::EButtonState m_state;
ImagePtr m_imageButtonUp;
ImagePtr m_imageButtonDown;
ImagePtr m_imageButtonOver;
};
typedef std::shared_ptr<UIButton> UIButtonPtr;

View File

@@ -26,32 +26,32 @@
#define UICONSTANTS_H
namespace UI {
enum ButtonState
enum EButtonState
{
Up,
Down,
MouseOver
ButtonUp,
ButtonDown,
ButtonMouseOver
};
enum ButtonEvent
enum EButtonEvent
{
PressUp,
PressDown,
EnterMouseOver,
LeaveMouseOver
ButtonPressUp,
ButtonPressDown,
ButtonEnterMouseOver,
ButtonLeaveMouseOver
};
enum MessageBoxFlags
enum EMessageBoxFlags
{
Ok = 1 << 0,
Cancel = 1 << 1,
Yes = 1 << 2,
No = 1 << 3,
OkCancel = Ok | Cancel,
YesNo = Yes | No
MessageBoxOk = 1 << 0,
MessageBoxCancel = 1 << 1,
MessageBoxYes = 1 << 2,
MessageBoxNo = 1 << 3,
MessageBoxOkCancel = MessageBoxOk | MessageBoxCancel,
MessageBoxYesNo = MessageBoxYes | MessageBoxNo
};
enum ControlType
enum EControlType
{
Element,
Container,

View File

@@ -52,7 +52,7 @@ public:
virtual void setActiveElement(UIElementPtr activeElement);
UIElementPtr getActiveElement() const { return m_activeElement; }
virtual UI::ControlType getControlType() const { return UI::Container; }
virtual UI::EControlType getControlType() const { return UI::Container; }
UIContainerPtr asUIContainer() { return std::static_pointer_cast<UIContainer>(shared_from_this()); }

View File

@@ -61,12 +61,12 @@ public:
virtual void setVisible(bool visible) { m_visible = visible; }
bool isVisible() const { return m_visible; }
virtual UI::ControlType getControlType() const { return UI::Element; }
virtual UI::EControlType getControlType() const { return UI::Element; }
UIElementPtr asUIElement() { return shared_from_this(); }
protected:
UI::ControlType m_type;
UI::EControlType m_type;
UIContainerPtr m_parent;
Rect m_rect;
std::string m_name;

View File

@@ -33,7 +33,7 @@ class UILabel : public UIElement
public:
UILabel() { }
virtual UI::ControlType getControlType() const { return UI::Label; }
virtual UI::EControlType getControlType() const { return UI::Label; }
};
#endif // UILABEL_H

View File

@@ -27,16 +27,16 @@
UIPanel::UIPanel()
{
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png"));
m_boderedImage->setTexCoords(Rect(0,214,5,32),
Rect(6,214,5,32),
Rect(43,214,32,5),
Rect(43,220,32,5),
Rect(43,225,5,5),
Rect(49,225,5,5),
Rect(43,230,5,5),
Rect(48,231,5,5),
Rect(11,214,32,32));
m_boderedImage = BorderedImagePtr(new BorderedImage("ui.png",
Rect(0,214,5,32),
Rect(6,214,5,32),
Rect(43,214,32,5),
Rect(43,220,32,5),
Rect(43,225,5,5),
Rect(49,225,5,5),
Rect(43,230,5,5),
Rect(48,231,5,5),
Rect(11,214,32,32)));
}
void UIPanel::render()

View File

@@ -36,7 +36,7 @@ public:
void render();
virtual UI::ControlType getControlType() const { return UI::Panel; }
virtual UI::EControlType getControlType() const { return UI::Panel; }
private:
BorderedImagePtr m_boderedImage;