Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Widgets/TestWorldSceneWidget.cpp @ 732:c35e98d22764
move Deprecated classes to a separate folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 14:27:35 +0200 |
parents | Framework/Widgets/TestWorldSceneWidget.cpp@4f2416d519b4 |
children | 2d8ab34c8c91 |
comparison
equal
deleted
inserted
replaced
729:529189f399ec | 732:c35e98d22764 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
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. | |
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 | |
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 | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "TestWorldSceneWidget.h" | |
23 | |
24 #include <Core/OrthancException.h> | |
25 | |
26 #include <math.h> | |
27 #include <stdio.h> | |
28 | |
29 namespace Deprecated | |
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 OrthancStone::MouseButton button, | |
39 OrthancStone::KeyboardModifiers modifiers, | |
40 int viewportX, | |
41 int viewportY, | |
42 double x, | |
43 double y, | |
44 IStatusBar* statusBar, | |
45 const std::vector<Touch>& touches) | |
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 | |
57 virtual void MouseOver(OrthancStone::CairoContext& context, | |
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, | |
78 OrthancStone::MouseWheelDirection direction, | |
79 OrthancStone::KeyboardModifiers modifiers, | |
80 IStatusBar* statusBar) | |
81 { | |
82 if (statusBar) | |
83 { | |
84 statusBar->SetMessage(direction == OrthancStone::MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
85 } | |
86 } | |
87 | |
88 virtual void KeyPressed(WorldSceneWidget& widget, | |
89 OrthancStone::KeyboardKeys key, | |
90 char keyChar, | |
91 OrthancStone::KeyboardModifiers modifiers, | |
92 IStatusBar* statusBar) | |
93 { | |
94 if (statusBar) | |
95 { | |
96 statusBar->SetMessage("Key pressed: \"" + std::string(1, keyChar) + "\""); | |
97 } | |
98 } | |
99 }; | |
100 | |
101 | |
102 bool TestWorldSceneWidget::RenderScene(OrthancStone::CairoContext& context, | |
103 const ViewportGeometry& view) | |
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 | |
111 float color = static_cast<float>(count_ % 16) / 15.0f; | |
112 cairo_set_source_rgb(cr, 0, 1.0f - color, color); | |
113 cairo_rectangle(cr, -10, -.5, 20, 1); | |
114 cairo_fill(cr); | |
115 | |
116 return true; | |
117 } | |
118 | |
119 | |
120 TestWorldSceneWidget::TestWorldSceneWidget(const std::string& name, bool animate) : | |
121 WorldSceneWidget(name), | |
122 interactor_(new Interactor), | |
123 animate_(animate), | |
124 count_(0) | |
125 { | |
126 SetInteractor(*interactor_); | |
127 } | |
128 | |
129 | |
130 OrthancStone::Extent2D TestWorldSceneWidget::GetSceneExtent() | |
131 { | |
132 return OrthancStone::Extent2D(-10, -.5, 10, .5); | |
133 } | |
134 | |
135 | |
136 void TestWorldSceneWidget::DoAnimation() | |
137 { | |
138 if (animate_) | |
139 { | |
140 count_++; | |
141 NotifyContentChanged(); | |
142 } | |
143 else | |
144 { | |
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
146 } | |
147 } | |
148 } | |
149 } |