comparison Framework/Viewport/WebAssemblyViewport.cpp @ 1351:1b8e37770d78 broker

ID vs CSS selector distinction in API and field names.
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 15 Apr 2020 12:57:36 +0200
parents df8bf351c23f
children d8bb885e9b0a
comparison
equal deleted inserted replaced
1350:c53a4667f895 1351:1b8e37770d78
137 137
138 EM_BOOL WebAssemblyViewport::OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) 138 EM_BOOL WebAssemblyViewport::OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
139 { 139 {
140 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); 140 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData);
141 141
142 LOG(TRACE) << "mouse down: " << that->GetFullCanvasId(); 142 LOG(TRACE) << "mouse down: " << that->GetCanvasCssSelector();
143 143
144 if (that->compositor_.get() != NULL && 144 if (that->compositor_.get() != NULL &&
145 that->interactor_.get() != NULL) 145 that->interactor_.get() != NULL)
146 { 146 {
147 PointerEvent pointer; 147 PointerEvent pointer;
211 } 211 }
212 } 212 }
213 213
214 WebAssemblyViewport::WebAssemblyViewport( 214 WebAssemblyViewport::WebAssemblyViewport(
215 const std::string& canvasId, bool enableEmscriptenMouseEvents) : 215 const std::string& canvasId, bool enableEmscriptenMouseEvents) :
216 shortCanvasId_(canvasId), 216 canvasId_(canvasId),
217 fullCanvasId_(canvasId), 217 canvasCssSelector_("#" + canvasId),
218 interactor_(new DefaultViewportInteractor), 218 interactor_(new DefaultViewportInteractor),
219 enableEmscriptenMouseEvents_(enableEmscriptenMouseEvents) 219 enableEmscriptenMouseEvents_(enableEmscriptenMouseEvents)
220 { 220 {
221 } 221 }
222 222
224 { 224 {
225 boost::shared_ptr<IViewport> viewport = shared_from_this(); 225 boost::shared_ptr<IViewport> viewport = shared_from_this();
226 controller_.reset(new ViewportController(viewport)); 226 controller_.reset(new ViewportController(viewport));
227 227
228 LOG(INFO) << "Initializing Stone viewport on HTML canvas: " 228 LOG(INFO) << "Initializing Stone viewport on HTML canvas: "
229 << shortCanvasId_; 229 << canvasId_;
230 230
231 if (shortCanvasId_.empty() || 231 if (canvasId_.empty() ||
232 shortCanvasId_[0] == '#') 232 canvasId_[0] == '#')
233 { 233 {
234 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, 234 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
235 "The canvas identifier must not start with '#'"); 235 "The canvas identifier must not start with '#'");
236 } 236 }
237 237
241 function(event) 241 function(event)
242 { 242 {
243 event.preventDefault(); 243 event.preventDefault();
244 } 244 }
245 }, 245 },
246 shortCanvasId_.c_str() // $0 246 canvasId_.c_str() // $0
247 ); 247 );
248 248
249 // It is not possible to monitor the resizing of individual 249 // It is not possible to monitor the resizing of individual
250 // canvas, so we track the full window of the browser 250 // canvas, so we track the full window of the browser
251 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 251 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
254 OnResize); 254 OnResize);
255 255
256 if (enableEmscriptenMouseEvents_) 256 if (enableEmscriptenMouseEvents_)
257 { 257 {
258 258
259 emscripten_set_mousedown_callback(fullCanvasId_.c_str(), 259 // if any of this function causes an error in the console, please
260 // make sure you are using the new (as of 1.39.x) version of
261 // emscripten element lookup rules( pass
262 // "-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1" to the linker.
263
264 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(),
260 reinterpret_cast<void*>(this), 265 reinterpret_cast<void*>(this),
261 false, 266 false,
262 OnMouseDown); 267 OnMouseDown);
263 268
264 emscripten_set_mousemove_callback(fullCanvasId_.c_str(), 269 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(),
265 reinterpret_cast<void*>(this), 270 reinterpret_cast<void*>(this),
266 false, 271 false,
267 OnMouseMove); 272 OnMouseMove);
268 273
269 emscripten_set_mouseup_callback(fullCanvasId_.c_str(), 274 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(),
270 reinterpret_cast<void*>(this), 275 reinterpret_cast<void*>(this),
271 false, 276 false,
272 OnMouseUp); 277 OnMouseUp);
273 } 278 }
274 } 279 }
281 NULL); 286 NULL);
282 287
283 if (enableEmscriptenMouseEvents_) 288 if (enableEmscriptenMouseEvents_)
284 { 289 {
285 290
286 emscripten_set_mousedown_callback(fullCanvasId_.c_str(), 291 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(),
287 reinterpret_cast<void*>(this), 292 reinterpret_cast<void*>(this),
288 false, 293 false,
289 OnMouseDown); 294 OnMouseDown);
290 295
291 emscripten_set_mousemove_callback(fullCanvasId_.c_str(), 296 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(),
292 reinterpret_cast<void*>(this), 297 reinterpret_cast<void*>(this),
293 false, 298 false,
294 OnMouseMove); 299 OnMouseMove);
295 300
296 emscripten_set_mouseup_callback(fullCanvasId_.c_str(), 301 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(),
297 reinterpret_cast<void*>(this), 302 reinterpret_cast<void*>(this),
298 false, 303 false,
299 OnMouseUp); 304 OnMouseUp);
300 } 305 }
301 } 306 }