annotate Samples/Sdl/TrackerSampleApp.cpp @ 656:002d9562c8f5

Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this might also be needed on macos and GNU/Linux ?) + fixed text info overlay pos for angle measure (this requires the app to be aware of the compositor)
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 14 May 2019 16:54:13 +0200
parents 462a5074f914
children cb3b76d16234
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21 #include "TrackerSampleApp.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23 #include "../Common/CreateLineMeasureTracker.h"
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
24 #include "../Common/CreateAngleMeasureTracker.h"
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26 #include "../../Applications/Sdl/SdlOpenGLWindow.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28 #include "../../Framework/Scene2D/PanSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29 #include "../../Framework/Scene2D/RotateSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 #include "../../Framework/Scene2D/Scene2D.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 #include "../../Framework/Scene2D/CairoCompositor.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34 #include "../../Framework/Scene2D/OpenGLCompositor.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 #include "../../Framework/StoneInitialization.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 // From Orthanc framework
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 #include <Core/Logging.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 #include <Core/OrthancException.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 #include <Core/Images/Image.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 #include <Core/Images/ImageProcessing.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 #include <Core/Images/PngWriter.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 #include <SDL.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 #include <stdio.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 using namespace Orthanc;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 namespace OrthancStone
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 const char* MeasureToolToString(size_t i)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 static const char* descs[] = {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 "GuiTool_Rotate",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 "GuiTool_Pan",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 "GuiTool_Zoom",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 "GuiTool_LineMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 "GuiTool_CircleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 "GuiTool_AngleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 "GuiTool_EllipseMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 "GuiTool_LAST"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 };
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 if (i >= GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Wrong tool index");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 return descs[i];
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 Scene2D& TrackerSampleApp::GetScene()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 return scene_;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 void TrackerSampleApp::SelectNextTool()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 currentTool_ = static_cast<GuiTool>(currentTool_ + 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 if (currentTool_ == GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 currentTool_ = static_cast<GuiTool>(0);;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
83 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
84 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
85 char buf[256];
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
86 sprintf(buf, "INFO TEXT\n*** INFO TEXT ***\ntoto tata tutu titi\nprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrout");
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
87
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
88 TextSceneLayer* layerP = NULL;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
89 if (scene_.HasLayer(FIXED_INFOTEXT_LAYER_ZINDEX))
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
90 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
91 TextSceneLayer& layer = dynamic_cast<TextSceneLayer&>(
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
92 scene_.GetLayer(FIXED_INFOTEXT_LAYER_ZINDEX));
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
93 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
94 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
95 else
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
96 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
97 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
98 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
99 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
100 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
101 layer->SetText(buf);
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
102 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
103 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
104 //layer->SetPosition(0,0);
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
105 scene_.SetLayer(FIXED_INFOTEXT_LAYER_ZINDEX, layer.release());
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
106 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
107 // position the fixed info text in the upper right corner
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
108 layerP->SetText(buf);
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
109 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
110 double cY = compositor_->GetCanvasHeight() * (-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
111 scene_.GetCanvasToSceneTransform().Apply(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
112 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
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
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
115 void TrackerSampleApp::DisplayFloatingCtrlInfoText(const PointerEvent& e)
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 ScenePoint2D p = e.GetMainPosition().Apply(scene_.GetCanvasToSceneTransform());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118
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 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
120 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
121 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
122 e.GetMainPosition().GetX(), e.GetMainPosition().GetY());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
124 if (scene_.HasLayer(FLOATING_INFOTEXT_LAYER_ZINDEX))
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 TextSceneLayer& layer =
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
127 dynamic_cast<TextSceneLayer&>(scene_.GetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 layer.SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 layer.SetPosition(p.GetX(), p.GetY());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 layer->SetColor(0, 255, 0);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 layer->SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 layer->SetBorder(20);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 layer->SetAnchor(BitmapAnchor_BottomCenter);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138 layer->SetPosition(p.GetX(), p.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
139 scene_.SetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX, layer.release());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 void TrackerSampleApp::HideInfoText()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 {
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
145 scene_.DeleteLayer(FLOATING_INFOTEXT_LAYER_ZINDEX);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 void TrackerSampleApp::HandleApplicationEvent(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 const SDL_Event & event)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 {
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
151 DisplayInfoText();
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
152
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153 if (event.type == SDL_MOUSEMOTION)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 int scancodeCount = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 if (activeTracker_.get() == NULL &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 SDL_SCANCODE_LCTRL < scancodeCount &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 keyboardState[SDL_SCANCODE_LCTRL])
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 // The "left-ctrl" key is down, while no tracker is present
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 // Let's display the info text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 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
165 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
166 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
167
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
168 DisplayFloatingCtrlInfoText(e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
171 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 HideInfoText();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 //LOG(TRACE) << "(event.type == SDL_MOUSEMOTION)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 if (activeTracker_.get() != NULL)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 //LOG(TRACE) << "(activeTracker_.get() != NULL)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
177 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
178 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
179 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
180
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181 //LOG(TRACE) << "event.button.x = " << event.button.x << " " <<
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182 // "event.button.y = " << event.button.y;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183 //LOG(TRACE) << "activeTracker_->PointerMove(e); " <<
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 // 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
185
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 activeTracker_->PointerMove(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
192 else if (event.type == SDL_MOUSEBUTTONUP)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196 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
197 e.AddPosition(compositor_->GetPixelCenterCoordinates(event.button.x, event.button.y));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 activeTracker_->PointerUp(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203 else if (event.type == SDL_MOUSEBUTTONDOWN)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 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
206 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
207 event.button.x, event.button.y));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 activeTracker_->PointerDown(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
213 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 // 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
217 activeTracker_ = CreateSuitableTracker(event, e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 else if (event.type == SDL_KEYDOWN &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 event.key.repeat == 0 /* Ignore key bounce */)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 switch (event.key.keysym.sym)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 case SDLK_ESCAPE:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
227 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 activeTracker_->Cancel();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 case SDLK_t:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 if (!activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 SelectNextTool();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 LOG(WARNING) << "You cannot change the active tool when an interaction"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 " is taking place";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 case SDLK_s:
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
245 scene_.FitContent(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
246 compositor_->GetCanvasHeight());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 case SDLK_c:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 TakeScreenshot(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 "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
252 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
253 compositor_->GetCanvasHeight());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261
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
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
263 void TrackerSampleApp::OnSceneTransformChanged(const Scene2D::SceneTransformChanged& message)
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
264 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
265 // do not try to call this too early!
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
266 if(compositor_.get() != NULL)
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
267 DisplayInfoText();
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
268 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
269
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 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
272 const PointerEvent & e)
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 switch (event.button.button)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276 case SDL_BUTTON_MIDDLE:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 new PanSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
279
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280 case SDL_BUTTON_RIGHT:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
281 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
282 new ZoomSceneTracker(scene_, e, compositor_->GetCanvasHeight())));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
283
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 case SDL_BUTTON_LEFT:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 //LOG(TRACE) << "CreateSuitableTracker: case SDL_BUTTON_LEFT:";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
287 // TODO: we need to iterate on the set of measuring tool and perform
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
288 // a hit test to check if a tracker needs to be created for edition.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 // Otherwise, depending upon the active tool, we might want to create
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 // a "measuring tool creation" tracker
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
292 // TODO: if there are conflicts, we should prefer a tracker that
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293 // pertains to the type of measuring tool currently selected (TBD?)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 FlexiblePointerTrackerPtr hitTestTracker = TrackerHitTest(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
295
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
296 if (hitTestTracker != NULL)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
297 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
298 //LOG(TRACE) << "hitTestTracker != NULL";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
299 return hitTestTracker;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
300 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
301 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
302 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 switch (currentTool_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
304 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
305 case GuiTool_Rotate:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
306 //LOG(TRACE) << "Creating RotateSceneTracker";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
307 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
308 new RotateSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
309 case GuiTool_Pan:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
310 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
311 new PanSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
312 case GuiTool_Zoom:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
313 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
314 new ZoomSceneTracker(scene_, e, compositor_->GetCanvasHeight())));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
315 //case GuiTool_AngleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
316 // return new AngleMeasureTracker(scene_, measureTools_, undoStack_, e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
317 //case GuiTool_CircleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
318 // return new CircleMeasureTracker(scene_, measureTools_, undoStack_, e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
319 //case GuiTool_EllipseMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
320 // return new EllipseMeasureTracker(scene_, measureTools_, undoStack_, 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
321 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
322 return FlexiblePointerTrackerPtr(new CreateLineMeasureTracker(
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 651
diff changeset
323 IObserver::GetBroker(), scene_, undoStack_, measureTools_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324 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
325 return FlexiblePointerTrackerPtr(new CreateAngleMeasureTracker(
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 651
diff changeset
326 IObserver::GetBroker(), scene_, undoStack_, measureTools_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
327 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
328 case GuiTool_CircleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
329 LOG(ERROR) << "Not implemented yet!";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
331 case GuiTool_EllipseMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
332 LOG(ERROR) << "Not implemented yet!";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
333 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
334 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
335 throw OrthancException(ErrorCode_InternalError, "Wrong tool!");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
336 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
337 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
338 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
339 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
340 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
341 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
342 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
343
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
344
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
345 void TrackerSampleApp::PrepareScene()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
346 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
347 // Texture of 2x2 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
348 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
349 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
350
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
351 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
352 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
353 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
354 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
355
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
356 p[3] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
357 p[4] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
358 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
359
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
360 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
361 p[0] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
362 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
363 p[2] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
364
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
365 p[3] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
366 p[4] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
367 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
368
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
369 scene_.SetLayer(TEXTURE_2x2_1_ZINDEX, new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
370
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
371 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
372 l->SetOrigin(-3, 2);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
373 l->SetPixelSpacing(1.5, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
374 l->SetAngle(20.0 / 180.0 * M_PI);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
375 scene_.SetLayer(TEXTURE_2x2_2_ZINDEX, l.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
376 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378 // Texture of 1x1 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
379 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
380 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
381
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
382 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
386
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
387 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388 l->SetOrigin(-2, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 l->SetAngle(20.0 / 180.0 * M_PI);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
390 scene_.SetLayer(TEXTURE_1x1_ZINDEX, l.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
391 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
392
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 // Some lines
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
394 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
395 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
396
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
397 layer->SetThickness(1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
399 PolylineSceneLayer::Chain chain;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
401 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
402 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404 layer->AddChain(chain, true);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
406 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
407 chain.push_back(ScenePoint2D(-5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
408 chain.push_back(ScenePoint2D(5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
409 chain.push_back(ScenePoint2D(5, 5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
410 chain.push_back(ScenePoint2D(-5, 5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
411 layer->AddChain(chain, true);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
412
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
413 double dy = 1.01;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
414 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
415 chain.push_back(ScenePoint2D(-4, -4));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
416 chain.push_back(ScenePoint2D(4, -4 + dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
417 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
418 chain.push_back(ScenePoint2D(4, 2));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
419 layer->AddChain(chain, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
420
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
421 layer->SetColor(0, 255, 255);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
422 scene_.SetLayer(LINESET_1_ZINDEX, layer.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
423 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
424
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
425 // Some text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
426 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
427 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
428 layer->SetText("Hello");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
429 scene_.SetLayer(LINESET_2_ZINDEX, layer.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
430 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
431 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
432
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
433
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
434 void TrackerSampleApp::DisableTracker()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
435 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
436 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
437 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
438 activeTracker_->Cancel();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
439 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
440 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
441 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
442
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
443 void TrackerSampleApp::TakeScreenshot(const std::string& target,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
444 unsigned int canvasWidth,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
445 unsigned int canvasHeight)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
446 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
447 CairoCompositor compositor(scene_, 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
448 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE_0, Orthanc::Encoding_Latin1);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
449 compositor.Refresh();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
450
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
451 Orthanc::ImageAccessor canvas;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
452 compositor.GetCanvas().GetReadOnlyAccessor(canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
453
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
454 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
455 Orthanc::ImageProcessing::Convert(png, canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
456
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
457 Orthanc::PngWriter writer;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
458 writer.WriteToFile(target, png);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
459 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
460
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
461
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
462 FlexiblePointerTrackerPtr TrackerSampleApp::TrackerHitTest(const PointerEvent & e)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
463 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
464 // std::vector<MeasureToolPtr> measureTools_;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
465 return nullptr;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
466 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
467
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
477 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
478 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
479 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
480 (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
481 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
482 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
483 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
484
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
485 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
486
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
487 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
488 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
489 // 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
490 // 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
491 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
492
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
493 GetScene().FitContent(window.GetCanvasWidth(), window.GetCanvasHeight());
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
494
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
495 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
496 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
497
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
498 compositor_.reset(new OpenGLCompositor(window, GetScene()));
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
499
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
500 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
501 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
502 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
503 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
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 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
506 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
507 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
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 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
510 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
511 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
512 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
513 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
514 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
515 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
516 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
517 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
518 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
519 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
520 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
521 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
522 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
523 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
524 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
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 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
527 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
528 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
529 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
530 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
531
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
532 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
533 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
534 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
535 default:
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
536 break;
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 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
539 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
540 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
541 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
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 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
544 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
545
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
546
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
547
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
548 }