d5d425a4529df3d7b131cecceaeafb316861a728
[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 #include <emscripten/html5.h>
28
29 #undef property
30 #undef uint
31
32 static canvasX;
33 static canvasY;
34
35 static inline const char *emscripten_event_type_to_string(int eventType)
36 {
37    const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize",
38          "scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange",
39          "visibilitychange", "touchstart", "touchend", "touchmove", "touchcancel", "gamepadconnected", "gamepaddisconnected", "beforeunload",
40          "batterychargingchange", "batterylevelchange", "webglcontextlost", "webglcontextrestored", "mouseenter", "mouseleave", "mouseover", "mouseout", "(invalid)" };
41    ++eventType;
42    if (eventType < 0) eventType = 0;
43    if (eventType >= sizeof(events)/sizeof(events[0])) eventType = sizeof(events)/sizeof(events[0])-1;
44    return events[eventType];
45 }
46
47 const char *emscripten_result_to_string(EMSCRIPTEN_RESULT result)
48 {
49    if (result == EMSCRIPTEN_RESULT_SUCCESS) return "EMSCRIPTEN_RESULT_SUCCESS";
50    if (result == EMSCRIPTEN_RESULT_DEFERRED) return "EMSCRIPTEN_RESULT_DEFERRED";
51    if (result == EMSCRIPTEN_RESULT_NOT_SUPPORTED) return "EMSCRIPTEN_RESULT_NOT_SUPPORTED";
52    if (result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED) return "EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED";
53    if (result == EMSCRIPTEN_RESULT_INVALID_TARGET) return "EMSCRIPTEN_RESULT_INVALID_TARGET";
54    if (result == EMSCRIPTEN_RESULT_UNKNOWN_TARGET) return "EMSCRIPTEN_RESULT_UNKNOWN_TARGET";
55    if (result == EMSCRIPTEN_RESULT_INVALID_PARAM) return "EMSCRIPTEN_RESULT_INVALID_PARAM";
56    if (result == EMSCRIPTEN_RESULT_FAILED) return "EMSCRIPTEN_RESULT_FAILED";
57    if (result == EMSCRIPTEN_RESULT_NO_DATA) return "EMSCRIPTEN_RESULT_NO_DATA";
58    return "Unknown EMSCRIPTEN_RESULT!";
59 }
60
61 default:
62
63 /*
64 public enum KeyCode : Key
65 {
66    escape            = 0x01,
67    // Characters
68    k1                = 0x02,
69    bang              = 0x02,
70    k2                = 0x03,
71    commercial        = 0x03,
72    k3                = 0x04,
73    pound             = 0x04,
74    k4                = 0x05,
75    dollar            = 0x05,
76    k5                = 0x06,
77    percent           = 0x06,
78    k6                = 0x07,
79    circumflex        = 0x07,
80    k7                = 0x08,
81    ampersand         = 0x08,
82    k8                = 0x09,
83    star              = 0x09,
84    k9                = 0x0A,
85    leftParanthesis   = 0x0A,
86    k0                = 0x0B,
87    rightParanthesis  = 0x0A,
88    minus             = 0x0C,
89    underscore        = 0x0C,
90    equal             = 0x0D,
91    plus              = 0x0D,
92    backSpace         = 0x0E,
93    tab               = 0x0F,
94    q                 = 0x10,
95    w                 = 0x11,
96    e                 = 0x12,
97    r                 = 0x13,
98    t                 = 0x14,
99    y                 = 0x15,
100    u                 = 0x16,
101    i                 = 0x17,
102    o                 = 0x18,
103    p                 = 0x19,
104    leftBracket       = 0x1A,
105    rightBracket      = 0x1B,
106    enter             = 0x1C,
107    leftControl       = 0x1D,
108    a                 = 0x1E,
109    s                 = 0x1F,
110    d                 = 0x20,
111    f                 = 0x21,
112    g                 = 0x22,
113    h                 = 0x23,
114    j                 = 0x24,
115    k                 = 0x25,
116    l                 = 0x26,
117    semicolon         = 0x27,
118    colon             = 0x27,
119    quote             = 0x28,
120    doubleQuote       = 0x28,
121    tilde             = 0x29,
122    backQuote         = 0x29,
123    leftShift         = 0x2A,
124    backSlash         = 0x2B,
125    pipe              = 0x2B,
126    z                 = 0x2C,
127    x                 = 0x2D,
128    c                 = 0x2E,
129    v                 = 0x2F,
130    b                 = 0x30,
131    n                 = 0x31,
132    m                 = 0x32,
133    comma             = 0x33,
134    smallerThan       = 0x33,
135    period            = 0x34,
136    greaterThan       = 0x34,
137    slash             = 0x35,
138    questionMark      = 0x35,
139
140    rightShift        = 0x36,
141    keyPadStar        = 0x37,
142    leftAlt           = 0x38,
143    space             = 0x39,
144
145    capsLock          = 0x3A,
146
147    // Function keys 1-10
148    f1                = 0x3B,
149    f2                = 0x3C,
150    f3                = 0x3D,
151    f4                = 0x3E,
152    f5                = 0x3F,
153    f6                = 0x40,
154    f7                = 0x41,
155    f8                = 0x42,
156    f9                = 0x43,
157    f10               = 0x44,
158
159    // Num Pad
160    numLock           = 0x45,
161    scrollLock        = 0x46,
162    keyPadHome        = 0x47,
163    keyPad7           = 0x47,
164    keyPadUp          = 0x48,
165    keyPad8           = 0x48,
166    keyPadPageUp      = 0x49,
167    keyPad9           = 0x49,
168    keyPadMinus       = 0x4A,
169    keyPadLeft        = 0x4B,
170    keyPad4           = 0x4B,
171    keyPad5           = 0x4C,
172    keyPadRight       = 0x4D,
173    keyPad6           = 0x4D,
174    keyPadPlus        = 0x4E,
175    keyPadEnd         = 0x4F,
176    keyPad1           = 0x4F,
177    keyPadDown        = 0x50,
178    keyPad2           = 0x50,
179    keyPadPageDown    = 0x51,
180    keyPad3           = 0x51,
181    keyPadInsert      = 0x52,
182    keyPad0           = 0x52,
183    keyPadDelete      = 0x53,
184    // KeyPadLess        = 0x56,
185
186    // F11-F12
187    f11               = 0x57,
188    f12               = 0x58,
189
190    keyPadEnter       = 0x60,
191    rightControl      = 0x61,
192    keyPadSlash       = 0x62,
193    printScreen       = 0x63,
194    rightAlt          = 0x64,
195    pauseBreak        = 0x65,
196
197    // Function Pad
198    home              = 0x66,
199    up                = 0x67,
200    pageUp            = 0x68,
201    left              = 0x69,
202    right             = 0x6A,
203    end               = 0x6B,
204    down              = 0x6C,
205    pageDown          = 0x6D,
206    insert            = 0x6E,
207    del               = 0x6F,
208
209    // Pseudo keys
210    shift             = 0x100,
211    alt               = 0x101,
212    control           = 0x102,
213    wheelUp           = 0x103,
214    wheelDown         = 0x104,
215    hotKey            = 0x105,
216    defaultKey        = 0x106,
217    capsState         = 0x107,
218    numState          = 0x108,
219    scrollState       = 0x109,
220
221    // Remote Control Buttons
222    play              = 0x201,
223    record            = 0x202,
224    pause             = 0x203,
225    rewind            = 0x204,
226    fastForward       = 0x205,
227    previousTrack     = 0x206,
228    nextTrack         = 0x207,
229    stop              = 0x208,
230    eject             = 0x209,
231    volumeUp          = 0x20A,
232    volumeDown        = 0x20B,
233    mute              = 0x20C,
234    remoteHome        = 0x213,
235    back              = f1,
236    menu1             = f2,
237    menu2             = f3,
238    menu3             = f4,
239    menu4             = f5,
240    select            = enter
241 };
242 */
243
244 static KeyCode keys[256] =
245 {
246    0,                //                            0x00
247    0,                //                            0x01
248    0,                //                            0x02
249    0,                // DOM_VK_CANCEL              0x03 (  3) Cancel key.
250    0,                //                            0x
251    0,                //                            0x
252    0,                // DOM_VK_HELP                0x06 (  6) Help key.
253    0,                //                            0x
254    backSpace,        // DOM_VK_BACK_SPACE          0x08 (  8) Backspace key.
255    tab,              // DOM_VK_TAB                 0x09 (  9) Tab key.
256    0,                //                            0x
257    0,                //                            0x
258    0,                // DOM_VK_CLEAR               0x0C ( 12) "5" key on Numpad when NumLock is unlocked. Or on Mac, clear key which is positioned at NumLock key.
259    enter,            // DOM_VK_RETURN              0x0D ( 13) Return/enter key on the main keyboard.
260    0,                // DOM_VK_ENTER               0x0E ( 14) Reserved, but not used. Obsolete since Gecko 30 (Dropped, see bug 969247.)
261    0,                //                            0x
262    shift,            // DOM_VK_SHIFT               0x10 ( 16) Shift key.
263    control,          // DOM_VK_CONTROL             0x11 ( 17) Control key.
264    alt,              // DOM_VK_ALT                 0x12 ( 18) Alt (Option on Mac) key.
265    pauseBreak,       // DOM_VK_PAUSE               0x13 ( 19) Pause key.
266    0,                // DOM_VK_CAPS_LOCK           0x14 ( 20) Caps lock.
267    0,                // DOM_VK_KANA                0x15 ( 21) Linux support for this keycode was added in Gecko 4.0. //0,                // DOM_VK_HANGUL  0x15 (21) Linux support for this keycode was added in Gecko 4.0.
268    0,                // DOM_VK_EISU                0x16 ( 22) "英数" key on Japanese Mac keyboard.
269    0,                // DOM_VK_JUNJA               0x17 ( 23) Linux support for this keycode was added in Gecko 4.0.
270    0,                // DOM_VK_FINAL               0x18 ( 24) Linux support for this keycode was added in Gecko 4.0.
271    0,                // DOM_VK_HANJA               0x19 ( 25) Linux support for this keycode was added in Gecko 4.0. //0,                // DOM_VK_KANJI   0x19 (25) Linux support for this keycode was added in Gecko 4.0.
272    0,                //                            0x
273    escape,           // DOM_VK_ESCAPE              0x1B ( 27) Escape key.
274    0,                // DOM_VK_CONVERT             0x1C ( 28) Linux support for this keycode was added in Gecko 4.0.
275    0,                // DOM_VK_NONCONVERT          0x1D ( 29) Linux support for this keycode was added in Gecko 4.0.
276    0,                // DOM_VK_ACCEPT              0x1E ( 30) Linux support for this keycode was added in Gecko 4.0.
277    0,                // DOM_VK_MODECHANGE          0x1F ( 31) Linux support for this keycode was added in Gecko 4.0.
278    0,                // DOM_VK_SPACE               0x20 ( 32) Space bar.
279    pageUp,           // DOM_VK_PAGE_UP             0x21 ( 33) Page Up key.
280    pageDown,         // DOM_VK_PAGE_DOWN           0x22 ( 34) Page Down key.
281    end,              // DOM_VK_END                 0x23 ( 35) End key.
282    home,             // DOM_VK_HOME                0x24 ( 36) Home key.
283    left,             // DOM_VK_LEFT                0x25 ( 37) Left arrow.
284    up,               // DOM_VK_UP                  0x26 ( 38) Up arrow.
285    right,            // DOM_VK_RIGHT               0x27 ( 39) Right arrow.
286    down,             // DOM_VK_DOWN                0x28 ( 40) Down arrow.
287    0,                // DOM_VK_SELECT              0x29 ( 41) Linux support for this keycode was added in Gecko 4.0.
288    0,                // DOM_VK_PRINT               0x2A ( 42) Linux support for this keycode was added in Gecko 4.0.
289    0,                // DOM_VK_EXECUTE             0x2B ( 43) Linux support for this keycode was added in Gecko 4.0.
290    printScreen,      // DOM_VK_PRINTSCREEN         0x2C ( 44) Print Screen key.
291    insert,           // DOM_VK_INSERT              0x2D ( 45) Ins(ert) key.
292    del,              // DOM_VK_DELETE              0x2E ( 46) Del(ete) key.
293    0,                //                            0x
294    k0,               // DOM_VK_0                   0x30 ( 48) "0" key in standard key location.
295    k1,               // DOM_VK_1                   0x31 ( 49) "1" key in standard key location.
296    k2,               // DOM_VK_2                   0x32 ( 50) "2" key in standard key location.
297    k3,               // DOM_VK_3                   0x33 ( 51) "3" key in standard key location.
298    k4,               // DOM_VK_4                   0x34 ( 52) "4" key in standard key location.
299    k5,               // DOM_VK_5                   0x35 ( 53) "5" key in standard key location.
300    k6,               // DOM_VK_6                   0x36 ( 54) "6" key in standard key location.
301    k7,               // DOM_VK_7                   0x37 ( 55) "7" key in standard key location.
302    k8,               // DOM_VK_8                   0x38 ( 56) "8" key in standard key location.
303    k9,               // DOM_VK_9                   0x39 ( 57) "9" key in standard key location.
304    colon,            // DOM_VK_COLON               0x3A ( 58) Colon (":") key.
305    semicolon,        // DOM_VK_SEMICOLON           0x3B ( 59) Semicolon (";") key.
306    smallerThan,      // DOM_VK_LESS_THAN           0x3C ( 60) Less-than ("<") key.
307    equal,            // DOM_VK_EQUALS              0x3D ( 61) Equals ("=") key.
308    greaterThan,      // DOM_VK_GREATER_THAN        0x3E ( 62) Greater-than (">") key.
309    questionMark,     // DOM_VK_QUESTION_MARK       0x3F ( 63) Question mark ("?") key.
310    0,                // DOM_VK_AT                  0x40 ( 64) Atmark ("@") key.
311    a,                // DOM_VK_A                   0x41 ( 65) "A" key.
312    b,                // DOM_VK_B                   0x42 ( 66) "B" key.
313    c,                // DOM_VK_C                   0x43 ( 67) "C" key.
314    d,                // DOM_VK_D                   0x44 ( 68) "D" key.
315    e,                // DOM_VK_E                   0x45 ( 69) "E" key.
316    f,                // DOM_VK_F                   0x46 ( 70) "F" key.
317    g,                // DOM_VK_G                   0x47 ( 71) "G" key.
318    h,                // DOM_VK_H                   0x48 ( 72) "H" key.
319    i,                // DOM_VK_I                   0x49 ( 73) "I" key.
320    j,                // DOM_VK_J                   0x4A ( 74) "J" key.
321    k,                // DOM_VK_K                   0x4B ( 75) "K" key.
322    l,                // DOM_VK_L                   0x4C ( 76) "L" key.
323    m,                // DOM_VK_M                   0x4D ( 77) "M" key.
324    n,                // DOM_VK_N                   0x4E ( 78) "N" key.
325    o,                // DOM_VK_O                   0x4F ( 79) "O" key.
326    p,                // DOM_VK_P                   0x50 ( 80) "P" key.
327    q,                // DOM_VK_Q                   0x51 ( 81) "Q" key.
328    r,                // DOM_VK_R                   0x52 ( 82) "R" key.
329    s,                // DOM_VK_S                   0x53 ( 83) "S" key.
330    t,                // DOM_VK_T                   0x54 ( 84) "T" key.
331    u,                // DOM_VK_U                   0x55 ( 85) "U" key.
332    v,                // DOM_VK_V                   0x56 ( 86) "V" key.
333    w,                // DOM_VK_W                   0x57 ( 87) "W" key.
334    x,                // DOM_VK_X                   0x58 ( 88) "X" key.
335    y,                // DOM_VK_Y                   0x59 ( 89) "Y" key.
336    z,                // DOM_VK_Z                   0x5A ( 90) "Z" key.
337    0,                // DOM_VK_WIN                 0x5B ( 91) Windows logo key on Windows. Or Super or Hyper key on Linux.
338    0,                //                            0x
339    0,                // DOM_VK_CONTEXT_MENU        0x5D ( 93) Opening context menu key.
340    0,                //                            0x
341    0,                // DOM_VK_SLEEP               0x5F ( 95) Linux support for this keycode was added in Gecko 4.0.
342    keyPad0,          // DOM_VK_NUMPAD0             0x60 ( 96) "0" on the numeric keypad.
343    keyPad1,          // DOM_VK_NUMPAD1             0x61 ( 97) "1" on the numeric keypad.
344    keyPad2,          // DOM_VK_NUMPAD2             0x62 ( 98) "2" on the numeric keypad.
345    keyPad3,          // DOM_VK_NUMPAD3             0x63 ( 99) "3" on the numeric keypad.
346    keyPad4,          // DOM_VK_NUMPAD4             0x64 (100) "4" on the numeric keypad.
347    keyPad5,          // DOM_VK_NUMPAD5             0x65 (101) "5" on the numeric keypad.
348    keyPad6,          // DOM_VK_NUMPAD6             0x66 (102) "6" on the numeric keypad.
349    keyPad7,          // DOM_VK_NUMPAD7             0x67 (103) "7" on the numeric keypad.
350    keyPad8,          // DOM_VK_NUMPAD8             0x68 (104) "8" on the numeric keypad.
351    keyPad9,          // DOM_VK_NUMPAD9             0x69 (105) "9" on the numeric keypad.
352    keyPadStar,       // DOM_VK_MULTIPLY            0x6A (106) "*" on the numeric keypad.
353    keyPadPlus,       // DOM_VK_ADD                 0x6B (107) "+" on the numeric keypad.
354    0,                // DOM_VK_SEPARATOR           0x6C (108)
355    keyPadMinus,      // DOM_VK_SUBTRACT            0x6D (109) "-" on the numeric keypad.
356    0,                // DOM_VK_DECIMAL             0x6E (110) Decimal point on the numeric keypad.
357    keyPadSlash,      // DOM_VK_DIVIDE              0x6F (111) "/" on the numeric keypad.
358    f1,               // DOM_VK_F1                  0x70 (112) F1 key.
359    f2,               // DOM_VK_F2                  0x71 (113) F2 key.
360    f3,               // DOM_VK_F3                  0x72 (114) F3 key.
361    f4,               // DOM_VK_F4                  0x73 (115) F4 key.
362    f5,               // DOM_VK_F5                  0x74 (116) F5 key.
363    f6,               // DOM_VK_F6                  0x75 (117) F6 key.
364    f7,               // DOM_VK_F7                  0x76 (118) F7 key.
365    f8,               // DOM_VK_F8                  0x77 (119) F8 key.
366    f9,               // DOM_VK_F9                  0x78 (120) F9 key.
367    f10,              // DOM_VK_F10                 0x79 (121) F10 key.
368    f11,              // DOM_VK_F11                 0x7A (122) F11 key.
369    f12,              // DOM_VK_F12                 0x7B (123) F12 key.
370    0,                // DOM_VK_F13                 0x7C (124) F13 key.
371    0,                // DOM_VK_F14                 0x7D (125) F14 key.
372    0,                // DOM_VK_F15                 0x7E (126) F15 key.
373    0,                // DOM_VK_F16                 0x7F (127) F16 key.
374    0,                // DOM_VK_F17                 0x80 (128) F17 key.
375    0,                // DOM_VK_F18                 0x81 (129) F18 key.
376    0,                // DOM_VK_F19                 0x82 (130) F19 key.
377    0,                // DOM_VK_F20                 0x83 (131) F20 key.
378    0,                // DOM_VK_F21                 0x84 (132) F21 key.
379    0,                // DOM_VK_F22                 0x85 (133) F22 key.
380    0,                // DOM_VK_F23                 0x86 (134) F23 key.
381    0,                // DOM_VK_F24                 0x87 (135) F24 key.
382    0,                //                            0x
383    0,                //                            0x
384    0,                //                            0x
385    0,                //                            0x
386    0,                //                            0x
387    0,                //                            0x
388    0,                //                            0x
389    0,                //                            0x
390    numLock,          // DOM_VK_NUM_LOCK            0x90 (144) Num Lock key.
391    scrollLock,       // DOM_VK_SCROLL_LOCK         0x91 (145) Scroll Lock key.
392    0,                // DOM_VK_WIN_OEM_FJ_JISHO    0x92 (146) An OEM specific key on Windows. This was used for "Dictionary" key on Fujitsu OASYS.
393    0,                // DOM_VK_WIN_OEM_FJ_MASSHOU  0x93 (147) An OEM specific key on Windows. This was used for "Unregister word" key on Fujitsu OASYS.
394    0,                // DOM_VK_WIN_OEM_FJ_TOUROKU  0x94 (148) An OEM specific key on Windows. This was used for "Register word" key on Fujitsu OASYS.
395    0,                // DOM_VK_WIN_OEM_FJ_LOYA     0x95 (149) An OEM specific key on Windows. This was used for "Left OYAYUBI" key on Fujitsu OASYS.
396    0,                // DOM_VK_WIN_OEM_FJ_ROYA     0x96 (150) An OEM specific key on Windows. This was used for "Right OYAYUBI" key on Fujitsu OASYS.
397    0,                //                            0x
398    0,                //                            0x
399    0,                //                            0x
400    0,                //                            0x
401    0,                //                            0x
402    0,                //                            0x
403    0,                //                            0x
404    0,                //                            0x
405    0,                //                            0x
406    circumflex,       // DOM_VK_CIRCUMFLEX          0xA0 (160) Circumflex ("^") key.
407    bang,             // DOM_VK_EXCLAMATION         0xA1 (161) Exclamation ("!") key.
408    doubleQuote,      // DOM_VK_DOUBLE_QUOTE        0xA3 (162) Double quote (""") key.
409    pound,            // DOM_VK_HASH                0xA3 (163) Hash ("#") key.
410    dollar,           // DOM_VK_DOLLAR              0xA4 (164) Dollar sign ("$") key.
411    percent,          // DOM_VK_PERCENT             0xA5 (165) Percent ("%") key.
412    ampersand,        // DOM_VK_AMPERSAND           0xA6 (166) Ampersand ("&") key.
413    underscore,       // DOM_VK_UNDERSCORE          0xA7 (167) Underscore ("_") key.
414    leftParanthesis,  // DOM_VK_OPEN_PAREN          0xA8 (168) Open parenthesis ("(") key.
415    rightParanthesis, // DOM_VK_CLOSE_PAREN         0xA9 (169) Close parenthesis (")") key.
416    star,             // DOM_VK_ASTERISK            0xAA (170) Asterisk ("*") key.
417    plus,             // DOM_VK_PLUS                0xAB (171) Plus ("+") key.
418    pipe,             // DOM_VK_PIPE                0xAC (172) Pipe ("|") key.
419    minus,            // DOM_VK_HYPHEN_MINUS        0xAD (173) Hyphen-US/docs/Minus ("-") key.
420    0,                // DOM_VK_OPEN_CURLY_BRACKET  0xAE (174) Open curly bracket ("{") key.
421    0,                // DOM_VK_CLOSE_CURLY_BRACKET 0xAF (175) Close curly bracket ("}") key.
422    tilde,            // DOM_VK_TILDE               0xB0 (176) Tilde ("~") key.
423    0,                //                            0x
424    0,                //                            0x
425    0,                //                            0x
426    0,                //                            0x
427    mute,             // DOM_VK_VOLUME_MUTE         0xB5 (181) Audio mute key.
428    volumeDown,       // DOM_VK_VOLUME_DOWN         0xB6 (182) Audio volume down key
429    volumeUp,         // DOM_VK_VOLUME_UP           0xB7 (183) Audio volume up key
430    0,                //                            0x
431    0,                //                            0x
432    0,                //                            0x
433    0,                //                            0x
434    comma,            // DOM_VK_COMMA               0xBC (188) Comma (",") key.
435    0,                //                            0x
436    period,           // DOM_VK_PERIOD              0xBE (190) Period (".") key.
437    slash,            // DOM_VK_SLASH               0xBF (191) Slash ("/") key.
438    backQuote,        // DOM_VK_BACK_QUOTE          0xC0 (192) Back tick ("`") key.
439    0,                //                            0x
440    0,                //                            0x
441    0,                //                            0x
442    0,                //                            0x
443    0,                //                            0x
444    0,                //                            0x
445    0,                //                            0x
446    0,                //                            0x
447    0,                //                            0x
448    0,                //                            0x
449    0,                //                            0x
450    0,                //                            0x
451    0,                //                            0x
452    0,                //                            0x
453    0,                //                            0x
454    0,                //                            0x
455    0,                //                            0x
456    0,                //                            0x
457    0,                //                            0x
458    0,                //                            0x
459    0,                //                            0x
460    0,                //                            0x
461    0,                //                            0x
462    0,                //                            0x
463    0,                //                            0x
464    0,                //                            0x
465    leftBracket,      // DOM_VK_OPEN_BRACKET        0xDB (219) Open square bracket ("[") key.
466    backSlash,        // DOM_VK_BACK_SLASH          0xDC (220) Back slash ("\") key.
467    rightBracket,     // DOM_VK_CLOSE_BRACKET       0xDD (221) Close square bracket ("]") key.
468    quote,            // DOM_VK_QUOTE               0xDE (222) Quote (''') key.
469    0,                //                            0x
470    0,                // DOM_VK_META                0xE0 (224) Meta key on Linux, Command key on Mac.
471    0,                // DOM_VK_ALTGR               0xE1 (225) AltGr key (Level 3 Shift key or Level 5 Shift key) on Linux.
472    0,                //                            0x
473    0,                // DOM_VK_WIN_ICO_HELP        0xE3 (227) An OEM specific key on Windows. This is (was?) used for Olivetti ICO keyboard.
474    0,                // DOM_VK_WIN_ICO_00          0xE4 (228) An OEM specific key on Windows. This is (was?) used for Olivetti ICO keyboard.
475    0,                //                            0x
476    0,                // DOM_VK_WIN_ICO_CLEAR       0xE6 (230) An OEM specific key on Windows. This is (was?) used for Olivetti ICO keyboard.
477    0,                //                            0x
478    0,                //                            0x
479    0,                // DOM_VK_WIN_OEM_RESET       0xE9 (233) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
480    0,                // DOM_VK_WIN_OEM_JUMP        0xEA (234) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
481    0,                // DOM_VK_WIN_OEM_PA1         0xEB (235) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
482    0,                // DOM_VK_WIN_OEM_PA2         0xEC (236) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
483    0,                // DOM_VK_WIN_OEM_PA3         0xED (237) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
484    0,                // DOM_VK_WIN_OEM_WSCTRL      0xEE (238) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
485    0,                // DOM_VK_WIN_OEM_CUSEL       0xEF (239) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
486    0,                // DOM_VK_WIN_OEM_ATTN        0xF0 (240) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
487    0,                // DOM_VK_WIN_OEM_FINISH      0xF1 (241) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
488    0,                // DOM_VK_WIN_OEM_COPY        0xF2 (242) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
489    0,                // DOM_VK_WIN_OEM_AUTO        0xF3 (243) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
490    0,                // DOM_VK_WIN_OEM_ENLW        0xF4 (244) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
491    0,                // DOM_VK_WIN_OEM_BACKTAB     0xF5 (245) An OEM specific key on Windows. This was used for Nokia/Ericsson's device.
492    0,                // DOM_VK_ATTN                0xF6 (246) Attn (Attention) key of IBM midrange computers, e.g., AS/400.
493    0,                // DOM_VK_CRSEL               0xF7 (247) CrSel (Cursor Selection) key of IBM 3270 keyboard layout.
494    0,                // DOM_VK_EXSEL               0xF8 (248) ExSel (Extend Selection) key of IBM 3270 keyboard layout.
495    0,                // DOM_VK_EREOF               0xF9 (249) Erase EOF key of IBM 3270 keyboard layout.
496    0,                // DOM_VK_PLAY                0xFA (250) Play key of IBM 3270 keyboard layout.
497    0,                // DOM_VK_ZOOM                0xFB (251) Zoom key.
498    0,                //                            0x
499    0,                // DOM_VK_PA1                 0xFD (253) PA1 key of IBM 3270 keyboard layout.
500    0,                // DOM_VK_WIN_OEM_CLEAR       0xFE (254) Clear key, but we're not sure the meaning difference from DOM_VK_CLEAR.
501    0
502 };
503
504 private EM_BOOL em_key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData)
505 {
506    uint method;
507    Key key = keys[e->keyCode ? e->keyCode : e->which];
508    unichar character = e->charCode ? e->charCode : e->which;
509    PrintLn(key, " | ", character);
510
511    printf("%s, key: \"%s\", code: \"%s\", location: %lu,%s%s%s%s repeat: %d, locale: \"%s\", char: \"%s\", charCode: %lu, keyCode: %lu, which: %lu\n",
512          emscripten_event_type_to_string(eventType), e->key, e->code, e->location,
513          e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "",
514          e->repeat, e->locale, e->charValue, e->charCode, e->keyCode, e->which);
515
516    switch(eventType)
517    {
518       case EMSCRIPTEN_EVENT_KEYPRESS: method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;  break;
519       case EMSCRIPTEN_EVENT_KEYDOWN:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown; break;
520       case EMSCRIPTEN_EVENT_KEYUP:    method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp;   break;
521       default:                        method = 0;
522    }
523
524    if(method)
525       /*result = */guiApp.desktop.KeyMessage(method, key, character);
526    return 0;
527 }
528
529 private EM_BOOL em_mouse_callback(int eventType, const EmscriptenMouseEvent *e, void *userData)
530 {
531    uint method;
532    Modifiers mods = 0;
533    bool consequential = false;
534    bool activate = false;
535
536    canvasX = e->canvasX;
537    canvasY = e->canvasY;
538
539    printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, movement: (%ld,%ld), canvas: (%ld,%ld)\n",
540          emscripten_event_type_to_string(eventType), e->screenX, e->screenY, e->clientX, e->clientY,
541          e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "",
542          e->button, e->buttons, e->movementX, e->movementY, e->canvasX, e->canvasY);
543
544    if(e->shiftKey) mods.shift = true;
545    if(e->ctrlKey) mods.ctrl = true;
546    if(e->altKey) mods.alt = true;
547    //if(e->metaKey) mods.meta = true;
548
549    // e->buttons
550    switch(eventType)
551    {
552       //case EMSCRIPTEN_EVENT_CLICK:      method = 0; break;
553       case EMSCRIPTEN_EVENT_MOUSEDOWN:
554          switch(e->button)
555          {
556             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;    break;
557             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;  break;
558             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown;   break;
559             default:                    method = 0;
560          }
561          break;
562       case EMSCRIPTEN_EVENT_MOUSEUP:
563          switch(e->button)
564          {
565             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;      break;
566             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;    break;
567             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;     break;
568             default:                    method = 0;
569          }
570          break;
571       case EMSCRIPTEN_EVENT_DBLCLICK:
572          switch(e->button)
573          {
574             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;   break;
575             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick; break;
576             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick;  break;
577             default:                    method = 0;
578          }
579          break;
580       case EMSCRIPTEN_EVENT_MOUSEMOVE:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
581       //case EMSCRIPTEN_EVENT_MOUSEENTER: method = 0; break;
582       //case EMSCRIPTEN_EVENT_MOUSELEAVE: method = 0; break;
583       case EMSCRIPTEN_EVENT_MOUSEOVER:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
584       //case EMSCRIPTEN_EVENT_MOUSEOUT:   method = 0; break;
585       default:                          method = 0;
586    }
587
588    if(method)
589       // e->screenX, e->screenY, e->clientX, e->clientY, e->movementX, e->movementY
590       guiApp.desktop.MouseMessage(method, e->canvasX, e->canvasY, &mods, consequential, true);
591    return 0;
592 }
593
594 private EM_BOOL em_wheel_callback(int eventType, const EmscriptenWheelEvent *e, void *userData)
595 {
596    printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, canvas: (%ld,%ld), delta:(%g,%g,%g), deltaMode:%lu\n",
597          emscripten_event_type_to_string(eventType), e->mouse.screenX, e->mouse.screenY, e->mouse.clientX, e->mouse.clientY,
598          e->mouse.ctrlKey ? " CTRL" : "", e->mouse.shiftKey ? " SHIFT" : "", e->mouse.altKey ? " ALT" : "", e->mouse.metaKey ? " META" : "",
599          e->mouse.button, e->mouse.buttons, e->mouse.canvasX, e->mouse.canvasY,
600          (float)e->deltaX, (float)e->deltaY, (float)e->deltaZ, e->deltaMode);
601    return 0;
602 }
603
604 private EM_BOOL em_uievent_callback(int eventType, const EmscriptenUiEvent *e, void *userData)
605 {
606    printf("%s, detail: %ld, document.body.client size: (%d,%d), window.inner size: (%d,%d), scrollPos: (%d, %d)\n",
607          emscripten_event_type_to_string(eventType), e->detail, e->documentBodyClientWidth, e->documentBodyClientHeight,
608          e->windowInnerWidth, e->windowInnerHeight, e->scrollTop, e->scrollLeft);
609    return 0;
610 }
611
612 private EM_BOOL em_focusevent_callback(int eventType, const EmscriptenFocusEvent *e, void *userData)
613 {
614    printf("%s, nodeName: \"%s\", id: \"%s\"\n", emscripten_event_type_to_string(eventType), e->nodeName, e->id[0] == '\0' ? "(empty string)" : e->id);
615    return 0;
616 }
617
618 private EM_BOOL em_deviceorientation_callback(int eventType, const EmscriptenDeviceOrientationEvent *e, void *userData)
619 {
620    printf("%s, (%g, %g, %g)\n", emscripten_event_type_to_string(eventType), e->alpha, e->beta, e->gamma);
621    return 0;
622 }
623
624 private EM_BOOL em_devicemotion_callback(int eventType, const EmscriptenDeviceMotionEvent *e, void *userData)
625 {
626    printf("%s, accel: (%g, %g, %g), accelInclGravity: (%g, %g, %g), rotationRate: (%g, %g, %g)\n",
627    emscripten_event_type_to_string(eventType),
628    e->accelerationX, e->accelerationY, e->accelerationZ,
629    e->accelerationIncludingGravityX, e->accelerationIncludingGravityY, e->accelerationIncludingGravityZ,
630    e->rotationRateAlpha, e->rotationRateBeta, e->rotationRateGamma);
631    return 0;
632 }
633
634 private EM_BOOL em_orientationchange_callback(int eventType, const EmscriptenOrientationChangeEvent *e, void *userData)
635 {
636    printf("%s, orientationAngle: %d, orientationIndex: %d\n", emscripten_event_type_to_string(eventType), e->orientationAngle, e->orientationIndex);
637    return 0;
638 }
639
640 private EM_BOOL em_fullscreenchange_callback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData)
641 {
642    printf("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: \"%s\", fs element id: \"%s\". New size: %dx%d pixels. Screen size: %dx%d pixels.\n",
643    emscripten_event_type_to_string(eventType), e->isFullscreen, e->fullscreenEnabled, e->nodeName, e->id, e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
644    return 0;
645 }
646
647 private EM_BOOL em_pointerlockchange_callback(int eventType, const EmscriptenPointerlockChangeEvent *e, void *userData)
648 {
649    printf("%s, isActive: %d, pointerlock element nodeName: \"%s\", id: \"%s\"\n",
650    emscripten_event_type_to_string(eventType), e->isActive, e->nodeName, e->id);
651    return 0;
652 }
653
654 private EM_BOOL em_visibilitychange_callback(int eventType, const EmscriptenVisibilityChangeEvent *e, void *userData)
655 {
656    printf("%s, hidden: %d, visibilityState: %d\n", emscripten_event_type_to_string(eventType), e->hidden, e->visibilityState);
657    return 0;
658 }
659
660 #if 0
661 private EM_BOOL em_touch_callback(int eventType, const EmscriptenTouchEvent *e, void *userData)
662 {
663    printf("%s, numTouches: %d %s%s%s%s\n",
664    emscripten_event_type_to_string(eventType), e->numTouches,
665    e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "");
666    for(int i = 0; i < e->numTouches; ++i)
667    {
668    const EmscriptenTouchPoint *t = &e->touches[i];
669    printf("  %ld: screen: (%ld,%ld), client: (%ld,%ld), page: (%ld,%ld), isChanged: %d, onTarget: %d, canvas: (%ld, %ld)\n",
670    t->identifier, t->screenX, t->screenY, t->clientX, t->clientY, t->pageX, t->pageY, t->isChanged, t->onTarget, t->canvasX, t->canvasY);
671 }
672
673 return 0;
674 }
675
676 private EM_BOOL em_gamepad_callback(int eventType, const EmscriptenGamepadEvent *e, void *userData)
677 {
678    printf("%s: timeStamp: %g, connected: %d, index: %ld, numAxes: %d, numButtons: %d, id: \"%s\", mapping: \"%s\"\n",
679    eventType != 0 ? emscripten_event_type_to_string(eventType) : "Gamepad state", e->timestamp, e->connected, e->index,
680    e->numAxes, e->numButtons, e->id, e->mapping);
681
682    if (e->connected)
683    {
684       for(int i = 0; i < e->numAxes; ++i)
685          printf("Axis %d: %g\n", i, e->axis[i]);
686       for(int i = 0; i < e->numButtons; ++i)
687          printf("Button %d: Digital: %d, Analog: %g\n", i, e->digitalButton[i], e->analogButton[i]);
688    }
689    return 0;
690 }
691
692 const char *beforeunload_callback(int eventType, const void *reserved, void *userData)
693 {
694    #ifdef REPORT_RESULT
695    return ""; // For test harness, don't show a confirmation dialog to not block and keep the test runner automated.
696    #else
697    return "Do you really want to leave the page?";
698    #endif
699 }
700
701 private EM_BOOL em_battery_callback(int eventType, const EmscriptenBatteryEvent *e, void *userData)
702 {
703    char t1[64];
704    formatTime(t1, (int)e->chargingTime);
705    char t2[64];
706    formatTime(t2, (int)e->dischargingTime);
707    printf("%s: chargingTime: %s, dischargingTime: %s, level: %g%%, charging: %d\n",
708    emscripten_event_type_to_string(eventType), t1, t2, e->level*100, e->charging);
709    return 0;
710 }
711
712 private EM_BOOL em_webglcontext_callback(int eventType, const void *reserved, void *userData)
713 {
714    printf("%s.\n", emscripten_event_type_to_string(eventType));
715    return 0;
716 }
717 #endif
718
719 default:
720 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
721 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp;
722 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
723 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
724 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;
725 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;
726 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;
727 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;
728 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick;
729 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;
730 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;
731 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick;
732 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown;
733 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;
734 private:
735
736 class EmscriptenInterface : Interface
737 {
738    class_property(name) = "Emscripten";
739
740
741    // --- User Interface System ---
742
743    bool ::Initialize()
744    {
745       sflnprintf("class(EmscriptenInterface) ::Initialize [STUB!]\n");
746       guiApp.desktop.ExternalPosition(0,0, 800, 240);
747
748 #ifdef __EMSCRIPTEN__
749
750       {
751       EMSCRIPTEN_RESULT ret;
752
753       ret = emscripten_set_keypress_callback(0, 0, 1, em_key_callback);
754       //TEST_RESULT(emscripten_set_keypress_callback);
755       ret = emscripten_set_keydown_callback(0, 0, 1, em_key_callback);
756       //TEST_RESULT(emscripten_set_keydown_callback);
757       ret = emscripten_set_keyup_callback(0, 0, 1, em_key_callback);
758       //TEST_RESULT(emscripten_set_keyup_callback);
759
760       //ret = emscripten_set_click_callback(0, 0, 1, em_mouse_callback);
761       //TEST_RESULT(emscripten_set_click_callback);
762       ret = emscripten_set_mousedown_callback(0, 0, 1, em_mouse_callback);
763       //TEST_RESULT(emscripten_set_mousedown_callback);
764       ret = emscripten_set_mouseup_callback(0, 0, 1, em_mouse_callback);
765       //TEST_RESULT(emscripten_set_mouseup_callback);
766       ret = emscripten_set_dblclick_callback(0, 0, 1, em_mouse_callback);
767       //TEST_RESULT(emscripten_set_dblclick_callback);
768       ret = emscripten_set_mousemove_callback(0, 0, 1, em_mouse_callback);
769       //TEST_RESULT(emscripten_set_mousemove_callback);
770       ret = emscripten_set_mouseenter_callback(0, 0, 1, em_mouse_callback);
771       //TEST_RESULT(emscripten_set_mouseenter_callback);
772       ret = emscripten_set_mouseleave_callback(0, 0, 1, em_mouse_callback);
773       //TEST_RESULT(emscripten_set_mouseleave_callback);
774       ret = emscripten_set_mouseover_callback(0, 0, 1, em_mouse_callback);
775       //TEST_RESULT(emscripten_set_mouseover_callback);
776       ret = emscripten_set_mouseout_callback(0, 0, 1, em_mouse_callback);
777       //TEST_RESULT(emscripten_set_mouseout_callback);
778
779       ret = emscripten_set_wheel_callback(0, 0, 1, em_wheel_callback);
780       //TEST_RESULT(emscripten_set_wheel_callback);
781
782       ret = emscripten_set_resize_callback(0, 0, 1, em_uievent_callback);
783       //TEST_RESULT(emscripten_set_resize_callback);
784       ret = emscripten_set_scroll_callback(0, 0, 1, em_uievent_callback);
785       //TEST_RESULT(emscripten_set_scroll_callback);
786
787       ret = emscripten_set_blur_callback(0, 0, 1, em_focusevent_callback);
788       //TEST_RESULT(emscripten_set_blur_callback);
789       ret = emscripten_set_focus_callback(0, 0, 1, em_focusevent_callback);
790       //TEST_RESULT(emscripten_set_focus_callback);
791       ret = emscripten_set_focusin_callback(0, 0, 1, em_focusevent_callback);
792       //TEST_RESULT(emscripten_set_focusin_callback);
793       ret = emscripten_set_focusout_callback(0, 0, 1, em_focusevent_callback);
794       //TEST_RESULT(emscripten_set_focusout_callback);
795
796       ret = emscripten_set_deviceorientation_callback(0, 1, em_deviceorientation_callback);
797       //TEST_RESULT(emscripten_set_deviceorientation_callback);
798       ret = emscripten_set_devicemotion_callback(0, 1, em_devicemotion_callback);
799       //TEST_RESULT(emscripten_set_devicemotion_callback);
800
801       ret = emscripten_set_orientationchange_callback(0, 1, em_orientationchange_callback);
802       //TEST_RESULT(emscripten_set_orientationchange_callback);
803
804 #if 0
805       // Test the polling of orientation.
806       EmscriptenOrientationChangeEvent oce;
807       ret = emscripten_get_orientation_status(&oce);
808       //TEST_RESULT(emscripten_get_orientation_status);
809       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
810       printf("The current orientation is:\n");
811       orientationchange_callback(EMSCRIPTEN_EVENT_ORIENTATIONCHANGE, &oce, 0);
812       }
813
814       int newOrientation = (oce.orientationIndex == EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY
815       || oce.orientationIndex == EMSCRIPTEN_ORIENTATION_PORTRAIT_SECONDARY) ? EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY : EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY;
816       // Test locking of orientation.
817       ret = emscripten_lock_orientation(newOrientation);
818       //TEST_RESULT(emscripten_lock_orientation);
819       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
820       printf("Locked orientation to state %d.\n", newOrientation);
821       }
822
823       ret = emscripten_get_orientation_status(&oce);
824       //TEST_RESULT(emscripten_get_orientation_status);
825       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
826       printf("The current orientation is after locking:\n");
827       orientationchange_callback(18, &oce, 0);
828       }
829
830       ret = emscripten_unlock_orientation();
831       //TEST_RESULT(emscripten_unlock_orientation);
832       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
833       printf("Unlocked orientation.\n");
834       }
835
836       EmscriptenFullscreenChangeEvent fsce;
837       ret = emscripten_get_fullscreen_status(&fsce);
838       //TEST_RESULT(emscripten_get_fullscreen_status);
839       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
840       printf("The current fullscreen status is:\n");
841       fullscreenchange_callback(EMSCRIPTEN_EVENT_FULLSCREENCHANGE, &fsce, 0);
842       }
843
844       ret = emscripten_set_fullscreenchange_callback(0, 0, 1, em_fullscreenchange_callback);
845       //TEST_RESULT(emscripten_set_fullscreenchange_callback);
846
847       // These won't do anything, since fullscreen must be requested in an event handler,
848       // but call these anyways to confirm that they don't crash in an exception in the test suite.
849       ret = emscripten_request_fullscreen(0, 1);
850       //TEST_RESULT(emscripten_request_fullscreen);
851       ret = emscripten_exit_fullscreen();
852       //TEST_RESULT(emscripten_exit_fullscreen);
853
854       EmscriptenPointerlockChangeEvent plce;
855       ret = emscripten_get_pointerlock_status(&plce);
856       //TEST_RESULT(emscripten_get_pointerlock_status);
857       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
858       printf("The current pointerlock status is:\n");
859       pointerlockchange_callback(EMSCRIPTEN_EVENT_POINTERLOCKCHANGE, &plce, 0);
860       }
861
862       ret = emscripten_set_pointerlockchange_callback(0, 0, 1, em_pointerlockchange_callback);
863       //TEST_RESULT(emscripten_set_pointerlockchange_callback);
864
865       // These won't do anything, since pointer lock must be requested in an event handler,
866       // but call these anyways to confirm that they don't crash in an exception in the test suite.
867       ret = emscripten_request_pointerlock(0, 1);
868       //TEST_RESULT(emscripten_request_pointerlock);
869       ret = emscripten_exit_pointerlock();
870       //TEST_RESULT(emscripten_exit_pointerlock);
871
872       int vibratePattern[] = {
873       150, 500,
874       300, 500,
875       450
876       };
877       ret = emscripten_vibrate_pattern(vibratePattern, sizeof(vibratePattern)/sizeof(vibratePattern[0]));
878       //TEST_RESULT(emscripten_vibrate_pattern);
879
880       EmscriptenVisibilityChangeEvent vce;
881       ret = emscripten_get_visibility_status(&vce);
882       //TEST_RESULT(emscripten_get_visibility_status);
883       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
884       printf("Current visibility status:\n");
885       visibilitychange_callback(EMSCRIPTEN_EVENT_VISIBILITYCHANGE, &vce, 0);
886       }
887
888       ret = emscripten_set_visibilitychange_callback(0, 1, visibilitychange_callback);
889       //TEST_RESULT(emscripten_set_visibilitychange_callback);
890
891       ret = emscripten_set_touchstart_callback(0, 0, 1, em_touch_callback);
892       //TEST_RESULT(emscripten_set_touchstart_callback);
893       ret = emscripten_set_touchend_callback(0, 0, 1, em_touch_callback);
894       //TEST_RESULT(emscripten_set_touchend_callback);
895       ret = emscripten_set_touchmove_callback(0, 0, 1, em_touch_callback);
896       //TEST_RESULT(emscripten_set_touchmove_callback);
897       ret = emscripten_set_touchcancel_callback(0, 0, 1, em_touch_callback);
898       //TEST_RESULT(emscripten_set_touchcancel_callback);
899
900       ret = emscripten_set_gamepadconnected_callback(0, 1, gamepad_callback);
901       //TEST_RESULT(emscripten_set_gamepadconnected_callback);
902       ret = emscripten_set_gamepaddisconnected_callback(0, 1, gamepad_callback);
903       //TEST_RESULT(emscripten_set_gamepaddisconnected_callback);
904
905       emscripten_set_main_loop(mainloop, 10, 0);
906
907       ret = emscripten_set_beforeunload_callback(0, beforeunload_callback);
908       //TEST_RESULT(emscripten_set_beforeunload_callback);
909
910       ret = emscripten_set_batterychargingchange_callback(0, battery_callback);
911       //TEST_RESULT(emscripten_set_batterychargingchange_callback);
912       ret = emscripten_set_batterylevelchange_callback(0, battery_callback);
913       //TEST_RESULT(emscripten_set_batterylevelchange_callback);
914
915       EmscriptenBatteryEvent bs;
916       ret = emscripten_get_battery_status(&bs);
917       //TEST_RESULT(emscripten_get_battery_status);
918       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
919       printf("Current battery status:\n");
920       battery_callback(EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE, &bs, 0);
921       }
922
923       ret = emscripten_set_webglcontextlost_callback(0, 0, 1, em_webglcontext_callback);
924       //TEST_RESULT(emscripten_set_webglcontextlost_callback);
925       ret = emscripten_set_webglcontextrestored_callback(0, 0, 1, em_webglcontext_callback);
926       //TEST_RESULT(emscripten_set_webglcontextrestored_callback);
927 #endif
928       }
929 #endif
930
931       return true;
932    }
933
934    void ::Terminate()
935    {
936       sflnprintf("class(EmscriptenInterface) ::Terminate [STUB!]\n");
937    }
938
939    bool ::ProcessInput(bool processAll)
940    {
941       //sflnprintf("class(EmscriptenInterface) ::ProcessInput [STUB!]\n");
942       return false;
943    }
944
945    void ::Wait()
946    {
947       sflnprintf("class(EmscriptenInterface) ::Wait [STUB!]\n");
948    }
949
950    void ::Lock(Window window)
951    {
952       sflnprintf("class(EmscriptenInterface) ::Lock [STUB!]\n");
953    }
954
955    void ::Unlock(Window window)
956    {
957       sflnprintf("class(EmscriptenInterface) ::Unlock [STUB!]\n");
958    }
959
960    void ::SetTimerResolution(uint hertz)
961    {
962       sflnprintf("class(EmscriptenInterface) ::SetTimerResolution [STUB!] Implement high resolution timer here\n");
963    }
964
965    const char ** ::GraphicsDrivers(int * numDrivers)
966    {
967       //sflnprintf("class(EmscriptenInterface) ::GraphicsDrivers [STUB!]\n");
968       static const char *graphicsDrivers[] = { "OpenGL" };
969       *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
970       return (const char **)graphicsDrivers;
971       return null;
972    }
973
974    void ::EnsureFullScreen(bool * fullScreen)
975    {
976       sflnprintf("class(EmscriptenInterface) ::EnsureFullScreen [STUB!]\n");
977       *fullScreen = true;
978    }
979
980    void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
981    {
982       sflnprintf("class(EmscriptenInterface) ::GetCurrentMode [STUB!]\n");
983    }
984
985    bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
986    {
987       sflnprintf("class(EmscriptenInterface) ::ScreenMode [STUB!]\n");
988       return true;
989    }
990
991
992    // --- Window Creation ---
993
994    void * ::CreateRootWindow(Window window)
995    {
996       sflnprintf("class(EmscriptenInterface) ::CreateRootWindow [STUB!]\n");
997       return null;
998    }
999
1000    void ::DestroyRootWindow(Window window)
1001    {
1002       sflnprintf("class(EmscriptenInterface) ::DestroyRootWindow [STUB!]\n");
1003    }
1004
1005
1006    // --- Window manipulation ---
1007
1008    void ::SetRootWindowCaption(Window window, const char * name)
1009    {
1010       sflnprintf("class(EmscriptenInterface) ::SetRootWindowCaption [STUB!]\n");
1011    }
1012
1013    void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
1014    {
1015       sflnprintf("class(EmscriptenInterface) ::Stub [STUB!]\n");
1016    }
1017
1018    void ::OffsetWindow(Window window, int * x, int * y)
1019    {
1020       //sflnprintf("class(EmscriptenInterface) ::OffsetWindow [STUB!]\n");
1021    }
1022
1023    void ::UpdateRootWindow(Window window)
1024    {
1025       sflnprintf("class(EmscriptenInterface) ::UpdateRootWindow [STUB!]\n");
1026    }
1027
1028    void ::SetRootWindowState(Window window, WindowState state, bool visible)
1029    {
1030       sflnprintf("class(EmscriptenInterface) ::SetRootWindowState [STUB!]\n");
1031    }
1032
1033    void ::ActivateRootWindow(Window window)
1034    {
1035       sflnprintf("class(EmscriptenInterface) ::ActivateRootWindow [STUB!]\n");
1036    }
1037
1038    void ::OrderRootWindow(Window window, bool topMost)
1039    {
1040       sflnprintf("class(EmscriptenInterface) ::OrderRootWindow [STUB!]\n");
1041    }
1042
1043    void ::SetRootWindowColor(Window window)
1044    {
1045       sflnprintf("class(EmscriptenInterface) ::SetRootWindowColor [STUB!]\n");
1046    }
1047
1048    void ::FlashRootWindow(Window window)
1049    {
1050       sflnprintf("class(EmscriptenInterface) ::FlashRootWindow [STUB!]\n");
1051    }
1052
1053
1054    // --- Mouse-based window movement ---
1055
1056    void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
1057    {
1058       sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
1059    }
1060
1061    void ::StopMoving(Window window)
1062    {
1063       sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
1064    }
1065
1066
1067    // --- Mouse manipulation ---
1068
1069    void ::GetMousePosition(int *x, int *y)
1070    {
1071       *x = canvasX;
1072       *y = canvasY;
1073    }
1074
1075    void ::SetMousePosition(int x, int y)
1076    {
1077       sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
1078    }
1079
1080    void ::SetMouseRange(Window window, Box box)
1081    {
1082       sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
1083    }
1084
1085    void ::SetMouseCapture(Window window)
1086    {
1087       sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
1088    }
1089
1090
1091    // --- Mouse cursor ---
1092
1093    void ::SetMouseCursor(Window window, SystemCursor cursor)
1094    {
1095       sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
1096    }
1097
1098
1099    // --- Caret manipulation ---
1100
1101    void ::SetCaret(int caretX, int caretY, int size)
1102    {
1103       sflnprintf("class(EmscriptenInterface) ::SetCaret [STUB!]\n");
1104    }
1105
1106
1107    // --- Clipboard manipulation ---
1108
1109    void ::ClearClipboard()
1110    {
1111       sflnprintf("class(EmscriptenInterface) ::ClearClipboard [STUB!]\n");
1112    }
1113
1114    bool ::AllocateClipboard(ClipBoard clipBoard, uint size)
1115    {
1116       sflnprintf("class(EmscriptenInterface) ::AllocateClipboard [STUB!]\n");
1117       return false;
1118    }
1119
1120    bool ::SaveClipboard(ClipBoard clipBoard)
1121    {
1122       sflnprintf("class(EmscriptenInterface) ::SaveClipboard [STUB!]\n");
1123       return false;
1124    }
1125
1126    bool ::LoadClipboard(ClipBoard clipBoard)
1127    {
1128       sflnprintf("class(EmscriptenInterface) ::LoadClipboard [STUB!]\n");
1129       return false;
1130    }
1131
1132    void ::UnloadClipboard(ClipBoard clipBoard)
1133    {
1134       sflnprintf("class(EmscriptenInterface) ::UnloadClipboard [STUB!]\n");
1135    }
1136
1137
1138    // --- State based input ---
1139
1140    bool ::AcquireInput(Window window, bool state)
1141    {
1142       sflnprintf("class(EmscriptenInterface) ::AcquireInput [STUB!]\n");
1143       return false;
1144    }
1145
1146    bool ::GetMouseState(MouseButtons * buttons, int * x, int * y)
1147    {
1148       sflnprintf("class(EmscriptenInterface) ::GetMouseState [STUB!]\n");
1149       return false;
1150    }
1151
1152    bool ::GetJoystickState(int device, Joystick joystick)
1153    {
1154       sflnprintf("class(EmscriptenInterface) ::GetJoystickState [STUB!]\n");
1155       return false;
1156    }
1157
1158    bool ::GetKeyState(Key key)
1159    {
1160       sflnprintf("class(EmscriptenInterface) ::GetKeyState [STUB!]\n");
1161       return false;
1162    }
1163
1164    bool ::SetIcon(Window window, BitmapResource icon)
1165    {
1166       sflnprintf("class(EmscriptenInterface) ::SetIcon [STUB!]\n");
1167       return false;
1168    }
1169
1170    void ::GetScreenArea(Window window, Box box)
1171    {
1172       sflnprintf("class(EmscriptenInterface) ::GetScreenArea [STUB!]\n");
1173    }
1174 }
1175
1176 #endif