Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Widgets/TestWorldSceneWidget.cpp @ 1290:7def6ab2929f bugs/2020-02-invisible-slice
Removal of debugging logs
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 21 Feb 2020 15:20:29 +0100 |
parents | 2d8ab34c8c91 |
children | 30deba7bc8e2 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
5 * Copyright (C) 2017-2020 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 | |
403 | 24 #include <Core/OrthancException.h> |
25 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
109
diff
changeset
|
26 #include <math.h> |
0 | 27 #include <stdio.h> |
28 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
29 namespace Deprecated |
0 | 30 { |
31 namespace Samples | |
32 { | |
33 class TestWorldSceneWidget::Interactor : public IWorldSceneInteractor | |
34 { | |
35 public: | |
36 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
37 const ViewportGeometry& view, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
38 OrthancStone::MouseButton button, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
39 OrthancStone::KeyboardModifiers modifiers, |
356
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
40 int viewportX, |
885f0a5eaa49
mouse tracker to set windowing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
327
diff
changeset
|
41 int viewportY, |
0 | 42 double x, |
43 double y, | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
439
diff
changeset
|
44 IStatusBar* statusBar, |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
439
diff
changeset
|
45 const std::vector<Touch>& touches) |
0 | 46 { |
47 if (statusBar) | |
48 { | |
49 char buf[64]; | |
50 sprintf(buf, "X = %0.2f, Y = %0.2f", x, y); | |
51 statusBar->SetMessage(buf); | |
52 } | |
53 | |
54 return NULL; | |
55 } | |
56 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
57 virtual void MouseOver(OrthancStone::CairoContext& context, |
0 | 58 WorldSceneWidget& widget, |
59 const ViewportGeometry& view, | |
60 double x, | |
61 double y, | |
62 IStatusBar* statusBar) | |
63 { | |
64 double S = 0.5; | |
65 | |
66 if (fabs(x) <= S && | |
67 fabs(y) <= S) | |
68 { | |
69 cairo_t* cr = context.GetObject(); | |
70 cairo_set_source_rgb(cr, 1, 0, 0); | |
71 cairo_rectangle(cr, -S, -S , 2.0 * S, 2.0 * S); | |
72 cairo_set_line_width(cr, 1.0 / view.GetZoom()); | |
73 cairo_stroke(cr); | |
74 } | |
75 } | |
76 | |
77 virtual void MouseWheel(WorldSceneWidget& widget, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
78 OrthancStone::MouseWheelDirection direction, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
79 OrthancStone::KeyboardModifiers modifiers, |
0 | 80 IStatusBar* statusBar) |
81 { | |
82 if (statusBar) | |
83 { | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
84 statusBar->SetMessage(direction == OrthancStone::MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); |
0 | 85 } |
86 } | |
87 | |
88 virtual void KeyPressed(WorldSceneWidget& widget, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
89 OrthancStone::KeyboardKeys key, |
327 | 90 char keyChar, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
91 OrthancStone::KeyboardModifiers modifiers, |
0 | 92 IStatusBar* statusBar) |
93 { | |
94 if (statusBar) | |
95 { | |
327 | 96 statusBar->SetMessage("Key pressed: \"" + std::string(1, keyChar) + "\""); |
0 | 97 } |
98 } | |
99 }; | |
100 | |
101 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
102 bool TestWorldSceneWidget::RenderScene(OrthancStone::CairoContext& context, |
327 | 103 const ViewportGeometry& view) |
0 | 104 { |
105 cairo_t* cr = context.GetObject(); | |
106 | |
107 // Clear background | |
108 cairo_set_source_rgb(cr, 0, 0, 0); | |
109 cairo_paint(cr); | |
110 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
111 float color = static_cast<float>(count_ % 16) / 15.0f; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
112 cairo_set_source_rgb(cr, 0, 1.0f - color, color); |
0 | 113 cairo_rectangle(cr, -10, -.5, 20, 1); |
114 cairo_fill(cr); | |
115 | |
116 return true; | |
117 } | |
118 | |
119 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
196
diff
changeset
|
120 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
|
121 WorldSceneWidget(name), |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
122 interactor_(new Interactor), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
123 animate_(animate), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
124 count_(0) |
0 | 125 { |
126 SetInteractor(*interactor_); | |
127 } | |
128 | |
129 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
130 OrthancStone::Extent2D TestWorldSceneWidget::GetSceneExtent() |
0 | 131 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
132 return OrthancStone::Extent2D(-10, -.5, 10, .5); |
0 | 133 } |
46
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 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
356
diff
changeset
|
136 void TestWorldSceneWidget::DoAnimation() |
0 | 137 { |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
138 if (animate_) |
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 count_++; |
278 | 141 NotifyContentChanged(); |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
142 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
143 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
144 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
146 } |
0 | 147 } |
148 } | |
149 } |