Mercurial > hg > orthanc-stone
annotate Samples/Sdl/TrackerSampleApp.cpp @ 731:ac4fe43551a1
merge am-dev -> default
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Tue, 21 May 2019 13:53:57 +0200 |
parents | 28b9e3a54200 |
children | 4d69256d2a46 284f37dc1c66 |
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 |
644 | 163 if (event.type == SDL_MOUSEMOTION) |
164 { | |
165 int scancodeCount = 0; | |
166 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | |
167 | |
168 if (activeTracker_.get() == NULL && | |
169 SDL_SCANCODE_LCTRL < scancodeCount && | |
170 keyboardState[SDL_SCANCODE_LCTRL]) | |
171 { | |
172 // The "left-ctrl" key is down, while no tracker is present | |
173 // Let's display the info text | |
174 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
|
175 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
|
176 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
|
177 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
178 DisplayFloatingCtrlInfoText(e); |
644 | 179 } |
180 else | |
181 { | |
182 HideInfoText(); | |
183 //LOG(TRACE) << "(event.type == SDL_MOUSEMOTION)"; | |
184 if (activeTracker_.get() != NULL) | |
185 { | |
186 //LOG(TRACE) << "(activeTracker_.get() != NULL)"; | |
187 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
|
188 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
|
189 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
|
190 |
644 | 191 //LOG(TRACE) << "event.button.x = " << event.button.x << " " << |
192 // "event.button.y = " << event.button.y; | |
193 //LOG(TRACE) << "activeTracker_->PointerMove(e); " << | |
194 // 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
|
195 |
644 | 196 activeTracker_->PointerMove(e); |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
197 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
198 activeTracker_.reset(); |
644 | 199 } |
200 } | |
201 } | |
202 else if (event.type == SDL_MOUSEBUTTONUP) | |
203 { | |
204 if (activeTracker_) | |
205 { | |
206 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
|
207 e.AddPosition(compositor_->GetPixelCenterCoordinates(event.button.x, event.button.y)); |
644 | 208 activeTracker_->PointerUp(e); |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
209 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
210 activeTracker_.reset(); |
644 | 211 } |
212 } | |
213 else if (event.type == SDL_MOUSEBUTTONDOWN) | |
214 { | |
215 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
|
216 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
|
217 event.button.x, event.button.y)); |
644 | 218 if (activeTracker_) |
219 { | |
220 activeTracker_->PointerDown(e); | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
221 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
222 activeTracker_.reset(); |
644 | 223 } |
224 else | |
225 { | |
226 // 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
|
227 activeTracker_ = CreateSuitableTracker(event, e); |
644 | 228 } |
229 } | |
230 else if (event.type == SDL_KEYDOWN && | |
231 event.key.repeat == 0 /* Ignore key bounce */) | |
232 { | |
233 switch (event.key.keysym.sym) | |
234 { | |
235 case SDLK_ESCAPE: | |
236 if (activeTracker_) | |
237 { | |
238 activeTracker_->Cancel(); | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
239 if (!activeTracker_->IsAlive()) |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
240 activeTracker_.reset(); |
644 | 241 } |
242 break; | |
243 | |
244 case SDLK_t: | |
245 if (!activeTracker_) | |
246 SelectNextTool(); | |
247 else | |
248 { | |
249 LOG(WARNING) << "You cannot change the active tool when an interaction" | |
250 " is taking place"; | |
251 } | |
252 break; | |
253 | |
254 case SDLK_s: | |
721
af0aa0c149fa
FitContent is now wrapped by the controller (for observability)
Benjamin Golinvaux <bgo@osimis.io>
parents:
706
diff
changeset
|
255 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
|
256 compositor_->GetCanvasHeight()); |
644 | 257 break; |
258 | |
259 case SDLK_c: | |
260 TakeScreenshot( | |
261 "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
|
262 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
|
263 compositor_->GetCanvasHeight()); |
644 | 264 break; |
265 | |
266 default: | |
267 break; | |
268 } | |
269 } | |
270 } | |
271 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
272 |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
273 void TrackerSampleApp::OnSceneTransformChanged( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
274 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
|
275 { |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
276 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
|
277 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
278 |
644 | 279 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker( |
280 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
|
281 const PointerEvent & e) |
644 | 282 { |
283 switch (event.button.button) | |
284 { | |
285 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
|
286 return FlexiblePointerTrackerPtr(new PanSceneTracker |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
287 (controller_, e)); |
644 | 288 |
289 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
|
290 return FlexiblePointerTrackerPtr(new ZoomSceneTracker |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
291 (controller_, e, compositor_->GetCanvasHeight())); |
644 | 292 |
293 case SDL_BUTTON_LEFT: | |
294 { | |
295 //LOG(TRACE) << "CreateSuitableTracker: case SDL_BUTTON_LEFT:"; | |
296 // TODO: we need to iterate on the set of measuring tool and perform | |
297 // a hit test to check if a tracker needs to be created for edition. | |
298 // Otherwise, depending upon the active tool, we might want to create | |
299 // a "measuring tool creation" tracker | |
300 | |
301 // TODO: if there are conflicts, we should prefer a tracker that | |
302 // pertains to the type of measuring tool currently selected (TBD?) | |
303 FlexiblePointerTrackerPtr hitTestTracker = TrackerHitTest(e); | |
304 | |
305 if (hitTestTracker != NULL) | |
306 { | |
307 //LOG(TRACE) << "hitTestTracker != NULL"; | |
308 return hitTestTracker; | |
309 } | |
310 else | |
311 { | |
312 switch (currentTool_) | |
313 { | |
314 case GuiTool_Rotate: | |
315 //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
|
316 return FlexiblePointerTrackerPtr(new RotateSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
317 controller_, e)); |
644 | 318 case GuiTool_Pan: |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
319 return FlexiblePointerTrackerPtr(new PanSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
320 controller_, e)); |
644 | 321 case GuiTool_Zoom: |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
322 return FlexiblePointerTrackerPtr(new ZoomSceneTracker( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
323 controller_, e, compositor_->GetCanvasHeight())); |
644 | 324 //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
|
325 // return new AngleMeasureTracker(GetScene(), e); |
644 | 326 //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
|
327 // return new CircleMeasureTracker(GetScene(), e); |
644 | 328 //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
|
329 // 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
|
330 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
|
331 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
|
332 IObserver::GetBroker(), controller_, e)); |
644 | 333 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
|
334 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
|
335 IObserver::GetBroker(), controller_, e)); |
644 | 336 case GuiTool_CircleMeasure: |
337 LOG(ERROR) << "Not implemented yet!"; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
338 return FlexiblePointerTrackerPtr(); |
644 | 339 case GuiTool_EllipseMeasure: |
340 LOG(ERROR) << "Not implemented yet!"; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
341 return FlexiblePointerTrackerPtr(); |
644 | 342 default: |
343 throw OrthancException(ErrorCode_InternalError, "Wrong tool!"); | |
344 } | |
345 } | |
346 } | |
347 default: | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
348 return FlexiblePointerTrackerPtr(); |
644 | 349 } |
350 } | |
351 | |
352 | |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
353 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
|
354 , 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
|
355 { |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
356 controller_ = ViewportControllerPtr(new ViewportController(broker)); |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
357 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
358 controller_->RegisterObserverCallback( |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
359 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
|
360 (*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
|
361 |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 } |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
370 |
644 | 371 void TrackerSampleApp::PrepareScene() |
372 { | |
373 // Texture of 2x2 size | |
374 { | |
375 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false); | |
376 | |
377 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
378 p[0] = 255; | |
379 p[1] = 0; | |
380 p[2] = 0; | |
381 | |
382 p[3] = 0; | |
383 p[4] = 255; | |
384 p[5] = 0; | |
385 | |
386 p = reinterpret_cast<uint8_t*>(i.GetRow(1)); | |
387 p[0] = 0; | |
388 p[1] = 0; | |
389 p[2] = 255; | |
390 | |
391 p[3] = 255; | |
392 p[4] = 0; | |
393 p[5] = 0; | |
394 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
395 GetScene()->SetLayer(TEXTURE_2x2_1_ZINDEX, new ColorTextureSceneLayer(i)); |
644 | 396 |
397 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
398 l->SetOrigin(-3, 2); | |
399 l->SetPixelSpacing(1.5, 1); | |
400 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
|
401 GetScene()->SetLayer(TEXTURE_2x2_2_ZINDEX, l.release()); |
644 | 402 } |
403 | |
404 // Texture of 1x1 size | |
405 { | |
406 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false); | |
407 | |
408 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0)); | |
409 p[0] = 255; | |
410 p[1] = 0; | |
411 p[2] = 0; | |
412 | |
413 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i)); | |
414 l->SetOrigin(-2, 1); | |
415 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
|
416 GetScene()->SetLayer(TEXTURE_1x1_ZINDEX, l.release()); |
644 | 417 } |
418 | |
419 // Some lines | |
420 { | |
421 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer); | |
422 | |
423 layer->SetThickness(1); | |
424 | |
425 PolylineSceneLayer::Chain chain; | |
426 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5)); | |
427 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5)); | |
428 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5)); | |
429 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5)); | |
430 layer->AddChain(chain, true); | |
431 | |
432 chain.clear(); | |
433 chain.push_back(ScenePoint2D(-5, -5)); | |
434 chain.push_back(ScenePoint2D(5, -5)); | |
435 chain.push_back(ScenePoint2D(5, 5)); | |
436 chain.push_back(ScenePoint2D(-5, 5)); | |
437 layer->AddChain(chain, true); | |
438 | |
439 double dy = 1.01; | |
440 chain.clear(); | |
441 chain.push_back(ScenePoint2D(-4, -4)); | |
442 chain.push_back(ScenePoint2D(4, -4 + dy)); | |
443 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy)); | |
444 chain.push_back(ScenePoint2D(4, 2)); | |
445 layer->AddChain(chain, false); | |
446 | |
447 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
|
448 GetScene()->SetLayer(LINESET_1_ZINDEX, layer.release()); |
644 | 449 } |
450 | |
451 // Some text | |
452 { | |
453 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer); | |
454 layer->SetText("Hello"); | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
455 GetScene()->SetLayer(LINESET_2_ZINDEX, layer.release()); |
644 | 456 } |
457 } | |
458 | |
459 | |
460 void TrackerSampleApp::DisableTracker() | |
461 { | |
462 if (activeTracker_) | |
463 { | |
464 activeTracker_->Cancel(); | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
465 activeTracker_.reset(); |
644 | 466 } |
467 } | |
468 | |
469 void TrackerSampleApp::TakeScreenshot(const std::string& target, | |
470 unsigned int canvasWidth, | |
471 unsigned int canvasHeight) | |
472 { | |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
473 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
|
474 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE_0, Orthanc::Encoding_Latin1); |
644 | 475 compositor.Refresh(); |
476 | |
477 Orthanc::ImageAccessor canvas; | |
478 compositor.GetCanvas().GetReadOnlyAccessor(canvas); | |
479 | |
480 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false); | |
481 Orthanc::ImageProcessing::Convert(png, canvas); | |
482 | |
483 Orthanc::PngWriter writer; | |
484 writer.WriteToFile(target, png); | |
485 } | |
486 | |
487 | |
488 FlexiblePointerTrackerPtr TrackerSampleApp::TrackerHitTest(const PointerEvent & e) | |
489 { | |
490 // std::vector<MeasureToolPtr> measureTools_; | |
706
ef07304d4423
Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents:
700
diff
changeset
|
491 return FlexiblePointerTrackerPtr(); |
644 | 492 } |
493 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
503 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
|
504 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
505 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
|
506 (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
|
507 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
|
508 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
509 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
510 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
511 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
|
512 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
513 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
|
514 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
515 // 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
|
516 // 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
|
517 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
|
518 |
721
af0aa0c149fa
FitContent is now wrapped by the controller (for observability)
Benjamin Golinvaux <bgo@osimis.io>
parents:
706
diff
changeset
|
519 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
|
520 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
521 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
|
522 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
|
523 |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
524 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
|
525 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 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
|
530 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
531 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
|
532 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
533 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
|
534 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
535 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
|
536 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
|
537 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
538 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
|
539 { |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
540 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
|
541 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
542 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
543 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
|
544 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
|
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 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
|
547 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
|
548 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
549 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
|
550 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
|
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 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
|
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 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
|
555 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
|
556 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
557 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
558 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
|
559 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
|
560 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
561 default: |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
562 break; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
563 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
564 } |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
565 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
|
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 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
|
568 } |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
569 |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
699
diff
changeset
|
570 // 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
|
571 // 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
|
572 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
|
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 |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
575 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
|
576 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
|
577 { |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
578 if (value == "") |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
579 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
|
580 else |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
581 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
|
582 DisplayInfoText(); |
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
583 } |
644 | 584 |
585 } |