aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-10-19 10:03:16 (GMT)
committerfluxgen <fluxgen>2002-10-19 10:03:16 (GMT)
commitd8a620710661149aecb6c95980f122bcdfdbea97 (patch)
tree1d4aee403db902a4951a5f67ccae03af3fc9d6c8 /src/tests
parentcf30c203fe43205aa06a4dfebe7a20f4c740749e (diff)
downloadfluxbox-d8a620710661149aecb6c95980f122bcdfdbea97.zip
fluxbox-d8a620710661149aecb6c95980f122bcdfdbea97.tar.bz2
initial import
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/testFont.cc95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/tests/testFont.cc b/src/tests/testFont.cc
new file mode 100644
index 0000000..d52c2af
--- /dev/null
+++ b/src/tests/testFont.cc
@@ -0,0 +1,95 @@
1
2#include "Font.hh"
3#include "BaseDisplay.hh"
4
5#include <X11/Xlib.h>
6#include <X11/Xutil.h>
7#include <X11/keysym.h>
8
9#include <string>
10#include <iostream>
11using namespace std;
12
13class App:public BaseDisplay {
14public:
15 App(const char *displayname):BaseDisplay("app", displayname) {
16
17 // using screen 0
18 m_win = XCreateSimpleWindow(getXDisplay(),
19 DefaultRootWindow(getXDisplay()),
20 0, 0,
21 640, 480,
22 1,
23 0,
24 0xFFFF);
25 XSelectInput(getXDisplay(), m_win, KeyPressMask|ExposureMask);
26 XMapWindow(getXDisplay(), m_win);
27 }
28 ~App() {
29 XDestroyWindow(getXDisplay(), m_win);
30 }
31
32 void handleEvent(XEvent * const ev) {
33 switch (ev->type) {
34 case KeyPress:
35 KeySym ks;
36 char keychar[1];
37 XLookupString(&ev->xkey, keychar, 1, &ks, 0);
38 if (ks == XK_Escape)
39 shutdown();
40 else { // toggle antialias
41 m_font.setAntialias(!m_font.isAntialias());
42 cerr<<boolalpha;
43 cerr<<"antialias: "<<m_font.isAntialias()<<endl;
44 redraw();
45 }
46 break;
47 case Expose:
48 redraw();
49 break;
50 }
51 }
52 void redraw() {
53 XClearWindow(getXDisplay(), m_win);
54 GC wingc = DefaultGC(getXDisplay(), 0);
55 m_font.drawText(m_win, 0, wingc,
56 m_text.c_str(), m_text.size(),
57 640/2 - m_font.textWidth(m_text.c_str(), m_text.size())/2, 480/2);
58
59 }
60 Window win() const { return m_win; }
61 FbTk::Font &font() { return m_font; }
62 void setText(const std::string& text) { m_text = text; }
63private:
64 Window m_win;
65 FbTk::Font m_font;
66 string m_text;
67};
68
69int main(int argc, char **argv) {
70 bool antialias = false;
71 string fontname("fixed");
72 string displayname("");
73 string text("testTEST0123456789,-+.;:\\!{}[]()");
74 for (int a=1; a<argc; ++a) {
75 if (strcmp("-font", argv[a])==0 && a + 1 < argc) {
76 fontname = argv[++a];
77 } else if (strcmp("-antialias", argv[a]) == 0) {
78 antialias = true;
79 } else if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
80 displayname = argv[++a];
81 } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) {
82 text = argv[++a];
83 }
84 }
85
86 App app(displayname.c_str());
87 app.font().setAntialias(antialias);
88 if (!app.font().load(fontname.c_str()))
89 cerr<<"Failed to load: "<<fontname<<endl;
90
91 app.setText(text);
92 app.redraw();
93 app.eventLoop();
94
95}