Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestWorldSceneWidget.cpp @ 40:7207a407bcd8
shared copyright with osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Jan 2017 16:37:42 +0100 |
parents | 351ab0da0150 |
children | 766d31dc5716 28956ed68280 |
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 | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "TestWorldSceneWidget.h" | |
35 | |
36 #include <stdio.h> | |
37 | |
38 namespace OrthancStone | |
39 { | |
40 namespace Samples | |
41 { | |
42 class TestWorldSceneWidget::Interactor : public IWorldSceneInteractor | |
43 { | |
44 public: | |
45 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
46 const SliceGeometry& slice, | |
47 const ViewportGeometry& view, | |
48 MouseButton button, | |
49 double x, | |
50 double y, | |
51 IStatusBar* statusBar) | |
52 { | |
53 if (statusBar) | |
54 { | |
55 char buf[64]; | |
56 sprintf(buf, "X = %0.2f, Y = %0.2f", x, y); | |
57 statusBar->SetMessage(buf); | |
58 } | |
59 | |
60 return NULL; | |
61 } | |
62 | |
63 virtual void MouseOver(CairoContext& context, | |
64 WorldSceneWidget& widget, | |
65 const SliceGeometry& slice, | |
66 const ViewportGeometry& view, | |
67 double x, | |
68 double y, | |
69 IStatusBar* statusBar) | |
70 { | |
71 double S = 0.5; | |
72 | |
73 if (fabs(x) <= S && | |
74 fabs(y) <= S) | |
75 { | |
76 cairo_t* cr = context.GetObject(); | |
77 cairo_set_source_rgb(cr, 1, 0, 0); | |
78 cairo_rectangle(cr, -S, -S , 2.0 * S, 2.0 * S); | |
79 cairo_set_line_width(cr, 1.0 / view.GetZoom()); | |
80 cairo_stroke(cr); | |
81 } | |
82 } | |
83 | |
84 virtual void MouseWheel(WorldSceneWidget& widget, | |
85 MouseWheelDirection direction, | |
86 KeyboardModifiers modifiers, | |
87 IStatusBar* statusBar) | |
88 { | |
89 if (statusBar) | |
90 { | |
91 statusBar->SetMessage(direction == MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
92 } | |
93 } | |
94 | |
95 virtual void KeyPressed(WorldSceneWidget& widget, | |
96 char key, | |
97 KeyboardModifiers modifiers, | |
98 IStatusBar* statusBar) | |
99 { | |
100 if (statusBar) | |
101 { | |
102 statusBar->SetMessage("Key pressed: \"" + std::string(1, key) + "\""); | |
103 } | |
104 } | |
105 }; | |
106 | |
107 | |
108 bool TestWorldSceneWidget::RenderScene(CairoContext& context, | |
109 const ViewportGeometry& view) | |
110 { | |
111 cairo_t* cr = context.GetObject(); | |
112 | |
113 // Clear background | |
114 cairo_set_source_rgb(cr, 0, 0, 0); | |
115 cairo_paint(cr); | |
116 | |
117 cairo_set_source_rgb(cr, 0, 1, 0); | |
118 cairo_rectangle(cr, -10, -.5, 20, 1); | |
119 cairo_fill(cr); | |
120 | |
121 return true; | |
122 } | |
123 | |
124 | |
125 TestWorldSceneWidget::TestWorldSceneWidget() : | |
126 interactor_(new Interactor) | |
127 { | |
128 SetInteractor(*interactor_); | |
129 } | |
130 | |
131 | |
132 void TestWorldSceneWidget::GetSceneExtent(double& x1, | |
133 double& y1, | |
134 double& x2, | |
135 double& y2) | |
136 { | |
137 x1 = -10; | |
138 x2 = 10; | |
139 y1 = -.5; | |
140 y2 = .5; | |
141 } | |
142 } | |
143 } |