Mercurial > hg > orthanc-stone
annotate Samples/WebAssembly/BasicScene.cpp @ 752:6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
hg ignore update + dev env notes for bgo
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 22 May 2019 16:00:58 +0200 |
parents | 419e5662d7a5 |
children | 92c400a09f1b |
rev | line source |
---|---|
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include <emscripten.h> |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <emscripten/html5.h> |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 // From Stone |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "../../Applications/Sdl/SdlOpenGLWindow.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "../../Framework/Scene2D/CairoCompositor.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include "../../Framework/Scene2D/OpenGLCompositor.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 #include "../../Framework/Scene2D/PanSceneTracker.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 #include "../../Framework/Scene2D/RotateSceneTracker.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #include "../../Framework/Scene2D/Scene2D.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../../Framework/Scene2D/ZoomSceneTracker.h" |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
35 #include "../../Framework/Scene2DViewport/ViewportController.h" |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "../../Framework/StoneInitialization.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "../../Framework/OpenGL/WebAssemblyOpenGLContext.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 // From Orthanc framework |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include <Core/Images/Image.h> |
617 | 41 #include <Core/Logging.h> |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
42 #include <Core/OrthancException.h> |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
44 #include <boost/make_shared.hpp> |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
45 |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 #include <stdio.h> |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 static const unsigned int FONT_SIZE = 32; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
50 using boost::shared_ptr; |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
51 using boost::make_shared; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
53 void PrepareScene(OrthancStone::Scene2DPtr scene) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 using namespace OrthancStone; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 // Texture of 2x2 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 p[2] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 p[3] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 p[4] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 p[0] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 p[2] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 p[3] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 p[4] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
80 scene->SetLayer(12, new ColorTextureSceneLayer(i)); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 l->SetOrigin(-3, 2); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 l->SetPixelSpacing(1.5, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 l->SetAngle(20.0 / 180.0 * M_PI); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
86 scene->SetLayer(14, l.release()); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 // Texture of 1x1 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 p[2] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 l->SetOrigin(-2, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 l->SetAngle(20.0 / 180.0 * M_PI); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
102 scene->SetLayer(13, l.release()); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 // Some lines |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 layer->SetThickness(1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 PolylineSceneLayer::Chain chain; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 layer->AddChain(chain, true); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 chain.push_back(ScenePoint2D(-5, -5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 chain.push_back(ScenePoint2D(5, -5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 chain.push_back(ScenePoint2D(5, 5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 chain.push_back(ScenePoint2D(-5, 5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 layer->AddChain(chain, true); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 double dy = 1.01; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 chain.push_back(ScenePoint2D(-4, -4)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 chain.push_back(ScenePoint2D(4, -4 + dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 chain.push_back(ScenePoint2D(4, 2)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 layer->AddChain(chain, false); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 layer->SetColor(0,255, 255); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
134 scene->SetLayer(50, layer.release()); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 // Some text |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 layer->SetText("Hello"); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
142 scene->SetLayer(100, layer.release()); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
617 | 146 namespace OrthancStone |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
148 class WebAssemblyViewport : public boost::noncopyable |
617 | 149 { |
150 private: | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
151 // the construction order is important because compositor_ |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
152 // will hold a reference to the scene that belong to the |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
153 // controller_ object |
617 | 154 OpenGL::WebAssemblyOpenGLContext context_; |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
155 ViewportControllerPtr controller_; |
617 | 156 OpenGLCompositor compositor_; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
617 | 158 void SetupEvents(const std::string& canvas); |
159 | |
160 public: | |
665 | 161 WebAssemblyViewport(MessageBroker& broker, |
162 const std::string& canvas) : | |
617 | 163 context_(canvas), |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
164 controller_(make_shared<ViewportController>(broker)), |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
165 compositor_(context_, *controller_->GetScene()) |
617 | 166 { |
167 compositor_.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | |
168 FONT_SIZE, Orthanc::Encoding_Latin1); | |
169 SetupEvents(canvas); | |
170 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
172 Scene2DPtr GetScene() |
617 | 173 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
174 return controller_->GetScene(); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
175 } |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
176 |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
177 ViewportControllerPtr GetController() |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
178 { |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
179 return controller_; |
617 | 180 } |
181 | |
182 void UpdateSize() | |
183 { | |
184 context_.UpdateSize(); | |
185 compositor_.UpdateSize(); | |
186 Refresh(); | |
187 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
617 | 189 void Refresh() |
190 { | |
191 compositor_.Refresh(); | |
192 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
617 | 194 const std::string& GetCanvasIdentifier() const |
195 { | |
196 return context_.GetCanvasIdentifier(); | |
197 } | |
198 | |
199 ScenePoint2D GetPixelCenterCoordinates(int x, int y) const | |
200 { | |
201 return compositor_.GetPixelCenterCoordinates(x, y); | |
202 } | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
203 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
204 unsigned int GetCanvasWidth() const |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
205 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
206 return context_.GetCanvasWidth(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
207 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
208 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
209 unsigned int GetCanvasHeight() const |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
210 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
211 return context_.GetCanvasHeight(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
212 } |
617 | 213 }; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
617 | 215 class ActiveTracker : public boost::noncopyable |
216 { | |
217 private: | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
218 OrthancStone::FlexiblePointerTrackerPtr tracker_; |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
219 std::string canvasIdentifier_; |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
220 bool insideCanvas_; |
617 | 221 |
222 public: | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
223 ActiveTracker(FlexiblePointerTrackerPtr tracker, |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
224 const WebAssemblyViewport& viewport) : |
617 | 225 tracker_(tracker), |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
226 canvasIdentifier_(viewport.GetCanvasIdentifier()), |
617 | 227 insideCanvas_(true) |
228 { | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
229 if (tracker_.get() == NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
230 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
231 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
232 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
233 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
234 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
235 bool IsAlive() const |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
236 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
237 return tracker_->IsAlive(); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
238 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
239 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
240 void PointerMove(const PointerEvent& event) |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
241 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
242 tracker_->PointerMove(event); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
243 } |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
244 |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
245 void PointerUp(const PointerEvent& event) |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
246 { |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
247 tracker_->PointerUp(event); |
617 | 248 } |
249 }; | |
250 } | |
251 | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
252 static OrthancStone::PointerEvent* ConvertMouseEvent( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
253 const EmscriptenMouseEvent& source, |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
254 OrthancStone::WebAssemblyViewport& viewport) |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
255 { |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
256 std::auto_ptr<OrthancStone::PointerEvent> target( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
257 new OrthancStone::PointerEvent); |
617 | 258 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
259 target->AddPosition(viewport.GetPixelCenterCoordinates( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
260 source.targetX, source.targetY)); |
617 | 261 target->SetAltModifier(source.altKey); |
262 target->SetControlModifier(source.ctrlKey); | |
263 target->SetShiftModifier(source.shiftKey); | |
264 | |
265 return target.release(); | |
266 } | |
267 | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
268 std::auto_ptr<OrthancStone::ActiveTracker> tracker_; |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
269 |
617 | 270 EM_BOOL OnMouseEvent(int eventType, |
271 const EmscriptenMouseEvent *mouseEvent, | |
272 void *userData) | |
273 { | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
274 if (mouseEvent != NULL && |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
275 userData != NULL) |
617 | 276 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
277 OrthancStone::WebAssemblyViewport& viewport = |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
278 *reinterpret_cast<OrthancStone::WebAssemblyViewport*>(userData); |
617 | 279 |
280 switch (eventType) | |
281 { | |
282 case EMSCRIPTEN_EVENT_CLICK: | |
283 { | |
284 static unsigned int count = 0; | |
285 char buf[64]; | |
286 sprintf(buf, "click %d", count++); | |
287 | |
288 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer); | |
289 layer->SetText(buf); | |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
290 viewport.GetScene()->SetLayer(100, layer.release()); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
291 viewport.Refresh(); |
617 | 292 break; |
293 } | |
294 | |
295 case EMSCRIPTEN_EVENT_MOUSEDOWN: | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
296 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
297 OrthancStone::FlexiblePointerTrackerPtr t; |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
298 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
299 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
300 std::auto_ptr<OrthancStone::PointerEvent> event( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
301 ConvertMouseEvent(*mouseEvent, viewport)); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
302 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
303 switch (mouseEvent->button) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
304 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
305 case 0: // Left button |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
306 emscripten_console_log("Creating RotateSceneTracker"); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
307 t.reset(new OrthancStone::RotateSceneTracker( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
308 viewport.GetController(), *event)); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
309 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
310 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
311 case 1: // Middle button |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
312 emscripten_console_log("Creating PanSceneTracker"); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
313 LOG(INFO) << "Creating PanSceneTracker" ; |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
314 t.reset(new OrthancStone::PanSceneTracker( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
315 viewport.GetController(), *event)); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
316 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
317 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
318 case 2: // Right button |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
319 emscripten_console_log("Creating ZoomSceneTracker"); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
320 t.reset(new OrthancStone::ZoomSceneTracker( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
321 viewport.GetController(), *event, viewport.GetCanvasWidth())); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
322 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
323 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
324 default: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
325 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
326 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
327 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
328 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
329 if (t.get() != NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
330 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
331 tracker_.reset( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
332 new OrthancStone::ActiveTracker(t, viewport)); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
333 viewport.Refresh(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
334 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
335 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
336 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
337 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
338 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
339 case EMSCRIPTEN_EVENT_MOUSEMOVE: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
340 if (tracker_.get() != NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
341 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
342 std::auto_ptr<OrthancStone::PointerEvent> event( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
343 ConvertMouseEvent(*mouseEvent, viewport)); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
344 tracker_->PointerMove(*event); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
345 viewport.Refresh(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
346 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
347 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
348 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
349 case EMSCRIPTEN_EVENT_MOUSEUP: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
350 if (tracker_.get() != NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
351 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
352 std::auto_ptr<OrthancStone::PointerEvent> event( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
353 ConvertMouseEvent(*mouseEvent, viewport)); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
354 tracker_->PointerUp(*event); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
355 viewport.Refresh(); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
356 if (!tracker_->IsAlive()) |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
357 tracker_.reset(); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
358 } |
617 | 359 break; |
360 | |
361 default: | |
362 break; | |
363 } | |
364 } | |
365 | |
366 return true; | |
367 } | |
368 | |
369 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
370 void OrthancStone::WebAssemblyViewport::SetupEvents(const std::string& canvas) |
617 | 371 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
372 #if 0 |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
373 emscripten_set_click_callback(canvas.c_str(), this, false, OnMouseEvent); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
374 #else |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
375 emscripten_set_mousedown_callback(canvas.c_str(), this, false, OnMouseEvent); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
376 emscripten_set_mousemove_callback(canvas.c_str(), this, false, OnMouseEvent); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
377 emscripten_set_mouseup_callback(canvas.c_str(), this, false, OnMouseEvent); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
378 #endif |
617 | 379 } |
380 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
381 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport1_; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
382 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport2_; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
383 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport3_; |
665 | 384 OrthancStone::MessageBroker broker_; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
386 EM_BOOL OnWindowResize( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
387 int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
389 if (viewport1_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
391 viewport1_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
394 if (viewport2_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
396 viewport2_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
399 if (viewport3_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
401 viewport3_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 return true; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 extern "C" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 int main(int argc, char const *argv[]) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 OrthancStone::StoneInitialize(); |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
412 // Orthanc::Logging::EnableInfoLevel(true); |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
413 // Orthanc::Logging::EnableTraceLevel(true); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
414 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded"));); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 EMSCRIPTEN_KEEPALIVE |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 void Initialize() |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 { |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
420 viewport1_.reset( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
421 new OrthancStone::WebAssemblyViewport(broker_, "mycanvas1")); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
422 PrepareScene(viewport1_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
423 viewport1_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
425 viewport2_.reset( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
426 new OrthancStone::WebAssemblyViewport(broker_, "mycanvas2")); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
427 PrepareScene(viewport2_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
428 viewport2_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 |
752
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
430 viewport3_.reset( |
6030db24eaea
Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
665
diff
changeset
|
431 new OrthancStone::WebAssemblyViewport(broker_, "mycanvas3")); |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
432 PrepareScene(viewport3_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
433 viewport3_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
435 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 } |