Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestWorldSceneWidget.cpp @ 54:01aa453d4d5b wasm
IWidget::HasRenderMouseOver
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Apr 2017 17:49:29 +0200 |
parents | 25befef48c35 |
children | f0f354a97581 |
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 | |
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. | |
16 * | |
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 | |
24 #include <stdio.h> | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 namespace Samples | |
29 { | |
30 class TestWorldSceneWidget::Interactor : public IWorldSceneInteractor | |
31 { | |
32 public: | |
33 virtual IWorldSceneMouseTracker* CreateMouseTracker(WorldSceneWidget& widget, | |
34 const SliceGeometry& slice, | |
35 const ViewportGeometry& view, | |
36 MouseButton button, | |
37 double x, | |
38 double y, | |
39 IStatusBar* statusBar) | |
40 { | |
41 if (statusBar) | |
42 { | |
43 char buf[64]; | |
44 sprintf(buf, "X = %0.2f, Y = %0.2f", x, y); | |
45 statusBar->SetMessage(buf); | |
46 } | |
47 | |
48 return NULL; | |
49 } | |
50 | |
54
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
51 virtual bool HasMouseOver(const WorldSceneWidget& widget, |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
52 const SliceGeometry& slice, |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
53 double x, |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
54 double y) |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
55 { |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
56 return true; |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
57 } |
01aa453d4d5b
IWidget::HasRenderMouseOver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
58 |
0 | 59 virtual void MouseOver(CairoContext& context, |
60 WorldSceneWidget& widget, | |
61 const SliceGeometry& slice, | |
62 const ViewportGeometry& view, | |
63 double x, | |
64 double y, | |
65 IStatusBar* statusBar) | |
66 { | |
67 double S = 0.5; | |
68 | |
69 if (fabs(x) <= S && | |
70 fabs(y) <= S) | |
71 { | |
72 cairo_t* cr = context.GetObject(); | |
73 cairo_set_source_rgb(cr, 1, 0, 0); | |
74 cairo_rectangle(cr, -S, -S , 2.0 * S, 2.0 * S); | |
75 cairo_set_line_width(cr, 1.0 / view.GetZoom()); | |
76 cairo_stroke(cr); | |
77 } | |
78 } | |
79 | |
80 virtual void MouseWheel(WorldSceneWidget& widget, | |
81 MouseWheelDirection direction, | |
82 KeyboardModifiers modifiers, | |
83 IStatusBar* statusBar) | |
84 { | |
85 if (statusBar) | |
86 { | |
87 statusBar->SetMessage(direction == MouseWheelDirection_Down ? "Wheel down" : "Wheel up"); | |
88 } | |
89 } | |
90 | |
91 virtual void KeyPressed(WorldSceneWidget& widget, | |
92 char key, | |
93 KeyboardModifiers modifiers, | |
94 IStatusBar* statusBar) | |
95 { | |
96 if (statusBar) | |
97 { | |
98 statusBar->SetMessage("Key pressed: \"" + std::string(1, key) + "\""); | |
99 } | |
100 } | |
101 }; | |
102 | |
103 | |
104 bool TestWorldSceneWidget::RenderScene(CairoContext& context, | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
105 const ViewportGeometry& view) |
0 | 106 { |
107 cairo_t* cr = context.GetObject(); | |
108 | |
109 // Clear background | |
110 cairo_set_source_rgb(cr, 0, 0, 0); | |
111 cairo_paint(cr); | |
112 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
113 float color = static_cast<float>(count_ % 16) / 15.0f; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
114 cairo_set_source_rgb(cr, 0, 1.0f - color, color); |
0 | 115 cairo_rectangle(cr, -10, -.5, 20, 1); |
116 cairo_fill(cr); | |
117 | |
118 return true; | |
119 } | |
120 | |
121 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
122 TestWorldSceneWidget::TestWorldSceneWidget(bool animate) : |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
123 interactor_(new Interactor), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
124 animate_(animate), |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
125 count_(0) |
0 | 126 { |
127 SetInteractor(*interactor_); | |
128 } | |
129 | |
130 | |
131 void TestWorldSceneWidget::GetSceneExtent(double& x1, | |
132 double& y1, | |
133 double& x2, | |
134 double& y2) | |
135 { | |
136 x1 = -10; | |
137 x2 = 10; | |
138 y1 = -.5; | |
139 y2 = .5; | |
140 } | |
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 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
143 void TestWorldSceneWidget::UpdateContent() |
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 if (animate_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
146 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
147 count_++; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
148 NotifyChange(); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
149 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
150 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
151 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
152 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
153 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
154 } |
0 | 155 } |
156 } |