1 // Created on: 1998-08-27
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest_EventManager.hxx>
19 #include <AIS_AnimationCamera.hxx>
20 #include <Aspect_DisplayConnection.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <AIS_Shape.hxx>
23 #include <Aspect_Grid.hxx>
25 #include <Message.hxx>
26 #include <ViewerTest_ContinuousRedrawer.hxx>
27 #include <ViewerTest_V3dView.hxx>
28 #include <ViewerTest.hxx>
32 #elif defined(HAVE_XLIB)
33 #include <Xw_Window.hxx>
35 #include <X11/Xutil.h>
36 #elif defined(__EMSCRIPTEN__)
37 #include <Wasm_Window.hxx>
38 #include <emscripten.h>
39 #include <emscripten/html5.h>
41 //! Callback flushing events and redrawing the WebGL canvas.
42 static void onWasmRedrawView (void* )
44 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
45 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
46 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
47 if (!aViewCtrl.IsNull() && !aView.IsNull() && !aCtx.IsNull())
49 aViewCtrl->ProcessExpose();
54 Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
56 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
58 //=======================================================================
59 //function : GlobalViewAnimation
61 //=======================================================================
62 const Handle(AIS_AnimationCamera)& ViewerTest_EventManager::GlobalViewAnimation()
64 static Handle(AIS_AnimationCamera) THE_CAMERA_ANIM = new AIS_AnimationCamera ("ViewerTest_EventManager_ViewAnimation", Handle(V3d_View)());
65 THE_CAMERA_ANIM->SetOwnDuration (0.5);
66 return THE_CAMERA_ANIM;
69 //=======================================================================
70 //function : ViewerTest_EventManager
72 //=======================================================================
73 ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
74 const Handle(AIS_InteractiveContext)& theCtx)
77 myToPickPnt (Standard_False),
78 myIsTmpContRedraw (Standard_False),
81 myViewAnimation = GlobalViewAnimation();
83 addActionHotKeys (Aspect_VKey_NavForward, Aspect_VKey_W, Aspect_VKey_W | Aspect_VKeyFlags_SHIFT);
84 addActionHotKeys (Aspect_VKey_NavBackward , Aspect_VKey_S, Aspect_VKey_S | Aspect_VKeyFlags_SHIFT);
85 addActionHotKeys (Aspect_VKey_NavSlideLeft, Aspect_VKey_A, Aspect_VKey_A | Aspect_VKeyFlags_SHIFT);
86 addActionHotKeys (Aspect_VKey_NavSlideRight, Aspect_VKey_D, Aspect_VKey_D | Aspect_VKeyFlags_SHIFT);
87 addActionHotKeys (Aspect_VKey_NavRollCCW, Aspect_VKey_Q, Aspect_VKey_Q | Aspect_VKeyFlags_SHIFT);
88 addActionHotKeys (Aspect_VKey_NavRollCW, Aspect_VKey_E, Aspect_VKey_E | Aspect_VKeyFlags_SHIFT);
90 addActionHotKeys (Aspect_VKey_NavSpeedIncrease, Aspect_VKey_Plus, Aspect_VKey_Plus | Aspect_VKeyFlags_SHIFT,
92 Aspect_VKey_NumpadAdd, Aspect_VKey_NumpadAdd | Aspect_VKeyFlags_SHIFT);
93 addActionHotKeys (Aspect_VKey_NavSpeedDecrease, Aspect_VKey_Minus, Aspect_VKey_Minus | Aspect_VKeyFlags_SHIFT,
94 Aspect_VKey_NumpadSubtract, Aspect_VKey_NumpadSubtract | Aspect_VKeyFlags_SHIFT);
96 addActionHotKeys (Aspect_VKey_NavLookUp, Aspect_VKey_Up);
97 addActionHotKeys (Aspect_VKey_NavLookDown, Aspect_VKey_Down);
98 addActionHotKeys (Aspect_VKey_NavLookLeft, Aspect_VKey_Left);
99 addActionHotKeys (Aspect_VKey_NavLookRight, Aspect_VKey_Right);
100 addActionHotKeys (Aspect_VKey_NavSlideLeft, Aspect_VKey_Left | Aspect_VKeyFlags_SHIFT);
101 addActionHotKeys (Aspect_VKey_NavSlideRight, Aspect_VKey_Right | Aspect_VKeyFlags_SHIFT);
102 addActionHotKeys (Aspect_VKey_NavSlideUp, Aspect_VKey_Up | Aspect_VKeyFlags_SHIFT);
103 addActionHotKeys (Aspect_VKey_NavSlideDown, Aspect_VKey_Down | Aspect_VKeyFlags_SHIFT);
105 // window could be actually not yet set to the View
106 //SetupWindowCallbacks (theView->Window());
109 //=======================================================================
110 //function : ~ViewerTest_EventManager
112 //=======================================================================
113 ViewerTest_EventManager::~ViewerTest_EventManager()
115 if (!myViewAnimation.IsNull()
116 && myViewAnimation->View() == myView)
118 myViewAnimation->Stop();
119 myViewAnimation->SetView (Handle(V3d_View)());
123 // =======================================================================
124 // function : UpdateMouseClick
126 // =======================================================================
127 bool ViewerTest_EventManager::UpdateMouseClick (const Graphic3d_Vec2i& thePoint,
128 Aspect_VKeyMouse theButton,
129 Aspect_VKeyFlags theModifiers,
130 bool theIsDoubleClick)
132 if (theIsDoubleClick && !myView.IsNull() && !myCtx.IsNull())
134 FitAllAuto (myCtx, myView);
137 return AIS_ViewController::UpdateMouseClick (thePoint, theButton, theModifiers, theIsDoubleClick);
140 //=======================================================================
141 //function : UpdateMouseButtons
143 //=======================================================================
144 bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
145 Aspect_VKeyMouse theButtons,
146 Aspect_VKeyFlags theModifiers,
149 SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode());
151 if (theButtons == Aspect_VKeyMouse_LeftButton)
153 if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0)
155 Graphic3d_Vec3d anXYZ;
156 myView->Convert (thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z());
157 Draw::Set (myPickPntArgVec[0].ToCString(), anXYZ.x());
158 Draw::Set (myPickPntArgVec[1].ToCString(), anXYZ.y());
159 Draw::Set (myPickPntArgVec[2].ToCString(), anXYZ.z());
164 return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated);
167 //==============================================================================
168 //function : ProcessExpose
170 //==============================================================================
171 void ViewerTest_EventManager::ProcessExpose()
173 if (!myView.IsNull())
175 FlushViewEvents (myCtx, myView, true);
179 //==============================================================================
180 //function : handleViewRedraw
182 //==============================================================================
183 void ViewerTest_EventManager::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
184 const Handle(V3d_View)& theView)
186 myUpdateRequests = 0;
187 AIS_ViewController::handleViewRedraw (theCtx, theView);
189 // On non-Windows platforms Aspect_Window::InvalidateContent() from rendering thread does not work as expected
190 // as in Tcl event loop the new message might go to sleep with new event remaining in queue.
191 // As a workaround - use dedicated background thread to ping Tcl event loop.
192 if (myToAskNextFrame)
194 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
195 if (!myIsTmpContRedraw
196 && (!aRedrawer.IsStarted() || aRedrawer.IsPaused()))
198 myIsTmpContRedraw = true;
199 #if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
200 aRedrawer.Start (theView, 60.0);
206 #if defined(__EMSCRIPTEN__)
207 emscripten_async_call (onWasmRedrawView, this, 0);
210 else if (myIsTmpContRedraw)
212 myIsTmpContRedraw = false;
214 ViewerTest_ContinuousRedrawer& aRedrawer = ViewerTest_ContinuousRedrawer::Instance();
220 //==============================================================================
221 //function : ProcessConfigure
223 //==============================================================================
224 void ViewerTest_EventManager::ProcessConfigure (bool theIsResized)
226 if (!myView.IsNull())
229 // track window moves to reverse stereo pair
230 && myView->RenderingParams().StereoMode != Graphic3d_StereoMode_RowInterlaced
231 && myView->RenderingParams().StereoMode != Graphic3d_StereoMode_ColumnInterlaced
232 && myView->RenderingParams().StereoMode != Graphic3d_StereoMode_ChessBoard)
237 myView->Window()->DoResize();
238 myView->MustBeResized();
239 myView->Invalidate();
240 FlushViewEvents (myCtx, myView, true);
244 //==============================================================================
245 //function : ProcessInput
247 //==============================================================================
248 void ViewerTest_EventManager::ProcessInput()
255 #if defined(__EMSCRIPTEN__)
256 // Queue onWasmRedrawView() callback to redraw canvas after all user input is flushed by browser.
257 // Redrawing viewer on every single message would be a pointless waste of resources,
258 // as user will see only the last drawn frame due to WebGL implementation details.
259 if (++myUpdateRequests == 1)
261 #if defined(__EMSCRIPTEN__)
262 emscripten_async_call (onWasmRedrawView, this, 0);
266 // handle synchronously
271 // =======================================================================
272 // function : navigationKeyModifierSwitch
274 // =======================================================================
275 bool ViewerTest_EventManager::navigationKeyModifierSwitch (unsigned int theModifOld,
276 unsigned int theModifNew,
279 bool hasActions = false;
280 for (unsigned int aKeyIter = 0; aKeyIter < Aspect_VKey_ModifiersLower; ++aKeyIter)
282 if (!myKeys.IsKeyDown (aKeyIter))
287 Aspect_VKey anActionOld = Aspect_VKey_UNKNOWN, anActionNew = Aspect_VKey_UNKNOWN;
288 myNavKeyMap.Find (aKeyIter | theModifOld, anActionOld);
289 myNavKeyMap.Find (aKeyIter | theModifNew, anActionNew);
290 if (anActionOld == anActionNew)
295 if (anActionOld != Aspect_VKey_UNKNOWN)
297 myKeys.KeyUp (anActionOld, theTimeStamp);
299 if (anActionNew != Aspect_VKey_UNKNOWN)
302 myKeys.KeyDown (anActionNew, theTimeStamp);
308 //=======================================================================
311 //=======================================================================
312 void ViewerTest_EventManager::KeyDown (Aspect_VKey theKey,
316 const unsigned int aModifOld = myKeys.Modifiers();
317 AIS_ViewController::KeyDown (theKey, theTime, thePressure);
319 const unsigned int aModifNew = myKeys.Modifiers();
320 if (aModifNew != aModifOld
321 && navigationKeyModifierSwitch (aModifOld, aModifNew, theTime))
323 // modifier key just pressed
326 Aspect_VKey anAction = Aspect_VKey_UNKNOWN;
327 if (myNavKeyMap.Find (theKey | myKeys.Modifiers(), anAction)
328 && anAction != Aspect_VKey_UNKNOWN)
330 AIS_ViewController::KeyDown (anAction, theTime, thePressure);
334 //=======================================================================
337 //=======================================================================
338 void ViewerTest_EventManager::KeyUp (Aspect_VKey theKey,
341 const unsigned int aModifOld = myKeys.Modifiers();
342 AIS_ViewController::KeyUp (theKey, theTime);
344 Aspect_VKey anAction = Aspect_VKey_UNKNOWN;
345 if (myNavKeyMap.Find (theKey | myKeys.Modifiers(), anAction)
346 && anAction != Aspect_VKey_UNKNOWN)
348 AIS_ViewController::KeyUp (anAction, theTime);
349 ProcessKeyPress (anAction);
352 const unsigned int aModifNew = myKeys.Modifiers();
353 if (aModifNew != aModifOld
354 && navigationKeyModifierSwitch (aModifOld, aModifNew, theTime))
356 // modifier key released
359 ProcessKeyPress (theKey | aModifNew);
362 //==============================================================================
363 //function : ProcessKeyPress
365 //==============================================================================
366 void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
376 case Aspect_VKey_Backspace: // AXO
378 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
380 myView->SetProj(V3d_XposYnegZpos);
386 if (myCtx->NbSelected() > 0)
388 myCtx->FitSelected (myView);
396 case Aspect_VKey_H: // HLR
398 std::cout << "HLR\n";
399 myView->SetComputedMode (!myView->ComputedMode());
403 case Aspect_VKey_P: // Type of HLR
405 myCtx->DefaultDrawer()->SetTypeOfHLR (myCtx->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo
408 if (myCtx->NbSelected() == 0)
410 AIS_ListOfInteractive aListOfShapes;
411 myCtx->DisplayedObjects (aListOfShapes);
412 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
414 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()))
416 aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
418 : Prs3d_TOH_PolyAlgo);
419 myCtx->Redisplay (aShape, Standard_False);
425 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
427 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (myCtx->SelectedInteractive()))
429 aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
431 : Prs3d_TOH_PolyAlgo);
432 myCtx->Redisplay (aShape, Standard_False);
436 myCtx->UpdateCurrentViewer();
439 case Aspect_VKey_S | Aspect_VKeyFlags_CTRL:
440 case Aspect_VKey_W | Aspect_VKeyFlags_CTRL:
442 Standard_Integer aDispMode = AIS_Shaded;
443 if (theKey == (Aspect_VKey_S | Aspect_VKeyFlags_CTRL))
445 aDispMode = AIS_Shaded;
446 std::cout << "setup Shaded display mode\n";
450 aDispMode = AIS_WireFrame;
451 std::cout << "setup WireFrame display mode\n";
454 if (myCtx->NbSelected() == 0)
456 myCtx->SetDisplayMode (aDispMode, true);
460 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
462 myCtx->SetDisplayMode (myCtx->SelectedInteractive(), aDispMode, false);
464 myCtx->UpdateCurrentViewer();
468 case Aspect_VKey_U: // Unset display mode
470 std::cout << "reset display mode to defaults\n";
471 if (myCtx->NbSelected() == 0)
473 myCtx->SetDisplayMode (AIS_WireFrame, true);
477 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
479 myCtx->UnsetDisplayMode (myCtx->SelectedInteractive(), false);
481 myCtx->UpdateCurrentViewer();
487 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
489 myView->SetProj (V3d_TypeOfOrientation_Zup_Top);
495 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
497 myView->SetProj (V3d_TypeOfOrientation_Zup_Bottom);
503 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
505 myView->SetProj (V3d_TypeOfOrientation_Zup_Left);
511 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
513 myView->SetProj (V3d_TypeOfOrientation_Zup_Right);
517 case Aspect_VKey_Comma:
519 myCtx->HilightNextDetected (myView);
522 case Aspect_VKey_Period:
524 myCtx->HilightPreviousDetected (myView);
527 case Aspect_VKey_Slash:
528 case Aspect_VKey_NumpadDivide:
530 Handle(Graphic3d_Camera) aCamera = myView->Camera();
531 if (aCamera->IsStereo())
533 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
538 case Aspect_VKey_NumpadMultiply:
540 Handle(Graphic3d_Camera) aCamera = myView->Camera();
541 if (aCamera->IsStereo())
543 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
548 case Aspect_VKey_Delete:
551 && myCtx->NbSelected() > 0)
553 Draw_Interprete ("verase");
557 case Aspect_VKey_Escape:
560 && ViewerTest_EventManager::ToCloseViewOnEscape())
562 Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose");
566 case Aspect_VKey_NavSpeedDecrease:
567 case Aspect_VKey_NavSpeedIncrease:
569 // handle slide speed
570 float aNewSpeed = theKey == Aspect_VKey_NavSpeedDecrease
571 ? myWalkSpeedRelative * 0.5f
572 : myWalkSpeedRelative * 2.0f;
573 if (aNewSpeed >= 0.00001f
574 && aNewSpeed <= 10.0f)
576 if (Abs (aNewSpeed - 0.1f) < 0.001f)
580 myWalkSpeedRelative = aNewSpeed;
586 if (theKey >= Aspect_VKey_0
587 && theKey <= Aspect_VKey_7)
589 const Standard_Integer aSelMode = theKey - Aspect_VKey_0;
590 bool toEnable = true;
593 AIS_ListOfInteractive aPrsList;
594 myCtx->DisplayedObjects (aPrsList);
595 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
597 TColStd_ListOfInteger aModes;
598 myCtx->ActivatedModes (aPrsIter.Value(), aModes);
599 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
601 if (aModeIter.Value() == aSelMode)
608 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
609 Draw_Interprete (aCmd.ToCString());
613 #if defined(__EMSCRIPTEN__)
614 //! Handle browser window resize event.
615 static EM_BOOL onResizeCallback (int theEventType, const EmscriptenUiEvent* theEvent, void* )
617 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
618 if (!aViewCtrl.IsNull()
619 && !ViewerTest::CurrentView().IsNull())
621 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
622 return aWindow->ProcessUiEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
627 //! Handle mouse input event.
628 static EM_BOOL onWasmMouseCallback (int theEventType, const EmscriptenMouseEvent* theEvent, void* )
630 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
631 if (!aViewCtrl.IsNull()
632 && !ViewerTest::CurrentView().IsNull())
634 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
635 return aWindow->ProcessMouseEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
640 //! Handle mouse wheel event.
641 static EM_BOOL onWasmWheelCallback (int theEventType, const EmscriptenWheelEvent* theEvent, void* )
643 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
644 if (!aViewCtrl.IsNull()
645 && !ViewerTest::CurrentView().IsNull())
647 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
648 return aWindow->ProcessWheelEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
653 //! Handle touch input event.
654 static EM_BOOL onWasmTouchCallback (int theEventType, const EmscriptenTouchEvent* theEvent, void* )
656 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
657 if (!aViewCtrl.IsNull()
658 && !ViewerTest::CurrentView().IsNull())
660 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
661 return aWindow->ProcessTouchEvent (*aViewCtrl, theEventType, theEvent) ? EM_TRUE : EM_FALSE;
666 //! Handle keyboard input event.
667 static EM_BOOL onWasmKeyCallback (int theEventType, const EmscriptenKeyboardEvent* theEvent, void* )
669 Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
670 if (!aViewCtrl.IsNull()
671 && !ViewerTest::CurrentView().IsNull())
673 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (ViewerTest::CurrentView()->Window());
674 aWindow->ProcessKeyEvent (*aViewCtrl, theEventType, theEvent);
681 // ==============================================================================
682 // function : SetupWindowCallbacks
684 // ==============================================================================
685 void ViewerTest_EventManager::SetupWindowCallbacks (const Handle(Aspect_Window)& theWin)
689 #elif defined(HAVE_XLIB)
691 Window anXWin = (Window )theWin->NativeHandle();
692 Display* anXDisplay = (Display* )theWin->DisplayConnection()->GetDisplayAspect();
693 XSynchronize (anXDisplay, 1);
695 // X11 : For keyboard on SUN
697 memset (&aWmHints, 0, sizeof(aWmHints));
698 aWmHints.flags = InputHint;
700 XSetWMHints (anXDisplay, anXWin, &aWmHints);
702 XSelectInput (anXDisplay, anXWin,
703 ExposureMask | KeyPressMask | KeyReleaseMask
704 | ButtonPressMask | ButtonReleaseMask
705 | StructureNotifyMask
707 | Button1MotionMask | Button2MotionMask
708 | Button3MotionMask | FocusChangeMask);
709 Atom aDeleteWindowAtom = theWin->DisplayConnection()->GetAtom (Aspect_XA_DELETE_WINDOW);
710 XSetWMProtocols (anXDisplay, anXWin, &aDeleteWindowAtom, 1);
712 XSynchronize (anXDisplay, 0);
713 #elif defined(__EMSCRIPTEN__)
714 Handle(Wasm_Window) aWindow = Handle(Wasm_Window)::DownCast (theWin);
715 if (aWindow->CanvasId().IsEmpty()
716 || aWindow->CanvasId() == "#")
718 Message::SendFail ("Error: unable registering callbacks to Module.canvas");
722 const char* aTargetId = aWindow->CanvasId().ToCString();
723 const EM_BOOL toUseCapture = EM_TRUE;
724 void* anOpaque = NULL; //this; // unused
726 // make sure to clear previously set listeners (e.g. created by another ViewerTest_EventManager instance)
727 emscripten_html5_remove_all_event_listeners();
729 // resize event implemented only for a window by browsers,
730 // so that if web application changes canvas size by other means it should use another way to tell OCCT about resize
731 emscripten_set_resize_callback (EMSCRIPTEN_EVENT_TARGET_WINDOW, anOpaque, toUseCapture, onResizeCallback);
733 emscripten_set_mousedown_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
734 emscripten_set_mouseup_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
735 emscripten_set_mousemove_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
736 emscripten_set_dblclick_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
737 emscripten_set_click_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
738 emscripten_set_mouseenter_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
739 emscripten_set_mouseleave_callback (aTargetId, anOpaque, toUseCapture, onWasmMouseCallback);
740 emscripten_set_wheel_callback (aTargetId, anOpaque, toUseCapture, onWasmWheelCallback);
742 emscripten_set_touchstart_callback (aTargetId, anOpaque, toUseCapture, onWasmTouchCallback);
743 emscripten_set_touchend_callback (aTargetId, anOpaque, toUseCapture, onWasmTouchCallback);
744 emscripten_set_touchmove_callback (aTargetId, anOpaque, toUseCapture, onWasmTouchCallback);
745 emscripten_set_touchcancel_callback(aTargetId, anOpaque, toUseCapture, onWasmTouchCallback);
747 // keyboard input requires a focusable element or EMSCRIPTEN_EVENT_TARGET_WINDOW
748 emscripten_set_keydown_callback (aTargetId, anOpaque, toUseCapture, onWasmKeyCallback);
749 emscripten_set_keyup_callback (aTargetId, anOpaque, toUseCapture, onWasmKeyCallback);