<wip> emscripten dev.
[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 #if 0
540    printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, movement: (%ld,%ld), canvas: (%ld,%ld)\n",
541          emscripten_event_type_to_string(eventType), e->screenX, e->screenY, e->clientX, e->clientY,
542          e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "",
543          e->button, e->buttons, e->movementX, e->movementY, e->canvasX, e->canvasY);
544 #endif
545
546    if(e->shiftKey) mods.shift = true;
547    if(e->ctrlKey) mods.ctrl = true;
548    if(e->altKey) mods.alt = true;
549    //if(e->metaKey) mods.meta = true;
550
551    // e->buttons
552    switch(eventType)
553    {
554       //case EMSCRIPTEN_EVENT_CLICK:      method = 0; break;
555       case EMSCRIPTEN_EVENT_MOUSEDOWN:
556          switch(e->button)
557          {
558             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;    break;
559             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;  break;
560             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown;   break;
561             default:                    method = 0;
562          }
563          break;
564       case EMSCRIPTEN_EVENT_MOUSEUP:
565          switch(e->button)
566          {
567             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;      break;
568             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;    break;
569             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;     break;
570             default:                    method = 0;
571          }
572          break;
573       case EMSCRIPTEN_EVENT_DBLCLICK:
574          switch(e->button)
575          {
576             case 0: mods.left = true;   method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;   break;
577             case 1: mods.middle = true; method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick; break;
578             case 2: mods.right = true;  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick;  break;
579             default:                    method = 0;
580          }
581          break;
582       case EMSCRIPTEN_EVENT_MOUSEMOVE:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
583       case EMSCRIPTEN_EVENT_MOUSEENTER: method = 0; break;
584       case EMSCRIPTEN_EVENT_MOUSELEAVE: method = 0; break;
585       case EMSCRIPTEN_EVENT_MOUSEOVER:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
586       case EMSCRIPTEN_EVENT_MOUSEOUT:   method = 0; break;
587       default:                          method = 0;
588    }
589
590    if(method)
591       // e->screenX, e->screenY, e->clientX, e->clientY, e->movementX, e->movementY
592       guiApp.desktop.MouseMessage(method, e->canvasX, e->canvasY, &mods, consequential, true);
593    return 0;
594 }
595
596 private EM_BOOL em_wheel_callback(int eventType, const EmscriptenWheelEvent *e, void *userData)
597 {
598    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",
599          emscripten_event_type_to_string(eventType), e->mouse.screenX, e->mouse.screenY, e->mouse.clientX, e->mouse.clientY,
600          e->mouse.ctrlKey ? " CTRL" : "", e->mouse.shiftKey ? " SHIFT" : "", e->mouse.altKey ? " ALT" : "", e->mouse.metaKey ? " META" : "",
601          e->mouse.button, e->mouse.buttons, e->mouse.canvasX, e->mouse.canvasY,
602          (float)e->deltaX, (float)e->deltaY, (float)e->deltaZ, e->deltaMode);
603    return 0;
604 }
605
606 private EM_BOOL em_uievent_callback(int eventType, const EmscriptenUiEvent *e, void *userData)
607 {
608    printf("%s, detail: %ld, document.body.client size: (%d,%d), window.inner size: (%d,%d), scrollPos: (%d, %d)\n",
609          emscripten_event_type_to_string(eventType), e->detail, e->documentBodyClientWidth, e->documentBodyClientHeight,
610          e->windowInnerWidth, e->windowInnerHeight, e->scrollTop, e->scrollLeft);
611    return 0;
612 }
613
614 private EM_BOOL em_focusevent_callback(int eventType, const EmscriptenFocusEvent *e, void *userData)
615 {
616    printf("%s, nodeName: \"%s\", id: \"%s\"\n", emscripten_event_type_to_string(eventType), e->nodeName, e->id[0] == '\0' ? "(empty string)" : e->id);
617    return 0;
618 }
619
620 private EM_BOOL em_deviceorientation_callback(int eventType, const EmscriptenDeviceOrientationEvent *e, void *userData)
621 {
622    printf("%s, (%g, %g, %g)\n", emscripten_event_type_to_string(eventType), e->alpha, e->beta, e->gamma);
623    return 0;
624 }
625
626 private EM_BOOL em_devicemotion_callback(int eventType, const EmscriptenDeviceMotionEvent *e, void *userData)
627 {
628    printf("%s, accel: (%g, %g, %g), accelInclGravity: (%g, %g, %g), rotationRate: (%g, %g, %g)\n",
629    emscripten_event_type_to_string(eventType),
630    e->accelerationX, e->accelerationY, e->accelerationZ,
631    e->accelerationIncludingGravityX, e->accelerationIncludingGravityY, e->accelerationIncludingGravityZ,
632    e->rotationRateAlpha, e->rotationRateBeta, e->rotationRateGamma);
633    return 0;
634 }
635
636 private EM_BOOL em_orientationchange_callback(int eventType, const EmscriptenOrientationChangeEvent *e, void *userData)
637 {
638    printf("%s, orientationAngle: %d, orientationIndex: %d\n", emscripten_event_type_to_string(eventType), e->orientationAngle, e->orientationIndex);
639    return 0;
640 }
641
642 private EM_BOOL em_fullscreenchange_callback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData)
643 {
644    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",
645    emscripten_event_type_to_string(eventType), e->isFullscreen, e->fullscreenEnabled, e->nodeName, e->id, e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
646    return 0;
647 }
648
649 private EM_BOOL em_pointerlockchange_callback(int eventType, const EmscriptenPointerlockChangeEvent *e, void *userData)
650 {
651    printf("%s, isActive: %d, pointerlock element nodeName: \"%s\", id: \"%s\"\n",
652    emscripten_event_type_to_string(eventType), e->isActive, e->nodeName, e->id);
653    return 0;
654 }
655
656 private EM_BOOL em_visibilitychange_callback(int eventType, const EmscriptenVisibilityChangeEvent *e, void *userData)
657 {
658    printf("%s, hidden: %d, visibilityState: %d\n", emscripten_event_type_to_string(eventType), e->hidden, e->visibilityState);
659    return 0;
660 }
661
662 #if 0
663 private EM_BOOL em_touch_callback(int eventType, const EmscriptenTouchEvent *e, void *userData)
664 {
665    printf("%s, numTouches: %d %s%s%s%s\n",
666    emscripten_event_type_to_string(eventType), e->numTouches,
667    e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "");
668    for(int i = 0; i < e->numTouches; ++i)
669    {
670    const EmscriptenTouchPoint *t = &e->touches[i];
671    printf("  %ld: screen: (%ld,%ld), client: (%ld,%ld), page: (%ld,%ld), isChanged: %d, onTarget: %d, canvas: (%ld, %ld)\n",
672    t->identifier, t->screenX, t->screenY, t->clientX, t->clientY, t->pageX, t->pageY, t->isChanged, t->onTarget, t->canvasX, t->canvasY);
673 }
674
675 return 0;
676 }
677
678 private EM_BOOL em_gamepad_callback(int eventType, const EmscriptenGamepadEvent *e, void *userData)
679 {
680    printf("%s: timeStamp: %g, connected: %d, index: %ld, numAxes: %d, numButtons: %d, id: \"%s\", mapping: \"%s\"\n",
681    eventType != 0 ? emscripten_event_type_to_string(eventType) : "Gamepad state", e->timestamp, e->connected, e->index,
682    e->numAxes, e->numButtons, e->id, e->mapping);
683
684    if (e->connected)
685    {
686       for(int i = 0; i < e->numAxes; ++i)
687          printf("Axis %d: %g\n", i, e->axis[i]);
688       for(int i = 0; i < e->numButtons; ++i)
689          printf("Button %d: Digital: %d, Analog: %g\n", i, e->digitalButton[i], e->analogButton[i]);
690    }
691    return 0;
692 }
693
694 const char *beforeunload_callback(int eventType, const void *reserved, void *userData)
695 {
696    #ifdef REPORT_RESULT
697    return ""; // For test harness, don't show a confirmation dialog to not block and keep the test runner automated.
698    #else
699    return "Do you really want to leave the page?";
700    #endif
701 }
702
703 private EM_BOOL em_battery_callback(int eventType, const EmscriptenBatteryEvent *e, void *userData)
704 {
705    char t1[64];
706    formatTime(t1, (int)e->chargingTime);
707    char t2[64];
708    formatTime(t2, (int)e->dischargingTime);
709    printf("%s: chargingTime: %s, dischargingTime: %s, level: %g%%, charging: %d\n",
710    emscripten_event_type_to_string(eventType), t1, t2, e->level*100, e->charging);
711    return 0;
712 }
713
714 private EM_BOOL em_webglcontext_callback(int eventType, const void *reserved, void *userData)
715 {
716    printf("%s.\n", emscripten_event_type_to_string(eventType));
717    return 0;
718 }
719 #endif
720
721 default:
722 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
723 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp;
724 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
725 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit;
726 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;
727 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick;
728 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown;
729 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp;
730 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick;
731 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown;
732 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp;
733 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick;
734 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown;
735 extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp;
736 private:
737
738 class EmscriptenInterface : Interface
739 {
740    class_property(name) = "Emscripten";
741
742
743    // --- User Interface System ---
744
745    bool ::Initialize()
746    {
747       sflnprintf("class(EmscriptenInterface) ::Initialize [STUB!]\n");
748       guiApp.desktop.ExternalPosition(0,0, 800, 240);
749
750 #ifdef __EMSCRIPTEN__
751
752       {
753       EMSCRIPTEN_RESULT ret;
754
755       ret = emscripten_set_keypress_callback(0, 0, 1, em_key_callback);
756       //TEST_RESULT(emscripten_set_keypress_callback);
757       ret = emscripten_set_keydown_callback(0, 0, 1, em_key_callback);
758       //TEST_RESULT(emscripten_set_keydown_callback);
759       ret = emscripten_set_keyup_callback(0, 0, 1, em_key_callback);
760       //TEST_RESULT(emscripten_set_keyup_callback);
761
762       //ret = emscripten_set_click_callback(0, 0, 1, em_mouse_callback);
763       //TEST_RESULT(emscripten_set_click_callback);
764       ret = emscripten_set_mousedown_callback(0, 0, 1, em_mouse_callback);
765       //TEST_RESULT(emscripten_set_mousedown_callback);
766       ret = emscripten_set_mouseup_callback(0, 0, 1, em_mouse_callback);
767       //TEST_RESULT(emscripten_set_mouseup_callback);
768       ret = emscripten_set_dblclick_callback(0, 0, 1, em_mouse_callback);
769       //TEST_RESULT(emscripten_set_dblclick_callback);
770       ret = emscripten_set_mousemove_callback(0, 0, 1, em_mouse_callback);
771       //TEST_RESULT(emscripten_set_mousemove_callback);
772       ret = emscripten_set_mouseenter_callback(0, 0, 1, em_mouse_callback);
773       //TEST_RESULT(emscripten_set_mouseenter_callback);
774       ret = emscripten_set_mouseleave_callback(0, 0, 1, em_mouse_callback);
775       //TEST_RESULT(emscripten_set_mouseleave_callback);
776       ret = emscripten_set_mouseover_callback(0, 0, 1, em_mouse_callback);
777       //TEST_RESULT(emscripten_set_mouseover_callback);
778       ret = emscripten_set_mouseout_callback(0, 0, 1, em_mouse_callback);
779       //TEST_RESULT(emscripten_set_mouseout_callback);
780
781       ret = emscripten_set_wheel_callback(0, 0, 1, em_wheel_callback);
782       //TEST_RESULT(emscripten_set_wheel_callback);
783
784       ret = emscripten_set_resize_callback(0, 0, 1, em_uievent_callback);
785       //TEST_RESULT(emscripten_set_resize_callback);
786       ret = emscripten_set_scroll_callback(0, 0, 1, em_uievent_callback);
787       //TEST_RESULT(emscripten_set_scroll_callback);
788
789       ret = emscripten_set_blur_callback(0, 0, 1, em_focusevent_callback);
790       //TEST_RESULT(emscripten_set_blur_callback);
791       ret = emscripten_set_focus_callback(0, 0, 1, em_focusevent_callback);
792       //TEST_RESULT(emscripten_set_focus_callback);
793       ret = emscripten_set_focusin_callback(0, 0, 1, em_focusevent_callback);
794       //TEST_RESULT(emscripten_set_focusin_callback);
795       ret = emscripten_set_focusout_callback(0, 0, 1, em_focusevent_callback);
796       //TEST_RESULT(emscripten_set_focusout_callback);
797
798       ret = emscripten_set_deviceorientation_callback(0, 1, em_deviceorientation_callback);
799       //TEST_RESULT(emscripten_set_deviceorientation_callback);
800       ret = emscripten_set_devicemotion_callback(0, 1, em_devicemotion_callback);
801       //TEST_RESULT(emscripten_set_devicemotion_callback);
802
803       ret = emscripten_set_orientationchange_callback(0, 1, em_orientationchange_callback);
804       //TEST_RESULT(emscripten_set_orientationchange_callback);
805
806 #if 0
807       // Test the polling of orientation.
808       EmscriptenOrientationChangeEvent oce;
809       ret = emscripten_get_orientation_status(&oce);
810       //TEST_RESULT(emscripten_get_orientation_status);
811       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
812       printf("The current orientation is:\n");
813       orientationchange_callback(EMSCRIPTEN_EVENT_ORIENTATIONCHANGE, &oce, 0);
814       }
815
816       int newOrientation = (oce.orientationIndex == EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY
817       || oce.orientationIndex == EMSCRIPTEN_ORIENTATION_PORTRAIT_SECONDARY) ? EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY : EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY;
818       // Test locking of orientation.
819       ret = emscripten_lock_orientation(newOrientation);
820       //TEST_RESULT(emscripten_lock_orientation);
821       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
822       printf("Locked orientation to state %d.\n", newOrientation);
823       }
824
825       ret = emscripten_get_orientation_status(&oce);
826       //TEST_RESULT(emscripten_get_orientation_status);
827       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
828       printf("The current orientation is after locking:\n");
829       orientationchange_callback(18, &oce, 0);
830       }
831
832       ret = emscripten_unlock_orientation();
833       //TEST_RESULT(emscripten_unlock_orientation);
834       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
835       printf("Unlocked orientation.\n");
836       }
837
838       EmscriptenFullscreenChangeEvent fsce;
839       ret = emscripten_get_fullscreen_status(&fsce);
840       //TEST_RESULT(emscripten_get_fullscreen_status);
841       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
842       printf("The current fullscreen status is:\n");
843       fullscreenchange_callback(EMSCRIPTEN_EVENT_FULLSCREENCHANGE, &fsce, 0);
844       }
845
846       ret = emscripten_set_fullscreenchange_callback(0, 0, 1, em_fullscreenchange_callback);
847       //TEST_RESULT(emscripten_set_fullscreenchange_callback);
848
849       // These won't do anything, since fullscreen must be requested in an event handler,
850       // but call these anyways to confirm that they don't crash in an exception in the test suite.
851       ret = emscripten_request_fullscreen(0, 1);
852       //TEST_RESULT(emscripten_request_fullscreen);
853       ret = emscripten_exit_fullscreen();
854       //TEST_RESULT(emscripten_exit_fullscreen);
855
856       EmscriptenPointerlockChangeEvent plce;
857       ret = emscripten_get_pointerlock_status(&plce);
858       //TEST_RESULT(emscripten_get_pointerlock_status);
859       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
860       printf("The current pointerlock status is:\n");
861       pointerlockchange_callback(EMSCRIPTEN_EVENT_POINTERLOCKCHANGE, &plce, 0);
862       }
863
864       ret = emscripten_set_pointerlockchange_callback(0, 0, 1, em_pointerlockchange_callback);
865       //TEST_RESULT(emscripten_set_pointerlockchange_callback);
866
867       // These won't do anything, since pointer lock must be requested in an event handler,
868       // but call these anyways to confirm that they don't crash in an exception in the test suite.
869       ret = emscripten_request_pointerlock(0, 1);
870       //TEST_RESULT(emscripten_request_pointerlock);
871       ret = emscripten_exit_pointerlock();
872       //TEST_RESULT(emscripten_exit_pointerlock);
873
874       int vibratePattern[] = {
875       150, 500,
876       300, 500,
877       450
878       };
879       ret = emscripten_vibrate_pattern(vibratePattern, sizeof(vibratePattern)/sizeof(vibratePattern[0]));
880       //TEST_RESULT(emscripten_vibrate_pattern);
881
882       EmscriptenVisibilityChangeEvent vce;
883       ret = emscripten_get_visibility_status(&vce);
884       //TEST_RESULT(emscripten_get_visibility_status);
885       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
886       printf("Current visibility status:\n");
887       visibilitychange_callback(EMSCRIPTEN_EVENT_VISIBILITYCHANGE, &vce, 0);
888       }
889
890       ret = emscripten_set_visibilitychange_callback(0, 1, visibilitychange_callback);
891       //TEST_RESULT(emscripten_set_visibilitychange_callback);
892
893       ret = emscripten_set_touchstart_callback(0, 0, 1, em_touch_callback);
894       //TEST_RESULT(emscripten_set_touchstart_callback);
895       ret = emscripten_set_touchend_callback(0, 0, 1, em_touch_callback);
896       //TEST_RESULT(emscripten_set_touchend_callback);
897       ret = emscripten_set_touchmove_callback(0, 0, 1, em_touch_callback);
898       //TEST_RESULT(emscripten_set_touchmove_callback);
899       ret = emscripten_set_touchcancel_callback(0, 0, 1, em_touch_callback);
900       //TEST_RESULT(emscripten_set_touchcancel_callback);
901
902       ret = emscripten_set_gamepadconnected_callback(0, 1, gamepad_callback);
903       //TEST_RESULT(emscripten_set_gamepadconnected_callback);
904       ret = emscripten_set_gamepaddisconnected_callback(0, 1, gamepad_callback);
905       //TEST_RESULT(emscripten_set_gamepaddisconnected_callback);
906
907       emscripten_set_main_loop(mainloop, 10, 0);
908
909       ret = emscripten_set_beforeunload_callback(0, beforeunload_callback);
910       //TEST_RESULT(emscripten_set_beforeunload_callback);
911
912       ret = emscripten_set_batterychargingchange_callback(0, battery_callback);
913       //TEST_RESULT(emscripten_set_batterychargingchange_callback);
914       ret = emscripten_set_batterylevelchange_callback(0, battery_callback);
915       //TEST_RESULT(emscripten_set_batterylevelchange_callback);
916
917       EmscriptenBatteryEvent bs;
918       ret = emscripten_get_battery_status(&bs);
919       //TEST_RESULT(emscripten_get_battery_status);
920       if (ret == EMSCRIPTEN_RESULT_SUCCESS) {
921       printf("Current battery status:\n");
922       battery_callback(EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE, &bs, 0);
923       }
924
925       ret = emscripten_set_webglcontextlost_callback(0, 0, 1, em_webglcontext_callback);
926       //TEST_RESULT(emscripten_set_webglcontextlost_callback);
927       ret = emscripten_set_webglcontextrestored_callback(0, 0, 1, em_webglcontext_callback);
928       //TEST_RESULT(emscripten_set_webglcontextrestored_callback);
929 #endif
930       }
931 #endif
932
933       return true;
934    }
935
936    void ::Terminate()
937    {
938       sflnprintf("class(EmscriptenInterface) ::Terminate [STUB!]\n");
939    }
940
941    bool ::ProcessInput(bool processAll)
942    {
943       //sflnprintf("class(EmscriptenInterface) ::ProcessInput [STUB!]\n");
944       return false;
945    }
946
947    void ::Wait()
948    {
949       sflnprintf("class(EmscriptenInterface) ::Wait [STUB!]\n");
950    }
951
952    void ::Lock(Window window)
953    {
954       sflnprintf("class(EmscriptenInterface) ::Lock [STUB!]\n");
955    }
956
957    void ::Unlock(Window window)
958    {
959       sflnprintf("class(EmscriptenInterface) ::Unlock [STUB!]\n");
960    }
961
962    void ::SetTimerResolution(uint hertz)
963    {
964       sflnprintf("class(EmscriptenInterface) ::SetTimerResolution [STUB!] Implement high resolution timer here\n");
965    }
966
967    const char ** ::GraphicsDrivers(int * numDrivers)
968    {
969       //sflnprintf("class(EmscriptenInterface) ::GraphicsDrivers [STUB!]\n");
970       static const char *graphicsDrivers[] = { "OpenGL" };
971       *numDrivers = sizeof(graphicsDrivers) / sizeof(char *);
972       return (const char **)graphicsDrivers;
973       return null;
974    }
975
976    void ::EnsureFullScreen(bool * fullScreen)
977    {
978       sflnprintf("class(EmscriptenInterface) ::EnsureFullScreen [STUB!]\n");
979       *fullScreen = true;
980    }
981
982    void ::GetCurrentMode(bool * fullScreen, Resolution * resolution, PixelFormat * colorDepth, int * refreshRate)
983    {
984       sflnprintf("class(EmscriptenInterface) ::GetCurrentMode [STUB!]\n");
985    }
986
987    bool ::ScreenMode(bool fullScreen, Resolution resolution, PixelFormat colorDepth, int refreshRate, bool * textMode)
988    {
989       sflnprintf("class(EmscriptenInterface) ::ScreenMode [STUB!]\n");
990       return true;
991    }
992
993
994    // --- Window Creation ---
995
996    void * ::CreateRootWindow(Window window)
997    {
998       sflnprintf("class(EmscriptenInterface) ::CreateRootWindow [STUB!]\n");
999       return null;
1000    }
1001
1002    void ::DestroyRootWindow(Window window)
1003    {
1004       sflnprintf("class(EmscriptenInterface) ::DestroyRootWindow [STUB!]\n");
1005    }
1006
1007
1008    // --- Window manipulation ---
1009
1010    void ::SetRootWindowCaption(Window window, const char * name)
1011    {
1012       sflnprintf("class(EmscriptenInterface) ::SetRootWindowCaption [STUB!]\n");
1013    }
1014
1015    void ::PositionRootWindow(Window window, int x, int y, int w, int h, bool move, bool resize)
1016    {
1017       sflnprintf("class(EmscriptenInterface) ::Stub [STUB!]\n");
1018    }
1019
1020    void ::OffsetWindow(Window window, int * x, int * y)
1021    {
1022       //sflnprintf("class(EmscriptenInterface) ::OffsetWindow [STUB!]\n");
1023    }
1024
1025    void ::UpdateRootWindow(Window window)
1026    {
1027       sflnprintf("class(EmscriptenInterface) ::UpdateRootWindow [STUB!]\n");
1028    }
1029
1030    void ::SetRootWindowState(Window window, WindowState state, bool visible)
1031    {
1032       sflnprintf("class(EmscriptenInterface) ::SetRootWindowState [STUB!]\n");
1033    }
1034
1035    void ::ActivateRootWindow(Window window)
1036    {
1037       sflnprintf("class(EmscriptenInterface) ::ActivateRootWindow [STUB!]\n");
1038    }
1039
1040    void ::OrderRootWindow(Window window, bool topMost)
1041    {
1042       sflnprintf("class(EmscriptenInterface) ::OrderRootWindow [STUB!]\n");
1043    }
1044
1045    void ::SetRootWindowColor(Window window)
1046    {
1047       sflnprintf("class(EmscriptenInterface) ::SetRootWindowColor [STUB!]\n");
1048    }
1049
1050    void ::FlashRootWindow(Window window)
1051    {
1052       sflnprintf("class(EmscriptenInterface) ::FlashRootWindow [STUB!]\n");
1053    }
1054
1055
1056    // --- Mouse-based window movement ---
1057
1058    void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
1059    {
1060       // sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
1061    }
1062
1063    void ::StopMoving(Window window)
1064    {
1065       // sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
1066    }
1067
1068
1069    // --- Mouse manipulation ---
1070
1071    void ::GetMousePosition(int *x, int *y)
1072    {
1073       *x = canvasX;
1074       *y = canvasY;
1075    }
1076
1077    void ::SetMousePosition(int x, int y)
1078    {
1079       // sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
1080    }
1081
1082    void ::SetMouseRange(Window window, Box box)
1083    {
1084       // sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
1085    }
1086
1087    void ::SetMouseCapture(Window window)
1088    {
1089       // sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
1090    }
1091
1092
1093    // --- Mouse cursor ---
1094
1095    void ::SetMouseCursor(Window window, SystemCursor cursor)
1096    {
1097       // sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
1098    }
1099
1100
1101    // --- Caret manipulation ---
1102
1103    void ::SetCaret(int caretX, int caretY, int size)
1104    {
1105       sflnprintf("class(EmscriptenInterface) ::SetCaret [STUB!]\n");
1106    }
1107
1108
1109    // --- Clipboard manipulation ---
1110
1111    void ::ClearClipboard()
1112    {
1113       sflnprintf("class(EmscriptenInterface) ::ClearClipboard [STUB!]\n");
1114    }
1115
1116    bool ::AllocateClipboard(ClipBoard clipBoard, uint size)
1117    {
1118       sflnprintf("class(EmscriptenInterface) ::AllocateClipboard [STUB!]\n");
1119       return false;
1120    }
1121
1122    bool ::SaveClipboard(ClipBoard clipBoard)
1123    {
1124       sflnprintf("class(EmscriptenInterface) ::SaveClipboard [STUB!]\n");
1125       return false;
1126    }
1127
1128    bool ::LoadClipboard(ClipBoard clipBoard)
1129    {
1130       sflnprintf("class(EmscriptenInterface) ::LoadClipboard [STUB!]\n");
1131       return false;
1132    }
1133
1134    void ::UnloadClipboard(ClipBoard clipBoard)
1135    {
1136       sflnprintf("class(EmscriptenInterface) ::UnloadClipboard [STUB!]\n");
1137    }
1138
1139
1140    // --- State based input ---
1141
1142    bool ::AcquireInput(Window window, bool state)
1143    {
1144       sflnprintf("class(EmscriptenInterface) ::AcquireInput [STUB!]\n");
1145       return false;
1146    }
1147
1148    bool ::GetMouseState(MouseButtons * buttons, int * x, int * y)
1149    {
1150       sflnprintf("class(EmscriptenInterface) ::GetMouseState [STUB!]\n");
1151       return false;
1152    }
1153
1154    bool ::GetJoystickState(int device, Joystick joystick)
1155    {
1156       sflnprintf("class(EmscriptenInterface) ::GetJoystickState [STUB!]\n");
1157       return false;
1158    }
1159
1160    bool ::GetKeyState(Key key)
1161    {
1162       sflnprintf("class(EmscriptenInterface) ::GetKeyState [STUB!]\n");
1163       return false;
1164    }
1165
1166    bool ::SetIcon(Window window, BitmapResource icon)
1167    {
1168       sflnprintf("class(EmscriptenInterface) ::SetIcon [STUB!]\n");
1169       return false;
1170    }
1171
1172    void ::GetScreenArea(Window window, Box box)
1173    {
1174       sflnprintf("class(EmscriptenInterface) ::GetScreenArea [STUB!]\n");
1175    }
1176 }
1177 #endif