mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
render do main menu
This commit is contained in:
@@ -23,4 +23,27 @@
|
||||
|
||||
|
||||
#include "uibutton.h"
|
||||
#include "../fonts.h"
|
||||
#include "../font.h"
|
||||
|
||||
UIButton::UIButton(const std::string& text) :
|
||||
m_text(text)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
void UIButton::render()
|
||||
{
|
||||
m_boderedImage->draw(m_rect);
|
||||
|
||||
g_fonts.get("tibia-8px-antialised")->renderText(m_text, m_rect, ALIGN_CENTER);
|
||||
}
|
||||
|
@@ -27,13 +27,22 @@
|
||||
|
||||
#include "../prerequisites.h"
|
||||
#include "uielement.h"
|
||||
#include "../borderedimage.h"
|
||||
|
||||
class UIButton : public UIElement
|
||||
{
|
||||
public:
|
||||
UIButton(UIContainerPtr parent) : UIElement(parent) { }
|
||||
UIButton(const std::string& text);
|
||||
|
||||
void render();
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Button; }
|
||||
|
||||
private:
|
||||
std::string m_text;
|
||||
BorderedImagePtr m_boderedImage;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
||||
|
||||
#endif // UIBUTTON_H
|
||||
|
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "uicontainer.h"
|
||||
|
||||
UIContainer g_gui;
|
||||
UIContainerPtr g_gui(new UIContainer);
|
||||
|
||||
void UIContainer::addChild(UIElementPtr child)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ void UIContainer::setRect(const Rect& rect)
|
||||
{
|
||||
// update children rect
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
UIElementPtr child = (*it)->asUIElement();
|
||||
const UIElementPtr& child = (*it);
|
||||
|
||||
// transforme child rect
|
||||
Rect childRect = child->getRect();
|
||||
@@ -94,6 +94,24 @@ void UIContainer::moveTo(const Point& pos)
|
||||
|
||||
}
|
||||
|
||||
void UIContainer::render()
|
||||
{
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
const UIElementPtr& child = (*it);
|
||||
child->render();
|
||||
}
|
||||
}
|
||||
|
||||
void UIContainer::update(int ticks, int elapsedTicks)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool UIContainer::onInputEvent(InputEvent* event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void UIContainer::setActiveElement(UIElementPtr activeElement)
|
||||
{
|
||||
|
||||
|
@@ -33,7 +33,7 @@
|
||||
class UIContainer : public UIElement
|
||||
{
|
||||
public:
|
||||
UIContainer(UIContainerPtr parent = UIContainerPtr()) : UIElement(parent) { }
|
||||
UIContainer() : UIElement() { }
|
||||
virtual ~UIContainer() { }
|
||||
|
||||
virtual void addChild(UIElementPtr child);
|
||||
@@ -45,15 +45,16 @@ public:
|
||||
virtual void move(const Point& trans);
|
||||
virtual void moveTo(const Point& pos);
|
||||
|
||||
virtual void render() { }
|
||||
virtual void update(int ticks, int elapsedTicks) { }
|
||||
virtual bool onInputEvent(InputEvent *event) { return false; }
|
||||
virtual void render();
|
||||
virtual void update(int ticks, int elapsedTicks);
|
||||
virtual bool onInputEvent(InputEvent *event);
|
||||
|
||||
virtual void setActiveElement(UIElementPtr activeElement);
|
||||
UIElementPtr getActiveElement() const { return m_activeElement; }
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Container; }
|
||||
UIContainerPtr asUIContainer() { return UIContainerPtr(this); }
|
||||
|
||||
UIContainerPtr asUIContainer() { return std::static_pointer_cast<UIContainer>(shared_from_this()); }
|
||||
|
||||
protected:
|
||||
std::list<UIElementPtr> m_children;
|
||||
@@ -63,6 +64,6 @@ private:
|
||||
void onMove(const Point& pos);
|
||||
};
|
||||
|
||||
extern UIContainer g_gui;
|
||||
extern UIContainerPtr g_gui;
|
||||
|
||||
#endif // UICONTAINER_H
|
||||
|
@@ -23,14 +23,3 @@
|
||||
|
||||
|
||||
#include "uielement.h"
|
||||
#include "uicontainer.h"
|
||||
|
||||
UIElement::UIElement(UIContainerPtr parent) :
|
||||
m_visible(true),
|
||||
m_active(true)
|
||||
{
|
||||
if(parent)
|
||||
parent->addChild(asUIElement());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -36,10 +36,10 @@ typedef std::shared_ptr<UIContainer> UIContainerPtr;
|
||||
class UIElement;
|
||||
typedef std::shared_ptr<UIElement> UIElementPtr;
|
||||
|
||||
class UIElement
|
||||
class UIElement : public std::enable_shared_from_this<UIElement>
|
||||
{
|
||||
public:
|
||||
UIElement(UIContainerPtr parent);
|
||||
UIElement() { }
|
||||
virtual ~UIElement() { }
|
||||
|
||||
virtual void render() { }
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Element; }
|
||||
|
||||
UIElementPtr asUIElement() { return UIElementPtr(this); }
|
||||
UIElementPtr asUIElement() { return shared_from_this(); }
|
||||
|
||||
protected:
|
||||
UI::ControlType m_type;
|
||||
|
@@ -31,7 +31,7 @@
|
||||
class UILabel : public UIElement
|
||||
{
|
||||
public:
|
||||
UILabel(UIContainerPtr parent) : UIElement(parent) { }
|
||||
UILabel() { }
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Label; }
|
||||
};
|
||||
|
@@ -24,3 +24,23 @@
|
||||
|
||||
#include "uipanel.h"
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void UIPanel::render()
|
||||
{
|
||||
m_boderedImage->draw(m_rect);
|
||||
UIContainer::render();
|
||||
}
|
||||
|
@@ -27,13 +27,21 @@
|
||||
|
||||
#include "../prerequisites.h"
|
||||
#include "uicontainer.h"
|
||||
#include "../borderedimage.h"
|
||||
|
||||
class UIPanel : public UIContainer
|
||||
{
|
||||
public:
|
||||
UIPanel(UIContainerPtr parent) : UIContainer(parent) { }
|
||||
UIPanel();
|
||||
|
||||
void render();
|
||||
|
||||
virtual UI::ControlType getControlType() const { return UI::Panel; }
|
||||
|
||||
private:
|
||||
BorderedImagePtr m_boderedImage;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<UIPanel> UIPanelPtr;
|
||||
|
||||
#endif // UIPANEL_H
|
||||
|
Reference in New Issue
Block a user