aboutsummaryrefslogtreecommitdiff
path: root/src/tests/testFont.cc
diff options
context:
space:
mode:
authorrathnor <rathnor>2002-12-01 13:42:15 (GMT)
committerrathnor <rathnor>2002-12-01 13:42:15 (GMT)
commit28b5c604490094e187494dcc566bd3d7a05a2c25 (patch)
tree8f78f5714a5cd055c10b067a2656fe7b2338e71a /src/tests/testFont.cc
parentb9134162f9633784d9097df18769a699a62650fe (diff)
downloadfluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.zip
fluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.tar.bz2
Indenting from tabs to emacs 4-space
Diffstat (limited to 'src/tests/testFont.cc')
-rw-r--r--src/tests/testFont.cc166
1 files changed, 83 insertions, 83 deletions
diff --git a/src/tests/testFont.cc b/src/tests/testFont.cc
index b949dc8..7498194 100644
--- a/src/tests/testFont.cc
+++ b/src/tests/testFont.cc
@@ -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: testFont.cc,v 1.4 2002/11/12 22:50:36 fluxgen Exp $ 22// $Id: testFont.cc,v 1.5 2002/12/01 13:42:15 rathnor Exp $
23 23
24#include "Font.hh" 24#include "Font.hh"
25#include "BaseDisplay.hh" 25#include "BaseDisplay.hh"
@@ -34,99 +34,99 @@ using namespace std;
34 34
35class App:public BaseDisplay { 35class App:public BaseDisplay {
36public: 36public:
37 App(const char *displayname):BaseDisplay("app", displayname) { 37 App(const char *displayname):BaseDisplay("app", displayname) {
38 38
39 // using screen 0 39 // using screen 0
40 m_win = XCreateSimpleWindow(getXDisplay(), 40 m_win = XCreateSimpleWindow(getXDisplay(),
41 DefaultRootWindow(getXDisplay()), 41 DefaultRootWindow(getXDisplay()),
42 0, 0, 42 0, 0,
43 640, 480, 43 640, 480,
44 1, 44 1,
45 0, 45 0,
46 0xFFFF); 46 0xFFFF);
47 XSelectInput(getXDisplay(), m_win, KeyPressMask|ExposureMask); 47 XSelectInput(getXDisplay(), m_win, KeyPressMask|ExposureMask);
48 XMapWindow(getXDisplay(), m_win); 48 XMapWindow(getXDisplay(), m_win);
49 } 49 }
50 ~App() { 50 ~App() {
51 XDestroyWindow(getXDisplay(), m_win); 51 XDestroyWindow(getXDisplay(), m_win);
52 } 52 }
53 53
54 void handleEvent(XEvent * const ev) { 54 void handleEvent(XEvent * const ev) {
55 switch (ev->type) { 55 switch (ev->type) {
56 case KeyPress: 56 case KeyPress:
57 KeySym ks; 57 KeySym ks;
58 char keychar[1]; 58 char keychar[1];
59 XLookupString(&ev->xkey, keychar, 1, &ks, 0); 59 XLookupString(&ev->xkey, keychar, 1, &ks, 0);
60 if (ks == XK_Escape) 60 if (ks == XK_Escape)
61 shutdown(); 61 shutdown();
62 else { // toggle antialias 62 else { // toggle antialias
63 m_font.setAntialias(!m_font.isAntialias()); 63 m_font.setAntialias(!m_font.isAntialias());
64 cerr<<boolalpha; 64 cerr<<boolalpha;
65 cerr<<"antialias: "<<m_font.isAntialias()<<endl; 65 cerr<<"antialias: "<<m_font.isAntialias()<<endl;
66 redraw(); 66 redraw();
67 } 67 }
68 break; 68 break;
69 case Expose: 69 case Expose:
70 redraw(); 70 redraw();
71 break; 71 break;
72 } 72 }
73 } 73 }
74 void redraw() { 74 void redraw() {
75 size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size()); 75 size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size());
76 size_t text_h = m_font.height(); 76 size_t text_h = m_font.height();
77 int x = 640/2 - text_w/2; 77 int x = 640/2 - text_w/2;
78 int y = 480/2 - text_h/2; 78 int y = 480/2 - text_h/2;
79 XClearWindow(getXDisplay(), m_win); 79 XClearWindow(getXDisplay(), m_win);
80 GC wingc = DefaultGC(getXDisplay(), 0); 80 GC wingc = DefaultGC(getXDisplay(), 0);
81 81
82 XDrawLine(getXDisplay(), m_win, wingc, 82 XDrawLine(getXDisplay(), m_win, wingc,
83 x, y + m_font.descent(), x + text_w, y + m_font.descent()); 83 x, y + m_font.descent(), x + text_w, y + m_font.descent());
84 XSetForeground(getXDisplay(), wingc, 0xFF00FF); // don't care what color it is 84 XSetForeground(getXDisplay(), wingc, 0xFF00FF); // don't care what color it is
85 XDrawLine(getXDisplay(), m_win, wingc, 85 XDrawLine(getXDisplay(), m_win, wingc,
86 x, y - text_h , x + text_w, y - text_h ); 86 x, y - text_h , x + text_w, y - text_h );
87 XSetForeground(getXDisplay(), wingc, 0xFF0000); // don't care what color it is 87 XSetForeground(getXDisplay(), wingc, 0xFF0000); // don't care what color it is
88 XDrawLine(getXDisplay(), m_win, wingc, 88 XDrawLine(getXDisplay(), m_win, wingc,
89 x, y, x + text_w, y); 89 x, y, x + text_w, y);
90 90
91 XSetForeground(getXDisplay(), wingc, 0); 91 XSetForeground(getXDisplay(), wingc, 0);
92 m_font.drawText(m_win, 0, wingc, 92 m_font.drawText(m_win, 0, wingc,
93 m_text.c_str(), m_text.size(), 93 m_text.c_str(), m_text.size(),
94 x, y); 94 x, y);
95 95
96 } 96 }
97 Window win() const { return m_win; } 97 Window win() const { return m_win; }
98 FbTk::Font &font() { return m_font; } 98 FbTk::Font &font() { return m_font; }
99 void setText(const std::string& text) { m_text = text; } 99 void setText(const std::string& text) { m_text = text; }
100private: 100private:
101 Window m_win; 101 Window m_win;
102 FbTk::Font m_font; 102 FbTk::Font m_font;
103 string m_text; 103 string m_text;
104}; 104};
105 105
106int main(int argc, char **argv) { 106int main(int argc, char **argv) {
107 bool antialias = false; 107 bool antialias = false;
108 string fontname("fixed"); 108 string fontname("fixed");
109 string displayname(""); 109 string displayname("");
110 string text("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-_¯åäöÅÄÖ^~+=`\"!#¤%&/()=¡@£$½¥{[]}¶½§±"); 110 string text("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-_¯åäöÅÄÖ^~+=`\"!#¤%&/()=¡@£$½¥{[]}¶½§±");
111 for (int a=1; a<argc; ++a) { 111 for (int a=1; a<argc; ++a) {
112 if (strcmp("-font", argv[a])==0 && a + 1 < argc) { 112 if (strcmp("-font", argv[a])==0 && a + 1 < argc) {
113 fontname = argv[++a]; 113 fontname = argv[++a];
114 } else if (strcmp("-antialias", argv[a]) == 0) { 114 } else if (strcmp("-antialias", argv[a]) == 0) {
115 antialias = true; 115 antialias = true;
116 } else if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) { 116 } else if (strcmp("-display", argv[a]) == 0 && a + 1 < argc) {
117 displayname = argv[++a]; 117 displayname = argv[++a];
118 } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) { 118 } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) {
119 text = argv[++a]; 119 text = argv[++a];
120 } 120 }
121 } 121 }
122 122
123 App app(displayname.c_str()); 123 App app(displayname.c_str());
124 app.font().setAntialias(antialias); 124 app.font().setAntialias(antialias);
125 if (!app.font().load(fontname.c_str())) 125 if (!app.font().load(fontname.c_str()))
126 cerr<<"Failed to load: "<<fontname<<endl; 126 cerr<<"Failed to load: "<<fontname<<endl;
127 127
128 app.setText(text); 128 app.setText(text);
129 app.redraw(); 129 app.redraw();
130 app.eventLoop(); 130 app.eventLoop();
131 131
132} 132}