diff options
author | fluxgen <fluxgen> | 2003-04-28 22:41:28 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-04-28 22:41:28 (GMT) |
commit | 3f62d0e80817935d071ff4074e282cdb9fb438fb (patch) | |
tree | 01f0415d75927c7175c440bead8b728da608c624 | |
parent | a61595347703bc21f8edefa7ca9c9d0453fef8f8 (diff) | |
download | fluxbox_paul-3f62d0e80817935d071ff4074e282cdb9fb438fb.zip fluxbox_paul-3f62d0e80817935d071ff4074e282cdb9fb438fb.tar.bz2 |
added WinButtonTheme with pixmap support
-rw-r--r-- | src/WinButton.cc | 174 |
1 files changed, 149 insertions, 25 deletions
diff --git a/src/WinButton.cc b/src/WinButton.cc index 0756515..650f312 100644 --- a/src/WinButton.cc +++ b/src/WinButton.cc | |||
@@ -19,19 +19,55 @@ | |||
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.3 2003/04/25 17:35:28 fluxgen Exp $ | 22 | /// $Id: WinButton.cc,v 1.4 2003/04/28 22:41:28 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" | ||
28 | |||
29 | #include <iostream> | ||
30 | using namespace std; | ||
31 | |||
32 | namespace { | ||
33 | |||
34 | inline void scale(const FbTk::Button &btn, WinButtonTheme::PixmapWithMask &pm) { | ||
35 | // copy pixmap and scale it | ||
36 | pm.pixmap_scaled = pm.pixmap; | ||
37 | pm.mask_scaled = pm.mask; | ||
38 | |||
39 | if (pm.pixmap_scaled.drawable() != 0) | ||
40 | pm.pixmap_scaled.scale(btn.width(), btn.height()); | ||
41 | if (pm.mask_scaled.drawable() != 0) | ||
42 | pm.mask_scaled.scale(btn.width(), btn.height()); | ||
43 | } | ||
44 | |||
45 | void updateScale(const FbTk::Button &btn, WinButtonTheme &theme) { | ||
46 | |||
47 | // we need to scale our pixmaps to right size | ||
48 | scale(btn, theme.closePixmap()); | ||
49 | scale(btn, theme.closePressedPixmap()); | ||
50 | scale(btn, theme.maximizePixmap()); | ||
51 | scale(btn, theme.maximizePressedPixmap()); | ||
52 | scale(btn, theme.iconifyPixmap()); | ||
53 | scale(btn, theme.iconifyPressedPixmap()); | ||
54 | scale(btn, theme.shadePixmap()); | ||
55 | scale(btn, theme.shadePressedPixmap()); | ||
56 | scale(btn, theme.stickPixmap()); | ||
57 | scale(btn, theme.stickPressedPixmap()); | ||
58 | } | ||
59 | |||
60 | }; | ||
27 | 61 | ||
28 | WinButton::WinButton(const FluxboxWindow &listen_to, | 62 | WinButton::WinButton(const FluxboxWindow &listen_to, |
63 | WinButtonTheme &theme, | ||
29 | Type buttontype, const FbTk::FbWindow &parent, | 64 | Type buttontype, const FbTk::FbWindow &parent, |
30 | int x, int y, | 65 | int x, int y, |
31 | unsigned int width, unsigned int height): | 66 | unsigned int width, unsigned int height): |
32 | FbTk::Button(parent, x, y, width, height), | 67 | FbTk::Button(parent, x, y, width, height), |
33 | m_type(buttontype), m_listen_to(listen_to) { | 68 | m_type(buttontype), m_listen_to(listen_to), m_theme(theme) { |
34 | 69 | ||
70 | theme.reconfigSig().attach(this); | ||
35 | } | 71 | } |
36 | 72 | ||
37 | void WinButton::exposeEvent(XExposeEvent &event) { | 73 | void WinButton::exposeEvent(XExposeEvent &event) { |
@@ -45,41 +81,123 @@ void WinButton::buttonReleaseEvent(XButtonEvent &event) { | |||
45 | } | 81 | } |
46 | 82 | ||
47 | void WinButton::drawType() { | 83 | void WinButton::drawType() { |
48 | if (gc() == 0) // must have valid graphic context | 84 | |
49 | return; | ||
50 | 85 | ||
51 | switch (m_type) { | 86 | switch (m_type) { |
52 | case MAXIMIZE: | 87 | case MAXIMIZE: |
53 | window().drawRectangle(gc(), | 88 | if (m_theme.maximizePixmap().pixmap_scaled.drawable() != 0) { |
54 | 2, 2, width() - 5, height() - 5); | 89 | if (pressed()) { |
55 | window().drawLine(gc(), | 90 | window().setBackgroundPixmap(m_theme. |
56 | 2, 3, width() - 3, 3); | 91 | maximizePressedPixmap(). |
92 | pixmap_scaled.drawable()); | ||
93 | } else if (m_theme.maximizePixmap().pixmap_scaled.drawable()) { | ||
94 | window().setBackgroundPixmap(m_theme. | ||
95 | maximizePixmap(). | ||
96 | pixmap_scaled.drawable()); | ||
97 | } | ||
98 | |||
99 | window().clear(); | ||
100 | |||
101 | } else { | ||
102 | if (gc() == 0) // must have valid graphic context | ||
103 | return; | ||
104 | window().drawRectangle(gc(), | ||
105 | 2, 2, width() - 5, height() - 5); | ||
106 | window().drawLine(gc(), | ||
107 | 2, 3, width() - 3, 3); | ||
108 | } | ||
57 | break; | 109 | break; |
58 | case MINIMIZE: | 110 | case MINIMIZE: |
59 | window().drawRectangle(gc(), | 111 | if (m_theme.iconifyPixmap().pixmap_scaled.drawable() != 0) { |
60 | 2, height() - 5, width() - 5, 2); | 112 | if (pressed()) { |
113 | window().setBackgroundPixmap(m_theme. | ||
114 | iconifyPressedPixmap(). | ||
115 | pixmap_scaled.drawable()); | ||
116 | } else if (m_theme.iconifyPixmap().pixmap_scaled.drawable()){ | ||
117 | window().setBackgroundPixmap(m_theme. | ||
118 | iconifyPixmap(). | ||
119 | pixmap_scaled.drawable()); | ||
120 | } | ||
121 | |||
122 | window().clear(); | ||
123 | |||
124 | } else { | ||
125 | if (gc() == 0) // must have valid graphic context | ||
126 | return; | ||
127 | window().drawRectangle(gc(), | ||
128 | 2, height() - 5, width() - 5, 2); | ||
129 | } | ||
61 | break; | 130 | break; |
62 | case STICK: | 131 | case STICK: |
63 | if (m_listen_to.isStuck()) { | 132 | if (m_theme.stickPixmap().pixmap_scaled.drawable() != 0) { |
64 | window().fillRectangle(gc(), | 133 | if (pressed()) { |
65 | width()/2 - width()/4, height()/2 - height()/4, | 134 | window().setBackgroundPixmap(m_theme. |
66 | width()/2, height()/2); | 135 | stickPressedPixmap(). |
136 | pixmap_scaled.drawable()); | ||
137 | |||
138 | } else if (m_theme.closePixmap().pixmap_scaled.drawable()) { | ||
139 | window().setBackgroundPixmap(m_theme. | ||
140 | stickPixmap(). | ||
141 | pixmap_scaled.drawable()); | ||
142 | } | ||
143 | |||
144 | window().clear(); | ||
145 | |||
67 | } else { | 146 | } else { |
68 | window().fillRectangle(gc(), | 147 | if (m_listen_to.isStuck()) { |
69 | width()/2, height()/2, | 148 | window().fillRectangle(gc(), |
70 | width()/5, height()/5); | 149 | width()/2 - width()/4, height()/2 - height()/4, |
150 | width()/2, height()/2); | ||
151 | } else { | ||
152 | if (gc() == 0) // must have valid graphic context | ||
153 | return; | ||
154 | window().fillRectangle(gc(), | ||
155 | width()/2, height()/2, | ||
156 | width()/5, height()/5); | ||
157 | } | ||
71 | } | 158 | } |
72 | |||
73 | break; | 159 | break; |
74 | case CLOSE: | 160 | case CLOSE: |
75 | window().drawLine(gc(), | 161 | |
76 | 2, 2, | 162 | if (m_theme.closePixmap().pixmap_scaled.drawable() != 0) { |
77 | width() - 3, height() - 3); | 163 | if (pressed()) { |
78 | window().drawLine(gc(), | 164 | window().setBackgroundPixmap(m_theme. |
79 | 2, width() - 3, | 165 | closePressedPixmap(). |
80 | height() - 3, 2); | 166 | pixmap_scaled.drawable()); |
167 | |||
168 | } else if (m_theme.closePixmap().pixmap_scaled.drawable()) { | ||
169 | window().setBackgroundPixmap(m_theme. | ||
170 | closePixmap(). | ||
171 | pixmap_scaled.drawable()); | ||
172 | } | ||
173 | |||
174 | window().clear(); | ||
175 | |||
176 | } else { | ||
177 | if (gc() == 0) // must have valid graphic context | ||
178 | return; | ||
179 | window().drawLine(gc(), | ||
180 | 2, 2, | ||
181 | width() - 3, height() - 3); | ||
182 | window().drawLine(gc(), | ||
183 | 2, width() - 3, | ||
184 | height() - 3, 2); | ||
185 | } | ||
81 | break; | 186 | break; |
82 | case SHADE: | 187 | case SHADE: |
188 | if (m_theme.shadePixmap().pixmap_scaled.drawable() != 0) { | ||
189 | if (pressed()) { | ||
190 | window().setBackgroundPixmap(m_theme. | ||
191 | shadePressedPixmap(). | ||
192 | pixmap_scaled.drawable()); | ||
193 | } else if (m_theme.shadePixmap().pixmap_scaled.drawable()) { | ||
194 | window().setBackgroundPixmap(m_theme. | ||
195 | shadePixmap(). | ||
196 | pixmap_scaled.drawable()); | ||
197 | } | ||
198 | |||
199 | window().clear(); | ||
200 | } | ||
83 | break; | 201 | break; |
84 | } | 202 | } |
85 | } | 203 | } |
@@ -91,4 +209,10 @@ void WinButton::clear() { | |||
91 | 209 | ||
92 | void WinButton::update(FbTk::Subject *subj) { | 210 | void WinButton::update(FbTk::Subject *subj) { |
93 | clear(); | 211 | clear(); |
212 | |||
213 | //!! TODO | ||
214 | // We need to optimize this | ||
215 | // This shouldn't be run on every button in every fluxbox window | ||
216 | updateScale(*this, m_theme); | ||
217 | drawType(); | ||
94 | } | 218 | } |