mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Put ComponentContainer directly in GuiComponent.
Necessary for parenting to allow getOffset(), etc.
This commit is contained in:
parent
424fcb0329
commit
628b0b6958
|
@ -1,34 +0,0 @@
|
|||
#include "ComponentContainer.h"
|
||||
#include "GuiComponent.h"
|
||||
|
||||
void ComponentContainer::addChild(GuiComponent* cmp)
|
||||
{
|
||||
mChildren.push_back(cmp);
|
||||
}
|
||||
|
||||
void ComponentContainer::removeChild(GuiComponent* cmp)
|
||||
{
|
||||
for(auto i = mChildren.begin(); i != mChildren.end(); i++)
|
||||
{
|
||||
if(*i == cmp)
|
||||
{
|
||||
mChildren.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentContainer::clearChildren()
|
||||
{
|
||||
mChildren.clear();
|
||||
}
|
||||
|
||||
unsigned int ComponentContainer::getChildCount()
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
GuiComponent* ComponentContainer::getChild(unsigned int i)
|
||||
{
|
||||
return mChildren.at(i);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef _COMPONENTCONTAINER_H_
|
||||
#define _COMPONENTCONTAINER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
class GuiComponent;
|
||||
|
||||
/**
|
||||
Generic container for Components.
|
||||
**/
|
||||
|
||||
class ComponentContainer
|
||||
{
|
||||
public:
|
||||
void addChild(GuiComponent* cmp);
|
||||
void removeChild(GuiComponent* cmp);
|
||||
void clearChildren();
|
||||
unsigned int getChildCount();
|
||||
GuiComponent* getChild(unsigned int i);
|
||||
|
||||
private:
|
||||
std::vector<GuiComponent*> mChildren;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#include "GuiComponent.h"
|
||||
#include "Window.h"
|
||||
#include "Log.h"
|
||||
|
||||
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL)
|
||||
{
|
||||
|
@ -89,3 +90,47 @@ void GuiComponent::setOffset(int x, int y)
|
|||
mOffset.x = x;
|
||||
mOffset.y = y;
|
||||
}
|
||||
|
||||
void GuiComponent::addChild(GuiComponent* cmp)
|
||||
{
|
||||
mChildren.push_back(cmp);
|
||||
|
||||
if(cmp->getParent())
|
||||
cmp->getParent()->removeChild(cmp);
|
||||
|
||||
cmp->setParent(this);
|
||||
}
|
||||
|
||||
void GuiComponent::removeChild(GuiComponent* cmp)
|
||||
{
|
||||
if(cmp->getParent() != this)
|
||||
{
|
||||
LOG(LogError) << "Tried to remove child from incorrect parent!";
|
||||
}
|
||||
|
||||
cmp->setParent(NULL);
|
||||
|
||||
for(auto i = mChildren.begin(); i != mChildren.end(); i++)
|
||||
{
|
||||
if(*i == cmp)
|
||||
{
|
||||
mChildren.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiComponent::clearChildren()
|
||||
{
|
||||
mChildren.clear();
|
||||
}
|
||||
|
||||
unsigned int GuiComponent::getChildCount()
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
GuiComponent* GuiComponent::getChild(unsigned int i)
|
||||
{
|
||||
return mChildren.at(i);
|
||||
}
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
|
||||
#include "InputConfig.h"
|
||||
#include "Vector2.h"
|
||||
#include "ComponentContainer.h"
|
||||
|
||||
class Window;
|
||||
|
||||
class GuiComponent : public ComponentContainer
|
||||
class GuiComponent
|
||||
{
|
||||
public:
|
||||
GuiComponent(Window* window);
|
||||
|
@ -28,10 +27,17 @@ public:
|
|||
void setParent(GuiComponent* parent);
|
||||
GuiComponent* getParent();
|
||||
|
||||
void addChild(GuiComponent* cmp);
|
||||
void removeChild(GuiComponent* cmp);
|
||||
void clearChildren();
|
||||
unsigned int getChildCount();
|
||||
GuiComponent* getChild(unsigned int i);
|
||||
|
||||
protected:
|
||||
Window* mWindow;
|
||||
GuiComponent* mParent;
|
||||
Vector2i mOffset;
|
||||
std::vector<GuiComponent*> mChildren;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue