comparison Samples/WebAssembly/RtViewer/RtViewerWasm.cpp @ 1406:5d7ee14dc1eb

Mouse wheel handler is now OK in SDL and Wasm
author Benjamin Golinvaux <bgo@osimis.io>
date Thu, 30 Apr 2020 00:25:55 +0200
parents 3e644f6fadd4
children 15173a383a00
comparison
equal deleted inserted replaced
1405:e4fe346c021e 1406:5d7ee14dc1eb
73 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \ 73 DISPATCH_JAVASCRIPT_EVENT("StoneException"); \
74 } 74 }
75 75
76 namespace OrthancStone 76 namespace OrthancStone
77 { 77 {
78 // typedef EM_BOOL (*OnMouseWheelFunc)(int eventType, const EmscriptenWheelEvent* wheelEvent, void* userData);
79
80 EM_BOOL RtViewerView_Scroll(int eventType,
81 const EmscriptenWheelEvent* wheelEvent,
82 void* userData)
83 {
84 RtViewerView* that = reinterpret_cast<RtViewerView*>(userData);
85
86 int delta = 0;
87 if (wheelEvent->deltaY < 0)
88 delta = -1;
89 if (wheelEvent->deltaY > 0)
90 delta = 1;
91
92 that->Scroll(delta);
93
94 return 1;
95 }
96
78 boost::shared_ptr<IViewport> RtViewerView::CreateViewport( 97 boost::shared_ptr<IViewport> RtViewerView::CreateViewport(
79 const std::string& canvasId) 98 const std::string& canvasId)
80 { 99 {
81 return WebGLViewport::Create(canvasId); 100 boost::shared_ptr<IViewport> viewport = WebGLViewport::Create(canvasId);
101
102 void* userData = reinterpret_cast<void*>(this);
103
104 // manually add the mouse wheel handler
105
106 std::string selector = "#" + canvasId;
107
108 emscripten_set_wheel_callback_on_thread(
109 selector.c_str(),
110 userData,
111 false,
112 &RtViewerView_Scroll,
113 EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD);
114
115 return viewport;
82 } 116 }
83 117
84 void RtViewerView::TakeScreenshot(const std::string& target, 118 void RtViewerView::TakeScreenshot(const std::string& target,
85 unsigned int canvasWidth, 119 unsigned int canvasWidth,
86 unsigned int canvasHeight) 120 unsigned int canvasHeight)