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