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