SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppEmscripten.cpp File Reference

App::run implementation from App.h for the Emscripten platform. More...

#include <App.h>
#include <SLGLState.h>
#include <SLEnums.h>
#include <SLInterface.h>
#include <AppCommon.h>
#include <SLAssetManager.h>
#include <SLScene.h>
#include <SLSceneView.h>
#include <CVCapture.h>
#include <Profiler.h>
#include <SLAssetLoader.h>
#include <emscripten.h>
#include <emscripten/em_asm.h>
#include <emscripten/html5.h>
#include <emscripten/val.h>
Include dependency graph for AppEmscripten.cpp:

Go to the source code of this file.

Functions

static SLbool onPaint ()
 Paint event handler that passes the event to the slPaintAllViews function. More...
 
static void updateCanvas ()
 
static void onLoadingCoreAssets ()
 
static EM_BOOL onAnimationFrame (double time, void *userData)
 
static EMSCRIPTEN_RESULT onMousePressed (int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
 
static EM_BOOL onMouseReleased (int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
 
static EM_BOOL onMouseDoubleClicked (int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
 
static EM_BOOL onMouseMove (int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
 
static EM_BOOL onMouseWheel (int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData)
 
static EM_BOOL onKeyPressed (int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
 
static EM_BOOL onKeyReleased (int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
 
static EM_BOOL onTouchStart (int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
 
static EM_BOOL onTouchEnd (int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
 
static EM_BOOL onTouchMove (int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
 
static const char * onUnload (int eventType, const void *reserved, void *userData)
 
static SLint convertToCanvasCoordinate (SLint coordinate)
 
static SLKey mapKeyToSLKey (unsigned long key)
 
static SLKey mapModifiersToSLModifiers (bool shiftDown, bool ctrlDown, bool altDown)
 
static SLKey mapModifiersToSLModifiers (const EmscriptenMouseEvent *mouseEvent)
 
static SLKey mapModifiersToSLModifiers (const EmscriptenKeyboardEvent *keyEvent)
 

Variables

static SLint svIndex
 Scene view index. More...
 
static SLint startX
 start position x in pixels More...
 
static SLint startY
 start position y in pixels More...
 
static SLint mouseX
 Last mouse position x in pixels. More...
 
static SLint mouseY
 Last mouse position y in pixels. More...
 
static SLVec2i touch2
 Last finger touch 2 position in pixels. More...
 
static SLVec2i touchDelta
 Delta between two fingers in x. More...
 
static SLint lastWidth
 Last window width in pixels. More...
 
static SLint lastHeight
 Last window height in pixels. More...
 
static int canvasWidth
 Width of the HTML canvas. More...
 
static int canvasHeight
 Height of the HTML canvas. More...
 
static int lastTouchDownX
 X coordinate of last touch down. More...
 
static int lastTouchDownY
 Y coordinate of last touch down. More...
 
static double lastTouchDownTimeMS
 Time of last touch down in milliseconds. More...
 
static long animationFrameID = 0
 ID of the current JavaScript animation frame. More...
 
static SLbool coreAssetsLoaded = false
 Indicates whether core assets can be used. More...
 

Detailed Description

App::run implementation from App.h for the Emscripten platform.

Date
June 2024

The functions implement mostly the callbacks for the platform that are forwarded to the C interface in SLInterface. For more info on how to create a new app with SLProject see: https://github.com/cpvrlab/SLProject4/wiki/Creating-a-New-App For more info about App framework see: https://cpvrlab.github.io/SLProject4/app-framework.html For more info about the Emscripten platform see: https://cpvrlab.github.io/SLProject4/emscripten.html For more info on how to set up the Emscripten platform see: https://github.com/cpvrlab/SLProject4/wiki/Build-for-the-web-with-Emscripten

Authors
Marino von Wattenwyl
Remarks
Please use clangformat to format the code. See more code style on https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style

Definition in file AppEmscripten.cpp.

Function Documentation

◆ convertToCanvasCoordinate()

static SLint convertToCanvasCoordinate ( SLint  coordinate)
static

Definition at line 534 of file AppEmscripten.cpp.

535 {
536  return (SLint)((double)coordinate * EM_ASM_DOUBLE(return window.devicePixelRatio));
537 }
static GLFWwindow * window
The global glfw window handle.
Definition: AppGLFW.cpp:35
int SLint
Definition: SL.h:170

◆ mapKeyToSLKey()

static SLKey mapKeyToSLKey ( unsigned long  key)
static

Definition at line 539 of file AppEmscripten.cpp.

540 {
541  switch (key)
542  {
543  case 8: return K_backspace;
544  case 9: return K_tab;
545  case 13: return K_enter;
546  case 16: return K_shift;
547  case 17: return K_ctrl;
548  case 18: return K_alt;
549  case 27: return K_esc;
550  case 32: return K_space;
551  case 33: return K_pageUp;
552  case 34: return K_pageDown;
553  case 35: return K_end;
554  case 36: return K_home;
555  case 37: return K_left;
556  case 38: return K_up;
557  case 39: return K_right;
558  case 40: return K_down;
559  case 45: return K_insert;
560  case 46: return K_delete;
561  case 96: return K_NP0;
562  case 97: return K_NP1;
563  case 98: return K_NP2;
564  case 99: return K_NP3;
565  case 100: return K_NP4;
566  case 101: return K_NP5;
567  case 102: return K_NP6;
568  case 103: return K_NP7;
569  case 104: return K_NP8;
570  case 105: return K_NP9;
571  case 106: return K_NPMultiply;
572  case 107: return K_NPAdd;
573  case 109: return K_NPSubtract;
574  case 110: return K_NPDecimal;
575  case 111: return K_NPDivide;
576  case 112: return K_F1;
577  case 113: return K_F2;
578  case 114: return K_F3;
579  case 115: return K_F4;
580  case 116: return K_F5;
581  case 117: return K_F6;
582  case 118: return K_F7;
583  case 119: return K_F8;
584  case 120: return K_F9;
585  case 121: return K_F10;
586  case 122: return K_F11;
587  case 123: return K_F12;
588  default: return (SLKey)key;
589  }
590 }
SLKey
Keyboard key codes enumeration.
Definition: SLEnums.h:16
@ K_down
Definition: SLEnums.h:25
@ K_NP5
Definition: SLEnums.h:38
@ K_delete
Definition: SLEnums.h:23
@ K_space
Definition: SLEnums.h:18
@ K_F2
Definition: SLEnums.h:50
@ K_F1
Definition: SLEnums.h:49
@ K_F12
Definition: SLEnums.h:60
@ K_NP9
Definition: SLEnums.h:42
@ K_F6
Definition: SLEnums.h:54
@ K_F4
Definition: SLEnums.h:52
@ K_up
Definition: SLEnums.h:24
@ K_enter
Definition: SLEnums.h:20
@ K_esc
Definition: SLEnums.h:21
@ K_tab
Definition: SLEnums.h:19
@ K_NP6
Definition: SLEnums.h:39
@ K_shift
Definition: SLEnums.h:62
@ K_end
Definition: SLEnums.h:29
@ K_insert
Definition: SLEnums.h:30
@ K_right
Definition: SLEnums.h:26
@ K_F9
Definition: SLEnums.h:57
@ K_NPDivide
Definition: SLEnums.h:43
@ K_pageDown
Definition: SLEnums.h:32
@ K_F8
Definition: SLEnums.h:56
@ K_F5
Definition: SLEnums.h:53
@ K_pageUp
Definition: SLEnums.h:31
@ K_NPMultiply
Definition: SLEnums.h:44
@ K_NPSubtract
Definition: SLEnums.h:46
@ K_NP8
Definition: SLEnums.h:41
@ K_NP1
Definition: SLEnums.h:34
@ K_NP3
Definition: SLEnums.h:36
@ K_ctrl
Definition: SLEnums.h:63
@ K_NP7
Definition: SLEnums.h:40
@ K_NP2
Definition: SLEnums.h:35
@ K_F10
Definition: SLEnums.h:58
@ K_F11
Definition: SLEnums.h:59
@ K_NP4
Definition: SLEnums.h:37
@ K_F3
Definition: SLEnums.h:51
@ K_F7
Definition: SLEnums.h:55
@ K_alt
Definition: SLEnums.h:64
@ K_left
Definition: SLEnums.h:27
@ K_NP0
Definition: SLEnums.h:33
@ K_backspace
Definition: SLEnums.h:22
@ K_home
Definition: SLEnums.h:28
@ K_NPDecimal
Definition: SLEnums.h:48
@ K_NPAdd
Definition: SLEnums.h:45

◆ mapModifiersToSLModifiers() [1/3]

SLKey mapModifiersToSLModifiers ( bool  shiftDown,
bool  ctrlDown,
bool  altDown 
)
static

Definition at line 592 of file AppEmscripten.cpp.

593 {
594  int modifiers = 0;
595  if (shiftDown) modifiers |= K_shift;
596  if (ctrlDown) modifiers |= K_ctrl;
597  if (altDown) modifiers |= K_alt;
598  return (SLKey)modifiers;
599 }
static SLKey modifiers
last modifier keys
Definition: AppGLFW.cpp:50

◆ mapModifiersToSLModifiers() [2/3]

SLKey mapModifiersToSLModifiers ( const EmscriptenKeyboardEvent *  keyEvent)
static

Definition at line 608 of file AppEmscripten.cpp.

609 {
610  return mapModifiersToSLModifiers(keyEvent->shiftKey,
611  keyEvent->ctrlKey,
612  keyEvent->altKey);
613 }
static SLKey mapModifiersToSLModifiers(bool shiftDown, bool ctrlDown, bool altDown)

◆ mapModifiersToSLModifiers() [3/3]

SLKey mapModifiersToSLModifiers ( const EmscriptenMouseEvent *  mouseEvent)
static

Definition at line 601 of file AppEmscripten.cpp.

602 {
603  return mapModifiersToSLModifiers(mouseEvent->shiftKey,
604  mouseEvent->ctrlKey,
605  mouseEvent->altKey);
606 }

◆ onAnimationFrame()

static EM_BOOL onAnimationFrame ( double  time,
void userData 
)
static

Definition at line 230 of file AppEmscripten.cpp.

231 {
232  if (coreAssetsLoaded)
233  onPaint();
234  else
236 
237  // Request another animation frame from the browser to run the next iteration of `update`.
238  animationFrameID = emscripten_request_animation_frame(onAnimationFrame, nullptr);
239 
240  return EM_TRUE;
241 }
static SLbool onPaint()
Paint event handler that passes the event to the slPaintAllViews function.
static SLbool coreAssetsLoaded
Indicates whether core assets can be used.
static long animationFrameID
ID of the current JavaScript animation frame.
static void onLoadingCoreAssets()
static EM_BOOL onAnimationFrame(double time, void *userData)

◆ onKeyPressed()

static EM_BOOL onKeyPressed ( int  eventType,
const EmscriptenKeyboardEvent *  keyEvent,
void userData 
)
static

Definition at line 400 of file AppEmscripten.cpp.

403 {
404  if (keyEvent->repeat)
405  return EM_TRUE;
406 
407  SLKey key = mapKeyToSLKey(keyEvent->keyCode);
410 
411  return EM_FALSE;
412 }
static SLint svIndex
Scene view index.
static SLKey mapKeyToSLKey(unsigned long key)
void slKeyPress(int sceneViewIndex, SLKey key, SLKey modifier)

◆ onKeyReleased()

static EM_BOOL onKeyReleased ( int  eventType,
const EmscriptenKeyboardEvent *  keyEvent,
void userData 
)
static

Definition at line 414 of file AppEmscripten.cpp.

417 {
418  SLKey key = mapKeyToSLKey(keyEvent->keyCode);
421 
422  return EM_FALSE;
423 }
void slKeyRelease(int sceneViewIndex, SLKey key, SLKey modifier)

◆ onLoadingCoreAssets()

static void onLoadingCoreAssets ( )
static

Definition at line 204 of file AppEmscripten.cpp.

205 {
206  if (AppCommon::assetLoader->isLoading())
207  {
209  return;
210  }
211 
212  coreAssetsLoaded = true;
213 
216  canvasWidth,
217  canvasHeight,
218  (int)(142.0 * EM_ASM_DOUBLE(return window.devicePixelRatio)),
220  reinterpret_cast<void*>(onPaint),
221  nullptr,
222  reinterpret_cast<void*>(App::config.onNewSceneView),
223  reinterpret_cast<void*>(App::config.onGuiBuild),
224  reinterpret_cast<void*>(App::config.onGuiLoadConfig),
225  reinterpret_cast<void*>(App::config.onGuiSaveConfig));
226 
227  EM_ASM(document.querySelector("#loading-overlay").style.opacity = 0);
228 }
static int canvasWidth
Width of the HTML canvas.
static int canvasHeight
Height of the HTML canvas.
SLint slCreateSceneView(SLAssetManager *am, SLScene *scene, int screenWidth, int screenHeight, int dotsPerInch, SLSceneID initScene, void *onWndUpdateCallback, void *onSelectNodeMeshCallback, void *onNewSceneViewCallback, void *onImGuiBuild, void *onImGuiLoadConfig, void *onImGuiSaveConfig)
static SLAssetManager * assetManager
asset manager is the owner of all assets
Definition: AppCommon.h:59
static SLAssetLoader * assetLoader
Asset-loader for async asset loading.
Definition: AppCommon.h:60
static SLScene * scene
Pointer to the one and only SLScene instance.
Definition: AppCommon.h:61
void checkIfAsyncLoadingIsDone()
Config config
The configuration set in App::run.
Definition: AppAndroid.cpp:34
OnGuiLoadConfigCallback onGuiLoadConfig
Definition: App.h:73
SLSceneID startSceneID
Definition: App.h:64
OnNewSceneViewCallback onNewSceneView
Definition: App.h:65
OnGuiSaveConfigCallback onGuiSaveConfig
Definition: App.h:74
OnGuiBuildCallback onGuiBuild
Definition: App.h:72

◆ onMouseDoubleClicked()

static EM_BOOL onMouseDoubleClicked ( int  eventType,
const EmscriptenMouseEvent *  mouseEvent,
void userData 
)
static

Definition at line 326 of file AppEmscripten.cpp.

329 {
330  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
331  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
333 
334  switch (mouseEvent->button)
335  {
336  case 0:
338  MB_left,
339  x,
340  y,
341  modifiers);
342  break;
343  case 1:
345  MB_middle,
346  x,
347  y,
348  modifiers);
349  break;
350  case 2:
352  MB_right,
353  x,
354  y,
355  modifiers);
356  break;
357  default: break;
358  }
359 
360  return EM_TRUE;
361 }
static SLint convertToCanvasCoordinate(SLint coordinate)
@ MB_left
Definition: SLEnums.h:100
@ MB_right
Definition: SLEnums.h:102
@ MB_middle
Definition: SLEnums.h:101
void slDoubleClick(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)

◆ onMouseMove()

static EM_BOOL onMouseMove ( int  eventType,
const EmscriptenMouseEvent *  mouseEvent,
void userData 
)
static

Definition at line 363 of file AppEmscripten.cpp.

366 {
367  mouseX = convertToCanvasCoordinate(mouseEvent->targetX);
368  mouseY = convertToCanvasCoordinate(mouseEvent->targetY);
369 
370  if (mouseEvent->altKey && mouseEvent->ctrlKey)
372  mouseX - 20,
373  mouseY,
374  mouseX + 20,
375  mouseY);
376  else
378  mouseX,
379  mouseY);
380 
381  return EM_TRUE;
382 }
static SLint mouseX
Last mouse position x in pixels.
static SLint mouseY
Last mouse position y in pixels.
void slTouch2Move(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)
void slMouseMove(int sceneViewIndex, int x, int y)

◆ onMousePressed()

static EMSCRIPTEN_RESULT onMousePressed ( int  eventType,
const EmscriptenMouseEvent *  mouseEvent,
void userData 
)
static

Definition at line 243 of file AppEmscripten.cpp.

246 {
247  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
248  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
250 
251  startX = x;
252  startY = y;
253 
254  switch (mouseEvent->button)
255  {
256  case 0:
257  if (modifiers & K_alt && modifiers & K_ctrl)
258  slTouch2Down(svIndex, x - 20, y, x + 20, y);
259  else
261  MB_left,
262  x,
263  y,
264  modifiers);
265  break;
266  case 1:
268  MB_middle,
269  x,
270  y,
271  modifiers);
272  break;
273  case 2:
275  MB_right,
276  x,
277  y,
278  modifiers);
279  break;
280  default: break;
281  }
282 
283  return EM_TRUE;
284 }
static SLint startY
start position y in pixels
static SLint startX
start position x in pixels
void slMouseDown(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)
void slTouch2Down(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)

◆ onMouseReleased()

static EM_BOOL onMouseReleased ( int  eventType,
const EmscriptenMouseEvent *  mouseEvent,
void userData 
)
static

Definition at line 286 of file AppEmscripten.cpp.

289 {
290  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
291  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
293 
294  startX = -1;
295  startY = -1;
296 
297  switch (mouseEvent->button)
298  {
299  case 0:
301  MB_left,
302  x,
303  y,
304  modifiers);
305  break;
306  case 1:
308  MB_middle,
309  x,
310  y,
311  modifiers);
312  break;
313  case 2:
315  MB_right,
316  x,
317  y,
318  modifiers);
319  break;
320  default: break;
321  }
322 
323  return EM_TRUE;
324 }
void slMouseUp(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)

◆ onMouseWheel()

static EM_BOOL onMouseWheel ( int  eventType,
const EmscriptenWheelEvent *  wheelEvent,
void userData 
)
static

Definition at line 384 of file AppEmscripten.cpp.

387 {
388  // Invert the sign because the scroll value is inverted
389  double deltaY = -wheelEvent->deltaY;
390 
391  // Make sure the delta is at least one integer
392  if (std::abs(deltaY) < 1) deltaY = Utils::sign(wheelEvent->deltaY);
393 
394  SLKey modifiers = mapModifiersToSLModifiers(&wheelEvent->mouse);
395  slMouseWheel(svIndex, (int)deltaY, modifiers);
396 
397  return EM_TRUE;
398 }
void slMouseWheel(int sceneViewIndex, int pos, SLKey modifier)
T sign(T a)
Definition: Utils.h:245
T abs(T a)
Definition: Utils.h:249

◆ onPaint()

static SLbool onPaint ( )
static

Paint event handler that passes the event to the slPaintAllViews function.

Definition at line 152 of file AppEmscripten.cpp.

153 {
154  if (AppCommon::sceneViews.empty())
155  return false;
156 
158 
159  int newCanvasWidth = EM_ASM_INT(return window.devicePixelRatio * window.innerWidth);
160  int newCanvasHeight = EM_ASM_INT(return window.devicePixelRatio * window.innerHeight);
161 
162  if (newCanvasWidth != canvasWidth || newCanvasHeight != canvasHeight)
163  {
164  canvasWidth = newCanvasWidth;
165  canvasHeight = newCanvasHeight;
166  updateCanvas();
167 
168  if (!AppCommon::sceneViews.empty())
170  canvasWidth,
171  canvasHeight);
172  }
173 
175  {
177  AppCommon::sceneToLoad = {}; // sets optional to empty
178  }
179 
180  if (AppCommon::assetLoader->isLoading())
182 
183  //////////////////////////////////////////////////////////////////////////
184  SLbool appNeedsUpdate = App::config.onUpdate && App::config.onUpdate(sv);
185  SLbool jobIsRunning = slUpdateParallelJob();
186  SLbool isLoading = AppCommon::assetLoader->isLoading();
187  SLbool viewNeedsUpdate = slPaintAllViews();
188  //////////////////////////////////////////////////////////////////////////
189 
190  return appNeedsUpdate || viewNeedsUpdate || jobIsRunning || isLoading;
191 }
static void updateCanvas()
bool SLbool
Definition: SL.h:175
void slSwitchScene(SLSceneView *sv, SLSceneID sceneID)
void slResize(int sceneViewIndex, int width, int height)
bool slPaintAllViews()
bool slUpdateParallelJob()
static optional< SLSceneID > sceneToLoad
Scene id to load at start up.
Definition: AppCommon.h:90
static SLVSceneView sceneViews
Vector of sceneview pointers.
Definition: AppCommon.h:62
bool isLoading() const
Definition: SLAssetLoader.h:68
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
OnUpdateCallback onUpdate
Definition: App.h:71

◆ onTouchEnd()

static EM_BOOL onTouchEnd ( int  eventType,
const EmscriptenTouchEvent *  touchEvent,
void userData 
)
static

Definition at line 455 of file AppEmscripten.cpp.

458 {
459  if (touchEvent->numTouches == 1)
460  {
461  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
462  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
464  MB_left,
465  mouseX,
466  mouseY,
467  K_none);
468 
469  int dx = std::abs(mouseX - lastTouchDownX);
470  int dy = std::abs(mouseY - lastTouchDownY);
471  double dt = touchEvent->timestamp - lastTouchDownTimeMS;
472 
473  if (dt > 800 && dx < 15 && dy < 15)
474  {
476  MB_right,
479  K_none);
481  MB_right,
484  K_none);
485  }
486  }
487  else if (touchEvent->numTouches == 2)
488  {
489  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
490  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
491  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
492  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
493  slTouch2Up(svIndex, x0, y0, x1, y1);
494  }
495 
496  return EM_TRUE;
497 }
static double lastTouchDownTimeMS
Time of last touch down in milliseconds.
static int lastTouchDownY
Y coordinate of last touch down.
static int lastTouchDownX
X coordinate of last touch down.
@ K_none
Definition: SLEnums.h:17
void slTouch2Up(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)

◆ onTouchMove()

static EM_BOOL onTouchMove ( int  eventType,
const EmscriptenTouchEvent *  touchEvent,
void userData 
)
static

Definition at line 499 of file AppEmscripten.cpp.

502 {
503  if (touchEvent->numTouches == 1)
504  {
505  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
506  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
508  }
509  else if (touchEvent->numTouches == 2)
510  {
511  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
512  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
513  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
514  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
515  slTouch2Move(svIndex, x0, y0, x1, y1);
516  }
517 
518  return EM_TRUE;
519 }

◆ onTouchStart()

static EM_BOOL onTouchStart ( int  eventType,
const EmscriptenTouchEvent *  touchEvent,
void userData 
)
static

Definition at line 425 of file AppEmscripten.cpp.

428 {
429  if (touchEvent->numTouches == 1)
430  {
431  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
432  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
434  MB_left,
435  mouseX,
436  mouseY,
437  K_none);
438  lastTouchDownTimeMS = touchEvent->timestamp;
439  }
440  else if (touchEvent->numTouches == 2)
441  {
442  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
443  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
444  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
445  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
446  slTouch2Down(svIndex, x0, y0, x1, y1);
447  }
448 
451 
452  return EM_TRUE;
453 }

◆ onUnload()

static const char * onUnload ( int  eventType,
const void reserved,
void userData 
)
static

Definition at line 521 of file AppEmscripten.cpp.

524 {
525  slTerminate();
526 
527  // Cancel the current animation frame to prevent `update` being called after
528  // everything has been terminated and cleaned up.
529  emscripten_cancel_animation_frame(animationFrameID);
530 
531  return nullptr;
532 }
void slTerminate()

◆ updateCanvas()

static void updateCanvas ( )
static

Definition at line 193 of file AppEmscripten.cpp.

194 {
195  // clang-format off
196  EM_ASM({
197  let canvas = Module['canvas'];
198  canvas.width = $0;
199  canvas.height = $1;
201  // clang-format on
202 }

Variable Documentation

◆ animationFrameID

long animationFrameID = 0
static

ID of the current JavaScript animation frame.

Definition at line 55 of file AppEmscripten.cpp.

◆ canvasHeight

int canvasHeight
static

Height of the HTML canvas.

Definition at line 51 of file AppEmscripten.cpp.

◆ canvasWidth

int canvasWidth
static

Width of the HTML canvas.

Definition at line 50 of file AppEmscripten.cpp.

◆ coreAssetsLoaded

SLbool coreAssetsLoaded = false
static

Indicates whether core assets can be used.

Definition at line 56 of file AppEmscripten.cpp.

◆ lastHeight

SLint lastHeight
static

Last window height in pixels.

Definition at line 49 of file AppEmscripten.cpp.

◆ lastTouchDownTimeMS

double lastTouchDownTimeMS
static

Time of last touch down in milliseconds.

Definition at line 54 of file AppEmscripten.cpp.

◆ lastTouchDownX

int lastTouchDownX
static

X coordinate of last touch down.

Definition at line 52 of file AppEmscripten.cpp.

◆ lastTouchDownY

int lastTouchDownY
static

Y coordinate of last touch down.

Definition at line 53 of file AppEmscripten.cpp.

◆ lastWidth

SLint lastWidth
static

Last window width in pixels.

Definition at line 48 of file AppEmscripten.cpp.

◆ mouseX

SLint mouseX
static

Last mouse position x in pixels.

Definition at line 44 of file AppEmscripten.cpp.

◆ mouseY

SLint mouseY
static

Last mouse position y in pixels.

Definition at line 45 of file AppEmscripten.cpp.

◆ startX

SLint startX
static

start position x in pixels

Definition at line 42 of file AppEmscripten.cpp.

◆ startY

SLint startY
static

start position y in pixels

Definition at line 43 of file AppEmscripten.cpp.

◆ svIndex

SLint svIndex
static

Scene view index.

Definition at line 41 of file AppEmscripten.cpp.

◆ touch2

SLVec2i touch2
static

Last finger touch 2 position in pixels.

Definition at line 46 of file AppEmscripten.cpp.

◆ touchDelta

SLVec2i touchDelta
static

Delta between two fingers in x.

Definition at line 47 of file AppEmscripten.cpp.