Mercurial > hg > orthanc-stone
annotate Framework/Widgets/WidgetBase.cpp @ 60:288c948199e5 wasm
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 May 2017 16:10:47 +0200 |
parents | 25befef48c35 |
children | ca644004d2ee |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "WidgetBase.h" | |
23 | |
16 | 24 #include "../../Resources/Orthanc/Core/OrthancException.h" |
25 #include "../../Resources/Orthanc/Core/Images/ImageProcessing.h" | |
26 #include "../../Resources/Orthanc/Core/Logging.h" | |
0 | 27 |
28 namespace OrthancStone | |
29 { | |
30 void WidgetBase::ClearBackgroundOrthanc(Orthanc::ImageAccessor& target) const | |
31 { | |
32 // Clear the background using Orthanc | |
33 | |
34 if (backgroundCleared_) | |
35 { | |
36 Orthanc::ImageProcessing::Set(target, | |
37 backgroundColor_[0], | |
38 backgroundColor_[1], | |
39 backgroundColor_[2], | |
40 255 /* alpha */); | |
41 } | |
42 } | |
43 | |
44 | |
45 void WidgetBase::ClearBackgroundCairo(CairoContext& context) const | |
46 { | |
47 // Clear the background using Cairo | |
48 | |
49 if (IsBackgroundCleared()) | |
50 { | |
51 uint8_t red, green, blue; | |
52 GetBackgroundColor(red, green, blue); | |
53 | |
54 context.SetSourceColor(red, green, blue); | |
55 cairo_paint(context.GetObject()); | |
56 } | |
57 } | |
58 | |
59 | |
60 void WidgetBase::ClearBackgroundCairo(Orthanc::ImageAccessor& target) const | |
61 { | |
62 CairoSurface surface(target); | |
63 CairoContext context(surface); | |
64 ClearBackgroundCairo(context); | |
65 } | |
66 | |
67 | |
68 void WidgetBase::NotifyChange() | |
69 { | |
70 observers_.NotifyChange(this); | |
71 } | |
72 | |
73 | |
74 void WidgetBase::UpdateStatusBar(const std::string& message) | |
75 { | |
76 if (statusBar_ != NULL) | |
77 { | |
78 statusBar_->SetMessage(message); | |
79 } | |
80 } | |
81 | |
82 | |
83 WidgetBase::WidgetBase() : | |
84 statusBar_(NULL), | |
85 started_(false), | |
86 backgroundCleared_(false) | |
87 { | |
88 backgroundColor_[0] = 0; | |
89 backgroundColor_[1] = 0; | |
90 backgroundColor_[2] = 0; | |
91 } | |
92 | |
93 | |
94 void WidgetBase::SetBackgroundColor(uint8_t red, | |
95 uint8_t green, | |
96 uint8_t blue) | |
97 { | |
98 backgroundColor_[0] = red; | |
99 backgroundColor_[1] = green; | |
100 backgroundColor_[2] = blue; | |
101 } | |
102 | |
103 void WidgetBase::GetBackgroundColor(uint8_t& red, | |
104 uint8_t& green, | |
105 uint8_t& blue) const | |
106 { | |
107 red = backgroundColor_[0]; | |
108 green = backgroundColor_[1]; | |
109 blue = backgroundColor_[2]; | |
110 } | |
111 | |
112 | |
113 void WidgetBase::Register(IChangeObserver& observer) | |
114 { | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
115 if (started_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
116 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
118 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
119 |
0 | 120 observers_.Register(observer); |
121 } | |
122 | |
123 | |
124 void WidgetBase::Unregister(IChangeObserver& observer) | |
125 { | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
126 if (started_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
127 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
128 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
129 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
130 |
0 | 131 observers_.Unregister(observer); |
132 } | |
133 | |
134 | |
135 void WidgetBase::Start() | |
136 { | |
137 if (started_) | |
138 { | |
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
140 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
141 else |
0 | 142 { |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
143 started_ = true; |
0 | 144 } |
145 } | |
146 | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
147 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
148 void WidgetBase::Stop() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
149 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
150 if (started_) |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
151 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
152 started_ = false; |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
153 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
154 else |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
155 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
157 } |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
158 } |
0 | 159 |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
160 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
161 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) |
0 | 162 { |
163 if (!started_) | |
164 { | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
166 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
167 |
0 | 168 #if 0 |
169 ClearBackgroundOrthanc(surface); | |
170 #else | |
171 ClearBackgroundCairo(surface); // Faster than Orthanc | |
172 #endif | |
173 | |
174 return true; | |
175 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
176 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
177 |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
178 void WidgetBase::UpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
179 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
181 } |
0 | 182 } |