ecere,ecereCOM: support Emscriptem platform. add new Emscripten interface driver.
[sdk] / ecere / src / gui / drivers / EmscriptenInterface.ec
1 namespace gui::drivers;
2
3 #ifdef BUILDING_ECERE_COM
4 import "Window"
5 import "Interface"
6 #else
7 #ifdef ECERE_STATIC
8 public import static "ecere"
9 #else
10 public import "ecere"
11 #endif
12 #endif
13
14 #ifdef __EMSCRIPTEN__
15
16 #include <stdio.h>
17
18 // source file line number printf (sflnprintf)
19 #define sflnprintf(format,...) printf("%s:% 5d: " format, __FILE__, __LINE__, ##__VA_ARGS__)
20
21 #define property _property
22 #define uint _uint
23
24 //#include <GLES2/gl2.h>
25 #include <GL/glfw.h>
26 #include <emscripten/emscripten.h>
27
28 #undef property
29 #undef uint
30
31
32 class EmscriptenInterface : Interface
33 {
34    class_property(name) = "Emscripten";
35
36
37    // --- User Interface System ---
38
39    bool ::Initialize()
40    {
41       sflnprintf("class(EmscriptenInterface) ::Initialize [STUB!]\n");
42       guiApp.desktop.ExternalPosition(0,0, 640, 480);
43       return true;
44    }
45
46    void ::Terminate()
47    {
48       sflnprintf("class(EmscriptenInterface) ::Terminate [STUB!]\n");
49    }
50
51    bool ::ProcessInput(bool processAll)
52    {
53       sflnprintf("class(EmscriptenInterface) ::ProcessInput [STUB!]\n");
54       return false;
55    }
56
57    void ::Wait()
58    {
59       sflnprintf("class(EmscriptenInterface) ::Wait [STUB!]\n");
60    }
61
62    void ::Lock(Window window)
63    {
64       sflnprintf("class(EmscriptenInterface) ::Lock [STUB!]\n");
65    }
66
67    void ::Unlock(Window window)
68    {
69       sflnprintf("class(EmscriptenInterface) ::Unlock [STUB!]\n");
70    }
71
72    void ::SetTimerResolution(uint hertz)
73    {
74       sflnprintf("class(EmscriptenInterface) ::SetTimerResolution [STUB!] Implement high resolution timer here\n");
75    }
76
77    const char ** ::GraphicsDrivers(int * numDrivers)
78    {
79       //sflnprintf("class(EmscriptenInterface) ::GraphicsDrivers [STUB!]\n");
80       static const char *graphicsDrivers[] = { "OpenGL" };
81       *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
82       return (const char **)graphicsDrivers;
83       return null;
84    }
85
86    void ::EnsureFullScreen(bool * fullScreen)
87    {
88       sflnprintf("class(EmscriptenInterface) ::EnsureFullScreen [STUB!]\n");
89       *fullScreen = true;
90    }
91
92    void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
93    {
94       sflnprintf("class(EmscriptenInterface) ::GetCurrentMode [STUB!]\n");
95    }
96
97    bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
98    {
99       sflnprintf("class(EmscriptenInterface) ::ScreenMode [STUB!]\n");
100       return true;
101    }
102
103
104    // --- Window Creation ---
105
106    void * ::CreateRootWindow(Window window)
107    {
108       sflnprintf("class(EmscriptenInterface) ::CreateRootWindow [STUB!]\n");
109       return null;
110    }
111
112    void ::DestroyRootWindow(Window window)
113    {
114       sflnprintf("class(EmscriptenInterface) ::DestroyRootWindow [STUB!]\n");
115    }
116
117
118    // --- Window manipulation ---
119
120    void ::SetRootWindowCaption(Window window, const char * name)
121    {
122       sflnprintf("class(EmscriptenInterface) ::SetRootWindowCaption [STUB!]\n");
123    }
124
125    void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
126    {
127       sflnprintf("class(EmscriptenInterface) ::Stub [STUB!]\n");
128    }
129
130    void ::OffsetWindow(Window window, int * x, int * y)
131    {
132       sflnprintf("class(EmscriptenInterface) ::OffsetWindow [STUB!]\n");
133    }
134
135    void ::UpdateRootWindow(Window window)
136    {
137       sflnprintf("class(EmscriptenInterface) ::UpdateRootWindow [STUB!]\n");
138    }
139
140    void ::SetRootWindowState(Window window, WindowState state, bool visible)
141    {
142       sflnprintf("class(EmscriptenInterface) ::SetRootWindowState [STUB!]\n");
143    }
144
145    void ::ActivateRootWindow(Window window)
146    {
147       sflnprintf("class(EmscriptenInterface) ::ActivateRootWindow [STUB!]\n");
148    }
149
150    void ::OrderRootWindow(Window window, bool topMost)
151    {
152       sflnprintf("class(EmscriptenInterface) ::OrderRootWindow [STUB!]\n");
153    }
154
155    void ::SetRootWindowColor(Window window)
156    {
157       sflnprintf("class(EmscriptenInterface) ::SetRootWindowColor [STUB!]\n");
158    }
159
160    void ::FlashRootWindow(Window window)
161    {
162       sflnprintf("class(EmscriptenInterface) ::FlashRootWindow [STUB!]\n");
163    }
164
165
166    // --- Mouse-based window movement ---
167
168    void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
169    {
170       sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
171    }
172
173    void ::StopMoving(Window window)
174    {
175       sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
176    }
177
178
179    // --- Mouse manipulation ---
180
181    void ::GetMousePosition(int *x, int *y)
182    {
183       sflnprintf("class(EmscriptenInterface) ::GetMousePosition [STUB!]\n");
184    }
185
186    void ::SetMousePosition(int x, int y)
187    {
188       sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
189    }
190
191    void ::SetMouseRange(Window window, Box box)
192    {
193       sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
194    }
195
196    void ::SetMouseCapture(Window window)
197    {
198       sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
199    }
200
201
202    // --- Mouse cursor ---
203
204    void ::SetMouseCursor(Window window, SystemCursor cursor)
205    {
206       sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
207    }
208
209
210    // --- Caret manipulation ---
211
212    void ::SetCaret(int caretX, int caretY, int size)
213    {
214       sflnprintf("class(EmscriptenInterface) ::SetCaret [STUB!]\n");
215    }
216
217
218    // --- Clipboard manipulation ---
219
220    void ::ClearClipboard()
221    {
222       sflnprintf("class(EmscriptenInterface) ::ClearClipboard [STUB!]\n");
223    }
224
225    bool ::AllocateClipboard(ClipBoard clipBoard, uint size)
226    {
227       sflnprintf("class(EmscriptenInterface) ::AllocateClipboard [STUB!]\n");
228       return false;
229    }
230
231    bool ::SaveClipboard(ClipBoard clipBoard)
232    {
233       sflnprintf("class(EmscriptenInterface) ::SaveClipboard [STUB!]\n");
234       return false;
235    }
236
237    bool ::LoadClipboard(ClipBoard clipBoard)
238    {
239       sflnprintf("class(EmscriptenInterface) ::LoadClipboard [STUB!]\n");
240       return false;
241    }
242
243    void ::UnloadClipboard(ClipBoard clipBoard)
244    {
245       sflnprintf("class(EmscriptenInterface) ::UnloadClipboard [STUB!]\n");
246    }
247
248
249    // --- State based input ---
250
251    bool ::AcquireInput(Window window, bool state)
252    {
253       sflnprintf("class(EmscriptenInterface) ::AcquireInput [STUB!]\n");
254       return false;
255    }
256
257    bool ::GetMouseState(MouseButtons * buttons, int * x, int * y)
258    {
259       sflnprintf("class(EmscriptenInterface) ::GetMouseState [STUB!]\n");
260       return false;
261    }
262
263    bool ::GetJoystickState(int device, Joystick joystick)
264    {
265       sflnprintf("class(EmscriptenInterface) ::GetJoystickState [STUB!]\n");
266       return false;
267    }
268
269    bool ::GetKeyState(Key key)
270    {
271       sflnprintf("class(EmscriptenInterface) ::GetKeyState [STUB!]\n");
272       return false;
273    }
274
275    bool ::SetIcon(Window window, BitmapResource icon)
276    {
277       sflnprintf("class(EmscriptenInterface) ::SetIcon [STUB!]\n");
278       return false;
279    }
280
281    void ::GetScreenArea(Window window, Box box)
282    {
283       sflnprintf("class(EmscriptenInterface) ::GetScreenArea [STUB!]\n");
284    }
285 }
286
287 #endif