aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2004-06-07 20:34:23 (GMT)
committerfluxgen <fluxgen>2004-06-07 20:34:23 (GMT)
commit8eb2ea889d00a6facba0259883d9d29b0deac2ff (patch)
tree48f215fc674d90aef76db9dcb9eab99446b3d38d
parent34edd2640a35cb825a647e8d37db6cbc8e6afea1 (diff)
downloadfluxbox_paul-8eb2ea889d00a6facba0259883d9d29b0deac2ff.zip
fluxbox_paul-8eb2ea889d00a6facba0259883d9d29b0deac2ff.tar.bz2
drawing of items is now done in MenuItem
-rw-r--r--src/FbTk/MenuItem.cc158
-rw-r--r--src/FbTk/MenuItem.hh41
2 files changed, 185 insertions, 14 deletions
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index 0dbdc69..55aef9a 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -1,5 +1,5 @@
1// MenuItem.cc for FbTk - Fluxbox Toolkit 1// MenuItem.cc 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,10 +19,13 @@
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.1 2003/01/12 17:06:07 fluxgen Exp $ 22// $Id: MenuItem.cc,v 1.2 2004/06/07 20:34:23 fluxgen Exp $
23 23
24#include "MenuItem.hh" 24#include "MenuItem.hh"
25#include "Command.hh" 25#include "Command.hh"
26#include "GContext.hh"
27#include "MenuTheme.hh"
28#include "App.hh"
26 29
27namespace FbTk { 30namespace FbTk {
28 31
@@ -31,4 +34,155 @@ void MenuItem::click(int button, int time) {
31 m_command->execute(); 34 m_command->execute();
32} 35}
33 36
37void MenuItem::draw(FbDrawable &draw,
38 const MenuTheme &theme,
39 bool highlight,
40 int x, int y,
41 unsigned int width, unsigned int height) const {
42 if (label().empty())
43 return;
44
45 const GContext &tgc =
46 (highlight ? theme.hiliteTextGC() :
47 (isEnabled() ? theme.frameTextGC() : theme.disableTextGC() ) );
48 int text_y = y, text_x = x;
49
50 int text_w = theme.frameFont().textWidth(label().c_str(), label().size());
51
52 text_y = y + theme.bevelWidth()/2 + theme.frameFont().ascent()/2 + height/2;
53
54 switch(theme.frameFontJustify()) {
55 case FbTk::LEFT:
56 text_x = x + theme.bevelWidth() + height + 1;
57 break;
58
59 case FbTk::RIGHT:
60 text_x = x + width - (height + theme.bevelWidth() + text_w);
61 break;
62 default: //center
63 text_x = x + ((width + 1 - text_w) / 2);
64 break;
65 }
66
67 theme.frameFont().drawText(draw.drawable(), // drawable
68 theme.screenNum(),
69 tgc.gc(),
70 m_label.c_str(), m_label.size(), // text string and lenght
71 text_x, text_y); // position
72
73 GC gc =
74 ((highlight || isSelected()) ? theme.hiliteTextGC().gc() :
75 theme.frameTextGC().gc());
76
77 int sel_x = x + height/4;
78
79
80 if (theme.bulletPos() == FbTk::RIGHT)
81 sel_x += width - height - 2*theme.bevelWidth();
82
83 if (isToggleItem() && theme.unselectedPixmap().pixmap().drawable() != 0) {
84 XSetClipMask(FbTk::App::instance()->display(),
85 gc,
86 theme.unselectedPixmap().mask().drawable());
87 XSetClipOrigin(FbTk::App::instance()->display(),
88 gc, sel_x, y);
89 // copy bullet pixmap to drawable
90 draw.copyArea(theme.unselectedPixmap().pixmap().drawable(),
91 gc,
92 0, 0,
93 sel_x, y,
94 theme.unselectedPixmap().width(),
95 theme.unselectedPixmap().height());
96 // disable clip mask
97 XSetClipMask(FbTk::App::instance()->display(),
98 gc,
99 None);
100 }
101
102
103 if (submenu()) {
104 if (theme.bulletPixmap().pixmap().drawable() != 0) {
105 // enable clip mask
106 XSetClipMask(FbTk::App::instance()->display(),
107 gc,
108 theme.bulletPixmap().mask().drawable());
109 XSetClipOrigin(FbTk::App::instance()->display(),
110 gc, sel_x, y);
111 // copy bullet pixmap to frame
112 draw.copyArea(theme.bulletPixmap().pixmap().drawable(),
113 gc,
114 0, 0,
115 sel_x, y,
116 theme.bulletPixmap().width(),
117 theme.bulletPixmap().height());
118 // disable clip mask
119 XSetClipMask(FbTk::App::instance()->display(),
120 gc,
121 None);
122 } else {
123 unsigned int half_w = height / 2, quarter_w = height / 4;
124 int sel_y = y + height/4;
125 switch (theme.bullet()) {
126 case MenuTheme::SQUARE:
127 draw.drawRectangle(gc, sel_x, sel_y, half_w, half_w);
128 break;
129
130 case MenuTheme::TRIANGLE:
131 XPoint tri[3];
132
133 if (theme.bulletPos() == FbTk::RIGHT) {
134 tri[0].x = sel_x + quarter_w - 2;
135 tri[0].y = sel_y + quarter_w - 2;
136 tri[1].x = 4;
137 tri[1].y = 2;
138 tri[2].x = -4;
139 tri[2].y = 2;
140 } else {
141 tri[0].x = sel_x + quarter_w - 2;
142 tri[0].y = y + half_w;
143 tri[1].x = 4;
144 tri[1].y = 2;
145 tri[2].x = 0;
146 tri[2].y = -4;
147 }
148
149 draw.fillPolygon(gc, tri, 3, Convex,
150 CoordModePrevious);
151 break;
152
153 case MenuTheme::DIAMOND:
154 XPoint dia[4];
155
156 dia[0].x = sel_x + quarter_w - 3;
157 dia[0].y = y + half_w;
158 dia[1].x = 3;
159 dia[1].y = -3;
160 dia[2].x = 3;
161 dia[2].y = 3;
162 dia[3].x = -3;
163 dia[3].y = 3;
164
165 draw.fillPolygon(gc, dia, 4, Convex,
166 CoordModePrevious);
167 break;
168 default:
169 break;
170 }
171 }
172 }
173
174}
175
176unsigned int MenuItem::height(const MenuTheme &theme) const {
177 return std::max(theme.frameFont().height() + theme.bevelWidth(), theme.itemHeight());
178}
179
180unsigned int MenuItem::width(const MenuTheme &theme) const {
181 // textwidth + bevel width on each side of the text
182 return theme.frameFont().textWidth(label().c_str(), label().size()) + 2*(theme.bevelWidth() + height(theme));
183
184}
185
186
187
34}; // end namespace FbTk 188}; // end namespace FbTk
diff --git a/src/FbTk/MenuItem.hh b/src/FbTk/MenuItem.hh
index 6aeb40c..1d9ed20 100644
--- a/src/FbTk/MenuItem.hh
+++ b/src/FbTk/MenuItem.hh
@@ -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.hh,v 1.4 2003/12/16 17:06:52 fluxgen Exp $ 22// $Id: MenuItem.hh,v 1.5 2004/06/07 20:33:20 fluxgen Exp $
23 23
24#ifndef FBTK_MENUITEM_HH 24#ifndef FBTK_MENUITEM_HH
25#define FBTK_MENUITEM_HH 25#define FBTK_MENUITEM_HH
@@ -31,11 +31,20 @@
31namespace FbTk { 31namespace FbTk {
32 32
33class Menu; 33class Menu;
34class MenuTheme;
35class FbDrawable;
34 36
35/// An interface for a menu item in Menu 37/// An interface for a menu item in Menu
36class MenuItem { 38class MenuItem {
37public: 39public:
38 MenuItem( 40 MenuItem()
41 : m_label(""),
42 m_submenu(0),
43 m_enabled(true),
44 m_selected(false),
45 m_toggle_item(false)
46 { }
47 explicit MenuItem(
39 const char *label) 48 const char *label)
40 : m_label(label ? label : ""), 49 : m_label(label ? label : ""),
41 m_submenu(0), 50 m_submenu(0),
@@ -63,21 +72,29 @@ public:
63 { } 72 { }
64 virtual ~MenuItem() { } 73 virtual ~MenuItem() { }
65 74
66 void setCommand(RefCount<Command> &cmd) { m_command = cmd; } 75 inline void setCommand(RefCount<Command> &cmd) { m_command = cmd; }
67 virtual void setSelected(bool selected) { m_selected = selected; } 76 virtual inline void setSelected(bool selected) { m_selected = selected; }
68 virtual void setEnabled(bool enabled) { m_enabled = enabled; } 77 virtual inline void setEnabled(bool enabled) { m_enabled = enabled; }
69 virtual void setLabel(const char *label) { m_label = (label ? label : ""); } 78 virtual inline void setLabel(const char *label) { m_label = (label ? label : ""); }
70 virtual void setToggleItem(bool val) { m_toggle_item = val; } 79 virtual inline void setToggleItem(bool val) { m_toggle_item = val; }
71 Menu *submenu() { return m_submenu; } 80 Menu *submenu() { return m_submenu; }
72 /** 81 /**
73 @name accessors 82 @name accessors
74 */ 83 */
75 //@{ 84 //@{
76 virtual const std::string &label() const { return m_label; } 85 virtual inline const std::string &label() const { return m_label; }
77 const Menu *submenu() const { return m_submenu; } 86 inline const Menu *submenu() const { return m_submenu; }
78 virtual bool isEnabled() const { return m_enabled; } 87 virtual inline bool isEnabled() const { return m_enabled; }
79 virtual bool isSelected() const { return m_selected; } 88 virtual inline bool isSelected() const { return m_selected; }
80 virtual bool isToggleItem() const { return m_toggle_item; } 89 virtual inline bool isToggleItem() const { return m_toggle_item; }
90 virtual unsigned int width(const MenuTheme &theme) const;
91 virtual unsigned int height(const MenuTheme &theme) const;
92 virtual void draw(FbDrawable &drawable,
93 const MenuTheme &theme,
94 bool highlight,
95 int x, int y,
96 unsigned int width, unsigned int height) const;
97 virtual void updateTheme(const MenuTheme &theme) { }
81 /** 98 /**
82 Called when the item was clicked with a specific button 99 Called when the item was clicked with a specific button
83 @param button the button number 100 @param button the button number