diff options
Diffstat (limited to 'src/FbTk/MenuItem.cc')
-rw-r--r-- | src/FbTk/MenuItem.cc | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc index ee997bb..69a2000 100644 --- a/src/FbTk/MenuItem.cc +++ b/src/FbTk/MenuItem.cc | |||
@@ -19,7 +19,7 @@ | |||
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.8 2004/09/01 08:00:24 akir Exp $ | 22 | // $Id: MenuItem.cc,v 1.9 2004/09/10 16:48:15 akir Exp $ |
23 | 23 | ||
24 | #include "MenuItem.hh" | 24 | #include "MenuItem.hh" |
25 | #include "Command.hh" | 25 | #include "Command.hh" |
@@ -37,11 +37,13 @@ void MenuItem::click(int button, int time) { | |||
37 | m_command->execute(); | 37 | m_command->execute(); |
38 | } | 38 | } |
39 | 39 | ||
40 | void MenuItem::draw(FbDrawable &draw, | 40 | void MenuItem::draw(FbDrawable &draw, |
41 | const MenuTheme &theme, | 41 | const MenuTheme &theme, |
42 | bool highlight, | 42 | bool highlight, |
43 | int x, int y, | 43 | int x, int y, |
44 | unsigned int width, unsigned int height) const { | 44 | unsigned int width, unsigned int height) const { |
45 | |||
46 | Display *disp = App::instance()->display(); | ||
45 | // | 47 | // |
46 | // Icon | 48 | // Icon |
47 | // | 49 | // |
@@ -58,11 +60,8 @@ void MenuItem::draw(FbDrawable &draw, | |||
58 | int icon_x = x + theme.bevelWidth(); | 60 | int icon_x = x + theme.bevelWidth(); |
59 | int icon_y = y + theme.bevelWidth(); | 61 | int icon_y = y + theme.bevelWidth(); |
60 | // enable clip mask | 62 | // enable clip mask |
61 | XSetClipMask(FbTk::App::instance()->display(), | 63 | XSetClipMask(disp, gc, m_icon->pixmap->mask().drawable()); |
62 | gc, | 64 | XSetClipOrigin(disp, gc, icon_x, icon_y); |
63 | m_icon->pixmap->mask().drawable()); | ||
64 | XSetClipOrigin(FbTk::App::instance()->display(), | ||
65 | gc, icon_x, icon_y); | ||
66 | 65 | ||
67 | draw.copyArea(m_icon->pixmap->pixmap().drawable(), | 66 | draw.copyArea(m_icon->pixmap->pixmap().drawable(), |
68 | gc, | 67 | gc, |
@@ -71,9 +70,7 @@ void MenuItem::draw(FbDrawable &draw, | |||
71 | m_icon->pixmap->width(), m_icon->pixmap->height()); | 70 | m_icon->pixmap->width(), m_icon->pixmap->height()); |
72 | 71 | ||
73 | // restore clip mask | 72 | // restore clip mask |
74 | XSetClipMask(FbTk::App::instance()->display(), | 73 | XSetClipMask(disp, gc, None); |
75 | gc, | ||
76 | None); | ||
77 | } | 74 | } |
78 | 75 | ||
79 | } | 76 | } |
@@ -90,7 +87,7 @@ void MenuItem::draw(FbDrawable &draw, | |||
90 | int text_y = y, text_x = x; | 87 | int text_y = y, text_x = x; |
91 | 88 | ||
92 | int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); | 89 | int text_w = theme.frameFont().textWidth(label().c_str(), label().size()); |
93 | 90 | ||
94 | int height_offset = theme.itemHeight() - (theme.frameFont().height() + 2*theme.bevelWidth()); | 91 | int height_offset = theme.itemHeight() - (theme.frameFont().height() + 2*theme.bevelWidth()); |
95 | text_y = y + theme.bevelWidth() + theme.frameFont().ascent() + height_offset/2; ///2 + height/2; | 92 | text_y = y + theme.bevelWidth() + theme.frameFont().ascent() + height_offset/2; ///2 + height/2; |
96 | 93 | ||
@@ -98,15 +95,15 @@ void MenuItem::draw(FbDrawable &draw, | |||
98 | case FbTk::LEFT: | 95 | case FbTk::LEFT: |
99 | text_x = x + theme.bevelWidth() + height + 1; | 96 | text_x = x + theme.bevelWidth() + height + 1; |
100 | break; | 97 | break; |
101 | 98 | ||
102 | case FbTk::RIGHT: | 99 | case FbTk::RIGHT: |
103 | text_x = x + width - (height + theme.bevelWidth() + text_w); | 100 | text_x = x + width - (height + theme.bevelWidth() + text_w); |
104 | break; | 101 | break; |
105 | default: //center | 102 | default: //center |
106 | text_x = x + ((width + 1 - text_w) / 2); | 103 | text_x = x + ((width + 1 - text_w) / 2); |
107 | break; | 104 | break; |
108 | } | 105 | } |
109 | 106 | ||
110 | theme.frameFont().drawText(draw.drawable(), // drawable | 107 | theme.frameFont().drawText(draw.drawable(), // drawable |
111 | theme.screenNum(), | 108 | theme.screenNum(), |
112 | tgc.gc(), | 109 | tgc.gc(), |
@@ -127,11 +124,8 @@ void MenuItem::draw(FbDrawable &draw, | |||
127 | // ToggleItem | 124 | // ToggleItem |
128 | // | 125 | // |
129 | if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) { | 126 | if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) { |
130 | XSetClipMask(FbTk::App::instance()->display(), | 127 | XSetClipMask(disp, gc, theme.unselectedPixmap().mask().drawable()); |
131 | gc, | 128 | XSetClipOrigin(disp, gc, sel_x, y); |
132 | theme.unselectedPixmap().mask().drawable()); | ||
133 | XSetClipOrigin(FbTk::App::instance()->display(), | ||
134 | gc, sel_x, y); | ||
135 | // copy bullet pixmap to drawable | 129 | // copy bullet pixmap to drawable |
136 | draw.copyArea(theme.unselectedPixmap().pixmap().drawable(), | 130 | draw.copyArea(theme.unselectedPixmap().pixmap().drawable(), |
137 | gc, | 131 | gc, |
@@ -140,22 +134,17 @@ void MenuItem::draw(FbDrawable &draw, | |||
140 | theme.unselectedPixmap().width(), | 134 | theme.unselectedPixmap().width(), |
141 | theme.unselectedPixmap().height()); | 135 | theme.unselectedPixmap().height()); |
142 | // disable clip mask | 136 | // disable clip mask |
143 | XSetClipMask(FbTk::App::instance()->display(), | 137 | XSetClipMask(disp, gc, None); |
144 | gc, | ||
145 | None); | ||
146 | } | 138 | } |
147 | 139 | ||
148 | // | 140 | // |
149 | // Submenu | 141 | // Submenu |
150 | // | 142 | // |
151 | if (submenu()) { | 143 | if (submenu()) { |
152 | if (theme.bulletPixmap().pixmap().drawable() != 0) { | 144 | if (theme.bulletPixmap().pixmap().drawable() != 0) { |
153 | // enable clip mask | 145 | // enable clip mask |
154 | XSetClipMask(FbTk::App::instance()->display(), | 146 | XSetClipMask(disp, gc, theme.bulletPixmap().mask().drawable()); |
155 | gc, | 147 | XSetClipOrigin(disp, gc, sel_x, y); |
156 | theme.bulletPixmap().mask().drawable()); | ||
157 | XSetClipOrigin(FbTk::App::instance()->display(), | ||
158 | gc, sel_x, y); | ||
159 | // copy bullet pixmap to frame | 148 | // copy bullet pixmap to frame |
160 | draw.copyArea(theme.bulletPixmap().pixmap().drawable(), | 149 | draw.copyArea(theme.bulletPixmap().pixmap().drawable(), |
161 | gc, | 150 | gc, |
@@ -164,9 +153,7 @@ void MenuItem::draw(FbDrawable &draw, | |||
164 | theme.bulletPixmap().width(), | 153 | theme.bulletPixmap().width(), |
165 | theme.bulletPixmap().height()); | 154 | theme.bulletPixmap().height()); |
166 | // disable clip mask | 155 | // disable clip mask |
167 | XSetClipMask(FbTk::App::instance()->display(), | 156 | XSetClipMask(disp, gc, None); |
168 | gc, | ||
169 | None); | ||
170 | } else { | 157 | } else { |
171 | unsigned int half_w = height / 2, quarter_w = height / 4; | 158 | unsigned int half_w = height / 2, quarter_w = height / 4; |
172 | int sel_y = y + height/4; | 159 | int sel_y = y + height/4; |
@@ -193,11 +180,11 @@ void MenuItem::draw(FbDrawable &draw, | |||
193 | tri[2].x = 0; | 180 | tri[2].x = 0; |
194 | tri[2].y = -4; | 181 | tri[2].y = -4; |
195 | } | 182 | } |
196 | 183 | ||
197 | draw.fillPolygon(gc, tri, 3, Convex, | 184 | draw.fillPolygon(gc, tri, 3, Convex, |
198 | CoordModePrevious); | 185 | CoordModePrevious); |
199 | break; | 186 | break; |
200 | 187 | ||
201 | case MenuTheme::DIAMOND: | 188 | case MenuTheme::DIAMOND: |
202 | XPoint dia[4]; | 189 | XPoint dia[4]; |
203 | 190 | ||
@@ -233,7 +220,7 @@ void MenuItem::setIcon(const std::string &filename, int screen_num) { | |||
233 | m_icon.reset(new Icon); | 220 | m_icon.reset(new Icon); |
234 | 221 | ||
235 | m_icon->filename = FbTk::StringUtil::expandFilename(filename); | 222 | m_icon->filename = FbTk::StringUtil::expandFilename(filename); |
236 | m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), | 223 | m_icon->pixmap.reset(Image::load(m_icon->filename.c_str(), |
237 | screen_num)); | 224 | screen_num)); |
238 | } | 225 | } |
239 | 226 | ||
@@ -245,8 +232,8 @@ unsigned int MenuItem::width(const MenuTheme &theme) const { | |||
245 | // textwidth + bevel width on each side of the text | 232 | // textwidth + bevel width on each side of the text |
246 | const unsigned int icon_width = height(theme); | 233 | const unsigned int icon_width = height(theme); |
247 | const unsigned int normal = theme.frameFont().textWidth(label().c_str(), label().size()) + | 234 | const unsigned int normal = theme.frameFont().textWidth(label().c_str(), label().size()) + |
248 | 2 * (theme.bevelWidth() + icon_width); | 235 | 2 * (theme.bevelWidth() + icon_width); |
249 | 236 | ||
250 | return m_icon.get() == 0 ? normal : normal + icon_width; | 237 | return m_icon.get() == 0 ? normal : normal + icon_width; |
251 | } | 238 | } |
252 | 239 | ||