tibia-client/src/framework/ui/uielement.h

142 lines
4.8 KiB
C
Raw Normal View History

2011-04-08 07:10:00 +02:00
#ifndef UIELEMENT_H
#define UIELEMENT_H
2011-07-13 23:12:36 +02:00
#include <global.h>
2011-04-17 21:14:24 +02:00
#include <core/input.h>
#include <script/luaobject.h>
2011-07-17 08:56:57 +02:00
#include <ui/uianchorlayout.h>
namespace UI {
enum ElementType {
Element = 0,
Container,
Panel,
Window,
Label,
TextEdit,
Button,
CheckBox,
LineDecoration
};
}
2011-04-09 19:18:50 +02:00
class UIElementSkin;
typedef std::shared_ptr<UIElementSkin> UIElementSkinPtr;
2011-04-08 07:10:00 +02:00
class UIContainer;
typedef std::shared_ptr<UIContainer> UIContainerPtr;
typedef std::weak_ptr<UIContainer> UIContainerWeakPtr;
2011-04-08 07:10:00 +02:00
class UIElement;
typedef std::shared_ptr<UIElement> UIElementPtr;
typedef std::weak_ptr<UIElement> UIElementWeakPtr;
2011-04-09 19:18:50 +02:00
class UIElement : public LuaObject
2011-04-08 07:10:00 +02:00
{
public:
UIElement(UI::ElementType type = UI::Element);
2011-05-01 20:47:35 +02:00
virtual ~UIElement();
2011-04-08 07:10:00 +02:00
static UIElementPtr create() { return UIElementPtr(new UIElement); }
void destroyLater();
virtual void destroy();
virtual void destroyCheck();
2011-04-17 00:06:42 +02:00
/// Draw element
2011-04-09 01:20:44 +02:00
virtual void render();
2011-04-17 00:06:42 +02:00
// events
2011-04-23 05:28:23 +02:00
virtual void onLoad();
2011-04-11 06:08:56 +02:00
virtual void onInputEvent(const InputEvent& event) { }
2011-04-15 04:13:53 +02:00
virtual void onFocusChange() { }
virtual void onRectUpdate() { }
2011-04-10 23:12:42 +02:00
UIElementPtr backwardsGetElementById(const std::string& id);
2011-04-10 09:34:52 +02:00
2011-04-16 21:46:31 +02:00
void moveTo(Point pos);
void setLocked(bool locked);
void setLayout(const UILayoutPtr& layout) { m_layout = layout; }
UILayoutPtr getLayout() const;
2011-07-17 08:56:57 +02:00
void applyDefaultSkin();
2011-04-17 21:14:24 +02:00
void setSkin(const UIElementSkinPtr& skin);
2011-05-03 00:48:41 +02:00
UIElementSkinPtr getSkin() const { return m_skin; }
2011-04-09 01:20:44 +02:00
2011-05-03 00:48:41 +02:00
void setParent(UIContainerPtr parent);
2011-04-09 19:18:50 +02:00
UIContainerPtr getParent() const { return m_parent.lock(); }
void setId(const std::string& id) { m_id = id; }
const std::string& getId() const { return m_id; }
2011-04-08 07:10:00 +02:00
void setEnabled(bool enabled) { m_enabled = enabled; }
bool isEnabled() const { return m_enabled; }
2011-04-08 07:10:00 +02:00
2011-05-03 00:48:41 +02:00
void setFocused(bool focused);
bool isFocused() const;
2011-04-11 06:08:56 +02:00
2011-05-13 01:24:57 +02:00
void setMouseOver(bool mouseOver) { m_mouseOver = mouseOver; }
bool isMouseOver() const { return m_mouseOver; }
2011-04-09 19:18:50 +02:00
void setVisible(bool visible) { m_visible = visible; }
2011-04-08 07:10:00 +02:00
bool isVisible() const { return m_visible; }
2011-04-16 21:46:31 +02:00
virtual bool isFocusable() const { return false; }
UI::ElementType getElementType() const { return m_type; }
2011-04-08 07:10:00 +02:00
UIElementPtr asUIElement() { return std::static_pointer_cast<UIElement>(shared_from_this()); }
2011-04-10 09:34:52 +02:00
virtual UIContainerPtr asUIContainer() { return UIContainerPtr(); }
virtual const char *getLuaTypeName() const { return "UIElement"; }
2011-04-09 19:18:50 +02:00
void setSize(const Size& size);
2011-07-17 08:56:57 +02:00
void setSize(int width, int height) { setSize(Size(width, height)); }
Size getSize() const { return m_rect.size(); }
void setWidth(int width) { setSize(width, getSize().height()); }
int getWidth() const { return getSize().width(); }
void setHeight(int height) { setSize(getSize().width(), height); }
int getHeight() const { return getSize().height(); }
/// Set the layout rect, always absolute position
void setRect(const Rect& rect);
/// Get layout size, it always return the absolute position
Rect getRect() const { return m_rect; }
2011-07-17 08:56:57 +02:00
void setMargin(int top, int right, int bottom, int left) { m_marginLeft = left; m_marginRight = right; m_marginTop = top; m_marginBottom = bottom; getLayout()->recalculateElementLayout(asUIElement()); }
void setMargin(int vertical, int horizontal) { m_marginLeft = m_marginRight = horizontal; m_marginTop = m_marginBottom = vertical; getLayout()->recalculateElementLayout(asUIElement()); }
void setMargin(int margin) { m_marginLeft = m_marginRight = m_marginTop = m_marginBottom = margin; getLayout()->recalculateElementLayout(asUIElement()); }
void setMarginLeft(int margin) { m_marginLeft = margin; getLayout()->recalculateElementLayout(asUIElement()); }
void setMarginRight(int margin) { m_marginRight = margin; getLayout()->recalculateElementLayout(asUIElement()); }
void setMarginTop(int margin) { m_marginTop = margin; getLayout()->recalculateElementLayout(asUIElement()); }
void setMarginBottom(int margin) { m_marginBottom = margin; getLayout()->recalculateElementLayout(asUIElement()); }
int getMarginLeft() const { return m_marginLeft; }
int getMarginRight() const { return m_marginRight; }
int getMarginTop() const { return m_marginTop; }
int getMarginBottom() const { return m_marginBottom; }
2011-07-17 08:56:57 +02:00
void centerIn(const std::string& targetId);
void addAnchor(AnchorPoint edge, const std::string& targetId, AnchorPoint targetEdge);
2011-07-17 08:56:57 +02:00
private:
UI::ElementType m_type;
2011-04-09 19:18:50 +02:00
UIContainerWeakPtr m_parent;
2011-04-17 21:14:24 +02:00
UIElementSkinPtr m_skin;
UILayoutPtr m_layout;
2011-04-09 19:18:50 +02:00
std::string m_id;
2011-04-08 07:10:00 +02:00
bool m_visible;
bool m_enabled;
2011-05-13 01:24:57 +02:00
bool m_mouseOver;
bool m_destroyed;
Rect m_rect;
int m_marginLeft;
int m_marginRight;
int m_marginTop;
int m_marginBottom;
2011-04-08 07:10:00 +02:00
};
#endif // UIELEMENT_H