summaryrefslogtreecommitdiff
path: root/src/interface/Component.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interface/Component.cpp')
-rw-r--r--src/interface/Component.cpp118
1 files changed, 90 insertions, 28 deletions
diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp
index 48a329b..ac66f92 100644
--- a/src/interface/Component.cpp
+++ b/src/interface/Component.cpp
@@ -1,61 +1,111 @@
-/*
- * Component.cpp
- *
- * Created on: Jan 8, 2012
- * Author: Simon
- */
-
+//#include "Platform.h"
#include "interface/Component.h"
+#include "interface/Engine.h"
+#include "interface/Point.h"
+#include "interface/State.h"
+#include "interface/Panel.h"
-namespace ui {
+using namespace ui;
-Component::Component(int x, int y, int width, int height):
- X(x),
- Y(y),
- Width(width),
- Height(height),
- Enabled(true),
- Visible(true)
+Component::Component(State* parent_state):
+ parentstate_(parent_state),
+ _parent(NULL),
+ Position(Point(0,0)),
+ Size(Point(0,0)),
+ Locked(false),
+ Visible(true)
{
+
}
-Component::~Component()
+Component::Component(Point position, Point size):
+ parentstate_(NULL),
+ _parent(NULL),
+ Position(position),
+ Size(size),
+ Locked(false),
+ Visible(true)
{
+
}
-void Component::Draw(void* userdata)
+Component::Component():
+ parentstate_(NULL),
+ _parent(NULL),
+ Position(Point(0,0)),
+ Size(Point(0,0)),
+ Locked(false),
+ Visible(true)
{
+
}
-void Component::Tick(float dt)
+bool Component::IsFocused() const
{
+ return parentstate_->IsFocused(this);
}
-void Component::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
+void Component::SetParentState(State* state)
{
+ parentstate_ = state;
}
-void Component::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
+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
+ GetParentState()->AddComponent(this);
+
+ //done in this loop.
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ // remove from parent state (if in parent state) and place in new parent
+ GetParentState()->RemoveComponent(this);
+ new_parent->children.push_back(this);
+ }
+ this->_parent = new_parent;
+}
+
+// ***** OVERRIDEABLES *****
+// Kept empty.
+
+void Component::Draw(const Point& screenPos)
{
}
-void Component::OnMouseEnter(int localx, int localy, int dx, int dy)
+void Component::Tick(float dt)
{
}
-void Component::OnMouseLeave(int localx, int localy, int dx, int dy)
+void Component::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
{
}
-void Component::OnMouseClick(int localx, int localy, unsigned int button)
+void Component::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
{
}
-void Component::OnMouseUnclick(int localx, int localy, unsigned int button)
+void Component::OnMouseClick(int localx, int localy, unsigned button)
{
}
-void Component::OnMouseDown(int localx, int localy, unsigned int button)
+void Component::OnMouseDown(int x, int y, unsigned button)
{
}
@@ -71,7 +121,19 @@ void Component::OnMouseMovedInside(int localx, int localy, int dx, int dy)
{
}
-void Component::OnMouseUp(int localx, int localy, unsigned int button)
+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)
{
}
@@ -83,7 +145,7 @@ void Component::OnMouseWheelInside(int localx, int localy, int d)
{
}
-void Component::OnMouseWheelFocused(int localx, int localy, int d)
+Component::~Component()
{
+
}
-} /* namespace ui */