Mercurial > hg > orthanc-stone
comparison Framework/Widgets/LayoutWidget.cpp @ 416:88c79f1537de captain
compatibility of captain branch with framework 1.4.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 10:44:32 +0100 |
parents | ce48c3b3b0e9 |
children |
comparison
equal
deleted
inserted
replaced
368:70823cb5ec9e | 416:88c79f1537de |
---|---|
26 | 26 |
27 #include <boost/math/special_functions/round.hpp> | 27 #include <boost/math/special_functions/round.hpp> |
28 | 28 |
29 namespace OrthancStone | 29 namespace OrthancStone |
30 { | 30 { |
31 // This is a compatibility reimplementation of | |
32 // "ImageAcessor::GetRegion()" to use Orthanc <= 1.4.2 together with | |
33 // Stone. | |
34 static void GetRegionCompatibility(Orthanc::ImageAccessor& target, | |
35 const Orthanc::ImageAccessor& source, | |
36 unsigned int x, | |
37 unsigned int y, | |
38 unsigned int width, | |
39 unsigned int height) | |
40 { | |
41 if (x + width > source.GetWidth() || | |
42 y + height > source.GetHeight()) | |
43 { | |
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
45 } | |
46 | |
47 if (width == 0 || | |
48 height == 0) | |
49 { | |
50 target.AssignWritable(source.GetFormat(), 0, 0, 0, NULL); | |
51 } | |
52 else if (source.IsReadOnly()) | |
53 { | |
54 const uint8_t* p = (reinterpret_cast<const uint8_t*>(source.GetBuffer()) + | |
55 y * source.GetPitch() + | |
56 x * source.GetBytesPerPixel()); | |
57 | |
58 target.AssignReadOnly(source.GetFormat(), width, height, source.GetPitch(), p); | |
59 } | |
60 else | |
61 { | |
62 uint8_t* p = (reinterpret_cast<uint8_t*>(source.GetBuffer()) + | |
63 y * source.GetPitch() + | |
64 x * source.GetBytesPerPixel()); | |
65 | |
66 target.AssignWritable(source.GetFormat(), width, height, source.GetPitch(), p); | |
67 } | |
68 } | |
69 | |
70 | |
31 class LayoutWidget::LayoutMouseTracker : public IMouseTracker | 71 class LayoutWidget::LayoutMouseTracker : public IMouseTracker |
32 { | 72 { |
33 private: | 73 private: |
34 std::auto_ptr<IMouseTracker> tracker_; | 74 std::auto_ptr<IMouseTracker> tracker_; |
35 int left_; | 75 int left_; |
36 int top_; | 76 int top_; |
37 unsigned int width_; | 77 unsigned int width_; |
38 unsigned int height_; | 78 unsigned int height_; |
39 | 79 |
40 public: | 80 public: |
41 LayoutMouseTracker(IMouseTracker* tracker, | 81 LayoutMouseTracker(IMouseTracker* tracker, |
42 int left, | 82 int left, |
43 int top, | 83 int top, |
44 unsigned int width, | 84 unsigned int width, |
56 } | 96 } |
57 | 97 |
58 virtual void Render(Orthanc::ImageAccessor& surface) | 98 virtual void Render(Orthanc::ImageAccessor& surface) |
59 { | 99 { |
60 Orthanc::ImageAccessor accessor; | 100 Orthanc::ImageAccessor accessor; |
61 surface.GetRegion(accessor, left_, top_, width_, height_); | 101 GetRegionCompatibility(accessor, surface, left_, top_, width_, height_); |
62 tracker_->Render(accessor); | 102 tracker_->Render(accessor); |
63 } | 103 } |
64 | 104 |
65 virtual void MouseUp() | 105 virtual void MouseUp() |
66 { | 106 { |
142 return true; | 182 return true; |
143 } | 183 } |
144 else | 184 else |
145 { | 185 { |
146 Orthanc::ImageAccessor accessor; | 186 Orthanc::ImageAccessor accessor; |
147 target.GetRegion(accessor, left_, top_, width_, height_); | 187 GetRegionCompatibility(accessor, target, left_, top_, width_, height_); |
148 return widget_->Render(accessor); | 188 return widget_->Render(accessor); |
149 } | 189 } |
150 } | 190 } |
151 | 191 |
152 IMouseTracker* CreateMouseTracker(MouseButton button, | 192 IMouseTracker* CreateMouseTracker(MouseButton button, |
174 int y) | 214 int y) |
175 { | 215 { |
176 if (Contains(x, y)) | 216 if (Contains(x, y)) |
177 { | 217 { |
178 Orthanc::ImageAccessor accessor; | 218 Orthanc::ImageAccessor accessor; |
179 target.GetRegion(accessor, left_, top_, width_, height_); | 219 GetRegionCompatibility(accessor, target, left_, top_, width_, height_); |
180 | 220 |
181 widget_->RenderMouseOver(accessor, x - left_, y - top_); | 221 widget_->RenderMouseOver(accessor, x - left_, y - top_); |
182 } | 222 } |
183 } | 223 } |
184 | 224 |