Mercurial > hg > orthanc-stone
annotate Framework/Widgets/TestWorldSceneWidget.cpp @ 109:53bd9277b025 wasm
using the Extent class
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Jun 2017 15:34:08 +0200 |
parents | d2adc6189a95 |
children | 53025eecbc95 |
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 | |
109
53bd9277b025
using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
121 Extent TestWorldSceneWidget::GetSceneExtent() |
0 | 122 { |
109
53bd9277b025
using the Extent class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
59
diff
changeset
|
123 return Extent(-10, -.5, 10, .5); |
0 | 124 } |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
125 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
126 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
127 void TestWorldSceneWidget::UpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
128 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
129 if (animate_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
130 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
131 count_++; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
132 NotifyChange(); |
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 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
135 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
137 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
138 } |
0 | 139 } |
140 } |