aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuItem.cc
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 /src/FbTk/MenuItem.cc
parent34edd2640a35cb825a647e8d37db6cbc8e6afea1 (diff)
downloadfluxbox_pavel-8eb2ea889d00a6facba0259883d9d29b0deac2ff.zip
fluxbox_pavel-8eb2ea889d00a6facba0259883d9d29b0deac2ff.tar.bz2
drawing of items is now done in MenuItem
Diffstat (limited to 'src/FbTk/MenuItem.cc')
-rw-r--r--src/FbTk/MenuItem.cc158
1 files changed, 156 insertions, 2 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