Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestWorldSceneWidget.cpp @ 386:e33659decec5
renamed UpdateContent() as DoAnimation()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Nov 2018 17:06:28 +0100 |
parents | 885f0a5eaa49 |
children | 99e31898910e |
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 | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
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. | |
327 | 16 * |
47 | 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, | |
281 | 37 KeyboardModifiers modifiers, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
38 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
39 int viewportY, |
0 | 40 double x, |
41 double y, | |
42 IStatusBar* statusBar) | |
43 { | |
44 if (statusBar) | |
45 { | |
46 char buf[64]; | |
47 sprintf(buf, "X = %0.2f, Y = %0.2f", x, y); | |
48 statusBar->SetMessage(buf); | |
49 } | |
50 | |
51 return NULL; | |
52 } | |
53 | |
54 virtual void MouseOver(CairoContext& context, | |
55 WorldSceneWidget& widget, | |
56 const ViewportGeometry& view, | |
57 double x, | |
58 double y, | |
59 IStatusBar* statusBar) | |
60 { | |
61 double S = 0.5; | |
62 | |
63 if (fabs(x) <= S && | |
64 fabs(y) <= S) | |
65 { | |
66 cairo_t* cr = context.GetObject(); | |
67 cairo_set_source_rgb(cr, 1, 0, 0); | |
68 cairo_rectangle(cr, -S, -S , 2.0 * S, 2.0 * S); | |
69 cairo_set_line_width(cr, 1.0 / view.GetZoom()); | |
70 cairo_stroke(cr); | |
71 } | |
72 } | |
73 | |
74 virtual void MouseWheel(WorldSceneWidget& widget, | |
75 MouseWheelDirection direction, | |
76 KeyboardModifiers modifiers, | |
77 IStatusBar* statusBar) | |
78 { | |
79 if (statusBar) | |
80 { | |
81 statusBar->SetMessage(direction == MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
82 } | |
83 } | |
84 | |
85 virtual void KeyPressed(WorldSceneWidget& widget, | |
327 | 86 KeyboardKeys key, |
87 char keyChar, | |
0 | 88 KeyboardModifiers modifiers, |
89 IStatusBar* statusBar) | |
90 { | |
91 if (statusBar) | |
92 { | |
327 | 93 statusBar->SetMessage("Key pressed: \"" + std::string(1, keyChar) + "\""); |
0 | 94 } |
95 } | |
96 }; | |
97 | |
98 | |
99 bool TestWorldSceneWidget::RenderScene(CairoContext& context, | |
327 | 100 const ViewportGeometry& view) |
0 | 101 { |
102 cairo_t* cr = context.GetObject(); | |
103 | |
104 // Clear background | |
105 cairo_set_source_rgb(cr, 0, 0, 0); | |
106 cairo_paint(cr); | |
107 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
108 float color = static_cast<float>(count_ % 16) / 15.0f; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
109 cairo_set_source_rgb(cr, 0, 1.0f - color, color); |
0 | 110 cairo_rectangle(cr, -10, -.5, 20, 1); |
111 cairo_fill(cr); | |
112 | |
113 return true; | |
114 } | |
115 | |
116 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
196
diff
changeset
|
117 TestWorldSceneWidget::TestWorldSceneWidget(const std::string& name, bool animate) : |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
196
diff
changeset
|
118 WorldSceneWidget(name), |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
119 interactor_(new Interactor), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
120 animate_(animate), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
121 count_(0) |
0 | 122 { |
123 SetInteractor(*interactor_); | |
124 } | |
125 | |
126 | |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
127 Extent2D TestWorldSceneWidget::GetSceneExtent() |
0 | 128 { |
111
7665ccbf33db
rename Extent as Extent2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
129 return Extent2D(-10, -.5, 10, .5); |
0 | 130 } |
46
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 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
133 void TestWorldSceneWidget::DoAnimation() |
0 | 134 { |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
135 if (animate_) |
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 count_++; |
278 | 138 NotifyContentChanged(); |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
139 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
140 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
141 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
143 } |
0 | 144 } |
145 } | |
146 } |