minor refactoring

This commit is contained in:
Vladislav Khorev 2014-01-07 10:35:42 +00:00
parent 91638909f6
commit 67bf868991
2 changed files with 85 additions and 73 deletions

View File

@ -22,11 +22,10 @@ extern const std::string CONST_TAPDOWN_SIGNAL_NAME;
typedef boost::variant<cardinal, vec2> TSignalParam; typedef boost::variant<cardinal, vec2> TSignalParam;
struct TWidgetStruct struct TWidgetDataStruct
{ {
std::string Name; std::string Name;
std::string GroupName; std::string GroupName;
int Order;
bool IsMouseDown; bool IsMouseDown;
@ -34,10 +33,9 @@ struct TWidgetStruct
std::map<std::string, std::shared_ptr<boost::signal<void (TSignalParam)>>> SignalMap; std::map<std::string, std::shared_ptr<boost::signal<void (TSignalParam)>>> SignalMap;
TWidgetStruct(const std::string& name, const std::string& groupName, std::shared_ptr<TInstancingWidgetAncestor> widget, int order = 0) TWidgetDataStruct(const std::string& name, const std::string& groupName, std::shared_ptr<TInstancingWidgetAncestor> widget)
: Name(name) : Name(name)
, GroupName(groupName) , GroupName(groupName)
, Order(order)
, IsMouseDown(false) , IsMouseDown(false)
, Widget(widget) , Widget(widget)
{ {
@ -47,30 +45,63 @@ struct TWidgetStruct
SignalMap[CONST_DRAG_SIGNAL_NAME] = std::shared_ptr<boost::signal<void (TSignalParam)>>(new boost::signal<void (TSignalParam)>()); SignalMap[CONST_DRAG_SIGNAL_NAME] = std::shared_ptr<boost::signal<void (TSignalParam)>>(new boost::signal<void (TSignalParam)>());
} }
TWidgetStruct(const TWidgetStruct& widgetStruct) TWidgetDataStruct(const TWidgetDataStruct& widgetStruct)
{ {
Name = widgetStruct.Name; Name = widgetStruct.Name;
Widget = widgetStruct.Widget; Widget = widgetStruct.Widget;
GroupName = widgetStruct.GroupName; GroupName = widgetStruct.GroupName;
IsMouseDown = widgetStruct.IsMouseDown; IsMouseDown = widgetStruct.IsMouseDown;
Order = widgetStruct.Order;
SignalMap = widgetStruct.SignalMap; SignalMap = widgetStruct.SignalMap;
} }
TWidgetStruct& operator=(const TWidgetStruct& widgetStruct) TWidgetDataStruct& operator=(const TWidgetDataStruct& widgetStruct)
{ {
//Self-assignment is ok //Self-assignment is ok
Name = widgetStruct.Name; Name = widgetStruct.Name;
Widget = widgetStruct.Widget; Widget = widgetStruct.Widget;
GroupName = widgetStruct.GroupName; GroupName = widgetStruct.GroupName;
IsMouseDown = widgetStruct.IsMouseDown; IsMouseDown = widgetStruct.IsMouseDown;
Order = widgetStruct.Order;
SignalMap = widgetStruct.SignalMap; SignalMap = widgetStruct.SignalMap;
return *this; return *this;
} }
~TWidgetDataStruct()
{
}
};
struct TWidgetStruct
{
boost::shared_ptr<TWidgetDataStruct> WidgetData;
int Order;
TWidgetStruct(const std::string& name, const std::string& groupName, std::shared_ptr<TInstancingWidgetAncestor> 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() ~TWidgetStruct()
{ {
} }
@ -158,8 +189,6 @@ public:
void DeleteWidgetOnUpdate(const std::string& name); void DeleteWidgetOnUpdate(const std::string& name);
void DeleteWidgetGroupOnUpdate(const std::string& groupName); void DeleteWidgetGroupOnUpdate(const std::string& groupName);
void DeleteWidgetLaterOnUpdate(const std::string& name);
void DeleteWidgetGroupLaterOnUpdate(const std::string& groupName);
void Update(cardinal dt); void Update(cardinal dt);
void Draw(); void Draw();

View File

@ -48,7 +48,7 @@ void TGUIManager::AddWidget(std::shared_ptr<TInstancingWidgetAncestor> widgetAnc
{ {
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++) for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++)
{ {
if (i->Name == name) if (i->WidgetData->Name == name)
{ {
return; return;
} }
@ -61,7 +61,7 @@ void TGUIManager::DeleteWidget(std::string name)
{ {
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++) for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++)
{ {
if (i->Name == name) if (i->WidgetData->Name == name)
{ {
WidgetArr.erase(i); WidgetArr.erase(i);
return; return;
@ -75,7 +75,7 @@ void TGUIManager::DeleteWidgetGroup(std::string groupName)
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end();) for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end();)
{ {
widgetErased = false; widgetErased = false;
if (i->GroupName == groupName) if (i->WidgetData->GroupName == groupName)
{ {
i = WidgetArr.erase(i); i = WidgetArr.erase(i);
widgetErased = true; widgetErased = true;
@ -90,31 +90,14 @@ void TGUIManager::DeleteWidgetGroup(std::string groupName)
void TGUIManager::DeleteWidgetOnUpdate(const std::string& name) void TGUIManager::DeleteWidgetOnUpdate(const std::string& name)
{ {
//PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidget, this, name)); PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidget, this, name));
PerformInMainThreadAsync(boost::bind(&TGUIManager::DeleteWidget, this, name));
} }
void TGUIManager::DeleteWidgetGroupOnUpdate(const std::string& groupName) void TGUIManager::DeleteWidgetGroupOnUpdate(const std::string& groupName)
{
//PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName));
PerformInMainThreadAsync(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)); PerformInMainThreadAsyncLater(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName));
} }
void TGUIManager::AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask) void TGUIManager::AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask)
{ {
WidgetTrasfromTaskList.push_back(widgetTransformTask); WidgetTrasfromTaskList.push_back(widgetTransformTask);
@ -130,12 +113,12 @@ void TGUIManager::Update(cardinal dt)
{ {
//i->Widget->Update(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) for (TWidgetArr::iterator j = WidgetArr.begin(); j != WidgetArr.end(); ++j)
{ {
if (j->GroupName == i->GroupName) if (j->WidgetData->GroupName == i->GroupName)
{ {
MoveWidgetByIterator(j, moveDistance); MoveWidgetByIterator(j, moveDistance);
} }
@ -213,7 +196,7 @@ void TGUIManager::Draw()
TRenderPairList::iterator j; 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); TRenderParamsSetter paramSetter(j->first);
@ -232,7 +215,7 @@ TWidgetArr::iterator TGUIManager::FindWidgetInArr(const std::string& widgetName)
for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i) for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
{ {
if (i->Name == widgetName) if (i->WidgetData->Name == widgetName)
{ {
break; break;
} }
@ -248,13 +231,13 @@ TWidgetArr::iterator TGUIManager::FindWidgetInArr(const std::string& widgetName)
void TGUIManager::MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift) void TGUIManager::MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift)
{ {
widget->Widget->LeftBottomPos += shift; widget->WidgetData->Widget->LeftBottomPos += shift;
std::vector<vec3>::iterator i; std::vector<vec3>::iterator i;
TRenderPairList::iterator itr; 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<vec3>& vertexCoordVec = itr->second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB]; std::vector<vec3>& 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) 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); MoveWidgetByIterator(i, shift);
} }
@ -302,14 +285,14 @@ void TGUIManager::OnMouseDown(vec2 pos, int touchNumber)
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) 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->WidgetData->Widget->OnTapDown(pos);
i->IsMouseDown = true; 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) if (! isTransparentForInput)
{ {
@ -340,13 +323,13 @@ void TGUIManager::OnMouseUp(vec2 pos, int touchNumber)
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) 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->OnTapUp(pos); i->WidgetData->Widget->OnTapUp(pos);
i->IsMouseDown = false; 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) if (! isTransparentForInput)
{ {
@ -378,11 +361,11 @@ void TGUIManager::OnMouseUp(vec2 pos, int touchNumber)
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) 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->OnTapUpAfterMove(pos); i->WidgetData->Widget->OnTapUpAfterMove(pos);
i->IsMouseDown = false; i->WidgetData->IsMouseDown = false;
//signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME])); //signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME]));
//Do not call signals here //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(); bool isTransparentForInput = i->WidgetData->Widget->IsTransparentForInput();
i->Widget->OnTapUpAfterMoveOut(pos); i->WidgetData->Widget->OnTapUpAfterMoveOut(pos);
i->IsMouseDown = false; i->WidgetData->IsMouseDown = false;
//signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME])); //signalMap.push_back((i->SignalMap[CONST_CLICK_SIGNAL_NAME]));
//Do not call signals here //Do not call signals here
@ -438,13 +421,13 @@ void TGUIManager::OnMove(vec2 shift, int touchNumber)
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) 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) if (! isTransparentForInput)
{ {
@ -462,12 +445,12 @@ void TGUIManager::OnMove(vec2 shift, int touchNumber)
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i) 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->WidgetData->Widget->OnMoveOut();
i->IsMouseDown = false; i->WidgetData->IsMouseDown = false;
if (! isTransparentForInput) if (! isTransparentForInput)
{ {
moveOutIsProcessed = true; moveOutIsProcessed = true;
@ -529,7 +512,7 @@ void TGUIManager::PrintWidgetList()
for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i) 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); Console->PrintImmediate(widgetRow);
} }
} }
@ -540,7 +523,7 @@ std::shared_ptr<boost::signal<void (TSignalParam)>> TGUIManager::GetOnClickSigna
TWidgetArr::iterator i = FindWidgetInArr(widgetName); 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<boost::signal<void (TSignalParam)>> TGUIManager::GetOnHoldSignal
TWidgetArr::iterator i = FindWidgetInArr(widgetName); 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<boost::signal<void (TSignalParam)>> TGUIManager::GetOnTapDownSig
TWidgetArr::iterator i = FindWidgetInArr(widgetName); 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<boost::signal<void (TSignalParam)>> TGUIManager::GetSignal(const
TWidgetArr::iterator i = FindWidgetInArr(widgetName); TWidgetArr::iterator i = FindWidgetInArr(widgetName);
if (i->SignalMap.count(signalName) == 0) if (i->WidgetData->SignalMap.count(signalName) == 0)
{ {
throw ErrorToLog("Illegal signal: "+signalName); 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) void TGUIManager::SQ_MoveWidget(const SQChar *widgetName, float x, float y)