#ifndef GUIMANAGER_H_INCLUDED #define GUIMANAGER_H_INCLUDED #include "include/Render/RenderMisc.h" #include "include/GUIManager/ButtonWidget.h" #include "include/GUIManager/KeyboardWidget.h" #include "include/GUIManager/WidgetXmlParsers.h" #include "include/Utils/Utils.h" #include "include/ScriptManager/ScriptManager.h" #include "boost/variant.hpp" #include "boost/thread.hpp" namespace SE { extern const std::string CONST_HOLD_SIGNAL_NAME; extern const std::string CONST_CLICK_SIGNAL_NAME; extern const std::string CONST_DRAG_SIGNAL_NAME; extern const std::string CONST_TAPDOWN_SIGNAL_NAME; typedef boost::variant TSignalParam; struct TWidgetDataStruct { std::string Name; std::string GroupName; bool IsMouseDown; std::shared_ptr Widget; std::map>> SignalMap; TWidgetDataStruct(const std::string& name, const std::string& groupName, std::shared_ptr widget) : Name(name) , GroupName(groupName) , IsMouseDown(false) , Widget(widget) { SignalMap[CONST_HOLD_SIGNAL_NAME] = std::shared_ptr>(new boost::signal()); SignalMap[CONST_CLICK_SIGNAL_NAME] = std::shared_ptr>(new boost::signal()); SignalMap[CONST_TAPDOWN_SIGNAL_NAME] = std::shared_ptr>(new boost::signal()); SignalMap[CONST_DRAG_SIGNAL_NAME] = std::shared_ptr>(new boost::signal()); } TWidgetDataStruct(const TWidgetDataStruct& widgetStruct) { Name = widgetStruct.Name; Widget = widgetStruct.Widget; GroupName = widgetStruct.GroupName; IsMouseDown = widgetStruct.IsMouseDown; SignalMap = widgetStruct.SignalMap; } TWidgetDataStruct& operator=(const TWidgetDataStruct& widgetStruct) { //Self-assignment is ok Name = widgetStruct.Name; Widget = widgetStruct.Widget; GroupName = widgetStruct.GroupName; IsMouseDown = widgetStruct.IsMouseDown; SignalMap = widgetStruct.SignalMap; return *this; } ~TWidgetDataStruct() { } }; struct TWidgetStruct { boost::shared_ptr WidgetData; int Order; TWidgetStruct(const std::string& name, const std::string& groupName, std::shared_ptr widget, int order = 0) : WidgetData(new TWidgetDataStruct(name, groupName, widget)) , Order(order) { } TWidgetStruct(const TWidgetStruct& widgetStruct) { WidgetData = widgetStruct.WidgetData; Order = widgetStruct.Order; } TWidgetStruct& operator=(const TWidgetStruct& widgetStruct) { if (&widgetStruct != this) { WidgetData = widgetStruct.WidgetData; Order = widgetStruct.Order; } return *this; } ~TWidgetStruct() { } //For sorting bool operator>(const TWidgetStruct& widget) const { return Order > widget.Order; } bool operator<(const TWidgetStruct& widget) const { return Order < widget.Order; } bool operator==(const TWidgetStruct& widget) const { return Order == widget.Order; } }; struct TWidgetTransformTask { std::string GroupName; vec2 PosTo; int CurrentTime; int TotalTime; enum TMoveStyle { MS_LINEAR, MS_SQR, MS_SQRT } MoveStyle; TWidgetTransformTask(const std::string& groupName, vec2 posTo, int totalTime, int currentTime, TMoveStyle moveStyle) : GroupName(groupName) , PosTo(posTo) , TotalTime(totalTime) , CurrentTime(currentTime) , MoveStyle(moveStyle) { } }; typedef std::list TWidgetTrasfromTaskList; typedef std::vector TWidgetArr; class TGUIManager : public TFunctionBinderInterface { protected: TWidgetArr WidgetArr; TWidgetTrasfromTaskList WidgetTrasfromTaskList; void MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift); TWidgetArr::iterator FindWidgetInArr(const std::string& widgetName); std::map LastTapPos; std::map TotalShift; boost::mutex WidgetListMutex; public: bool KeyboardIsOnScreen; boost::signal KeyPressedSignal; boost::signal SetTextSignal; boost::signal OnKeyboardShowSignal; boost::signal OnKeyboardHideSignal; TGUIManager(); ~TGUIManager(); void AddWidget(std::shared_ptr widgetAncestor, const std::string& name, const std::string& groupName, int order = 0); void DeleteWidget(std::string name); void DeleteWidgetGroup(std::string groupName); void DeleteWidgetOnUpdate(const std::string& name); void DeleteWidgetGroupOnUpdate(const std::string& groupName); void Update(cardinal dt); void Draw(); void MoveWidget(const std::string& widgetName, vec2 shift); void MoveWidgetGroup(const std::string& widgetGroupName, const std::string& exceptWidget, vec2 shift); void AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask); void OnMouseDown(vec2 pos, int touchNumber); void OnMouseUp(vec2 pos, int touchNumber); void OnMouseUpAfterMove(vec2 pos, int touchNumber); void OnMove(vec2 shift, int touchNumber); void ShowKeyboard(const std::string text = ""); void HideKeyboard(); bool IsKeyboardOnScreen(); void PrintWidgetList(); std::shared_ptr> GetOnClickSignal(const std::string& widgetName); std::shared_ptr> GetOnHoldSignal(const std::string& widgetName); std::shared_ptr> GetSignal(const std::string& signalName, const std::string& widgetName); std::shared_ptr> GetOnTapDownSignal(const std::string& widgetName); //TFunctionBinderInterface implementation: void SQ_MoveWidget(const SQChar *widgetName, float x, float y); virtual void BindFunctions(); }; } //namespace SE #endif