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

139 lines
5.1 KiB
C
Raw Normal View History

2011-04-08 07:10:00 +02:00
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef UIELEMENT_H
#define UIELEMENT_H
2011-04-17 21:14:24 +02:00
#include <prerequisites.h>
#include <core/input.h>
#include <script/scriptable.h>
2011-04-17 21:14:24 +02:00
#include <ui/uiconstants.h>
#include <ui/uielementskin.h>
#include <ui/uilayout.h>
2011-04-09 19:18:50 +02:00
class UIElementSkin;
2011-04-08 07:10:00 +02:00
class UIContainer;
2011-04-11 23:22:01 +02:00
typedef boost::shared_ptr<UIContainer> UIContainerPtr;
typedef boost::weak_ptr<UIContainer> UIContainerWeakPtr;
2011-04-08 07:10:00 +02:00
class UIElement;
2011-04-11 23:22:01 +02:00
typedef boost::shared_ptr<UIElement> UIElementPtr;
typedef boost::weak_ptr<UIElement> UIElementWeakPtr;
2011-04-09 19:18:50 +02:00
class UIElement : public Scriptable
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
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 setLayout(const UILayoutPtr& layout) { m_layout = layout; }
UILayoutPtr getLayout() const;
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
2011-04-11 23:22:01 +02:00
UIElementPtr asUIElement() { return boost::static_pointer_cast<UIElement>(shared_from_this()); }
2011-04-10 09:34:52 +02:00
virtual UIContainerPtr asUIContainer() { return UIContainerPtr(); }
2011-04-22 00:44:30 +02:00
virtual const char *getScriptableName() const { return "UIElement"; }
2011-04-09 19:18:50 +02:00
void setSize(const Size& size);
Size getSize() { return m_rect.size(); }
/// 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; }
// margins
void setMargin(int top, int left, int bottom, int right) { m_marginLeft = left; m_marginRight = right; m_marginTop = top; m_marginBottom = bottom; getLayout()->recalculateElementLayout(asUIElement()); }
void setMargin(int horizontal, int vertical) { 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; }
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;
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