Mercurial > hg > orthanc-stone
annotate Samples/WebAssembly/BasicScene.cpp @ 631:ea8322566596
notes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 May 2019 18:26:52 +0200 |
parents | 0925b27e8750 |
children | 419e5662d7a5 |
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" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "../../Framework/StoneInitialization.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "../../Framework/OpenGL/WebAssemblyOpenGLContext.h" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 // From Orthanc framework |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include <Core/Images/Image.h> |
617 | 40 #include <Core/Logging.h> |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
41 #include <Core/OrthancException.h> |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 #include <stdio.h> |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 static const unsigned int FONT_SIZE = 32; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
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 void PrepareScene(OrthancStone::Scene2D& scene) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 using namespace OrthancStone; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 // Texture of 2x2 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 if (1) |
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 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); |
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 p[2] = 0; |
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 p[3] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 p[4] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 p[0] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 p[2] = 255; |
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[3] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 p[4] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 scene.SetLayer(12, new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 l->SetOrigin(-3, 2); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 l->SetPixelSpacing(1.5, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 l->SetAngle(20.0 / 180.0 * M_PI); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 scene.SetLayer(14, l.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 // Texture of 1x1 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); |
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 p[2] = 0; |
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 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 l->SetOrigin(-2, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 l->SetAngle(20.0 / 180.0 * M_PI); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 scene.SetLayer(13, l.release()); |
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 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 // Some lines |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); |
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 layer->SetThickness(1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 PolylineSceneLayer::Chain chain; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 layer->AddChain(chain, true); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 chain.push_back(ScenePoint2D(-5, -5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 chain.push_back(ScenePoint2D(5, -5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 chain.push_back(ScenePoint2D(5, 5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 chain.push_back(ScenePoint2D(-5, 5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 layer->AddChain(chain, true); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 double dy = 1.01; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 chain.push_back(ScenePoint2D(-4, -4)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 chain.push_back(ScenePoint2D(4, -4 + dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 chain.push_back(ScenePoint2D(4, 2)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 layer->AddChain(chain, false); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 layer->SetColor(0,255, 255); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 scene.SetLayer(50, layer.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 // Some text |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 layer->SetText("Hello"); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 scene.SetLayer(100, layer.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 } |
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 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
617 | 144 namespace OrthancStone |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
146 class WebAssemblyViewport : public boost::noncopyable |
617 | 147 { |
148 private: | |
149 OpenGL::WebAssemblyOpenGLContext context_; | |
150 Scene2D scene_; | |
151 OpenGLCompositor compositor_; | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
617 | 153 void SetupEvents(const std::string& canvas); |
154 | |
155 public: | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
156 WebAssemblyViewport(const std::string& canvas) : |
617 | 157 context_(canvas), |
158 compositor_(context_, scene_) | |
159 { | |
160 compositor_.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, | |
161 FONT_SIZE, Orthanc::Encoding_Latin1); | |
162 SetupEvents(canvas); | |
163 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
617 | 165 Scene2D& GetScene() |
166 { | |
167 return scene_; | |
168 } | |
169 | |
170 void UpdateSize() | |
171 { | |
172 context_.UpdateSize(); | |
173 compositor_.UpdateSize(); | |
174 Refresh(); | |
175 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
617 | 177 void Refresh() |
178 { | |
179 compositor_.Refresh(); | |
180 } | |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
617 | 182 const std::string& GetCanvasIdentifier() const |
183 { | |
184 return context_.GetCanvasIdentifier(); | |
185 } | |
186 | |
187 ScenePoint2D GetPixelCenterCoordinates(int x, int y) const | |
188 { | |
189 return compositor_.GetPixelCenterCoordinates(x, y); | |
190 } | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
191 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
192 unsigned int GetCanvasWidth() const |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
193 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
194 return context_.GetCanvasWidth(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
195 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
196 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
197 unsigned int GetCanvasHeight() const |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
198 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
199 return context_.GetCanvasHeight(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
200 } |
617 | 201 }; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
617 | 205 class ActiveTracker : public boost::noncopyable |
206 { | |
207 private: | |
208 std::auto_ptr<IPointerTracker> tracker_; | |
209 std::string canvasIdentifier_; | |
210 bool insideCanvas_; | |
211 | |
212 public: | |
213 ActiveTracker(IPointerTracker* tracker, | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
214 const WebAssemblyViewport& viewport) : |
617 | 215 tracker_(tracker), |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
216 canvasIdentifier_(viewport.GetCanvasIdentifier()), |
617 | 217 insideCanvas_(true) |
218 { | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
219 if (tracker_.get() == NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
220 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
221 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
222 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
223 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
224 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
225 void Update(const PointerEvent& event) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
226 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
227 tracker_->Update(event); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
228 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
229 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
230 void Release() |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
231 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
232 tracker_->Release(); |
617 | 233 } |
234 }; | |
235 } | |
236 | |
237 | |
238 | |
239 static OrthancStone::PointerEvent* ConvertMouseEvent(const EmscriptenMouseEvent& source, | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
240 OrthancStone::WebAssemblyViewport& viewport) |
617 | 241 { |
242 std::auto_ptr<OrthancStone::PointerEvent> target(new OrthancStone::PointerEvent); | |
243 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
244 target->AddPosition(viewport.GetPixelCenterCoordinates(source.targetX, source.targetY)); |
617 | 245 target->SetAltModifier(source.altKey); |
246 target->SetControlModifier(source.ctrlKey); | |
247 target->SetShiftModifier(source.shiftKey); | |
248 | |
249 return target.release(); | |
250 } | |
251 | |
252 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
253 std::auto_ptr<OrthancStone::ActiveTracker> tracker_; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
254 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
255 |
617 | 256 EM_BOOL OnMouseEvent(int eventType, |
257 const EmscriptenMouseEvent *mouseEvent, | |
258 void *userData) | |
259 { | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
260 if (mouseEvent != NULL && |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
261 userData != NULL) |
617 | 262 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
263 OrthancStone::WebAssemblyViewport& viewport = |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
264 *reinterpret_cast<OrthancStone::WebAssemblyViewport*>(userData); |
617 | 265 |
266 switch (eventType) | |
267 { | |
268 case EMSCRIPTEN_EVENT_CLICK: | |
269 { | |
270 static unsigned int count = 0; | |
271 char buf[64]; | |
272 sprintf(buf, "click %d", count++); | |
273 | |
274 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer); | |
275 layer->SetText(buf); | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
276 viewport.GetScene().SetLayer(100, layer.release()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
277 viewport.Refresh(); |
617 | 278 break; |
279 } | |
280 | |
281 case EMSCRIPTEN_EVENT_MOUSEDOWN: | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
282 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
283 std::auto_ptr<OrthancStone::IPointerTracker> t; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
284 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
285 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
286 std::auto_ptr<OrthancStone::PointerEvent> event(ConvertMouseEvent(*mouseEvent, viewport)); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
287 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
288 switch (mouseEvent->button) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
289 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
290 case 0: // Left button |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
291 t.reset(new OrthancStone::RotateSceneTracker(viewport.GetScene(), *event)); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
292 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
293 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
294 case 1: // Middle button |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
295 t.reset(new OrthancStone::PanSceneTracker(viewport.GetScene(), *event)); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
296 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
297 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
298 case 2: // Right button |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
299 t.reset(new OrthancStone::ZoomSceneTracker |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
300 (viewport.GetScene(), *event, viewport.GetCanvasWidth())); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
301 break; |
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 default: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
304 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
305 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
306 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
307 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
308 if (t.get() != NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
309 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
310 tracker_.reset(new OrthancStone::ActiveTracker(t.release(), viewport)); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
311 viewport.Refresh(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
312 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
313 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
314 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
315 } |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
316 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
317 case EMSCRIPTEN_EVENT_MOUSEMOVE: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
318 if (tracker_.get() != NULL) |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
319 { |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
320 std::auto_ptr<OrthancStone::PointerEvent> event(ConvertMouseEvent(*mouseEvent, viewport)); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
321 tracker_->Update(*event); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
322 viewport.Refresh(); |
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 break; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
325 |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
326 case EMSCRIPTEN_EVENT_MOUSEUP: |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
327 if (tracker_.get() != NULL) |
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 tracker_->Release(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
330 viewport.Refresh(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
331 tracker_.reset(); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
332 } |
617 | 333 break; |
334 | |
335 default: | |
336 break; | |
337 } | |
338 } | |
339 | |
340 return true; | |
341 } | |
342 | |
343 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
344 void OrthancStone::WebAssemblyViewport::SetupEvents(const std::string& canvas) |
617 | 345 { |
631 | 346 if (0) |
347 { | |
348 emscripten_set_click_callback(canvas.c_str(), this, false, OnMouseEvent); | |
349 } | |
350 else | |
351 { | |
352 emscripten_set_mousedown_callback(canvas.c_str(), this, false, OnMouseEvent); | |
353 emscripten_set_mousemove_callback(canvas.c_str(), this, false, OnMouseEvent); | |
354 emscripten_set_mouseup_callback(canvas.c_str(), this, false, OnMouseEvent); | |
355 } | |
617 | 356 } |
357 | |
358 | |
359 | |
360 | |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
361 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport1_; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
362 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport2_; |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
363 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport3_; |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 EM_BOOL OnWindowResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
368 if (viewport1_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
370 viewport1_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
373 if (viewport2_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
375 viewport2_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
378 if (viewport3_.get() != NULL) |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 { |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
380 viewport3_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 return true; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 extern "C" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 int main(int argc, char const *argv[]) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 OrthancStone::StoneInitialize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded"));); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 EMSCRIPTEN_KEEPALIVE |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 void Initialize() |
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 viewport1_.reset(new OrthancStone::WebAssemblyViewport("mycanvas1")); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
400 PrepareScene(viewport1_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
401 viewport1_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
403 viewport2_.reset(new OrthancStone::WebAssemblyViewport("mycanvas2")); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
404 PrepareScene(viewport2_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
405 viewport2_->UpdateSize(); |
616
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 |
618
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
407 viewport3_.reset(new OrthancStone::WebAssemblyViewport("mycanvas3")); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
408 PrepareScene(viewport3_->GetScene()); |
0925b27e8750
mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
617
diff
changeset
|
409 viewport3_->UpdateSize(); |
616
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 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
412 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
413 } |