aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorsimonb <simonb>2006-04-04 14:07:07 (GMT)
committersimonb <simonb>2006-04-04 14:07:07 (GMT)
commit42719701dc17b5acef41223fe0237b9154cb3f0a (patch)
treedc2c5567e071fa6d445003439800ba03b328ce20 /src/FbTk
parentc243fa897f37dabeade187ac74ea5cd175e80a22 (diff)
downloadfluxbox_paul-42719701dc17b5acef41223fe0237b9154cb3f0a.zip
fluxbox_paul-42719701dc17b5acef41223fe0237b9154cb3f0a.tar.bz2
rotated Xmb Fonts, by rotating as we draw
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Text.hh25
-rw-r--r--src/FbTk/XmbFontImp.cc82
-rw-r--r--src/FbTk/XmbFontImp.hh3
3 files changed, 102 insertions, 8 deletions
diff --git a/src/FbTk/Text.hh b/src/FbTk/Text.hh
index ceb0f19..5336546 100644
--- a/src/FbTk/Text.hh
+++ b/src/FbTk/Text.hh
@@ -75,6 +75,31 @@ inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w,
75 75
76} 76}
77 77
78// still require w and h in ROT0 coords
79inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsigned int w, unsigned int h) {
80
81 int x = orig_x;
82 int y = orig_y;
83
84 switch(orient) {
85 case ROT0:
86 break;
87 case ROT90:
88 orig_y = h - x;
89 orig_x = y;
90 break;
91 case ROT180:
92 orig_x = w - x;
93 orig_y = h - y;
94 break;
95 case ROT270:
96 orig_y = x;
97 orig_x = w - y;
98 break;
99 }
100
101}
102
78// When positioning an X11 box inside another area, we need to 103// When positioning an X11 box inside another area, we need to
79// relocate the x,y coordinates 104// relocate the x,y coordinates
80inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w, unsigned int h, unsigned int bw) { 105inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w, unsigned int h, unsigned int bw) {
diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc
index e923040..f33942a 100644
--- a/src/FbTk/XmbFontImp.cc
+++ b/src/FbTk/XmbFontImp.cc
@@ -25,7 +25,8 @@
25 25
26#include "App.hh" 26#include "App.hh"
27#include "StringUtil.hh" 27#include "StringUtil.hh"
28#include "FbDrawable.hh" 28#include "FbPixmap.hh"
29#include "GContext.hh"
29 30
30#ifdef HAVE_CONFIG_H 31#ifdef HAVE_CONFIG_H
31#include "config.h" 32#include "config.h"
@@ -56,6 +57,8 @@
56 #include <string.h> 57 #include <string.h>
57#endif 58#endif
58 59
60#include <X11/Xlib.h>
61
59using namespace std; 62using namespace std;
60 63
61namespace { 64namespace {
@@ -183,24 +186,87 @@ bool XmbFontImp::load(const std::string &fontname) {
183 return true; 186 return true;
184} 187}
185 188
186void XmbFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text, 189void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const char *text,
187 size_t len, int x, int y, FbTk::Orientation orient) const { 190 size_t len, int x, int y, FbTk::Orientation orient) const {
188 191
189 if (m_fontset == 0) 192 if (m_fontset == 0)
190 return; 193 return;
191 194
195 if (orient == ROT0) {
196#ifdef X_HAVE_UTF8_STRING
197 if (m_utf8mode) {
198 Xutf8DrawString(d.display(), d.drawable(), m_fontset,
199 main_gc, x, y,
200 text, len);
201 } else
202#endif //X_HAVE_UTF8_STRING
203 {
204 XmbDrawString(d.display(), d.drawable(), m_fontset,
205 main_gc, x, y,
206 text, len);
207 }
208 return;
209 }
210
211 Display *dpy = App::instance()->display();
212 Window rootwin = DefaultRootWindow(dpy);
213
214 int xpos = x, ypos = y;
215 unsigned int w = d.width();
216 unsigned int h = d.height();
217
218 translateSize(orient, w, h);
219 untranslateCoords(orient, xpos, ypos, w, h);
220
221 // not straight forward, we actually draw it elsewhere, then rotate it
222 FbTk::FbPixmap canvas(rootwin, w, h, 1);
223
224 // create graphic context for our canvas
225 FbTk::GContext font_gc(canvas);
226 font_gc.setBackground(None);
227 font_gc.setForeground(None);
228
229 XFillRectangle(dpy, canvas.drawable(), font_gc.gc(), 0, 0, canvas.width(), canvas.height());
230 font_gc.setForeground(1);
231
232
192#ifdef X_HAVE_UTF8_STRING 233#ifdef X_HAVE_UTF8_STRING
193 if (m_utf8mode) { 234 if (m_utf8mode) {
194 Xutf8DrawString(w.display(), w.drawable(), m_fontset, 235 Xutf8DrawString(dpy, canvas.drawable(), m_fontset,
195 gc, x, y, 236 font_gc.gc(), xpos, ypos,
196 text, len); 237 text, len);
197 } else 238 } else
198#endif //X_HAVE_UTF8_STRING 239#endif //X_HAVE_UTF8_STRING
199 { 240 {
200 XmbDrawString(w.display(), w.drawable(), m_fontset, 241 XmbDrawString(dpy, canvas.drawable(), m_fontset,
201 gc, x, y, 242 font_gc.gc(), xpos, ypos,
202 text, len); 243 text, len);
203 } 244 }
245
246 canvas.rotate(orient);
247
248 GC my_gc = XCreateGC(dpy, d.drawable(), 0, 0);
249
250 XCopyGC(dpy, main_gc, GCForeground|GCBackground, my_gc);
251
252 // vertical or upside down
253
254 XSetFillStyle(dpy, my_gc, FillStippled);
255
256 // vertical or upside down
257
258 XSetFillStyle(dpy, my_gc, FillStippled);
259
260 XSetStipple(dpy, my_gc, canvas.drawable());
261
262 XSetTSOrigin(dpy, my_gc, 0, 0);
263
264 XFillRectangle(dpy, d.drawable(), my_gc, 0, 0,
265 canvas.width(),
266 canvas.height());
267
268 XFreeGC(dpy, my_gc);
269
204} 270}
205 271
206unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const { 272unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const {
diff --git a/src/FbTk/XmbFontImp.hh b/src/FbTk/XmbFontImp.hh
index 9ee5db5..4a8f20b 100644
--- a/src/FbTk/XmbFontImp.hh
+++ b/src/FbTk/XmbFontImp.hh
@@ -43,6 +43,9 @@ public:
43 int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; } 43 int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; }
44 bool loaded() const { return m_fontset != 0; } 44 bool loaded() const { return m_fontset != 0; }
45 bool utf8() const { return m_utf8mode; } 45 bool utf8() const { return m_utf8mode; }
46
47 bool validOrientation(FbTk::Orientation orient) { return true; }; // rotated on demand
48
46private: 49private:
47 XFontSet m_fontset; 50 XFontSet m_fontset;
48 XFontSetExtents *m_setextents; 51 XFontSetExtents *m_setextents;