Mercurial > hg > orthanc-stone
comparison Samples/Common/MeasureTools.h @ 654:462a5074f914
Turned the scene into an observable to be able to dynamically react to
scene to canvas transform changes --> now the handles and angle measure
adornments are immune to zoom changes
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 14 May 2019 13:51:00 +0200 |
parents | 1e9ed656318e |
children | cb3b76d16234 |
comparison
equal
deleted
inserted
replaced
653:4eccf698e52f | 654:462a5074f914 |
---|---|
31 #include <vector> | 31 #include <vector> |
32 #include <cmath> | 32 #include <cmath> |
33 | 33 |
34 namespace OrthancStone | 34 namespace OrthancStone |
35 { | 35 { |
36 class MeasureTool | 36 class MeasureTool : public IObserver |
37 { | 37 { |
38 public: | 38 public: |
39 virtual ~MeasureTool() {} | 39 virtual ~MeasureTool(); |
40 | 40 |
41 /** | 41 /** |
42 Enabled tools are rendered in the scene. | 42 Enabled tools are rendered in the scene. |
43 */ | 43 */ |
44 void Enable(); | 44 void Enable(); |
49 creation command has been undone, the measure remains alive in the | 49 creation command has been undone, the measure remains alive in the |
50 command object but is disabled so that it can be redone later on easily) | 50 command object but is disabled so that it can be redone later on easily) |
51 */ | 51 */ |
52 void Disable(); | 52 void Disable(); |
53 | 53 |
54 /** | |
55 This method is called when the scene transform changes. It allows to | |
56 recompute the visual elements whose content depend upon the scene transform | |
57 */ | |
58 void OnSceneTransformChanged(const Scene2D::SceneTransformChanged& message); | |
59 | |
54 protected: | 60 protected: |
55 MeasureTool(Scene2D& scene) | 61 MeasureTool(MessageBroker& broker, Scene2D& scene); |
56 : scene_(scene) | 62 |
57 , enabled_(true) | |
58 { | |
59 } | |
60 | |
61 | |
62 | |
63 /** | 63 /** |
64 This is the meat of the tool: this method must [create (if needed) and] | 64 This is the meat of the tool: this method must [create (if needed) and] |
65 update the layers and their data according to the measure tool kind and | 65 update the layers and their data according to the measure tool kind and |
66 current state. This is repeatedly called during user interaction | 66 current state. This is repeatedly called during user interaction |
67 */ | 67 */ |
68 virtual void RefreshScene() = 0; | 68 virtual void RefreshScene() = 0; |
69 | 69 |
70 Scene2D& GetScene() | 70 Scene2D& GetScene(); |
71 { | |
72 return scene_; | |
73 } | |
74 | 71 |
75 /** | 72 /** |
76 enabled_ is not accessible by subclasses because there is a state machine | 73 enabled_ is not accessible by subclasses because there is a state machine |
77 that we do not wanna mess with | 74 that we do not wanna mess with |
78 */ | 75 */ |
79 bool IsEnabled() const | 76 bool IsEnabled() const; |
80 { | |
81 return enabled_; | |
82 } | |
83 | 77 |
84 private: | 78 private: |
85 Scene2D& scene_; | 79 Scene2D& scene_; |
86 bool enabled_; | 80 bool enabled_; |
87 }; | 81 }; |