diff options
-rw-r--r-- | src/WinButton.cc | 117 |
1 files changed, 35 insertions, 82 deletions
diff --git a/src/WinButton.cc b/src/WinButton.cc index 078daa9..01684fb 100644 --- a/src/WinButton.cc +++ b/src/WinButton.cc | |||
@@ -19,55 +19,13 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | /// $Id: WinButton.cc,v 1.8 2003/08/13 10:14:54 fluxgen Exp $ | 22 | /// $Id: WinButton.cc,v 1.9 2003/08/22 15:04:18 fluxgen Exp $ |
23 | 23 | ||
24 | #include "WinButton.hh" | 24 | #include "WinButton.hh" |
25 | #include "App.hh" | 25 | #include "App.hh" |
26 | #include "Window.hh" | 26 | #include "Window.hh" |
27 | #include "WinButtonTheme.hh" | 27 | #include "WinButtonTheme.hh" |
28 | 28 | ||
29 | namespace { | ||
30 | |||
31 | inline void scale(const FbTk::Button &btn, WinButtonTheme::PixmapWithMask &pm) { | ||
32 | // copy pixmap and scale it | ||
33 | pm.pixmap_scaled = pm.pixmap; | ||
34 | pm.mask_scaled = pm.mask; | ||
35 | |||
36 | if (pm.pixmap_scaled.drawable() != 0) | ||
37 | pm.pixmap_scaled.scale(btn.width(), btn.height()); | ||
38 | if (pm.mask_scaled.drawable() != 0) | ||
39 | pm.mask_scaled.scale(btn.width(), btn.height()); | ||
40 | } | ||
41 | |||
42 | void updateScale(const FbTk::Button &btn, WinButtonTheme &theme) { | ||
43 | |||
44 | // we need to scale our pixmaps to right size | ||
45 | scale(btn, theme.closePixmap()); | ||
46 | scale(btn, theme.closeUnfocusPixmap()); | ||
47 | scale(btn, theme.closePressedPixmap()); | ||
48 | |||
49 | scale(btn, theme.maximizePixmap()); | ||
50 | scale(btn, theme.maximizeUnfocusPixmap()); | ||
51 | scale(btn, theme.maximizePressedPixmap()); | ||
52 | |||
53 | scale(btn, theme.iconifyPixmap()); | ||
54 | scale(btn, theme.iconifyUnfocusPixmap()); | ||
55 | scale(btn, theme.iconifyPressedPixmap()); | ||
56 | |||
57 | scale(btn, theme.shadePixmap()); | ||
58 | scale(btn, theme.shadeUnfocusPixmap()); | ||
59 | scale(btn, theme.shadePressedPixmap()); | ||
60 | |||
61 | scale(btn, theme.stickPixmap()); | ||
62 | scale(btn, theme.stickUnfocusPixmap()); | ||
63 | scale(btn, theme.stickPressedPixmap()); | ||
64 | |||
65 | scale(btn, theme.stuckPixmap()); | ||
66 | scale(btn, theme.stuckUnfocusPixmap()); | ||
67 | } | ||
68 | |||
69 | }; | ||
70 | |||
71 | WinButton::WinButton(const FluxboxWindow &listen_to, | 29 | WinButton::WinButton(const FluxboxWindow &listen_to, |
72 | WinButtonTheme &theme, | 30 | WinButtonTheme &theme, |
73 | Type buttontype, const FbTk::FbWindow &parent, | 31 | Type buttontype, const FbTk::FbWindow &parent, |
@@ -94,23 +52,23 @@ void WinButton::drawType() { | |||
94 | 52 | ||
95 | switch (m_type) { | 53 | switch (m_type) { |
96 | case MAXIMIZE: | 54 | case MAXIMIZE: |
97 | if (m_theme.maximizePixmap().pixmap_scaled.drawable() != 0) { | 55 | if (m_theme.maximizePixmap().pixmap.drawable() != 0) { |
98 | if (pressed()) { | 56 | if (pressed()) { |
99 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 57 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
100 | maximizePressedPixmap(). | 58 | maximizePressedPixmap(). |
101 | pixmap_scaled.drawable()); | 59 | pixmap.drawable()); |
102 | } else if (m_theme.maximizePixmap().pixmap_scaled.drawable()) { | 60 | } else if (m_theme.maximizePixmap().pixmap.drawable()) { |
103 | // check focus | 61 | // check focus |
104 | if (!m_listen_to.isFocused() && | 62 | if (!m_listen_to.isFocused() && |
105 | m_theme.maximizeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 63 | m_theme.maximizeUnfocusPixmap().pixmap.drawable() != 0) { |
106 | // not focused | 64 | // not focused |
107 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 65 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
108 | maximizeUnfocusPixmap(). | 66 | maximizeUnfocusPixmap(). |
109 | pixmap_scaled.drawable()); | 67 | pixmap.drawable()); |
110 | } else { // focused | 68 | } else { // focused |
111 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 69 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
112 | maximizePixmap(). | 70 | maximizePixmap(). |
113 | pixmap_scaled.drawable()); | 71 | pixmap.drawable()); |
114 | } | 72 | } |
115 | } | 73 | } |
116 | 74 | ||
@@ -126,23 +84,23 @@ void WinButton::drawType() { | |||
126 | } | 84 | } |
127 | break; | 85 | break; |
128 | case MINIMIZE: | 86 | case MINIMIZE: |
129 | if (m_theme.iconifyPixmap().pixmap_scaled.drawable() != 0) { | 87 | if (m_theme.iconifyPixmap().pixmap.drawable() != 0) { |
130 | if (pressed()) { | 88 | if (pressed()) { |
131 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 89 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
132 | iconifyPressedPixmap(). | 90 | iconifyPressedPixmap(). |
133 | pixmap_scaled.drawable()); | 91 | pixmap.drawable()); |
134 | } else if (m_theme.iconifyPixmap().pixmap_scaled.drawable()){ | 92 | } else if (m_theme.iconifyPixmap().pixmap.drawable()){ |
135 | // check focus | 93 | // check focus |
136 | if (!m_listen_to.isFocused() && | 94 | if (!m_listen_to.isFocused() && |
137 | m_theme.iconifyUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 95 | m_theme.iconifyUnfocusPixmap().pixmap.drawable() != 0) { |
138 | // not focused | 96 | // not focused |
139 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 97 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
140 | iconifyUnfocusPixmap(). | 98 | iconifyUnfocusPixmap(). |
141 | pixmap_scaled.drawable()); | 99 | pixmap.drawable()); |
142 | } else { // focused | 100 | } else { // focused |
143 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 101 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
144 | iconifyPixmap(). | 102 | iconifyPixmap(). |
145 | pixmap_scaled.drawable()); | 103 | pixmap.drawable()); |
146 | } | 104 | } |
147 | } | 105 | } |
148 | 106 | ||
@@ -156,41 +114,41 @@ void WinButton::drawType() { | |||
156 | } | 114 | } |
157 | break; | 115 | break; |
158 | case STICK: | 116 | case STICK: |
159 | if (m_theme.stickPixmap().pixmap_scaled.drawable() != 0) { | 117 | if (m_theme.stickPixmap().pixmap.drawable() != 0) { |
160 | if (m_listen_to.isStuck() && | 118 | if (m_listen_to.isStuck() && |
161 | m_theme.stuckPixmap().pixmap_scaled.drawable() && | 119 | m_theme.stuckPixmap().pixmap.drawable() && |
162 | ! pressed()) { // we're using the same pixmap for pressed as in not stuck | 120 | ! pressed()) { // we're using the same pixmap for pressed as in not stuck |
163 | // check focus | 121 | // check focus |
164 | if (!m_listen_to.isFocused() && | 122 | if (!m_listen_to.isFocused() && |
165 | m_theme.stuckUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 123 | m_theme.stuckUnfocusPixmap().pixmap.drawable() != 0) { |
166 | // not focused | 124 | // not focused |
167 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 125 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
168 | stuckUnfocusPixmap(). | 126 | stuckUnfocusPixmap(). |
169 | pixmap_scaled.drawable()); | 127 | pixmap.drawable()); |
170 | } else { // focused | 128 | } else { // focused |
171 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 129 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
172 | stuckPixmap(). | 130 | stuckPixmap(). |
173 | pixmap_scaled.drawable()); | 131 | pixmap.drawable()); |
174 | } | 132 | } |
175 | } else { // not stuck | 133 | } else { // not stuck |
176 | 134 | ||
177 | if (pressed()) { | 135 | if (pressed()) { |
178 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 136 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
179 | stickPressedPixmap(). | 137 | stickPressedPixmap(). |
180 | pixmap_scaled.drawable()); | 138 | pixmap.drawable()); |
181 | 139 | ||
182 | } else if (m_theme.stickPixmap().pixmap_scaled.drawable()) { | 140 | } else if (m_theme.stickPixmap().pixmap.drawable()) { |
183 | // check focus | 141 | // check focus |
184 | if (!m_listen_to.isFocused() && | 142 | if (!m_listen_to.isFocused() && |
185 | m_theme.stickUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 143 | m_theme.stickUnfocusPixmap().pixmap.drawable() != 0) { |
186 | // not focused | 144 | // not focused |
187 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 145 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
188 | stickUnfocusPixmap(). | 146 | stickUnfocusPixmap(). |
189 | pixmap_scaled.drawable()); | 147 | pixmap.drawable()); |
190 | } else { // focused | 148 | } else { // focused |
191 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 149 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
192 | stickPixmap(). | 150 | stickPixmap(). |
193 | pixmap_scaled.drawable()); | 151 | pixmap.drawable()); |
194 | } | 152 | } |
195 | 153 | ||
196 | } | 154 | } |
@@ -214,24 +172,24 @@ void WinButton::drawType() { | |||
214 | break; | 172 | break; |
215 | case CLOSE: | 173 | case CLOSE: |
216 | 174 | ||
217 | if (m_theme.closePixmap().pixmap_scaled.drawable() != 0) { | 175 | if (m_theme.closePixmap().pixmap.drawable() != 0) { |
218 | if (pressed()) { | 176 | if (pressed()) { |
219 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 177 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
220 | closePressedPixmap(). | 178 | closePressedPixmap(). |
221 | pixmap_scaled.drawable()); | 179 | pixmap.drawable()); |
222 | 180 | ||
223 | } else if (m_theme.closePixmap().pixmap_scaled.drawable()) { | 181 | } else if (m_theme.closePixmap().pixmap.drawable()) { |
224 | // check focus | 182 | // check focus |
225 | if (!m_listen_to.isFocused() && | 183 | if (!m_listen_to.isFocused() && |
226 | m_theme.closeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 184 | m_theme.closeUnfocusPixmap().pixmap.drawable() != 0) { |
227 | // not focused | 185 | // not focused |
228 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 186 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
229 | closeUnfocusPixmap(). | 187 | closeUnfocusPixmap(). |
230 | pixmap_scaled.drawable()); | 188 | pixmap.drawable()); |
231 | } else { // focused | 189 | } else { // focused |
232 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 190 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
233 | closePixmap(). | 191 | closePixmap(). |
234 | pixmap_scaled.drawable()); | 192 | pixmap.drawable()); |
235 | } | 193 | } |
236 | } | 194 | } |
237 | 195 | ||
@@ -249,23 +207,23 @@ void WinButton::drawType() { | |||
249 | } | 207 | } |
250 | break; | 208 | break; |
251 | case SHADE: | 209 | case SHADE: |
252 | if (m_theme.shadePixmap().pixmap_scaled.drawable() != 0) { | 210 | if (m_theme.shadePixmap().pixmap.drawable() != 0) { |
253 | if (pressed()) { | 211 | if (pressed()) { |
254 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 212 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
255 | shadePressedPixmap(). | 213 | shadePressedPixmap(). |
256 | pixmap_scaled.drawable()); | 214 | pixmap.drawable()); |
257 | } else if (m_theme.shadePixmap().pixmap_scaled.drawable()) { | 215 | } else if (m_theme.shadePixmap().pixmap.drawable()) { |
258 | // check focus | 216 | // check focus |
259 | if (!m_listen_to.isFocused() && | 217 | if (!m_listen_to.isFocused() && |
260 | m_theme.shadeUnfocusPixmap().pixmap_scaled.drawable() != 0) { | 218 | m_theme.shadeUnfocusPixmap().pixmap.drawable() != 0) { |
261 | // not focused | 219 | // not focused |
262 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 220 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
263 | shadeUnfocusPixmap(). | 221 | shadeUnfocusPixmap(). |
264 | pixmap_scaled.drawable()); | 222 | pixmap.drawable()); |
265 | } else { // focused | 223 | } else { // focused |
266 | FbTk::FbWindow::setBackgroundPixmap(m_theme. | 224 | FbTk::FbWindow::setBackgroundPixmap(m_theme. |
267 | shadePixmap(). | 225 | shadePixmap(). |
268 | pixmap_scaled.drawable()); | 226 | pixmap.drawable()); |
269 | } | 227 | } |
270 | } | 228 | } |
271 | 229 | ||
@@ -282,10 +240,5 @@ void WinButton::clear() { | |||
282 | 240 | ||
283 | void WinButton::update(FbTk::Subject *subj) { | 241 | void WinButton::update(FbTk::Subject *subj) { |
284 | clear(); | 242 | clear(); |
285 | |||
286 | //!! TODO | ||
287 | // We need to optimize this | ||
288 | // This shouldn't be run on every button in every fluxbox window | ||
289 | updateScale(*this, m_theme); | ||
290 | drawType(); | 243 | drawType(); |
291 | } | 244 | } |