Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestWorldSceneWidget.cpp @ 160:e9dae7e7bffc wasm
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Feb 2018 09:18:06 +0100 |
parents | e2fe9352f240 |
children | fccffbf99ba1 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
111
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "TestWorldSceneWidget.h" | |
23 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
24 #include <math.h> |
0 | 25 #include <stdio.h> |
26 | |
27 namespace OrthancStone | |
28 { | |
29 namespace Samples | |
30 { | |
31 class TestWorldSceneWidget::Interactor : public IWorldSceneInteractor | |
32 { | |
33 public: | |
34 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
35 const ViewportGeometry& view, | |
36 MouseButton button, | |
37 double x, | |
38 double y, | |
39 IStatusBar* statusBar) | |
40 { | |
41 if (statusBar) | |
42 { | |
43 char buf[64]; | |
44 sprintf(buf, "X = %0.2f, Y = %0.2f", x, y); | |
45 statusBar->SetMessage(buf); | |
46 } | |
47 | |
48 return NULL; | |
49 } | |
50 | |
51 virtual void MouseOver(CairoContext& context, | |
52 WorldSceneWidget& widget, | |
53 const ViewportGeometry& view, | |
54 double x, | |
55 double y, | |
56 IStatusBar* statusBar) | |
57 { | |
58 double S = 0.5; | |
59 | |
60 if (fabs(x) <= S && | |
61 fabs(y) <= S) | |
62 { | |
63 cairo_t* cr = context.GetObject(); | |
64 cairo_set_source_rgb(cr, 1, 0, 0); | |
65 cairo_rectangle(cr, -S, -S , 2.0 * S, 2.0 * S); | |
66 cairo_set_line_width(cr, 1.0 / view.GetZoom()); | |
67 cairo_stroke(cr); | |
68 } | |
69 } | |
70 | |
71 virtual void MouseWheel(WorldSceneWidget& widget, | |
72 MouseWheelDirection direction, | |
73 KeyboardModifiers modifiers, | |
74 IStatusBar* statusBar) | |
75 { | |
76 if (statusBar) | |
77 { | |
78 statusBar->SetMessage(direction == MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
79 } | |
80 } | |
81 | |
82 virtual void KeyPressed(WorldSceneWidget& widget, | |
83 char key, | |
84 KeyboardModifiers modifiers, | |
85 IStatusBar* statusBar) | |
86 { | |
87 if (statusBar) | |
88 { | |
89 statusBar->SetMessage("Key pressed: \"" + std::string(1, key) + "\""); | |
90 } | |
91 } | |
92 }; | |
93 | |
94 | |
95 bool TestWorldSceneWidget::RenderScene(CairoContext& context, | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
96 const ViewportGeometry& view) |
0 | 97 { |
98 cairo_t* cr = context.GetObject(); | |
99 | |
100 // Clear background | |
101 cairo_set_source_rgb(cr, 0, 0, 0); | |
102 cairo_paint(cr); | |
103 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
104 float color = static_cast<float>(count_ % 16) / 15.0f; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
105 cairo_set_source_rgb(cr, 0, 1.0f - color, color); |
0 | 106 cairo_rectangle(cr, -10, -.5, 20, 1); |
107 cairo_fill(cr); | |
108 | |
109 return true; | |
110 } | |
111 | |
112 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
113 TestWorldSceneWidget::TestWorldSceneWidget(bool animate) : |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
114 interactor_(new Interactor), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
115 animate_(animate), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
116 count_(0) |
0 | 117 { |
118 SetInteractor(*interactor_); | |
119 } | |
120 | |
121 | |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
122 Extent2D TestWorldSceneWidget::GetSceneExtent() |
0 | 123 { |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
124 return Extent2D(-10, -.5, 10, .5); |
0 | 125 } |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
126 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
127 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
128 void TestWorldSceneWidget::UpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
129 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
130 if (animate_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
131 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
132 count_++; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
133 NotifyChange(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
134 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
135 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
136 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
137 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
138 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
139 } |
0 | 140 } |
141 } |