Mercurial > hg > orthanc-stone
annotate Samples/WebAssembly/BasicScene.cpp @ 616:97926984d5d0
WebAssembly sample using Scene2D
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2019 13:27:41 +0200 |
parents | |
children | 7efa2543699d |
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> |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #include <stdio.h> |
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 static const unsigned int FONT_SIZE = 32; |
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 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 void PrepareScene(OrthancStone::Scene2D& scene) |
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 using namespace OrthancStone; |
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 // Texture of 2x2 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); |
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 p[2] = 0; |
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 p[3] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 p[4] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 p[0] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 p[2] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 p[3] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 p[4] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 p[5] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 scene.SetLayer(12, new ColorTextureSceneLayer(i)); |
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 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 l->SetOrigin(-3, 2); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 l->SetPixelSpacing(1.5, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 l->SetAngle(20.0 / 180.0 * M_PI); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 scene.SetLayer(14, l.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
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 // Texture of 1x1 size |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 if (1) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); |
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 p[0] = 255; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 p[1] = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 p[2] = 0; |
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 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 l->SetOrigin(-2, 1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 l->SetAngle(20.0 / 180.0 * M_PI); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 scene.SetLayer(13, l.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 // Some lines |
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 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); |
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 layer->SetThickness(1); |
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 PolylineSceneLayer::Chain chain; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 layer->AddChain(chain, true); |
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 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 chain.push_back(ScenePoint2D(-5, -5)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 chain.push_back(ScenePoint2D(5, -5)); |
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 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 double dy = 1.01; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 chain.clear(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 chain.push_back(ScenePoint2D(-4, -4)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 chain.push_back(ScenePoint2D(4, -4 + dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 chain.push_back(ScenePoint2D(4, 2)); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 layer->AddChain(chain, false); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 layer->SetColor(0,255, 255); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 scene.SetLayer(50, layer.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 // Some text |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 if (1) |
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 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 layer->SetText("Hello"); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 scene.SetLayer(100, layer.release()); |
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 } |
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 class WebAssemblyCanvas : public boost::noncopyable |
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 private: |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 OrthancStone::OpenGL::WebAssemblyOpenGLContext context_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 OrthancStone::Scene2D scene_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 OrthancStone::OpenGLCompositor compositor_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 public: |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 WebAssemblyCanvas(const std::string& canvas) : |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 context_(canvas), |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 compositor_(context_, scene_) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 compositor_.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 FONT_SIZE, Orthanc::Encoding_Latin1); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 OrthancStone::Scene2D& GetScene() |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 return scene_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 void UpdateSize() |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 context_.UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 compositor_.UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 Refresh(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 void Refresh() |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 compositor_.Refresh(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 }; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 std::auto_ptr<WebAssemblyCanvas> canvas1_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 std::auto_ptr<WebAssemblyCanvas> canvas2_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 std::auto_ptr<WebAssemblyCanvas> canvas3_; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 EM_BOOL OnWindowResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 if (canvas1_.get() != NULL) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 canvas1_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 if (canvas2_.get() != NULL) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 canvas2_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 if (canvas3_.get() != NULL) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 canvas3_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 return true; |
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 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 EM_BOOL OnMouseClick(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 if (userData != NULL) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 WebAssemblyCanvas& canvas = *reinterpret_cast<WebAssemblyCanvas*>(userData); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 static unsigned int count = 0; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 char buf[64]; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 sprintf(buf, "click %d", count++); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 std::auto_ptr<OrthancStone::TextSceneLayer> layer(new OrthancStone::TextSceneLayer); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 layer->SetText(buf); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 canvas.GetScene().SetLayer(100, layer.release()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 canvas.Refresh(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 return true; |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 extern "C" |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 int main(int argc, char const *argv[]) |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 OrthancStone::StoneInitialize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded"));); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 EMSCRIPTEN_KEEPALIVE |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 void Initialize() |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 { |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 canvas1_.reset(new WebAssemblyCanvas("mycanvas1")); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 PrepareScene(canvas1_->GetScene()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 canvas1_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 canvas2_.reset(new WebAssemblyCanvas("mycanvas2")); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 PrepareScene(canvas2_->GetScene()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 canvas2_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 canvas3_.reset(new WebAssemblyCanvas("mycanvas3")); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 PrepareScene(canvas3_->GetScene()); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 canvas3_->UpdateSize(); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 emscripten_set_click_callback("mycanvas1", canvas1_.get(), false, OnMouseClick); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 emscripten_set_click_callback("mycanvas2", canvas2_.get(), false, OnMouseClick); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 emscripten_set_click_callback("mycanvas3", canvas3_.get(), false, OnMouseClick); |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 } |
97926984d5d0
WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 } |