Mercurial > hg > orthanc-stone
comparison Framework/Widgets/WidgetBase.cpp @ 61:ca644004d2ee wasm
MAJOR - removal of Start/Stop and observers in IWidget
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 May 2017 17:55:13 +0200 |
parents | 25befef48c35 |
children | bd48431ac285 |
comparison
equal
deleted
inserted
replaced
60:288c948199e5 | 61:ca644004d2ee |
---|---|
25 #include "../../Resources/Orthanc/Core/Images/ImageProcessing.h" | 25 #include "../../Resources/Orthanc/Core/Images/ImageProcessing.h" |
26 #include "../../Resources/Orthanc/Core/Logging.h" | 26 #include "../../Resources/Orthanc/Core/Logging.h" |
27 | 27 |
28 namespace OrthancStone | 28 namespace OrthancStone |
29 { | 29 { |
30 void WidgetBase::NotifyChange() | |
31 { | |
32 if (parent_ != NULL) | |
33 { | |
34 parent_->NotifyChange(); | |
35 } | |
36 | |
37 if (viewport_ != NULL) | |
38 { | |
39 viewport_->NotifyChange(*this); | |
40 } | |
41 } | |
42 | |
43 | |
44 void WidgetBase::SetParent(IWidget& parent) | |
45 { | |
46 if (parent_ != NULL) | |
47 { | |
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
49 } | |
50 else | |
51 { | |
52 parent_ = &parent; | |
53 } | |
54 } | |
55 | |
56 | |
30 void WidgetBase::ClearBackgroundOrthanc(Orthanc::ImageAccessor& target) const | 57 void WidgetBase::ClearBackgroundOrthanc(Orthanc::ImageAccessor& target) const |
31 { | 58 { |
32 // Clear the background using Orthanc | 59 // Clear the background using Orthanc |
33 | 60 |
34 if (backgroundCleared_) | 61 if (backgroundCleared_) |
63 CairoContext context(surface); | 90 CairoContext context(surface); |
64 ClearBackgroundCairo(context); | 91 ClearBackgroundCairo(context); |
65 } | 92 } |
66 | 93 |
67 | 94 |
68 void WidgetBase::NotifyChange() | |
69 { | |
70 observers_.NotifyChange(this); | |
71 } | |
72 | |
73 | |
74 void WidgetBase::UpdateStatusBar(const std::string& message) | 95 void WidgetBase::UpdateStatusBar(const std::string& message) |
75 { | 96 { |
76 if (statusBar_ != NULL) | 97 if (statusBar_ != NULL) |
77 { | 98 { |
78 statusBar_->SetMessage(message); | 99 statusBar_->SetMessage(message); |
79 } | 100 } |
80 } | 101 } |
81 | 102 |
82 | 103 |
83 WidgetBase::WidgetBase() : | 104 WidgetBase::WidgetBase() : |
105 parent_(NULL), | |
106 viewport_(NULL), | |
84 statusBar_(NULL), | 107 statusBar_(NULL), |
85 started_(false), | |
86 backgroundCleared_(false) | 108 backgroundCleared_(false) |
87 { | 109 { |
88 backgroundColor_[0] = 0; | 110 backgroundColor_[0] = 0; |
89 backgroundColor_[1] = 0; | 111 backgroundColor_[1] = 0; |
90 backgroundColor_[2] = 0; | 112 backgroundColor_[2] = 0; |
91 } | 113 } |
92 | 114 |
93 | 115 |
116 void WidgetBase::SetViewport(IViewport& viewport) | |
117 { | |
118 if (viewport_ != NULL) | |
119 { | |
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
121 } | |
122 else | |
123 { | |
124 viewport_ = &viewport; | |
125 } | |
126 } | |
127 | |
128 | |
94 void WidgetBase::SetBackgroundColor(uint8_t red, | 129 void WidgetBase::SetBackgroundColor(uint8_t red, |
95 uint8_t green, | 130 uint8_t green, |
96 uint8_t blue) | 131 uint8_t blue) |
97 { | 132 { |
98 backgroundColor_[0] = red; | 133 backgroundColor_[0] = red; |
108 green = backgroundColor_[1]; | 143 green = backgroundColor_[1]; |
109 blue = backgroundColor_[2]; | 144 blue = backgroundColor_[2]; |
110 } | 145 } |
111 | 146 |
112 | 147 |
113 void WidgetBase::Register(IChangeObserver& observer) | |
114 { | |
115 if (started_) | |
116 { | |
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
118 } | |
119 | |
120 observers_.Register(observer); | |
121 } | |
122 | |
123 | |
124 void WidgetBase::Unregister(IChangeObserver& observer) | |
125 { | |
126 if (started_) | |
127 { | |
128 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
129 } | |
130 | |
131 observers_.Unregister(observer); | |
132 } | |
133 | |
134 | |
135 void WidgetBase::Start() | |
136 { | |
137 if (started_) | |
138 { | |
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
140 } | |
141 else | |
142 { | |
143 started_ = true; | |
144 } | |
145 } | |
146 | |
147 | |
148 void WidgetBase::Stop() | |
149 { | |
150 if (started_) | |
151 { | |
152 started_ = false; | |
153 } | |
154 else | |
155 { | |
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
157 } | |
158 } | |
159 | |
160 | |
161 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) | 148 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) |
162 { | 149 { |
163 if (!started_) | |
164 { | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
166 } | |
167 | |
168 #if 0 | 150 #if 0 |
169 ClearBackgroundOrthanc(surface); | 151 ClearBackgroundOrthanc(surface); |
170 #else | 152 #else |
171 ClearBackgroundCairo(surface); // Faster than Orthanc | 153 ClearBackgroundCairo(surface); // Faster than Orthanc |
172 #endif | 154 #endif |