Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Widgets/WidgetBase.cpp @ 732:c35e98d22764
move Deprecated classes to a separate folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 14:27:35 +0200 |
parents | Framework/Widgets/WidgetBase.cpp@4f2416d519b4 |
children | 2d8ab34c8c91 |
comparison
equal
deleted
inserted
replaced
729:529189f399ec | 732:c35e98d22764 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
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. | |
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 | |
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 | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "WidgetBase.h" | |
23 | |
24 #include <Core/OrthancException.h> | |
25 #include <Core/Images/ImageProcessing.h> | |
26 #include <Core/Logging.h> | |
27 | |
28 namespace Deprecated | |
29 { | |
30 void WidgetBase::NotifyContentChanged() | |
31 { | |
32 if (parent_ != NULL) | |
33 { | |
34 parent_->NotifyContentChanged(); | |
35 } | |
36 | |
37 if (viewport_ != NULL) | |
38 { | |
39 viewport_->NotifyBackgroundChanged(); | |
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 | |
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(OrthancStone::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 OrthancStone::CairoSurface surface(target, false /* no alpha */); | |
90 OrthancStone::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(const std::string& name) : | |
105 parent_(NULL), | |
106 viewport_(NULL), | |
107 statusBar_(NULL), | |
108 backgroundCleared_(false), | |
109 transmitMouseOver_(false), | |
110 name_(name) | |
111 { | |
112 backgroundColor_[0] = 0; | |
113 backgroundColor_[1] = 0; | |
114 backgroundColor_[2] = 0; | |
115 } | |
116 | |
117 | |
118 void WidgetBase::SetViewport(WidgetViewport& viewport) | |
119 { | |
120 if (viewport_ != NULL) | |
121 { | |
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
123 } | |
124 else | |
125 { | |
126 viewport_ = &viewport; | |
127 } | |
128 } | |
129 | |
130 | |
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 } | |
160 | |
161 | |
162 void WidgetBase::DoAnimation() | |
163 { | |
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
165 } | |
166 } |