comparison OrthancStone/Sources/Viewport/WebAssemblyViewport.h @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Viewport/WebAssemblyViewport.h@6e43cac7833c
children a48ae10857b1
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #if !defined(ORTHANC_ENABLE_WASM)
25 # error Macro ORTHANC_ENABLE_WASM must be defined
26 #endif
27
28 #if ORTHANC_ENABLE_WASM != 1
29 # error This file can only be used if targeting WebAssembly
30 #endif
31
32 #include "IViewport.h"
33
34 #include <Compatibility.h>
35
36 #include <emscripten.h>
37 #include <emscripten/html5.h>
38
39 #include <memory>
40 #include <string>
41
42 namespace OrthancStone
43 {
44 class WebAssemblyViewport : public IViewport,
45 public boost::enable_shared_from_this<WebAssemblyViewport>
46
47 {
48 private:
49 class WasmLock;
50
51 std::string canvasId_;
52 std::string canvasCssSelector_;
53 std::unique_ptr<ICompositor> compositor_;
54 std::unique_ptr<ViewportController> controller_;
55 std::unique_ptr<IViewportInteractor> interactor_;
56 bool enableEmscriptenMouseEvents_;
57
58 static EM_BOOL OnRequestAnimationFrame(double time, void *userData);
59
60 static EM_BOOL OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData);
61
62 static EM_BOOL OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
63
64 static EM_BOOL OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
65
66 static EM_BOOL OnMouseUp(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
67
68 protected:
69 void Invalidate();
70
71 void ClearCompositor()
72 {
73 compositor_.reset();
74 }
75
76 bool HasCompositor() const
77 {
78 return compositor_.get() != NULL;
79 }
80
81 void AcquireCompositor(ICompositor* compositor /* takes ownership */);
82
83 virtual void Paint(ICompositor& compositor,
84 ViewportController& controller) = 0;
85
86 virtual void UpdateSize(ICompositor& compositor) = 0;
87
88 /**
89 The second argument is temporary and should be deleted once the migration
90 to interactors is finished.
91 */
92 WebAssemblyViewport(const std::string& canvasId,
93 bool enableEmscriptenMouseEvents = true);
94
95 void PostConstructor();
96
97 public:
98 virtual ILock* Lock() ORTHANC_OVERRIDE;
99
100 ~WebAssemblyViewport();
101
102 virtual void UpdateCanvasSize();
103
104 /**
105 This method takes ownership
106 */
107 void AcquireInteractor(IViewportInteractor* interactor);
108
109 const std::string& GetCanvasId() const
110 {
111 return canvasId_;
112 }
113
114 /**
115 emscripten functions requires the css selector for the canvas. This is
116 different from the canvas id (the syntax is '#mycanvasid')
117 */
118 const std::string& GetCanvasCssSelector() const
119 {
120 return canvasCssSelector_;
121 }
122 };
123 }