diff options
author | fluxgen <fluxgen> | 2004-06-10 11:40:43 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-06-10 11:40:43 (GMT) |
commit | af30481a47f13a27251b6ab0e4cff66f924f326a (patch) | |
tree | 267d4f442ab630710d05f776de72c483f0a2199a /src | |
parent | d07e5f1cc5ba47f3200a85065cfacedd83b3db4f (diff) | |
download | fluxbox_paul-af30481a47f13a27251b6ab0e4cff66f924f326a.zip fluxbox_paul-af30481a47f13a27251b6ab0e4cff66f924f326a.tar.bz2 |
icon in menu item
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/MenuItem.cc | 80 | ||||
-rw-r--r-- | src/FbTk/MenuItem.hh | 17 |
2 files changed, 89 insertions, 8 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc index 55aef9a..0d5989f 100644 --- a/src/FbTk/MenuItem.cc +++ b/src/FbTk/MenuItem.cc | |||
@@ -19,12 +19,14 @@ | |||
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: MenuItem.cc,v 1.2 2004/06/07 20:34:23 fluxgen Exp $ | 22 | // $Id: MenuItem.cc,v 1.3 2004/06/10 11:40:43 fluxgen Exp $ |
23 | 23 | ||
24 | #include "MenuItem.hh" | 24 | #include "MenuItem.hh" |
25 | #include "Command.hh" | 25 | #include "Command.hh" |
26 | #include "GContext.hh" | 26 | #include "GContext.hh" |
27 | #include "MenuTheme.hh" | 27 | #include "MenuTheme.hh" |
28 | #include "PixmapWithMask.hh" | ||
29 | #include "Image.hh" | ||
28 | #include "App.hh" | 30 | #include "App.hh" |
29 | 31 | ||
30 | namespace FbTk { | 32 | namespace FbTk { |
@@ -39,12 +41,51 @@ void MenuItem::draw(FbDrawable &draw, | |||
39 | bool highlight, | 41 | bool highlight, |
40 | int x, int y, | 42 | int x, int y, |
41 | unsigned int width, unsigned int height) const { | 43 | unsigned int width, unsigned int height) const { |
44 | // | ||
45 | // Icon | ||
46 | // | ||
47 | if (m_icon.get() != 0 && m_icon->pixmap.get() != 0) { | ||
48 | // scale pixmap to right size | ||
49 | if (height - 2*theme.bevelWidth() != m_icon->pixmap->height() && | ||
50 | !m_icon->filename.empty()) { | ||
51 | unsigned int scale_size = height - 2*theme.bevelWidth(); | ||
52 | m_icon->pixmap->scale(scale_size, scale_size); | ||
53 | } | ||
54 | |||
55 | if (m_icon->pixmap->pixmap().drawable() != 0) { | ||
56 | GC gc = theme.frameTextGC().gc(); | ||
57 | int icon_x = x + theme.bevelWidth(); | ||
58 | int icon_y = y + theme.bevelWidth(); | ||
59 | // enable clip mask | ||
60 | XSetClipMask(FbTk::App::instance()->display(), | ||
61 | gc, | ||
62 | m_icon->pixmap->mask().drawable()); | ||
63 | XSetClipOrigin(FbTk::App::instance()->display(), | ||
64 | gc, icon_x, icon_y); | ||
65 | |||
66 | draw.copyArea(m_icon->pixmap->pixmap().drawable(), | ||
67 | gc, | ||
68 | 0, 0, | ||
69 | icon_x, icon_y, | ||
70 | m_icon->pixmap->width(), m_icon->pixmap->height()); | ||
71 | |||
72 | // restore clip mask | ||
73 | XSetClipMask(FbTk::App::instance()->display(), | ||
74 | gc, | ||
75 | None); | ||
76 | } | ||
77 | |||
78 | } | ||
79 | |||
42 | if (label().empty()) | 80 | if (label().empty()) |
43 | return; | 81 | return; |
44 | 82 | ||
45 | const GContext &tgc = | 83 | const GContext &tgc = |
46 | (highlight ? theme.hiliteTextGC() : | 84 | (highlight ? theme.hiliteTextGC() : |
47 | (isEnabled() ? theme.frameTextGC() : theme.disableTextGC() ) ); | 85 | (isEnabled() ? theme.frameTextGC() : theme.disableTextGC() ) ); |
86 | // | ||
87 | // Text | ||
88 | // | ||
48 | int text_y = y, text_x = x; | 89 | int text_y = y, text_x = x; |
49 | 90 | ||
50 | int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); | 91 | int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); |
@@ -63,7 +104,7 @@ void MenuItem::draw(FbDrawable &draw, | |||
63 | text_x = x + ((width + 1 - text_w) / 2); | 104 | text_x = x + ((width + 1 - text_w) / 2); |
64 | break; | 105 | break; |
65 | } | 106 | } |
66 | 107 | ||
67 | theme.frameFont().drawText(draw.drawable(), // drawable | 108 | theme.frameFont().drawText(draw.drawable(), // drawable |
68 | theme.screenNum(), | 109 | theme.screenNum(), |
69 | tgc.gc(), | 110 | tgc.gc(), |
@@ -80,6 +121,9 @@ void MenuItem::draw(FbDrawable &draw, | |||
80 | if (theme.bulletPos() == FbTk::RIGHT) | 121 | if (theme.bulletPos() == FbTk::RIGHT) |
81 | sel_x += width - height - 2*theme.bevelWidth(); | 122 | sel_x += width - height - 2*theme.bevelWidth(); |
82 | 123 | ||
124 | // | ||
125 | // ToggleItem | ||
126 | // | ||
83 | if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) { | 127 | if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) { |
84 | XSetClipMask(FbTk::App::instance()->display(), | 128 | XSetClipMask(FbTk::App::instance()->display(), |
85 | gc, | 129 | gc, |
@@ -99,7 +143,9 @@ void MenuItem::draw(FbDrawable &draw, | |||
99 | None); | 143 | None); |
100 | } | 144 | } |
101 | 145 | ||
102 | 146 | // | |
147 | // Submenu | ||
148 | // | ||
103 | if (submenu()) { | 149 | if (submenu()) { |
104 | if (theme.bulletPixmap().pixmap().drawable() != 0) { | 150 | if (theme.bulletPixmap().pixmap().drawable() != 0) { |
105 | // enable clip mask | 151 | // enable clip mask |
@@ -171,6 +217,21 @@ void MenuItem::draw(FbDrawable &draw, | |||
171 | } | 217 | } |
172 | } | 218 | } |
173 | 219 | ||
220 | |||
221 | } | ||
222 | |||
223 | void MenuItem::setIcon(const std::string &filename, int screen_num) { | ||
224 | if (filename.empty()) { | ||
225 | if (m_icon.get() != 0) | ||
226 | m_icon.reset(0); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | if (m_icon.get() == 0) | ||
231 | m_icon.reset(new Icon); | ||
232 | |||
233 | m_icon->filename = filename; | ||
234 | m_icon->pixmap.reset(Image::load(filename.c_str(), screen_num)); | ||
174 | } | 235 | } |
175 | 236 | ||
176 | unsigned int MenuItem::height(const MenuTheme &theme) const { | 237 | unsigned int MenuItem::height(const MenuTheme &theme) const { |
@@ -179,10 +240,21 @@ unsigned int MenuItem::height(const MenuTheme &theme) const { | |||
179 | 240 | ||
180 | unsigned int MenuItem::width(const MenuTheme &theme) const { | 241 | unsigned int MenuItem::width(const MenuTheme &theme) const { |
181 | // textwidth + bevel width on each side of the text | 242 | // textwidth + bevel width on each side of the text |
182 | return theme.frameFont().textWidth(label().c_str(), label().size()) + 2*(theme.bevelWidth() + height(theme)); | 243 | int normal = theme.frameFont().textWidth(label().c_str(), label().size()) + 2*(theme.bevelWidth() + height(theme)); |
244 | if (m_icon.get() == 0) | ||
245 | return normal; | ||
246 | else | ||
247 | return normal + 2 * (theme.bevelWidth() + height(theme)); | ||
183 | 248 | ||
184 | } | 249 | } |
185 | 250 | ||
251 | void MenuItem::updateTheme(const MenuTheme &theme) { | ||
252 | if (m_icon.get() == 0) | ||
253 | return; | ||
186 | 254 | ||
255 | m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), theme.screenNum())); | ||
256 | |||
257 | |||
258 | } | ||
187 | 259 | ||
188 | }; // end namespace FbTk | 260 | }; // end namespace FbTk |
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh index 1d9ed20..efeab4d 100644 --- a/src/FbTk/MenuItem.hh +++ b/src/FbTk/MenuItem.hh | |||
@@ -1,5 +1,5 @@ | |||
1 | // MenuItem.hh for FbTk - Fluxbox Toolkit | 1 | // MenuItem.hh for FbTk - Fluxbox Toolkit |
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | 2 | // Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) |
3 | // | 3 | // |
4 | // Permission is hereby granted, free of charge, to any person obtaining a | 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
5 | // copy of this software and associated documentation files (the "Software"), | 5 | // copy of this software and associated documentation files (the "Software"), |
@@ -19,20 +19,22 @@ | |||
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: MenuItem.hh,v 1.5 2004/06/07 20:33:20 fluxgen Exp $ | 22 | // $Id: MenuItem.hh,v 1.6 2004/06/10 11:40:43 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef FBTK_MENUITEM_HH | 24 | #ifndef FBTK_MENUITEM_HH |
25 | #define FBTK_MENUITEM_HH | 25 | #define FBTK_MENUITEM_HH |
26 | 26 | ||
27 | #include "RefCount.hh" | 27 | #include "RefCount.hh" |
28 | #include "Command.hh" | 28 | #include "Command.hh" |
29 | #include <string> | ||
30 | 29 | ||
30 | #include <string> | ||
31 | #include <memory> | ||
31 | namespace FbTk { | 32 | namespace FbTk { |
32 | 33 | ||
33 | class Menu; | 34 | class Menu; |
34 | class MenuTheme; | 35 | class MenuTheme; |
35 | class FbDrawable; | 36 | class FbDrawable; |
37 | class PixmapWithMask; | ||
36 | 38 | ||
37 | /// An interface for a menu item in Menu | 39 | /// An interface for a menu item in Menu |
38 | class MenuItem { | 40 | class MenuItem { |
@@ -77,6 +79,7 @@ public: | |||
77 | virtual inline void setEnabled(bool enabled) { m_enabled = enabled; } | 79 | virtual inline void setEnabled(bool enabled) { m_enabled = enabled; } |
78 | virtual inline void setLabel(const char *label) { m_label = (label ? label : ""); } | 80 | virtual inline void setLabel(const char *label) { m_label = (label ? label : ""); } |
79 | virtual inline void setToggleItem(bool val) { m_toggle_item = val; } | 81 | virtual inline void setToggleItem(bool val) { m_toggle_item = val; } |
82 | void setIcon(const std::string &filename, int screen_num); | ||
80 | Menu *submenu() { return m_submenu; } | 83 | Menu *submenu() { return m_submenu; } |
81 | /** | 84 | /** |
82 | @name accessors | 85 | @name accessors |
@@ -94,7 +97,7 @@ public: | |||
94 | bool highlight, | 97 | bool highlight, |
95 | int x, int y, | 98 | int x, int y, |
96 | unsigned int width, unsigned int height) const; | 99 | unsigned int width, unsigned int height) const; |
97 | virtual void updateTheme(const MenuTheme &theme) { } | 100 | virtual void updateTheme(const MenuTheme &theme); |
98 | /** | 101 | /** |
99 | Called when the item was clicked with a specific button | 102 | Called when the item was clicked with a specific button |
100 | @param button the button number | 103 | @param button the button number |
@@ -111,6 +114,12 @@ private: | |||
111 | RefCount<Command> m_command; ///< command to be executed | 114 | RefCount<Command> m_command; ///< command to be executed |
112 | bool m_enabled, m_selected; | 115 | bool m_enabled, m_selected; |
113 | bool m_toggle_item; | 116 | bool m_toggle_item; |
117 | |||
118 | struct Icon { | ||
119 | std::auto_ptr<PixmapWithMask> pixmap; | ||
120 | std::string filename; | ||
121 | }; | ||
122 | std::auto_ptr<Icon> m_icon; | ||
114 | }; | 123 | }; |
115 | 124 | ||
116 | } // end namespace FbTk | 125 | } // end namespace FbTk |