summaryrefslogtreecommitdiff
path: root/src/interface/Window.h
blob: c2c5e16e14ce1abdba14f9b037c87b6a42d81001 (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
#ifndef WINDOW_H
#define WINDOW_H

#include <vector>
#include "interface/Point.h"
#include "Engine.h"

namespace ui
{

enum ChromeStyle
{
	None, Title, Resizable
};
//class State;
	class Engine;
	class Component;

	/* class State
	 *
	 * A UI state. Contains all components.
	 */
	class Window
	{
	public:
		Point Position;
		Point Size;

		Window(Point _position, Point _size);
		virtual ~Window();

		bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds

		// Add Component to state
		void AddComponent(Component* c);

		// Get the number of components this state has.
		unsigned GetComponentCount();

		// Get component by index. (See GetComponentCount())
		Component* GetComponent(unsigned idx);

		// Remove a component from state. NOTE: This DOES NOT free component from memory.
		void RemoveComponent(Component* c);

		// Remove a component from state. NOTE: This WILL free component from memory.
		void RemoveComponent(unsigned idx);

		virtual void ToolTip(Component * sender, ui::Point mousePosition, std::string toolTip) {}

		virtual void DoInitialized();
		virtual void DoExit();
		virtual void DoTick(float dt);
		virtual void DoDraw();

		virtual void DoMouseMove(int x, int y, int dx, int dy);
		virtual void DoMouseDown(int x, int y, unsigned button);
		virtual void DoMouseUp(int x, int y, unsigned button);
		virtual void DoMouseWheel(int x, int y, int d);
		virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
		virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);

		//Sets halt and destroy, this causes the Windows to stop sending events and remove itself.
		void SelfDestruct();

		bool IsFocused(const Component* c) const;
		void FocusComponent(Component* c);

		void* UserData;

	protected:
		virtual void OnInitialized() {}
		virtual void OnExit() {}
		virtual void OnTick(float dt) {}
		virtual void OnDraw() {}

		virtual void OnMouseMove(int x, int y, int dx, int dy) {}
		virtual void OnMouseDown(int x, int y, unsigned button) {}
		virtual void OnMouseUp(int x, int y, unsigned button) {}
		virtual void OnMouseWheel(int x, int y, int d) {}
		virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
		virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
		std::vector<Component*> Components;
		Component* focusedComponent_;
		ChromeStyle chrome;

		//These controls allow a component to call the destruction of the Window inside an event (called by the Window)
		void finalise();
		bool halt;
		bool destruct;
#ifdef DEBUG
		bool debugMode;
#endif

	};


/*class Window : public State
{
private:
	ChromeStyle chrome;
public:
	Window(Point _position, Point _size);
	Point Position;
	Point Size;

	virtual void DoTick(float dt);
	virtual void DoDraw();

	virtual void DoMouseMove(int x, int y, int dx, int dy);
	virtual void DoMouseDown(int x, int y, unsigned button);
	virtual void DoMouseUp(int x, int y, unsigned button);
	virtual void DoMouseWheel(int x, int y, int d);
};*/
}
#endif // WINDOW_H