Mercurial > hg > orthanc-stone
annotate Samples/Sdl/TrackerSampleApp.cpp @ 753:a386bbc955dc
dummy
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 22 May 2019 16:01:34 +0200 |
parents | 284f37dc1c66 |
children | 92c400a09f1b |
rev | line source |
---|---|
644 | 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 #include "TrackerSampleApp.h" | |
22 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
23 #include <Framework/Scene2DViewport/CreateLineMeasureTracker.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
24 #include <Framework/Scene2DViewport/CreateAngleMeasureTracker.h> |
644 | 25 |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
26 #include <Framework/Scene2D/PanSceneTracker.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
27 #include <Framework/Scene2D/RotateSceneTracker.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
28 #include <Framework/Scene2D/Scene2D.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
29 #include <Framework/Scene2D/ZoomSceneTracker.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
30 #include <Framework/Scene2D/CairoCompositor.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
31 #include <Framework/Scene2D/ColorTextureSceneLayer.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
32 #include <Framework/Scene2D/OpenGLCompositor.h> |
644 | 33 |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
34 #include <Framework/StoneInitialization.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
35 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
36 #include <Applications/Sdl/SdlOpenGLWindow.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
37 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
38 // From Orthanc framework |
644 | 39 #include <Core/Logging.h> |
40 #include <Core/OrthancException.h> | |
41 #include <Core/Images/Image.h> | |
42 #include <Core/Images/ImageProcessing.h> | |
43 #include <Core/Images/PngWriter.h> | |
44 | |
45 #include <SDL.h> | |
46 #include <stdio.h> | |
47 | |
48 using namespace Orthanc; | |
49 | |
50 namespace OrthancStone | |
51 { | |
52 const char* MeasureToolToString(size_t i) | |
53 { | |
54 static const char* descs[] = { | |
55 "GuiTool_Rotate", | |
56 "GuiTool_Pan", | |
57 "GuiTool_Zoom", | |
58 "GuiTool_LineMeasure", | |
59 "GuiTool_CircleMeasure", | |
60 "GuiTool_AngleMeasure", | |
61 "GuiTool_EllipseMeasure", | |
62 "GuiTool_LAST" | |
63 }; | |
64 if (i >= GuiTool_LAST) | |
65 { | |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Wrong tool index"); | |
67 } | |
68 return descs[i]; | |
69 } | |
70 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
71 Scene2DPtr TrackerSampleApp::GetScene() |
644 | 72 { |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
73 return controller_->GetScene(); |
644 | 74 } |
75 | |
76 void TrackerSampleApp::SelectNextTool() | |
77 { | |
78 currentTool_ = static_cast<GuiTool>(currentTool_ + 1); | |
79 if (currentTool_ == GuiTool_LAST) | |
80 currentTool_ = static_cast<GuiTool>(0);; | |
81 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_)); | |
82 } | |
83 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
84 void TrackerSampleApp::DisplayInfoText() |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
85 { |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
86 // do not try to use stuff too early! |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
87 if (compositor_.get() == NULL) |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
88 return; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
89 |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
90 std::stringstream msg; |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
91 |
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
92 for (std::map<std::string, std::string>::const_iterator kv = infoTextMap_.begin(); |
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
93 kv != infoTextMap_.end(); ++kv) |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
94 { |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
95 msg << kv->first << " : " << kv->second << std::endl; |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
96 } |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
97 std::string msgS = msg.str(); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
98 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
99 TextSceneLayer* layerP = NULL; |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
100 if (GetScene()->HasLayer(FIXED_INFOTEXT_LAYER_ZINDEX)) |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
101 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
102 TextSceneLayer& layer = dynamic_cast<TextSceneLayer&>( |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
103 GetScene()->GetLayer(FIXED_INFOTEXT_LAYER_ZINDEX)); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
104 layerP = &layer; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
105 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
106 else |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
107 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
108 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
109 layerP = layer.get(); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
110 layer->SetColor(0, 255, 0); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
111 layer->SetFontIndex(1); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
112 layer->SetBorder(20); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
113 layer->SetAnchor(BitmapAnchor_TopLeft); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
114 //layer->SetPosition(0,0); |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
115 GetScene()->SetLayer(FIXED_INFOTEXT_LAYER_ZINDEX, layer.release()); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
116 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
117 // position the fixed info text in the upper right corner |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
118 layerP->SetText(msgS.c_str()); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
119 double cX = compositor_->GetCanvasWidth() * (-0.5); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
120 double cY = compositor_->GetCanvasHeight() * (-0.5); |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
121 GetScene()->GetCanvasToSceneTransform().Apply(cX,cY); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
122 layerP->SetPosition(cX, cY); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
123 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
124 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
125 void TrackerSampleApp::DisplayFloatingCtrlInfoText(const PointerEvent& e) |
644 | 126 { |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
127 ScenePoint2D p = e.GetMainPosition().Apply(GetScene()->GetCanvasToSceneTransform()); |
644 | 128 |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
129 char buf[128]; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
130 sprintf(buf, "S:(%0.02f,%0.02f) C:(%0.02f,%0.02f)", |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
131 p.GetX(), p.GetY(), |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
132 e.GetMainPosition().GetX(), e.GetMainPosition().GetY()); |
644 | 133 |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
134 if (GetScene()->HasLayer(FLOATING_INFOTEXT_LAYER_ZINDEX)) |
644 | 135 { |
136 TextSceneLayer& layer = | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
137 dynamic_cast<TextSceneLayer&>(GetScene()->GetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX)); |
644 | 138 layer.SetText(buf); |
139 layer.SetPosition(p.GetX(), p.GetY()); | |
140 } | |
141 else | |
142 { | |
143 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); | |
144 layer->SetColor(0, 255, 0); | |
145 layer->SetText(buf); | |
146 layer->SetBorder(20); | |
147 layer->SetAnchor(BitmapAnchor_BottomCenter); | |
148 layer->SetPosition(p.GetX(), p.GetY()); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
149 GetScene()->SetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX, layer.release()); |
644 | 150 } |
151 } | |
152 | |
153 void TrackerSampleApp::HideInfoText() | |
154 { | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
155 GetScene()->DeleteLayer(FLOATING_INFOTEXT_LAYER_ZINDEX); |
644 | 156 } |
157 | |
158 void TrackerSampleApp::HandleApplicationEvent( | |
159 const SDL_Event & event) | |
160 { | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
161 DisplayInfoText(); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
162 |
753 | 163 // we seed the random number generator for random measure tool |
164 // generation | |
165 srand(42); | |
166 | |
644 | 167 if (event.type == SDL_MOUSEMOTION) |
168 { | |
169 int scancodeCount = 0; | |
170 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | |
171 | |
172 if (activeTracker_.get() == NULL && | |
750 | 173 SDL_SCANCODE_LALT < scancodeCount && |
174 keyboardState[SDL_SCANCODE_LALT]) | |
644 | 175 { |
176 // The "left-ctrl" key is down, while no tracker is present | |
177 // Let's display the info text | |
178 PointerEvent e; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
179 e.AddPosition(compositor_->GetPixelCenterCoordinates( |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
180 event.button.x, event.button.y)); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
181 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
182 DisplayFloatingCtrlInfoText(e); |
644 | 183 } |
184 else | |
185 { | |
186 HideInfoText(); | |
187 //LOG(TRACE) << "(event.type == SDL_MOUSEMOTION)"; | |
188 if (activeTracker_.get() != NULL) | |
189 { | |
190 //LOG(TRACE) << "(activeTracker_.get() != NULL)"; | |
191 PointerEvent e; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
192 e.AddPosition(compositor_->GetPixelCenterCoordinates( |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
193 event.button.x, event.button.y)); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
194 |
644 | 195 //LOG(TRACE) << "event.button.x = " << event.button.x << " " << |
196 // "event.button.y = " << event.button.y; | |
197 //LOG(TRACE) << "activeTracker_->PointerMove(e); " << | |
198 // e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY(); | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
199 |
644 | 200 activeTracker_->PointerMove(e); |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
201 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
202 activeTracker_.reset(); |
644 | 203 } |
204 } | |
205 } | |
206 else if (event.type == SDL_MOUSEBUTTONUP) | |
207 { | |
208 if (activeTracker_) | |
209 { | |
210 PointerEvent e; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
211 e.AddPosition(compositor_->GetPixelCenterCoordinates(event.button.x, event.button.y)); |
644 | 212 activeTracker_->PointerUp(e); |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
213 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
214 activeTracker_.reset(); |
644 | 215 } |
216 } | |
217 else if (event.type == SDL_MOUSEBUTTONDOWN) | |
218 { | |
219 PointerEvent e; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
220 e.AddPosition(compositor_->GetPixelCenterCoordinates( |
651
62f6ff016085
Iteration in angle measuring tool. Text label is not ok and handles and arcs
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
221 event.button.x, event.button.y)); |
644 | 222 if (activeTracker_) |
223 { | |
224 activeTracker_->PointerDown(e); | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
225 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
226 activeTracker_.reset(); |
644 | 227 } |
228 else | |
229 { | |
230 // we ATTEMPT to create a tracker if need be | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
231 activeTracker_ = CreateSuitableTracker(event, e); |
644 | 232 } |
233 } | |
234 else if (event.type == SDL_KEYDOWN && | |
235 event.key.repeat == 0 /* Ignore key bounce */) | |
236 { | |
237 switch (event.key.keysym.sym) | |
238 { | |
239 case SDLK_ESCAPE: | |
240 if (activeTracker_) | |
241 { | |
242 activeTracker_->Cancel(); | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
243 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
244 activeTracker_.reset(); |
644 | 245 } |
246 break; | |
247 | |
248 case SDLK_t: | |
249 if (!activeTracker_) | |
250 SelectNextTool(); | |
251 else | |
252 { | |
253 LOG(WARNING) << "You cannot change the active tool when an interaction" | |
254 " is taking place"; | |
255 } | |
256 break; | |
257 | |
753 | 258 case SDLK_m: |
259 // let's create a random measuring tool | |
260 | |
261 | |
262 | |
644 | 263 case SDLK_s: |
721
af0aa0c149fa
FitContent is now wrapped by the controller (for observability)
Benjamin Golinvaux <bgo@osimis.io>
parents:
706
diff
changeset
|
264 controller_->FitContent(compositor_->GetCanvasWidth(), |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
265 compositor_->GetCanvasHeight()); |
644 | 266 break; |
267 | |
750 | 268 case SDLK_z: |
269 LOG(INFO) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; | |
270 if (event.key.keysym.mod & KMOD_CTRL) | |
271 { | |
272 if (controller_->CanUndo()) | |
273 { | |
274 LOG(INFO) << "Undoing..."; | |
275 controller_->Undo(); | |
276 } | |
277 else | |
278 { | |
279 LOG(WARNING) << "Nothing to undo!!!"; | |
280 } | |
281 } | |
282 break; | |
283 | |
284 case SDLK_y: | |
285 LOG(INFO) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; | |
286 if (event.key.keysym.mod & KMOD_CTRL) | |
287 { | |
288 if (controller_->CanRedo()) | |
289 { | |
290 LOG(INFO) << "Redoing..."; | |
291 controller_->Redo(); | |
292 } | |
293 else | |
294 { | |
295 LOG(WARNING) << "Nothing to redo!!!"; | |
296 } | |
297 } | |
298 break; | |
299 | |
644 | 300 case SDLK_c: |
301 TakeScreenshot( | |
302 "screenshot.png", | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
303 compositor_->GetCanvasWidth(), |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
304 compositor_->GetCanvasHeight()); |
644 | 305 break; |
306 | |
307 default: | |
308 break; | |
309 } | |
310 } | |
311 } | |
312 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
313 |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
314 void TrackerSampleApp::OnSceneTransformChanged( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
315 const ViewportController::SceneTransformChanged& message) |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
316 { |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
317 DisplayInfoText(); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
318 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
319 |
644 | 320 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker( |
321 const SDL_Event & event, | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
322 const PointerEvent & e) |
644 | 323 { |
324 switch (event.button.button) | |
325 { | |
326 case SDL_BUTTON_MIDDLE: | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
327 return FlexiblePointerTrackerPtr(new PanSceneTracker |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
328 (controller_, e)); |
644 | 329 |
330 case SDL_BUTTON_RIGHT: | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
331 return FlexiblePointerTrackerPtr(new ZoomSceneTracker |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
332 (controller_, e, compositor_->GetCanvasHeight())); |
644 | 333 |
334 case SDL_BUTTON_LEFT: | |
335 { | |
336 //LOG(TRACE) << "CreateSuitableTracker: case SDL_BUTTON_LEFT:"; | |
337 // TODO: we need to iterate on the set of measuring tool and perform | |
338 // a hit test to check if a tracker needs to be created for edition. | |
339 // Otherwise, depending upon the active tool, we might want to create | |
340 // a "measuring tool creation" tracker | |
341 | |
342 // TODO: if there are conflicts, we should prefer a tracker that | |
343 // pertains to the type of measuring tool currently selected (TBD?) | |
344 FlexiblePointerTrackerPtr hitTestTracker = TrackerHitTest(e); | |
345 | |
346 if (hitTestTracker != NULL) | |
347 { | |
348 //LOG(TRACE) << "hitTestTracker != NULL"; | |
349 return hitTestTracker; | |
350 } | |
351 else | |
352 { | |
353 switch (currentTool_) | |
354 { | |
355 case GuiTool_Rotate: | |
356 //LOG(TRACE) << "Creating RotateSceneTracker"; | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
357 return FlexiblePointerTrackerPtr(new RotateSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
358 controller_, e)); |
644 | 359 case GuiTool_Pan: |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
360 return FlexiblePointerTrackerPtr(new PanSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
361 controller_, e)); |
644 | 362 case GuiTool_Zoom: |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
363 return FlexiblePointerTrackerPtr(new ZoomSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
364 controller_, e, compositor_->GetCanvasHeight())); |
644 | 365 //case GuiTool_AngleMeasure: |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
721
diff
changeset
|
366 // return new AngleMeasureTracker(GetScene(), e); |
644 | 367 //case GuiTool_CircleMeasure: |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
721
diff
changeset
|
368 // return new CircleMeasureTracker(GetScene(), e); |
644 | 369 //case GuiTool_EllipseMeasure: |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
721
diff
changeset
|
370 // return new EllipseMeasureTracker(GetScene(), e); |
651
62f6ff016085
Iteration in angle measuring tool. Text label is not ok and handles and arcs
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
371 case GuiTool_LineMeasure: |
62f6ff016085
Iteration in angle measuring tool. Text label is not ok and handles and arcs
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
372 return FlexiblePointerTrackerPtr(new CreateLineMeasureTracker( |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
721
diff
changeset
|
373 IObserver::GetBroker(), controller_, e)); |
644 | 374 case GuiTool_AngleMeasure: |
651
62f6ff016085
Iteration in angle measuring tool. Text label is not ok and handles and arcs
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
375 return FlexiblePointerTrackerPtr(new CreateAngleMeasureTracker( |
722
28b9e3a54200
Undo mechanism implemented (not connected to UI yet). Undo stack and measuring
Benjamin Golinvaux <bgo@osimis.io>
parents:
721
diff
changeset
|
376 IObserver::GetBroker(), controller_, e)); |
644 | 377 case GuiTool_CircleMeasure: |
378 LOG(ERROR) << "Not implemented yet!"; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
379 return FlexiblePointerTrackerPtr(); |
644 | 380 case GuiTool_EllipseMeasure: |
381 LOG(ERROR) << "Not implemented yet!"; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
382 return FlexiblePointerTrackerPtr(); |
644 | 383 default: |
384 throw OrthancException(ErrorCode_InternalError, "Wrong tool!"); | |
385 } | |
386 } | |
387 } | |
388 default: | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
389 return FlexiblePointerTrackerPtr(); |
644 | 390 } |
391 } | |
392 | |
393 | |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
394 TrackerSampleApp::TrackerSampleApp(MessageBroker& broker) : IObserver(broker) |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
395 , currentTool_(GuiTool_Rotate) |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
396 { |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
397 controller_ = ViewportControllerPtr(new ViewportController(broker)); |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
398 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
399 controller_->RegisterObserverCallback( |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
400 new Callable<TrackerSampleApp, ViewportController::SceneTransformChanged> |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
401 (*this, &TrackerSampleApp::OnSceneTransformChanged)); |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
402 |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
403 TEXTURE_2x2_1_ZINDEX = 1; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
404 TEXTURE_1x1_ZINDEX = 2; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
405 TEXTURE_2x2_2_ZINDEX = 3; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
406 LINESET_1_ZINDEX = 4; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
407 LINESET_2_ZINDEX = 5; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
408 FLOATING_INFOTEXT_LAYER_ZINDEX = 6; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
409 FIXED_INFOTEXT_LAYER_ZINDEX = 7; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
410 } |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
411 |
644 | 412 void TrackerSampleApp::PrepareScene() |
413 { | |
414 // Texture of 2x2 size | |
415 { | |
416 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); | |
417 | |
418 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
419 p[0] = 255; | |
420 p[1] = 0; | |
421 p[2] = 0; | |
422 | |
423 p[3] = 0; | |
424 p[4] = 255; | |
425 p[5] = 0; | |
426 | |
427 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); | |
428 p[0] = 0; | |
429 p[1] = 0; | |
430 p[2] = 255; | |
431 | |
432 p[3] = 255; | |
433 p[4] = 0; | |
434 p[5] = 0; | |
435 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
436 GetScene()->SetLayer(TEXTURE_2x2_1_ZINDEX, new ColorTextureSceneLayer(i)); |
644 | 437 |
438 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
439 l->SetOrigin(-3, 2); | |
440 l->SetPixelSpacing(1.5, 1); | |
441 l->SetAngle(20.0 / 180.0 * M_PI); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
442 GetScene()->SetLayer(TEXTURE_2x2_2_ZINDEX, l.release()); |
644 | 443 } |
444 | |
445 // Texture of 1x1 size | |
446 { | |
447 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); | |
448 | |
449 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
450 p[0] = 255; | |
451 p[1] = 0; | |
452 p[2] = 0; | |
453 | |
454 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
455 l->SetOrigin(-2, 1); | |
456 l->SetAngle(20.0 / 180.0 * M_PI); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
457 GetScene()->SetLayer(TEXTURE_1x1_ZINDEX, l.release()); |
644 | 458 } |
459 | |
460 // Some lines | |
461 { | |
462 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); | |
463 | |
464 layer->SetThickness(1); | |
465 | |
466 PolylineSceneLayer::Chain chain; | |
467 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); | |
468 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); | |
469 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); | |
470 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); | |
471 layer->AddChain(chain, true); | |
472 | |
473 chain.clear(); | |
474 chain.push_back(ScenePoint2D(-5, -5)); | |
475 chain.push_back(ScenePoint2D(5, -5)); | |
476 chain.push_back(ScenePoint2D(5, 5)); | |
477 chain.push_back(ScenePoint2D(-5, 5)); | |
478 layer->AddChain(chain, true); | |
479 | |
480 double dy = 1.01; | |
481 chain.clear(); | |
482 chain.push_back(ScenePoint2D(-4, -4)); | |
483 chain.push_back(ScenePoint2D(4, -4 + dy)); | |
484 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); | |
485 chain.push_back(ScenePoint2D(4, 2)); | |
486 layer->AddChain(chain, false); | |
487 | |
488 layer->SetColor(0, 255, 255); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
489 GetScene()->SetLayer(LINESET_1_ZINDEX, layer.release()); |
644 | 490 } |
491 | |
492 // Some text | |
493 { | |
494 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); | |
495 layer->SetText("Hello"); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
496 GetScene()->SetLayer(LINESET_2_ZINDEX, layer.release()); |
644 | 497 } |
498 } | |
499 | |
500 | |
501 void TrackerSampleApp::DisableTracker() | |
502 { | |
503 if (activeTracker_) | |
504 { | |
505 activeTracker_->Cancel(); | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
506 activeTracker_.reset(); |
644 | 507 } |
508 } | |
509 | |
510 void TrackerSampleApp::TakeScreenshot(const std::string& target, | |
511 unsigned int canvasWidth, | |
512 unsigned int canvasHeight) | |
513 { | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
514 CairoCompositor compositor(*GetScene(), canvasWidth, canvasHeight); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
515 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE_0, Orthanc::Encoding_Latin1); |
644 | 516 compositor.Refresh(); |
517 | |
518 Orthanc::ImageAccessor canvas; | |
519 compositor.GetCanvas().GetReadOnlyAccessor(canvas); | |
520 | |
521 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false); | |
522 Orthanc::ImageProcessing::Convert(png, canvas); | |
523 | |
524 Orthanc::PngWriter writer; | |
525 writer.WriteToFile(target, png); | |
526 } | |
527 | |
528 | |
529 FlexiblePointerTrackerPtr TrackerSampleApp::TrackerHitTest(const PointerEvent & e) | |
530 { | |
531 // std::vector<MeasureToolPtr> measureTools_; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
532 return FlexiblePointerTrackerPtr(); |
644 | 533 } |
534 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
535 static void GLAPIENTRY |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
536 OpenGLMessageCallback(GLenum source, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
537 GLenum type, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
538 GLuint id, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
539 GLenum severity, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
540 GLsizei length, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
541 const GLchar* message, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
542 const void* userParam) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
543 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
544 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
545 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
546 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
547 (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
548 type, severity, message); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
549 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
550 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
551 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
552 static bool g_stopApplication = false; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
553 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
554 void TrackerSampleApp::Run() |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
555 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
556 // False means we do NOT let Windows treat this as a legacy application |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
557 // that needs to be scaled |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
558 SdlOpenGLWindow window("Hello", 1024, 1024, false); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
559 |
721
af0aa0c149fa
FitContent is now wrapped by the controller (for observability)
Benjamin Golinvaux <bgo@osimis.io>
parents:
706
diff
changeset
|
560 controller_->FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
561 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
562 glEnable(GL_DEBUG_OUTPUT); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
563 glDebugMessageCallback(OpenGLMessageCallback, 0); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
564 |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
565 compositor_.reset(new OpenGLCompositor(window, *GetScene())); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
566 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
567 compositor_->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
568 FONT_SIZE_0, Orthanc::Encoding_Latin1); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
569 compositor_->SetFont(1, Orthanc::EmbeddedResources::UBUNTU_FONT, |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
570 FONT_SIZE_1, Orthanc::Encoding_Latin1); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
571 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
572 while (!g_stopApplication) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
573 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
574 compositor_->Refresh(); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
575 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
576 SDL_Event event; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
577 while (!g_stopApplication && SDL_PollEvent(&event)) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
578 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
579 if (event.type == SDL_QUIT) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
580 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
581 g_stopApplication = true; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
582 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
583 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
584 else if (event.type == SDL_WINDOWEVENT && |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
585 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
586 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
587 DisableTracker(); // was: tracker.reset(NULL); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
588 compositor_->UpdateSize(); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
589 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
590 else if (event.type == SDL_KEYDOWN && |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
591 event.key.repeat == 0 /* Ignore key bounce */) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
592 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
593 switch (event.key.keysym.sym) |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
594 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
595 case SDLK_f: |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
596 window.GetWindow().ToggleMaximize(); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
597 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
598 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
599 case SDLK_q: |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
600 g_stopApplication = true; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
601 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
602 default: |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
603 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
604 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
605 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
606 HandleApplicationEvent(event); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
607 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
608 SDL_Delay(1); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
609 } |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
610 |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
611 // the following is paramount because the compositor holds a reference |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
612 // to the scene and we do not want this reference to become dangling |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
613 compositor_.reset(NULL); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
614 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
615 |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
616 void TrackerSampleApp::SetInfoDisplayMessage( |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
617 std::string key, std::string value) |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
618 { |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
619 if (value == "") |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
620 infoTextMap_.erase(key); |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
621 else |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
622 infoTextMap_[key] = value; |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
623 DisplayInfoText(); |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
624 } |
644 | 625 |
626 } |