summaryrefslogtreecommitdiff
path: root/src/interface/Component.cpp
blob: 75e9c40f5fbaeea8f987c6438c0e7e317c97fba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//#include "Platform.h"
#include "interface/Component.h"
#include "interface/Engine.h"
#include "interface/Point.h"
#include "interface/Window.h"
#include "interface/Panel.h"

using namespace ui;

Component::Component(Window* parent_state):
	parentstate_(parent_state),
	_parent(NULL),
	Position(Point(0,0)),
	Size(Point(0,0)),
	Locked(false),
	Visible(true)
{

}

Component::Component(Point position, Point size):
	parentstate_(NULL),
	_parent(NULL),
	Position(position),
	Size(size),
	Locked(false),
	Visible(true)
{

}

Component::Component():
	parentstate_(NULL),
	_parent(NULL),
	Position(Point(0,0)),
	Size(Point(0,0)),
	Locked(false),
	Visible(true)
{

}

bool Component::IsFocused() const
{
	return parentstate_->IsFocused(this);
}

void Component::SetParentWindow(Window* window)
{
	parentstate_ = window;
}

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
					GetParentWindow()->AddComponent(this);
					
					//done in this loop.
					break;
				}
			}
		}
	}
	else
	{
		// remove from parent state (if in parent state) and place in new parent
		if(GetParentWindow())
			GetParentWindow()->RemoveComponent(this);
		new_parent->children.push_back(this);
	}
	this->_parent = new_parent;
}

// ***** OVERRIDEABLES *****
// Kept empty.

void Component::Draw(const Point& screenPos)
{
}

void Component::Tick(float dt)
{
}

void Component::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
{
}

void Component::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
{
}

void Component::OnMouseClick(int localx, int localy, unsigned button)
{
}

void Component::OnMouseDown(int x, int y, unsigned button)
{
}

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)
{
}

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)
{
}

void Component::OnMouseWheel(int localx, int localy, int d)
{
}

void Component::OnMouseWheelInside(int localx, int localy, int d)
{
}

Component::~Component()
{

}