2011-04-08 07:10:00 +02:00
|
|
|
#ifndef UICONTAINER_H
|
|
|
|
#define UICONTAINER_H
|
|
|
|
|
2011-07-13 23:12:36 +02:00
|
|
|
#include <global.h>
|
2011-04-17 21:14:24 +02:00
|
|
|
#include <ui/uielement.h>
|
2011-04-08 07:10:00 +02:00
|
|
|
|
|
|
|
class UIContainer : public UIElement
|
|
|
|
{
|
|
|
|
public:
|
2011-05-09 22:38:01 +02:00
|
|
|
UIContainer(UI::ElementType type = UI::Container) :
|
2011-04-17 00:06:42 +02:00
|
|
|
UIElement(type) { }
|
2011-04-08 07:10:00 +02:00
|
|
|
virtual ~UIContainer() { }
|
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
static UIContainerPtr create() { return UIContainerPtr(new UIContainer); }
|
2011-05-09 22:38:01 +02:00
|
|
|
virtual void destroy();
|
2011-04-23 05:28:23 +02:00
|
|
|
virtual void onLoad();
|
2011-04-11 22:06:03 +02:00
|
|
|
virtual void render();
|
|
|
|
virtual void onInputEvent(const InputEvent& event);
|
|
|
|
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Add an element, this must never be called from events loops
|
2011-05-03 00:48:41 +02:00
|
|
|
void addChild(const UIElementPtr& child);
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Remove an element, this must never be called from events loops
|
2011-05-03 00:48:41 +02:00
|
|
|
void removeChild(const UIElementPtr& child);
|
|
|
|
/// Check if has child
|
|
|
|
bool hasChild(const UIElementPtr& child);
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Find an element in this container by id
|
2011-04-10 09:34:52 +02:00
|
|
|
UIElementPtr getChildById(const std::string& id);
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Find an element in this container and in its children by id
|
2011-04-10 09:34:52 +02:00
|
|
|
UIElementPtr recursiveGetChildById(const std::string& id);
|
2011-05-12 00:16:11 +02:00
|
|
|
/// Find an element by position
|
|
|
|
UIElementPtr getChildByPos(const Point& pos);
|
2011-07-27 01:13:27 +02:00
|
|
|
UIElementPtr getChildBefore(const UIElementPtr& reference);
|
|
|
|
UIElementPtr getChildAfter(const UIElementPtr& reference);
|
2011-05-12 00:16:11 +02:00
|
|
|
/// Find an element in this container and in its children by position
|
|
|
|
UIElementPtr recursiveGetChildByPos(const Point& pos);
|
2011-05-03 00:48:41 +02:00
|
|
|
/// Get children
|
|
|
|
const std::list<UIElementPtr>& getChildren() const { return m_children; }
|
2011-04-22 15:49:46 +02:00
|
|
|
/// Pushs a child to the top
|
|
|
|
void pushChildToTop(const UIElementPtr& child);
|
2011-07-17 08:56:57 +02:00
|
|
|
/// Return number of children
|
2011-04-22 15:49:46 +02:00
|
|
|
int getChildCount() const { return m_children.size(); }
|
2011-04-08 07:10:00 +02:00
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Disable all children except the specified element
|
2011-05-03 00:48:41 +02:00
|
|
|
bool lockElement(const UIElementPtr& element);
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Renable all children
|
2011-05-03 00:48:41 +02:00
|
|
|
bool unlockElement(const UIElementPtr& element);
|
2011-04-17 00:06:42 +02:00
|
|
|
|
|
|
|
/// Focus next element
|
|
|
|
void focusNextElement();
|
|
|
|
/// Focus element
|
2011-05-03 00:48:41 +02:00
|
|
|
void setFocusedElement(const UIElementPtr& focusedElement);
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Get focused element
|
2011-04-11 06:08:56 +02:00
|
|
|
UIElementPtr getFocusedElement() const { return m_focusedElement; }
|
2011-04-08 07:10:00 +02:00
|
|
|
|
2011-05-09 22:38:01 +02:00
|
|
|
virtual UI::ElementType getElementType() const { return UI::Container; }
|
2011-07-27 01:13:27 +02:00
|
|
|
UIContainerPtr asUIContainer() { return std::static_pointer_cast<UIContainer>(shared_from_this()); }
|
2011-04-08 07:10:00 +02:00
|
|
|
|
2011-07-27 01:13:27 +02:00
|
|
|
virtual const char *getLuaTypeName() const { return "UIContainer"; }
|
2011-04-22 00:44:30 +02:00
|
|
|
|
2011-04-17 00:06:42 +02:00
|
|
|
/// Get root container (the container that contains everything)
|
2011-05-01 20:47:35 +02:00
|
|
|
static UIContainerPtr& getRoot();
|
2011-04-10 22:40:44 +02:00
|
|
|
|
2011-04-11 22:06:03 +02:00
|
|
|
private:
|
2011-04-08 07:10:00 +02:00
|
|
|
std::list<UIElementPtr> m_children;
|
2011-05-01 20:47:35 +02:00
|
|
|
std::list<UIElementPtr> m_lockedElements;
|
2011-04-11 06:08:56 +02:00
|
|
|
UIElementPtr m_focusedElement;
|
2011-04-08 07:10:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // UICONTAINER_H
|