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

109 lines
3.7 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 <ui/uiconstants.h>
#include <ui/uilayout.h>
#include <ui/uielementskin.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
2011-04-23 05:28:23 +02:00
typedef boost::function<void(UIElementPtr)> UIElementCallback;
2011-04-10 22:40:44 +02:00
class UIElement : public UILayout
2011-04-08 07:10:00 +02:00
{
public:
2011-04-09 01:20:44 +02:00
UIElement(UI::EElementType type = UI::Element);
2011-05-01 20:47:35 +02:00
virtual ~UIElement();
2011-04-08 07:10:00 +02:00
2011-04-17 00:06:42 +02:00
/// Destroy this element by removing it from its parent
void destroy();
2011-05-01 20:47:35 +02:00
virtual void internalOnDestroy();
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() { }
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);
2011-04-17 21:14:24 +02:00
void setSkin(const UIElementSkinPtr& skin);
const UIElementSkinPtr& getSkin() const { return m_skin; }
2011-04-09 01:20:44 +02:00
2011-04-11 22:06:03 +02:00
void setParent(UIContainerPtr parent) { m_parent = 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-04-11 06:08:56 +02:00
void setFocused(bool focused) { m_focused = focused; }
bool isFocused() const { return m_focused; }
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; }
2011-04-09 01:20:44 +02:00
UI::EElementType 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
2011-04-23 05:28:23 +02:00
void setOnDestroy(const UIElementCallback& onDestroyCallback) { m_onDestroyCallback = onDestroyCallback; }
void setOnLoad(const UIElementCallback& onLoadCallback) { m_onLoadCallback = onLoadCallback; }
private:
2011-04-09 01:20:44 +02:00
UI::EElementType m_type;
2011-04-09 19:18:50 +02:00
UIContainerWeakPtr m_parent;
2011-04-17 21:14:24 +02:00
UIElementSkinPtr m_skin;
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-04-11 06:08:56 +02:00
bool m_focused;
2011-04-23 05:28:23 +02:00
UIElementCallback m_onLoadCallback;
UIElementCallback m_onDestroyCallback;
2011-04-08 07:10:00 +02:00
};
#endif // UIELEMENT_H