aboutsummaryrefslogtreecommitdiff
path: root/src/tests/testFont.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/testFont.cc')
-rw-r--r--src/tests/testFont.cc108
1 files changed, 56 insertions, 52 deletions
diff --git a/src/tests/testFont.cc b/src/tests/testFont.cc
index 7498194..c450216 100644
--- a/src/tests/testFont.cc
+++ b/src/tests/testFont.cc
@@ -19,92 +19,91 @@
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.5 2002/12/01 13:42:15 rathnor Exp $ 22// $Id: testFont.cc,v 1.6 2003/09/11 16:51:03 fluxgen Exp $
23 23
24#include "App.hh"
25#include "FbWindow.hh"
24#include "Font.hh" 26#include "Font.hh"
25#include "BaseDisplay.hh" 27#include "EventHandler.hh"
28#include "EventManager.hh"
29#include "GContext.hh"
30#include "Color.hh"
26 31
27#include <X11/Xlib.h>
28#include <X11/Xutil.h> 32#include <X11/Xutil.h>
29#include <X11/keysym.h> 33#include <X11/keysym.h>
30#include <X11/Xft/Xft.h> 34
31#include <string> 35#include <string>
32#include <iostream> 36#include <iostream>
33using namespace std; 37using namespace std;
34 38
35class App:public BaseDisplay { 39class App:public FbTk::App, public FbTk::EventHandler {
36public: 40public:
37 App(const char *displayname):BaseDisplay("app", displayname) { 41 App(const char *displayname):
42 FbTk::App(displayname),
43 m_win(DefaultScreen(display()),
44 0, 0, 640, 480, KeyPressMask | ExposureMask) {
38 45
39 // using screen 0 46 m_win.show();
40 m_win = XCreateSimpleWindow(getXDisplay(), 47 m_win.setBackgroundColor(FbTk::Color("white", m_win.screenNumber()));
41 DefaultRootWindow(getXDisplay()), 48 FbTk::EventManager::instance()->add(*this, m_win);
42 0, 0,
43 640, 480,
44 1,
45 0,
46 0xFFFF);
47 XSelectInput(getXDisplay(), m_win, KeyPressMask|ExposureMask);
48 XMapWindow(getXDisplay(), m_win);
49 } 49 }
50 ~App() { 50 ~App() {
51 XDestroyWindow(getXDisplay(), m_win);
52 } 51 }
53 52 void keyPressEvent(XKeyEvent &ke) {
54 void handleEvent(XEvent * const ev) { 53 KeySym ks;
55 switch (ev->type) { 54 char keychar[1];
56 case KeyPress: 55 XLookupString(&ke, keychar, 1, &ks, 0);
57 KeySym ks; 56 if (ks == XK_Escape)
58 char keychar[1]; 57 end();
59 XLookupString(&ev->xkey, keychar, 1, &ks, 0); 58 else { // toggle antialias
60 if (ks == XK_Escape) 59 m_font.setAntialias(!m_font.isAntialias());
61 shutdown(); 60 cerr<<boolalpha;
62 else { // toggle antialias 61 cerr<<"antialias: "<<m_font.isAntialias()<<endl;
63 m_font.setAntialias(!m_font.isAntialias());
64 cerr<<boolalpha;
65 cerr<<"antialias: "<<m_font.isAntialias()<<endl;
66 redraw();
67 }
68 break;
69 case Expose:
70 redraw(); 62 redraw();
71 break;
72 } 63 }
73 } 64 }
65
66 void exposeEvent(XExposeEvent &event) {
67 redraw();
68 }
69
74 void redraw() { 70 void redraw() {
75 size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size()); 71 size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size());
76 size_t text_h = m_font.height(); 72 size_t text_h = m_font.height();
77 int x = 640/2 - text_w/2; 73 int x = 640/2 - text_w/2;
78 int y = 480/2 - text_h/2; 74 int y = 480/2 - text_h/2;
79 XClearWindow(getXDisplay(), m_win); 75 m_win.clear();
80 GC wingc = DefaultGC(getXDisplay(), 0); 76 FbTk::GContext wingc(m_win.drawable());
81 77
82 XDrawLine(getXDisplay(), m_win, wingc, 78 m_win.drawLine(wingc.gc(),
83 x, y + m_font.descent(), x + text_w, y + m_font.descent()); 79 x, y + m_font.descent(),
84 XSetForeground(getXDisplay(), wingc, 0xFF00FF); // don't care what color it is 80 x + text_w, y + m_font.descent());
85 XDrawLine(getXDisplay(), m_win, wingc, 81 m_win.drawLine(wingc.gc(),
86 x, y - text_h , x + text_w, y - text_h ); 82 x, y - text_h,
87 XSetForeground(getXDisplay(), wingc, 0xFF0000); // don't care what color it is 83 x + text_w, y - text_h);
88 XDrawLine(getXDisplay(), m_win, wingc, 84 wingc.setForeground(FbTk::Color("red", m_win.screenNumber()));
89 x, y, x + text_w, y); 85 m_win.drawLine(wingc.gc(),
90 86 x, y, x + text_w, y);
91 XSetForeground(getXDisplay(), wingc, 0); 87 wingc.setForeground(FbTk::Color("black", m_win.screenNumber()));
92 m_font.drawText(m_win, 0, wingc, 88 m_font.drawText(m_win.drawable(),
89 0, wingc.gc(),
93 m_text.c_str(), m_text.size(), 90 m_text.c_str(), m_text.size(),
94 x, y); 91 x, y);
95 92
96 } 93 }
97 Window win() const { return m_win; } 94
98 FbTk::Font &font() { return m_font; } 95 FbTk::Font &font() { return m_font; }
99 void setText(const std::string& text) { m_text = text; } 96 void setText(const std::string& text) { m_text = text; }
97
100private: 98private:
101 Window m_win; 99 FbTk::FbWindow m_win;
102 FbTk::Font m_font; 100 FbTk::Font m_font;
103 string m_text; 101 string m_text;
104}; 102};
105 103
106int main(int argc, char **argv) { 104int main(int argc, char **argv) {
107 bool antialias = false; 105 bool antialias = false;
106 bool rotate = false;
108 string fontname("fixed"); 107 string fontname("fixed");
109 string displayname(""); 108 string displayname("");
110 string text("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-_¯åäöÅÄÖ^~+=`\"!#¤%&/()=¡@£$½¥{[]}¶½§±"); 109 string text("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-_¯åäöÅÄÖ^~+=`\"!#¤%&/()=¡@£$½¥{[]}¶½§±");
@@ -117,7 +116,9 @@ int main(int argc, char **argv) {
117 displayname = argv[++a]; 116 displayname = argv[++a];
118 } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) { 117 } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) {
119 text = argv[++a]; 118 text = argv[++a];
120 } 119 } else if (strcmp("-rotate", argv[a]) == 0)
120 rotate = true;
121
121 } 122 }
122 123
123 App app(displayname.c_str()); 124 App app(displayname.c_str());
@@ -126,6 +127,9 @@ int main(int argc, char **argv) {
126 cerr<<"Failed to load: "<<fontname<<endl; 127 cerr<<"Failed to load: "<<fontname<<endl;
127 128
128 app.setText(text); 129 app.setText(text);
130 if (rotate)
131 app.font().rotate(90);
132
129 app.redraw(); 133 app.redraw();
130 app.eventLoop(); 134 app.eventLoop();
131 135