trunk 20080912
[gitenigma.git] / lib / gui / testpicture.cpp
blob7afc904c466654a58289825f372577e6d9e24a4d
1 #include <lib/gui/testpicture.h>
2 #include <lib/gui/eskin.h>
3 #include <lib/gui/elabel.h>
4 #include <lib/gdi/font.h>
5 #include <lib/gui/guiactions.h>
6 #include <lib/gui/numberactions.h>
8 void eTestPicture::hideDesc()
10 if (testmode != testFUBK)
11 description->hide();
14 int eTestPicture::eventHandler(const eWidgetEvent &event)
16 switch (event.type)
18 case eWidgetEvent::evtAction:
19 if (event.action == &i_cursorActions->ok)
20 close(-1);
21 else if (event.action == &i_cursorActions->cancel)
22 close(-1);
23 else if (event.action == &i_numberActions->key0)
24 close(0);
25 else if (event.action == &i_numberActions->key1)
26 close(1);
27 else if (event.action == &i_numberActions->key2)
28 close(2);
29 else if (event.action == &i_numberActions->key3)
30 close(3);
31 else if (event.action == &i_numberActions->key4)
32 close(4);
33 else if (event.action == &i_numberActions->key5)
34 close(5);
35 else if (event.action == &i_numberActions->key6)
36 close(6);
37 else if (event.action == &i_numberActions->key7)
38 close(7);
39 else if (event.action == &i_numberActions->key8)
40 close(8);
41 else if (event.action == &i_numberActions->key9)
42 close(9);
43 else
44 break;
45 return 0;
46 case eWidgetEvent::willShow:
47 desctimer.start(1000);
48 break;
49 default:
50 break;
52 return eWidget::eventHandler(event);
55 void eTestPicture::redrawWidget(gPainter *target, const eRect &area)
57 switch (testmode)
59 case testColorbar:
61 for (int i=0; i<8; ++i)
63 gColor c=basic[i];
65 target->setForegroundColor(c);
66 target->fill(eRect(720/8*i, 0, 720/8, 576));
68 break;
70 case testGray:
72 for (int i=0; i<8; ++i)
74 gColor c=gray+i;
76 target->setForegroundColor(c);
77 target->fill(eRect(720/8*i, 0, 720/8, 576));
79 break;
81 case testFUBK:
83 // background
84 target->setBackgroundColor(gray+2);
85 target->clear();
87 // white lines
88 target->setForegroundColor(white);
89 for (int x=6; x<720; x+=44)
90 target->fill(eRect(x, 0, 3, 576));
91 for (int y=34; y<576; y+=44)
92 target->fill(eRect(0, y, 720, 3));
94 for (int i=0; i<8; ++i)
96 target->setForegroundColor(basic[i]);
97 target->fill(eRect(140+i*55, 80, 55, 80));
98 target->setForegroundColor(gray+i);
99 target->fill(eRect(140+i*55, 160, 55, 80));
101 #if 1
102 int freq;
103 int phase=0;
104 for (int x=0; x<440; x+=freq)
106 freq=(440-x)/44 + 1;
107 target->setForegroundColor(phase ? white : black);
108 target->fill(eRect(140+x, 320, freq, 160));
109 phase = !phase;
111 #endif
112 #if 0
113 double phase=0;
114 for (int x=0; x<440; ++x)
116 // freq = 0.5 .. 5Mhz -> 10 Pixel ~= 1Mhz
117 double inc = (x/440.0)*(x/440.0) * 3.141 * 2 / 5.0 + 0.5;
118 phase += inc;
119 int s = int((sin(phase) + 1) * 4);
120 if (s < 0)
121 s = 0;
122 if (s > 7)
123 s = 7;
124 target->setForegroundColor(gray + s);
125 target->fill(eRect(140+x, 320, 1, 160));
127 #endif
129 break;
131 case testRed:
132 target->setBackgroundColor(red);
133 target->clear();
134 break;
135 case testGreen:
136 target->setBackgroundColor(green);
137 target->clear();
138 break;
139 case testBlue:
140 target->setBackgroundColor(blue);
141 target->clear();
142 break;
143 case testWhite:
144 target->setBackgroundColor(white);
145 target->clear();
146 break;
147 case testBlack:
148 target->setBackgroundColor(black);
149 target->clear();
150 break;
154 eTestPicture::eTestPicture(int testmode): eWidget(0, 1), testmode(testmode), desctimer(eApp)
156 red = eSkin::getActive()->queryColor("std_red");
157 green = eSkin::getActive()->queryColor("std_green");
158 blue = eSkin::getActive()->queryColor("std_blue");
159 black = eSkin::getActive()->queryColor("std_black");
160 white = eSkin::getActive()->queryColor("std_white");
161 gray = eSkin::getActive()->queryColor("std_gray");
162 setBackgroundColor(-1);
164 CONNECT(desctimer.timeout, eTestPicture::hideDesc);
166 basic[0] = white;
167 basic[1] = eSkin::getActive()->queryColor("std_dyellow");
168 basic[2] = eSkin::getActive()->queryColor("std_dcyan");
169 basic[3] = eSkin::getActive()->queryColor("std_dgreen");
170 basic[4] = eSkin::getActive()->queryColor("std_dmagenta");
171 basic[5] = eSkin::getActive()->queryColor("std_dred");
172 basic[6] = eSkin::getActive()->queryColor("std_dblue");
173 basic[7] = black;
175 addActionMap(&i_numberActions->map);
176 addActionMap(&i_cursorActions->map);
178 description = new eLabel(this, eLabel::flagVCenter);
179 switch (testmode)
181 case testColorbar:
182 case testRed:
183 case testBlue:
184 case testGreen:
185 case testWhite:
186 case testBlack:
187 case testGray:
188 description->move(ePoint(100, 100));
189 description->resize(eSize(200, 30));
190 description->setBackgroundColor(black);
191 description->setForegroundColor(white);
192 break;
193 case testFUBK:
194 description->move(ePoint(140, 240));
195 description->resize(eSize(440, 80));
196 description->setBackgroundColor(black);
197 description->setForegroundColor(white);
198 description->setText("ENIGMA");
199 description->setAlign(eTextPara::dirCenter);
200 break;
201 default:
202 break;
204 switch (testmode)
206 case testColorbar: description->setText("COLORBAR"); break;
207 case testRed: description->setText("RED"); break;
208 case testBlue: description->setText("BLUE"); break;
209 case testGreen: description->setText("GREEN"); break;
210 case testWhite: description->setText("WHITE (100%)"); break;
211 case testGray: description->setText("0% TO 100%"); break;
212 case testBlack: description->setText("BLACK (0%)"); break;
214 description->show();
216 setHelpID(95);
219 int eTestPicture::display(int mode)
221 int res;
222 eTestPicture test(mode);
223 test.move(ePoint(0, 0));
224 test.resize(eSize(720, 576));
225 test.show();
226 res = test.exec();
227 test.hide();
228 return res;