annotate Samples/Sdl/TrackerSampleApp.cpp @ 938:eaaa9b574e05 toa2019073101

Fixed the Stone samples wrt the recent API changes (SdlOpenGLViewport, ICompositor...)
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 31 Jul 2019 10:58:16 +0200
parents f9ae731fdc25
children efc5b62b9539
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
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
23 #include "../../Applications/Sdl/SdlOpenGLContext.h"
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24
737
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
25 #include "../../Framework/Scene2D/CairoCompositor.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
26 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
27 #include "../../Framework/Scene2D/OpenGLCompositor.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
28 #include "../../Framework/Scene2D/PanSceneTracker.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
29 #include "../../Framework/Scene2D/RotateSceneTracker.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
30 #include "../../Framework/Scene2D/Scene2D.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
31 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
858
e3c56d4f863f GuiAdapter : mouse event routing in SDL + split the undo stack from the
Benjamin Golinvaux <bgo@osimis.io>
parents: 818
diff changeset
32 #include "../../Framework/Scene2DViewport/UndoStack.h"
737
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
33 #include "../../Framework/Scene2DViewport/CreateAngleMeasureTracker.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
34 #include "../../Framework/Scene2DViewport/CreateLineMeasureTracker.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
35 #include "../../Framework/StoneInitialization.h"
698
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
36
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
37 // From Orthanc framework
644
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
787
1a28fce57ff3 Fixed Visual Studio 2008 build
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
44 #include <boost/ref.hpp>
1a28fce57ff3 Fixed Visual Studio 2008 build
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
45 #include <boost/make_shared.hpp>
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 #include <SDL.h>
787
1a28fce57ff3 Fixed Visual Studio 2008 build
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
47
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 #include <stdio.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 namespace OrthancStone
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 const char* MeasureToolToString(size_t i)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 static const char* descs[] = {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 "GuiTool_Rotate",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 "GuiTool_Pan",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 "GuiTool_Zoom",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 "GuiTool_LineMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 "GuiTool_CircleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 "GuiTool_AngleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 "GuiTool_EllipseMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 "GuiTool_LAST"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 };
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 if (i >= GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Wrong tool index");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 return descs[i];
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
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 void TrackerSampleApp::SelectNextTool()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 currentTool_ = static_cast<GuiTool>(currentTool_ + 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74 if (currentTool_ == GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 currentTool_ = static_cast<GuiTool>(0);;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
79 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
80 {
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
81 // 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
82 std::stringstream msg;
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
83
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
84 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
85 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
86 {
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
87 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
88 }
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
89 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
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* layerP = NULL;
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
92 if (controller_->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
93 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
94 TextSceneLayer& layer = dynamic_cast<TextSceneLayer&>(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
95 controller_->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
96 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
97 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
98 else
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
99 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
100 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
101 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
102 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
103 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
104 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
105 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
106 //layer->SetPosition(0,0);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
107 controller_->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
108 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
109 // 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
110 layerP->SetText(msgS.c_str());
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
111 double cX = GetCompositor().GetCanvasWidth() * (-0.5);
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
112 double cY = GetCompositor().GetCanvasHeight() * (-0.5);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
113 controller_->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
114 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
115 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
116
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
117 void TrackerSampleApp::DisplayFloatingCtrlInfoText(const PointerEvent& e)
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 {
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
119 ScenePoint2D p = e.GetMainPosition().Apply(controller_->GetScene().GetCanvasToSceneTransform());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
121 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
122 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
123 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
124 e.GetMainPosition().GetX(), e.GetMainPosition().GetY());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
126 if (controller_->GetScene().HasLayer(FLOATING_INFOTEXT_LAYER_ZINDEX))
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 TextSceneLayer& layer =
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
129 dynamic_cast<TextSceneLayer&>(controller_->GetScene().GetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 layer.SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 layer.SetPosition(p.GetX(), p.GetY());
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 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 layer->SetColor(0, 255, 0);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 layer->SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138 layer->SetBorder(20);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 layer->SetAnchor(BitmapAnchor_BottomCenter);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 layer->SetPosition(p.GetX(), p.GetY());
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
141 controller_->GetScene().SetLayer(FLOATING_INFOTEXT_LAYER_ZINDEX, layer.release());
644
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 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 void TrackerSampleApp::HideInfoText()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146 {
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
147 controller_->GetScene().DeleteLayer(FLOATING_INFOTEXT_LAYER_ZINDEX);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
150 ScenePoint2D TrackerSampleApp::GetRandomPointInScene() const
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
151 {
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
152 unsigned int w = GetCompositor().GetCanvasWidth();
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
153 LOG(TRACE) << "GetCompositor().GetCanvasWidth() = " <<
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
154 GetCompositor().GetCanvasWidth();
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
155 unsigned int h = GetCompositor().GetCanvasHeight();
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
156 LOG(TRACE) << "GetCompositor().GetCanvasHeight() = " <<
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
157 GetCompositor().GetCanvasHeight();
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
158
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
159 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
160 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
161
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
162 int x = rand() % w;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
163 int y = rand() % h;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
164 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
165
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
166 ScenePoint2D p = controller_->GetViewport().GetPixelCenterCoordinates(x, y);
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
167 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
168
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
169 ScenePoint2D r = p.Apply(controller_->GetScene().GetCanvasToSceneTransform());
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
170 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
171 return r;
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
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
174 void TrackerSampleApp::CreateRandomMeasureTool()
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 static bool srandCalled = false;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
177 if (!srandCalled)
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
178 {
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
179 srand(42);
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
180 srandCalled = true;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
181 }
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 int i = rand() % 2;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
184 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
185 switch (i)
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 case 0:
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
188 // line measure
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
189 {
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
190 boost::shared_ptr<CreateLineMeasureCommand> cmd =
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
191 boost::make_shared<CreateLineMeasureCommand>(
787
1a28fce57ff3 Fixed Visual Studio 2008 build
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
192 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
193 controller_,
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
194 GetRandomPointInScene());
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
195 cmd->SetEnd(GetRandomPointInScene());
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
196 controller_->PushCommand(cmd);
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
197 }
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
198 break;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
199 case 1:
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
200 // angle measure
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
201 {
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
202 boost::shared_ptr<CreateAngleMeasureCommand> cmd =
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
203 boost::make_shared<CreateAngleMeasureCommand>(
787
1a28fce57ff3 Fixed Visual Studio 2008 build
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
204 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
205 controller_,
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
206 GetRandomPointInScene());
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
207 cmd->SetCenter(GetRandomPointInScene());
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
208 cmd->SetSide2End(GetRandomPointInScene());
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
209 controller_->PushCommand(cmd);
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
210 }
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
211 break;
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
212 }
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
213 }
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
214
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 void TrackerSampleApp::HandleApplicationEvent(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 const SDL_Event & event)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217 {
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
218 DisplayInfoText();
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
219
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 if (event.type == SDL_MOUSEMOTION)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 int scancodeCount = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
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 if (activeTracker_.get() == NULL &&
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
226 SDL_SCANCODE_LALT < scancodeCount &&
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
227 keyboardState[SDL_SCANCODE_LALT])
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 // The "left-ctrl" key is down, while no tracker is present
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 // Let's display the info text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 PointerEvent e;
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
232 e.AddPosition(controller_->GetViewport().GetPixelCenterCoordinates(
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
233 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
234
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
235 DisplayFloatingCtrlInfoText(e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 }
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
237 else if (activeTracker_.get() != NULL)
644
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 HideInfoText();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 //LOG(TRACE) << "(event.type == SDL_MOUSEMOTION)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 if (activeTracker_.get() != NULL)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 //LOG(TRACE) << "(activeTracker_.get() != NULL)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 PointerEvent e;
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
245 e.AddPosition(controller_->GetViewport().GetPixelCenterCoordinates(
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 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
247
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248 //LOG(TRACE) << "event.button.x = " << event.button.x << " " <<
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 // "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
250 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
251 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
252
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 activeTracker_->PointerMove(e);
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
254 if (!activeTracker_->IsAlive())
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
255 activeTracker_.reset();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 }
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
258 else
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
259 {
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
260 HideInfoText();
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
261
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
262 PointerEvent e;
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
263 e.AddPosition(controller_->GetViewport().GetPixelCenterCoordinates(event.button.x, event.button.y));
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
264
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
265 ScenePoint2D scenePos = e.GetMainPosition().Apply(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
266 controller_->GetScene().GetCanvasToSceneTransform());
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
267 //auto measureTools = GetController()->HitTestMeasureTools(scenePos);
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
268 //LOG(TRACE) << "# of hit tests: " << measureTools.size();
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
269
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
270 // this returns the collection of measuring tools where hit test is true
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
271 std::vector<boost::shared_ptr<MeasureTool> > measureTools = controller_->HitTestMeasureTools(scenePos);
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
272
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
273 // let's refresh the measuring tools highlighted state
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
274 // first let's tag them as "unhighlighted"
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
275 controller_->ResetMeasuringToolsHighlight();
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
276
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
277 // then immediately take the first one and ask it to highlight the
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
278 // measuring tool UI part that is hot
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
279 if (measureTools.size() > 0)
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
280 {
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
281 measureTools[0]->Highlight(scenePos);
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
282 }
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
283 }
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 else if (event.type == SDL_MOUSEBUTTONUP)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
287 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
288 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 PointerEvent e;
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
290 e.AddPosition(controller_->GetViewport().GetPixelCenterCoordinates(event.button.x, event.button.y));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291 activeTracker_->PointerUp(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
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 }
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 else if (event.type == SDL_MOUSEBUTTONDOWN)
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 PointerEvent e;
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
299 e.AddPosition(controller_->GetViewport().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
300 event.button.x, event.button.y));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
301 if (activeTracker_)
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 activeTracker_->PointerDown(e);
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
304 if (!activeTracker_->IsAlive())
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
305 activeTracker_.reset();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
306 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
307 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
308 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
309 // 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
310 activeTracker_ = CreateSuitableTracker(event, e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
311 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
312 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
313 else if (event.type == SDL_KEYDOWN &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
314 event.key.repeat == 0 /* Ignore key bounce */)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
315 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
316 switch (event.key.keysym.sym)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
317 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
318 case SDLK_ESCAPE:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
319 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
320 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
321 activeTracker_->Cancel();
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
322 if (!activeTracker_->IsAlive())
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
323 activeTracker_.reset();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
325 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
326
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
327 case SDLK_t:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
328 if (!activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
329 SelectNextTool();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
331 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
332 LOG(WARNING) << "You cannot change the active tool when an interaction"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
333 " is taking place";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
334 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
335 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
336
753
Benjamin Golinvaux <bgo@osimis.io>
parents: 750
diff changeset
337 case SDLK_m:
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
338 CreateRandomMeasureTool();
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
339 break;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
340 case SDLK_s:
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
341 controller_->FitContent(GetCompositor().GetCanvasWidth(),
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
342 GetCompositor().GetCanvasHeight());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
343 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
344
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
345 case SDLK_z:
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
346 LOG(TRACE) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod;
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
347 if (event.key.keysym.mod & KMOD_CTRL)
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
348 {
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
349 if (controller_->CanUndo())
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
350 {
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
351 LOG(TRACE) << "Undoing...";
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
352 controller_->Undo();
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
353 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
354 else
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
355 {
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
356 LOG(WARNING) << "Nothing to undo!!!";
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
357 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
358 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
359 break;
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
360
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
361 case SDLK_y:
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
362 LOG(TRACE) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod;
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
363 if (event.key.keysym.mod & KMOD_CTRL)
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
364 {
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
365 if (controller_->CanRedo())
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
366 {
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 754
diff changeset
367 LOG(TRACE) << "Redoing...";
750
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
368 controller_->Redo();
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
369 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
370 else
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
371 {
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
372 LOG(WARNING) << "Nothing to redo!!!";
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
373 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
374 }
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
375 break;
284f37dc1c66 Wired undo redo to keys
Benjamin Golinvaux <bgo@osimis.io>
parents: 722
diff changeset
376
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377 case SDLK_c:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378 TakeScreenshot(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
379 "screenshot.png",
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
380 GetCompositor().GetCanvasWidth(),
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
381 GetCompositor().GetCanvasHeight());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
382 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 break;
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 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
390
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
391 void TrackerSampleApp::OnSceneTransformChanged(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
392 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
393 {
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
394 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
395 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
396
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
397 boost::shared_ptr<IFlexiblePointerTracker> TrackerSampleApp::CreateSuitableTracker(
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398 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
399 const PointerEvent & e)
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 {
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
401 using namespace Orthanc;
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
402
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403 switch (event.button.button)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405 case SDL_BUTTON_MIDDLE:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
406 return boost::shared_ptr<IFlexiblePointerTracker>(new PanSceneTracker
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
407 (controller_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
408
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
409 case SDL_BUTTON_RIGHT:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
410 return boost::shared_ptr<IFlexiblePointerTracker>(new ZoomSceneTracker
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
411 (controller_, e, GetCompositor().GetCanvasHeight()));
644
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 case SDL_BUTTON_LEFT:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
414 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
415 //LOG(TRACE) << "CreateSuitableTracker: case SDL_BUTTON_LEFT:";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
416 // 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
417 // 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
418 // Otherwise, depending upon the active tool, we might want to create
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
419 // a "measuring tool creation" tracker
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 // TODO: if there are conflicts, we should prefer a tracker that
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
422 // pertains to the type of measuring tool currently selected (TBD?)
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
423 boost::shared_ptr<IFlexiblePointerTracker> hitTestTracker = TrackerHitTest(e);
644
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 if (hitTestTracker != NULL)
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 //LOG(TRACE) << "hitTestTracker != NULL";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
428 return hitTestTracker;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
429 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
430 else
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 switch (currentTool_)
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 case GuiTool_Rotate:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
435 //LOG(TRACE) << "Creating RotateSceneTracker";
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
436 return boost::shared_ptr<IFlexiblePointerTracker>(new RotateSceneTracker(
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
437 controller_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
438 case GuiTool_Pan:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
439 return boost::shared_ptr<IFlexiblePointerTracker>(new PanSceneTracker(
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 699
diff changeset
440 controller_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
441 case GuiTool_Zoom:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
442 return boost::shared_ptr<IFlexiblePointerTracker>(new ZoomSceneTracker(
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
443 controller_, e, GetCompositor().GetCanvasHeight()));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
444 //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
445 // return new AngleMeasureTracker(GetScene(), e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
446 //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
447 // return new CircleMeasureTracker(GetScene(), e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
448 //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
449 // 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
450 case GuiTool_LineMeasure:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
451 return boost::shared_ptr<IFlexiblePointerTracker>(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
452 IObserver::GetBroker(), controller_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
453 case GuiTool_AngleMeasure:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
454 return boost::shared_ptr<IFlexiblePointerTracker>(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
455 IObserver::GetBroker(), controller_, e));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
456 case GuiTool_CircleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
457 LOG(ERROR) << "Not implemented yet!";
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
458 return boost::shared_ptr<IFlexiblePointerTracker>();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
459 case GuiTool_EllipseMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
460 LOG(ERROR) << "Not implemented yet!";
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
461 return boost::shared_ptr<IFlexiblePointerTracker>();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
462 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
463 throw OrthancException(ErrorCode_InternalError, "Wrong tool!");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
464 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
465 }
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 default:
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
468 return boost::shared_ptr<IFlexiblePointerTracker>();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
469 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
470 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
471
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
472
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
473 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
474 , currentTool_(GuiTool_Rotate)
858
e3c56d4f863f GuiAdapter : mouse event routing in SDL + split the undo stack from the
Benjamin Golinvaux <bgo@osimis.io>
parents: 818
diff changeset
475 , undoStack_(new UndoStack)
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
476 , viewport_("Hello", 1024, 1024, false) // False means we do NOT let Windows treat this as a legacy application that needs to be scaled
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
477 {
858
e3c56d4f863f GuiAdapter : mouse event routing in SDL + split the undo stack from the
Benjamin Golinvaux <bgo@osimis.io>
parents: 818
diff changeset
478 controller_ = boost::shared_ptr<ViewportController>(
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
479 new ViewportController(undoStack_, broker, viewport_));
698
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
480
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
481 controller_->RegisterObserverCallback(
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
482 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
483 (*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
484
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
485 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
486 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
487 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
488 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
489 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
490 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
491 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
492 }
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
493
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
494 void TrackerSampleApp::PrepareScene()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
495 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
496 // Texture of 2x2 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
497 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
498 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
499
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
500 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
501 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
502 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
503 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
504
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
505 p[3] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
506 p[4] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
507 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
508
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
509 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
510 p[0] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
511 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
512 p[2] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
513
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
514 p[3] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
515 p[4] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
516 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
517
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
518 controller_->GetScene().SetLayer(TEXTURE_2x2_1_ZINDEX, new ColorTextureSceneLayer(i));
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
519
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
520 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
521 l->SetOrigin(-3, 2);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
522 l->SetPixelSpacing(1.5, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
523 l->SetAngle(20.0 / 180.0 * M_PI);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
524 controller_->GetScene().SetLayer(TEXTURE_2x2_2_ZINDEX, l.release());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
525 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
526
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
527 // Texture of 1x1 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
528 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
529 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
530
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
531 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
532 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
533 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
534 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
535
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
536 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
537 l->SetOrigin(-2, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
538 l->SetAngle(20.0 / 180.0 * M_PI);
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
539 controller_->GetScene().SetLayer(TEXTURE_1x1_ZINDEX, l.release());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
540 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
541
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
542 // Some lines
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
543 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
544 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
545
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
546 layer->SetThickness(1);
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 PolylineSceneLayer::Chain chain;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
549 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
550 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
551 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
552 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
553 layer->AddChain(chain, true, 255, 0, 0);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
554
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
555 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
556 chain.push_back(ScenePoint2D(-5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
557 chain.push_back(ScenePoint2D(5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
558 chain.push_back(ScenePoint2D(5, 5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
559 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
560 layer->AddChain(chain, true, 0, 255, 0);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
561
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
562 double dy = 1.01;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
563 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
564 chain.push_back(ScenePoint2D(-4, -4));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
565 chain.push_back(ScenePoint2D(4, -4 + dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
566 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
567 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
568 layer->AddChain(chain, false, 0, 0, 255);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
569
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
570 controller_->GetScene().SetLayer(LINESET_1_ZINDEX, layer.release());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
571 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
572
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
573 // Some text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
574 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
575 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
576 layer->SetText("Hello");
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
577 controller_->GetScene().SetLayer(LINESET_2_ZINDEX, layer.release());
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
578 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
579 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
580
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
581
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
582 void TrackerSampleApp::DisableTracker()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
583 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
584 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
585 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
586 activeTracker_->Cancel();
706
ef07304d4423 Fixed C++ code to be C++03 compatible
Benjamin Golinvaux <bgo@osimis.io>
parents: 700
diff changeset
587 activeTracker_.reset();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
588 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
589 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
590
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
591 void TrackerSampleApp::TakeScreenshot(const std::string& target,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
592 unsigned int canvasWidth,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
593 unsigned int canvasHeight)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
594 {
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
595 CairoCompositor compositor(controller_->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
596 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
597 compositor.Refresh();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
598
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
599 Orthanc::ImageAccessor canvas;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
600 compositor.GetCanvas().GetReadOnlyAccessor(canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
601
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
602 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
603 Orthanc::ImageProcessing::Convert(png, canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
604
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
605 Orthanc::PngWriter writer;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
606 writer.WriteToFile(target, png);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
607 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
608
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
609
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
610 boost::shared_ptr<IFlexiblePointerTracker> TrackerSampleApp::TrackerHitTest(const PointerEvent & e)
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
611 {
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
612 // std::vector<boost::shared_ptr<MeasureTool>> measureTools_;
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
613 ScenePoint2D scenePos = e.GetMainPosition().Apply(
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 890
diff changeset
614 controller_->GetScene().GetCanvasToSceneTransform());
871
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
615
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
616 std::vector<boost::shared_ptr<MeasureTool> > measureTools = controller_->HitTestMeasureTools(scenePos);
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
617
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
618 if (measureTools.size() > 0)
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
619 {
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
620 return measureTools[0]->CreateEditionTracker(e);
4bc8d9609447 Added support for measuring tool edition in TrackerSampleApp
Benjamin Golinvaux <bgo@osimis.io>
parents: 858
diff changeset
621 }
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
622 return boost::shared_ptr<IFlexiblePointerTracker>();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
623 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
624
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 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
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
634 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
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 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
637 (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
638 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
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 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
641
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
642 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
643
938
eaaa9b574e05 Fixed the Stone samples wrt the recent API changes (SdlOpenGLViewport, ICompositor...)
Benjamin Golinvaux <bgo@osimis.io>
parents: 900
diff changeset
644 ICompositor& TrackerSampleApp::GetCompositor()
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
645 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
646 using namespace Orthanc;
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
647 try
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
648 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
649 SdlViewport& viewport = dynamic_cast<SdlViewport&>(viewport_);
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
650 return viewport.GetCompositor();
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
651 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
652 catch (std::bad_cast e)
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
653 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
654 throw OrthancException(ErrorCode_InternalError, "Wrong viewport type!");
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
655 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
656 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
657
938
eaaa9b574e05 Fixed the Stone samples wrt the recent API changes (SdlOpenGLViewport, ICompositor...)
Benjamin Golinvaux <bgo@osimis.io>
parents: 900
diff changeset
658 const ICompositor& TrackerSampleApp::GetCompositor() const
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
659 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
660 using namespace Orthanc;
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
661 try
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
662 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
663 SdlViewport& viewport = const_cast<SdlViewport&>(dynamic_cast<const SdlViewport&>(viewport_));
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
664 return viewport.GetCompositor();
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
665 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
666 catch (std::bad_cast e)
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
667 {
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
668 throw OrthancException(ErrorCode_InternalError, "Wrong viewport type!");
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
669 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
670 }
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
671
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
672
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
673 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
674 {
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
675 controller_->FitContent(viewport_.GetCanvasWidth(), viewport_.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
676
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
677 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
678 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
679
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
680 GetCompositor().SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT,
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
681 FONT_SIZE_0, Orthanc::Encoding_Latin1);
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
682 GetCompositor().SetFont(1, Orthanc::EmbeddedResources::UBUNTU_FONT,
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
683 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
684
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
685 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
686 {
893
0c5201499af8 Fixes to TrackerSampleApp following IViewport refactoring (FusionMprSdl not working yet)
Benjamin Golinvaux <bgo@osimis.io>
parents: 891
diff changeset
687 GetCompositor().Refresh();
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
688
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
689 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
690 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
691 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
692 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
693 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
694 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
695 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
696 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
697 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
698 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
699 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
700 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
701 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
702 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
703 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
704 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
705 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
706 {
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
707 case SDLK_f:
938
eaaa9b574e05 Fixed the Stone samples wrt the recent API changes (SdlOpenGLViewport, ICompositor...)
Benjamin Golinvaux <bgo@osimis.io>
parents: 900
diff changeset
708 viewport_.GetWindow().ToggleMaximize();
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
709 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
710
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
711 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
712 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
713 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
714 default:
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
715 break;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
716 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
717 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
718 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
719 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
720 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
721 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
722 }
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
723
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
724 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
725 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
726 {
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
727 if (value == "")
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
728 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
729 else
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
730 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
731 DisplayInfoText();
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
732 }
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
733
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
734 }