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