2012-01-14 12:51:24 -06:00
|
|
|
//#include "Platform.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
#include "interface/Component.h"
|
2012-01-14 12:51:24 -06:00
|
|
|
#include "interface/Engine.h"
|
|
|
|
#include "interface/Point.h"
|
2012-01-17 14:46:06 -06:00
|
|
|
#include "interface/Window.h"
|
2012-01-14 12:51:24 -06:00
|
|
|
#include "interface/Panel.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
using namespace ui;
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-01-17 14:46:06 -06:00
|
|
|
Component::Component(Window* parent_state):
|
2012-01-14 12:51:24 -06:00
|
|
|
parentstate_(parent_state),
|
|
|
|
_parent(NULL),
|
|
|
|
Position(Point(0,0)),
|
|
|
|
Size(Point(0,0)),
|
|
|
|
Locked(false),
|
|
|
|
Visible(true)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
Component::Component(Point position, Point size):
|
|
|
|
parentstate_(NULL),
|
|
|
|
_parent(NULL),
|
|
|
|
Position(position),
|
|
|
|
Size(size),
|
|
|
|
Locked(false),
|
|
|
|
Visible(true)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
Component::Component():
|
|
|
|
parentstate_(NULL),
|
|
|
|
_parent(NULL),
|
|
|
|
Position(Point(0,0)),
|
|
|
|
Size(Point(0,0)),
|
|
|
|
Locked(false),
|
|
|
|
Visible(true)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
bool Component::IsFocused() const
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-14 12:51:24 -06:00
|
|
|
return parentstate_->IsFocused(this);
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-17 14:46:06 -06:00
|
|
|
void Component::SetParentWindow(Window* window)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-01-17 14:46:06 -06:00
|
|
|
parentstate_ = window;
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
void Component::SetParent(Panel* new_parent)
|
|
|
|
{
|
|
|
|
if(new_parent == NULL)
|
|
|
|
{
|
|
|
|
if(_parent != NULL)
|
|
|
|
{
|
|
|
|
// remove from current parent and send component to parent state
|
|
|
|
for(int i = 0; i < _parent->GetChildCount(); ++i)
|
|
|
|
{
|
|
|
|
if(_parent->GetChild(i) == this)
|
|
|
|
{
|
|
|
|
// remove ourself from parent component
|
|
|
|
_parent->RemoveChild(i, false);
|
|
|
|
|
|
|
|
// add ourself to the parent state
|
2012-01-17 14:46:06 -06:00
|
|
|
GetParentWindow()->AddComponent(this);
|
2012-01-14 12:51:24 -06:00
|
|
|
|
|
|
|
//done in this loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// remove from parent state (if in parent state) and place in new parent
|
2012-01-17 14:46:06 -06:00
|
|
|
if(GetParentWindow())
|
|
|
|
GetParentWindow()->RemoveComponent(this);
|
2012-01-14 12:51:24 -06:00
|
|
|
new_parent->children.push_back(this);
|
|
|
|
}
|
|
|
|
this->_parent = new_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***** OVERRIDEABLES *****
|
|
|
|
// Kept empty.
|
|
|
|
|
|
|
|
void Component::Draw(const Point& screenPos)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
void Component::Tick(float dt)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-29 18:40:28 -06:00
|
|
|
void Component::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-29 18:40:28 -06:00
|
|
|
void Component::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
void Component::OnMouseClick(int localx, int localy, unsigned button)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
void Component::OnMouseDown(int x, int y, unsigned button)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseHover(int localx, int localy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseMoved(int localx, int localy, int dx, int dy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseMovedInside(int localx, int localy, int dx, int dy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
void Component::OnMouseEnter(int localx, int localy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseLeave(int localx, int localy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseUnclick(int localx, int localy, unsigned button)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseUp(int x, int y, unsigned button)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseWheel(int localx, int localy, int d)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Component::OnMouseWheelInside(int localx, int localy, int d)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
Component::~Component()
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2012-04-07 18:11:21 -05:00
|
|
|
if(GetParentWindow()->IsFocused(this))
|
|
|
|
GetParentWindow()->FocusComponent(NULL);
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|