1 module polyplex.core.window;
2 import polyplex.core.render;
3 import polyplex.math;
4 import polyplex;
5 import sev.event;
6 
7 public class BoundsEventArgs : EventArgs {
8 public :
9 	int X;
10 	int Y;
11 	int Width;
12 	int Height;
13 }
14 
15 public class WindowBounds {
16 private :
17 	Rectangle winRect;
18 	Window owner;
19 protected :
20 	void updateWindowBounds(Rectangle rect) {
21 		winRect = rect;
22 	}
23 public :
24 
25 	Event windowResizeRequestEvent;
26 	Event windowPositionRequestEvent;
27 	this(Window owner, Rectangle winRect) {
28 		windowResizeRequestEvent = new Event();
29 		windowPositionRequestEvent = new Event();
30 		this.owner = owner;
31 		this.winRect = winRect;
32 	}
33 
34 	@property int X() {
35 		return winRect.X;
36 	}
37 
38 	@property int Y() {
39 		return winRect.Y;
40 	}
41 
42 	@property int Width() {
43 		return winRect.Width;
44 	}
45 
46 	@property int Height() {
47 		return winRect.Height;
48 	}
49 
50 	@property Vector2i Center() {
51 		return Vector2i(winRect.Width/2, winRect.Height/2);
52 	}
53 
54 	void ResizeWindow(int width, int height) {
55 		winRect.Width  = width;
56 		winRect.Height = height;
57 		BoundsEventArgs args;
58 		args.Width = width;
59 		args.Height = height;
60 		windowResizeRequestEvent(cast(void*)this, cast(EventArgs)args);
61 	}
62 
63 	void MoveWindow(int x, int y) {
64 		winRect.X = x;
65 		winRect.Y = y;
66 		BoundsEventArgs args;
67 		args.X = x;
68 		args.Y = y;
69 		windowPositionRequestEvent(cast(void*)this, cast(EventArgs)args);
70 	}
71 }
72 
73 public abstract class Window {
74 protected :
75 	string SurfaceName;
76 	GraphicsBackend ActiveBackend;
77 	GraphicsContext ActiveContext;
78 
79 	void updateBounds(Rectangle rect) {
80 		ClientBounds.updateWindowBounds(rect);
81 	}
82 
83 	void replaceOn(Game game) {
84 		game.forceWindowChange(this);
85 	}
86 
87 public :
88 	WindowBounds ClientBounds;
89 	bool AutoFocus = true;	
90 
91 	// Base Constructor.
92 	this(string name) {
93 		this.SurfaceName = name;
94 	}
95 
96 	~this() {
97 		DestroyContext();
98 	}
99 
100 	// Allow Resizing
101 	abstract @property bool AllowResizing();
102 	abstract @property void AllowResizing(bool allow);
103 
104 	// VSync
105 	abstract @property VSyncState VSync();
106 	abstract @property void VSync(VSyncState value);
107 
108 	// Borderless Window Mode
109 	abstract @property bool Borderless();
110 	abstract @property void Borderless(bool i);
111 
112 	// Fullscreen
113 	abstract @property bool Fullscreen();
114 	abstract @property void Fullscreen(bool i);
115 
116 	// Client Bounds
117 	abstract @property bool Visible();
118 
119 	// Window Title
120 	abstract @property string Title();
121 	abstract @property void Title(string value);
122 
123 	abstract void Close();
124 	abstract void Show();
125 	abstract void UpdateState();
126 	abstract void SwapBuffers();
127 	abstract void Focus();
128 	abstract void SetIcon();
129 
130 	abstract GraphicsContext CreateContext(GraphicsBackend backend);
131 	public abstract void DestroyContext();
132 }
133 
134 public struct GraphicsContext {
135 	void* ContextPtr;
136 }