aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-09-11 16:51:21 (GMT)
committerfluxgen <fluxgen>2003-09-11 16:51:21 (GMT)
commitfbe722de6da27d80c69551bdeffa271764094c6f (patch)
treef1f048c4ee239783d7e699394210477306e4d496
parent9582e35ab89e14397bf1aeaea1d98a10d4064c60 (diff)
downloadfluxbox-fbe722de6da27d80c69551bdeffa271764094c6f.zip
fluxbox-fbe722de6da27d80c69551bdeffa271764094c6f.tar.bz2
update
-rw-r--r--src/tests/Makefile16
-rw-r--r--src/tests/testFont.cc108
2 files changed, 65 insertions, 59 deletions
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 2df6ebe..90e45ce 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -4,13 +4,12 @@ LIBS=
4XFLAGS= -I/usr/X11R6/include 4XFLAGS= -I/usr/X11R6/include
5XLIBS= -L/usr/X11R6/lib -lX11 -lXft 5XLIBS= -L/usr/X11R6/lib -lX11 -lXft
6COMPILEFILE=$(CXX) -c $(CXXFLAGS) 6COMPILEFILE=$(CXX) -c $(CXXFLAGS)
7FONT_OBJ = ../BaseDisplay.o ../FbTk/Font.o ../FbTk/XFontImp.o ../FbTk/XftFontImp.o ../FbTk/XmbFontImp.o \ 7FONT_OBJ = ../FbTk/libFbTk.a
8 ../FbTk/Timer.o ../StringUtil.o ../i18n.o
9 8
10all: testLayers testStringUtil testKeys testResource testSignal 9all: testLayers testStringUtil testKeys testResource testSignal glxtest
11 10
12.cc.o: 11.cc.o:
13 $(CXX) -c $(CXXFLAGS) $< -o $@ 12 $(CXX) -c $(CXXFLAGS) $<
14 13
15../FbTk/XftFontImp.o: ../FbTk/XftFontImp.hh ../FbTk/XftFontImp.cc 14../FbTk/XftFontImp.o: ../FbTk/XftFontImp.hh ../FbTk/XftFontImp.cc
16 15
@@ -20,8 +19,11 @@ all: testLayers testStringUtil testKeys testResource testSignal
20 19
21../FbTk/Font.o: ../FbTk/XFontImp.hh ../FbTk/XftFontImp.hh ../FbTk/XmbFontImp.hh ../FbTk/Font.hh ../FbTk/Font.cc 20../FbTk/Font.o: ../FbTk/XFontImp.hh ../FbTk/XftFontImp.hh ../FbTk/XmbFontImp.hh ../FbTk/Font.hh ../FbTk/Font.cc
22 21
22glxtest: ../FbTk/App.hh glxtest.cc
23 ${CXX} glxtest.cc ${CXXFLAGS} ${XLIBS} -lGL -lGLU -lXpm -o glxtest
24
23StringUtil.o: ../StringUtil.cc ../StringUtil.hh 25StringUtil.o: ../StringUtil.cc ../StringUtil.hh
24 $(CXX) -c $(CXXFLAGS) ../StringUtil.cc -o StringUtil.o 26 $(CXX) -c $(CXXFLAGS) ../StringUtil.cc
25 27
26Keys.o: ../Keys.cc ../Keys.hh 28Keys.o: ../Keys.cc ../Keys.hh
27 $(CXX) -c $(CXXFLAGS) $(XFLAGS) ../Keys.cc -o Keys.o 29 $(CXX) -c $(CXXFLAGS) $(XFLAGS) ../Keys.cc -o Keys.o
@@ -32,8 +34,8 @@ Resource.o: ../Resource.cc ../Resource.hh
32../FbTk/SignalHandler.o: 34../FbTk/SignalHandler.o:
33 ${COMPILEFILE} ../FbTk/SignalHandler.cc -o ../FbTk/SignalHandler.o 35 ${COMPILEFILE} ../FbTk/SignalHandler.cc -o ../FbTk/SignalHandler.o
34 36
35testStringUtil: StringUtiltest.o StringUtil.o 37testStringUtil: StringUtiltest.o ../FbTk/StringUtil.o
36 $(CXX) $(LIBS) StringUtiltest.o StringUtil.o -o testStringUtil 38 $(CXX) $(LIBS) StringUtiltest.o ../FbTk/StringUtil.o -o testStringUtil
37 39
38testKeys: Keys.o testKeys.o StringUtil.o 40testKeys: Keys.o testKeys.o StringUtil.o
39 $(CXX) $(LIBS) $(XLIBS) StringUtil.o Keys.o testKeys.o -o testKeys 41 $(CXX) $(LIBS) $(XLIBS) StringUtil.o Keys.o testKeys.o -o testKeys
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