1 /**
2 Copyright: Copyright (c) 2013-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 
7 module voxelman.platform.iwindow;
8 
9 import voxelman.math;
10 import voxelman.platform.isharedcontext;
11 import voxelman.utils.signal;
12 public import voxelman.platform.cursoricon : CursorIcon;
13 public import voxelman.platform.input : KeyCode, PointerButton;
14 public import derelict.opengl.types : GLVersion;
15 
16 struct WindowParams
17 {
18 	ivec2 size;
19 	string title;
20 	bool center = false;
21 	bool openglDebugContext = false;
22 
23 	version(Windows) {
24 		bool openglForwardCompat = false;
25 		bool openglCoreProfile = false;
26 		GLVersion openglVersion = GLVersion.gl31;
27 	} else version(OSX) {
28 		bool openglForwardCompat = true;
29 		bool openglCoreProfile = true;
30 		GLVersion openglVersion = GLVersion.gl32;
31 	} else version(linux) {
32 		bool openglForwardCompat = true;
33 		bool openglCoreProfile = false;
34 		GLVersion openglVersion = GLVersion.gl31;
35 	}
36 }
37 
38 abstract class IWindow
39 {
40 	void init(WindowParams);
41 	ISharedContext createSharedContext();
42 	void reshape(ivec2 viewportSize);
43 	void moveToCenter();
44 	void processEvents(); // will emit signals
45 	double elapsedTime() @property; // in seconds
46 	void swapBuffers();
47 	void setVsync(bool);
48 	void releaseWindow();
49 
50 	void mousePosition(ivec2 newPosition) @property;
51 	ivec2 mousePosition() @property;
52 
53 	ivec2 size() @property;
54 	ivec2 framebufferSize() @property;
55 	void size(ivec2 newSize) @property;
56 
57 	bool isKeyPressed(uint key);
58 
59 	string clipboardString() @property;
60 	void clipboardString(string newClipboardString) @property;
61 
62 	void isCursorLocked(bool value);
63 	bool isCursorLocked();
64 
65 	void setCursorIcon(CursorIcon icon);
66 
67 	Signal!(KeyCode, uint) keyPressed;
68 	Signal!(KeyCode, uint) keyReleased;
69 	Signal!dchar charEntered;
70 	Signal!(PointerButton, uint) mousePressed;
71 	Signal!(PointerButton, uint) mouseReleased;
72 	Signal!ivec2 mouseMoved;
73 	Signal!bool focusChanged;
74 	Signal!ivec2 windowResized;
75 	Signal!ivec2 windowMoved;
76 	Signal!bool windowIconified;
77 	Signal!dvec2 wheelScrolled;
78 	Signal!() closePressed;
79 	Signal!() refresh;
80 }