diff options
Diffstat (limited to 'src/FbTk/MenuItem.cc')
-rw-r--r-- | src/FbTk/MenuItem.cc | 80 |
1 files changed, 76 insertions, 4 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 |