diff options
author | simonb <simonb> | 2006-03-26 04:02:30 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-03-26 04:02:30 (GMT) |
commit | af74a2284551c8511b66d77112c7bf32831c1522 (patch) | |
tree | 35a8830352f5facc1fc9c58b82c0c6dce8fc921e /src/tests/testFont.cc | |
parent | 872f6a0e1e4230f702ad69fa2d7e10a2fa78b7a3 (diff) | |
download | fluxbox-af74a2284551c8511b66d77112c7bf32831c1522.zip fluxbox-af74a2284551c8511b66d77112c7bf32831c1522.tar.bz2 |
rotated fonts, buttons, containers. Used for tabs for now
Diffstat (limited to 'src/tests/testFont.cc')
-rw-r--r-- | src/tests/testFont.cc | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/src/tests/testFont.cc b/src/tests/testFont.cc index 2ee764c..b382594 100644 --- a/src/tests/testFont.cc +++ b/src/tests/testFont.cc | |||
@@ -43,6 +43,7 @@ public: | |||
43 | 0, 0, 640, 480, KeyPressMask | ExposureMask) { | 43 | 0, 0, 640, 480, KeyPressMask | ExposureMask) { |
44 | m_background = background; | 44 | m_background = background; |
45 | m_foreground = foreground; | 45 | m_foreground = foreground; |
46 | m_orient = FbTk::ROT0; | ||
46 | m_win.show(); | 47 | m_win.show(); |
47 | m_win.setBackgroundColor(FbTk::Color(background.c_str(), m_win.screenNumber())); | 48 | m_win.setBackgroundColor(FbTk::Color(background.c_str(), m_win.screenNumber())); |
48 | FbTk::EventManager::instance()->add(*this, m_win); | 49 | FbTk::EventManager::instance()->add(*this, m_win); |
@@ -70,43 +71,70 @@ public: | |||
70 | 71 | ||
71 | void redraw() { | 72 | void redraw() { |
72 | size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size()); | 73 | size_t text_w = m_font.textWidth(m_text.c_str(), m_text.size()); |
74 | int mult = 1; | ||
75 | if (m_orient == FbTk::ROT180) | ||
76 | mult = -1; | ||
73 | size_t text_h = m_font.height(); | 77 | size_t text_h = m_font.height(); |
74 | int x = 640/2 - text_w/2; | 78 | int x = 640/2 - mult* text_w/2; |
75 | int y = 480/2 - text_h/2; | 79 | int y = 480/2 - mult*text_h/2; |
76 | m_win.clear(); | 80 | m_win.clear(); |
77 | FbTk::GContext wingc(m_win.drawable()); | 81 | FbTk::GContext wingc(m_win.drawable()); |
78 | 82 | ||
83 | int bx1 = 0; | ||
84 | int by1 = 0; | ||
85 | int bx2 = text_w; | ||
86 | int by2 = 0; | ||
87 | int tmp; | ||
88 | |||
89 | switch (m_orient) { | ||
90 | case FbTk::ROT90: | ||
91 | by2 = bx2; | ||
92 | bx2 = 0; | ||
93 | break; | ||
94 | case FbTk::ROT180: | ||
95 | bx2 = -bx2; | ||
96 | break; | ||
97 | case FbTk::ROT270: | ||
98 | by2 = -bx2; | ||
99 | bx2 = 0; | ||
100 | break; | ||
101 | } | ||
102 | |||
103 | /* | ||
79 | m_win.drawLine(wingc.gc(), | 104 | m_win.drawLine(wingc.gc(), |
80 | x, y + m_font.descent(), | 105 | x, y + m_font.descent(), |
81 | x + text_w, y + m_font.descent()); | 106 | x + text_w, y + m_font.descent()); |
82 | m_win.drawLine(wingc.gc(), | 107 | m_win.drawLine(wingc.gc(), |
83 | x, y - text_h, | 108 | x, y - text_h, |
84 | x + text_w, y - text_h); | 109 | x + text_w, y - text_h); |
110 | */ | ||
111 | // draw the baseline in red | ||
85 | wingc.setForeground(FbTk::Color("red", m_win.screenNumber())); | 112 | wingc.setForeground(FbTk::Color("red", m_win.screenNumber())); |
86 | m_win.drawLine(wingc.gc(), | 113 | m_win.drawLine(wingc.gc(), |
87 | x, y, x + text_w, y); | 114 | x + bx1, y + by1, x + bx2, y+by2); |
88 | wingc.setForeground(FbTk::Color(m_foreground.c_str(), m_win.screenNumber())); | 115 | wingc.setForeground(FbTk::Color(m_foreground.c_str(), m_win.screenNumber())); |
89 | //cerr<<"text width: "<<m_font.textWidth(m_text.c_str(), m_text.size())<<endl; | 116 | cerr<<"text size "<<text_w<<"x"<<text_h<<endl; |
90 | m_font.drawText(m_win, | 117 | m_font.drawText(m_win, |
91 | 0, wingc.gc(), | 118 | 0, wingc.gc(), |
92 | m_text.c_str(), m_text.size(), | 119 | m_text.c_str(), m_text.size(), |
93 | x, y); | 120 | x, y, m_orient); |
94 | 121 | ||
95 | } | 122 | } |
96 | 123 | ||
97 | FbTk::Font &font() { return m_font; } | 124 | FbTk::Font &font() { return m_font; } |
98 | void setText(const std::string& text) { m_text = text; } | 125 | void setText(const std::string& text, const FbTk::Orientation orient) { m_text = text; m_orient = orient; } |
99 | 126 | ||
100 | private: | 127 | private: |
101 | string m_foreground, m_background; | 128 | string m_foreground, m_background; |
102 | FbTk::FbWindow m_win; | 129 | FbTk::FbWindow m_win; |
103 | FbTk::Font m_font; | 130 | FbTk::Font m_font; |
131 | FbTk::Orientation m_orient; | ||
104 | string m_text; | 132 | string m_text; |
105 | }; | 133 | }; |
106 | 134 | ||
107 | int main(int argc, char **argv) { | 135 | int main(int argc, char **argv) { |
108 | //bool antialias = false; | 136 | //bool antialias = false; |
109 | bool rotate = false; | 137 | FbTk::Orientation orient = FbTk::ROT0; |
110 | bool xft = false; | 138 | bool xft = false; |
111 | string fontname(""); | 139 | string fontname(""); |
112 | string displayname(""); | 140 | string displayname(""); |
@@ -122,8 +150,8 @@ int main(int argc, char **argv) { | |||
122 | displayname = argv[++a]; | 150 | displayname = argv[++a]; |
123 | } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) { | 151 | } else if (strcmp("-text", argv[a]) == 0 && a + 1 < argc) { |
124 | text = argv[++a]; | 152 | text = argv[++a]; |
125 | } else if (strcmp("-rotate", argv[a]) == 0) { | 153 | } else if (strcmp("-orient", argv[a]) == 0) { |
126 | rotate = true; | 154 | orient = (FbTk::Orientation) (atoi(argv[++a]) % 4); |
127 | } else if (strcmp("-bg", argv[a]) == 0 && a + 1 < argc) { | 155 | } else if (strcmp("-bg", argv[a]) == 0 && a + 1 < argc) { |
128 | background = argv[++a]; | 156 | background = argv[++a]; |
129 | } else if (strcmp("-fg", argv[a]) == 0 && a + 1 < argc) { | 157 | } else if (strcmp("-fg", argv[a]) == 0 && a + 1 < argc) { |
@@ -134,7 +162,7 @@ int main(int argc, char **argv) { | |||
134 | // cerr<<"-antialias"<<endl; | 162 | // cerr<<"-antialias"<<endl; |
135 | cerr<<"-display <display>"<<endl; | 163 | cerr<<"-display <display>"<<endl; |
136 | cerr<<"-text <text>"<<endl; | 164 | cerr<<"-text <text>"<<endl; |
137 | cerr<<"-rotate"<<endl; | 165 | cerr<<"-orient"<<endl; |
138 | cerr<<"-fg <foreground color>"<<endl; | 166 | cerr<<"-fg <foreground color>"<<endl; |
139 | cerr<<"-bg <background color>"<<endl; | 167 | cerr<<"-bg <background color>"<<endl; |
140 | cerr<<"-h"<<endl; | 168 | cerr<<"-h"<<endl; |
@@ -148,10 +176,12 @@ int main(int argc, char **argv) { | |||
148 | //app.font().setAntialias(antialias); | 176 | //app.font().setAntialias(antialias); |
149 | if (!app.font().load(fontname.c_str())) | 177 | if (!app.font().load(fontname.c_str())) |
150 | cerr<<"Failed to load: "<<fontname<<endl; | 178 | cerr<<"Failed to load: "<<fontname<<endl; |
179 | if (orient && !app.font().validOrientation(orient)) { | ||
180 | cerr<<"Orientation not valid ("<<orient<<")"<<endl; | ||
181 | orient = FbTk::ROT0; | ||
182 | } | ||
151 | cerr<<"Setting text: "<<text<<endl; | 183 | cerr<<"Setting text: "<<text<<endl; |
152 | app.setText(text); | 184 | app.setText(text, orient); |
153 | if (rotate) | ||
154 | app.font().rotate(90); | ||
155 | 185 | ||
156 | app.redraw(); | 186 | app.redraw(); |
157 | app.eventLoop(); | 187 | app.eventLoop(); |