diff options
author | fluxgen <fluxgen> | 2004-01-11 20:57:53 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-01-11 20:57:53 (GMT) |
commit | a819ff8252cc65c7e49d41b67c9bb1c1a40f0fb2 (patch) | |
tree | 22bd24d218a83281c7d10e9c7e03be759959d81c /src/tests/texturetest.cc | |
parent | d03b0107e7cb1d58acd28f2b3df8b393199d84bd (diff) | |
download | fluxbox_pavel-a819ff8252cc65c7e49d41b67c9bb1c1a40f0fb2.zip fluxbox_pavel-a819ff8252cc65c7e49d41b67c9bb1c1a40f0fb2.tar.bz2 |
texture tests
Diffstat (limited to 'src/tests/texturetest.cc')
-rw-r--r-- | src/tests/texturetest.cc | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/tests/texturetest.cc b/src/tests/texturetest.cc new file mode 100644 index 0000000..0ba6741 --- /dev/null +++ b/src/tests/texturetest.cc | |||
@@ -0,0 +1,135 @@ | |||
1 | #include "ImageControl.hh" | ||
2 | #include "Color.hh" | ||
3 | #include "GContext.hh" | ||
4 | #include "FbPixmap.hh" | ||
5 | #include "Texture.hh" | ||
6 | #include "FbWindow.hh" | ||
7 | #include "EventHandler.hh" | ||
8 | #include "EventManager.hh" | ||
9 | #include "Theme.hh" | ||
10 | #include "Font.hh" | ||
11 | #include "App.hh" | ||
12 | |||
13 | #include <memory> | ||
14 | #include <iostream> | ||
15 | #include <string> | ||
16 | |||
17 | using namespace std; | ||
18 | using namespace FbTk; | ||
19 | |||
20 | class TestTheme: public Theme { | ||
21 | public: | ||
22 | TestTheme(int screen):Theme(screen) { } | ||
23 | bool fallback(ThemeItem_base &item) { return false; } | ||
24 | void reconfigTheme() { } | ||
25 | }; | ||
26 | |||
27 | class Application: public FbTk::FbWindow, public FbTk::EventHandler { | ||
28 | public: | ||
29 | Application(int box_size, int num): | ||
30 | FbWindow(0, 0, 0, 640, box_size*num/8 - 3*5, ExposureMask | KeyPressMask), | ||
31 | m_box_size(box_size), | ||
32 | m_num(num), | ||
33 | m_font("fixed"), | ||
34 | m_imgctrl(screenNumber(), true, 8, | ||
35 | 100, 100), | ||
36 | m_background(*this, 640, 480, depth()), | ||
37 | m_gc(m_background) { | ||
38 | setName("Texture Test"); | ||
39 | setBackgroundPixmap(m_background.drawable()); | ||
40 | |||
41 | FbTk::EventManager::instance()->add(*this, *this); | ||
42 | |||
43 | renderPixmaps(); | ||
44 | |||
45 | show(); | ||
46 | } | ||
47 | void keyPressEvent(XKeyEvent &ev) { | ||
48 | App::instance()->end(); | ||
49 | } | ||
50 | void exposeEvent(XExposeEvent &ev) { | ||
51 | clear(); | ||
52 | } | ||
53 | |||
54 | private: | ||
55 | |||
56 | void renderPixmap(const Texture &text, int x, int y) { | ||
57 | Pixmap pm = m_imgctrl.renderImage(m_box_size, m_box_size, | ||
58 | text); | ||
59 | |||
60 | m_background.copyArea(pm, m_gc.gc(), | ||
61 | 0, 0, | ||
62 | x, y, | ||
63 | m_box_size, m_box_size); | ||
64 | m_imgctrl.removeImage(pm); | ||
65 | } | ||
66 | |||
67 | void renderPixmaps() { | ||
68 | |||
69 | m_gc.setForeground(Color("gray", screenNumber())); | ||
70 | |||
71 | m_background.fillRectangle(m_gc.gc(), | ||
72 | 0, 0, | ||
73 | width(), height()); | ||
74 | // for text color | ||
75 | m_gc.setForeground(Color("black", screenNumber())); | ||
76 | |||
77 | const int step_size = m_box_size + 5; | ||
78 | int next_x = 5; | ||
79 | int next_y = 5; | ||
80 | |||
81 | TestTheme tm(screenNumber()); | ||
82 | std::auto_ptr<ThemeItem<Texture> > text; | ||
83 | char value[18]; | ||
84 | for (int i=0; i<m_num; ++i) { | ||
85 | sprintf(value, "%d", i); | ||
86 | text.reset(new ThemeItem<Texture> | ||
87 | (tm, | ||
88 | string("texture") + value, | ||
89 | string("Texture") + value)); | ||
90 | cerr<<"Theme: "<<text->name()<<endl; | ||
91 | // load new style | ||
92 | ThemeManager::instance().load("test.theme"); | ||
93 | |||
94 | renderPixmap(**text.get(), next_x, next_y); | ||
95 | |||
96 | next_x += step_size; | ||
97 | if (next_x + m_box_size > width()) { | ||
98 | m_font.drawText(m_background.drawable(), | ||
99 | screenNumber(), | ||
100 | m_gc.gc(), | ||
101 | value, strlen(value), | ||
102 | next_x, next_y + m_box_size/2); | ||
103 | next_x = 5; | ||
104 | next_y += step_size; | ||
105 | } | ||
106 | |||
107 | } | ||
108 | |||
109 | |||
110 | } | ||
111 | |||
112 | |||
113 | const int m_box_size; | ||
114 | const int m_num; | ||
115 | FbTk::Font m_font; | ||
116 | ImageControl m_imgctrl; | ||
117 | FbPixmap m_background; | ||
118 | FbTk::GContext m_gc; | ||
119 | }; | ||
120 | |||
121 | int main(int argc, char **argv) { | ||
122 | int boxsize= 60; | ||
123 | int num = 63; | ||
124 | for (int i=1; i<argc; ++i) { | ||
125 | if (strcmp(argv[i], "-boxsize") == 0 && i + 1 < argc) | ||
126 | boxsize = atoi(argv[++i]); | ||
127 | else if (strcmp(argv[i], "-num") == 0 && i + 1 < argc) | ||
128 | num = atoi(argv[++i]); | ||
129 | } | ||
130 | App realapp; | ||
131 | Application app(boxsize, num); | ||
132 | |||
133 | realapp.eventLoop(); | ||
134 | |||
135 | } | ||