Mercurial > hg > orthanc-stone
annotate Framework/Widgets/WidgetBase.cpp @ 489:f6b7f113cf27 bgo-commands-codegen
Ongoing work on code generation
author | bgo-osimis |
---|---|
date | Mon, 18 Feb 2019 07:46:59 +0100 |
parents | b70e9be013e4 |
children | aaeec7be8fb7 |
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 | |
439 | 5 * Copyright (C) 2017-2019 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 { | |
278 | 30 void WidgetBase::NotifyContentChanged() |
61
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 { |
278 | 34 parent_->NotifyContentChanged(); |
61
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 { |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
278
diff
changeset
|
39 viewport_->NotifyBackgroundChanged(); |
61
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 | |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
212
diff
changeset
|
104 WidgetBase::WidgetBase(const std::string& name) : |
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), |
273
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
212
diff
changeset
|
109 transmitMouseOver_(false), |
f21ba2468570
force all Widgets to have a name to ease debugging
am@osimis.io
parents:
212
diff
changeset
|
110 name_(name) |
0 | 111 { |
112 backgroundColor_[0] = 0; | |
113 backgroundColor_[1] = 0; | |
114 backgroundColor_[2] = 0; | |
115 } | |
116 | |
117 | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
278
diff
changeset
|
118 void WidgetBase::SetViewport(WidgetViewport& viewport) |
61
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
119 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
120 if (viewport_ != NULL) |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
121 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
122 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
|
123 } |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
124 else |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
125 { |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
126 viewport_ = &viewport; |
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 |
ca644004d2ee
MAJOR - removal of Start/Stop and observers in IWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
48
diff
changeset
|
130 |
0 | 131 void WidgetBase::SetBackgroundColor(uint8_t red, |
132 uint8_t green, | |
133 uint8_t blue) | |
134 { | |
135 backgroundColor_[0] = red; | |
136 backgroundColor_[1] = green; | |
137 backgroundColor_[2] = blue; | |
138 } | |
139 | |
140 void WidgetBase::GetBackgroundColor(uint8_t& red, | |
141 uint8_t& green, | |
142 uint8_t& blue) const | |
143 { | |
144 red = backgroundColor_[0]; | |
145 green = backgroundColor_[1]; | |
146 blue = backgroundColor_[2]; | |
147 } | |
148 | |
149 | |
150 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) | |
151 { | |
152 #if 0 | |
153 ClearBackgroundOrthanc(surface); | |
154 #else | |
155 ClearBackgroundCairo(surface); // Faster than Orthanc | |
156 #endif | |
157 | |
158 return true; | |
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 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
162 void WidgetBase::DoAnimation() |
46
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
163 { |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
766d31dc5716
removing threads for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
40
diff
changeset
|
165 } |
0 | 166 } |