annotate Samples/WebAssembly/BasicScene.cpp @ 1307:8a28a9bf8876 broker

ViewportController now gets a ref to its parent viewport for proper lock usage
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Mar 2020 10:07:37 +0100
parents 2d8ab34c8c91
children 8a0a62189f46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
616
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
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
22 #include "dev.h"
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <emscripten.h>
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <emscripten/html5.h>
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 // From Stone
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../../Framework/StoneInitialization.h"
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 // From Orthanc framework
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <Core/Images/Image.h>
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
33 #include <Core/Logging.h>
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
34 #include <Core/OrthancException.h>
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
36 void PrepareScene(OrthancStone::Scene2D& scene)
616
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 using namespace OrthancStone;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 // Texture of 2x2 size
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (1)
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 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 p[0] = 255;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 p[1] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 p[2] = 0;
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 p[3] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 p[4] = 255;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 p[5] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 p[0] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 p[1] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 p[2] = 255;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 p[3] = 255;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 p[4] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 p[5] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
63 scene.SetLayer(12, new ColorTextureSceneLayer(i));
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 l->SetOrigin(-3, 2);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 l->SetPixelSpacing(1.5, 1);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 l->SetAngle(20.0 / 180.0 * M_PI);
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
69 scene.SetLayer(14, l.release());
616
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
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 // Texture of 1x1 size
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if (1)
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 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
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 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 p[0] = 255;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 p[1] = 0;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 p[2] = 0;
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(-2, 1);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 l->SetAngle(20.0 / 180.0 * M_PI);
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
85 scene.SetLayer(13, l.release());
616
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
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 // Some lines
892
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
89 if (1)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 layer->SetThickness(1);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 PolylineSceneLayer::Chain chain;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 756
diff changeset
100 layer->AddChain(chain, true, 255, 0, 0);
616
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 chain.clear();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 chain.push_back(ScenePoint2D(-5, -5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 chain.push_back(ScenePoint2D(5, -5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 chain.push_back(ScenePoint2D(5, 5));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 chain.push_back(ScenePoint2D(-5, 5));
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 756
diff changeset
107 layer->AddChain(chain, true, 0, 255, 0);
616
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 double dy = 1.01;
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 chain.clear();
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 chain.push_back(ScenePoint2D(-4, -4));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 chain.push_back(ScenePoint2D(4, -4 + dy));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 chain.push_back(ScenePoint2D(4, 2));
820
270c31978df1 BasicMPR sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 756
diff changeset
115 layer->AddChain(chain, false, 0, 0, 255);
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
117 scene.SetLayer(50, layer.release());
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
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 // Some text
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 if (1)
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 layer->SetText("Hello");
826
2de01660debe reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 820
diff changeset
125 scene.SetLayer(100, layer.release());
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
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
617
7efa2543699d simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
129
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
130 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport1_;
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
131 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport2_;
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
132 std::auto_ptr<OrthancStone::WebAssemblyViewport> viewport3_;
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
133 boost::shared_ptr<OrthancStone::ViewportController> controller1_;
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
134 boost::shared_ptr<OrthancStone::ViewportController> controller2_;
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
135 boost::shared_ptr<OrthancStone::ViewportController> controller3_;
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
136 OrthancStone::MessageBroker broker_;
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
137
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
752
6030db24eaea Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 665
diff changeset
139 EM_BOOL OnWindowResize(
6030db24eaea Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 665
diff changeset
140 int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
142 if (viewport1_.get() != NULL)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
144 viewport1_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
147 if (viewport2_.get() != NULL)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
149 viewport2_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
152 if (viewport3_.get() != NULL)
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
154 viewport3_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return true;
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
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 extern "C"
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 int main(int argc, char const *argv[])
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 OrthancStone::StoneInitialize();
752
6030db24eaea Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 665
diff changeset
165 // Orthanc::Logging::EnableInfoLevel(true);
6030db24eaea Fixed wasm sample (BasicScene) according to changes (ViewportController) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 665
diff changeset
166 // Orthanc::Logging::EnableTraceLevel(true);
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 EM_ASM(window.dispatchEvent(new CustomEvent("WebAssemblyLoaded")););
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
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 EMSCRIPTEN_KEEPALIVE
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 void Initialize()
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
173 viewport1_.reset(new OrthancStone::WebAssemblyViewport("mycanvas1"));
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
174 PrepareScene(viewport1_->GetScene());
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
175 viewport1_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
177 viewport2_.reset(new OrthancStone::WebAssemblyViewport("mycanvas2"));
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
178 PrepareScene(viewport2_->GetScene());
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
179 viewport2_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
181 viewport3_.reset(new OrthancStone::WebAssemblyViewport("mycanvas3"));
618
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
182 PrepareScene(viewport3_->GetScene());
0925b27e8750 mouse events in wasm sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 617
diff changeset
183 viewport3_->UpdateSize();
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
185 viewport1_->GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
186 FONT_SIZE, Orthanc::Encoding_Latin1);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
187 viewport2_->GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
188 FONT_SIZE, Orthanc::Encoding_Latin1);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
189 viewport3_->GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
190 FONT_SIZE, Orthanc::Encoding_Latin1);
892
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
191
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
192 controller1_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport1_));
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
193 controller2_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport2_));
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
194 controller3_.reset(new OrthancStone::ViewportController(boost::make_shared<OrthancStone::UndoStack>(), broker_, *viewport3_));
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
195
892
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
196 controller1_->FitContent(viewport1_->GetCanvasWidth(), viewport1_->GetCanvasHeight());
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
197 controller2_->FitContent(viewport2_->GetCanvasWidth(), viewport2_->GetCanvasHeight());
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
198 controller3_->FitContent(viewport3_->GetCanvasWidth(), viewport3_->GetCanvasHeight());
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
199
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
200 viewport1_->Refresh();
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
201 viewport2_->Refresh();
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
202 viewport3_->Refresh();
50cd372e2460 fix OpenGL context for fonts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 891
diff changeset
203
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
204 SetupEvents("mycanvas1", controller1_);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
205 SetupEvents("mycanvas2", controller2_);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
206 SetupEvents("mycanvas3", controller3_);
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 826
diff changeset
207
616
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize);
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
97926984d5d0 WebAssembly sample using Scene2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }