Mercurial > hg > orthanc-stone
annotate Framework/Widgets/WidgetBase.cpp @ 253:8ff70c04c6df am-2
IObservable/IObserver now working in WASM too
author | am@osimis.io |
---|---|
date | Tue, 03 Jul 2018 10:48:47 +0200 |
parents | 5412adf19980 |
children | f21ba2468570 |
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 | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., 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 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
24 #include <Core/OrthancException.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
25 #include <Core/Images/ImageProcessing.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/Logging.h> |
0 | 27 |
28 namespace OrthancStone | |
29 { | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
30 void WidgetBase::NotifyChange() |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
31 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
32 if (parent_ != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
33 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
34 parent_->NotifyChange(); |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
35 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
36 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
37 if (viewport_ != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
38 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
39 viewport_->NotifyChange(*this); |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
40 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
41 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
42 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
43 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
44 void WidgetBase::SetParent(IWidget& parent) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
45 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
46 if (parent_ != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
47 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
49 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
50 else |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
51 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
52 parent_ = &parent; |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
53 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
54 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
55 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
56 |
0 | 57 void WidgetBase::ClearBackgroundOrthanc(Orthanc::ImageAccessor& target) const |
58 { | |
59 // Clear the background using Orthanc | |
60 | |
61 if (backgroundCleared_) | |
62 { | |
63 Orthanc::ImageProcessing::Set(target, | |
64 backgroundColor_[0], | |
65 backgroundColor_[1], | |
66 backgroundColor_[2], | |
67 255 /* alpha */); | |
68 } | |
69 } | |
70 | |
71 | |
72 void WidgetBase::ClearBackgroundCairo(CairoContext& context) const | |
73 { | |
74 // Clear the background using Cairo | |
75 | |
76 if (IsBackgroundCleared()) | |
77 { | |
78 uint8_t red, green, blue; | |
79 GetBackgroundColor(red, green, blue); | |
80 | |
81 context.SetSourceColor(red, green, blue); | |
82 cairo_paint(context.GetObject()); | |
83 } | |
84 } | |
85 | |
86 | |
87 void WidgetBase::ClearBackgroundCairo(Orthanc::ImageAccessor& target) const | |
88 { | |
89 CairoSurface surface(target); | |
90 CairoContext context(surface); | |
91 ClearBackgroundCairo(context); | |
92 } | |
93 | |
94 | |
95 void WidgetBase::UpdateStatusBar(const std::string& message) | |
96 { | |
97 if (statusBar_ != NULL) | |
98 { | |
99 statusBar_->SetMessage(message); | |
100 } | |
101 } | |
102 | |
103 | |
104 WidgetBase::WidgetBase() : | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
105 parent_(NULL), |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
106 viewport_(NULL), |
0 | 107 statusBar_(NULL), |
85 | 108 backgroundCleared_(false), |
109 transmitMouseOver_(false) | |
0 | 110 { |
111 backgroundColor_[0] = 0; | |
112 backgroundColor_[1] = 0; | |
113 backgroundColor_[2] = 0; | |
114 } | |
115 | |
116 | |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
117 void WidgetBase::SetViewport(IViewport& viewport) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
118 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
119 if (viewport_ != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
120 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
122 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
123 else |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
124 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
125 viewport_ = &viewport; |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
126 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
127 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
128 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
129 |
0 | 130 void WidgetBase::SetBackgroundColor(uint8_t red, |
131 uint8_t green, | |
132 uint8_t blue) | |
133 { | |
134 backgroundColor_[0] = red; | |
135 backgroundColor_[1] = green; | |
136 backgroundColor_[2] = blue; | |
137 } | |
138 | |
139 void WidgetBase::GetBackgroundColor(uint8_t& red, | |
140 uint8_t& green, | |
141 uint8_t& blue) const | |
142 { | |
143 red = backgroundColor_[0]; | |
144 green = backgroundColor_[1]; | |
145 blue = backgroundColor_[2]; | |
146 } | |
147 | |
148 | |
149 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) | |
150 { | |
151 #if 0 | |
152 ClearBackgroundOrthanc(surface); | |
153 #else | |
154 ClearBackgroundCairo(surface); // Faster than Orthanc | |
155 #endif | |
156 | |
157 return true; | |
158 } | |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
159 |
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 void WidgetBase::UpdateContent() |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
162 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
163 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
164 } |
0 | 165 } |