aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/MenuItem.cc63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index 3918a96..7890188 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -20,17 +20,18 @@
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22#include "MenuItem.hh" 22#include "MenuItem.hh"
23#include "Menu.hh"
24#include "MenuTheme.hh"
25#include "App.hh"
23#include "Command.hh" 26#include "Command.hh"
27#include "Image.hh"
24#include "GContext.hh" 28#include "GContext.hh"
25#include "MenuTheme.hh"
26#include "PixmapWithMask.hh" 29#include "PixmapWithMask.hh"
27#include "Image.hh"
28#include "App.hh"
29#include "StringUtil.hh" 30#include "StringUtil.hh"
30#include "Menu.hh"
31 31
32#include <X11/keysym.h> 32#include <X11/keysym.h>
33 33
34
34namespace FbTk { 35namespace FbTk {
35 36
36MenuItem::~MenuItem() { } 37MenuItem::~MenuItem() { }
@@ -102,7 +103,10 @@ void MenuItem::draw(FbDrawable &draw,
102 // text and submenu icon are background 103 // text and submenu icon are background
103 // selected pixmaps are foreground 104 // selected pixmaps are foreground
104 105
106 int h = static_cast<int>(height);
107 int bevel = theme->bevelWidth();
105 Display *disp = App::instance()->display(); 108 Display *disp = App::instance()->display();
109
106 // 110 //
107 // Icon 111 // Icon
108 // 112 //
@@ -114,16 +118,18 @@ void MenuItem::draw(FbDrawable &draw,
114 tmp_mask.copy(icon()->mask()); 118 tmp_mask.copy(icon()->mask());
115 119
116 // scale pixmap to right size 120 // scale pixmap to right size
117 if (height - 2*theme->bevelWidth() != tmp_pixmap.height()) { 121 if ((h - (2*bevel)) != static_cast<int>(tmp_pixmap.height())) {
118 unsigned int scale_size = height - 2*theme->bevelWidth(); 122 int scale_size = h - 2*bevel;
119 tmp_pixmap.scale(scale_size, scale_size); 123 if (scale_size > 0) {
120 tmp_mask.scale(scale_size, scale_size); 124 tmp_pixmap.scale(scale_size, scale_size);
125 tmp_mask.scale(scale_size, scale_size);
126 }
121 } 127 }
122 128
123 if (tmp_pixmap.drawable() != 0) { 129 if (tmp_pixmap.drawable() != 0) {
124 GC gc = theme->frameTextGC().gc(); 130 GC gc = theme->frameTextGC().gc();
125 int icon_x = x + theme->bevelWidth(); 131 int icon_x = x + bevel;
126 int icon_y = y + theme->bevelWidth(); 132 int icon_y = y + bevel;
127 // enable clip mask 133 // enable clip mask
128 XSetClipMask(disp, gc, tmp_mask.drawable()); 134 XSetClipMask(disp, gc, tmp_mask.drawable());
129 XSetClipOrigin(disp, gc, icon_x, icon_y); 135 XSetClipOrigin(disp, gc, icon_x, icon_y);
@@ -165,22 +171,24 @@ void MenuItem::draw(FbDrawable &draw,
165 (highlight ? theme->hiliteTextGC() : 171 (highlight ? theme->hiliteTextGC() :
166 (isEnabled() ? theme->frameTextGC() : theme->disableTextGC() ) ); 172 (isEnabled() ? theme->frameTextGC() : theme->disableTextGC() ) );
167 const Font& font = (highlight ? theme->hiliteFont() : theme->frameFont()); 173 const Font& font = (highlight ? theme->hiliteFont() : theme->frameFont());
174
168 // 175 //
169 // Text 176 // Text
170 // 177 //
171 int text_y = y, text_x = x; 178 int text_y = y;
179 int text_x = x;
172 int text_w = font.textWidth(label()); 180 int text_w = font.textWidth(label());
173 181
174 int height_offset = theme->itemHeight() - (font.height() + 2*theme->bevelWidth()); 182 int height_offset = theme->itemHeight() - (font.height() + 2*bevel);
175 text_y = y + theme->bevelWidth() + font.ascent() + height_offset/2; 183 text_y = y + bevel + font.ascent() + height_offset/2;
176 184
177 switch(highlight ? theme->hiliteFontJustify() : theme->frameFontJustify()) { 185 switch(highlight ? theme->hiliteFontJustify() : theme->frameFontJustify()) {
178 case FbTk::LEFT: 186 case FbTk::LEFT:
179 text_x = x + theme->bevelWidth() + height + 1; 187 text_x = x + bevel + h + 1;
180 break; 188 break;
181 189
182 case FbTk::RIGHT: 190 case FbTk::RIGHT:
183 text_x = x + width - (height + theme->bevelWidth() + text_w); 191 text_x = x + width - (h + bevel + text_w);
184 break; 192 break;
185 default: //center 193 default: //center
186 text_x = x + ((width + 1 - text_w) / 2); 194 text_x = x + ((width + 1 - text_w) / 2);
@@ -194,10 +202,10 @@ void MenuItem::draw(FbDrawable &draw,
194 theme->frameTextGC().gc(); 202 theme->frameTextGC().gc();
195 int sel_x = x; 203 int sel_x = x;
196 int sel_y = y; 204 int sel_y = y;
197 unsigned int item_pm_height = theme->itemHeight(); 205 int item_pm_height = static_cast<int>(theme->itemHeight());
198 206
199 if (theme->bulletPos() == FbTk::RIGHT) 207 if (theme->bulletPos() == FbTk::RIGHT)
200 sel_x += width - height - theme->bevelWidth(); 208 sel_x += static_cast<int>(width) - h - bevel;
201 209
202 // selected pixmap is foreground 210 // selected pixmap is foreground
203 if (draw_foreground && isToggleItem()) { 211 if (draw_foreground && isToggleItem()) {
@@ -218,9 +226,10 @@ void MenuItem::draw(FbDrawable &draw,
218 else 226 else
219 pm = &theme->unselectedPixmap(); 227 pm = &theme->unselectedPixmap();
220 } 228 }
229
221 if (pm != 0 && pm->pixmap().drawable() != 0) { 230 if (pm != 0 && pm->pixmap().drawable() != 0) {
222 unsigned int selw = pm->width(); 231 int selw = static_cast<int>(pm->width());
223 unsigned int selh = pm->height(); 232 int selh = static_cast<int>(pm->height());
224 int offset_x = 0; 233 int offset_x = 0;
225 int offset_y = 0; 234 int offset_y = 0;
226 if (selw < item_pm_height) 235 if (selw < item_pm_height)
@@ -258,9 +267,8 @@ void MenuItem::draw(FbDrawable &draw,
258 pm = &theme->bulletPixmap(); 267 pm = &theme->bulletPixmap();
259 268
260 if (pm && pm->pixmap().drawable() != 0) { 269 if (pm && pm->pixmap().drawable() != 0) {
261 unsigned int selw = pm->width(); 270 int selw = static_cast<int>(pm->width());
262 unsigned int selh = pm->height(); 271 int selh = static_cast<int>(pm->height());
263
264 int offset_x = 0; 272 int offset_x = 0;
265 int offset_y = 0; 273 int offset_y = 0;
266 if (selw < item_pm_height) 274 if (selw < item_pm_height)
@@ -281,7 +289,8 @@ void MenuItem::draw(FbDrawable &draw,
281 XSetClipMask(disp, gc, None); 289 XSetClipMask(disp, gc, None);
282 290
283 } else { 291 } else {
284 unsigned int half_w = item_pm_height / 2, quarter_w = item_pm_height / 4; 292 int half_w = item_pm_height / 2;
293 int quarter_w = item_pm_height / 4;
285 switch (theme->bullet()) { 294 switch (theme->bullet()) {
286 case MenuTheme::SQUARE: 295 case MenuTheme::SQUARE:
287 draw.drawRectangle(gc, sel_x+quarter_w, y+quarter_w, half_w, half_w); 296 draw.drawRectangle(gc, sel_x+quarter_w, y+quarter_w, half_w, half_w);
@@ -323,8 +332,7 @@ void MenuItem::draw(FbDrawable &draw,
323 332
324void MenuItem::setIcon(const std::string &filename, int screen_num) { 333void MenuItem::setIcon(const std::string &filename, int screen_num) {
325 if (filename.empty()) { 334 if (filename.empty()) {
326 if (m_icon.get() != 0) 335 m_icon.reset(0);
327 m_icon.reset(0);
328 return; 336 return;
329 } 337 }
330 338
@@ -337,9 +345,10 @@ void MenuItem::setIcon(const std::string &filename, int screen_num) {
337} 345}
338 346
339unsigned int MenuItem::height(const FbTk::ThemeProxy<MenuTheme> &theme) const { 347unsigned int MenuItem::height(const FbTk::ThemeProxy<MenuTheme> &theme) const {
348 const unsigned int bevel = theme->bevelWidth();
340 return std::max(theme->itemHeight(), 349 return std::max(theme->itemHeight(),
341 std::max(theme->frameFont().height() + 2*theme->bevelWidth(), 350 std::max(theme->frameFont().height() + 2*bevel,
342 theme->hiliteFont().height() + 2*theme->bevelWidth())); 351 theme->hiliteFont().height() + 2*bevel));
343} 352}
344 353
345unsigned int MenuItem::width(const FbTk::ThemeProxy<MenuTheme> &theme) const { 354unsigned int MenuItem::width(const FbTk::ThemeProxy<MenuTheme> &theme) const {