diff --git a/include/GUIManager/GUIManager.h b/include/GUIManager/GUIManager.h index 0e2c5a9..97634fa 100644 --- a/include/GUIManager/GUIManager.h +++ b/include/GUIManager/GUIManager.h @@ -22,11 +22,10 @@ extern const std::string CONST_TAPDOWN_SIGNAL_NAME; typedef boost::variant TSignalParam; -struct TWidgetStruct +struct TWidgetDataStruct { std::string Name; std::string GroupName; - int Order; bool IsMouseDown; @@ -34,10 +33,9 @@ struct TWidgetStruct std::map>> SignalMap; - TWidgetStruct(const std::string& name, const std::string& groupName, std::shared_ptr widget, int order = 0) + TWidgetDataStruct(const std::string& name, const std::string& groupName, std::shared_ptr widget) : Name(name) , GroupName(groupName) - , Order(order) , IsMouseDown(false) , Widget(widget) { @@ -47,30 +45,63 @@ struct TWidgetStruct SignalMap[CONST_DRAG_SIGNAL_NAME] = std::shared_ptr>(new boost::signal()); } - TWidgetStruct(const TWidgetStruct& widgetStruct) + TWidgetDataStruct(const TWidgetDataStruct& widgetStruct) { Name = widgetStruct.Name; Widget = widgetStruct.Widget; GroupName = widgetStruct.GroupName; IsMouseDown = widgetStruct.IsMouseDown; - Order = widgetStruct.Order; SignalMap = widgetStruct.SignalMap; } - TWidgetStruct& operator=(const TWidgetStruct& widgetStruct) + TWidgetDataStruct& operator=(const TWidgetDataStruct& widgetStruct) { //Self-assignment is ok Name = widgetStruct.Name; Widget = widgetStruct.Widget; GroupName = widgetStruct.GroupName; IsMouseDown = widgetStruct.IsMouseDown; - Order = widgetStruct.Order; 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() { } @@ -158,8 +189,6 @@ public: void DeleteWidgetOnUpdate(const std::string& name); void DeleteWidgetGroupOnUpdate(const std::string& groupName); - void DeleteWidgetLaterOnUpdate(const std::string& name); - void DeleteWidgetGroupLaterOnUpdate(const std::string& groupName); void Update(cardinal dt); void Draw(); diff --git a/src/GUIManager/GUIManager.cpp b/src/GUIManager/GUIManager.cpp index a3d5b34..4f32d99 100644 --- a/src/GUIManager/GUIManager.cpp +++ b/src/GUIManager/GUIManager.cpp @@ -48,7 +48,7 @@ void TGUIManager::AddWidget(std::shared_ptr widgetAnc { for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++) { - if (i->Name == name) + if (i->WidgetData->Name == name) { return; } @@ -61,7 +61,7 @@ void TGUIManager::DeleteWidget(std::string name) { for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++) { - if (i->Name == name) + if (i->WidgetData->Name == name) { WidgetArr.erase(i); return; @@ -75,7 +75,7 @@ void TGUIManager::DeleteWidgetGroup(std::string groupName) for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end();) { widgetErased = false; - if (i->GroupName == groupName) + if (i->WidgetData->GroupName == groupName) { i = WidgetArr.erase(i); widgetErased = true; @@ -90,31 +90,14 @@ void TGUIManager::DeleteWidgetGroup(std::string groupName) void TGUIManager::DeleteWidgetOnUpdate(const std::string& name) { - //PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidget, this, name)); - PerformInMainThreadAsync(boost::bind(&TGUIManager::DeleteWidget, this, name)); - + PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidget, this, name)); } void TGUIManager::DeleteWidgetGroupOnUpdate(const std::string& groupName) { - //PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName)); - PerformInMainThreadAsync(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName)); - + PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName)); } -void TGUIManager::DeleteWidgetLaterOnUpdate(const std::string& name) -{ - PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidget, this, name)); -} - -void TGUIManager::DeleteWidgetGroupLaterOnUpdate(const std::string& groupName) -{ - PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName)); -} - - - - void TGUIManager::AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask) { WidgetTrasfromTaskList.push_back(widgetTransformTask); @@ -130,12 +113,12 @@ void TGUIManager::Update(cardinal dt) { //i->Widget->Update(dt); - if (i->IsMouseDown) + if (i->WidgetData->IsMouseDown) { - signalMap.push_back((i->SignalMap[CONST_HOLD_SIGNAL_NAME])); + signalMap.push_back((i->WidgetData->SignalMap[CONST_HOLD_SIGNAL_NAME])); } - i->Widget->Update(dt); + i->WidgetData->Widget->Update(dt); } @@ -182,7 +165,7 @@ void TGUIManager::Update(cardinal dt) for (TWidgetArr::iterator j = WidgetArr.begin(); j != WidgetArr.end(); ++j) { - if (j->GroupName == i->GroupName) + if (j->WidgetData->GroupName == i->GroupName) { MoveWidgetByIterator(j, moveDistance); } @@ -213,7 +196,7 @@ void TGUIManager::Draw() TRenderPairList::iterator j; - for (j = i->Widget->TriangleListVector.begin(); j != i->Widget->TriangleListVector.end(); ++j) + for (j = i->WidgetData->Widget->TriangleListVector.begin(); j != i->WidgetData->Widget->TriangleListVector.end(); ++j) { TRenderParamsSetter paramSetter(j->first); @@ -232,7 +215,7 @@ TWidgetArr::iterator TGUIManager::FindWidgetInArr(const std::string& widgetName) for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i) { - if (i->Name == widgetName) + if (i->WidgetData->Name == widgetName) { break; } @@ -248,13 +231,13 @@ TWidgetArr::iterator TGUIManager::FindWidgetInArr(const std::string& widgetName) void TGUIManager::MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift) { - widget->Widget->LeftBottomPos += shift; + widget->WidgetData->Widget->LeftBottomPos += shift; std::vector::iterator i; TRenderPairList::iterator itr; - for (itr = widget->Widget->TriangleListVector.begin(); itr != widget->Widget->TriangleListVector.end(); ++itr) + for (itr = widget->WidgetData->Widget->TriangleListVector.begin(); itr != widget->WidgetData->Widget->TriangleListVector.end(); ++itr) { std::vector& vertexCoordVec = itr->second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB]; @@ -278,7 +261,7 @@ void TGUIManager::MoveWidgetGroup(const std::string& widgetGroupName, const std: { for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); ++i) { - if (i->GroupName == widgetGroupName && i->Name != exceptWidget) + if (i->WidgetData->GroupName == widgetGroupName && i->WidgetData->Name != exceptWidget) { MoveWidgetByIterator(i, shift); } @@ -302,14 +285,14 @@ void TGUIManager::OnMouseDown(vec2 pos, int touchNumber) for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) { - if (i->Widget->CheckClick(pos)) + if (i->WidgetData->Widget->CheckClick(pos)) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); - i->Widget->OnTapDown(pos); - i->IsMouseDown = true; + i->WidgetData->Widget->OnTapDown(pos); + i->WidgetData->IsMouseDown = true; - signalMap.push_back((i->SignalMap[CONST_TAPDOWN_SIGNAL_NAME])); + signalMap.push_back((i->WidgetData->SignalMap[CONST_TAPDOWN_SIGNAL_NAME])); if (! isTransparentForInput) { @@ -340,13 +323,13 @@ void TGUIManager::OnMouseUp(vec2 pos, int touchNumber) for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) { - if (i->Widget->CheckClick(pos)) + if (i->WidgetData->Widget->CheckClick(pos)) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); - i->Widget->OnTapUp(pos); - i->IsMouseDown = false; + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); + i->WidgetData->Widget->OnTapUp(pos); + i->WidgetData->IsMouseDown = false; - signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME])); + signalMap.push_back((i->WidgetData->SignalMap[CONST_CLICK_SIGNAL_NAME])); if (! isTransparentForInput) { @@ -378,11 +361,11 @@ void TGUIManager::OnMouseUp(vec2 pos, int touchNumber) for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) { - if (i->Widget->CheckClick(pos)) + if (i->WidgetData->Widget->CheckClick(pos)) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); - i->Widget->OnTapUpAfterMove(pos); - i->IsMouseDown = false; + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); + i->WidgetData->Widget->OnTapUpAfterMove(pos); + i->WidgetData->IsMouseDown = false; //signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME])); //Do not call signals here @@ -393,11 +376,11 @@ void TGUIManager::OnMouseUp(vec2 pos, int touchNumber) } } - if (i->Widget->CheckClick(LastTapPos[touchNumber]) && !i->Widget->CheckClick(pos)) + if (i->WidgetData->Widget->CheckClick(LastTapPos[touchNumber]) && !i->WidgetData->Widget->CheckClick(pos)) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); - i->Widget->OnTapUpAfterMoveOut(pos); - i->IsMouseDown = false; + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); + i->WidgetData->Widget->OnTapUpAfterMoveOut(pos); + i->WidgetData->IsMouseDown = false; //signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME])); //Do not call signals here @@ -438,13 +421,13 @@ void TGUIManager::OnMove(vec2 shift, int touchNumber) for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) { - if (!moveIsProcessed && i->Widget->CheckClick(LastTapPos[touchNumber]-TotalShift[touchNumber])) + if (!moveIsProcessed && i->WidgetData->Widget->CheckClick(LastTapPos[touchNumber]-TotalShift[touchNumber])) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); - i->Widget->OnMove(shift); + i->WidgetData->Widget->OnMove(shift); - signalMap.push_back((i->SignalMap[CONST_DRAG_SIGNAL_NAME])); + signalMap.push_back((i->WidgetData->SignalMap[CONST_DRAG_SIGNAL_NAME])); if (! isTransparentForInput) { @@ -462,12 +445,12 @@ void TGUIManager::OnMove(vec2 shift, int touchNumber) for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) { - if (!moveOutIsProcessed && i->Widget->CheckClick(LastTapPos[touchNumber]) && !i->Widget->CheckClick(LastTapPos[touchNumber]-TotalShift[touchNumber])) + if (!moveOutIsProcessed && i->WidgetData->Widget->CheckClick(LastTapPos[touchNumber]) && !i->WidgetData->Widget->CheckClick(LastTapPos[touchNumber]-TotalShift[touchNumber])) { - bool isTransparentForInput = i->Widget->IsTransparentForInput(); + bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput(); - i->Widget->OnMoveOut(); - i->IsMouseDown = false; + i->WidgetData->Widget->OnMoveOut(); + i->WidgetData->IsMouseDown = false; if (! isTransparentForInput) { moveOutIsProcessed = true; @@ -529,7 +512,7 @@ void TGUIManager::PrintWidgetList() for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i) { - std::string widgetRow = i->Name + " (" + tostr(i->Widget->LeftBottomPos.v[0]) + ", " + tostr(i->Widget->LeftBottomPos.v[1]) + ")"; + std::string widgetRow = i->WidgetData->Name + " (" + tostr(i->WidgetData->Widget->LeftBottomPos.v[0]) + ", " + tostr(i->WidgetData->Widget->LeftBottomPos.v[1]) + ")"; Console->PrintImmediate(widgetRow); } } @@ -540,7 +523,7 @@ std::shared_ptr> TGUIManager::GetOnClickSigna TWidgetArr::iterator i = FindWidgetInArr(widgetName); - return i->SignalMap[CONST_CLICK_SIGNAL_NAME]; + return i->WidgetData->SignalMap[CONST_CLICK_SIGNAL_NAME]; } @@ -549,7 +532,7 @@ std::shared_ptr> TGUIManager::GetOnHoldSignal TWidgetArr::iterator i = FindWidgetInArr(widgetName); - return i->SignalMap[CONST_HOLD_SIGNAL_NAME]; + return i->WidgetData->SignalMap[CONST_HOLD_SIGNAL_NAME]; } @@ -558,7 +541,7 @@ std::shared_ptr> TGUIManager::GetOnTapDownSig TWidgetArr::iterator i = FindWidgetInArr(widgetName); - return i->SignalMap[CONST_TAPDOWN_SIGNAL_NAME]; + return i->WidgetData->SignalMap[CONST_TAPDOWN_SIGNAL_NAME]; } @@ -567,12 +550,12 @@ std::shared_ptr> TGUIManager::GetSignal(const TWidgetArr::iterator i = FindWidgetInArr(widgetName); - if (i->SignalMap.count(signalName) == 0) + if (i->WidgetData->SignalMap.count(signalName) == 0) { throw ErrorToLog("Illegal signal: "+signalName); } - return i->SignalMap[signalName]; + return i->WidgetData->SignalMap[signalName]; } void TGUIManager::SQ_MoveWidget(const SQChar *widgetName, float x, float y)