comparison OrthancStone/Sources/Scene2D/GrayscaleWindowingSceneTracker.cpp @ 1606:874e178f34e9

- ViewportController now has weak ptr to Viewport - Measuring tools + related commands and all trackers now store only a weak_ptr to the Viewport and lock() on demand for usage - LayerHolder and FixedPoint aligner store only a weak_ptr to the Viewport, too - Fixed float/double warning in GrayscaleWindowingSceneTracker
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 28 Oct 2020 20:14:34 +0100
parents 8563ea5d8ae4
children 5cdc5b98f14d
comparison
equal deleted inserted replaced
1605:b3c439d96d3e 1606:874e178f34e9
36 private: 36 private:
37 std::unique_ptr<IViewport::ILock> lock_; 37 std::unique_ptr<IViewport::ILock> lock_;
38 FloatTextureSceneLayer* layer_; 38 FloatTextureSceneLayer* layer_;
39 39
40 public: 40 public:
41 GrayscaleLayerAccessor(boost::shared_ptr<IViewport> viewport, 41 GrayscaleLayerAccessor(boost::weak_ptr<IViewport> viewportWeak,
42 int layerIndex) : 42 int layerIndex) :
43 layer_(NULL) 43 layer_(NULL)
44 { 44 {
45 boost::shared_ptr<IViewport> viewport = viewportWeak.lock();
45 if (viewport != NULL) 46 if (viewport != NULL)
46 { 47 {
47 lock_.reset(viewport->Lock()); 48 lock_.reset(viewport->Lock());
48 49
49 if (lock_->GetController().GetScene().HasLayer(layerIndex)) 50 if (lock_->GetController().GetScene().HasLayer(layerIndex))
87 void GrayscaleWindowingSceneTracker::SetWindowing(float center, 88 void GrayscaleWindowingSceneTracker::SetWindowing(float center,
88 float width) 89 float width)
89 { 90 {
90 if (active_) 91 if (active_)
91 { 92 {
92 GrayscaleLayerAccessor accessor(viewport_, layerIndex_); 93 boost::shared_ptr<IViewport> viewport = viewport_.lock();
94 GrayscaleLayerAccessor accessor(viewport, layerIndex_);
93 95
94 if (accessor.IsValid()) 96 if (accessor.IsValid())
95 { 97 {
96 accessor.GetLayer().SetCustomWindowing(center, width); 98 accessor.GetLayer().SetCustomWindowing(center, width);
97 accessor.Invalidate(); 99 accessor.Invalidate();
98 } 100 }
99 } 101 }
100 } 102 }
101 103
102 104
103 GrayscaleWindowingSceneTracker::GrayscaleWindowingSceneTracker(boost::shared_ptr<IViewport> viewport, 105 GrayscaleWindowingSceneTracker::GrayscaleWindowingSceneTracker(boost::weak_ptr<IViewport> viewport,
104 int layerIndex, 106 int layerIndex,
105 const PointerEvent& event, 107 const PointerEvent& event,
106 unsigned int canvasWidth, 108 unsigned int canvasWidth,
107 unsigned int canvasHeight) : 109 unsigned int canvasHeight) :
108 OneGesturePointerTracker(viewport), 110 OneGesturePointerTracker(viewport),
113 active_ = false; 115 active_ = false;
114 116
115 if (canvasWidth > 3 && 117 if (canvasWidth > 3 &&
116 canvasHeight > 3) 118 canvasHeight > 3)
117 { 119 {
118 GrayscaleLayerAccessor accessor(viewport_, layerIndex_); 120 boost::weak_ptr<IViewport> viewport = viewport_.lock();
121 GrayscaleLayerAccessor accessor(viewport, layerIndex_);
119 122
120 if (accessor.IsValid()) 123 if (accessor.IsValid())
121 { 124 {
122 FloatTextureSceneLayer& layer = accessor.GetLayer(); 125 FloatTextureSceneLayer& layer = accessor.GetLayer();
123 126
141 if (active_) 144 if (active_)
142 { 145 {
143 const double x = event.GetMainPosition().GetX(); 146 const double x = event.GetMainPosition().GetX();
144 const double y = event.GetMainPosition().GetY(); 147 const double y = event.GetMainPosition().GetY();
145 148
146 float center = originalCenter_ + (x - clickX_) * normalization_; 149 float center = originalCenter_ + static_cast<float>((x - clickX_) * normalization_);
147 float width = originalWidth_ + (y - clickY_) * normalization_; 150 float width = originalWidth_ + static_cast<float>((y - clickY_) * normalization_);
148 151
149 if (width <= 1) 152 if (width <= 1)
150 { 153 {
151 width = 1; 154 width = 1;
152 } 155 }