1 /* 2 * Copyright 2014 The Emscripten Authors. All rights reserved. 3 * Emscripten is available under two separate licenses, the MIT license and the 4 * University of Illinois/NCSA Open Source License. Both these licenses can be 5 * found in the LICENSE file. 6 */ 7 8 #pragma once 9 10 #ifdef __cplusplus 11 #if !defined(__DEFINED_pthread_t) 12 typedef unsigned long pthread_t; 13 #define __DEFINED_pthread_t 14 #endif 15 #else 16 #if !defined(__DEFINED_pthread_t) 17 typedef struct __pthread * pthread_t; 18 #define __DEFINED_pthread_t 19 #endif 20 #endif 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /* This file defines Emscripten low-level glue bindings for interfacing with HTML5 APIs 27 * 28 * Documentation for the public APIs defined in this file must be updated in: 29 * site/source/docs/api_reference/html5.h.rst 30 * A prebuilt local version of the documentation is available at: 31 * site/build/text/docs/api_reference/html5.h.txt 32 * You can also build docs locally as HTML or other formats in site/ 33 * An online HTML version (which may be of a different version of Emscripten) 34 * is up at http://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html 35 */ 36 37 #define EMSCRIPTEN_EVENT_KEYPRESS 1 38 #define EMSCRIPTEN_EVENT_KEYDOWN 2 39 #define EMSCRIPTEN_EVENT_KEYUP 3 40 #define EMSCRIPTEN_EVENT_CLICK 4 41 #define EMSCRIPTEN_EVENT_MOUSEDOWN 5 42 #define EMSCRIPTEN_EVENT_MOUSEUP 6 43 #define EMSCRIPTEN_EVENT_DBLCLICK 7 44 #define EMSCRIPTEN_EVENT_MOUSEMOVE 8 45 #define EMSCRIPTEN_EVENT_WHEEL 9 46 #define EMSCRIPTEN_EVENT_RESIZE 10 47 #define EMSCRIPTEN_EVENT_SCROLL 11 48 #define EMSCRIPTEN_EVENT_BLUR 12 49 #define EMSCRIPTEN_EVENT_FOCUS 13 50 #define EMSCRIPTEN_EVENT_FOCUSIN 14 51 #define EMSCRIPTEN_EVENT_FOCUSOUT 15 52 #define EMSCRIPTEN_EVENT_DEVICEORIENTATION 16 53 #define EMSCRIPTEN_EVENT_DEVICEMOTION 17 54 #define EMSCRIPTEN_EVENT_ORIENTATIONCHANGE 18 55 #define EMSCRIPTEN_EVENT_FULLSCREENCHANGE 19 56 #define EMSCRIPTEN_EVENT_POINTERLOCKCHANGE 20 57 #define EMSCRIPTEN_EVENT_VISIBILITYCHANGE 21 58 #define EMSCRIPTEN_EVENT_TOUCHSTART 22 59 #define EMSCRIPTEN_EVENT_TOUCHEND 23 60 #define EMSCRIPTEN_EVENT_TOUCHMOVE 24 61 #define EMSCRIPTEN_EVENT_TOUCHCANCEL 25 62 #define EMSCRIPTEN_EVENT_GAMEPADCONNECTED 26 63 #define EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED 27 64 #define EMSCRIPTEN_EVENT_BEFOREUNLOAD 28 65 #define EMSCRIPTEN_EVENT_BATTERYCHARGINGCHANGE 29 66 #define EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE 30 67 #define EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST 31 68 #define EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED 32 69 #define EMSCRIPTEN_EVENT_MOUSEENTER 33 70 #define EMSCRIPTEN_EVENT_MOUSELEAVE 34 71 #define EMSCRIPTEN_EVENT_MOUSEOVER 35 72 #define EMSCRIPTEN_EVENT_MOUSEOUT 36 73 #define EMSCRIPTEN_EVENT_CANVASRESIZED 37 74 #define EMSCRIPTEN_EVENT_POINTERLOCKERROR 38 75 76 #define EMSCRIPTEN_RESULT int 77 78 #define EMSCRIPTEN_RESULT_SUCCESS 0 79 #define EMSCRIPTEN_RESULT_DEFERRED 1 80 #define EMSCRIPTEN_RESULT_NOT_SUPPORTED -1 81 #define EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED -2 82 #define EMSCRIPTEN_RESULT_INVALID_TARGET -3 83 #define EMSCRIPTEN_RESULT_UNKNOWN_TARGET -4 84 #define EMSCRIPTEN_RESULT_INVALID_PARAM -5 85 #define EMSCRIPTEN_RESULT_FAILED -6 86 #define EMSCRIPTEN_RESULT_NO_DATA -7 87 #define EMSCRIPTEN_RESULT_TIMED_OUT -8 88 89 #define EMSCRIPTEN_EVENT_TARGET_INVALID 0 90 #define EMSCRIPTEN_EVENT_TARGET_DOCUMENT ((const char*)1) 91 #define EMSCRIPTEN_EVENT_TARGET_WINDOW ((const char*)2) 92 #define EMSCRIPTEN_EVENT_TARGET_SCREEN ((const char*)3) 93 94 #define EM_BOOL int 95 #define EM_TRUE 1 96 #define EM_FALSE 0 97 #define EM_UTF8 char 98 99 #define DOM_KEY_LOCATION int 100 #define DOM_KEY_LOCATION_STANDARD 0x00 101 #define DOM_KEY_LOCATION_LEFT 0x01 102 #define DOM_KEY_LOCATION_RIGHT 0x02 103 #define DOM_KEY_LOCATION_NUMPAD 0x03 104 105 #define EM_HTML5_SHORT_STRING_LEN_BYTES 32 106 #define EM_HTML5_MEDIUM_STRING_LEN_BYTES 64 107 #define EM_HTML5_LONG_STRING_LEN_BYTES 128 108 109 typedef struct EmscriptenKeyboardEvent { 110 unsigned long location; 111 EM_BOOL ctrlKey; 112 EM_BOOL shiftKey; 113 EM_BOOL altKey; 114 EM_BOOL metaKey; 115 EM_BOOL repeat; 116 unsigned long charCode; 117 unsigned long keyCode; 118 unsigned long which; 119 EM_UTF8 key[EM_HTML5_SHORT_STRING_LEN_BYTES]; 120 EM_UTF8 code[EM_HTML5_SHORT_STRING_LEN_BYTES]; 121 EM_UTF8 charValue[EM_HTML5_SHORT_STRING_LEN_BYTES]; 122 EM_UTF8 locale[EM_HTML5_SHORT_STRING_LEN_BYTES]; 123 } EmscriptenKeyboardEvent; 124 125 126 typedef EM_BOOL (*em_key_callback_func)(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData); 127 extern EMSCRIPTEN_RESULT emscripten_set_keypress_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_key_callback_func callback, pthread_t targetThread); 128 extern EMSCRIPTEN_RESULT emscripten_set_keydown_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_key_callback_func callback, pthread_t targetThread); 129 extern EMSCRIPTEN_RESULT emscripten_set_keyup_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_key_callback_func callback, pthread_t targetThread); 130 131 typedef struct EmscriptenMouseEvent { 132 long screenX; 133 long screenY; 134 long clientX; 135 long clientY; 136 EM_BOOL ctrlKey; 137 EM_BOOL shiftKey; 138 EM_BOOL altKey; 139 EM_BOOL metaKey; 140 unsigned short button; 141 unsigned short buttons; 142 long movementX; 143 long movementY; 144 long targetX; 145 long targetY; 146 // canvasX and canvasY are deprecated - there no longer exists a Module['canvas'] object, so canvasX/Y are no longer reported (register a listener on canvas directly to get canvas coordinates, or translate manually) 147 long canvasX; 148 long canvasY; 149 long padding; 150 } EmscriptenMouseEvent; 151 152 153 typedef EM_BOOL (*em_mouse_callback_func)(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); 154 extern EMSCRIPTEN_RESULT emscripten_set_click_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 155 extern EMSCRIPTEN_RESULT emscripten_set_mousedown_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 156 extern EMSCRIPTEN_RESULT emscripten_set_mouseup_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 157 extern EMSCRIPTEN_RESULT emscripten_set_dblclick_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 158 extern EMSCRIPTEN_RESULT emscripten_set_mousemove_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 159 extern EMSCRIPTEN_RESULT emscripten_set_mouseenter_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 160 extern EMSCRIPTEN_RESULT emscripten_set_mouseleave_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 161 extern EMSCRIPTEN_RESULT emscripten_set_mouseover_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 162 extern EMSCRIPTEN_RESULT emscripten_set_mouseout_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_mouse_callback_func callback, pthread_t targetThread); 163 164 extern EMSCRIPTEN_RESULT emscripten_get_mouse_status(EmscriptenMouseEvent *mouseState); 165 166 #define DOM_DELTA_PIXEL 0x00 167 #define DOM_DELTA_LINE 0x01 168 #define DOM_DELTA_PAGE 0x02 169 170 typedef struct EmscriptenWheelEvent { 171 EmscriptenMouseEvent mouse; 172 double deltaX; 173 double deltaY; 174 double deltaZ; 175 unsigned long deltaMode; 176 } EmscriptenWheelEvent; 177 178 179 typedef EM_BOOL (*em_wheel_callback_func)(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData); 180 extern EMSCRIPTEN_RESULT emscripten_set_wheel_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_wheel_callback_func callback, pthread_t targetThread); 181 182 typedef struct EmscriptenUiEvent { 183 long detail; 184 int documentBodyClientWidth; 185 int documentBodyClientHeight; 186 int windowInnerWidth; 187 int windowInnerHeight; 188 int windowOuterWidth; 189 int windowOuterHeight; 190 int scrollTop; 191 int scrollLeft; 192 } EmscriptenUiEvent; 193 194 195 typedef EM_BOOL (*em_ui_callback_func)(int eventType, const EmscriptenUiEvent *uiEvent, void *userData); 196 extern EMSCRIPTEN_RESULT emscripten_set_resize_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_ui_callback_func callback, pthread_t targetThread); 197 extern EMSCRIPTEN_RESULT emscripten_set_scroll_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_ui_callback_func callback, pthread_t targetThread); 198 199 typedef struct EmscriptenFocusEvent { 200 EM_UTF8 nodeName[EM_HTML5_LONG_STRING_LEN_BYTES]; 201 EM_UTF8 id[EM_HTML5_LONG_STRING_LEN_BYTES]; 202 } EmscriptenFocusEvent; 203 204 typedef EM_BOOL (*em_focus_callback_func)(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData); 205 extern EMSCRIPTEN_RESULT emscripten_set_blur_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_focus_callback_func callback, pthread_t targetThread); 206 extern EMSCRIPTEN_RESULT emscripten_set_focus_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_focus_callback_func callback, pthread_t targetThread); 207 extern EMSCRIPTEN_RESULT emscripten_set_focusin_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_focus_callback_func callback, pthread_t targetThread); 208 extern EMSCRIPTEN_RESULT emscripten_set_focusout_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_focus_callback_func callback, pthread_t targetThread); 209 210 typedef struct EmscriptenDeviceOrientationEvent { 211 double alpha; 212 double beta; 213 double gamma; 214 EM_BOOL absolute; 215 } EmscriptenDeviceOrientationEvent; 216 217 218 typedef EM_BOOL (*em_deviceorientation_callback_func)(int eventType, const EmscriptenDeviceOrientationEvent *deviceOrientationEvent, void *userData); 219 extern EMSCRIPTEN_RESULT emscripten_set_deviceorientation_callback_on_thread(void *userData, EM_BOOL useCapture, em_deviceorientation_callback_func callback, pthread_t targetThread); 220 221 extern EMSCRIPTEN_RESULT emscripten_get_deviceorientation_status(EmscriptenDeviceOrientationEvent *orientationState); 222 223 #define EMSCRIPTEN_DEVICE_MOTION_EVENT_SUPPORTS_ACCELERATION 0x01 224 #define EMSCRIPTEN_DEVICE_MOTION_EVENT_SUPPORTS_ACCELERATION_INCLUDING_GRAVITY 0x02 225 #define EMSCRIPTEN_DEVICE_MOTION_EVENT_SUPPORTS_ROTATION_RATE 0x04 226 227 typedef struct EmscriptenDeviceMotionEvent { 228 double accelerationX; 229 double accelerationY; 230 double accelerationZ; 231 double accelerationIncludingGravityX; 232 double accelerationIncludingGravityY; 233 double accelerationIncludingGravityZ; 234 double rotationRateAlpha; 235 double rotationRateBeta; 236 double rotationRateGamma; 237 int supportedFields; 238 } EmscriptenDeviceMotionEvent; 239 240 241 typedef EM_BOOL (*em_devicemotion_callback_func)(int eventType, const EmscriptenDeviceMotionEvent *deviceMotionEvent, void *userData); 242 extern EMSCRIPTEN_RESULT emscripten_set_devicemotion_callback_on_thread(void *userData, EM_BOOL useCapture, em_devicemotion_callback_func callback, pthread_t targetThread); 243 244 extern EMSCRIPTEN_RESULT emscripten_get_devicemotion_status(EmscriptenDeviceMotionEvent *motionState); 245 246 #define EMSCRIPTEN_ORIENTATION_PORTRAIT_PRIMARY 1 247 #define EMSCRIPTEN_ORIENTATION_PORTRAIT_SECONDARY 2 248 #define EMSCRIPTEN_ORIENTATION_LANDSCAPE_PRIMARY 4 249 #define EMSCRIPTEN_ORIENTATION_LANDSCAPE_SECONDARY 8 250 251 typedef struct EmscriptenOrientationChangeEvent { 252 int orientationIndex; 253 int orientationAngle; 254 } EmscriptenOrientationChangeEvent; 255 256 257 typedef EM_BOOL (*em_orientationchange_callback_func)(int eventType, const EmscriptenOrientationChangeEvent *orientationChangeEvent, void *userData); 258 extern EMSCRIPTEN_RESULT emscripten_set_orientationchange_callback_on_thread(void *userData, EM_BOOL useCapture, em_orientationchange_callback_func callback, pthread_t targetThread); 259 260 extern EMSCRIPTEN_RESULT emscripten_get_orientation_status(EmscriptenOrientationChangeEvent *orientationStatus); 261 extern EMSCRIPTEN_RESULT emscripten_lock_orientation(int allowedOrientations); 262 extern EMSCRIPTEN_RESULT emscripten_unlock_orientation(void); 263 264 typedef struct EmscriptenFullscreenChangeEvent { 265 EM_BOOL isFullscreen; 266 EM_BOOL fullscreenEnabled; 267 EM_UTF8 nodeName[EM_HTML5_LONG_STRING_LEN_BYTES]; 268 EM_UTF8 id[EM_HTML5_LONG_STRING_LEN_BYTES]; 269 int elementWidth; 270 int elementHeight; 271 int screenWidth; 272 int screenHeight; 273 } EmscriptenFullscreenChangeEvent; 274 275 276 typedef EM_BOOL (*em_fullscreenchange_callback_func)(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData); 277 extern EMSCRIPTEN_RESULT emscripten_set_fullscreenchange_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_fullscreenchange_callback_func callback, pthread_t targetThread); 278 279 extern EMSCRIPTEN_RESULT emscripten_get_fullscreen_status(EmscriptenFullscreenChangeEvent *fullscreenStatus); 280 281 #define EMSCRIPTEN_FULLSCREEN_SCALE int 282 #define EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT 0 283 #define EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH 1 284 #define EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT 2 285 #define EMSCRIPTEN_FULLSCREEN_SCALE_CENTER 3 286 287 #define EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE int 288 #define EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE 0 289 #define EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF 1 290 #define EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF 2 291 292 #define EMSCRIPTEN_FULLSCREEN_FILTERING int 293 #define EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT 0 294 #define EMSCRIPTEN_FULLSCREEN_FILTERING_NEAREST 1 295 #define EMSCRIPTEN_FULLSCREEN_FILTERING_BILINEAR 2 296 297 typedef EM_BOOL (*em_canvasresized_callback_func)(int eventType, const void *reserved, void *userData); 298 299 typedef struct EmscriptenFullscreenStrategy { 300 EMSCRIPTEN_FULLSCREEN_SCALE scaleMode; 301 EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE canvasResolutionScaleMode; 302 EMSCRIPTEN_FULLSCREEN_FILTERING filteringMode; 303 em_canvasresized_callback_func canvasResizedCallback; 304 void *canvasResizedCallbackUserData; 305 pthread_t canvasResizedCallbackTargetThread; 306 } EmscriptenFullscreenStrategy; 307 308 extern EMSCRIPTEN_RESULT emscripten_request_fullscreen(const char *target, EM_BOOL deferUntilInEventHandler); 309 extern EMSCRIPTEN_RESULT emscripten_request_fullscreen_strategy(const char *target, EM_BOOL deferUntilInEventHandler, const EmscriptenFullscreenStrategy *fullscreenStrategy); 310 311 extern EMSCRIPTEN_RESULT emscripten_exit_fullscreen(void); 312 313 extern EMSCRIPTEN_RESULT emscripten_enter_soft_fullscreen(const char *target, const EmscriptenFullscreenStrategy *fullscreenStrategy); 314 315 extern EMSCRIPTEN_RESULT emscripten_exit_soft_fullscreen(void); 316 317 typedef struct EmscriptenPointerlockChangeEvent { 318 EM_BOOL isActive; 319 EM_UTF8 nodeName[EM_HTML5_LONG_STRING_LEN_BYTES]; 320 EM_UTF8 id[EM_HTML5_LONG_STRING_LEN_BYTES]; 321 } EmscriptenPointerlockChangeEvent; 322 323 324 typedef EM_BOOL (*em_pointerlockchange_callback_func)(int eventType, const EmscriptenPointerlockChangeEvent *pointerlockChangeEvent, void *userData); 325 extern EMSCRIPTEN_RESULT emscripten_set_pointerlockchange_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_pointerlockchange_callback_func callback, pthread_t targetThread); 326 327 typedef EM_BOOL (*em_pointerlockerror_callback_func)(int eventType, const void *reserved, void *userData); 328 extern EMSCRIPTEN_RESULT emscripten_set_pointerlockerror_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_pointerlockerror_callback_func callback, pthread_t targetThread); 329 330 extern EMSCRIPTEN_RESULT emscripten_get_pointerlock_status(EmscriptenPointerlockChangeEvent *pointerlockStatus); 331 332 extern EMSCRIPTEN_RESULT emscripten_request_pointerlock(const char *target, EM_BOOL deferUntilInEventHandler); 333 334 extern EMSCRIPTEN_RESULT emscripten_exit_pointerlock(void); 335 336 #define EMSCRIPTEN_VISIBILITY_HIDDEN 0 337 #define EMSCRIPTEN_VISIBILITY_VISIBLE 1 338 #define EMSCRIPTEN_VISIBILITY_PRERENDER 2 339 #define EMSCRIPTEN_VISIBILITY_UNLOADED 3 340 341 typedef struct EmscriptenVisibilityChangeEvent { 342 EM_BOOL hidden; 343 int visibilityState; 344 } EmscriptenVisibilityChangeEvent; 345 346 typedef EM_BOOL (*em_visibilitychange_callback_func)(int eventType, const EmscriptenVisibilityChangeEvent *visibilityChangeEvent, void *userData); 347 extern EMSCRIPTEN_RESULT emscripten_set_visibilitychange_callback_on_thread(void *userData, EM_BOOL useCapture, em_visibilitychange_callback_func callback, pthread_t targetThread); 348 349 extern EMSCRIPTEN_RESULT emscripten_get_visibility_status(EmscriptenVisibilityChangeEvent *visibilityStatus); 350 351 352 typedef struct EmscriptenTouchPoint 353 { 354 long identifier; 355 long screenX; 356 long screenY; 357 long clientX; 358 long clientY; 359 long pageX; 360 long pageY; 361 EM_BOOL isChanged; 362 EM_BOOL onTarget; 363 long targetX; 364 long targetY; 365 // canvasX and canvasY are deprecated - there no longer exists a Module['canvas'] object, so canvasX/Y are no longer reported (register a listener on canvas directly to get canvas coordinates, or translate manually) 366 long canvasX; 367 long canvasY; 368 } EmscriptenTouchPoint; 369 370 typedef struct EmscriptenTouchEvent { 371 int numTouches; 372 EM_BOOL ctrlKey; 373 EM_BOOL shiftKey; 374 EM_BOOL altKey; 375 EM_BOOL metaKey; 376 EmscriptenTouchPoint touches[32]; 377 } EmscriptenTouchEvent; 378 379 380 typedef EM_BOOL (*em_touch_callback_func)(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData); 381 extern EMSCRIPTEN_RESULT emscripten_set_touchstart_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_touch_callback_func callback, pthread_t targetThread); 382 extern EMSCRIPTEN_RESULT emscripten_set_touchend_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_touch_callback_func callback, pthread_t targetThread); 383 extern EMSCRIPTEN_RESULT emscripten_set_touchmove_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_touch_callback_func callback, pthread_t targetThread); 384 extern EMSCRIPTEN_RESULT emscripten_set_touchcancel_callback_on_thread(const char *target, void *userData, EM_BOOL useCapture, em_touch_callback_func callback, pthread_t targetThread); 385 386 387 typedef struct EmscriptenGamepadEvent { 388 double timestamp; 389 int numAxes; 390 int numButtons; 391 double axis[64]; 392 double analogButton[64]; 393 EM_BOOL digitalButton[64]; 394 EM_BOOL connected; 395 long index; 396 EM_UTF8 id[EM_HTML5_MEDIUM_STRING_LEN_BYTES]; 397 EM_UTF8 mapping[EM_HTML5_MEDIUM_STRING_LEN_BYTES]; 398 } EmscriptenGamepadEvent; 399 400 401 typedef EM_BOOL (*em_gamepad_callback_func)(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData); 402 extern EMSCRIPTEN_RESULT emscripten_set_gamepadconnected_callback_on_thread(void *userData, EM_BOOL useCapture, em_gamepad_callback_func callback, pthread_t targetThread); 403 extern EMSCRIPTEN_RESULT emscripten_set_gamepaddisconnected_callback_on_thread(void *userData, EM_BOOL useCapture, em_gamepad_callback_func callback, pthread_t targetThread); 404 405 extern EMSCRIPTEN_RESULT emscripten_sample_gamepad_data(void); 406 extern int emscripten_get_num_gamepads(void); 407 extern EMSCRIPTEN_RESULT emscripten_get_gamepad_status(int index, EmscriptenGamepadEvent *gamepadState); 408 409 typedef struct EmscriptenBatteryEvent { 410 double chargingTime; 411 double dischargingTime; 412 double level; 413 EM_BOOL charging; 414 } EmscriptenBatteryEvent; 415 416 typedef EM_BOOL (*em_battery_callback_func)(int eventType, const EmscriptenBatteryEvent *batteryEvent, void *userData); 417 extern EMSCRIPTEN_RESULT emscripten_set_batterychargingchange_callback_on_thread(void *userData, em_battery_callback_func callback, pthread_t targetThread); 418 extern EMSCRIPTEN_RESULT emscripten_set_batterylevelchange_callback_on_thread(void *userData, em_battery_callback_func callback, pthread_t targetThread); 419 420 extern EMSCRIPTEN_RESULT emscripten_get_battery_status(EmscriptenBatteryEvent *batteryState); 421 422 423 extern EMSCRIPTEN_RESULT emscripten_vibrate(int msecs); 424 extern EMSCRIPTEN_RESULT emscripten_vibrate_pattern(int *msecsArray, int numEntries); 425 426 typedef const char *(*em_beforeunload_callback)(int eventType, const void *reserved, void *userData); 427 extern EMSCRIPTEN_RESULT emscripten_set_beforeunload_callback_on_thread(void *userData, em_beforeunload_callback callback, pthread_t targetThread); 428 429 // Sets the canvas.width & canvas.height properties. 430 extern EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height); 431 432 // Returns the canvas.width & canvas.height properties. 433 extern EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height); 434 435 extern EMSCRIPTEN_RESULT emscripten_set_element_css_size(const char *target, double width, double height); 436 extern EMSCRIPTEN_RESULT emscripten_get_element_css_size(const char *target, double *width, double *height); 437 438 extern void emscripten_html5_remove_all_event_listeners(void); 439 440 #define EM_CALLBACK_THREAD_CONTEXT_MAIN_BROWSER_THREAD ((pthread_t)0x1) 441 #define EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD ((pthread_t)0x2) 442 443 #define emscripten_set_keypress_callback(target, userData, useCapture, callback) emscripten_set_keypress_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 444 #define emscripten_set_keydown_callback(target, userData, useCapture, callback) emscripten_set_keydown_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 445 #define emscripten_set_keyup_callback(target, userData, useCapture, callback) emscripten_set_keyup_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 446 #define emscripten_set_click_callback(target, userData, useCapture, callback) emscripten_set_click_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 447 #define emscripten_set_mousedown_callback(target, userData, useCapture, callback) emscripten_set_mousedown_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 448 #define emscripten_set_mouseup_callback(target, userData, useCapture, callback) emscripten_set_mouseup_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 449 #define emscripten_set_dblclick_callback(target, userData, useCapture, callback) emscripten_set_dblclick_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 450 #define emscripten_set_mousemove_callback(target, userData, useCapture, callback) emscripten_set_mousemove_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 451 #define emscripten_set_mouseenter_callback(target, userData, useCapture, callback) emscripten_set_mouseenter_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 452 #define emscripten_set_mouseleave_callback(target, userData, useCapture, callback) emscripten_set_mouseleave_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 453 #define emscripten_set_mouseover_callback(target, userData, useCapture, callback) emscripten_set_mouseover_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 454 #define emscripten_set_mouseout_callback(target, userData, useCapture, callback) emscripten_set_mouseout_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 455 #define emscripten_set_wheel_callback(target, userData, useCapture, callback) emscripten_set_wheel_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 456 #define emscripten_set_resize_callback(target, userData, useCapture, callback) emscripten_set_resize_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 457 #define emscripten_set_scroll_callback(target, userData, useCapture, callback) emscripten_set_scroll_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 458 #define emscripten_set_blur_callback(target, userData, useCapture, callback) emscripten_set_blur_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 459 #define emscripten_set_focus_callback(target, userData, useCapture, callback) emscripten_set_focus_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 460 #define emscripten_set_focusin_callback(target, userData, useCapture, callback) emscripten_set_focusin_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 461 #define emscripten_set_focusout_callback(target, userData, useCapture, callback) emscripten_set_focusout_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 462 #define emscripten_set_deviceorientation_callback(userData, useCapture, callback) emscripten_set_deviceorientation_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 463 #define emscripten_set_devicemotion_callback(userData, useCapture, callback) emscripten_set_devicemotion_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 464 #define emscripten_set_orientationchange_callback(userData, useCapture, callback) emscripten_set_orientationchange_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 465 #define emscripten_set_fullscreenchange_callback(target, userData, useCapture, callback) emscripten_set_fullscreenchange_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 466 #define emscripten_set_pointerlockchange_callback(target, userData, useCapture, callback) emscripten_set_pointerlockchange_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 467 #define emscripten_set_pointerlockerror_callback(target, userData, useCapture, callback) emscripten_set_pointerlockerror_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 468 #define emscripten_set_visibilitychange_callback(userData, useCapture, callback) emscripten_set_visibilitychange_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 469 #define emscripten_set_touchstart_callback(target, userData, useCapture, callback) emscripten_set_touchstart_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 470 #define emscripten_set_touchend_callback(target, userData, useCapture, callback) emscripten_set_touchend_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 471 #define emscripten_set_touchmove_callback(target, userData, useCapture, callback) emscripten_set_touchmove_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 472 #define emscripten_set_touchcancel_callback(target, userData, useCapture, callback) emscripten_set_touchcancel_callback_on_thread( (target), (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 473 #define emscripten_set_gamepadconnected_callback(userData, useCapture, callback) emscripten_set_gamepadconnected_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 474 #define emscripten_set_gamepaddisconnected_callback(userData, useCapture, callback) emscripten_set_gamepaddisconnected_callback_on_thread( (userData), (useCapture), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 475 #define emscripten_set_batterychargingchange_callback(userData, callback) emscripten_set_batterychargingchange_callback_on_thread( (userData), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 476 #define emscripten_set_batterylevelchange_callback(userData, callback) emscripten_set_batterylevelchange_callback_on_thread( (userData), (callback), EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD) 477 #define emscripten_set_beforeunload_callback(userData, callback) emscripten_set_beforeunload_callback_on_thread( (userData), (callback), EM_CALLBACK_THREAD_CONTEXT_MAIN_BROWSER_THREAD) 478 479 extern long emscripten_set_timeout(void (*cb)(void *userData), double msecs, void *userData); 480 extern void emscripten_clear_timeout(long setTimeoutId); 481 extern void emscripten_set_timeout_loop(EM_BOOL (*cb)(double time, void *userData), double intervalMsecs, void *userData); 482 483 extern long emscripten_request_animation_frame(EM_BOOL (*cb)(double time, void *userData), void *userData); 484 extern void emscripten_cancel_animation_frame(long requestAnimationFrameId); 485 extern void emscripten_request_animation_frame_loop(EM_BOOL (*cb)(double time, void *userData), void *userData); 486 487 extern long emscripten_set_immediate(void (*cb)(void *userData), void *userData); 488 extern void emscripten_clear_immediate(long setImmediateId); 489 extern void emscripten_set_immediate_loop(EM_BOOL (*cb)(void *userData), void *userData); 490 491 extern long emscripten_set_interval(void (*cb)(void *userData), double intervalMsecs, void *userData); 492 extern void emscripten_clear_interval(long setIntervalId); 493 494 extern double emscripten_date_now(void); 495 extern double emscripten_performance_now(void); 496 497 extern void emscripten_console_log(const char *utf8String); 498 extern void emscripten_console_warn(const char *utf8String); 499 extern void emscripten_console_error(const char *utf8String); 500 501 extern void emscripten_throw_number(double number); 502 extern void emscripten_throw_string(const char *utf8String); 503 504 extern void emscripten_unwind_to_js_event_loop(void) __attribute__((noreturn)); 505 506 #ifdef __cplusplus 507 } // ~extern "C" 508 #endif 509 510 // For backwards compatibility, always include html5_webgl.h from html5.h 511 #include <emscripten/html5_webgl.h> 512