added "iv.dynstring"
[iv.d.git] / egra / test.d
blob49ee41700e4ff165c8223a26405c0945ce8f96da
1 /* E-Mail Client
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module test /*is aliced*/;
19 import arsd.simpledisplay;
21 import iv.cmdcon;
22 import iv.cmdcongl;
23 import iv.strex;
24 import iv.utfutil;
25 import iv.vfs.io;
26 import iv.vfs.util;
28 import iv.egra;
31 // ////////////////////////////////////////////////////////////////////////// //
32 static immutable string TestStyle = `
33 MainPaneWindow {
34 grouplist-divline: white;
35 grouplist-back: #222;
37 threadlist-divline: white;
38 threadlist-back: #222;
41 TitlerWindow {
42 frame: white;
43 title-back: @frame;
44 title-text: black;
46 back: rgb(0, 92, 0);
47 text: #7f0;
52 // ////////////////////////////////////////////////////////////////////////// //
53 //__gshared int lastWinWidth, lastWinHeight;
56 // ////////////////////////////////////////////////////////////////////////// //
57 public class TitlerWindow : SubWindow {
58 public:
59 LineEditWidget edtTitle;
60 LineEditWidget fromName;
61 LineEditWidget fromMail;
63 protected:
64 string name;
65 string mail;
66 string folder;
67 string title;
69 bool delegate (const(char)[] name, const(char)[] mail, const(char)[] folder, const(char)[] title) onSelected;
71 override void createWidgets () {
72 new SpacerWidget(2);
74 version(none) {
75 fromName = new LineEditWidget("Name:");
76 fromName.flex = 1;
78 new SpacerWidget(1);
79 fromMail = new LineEditWidget("Mail:");
80 fromMail.flex = 1;
82 new SpacerWidget(1);
83 edtTitle = new LineEditWidget("Title:");
84 edtTitle.flex = 1;
85 } else {
86 (new HBoxWidget).enter{
87 with (new HotLabelWidget("&Name:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
88 new SpacerWidget(4);
89 fromName = new LineEditWidget();
90 fromName.flex = 1;
91 }.flex = 1;
93 new SpacerWidget(1);
94 (new HBoxWidget).enter{
95 with (new HotLabelWidget("&Mail:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
96 new SpacerWidget(4);
97 fromMail = new LineEditWidget();
98 fromMail.flex = 1;
99 }.flex = 1;
101 new SpacerWidget(1);
102 (new HBoxWidget).enter{
103 with (new HotLabelWidget("&Title:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
104 new SpacerWidget(4);
105 edtTitle = new LineEditWidget();
106 edtTitle.flex = 1;
107 }.flex = 1;
110 new SpacerWidget(4);
111 (new HBoxWidget).enter{
112 new SpacerWidget(2);
113 new SpringWidget(1);
114 with (new ButtonWidget(" O&k ")) {
115 hsizeId = "okcancel";
116 deftype = Default.Accept;
117 onAction = delegate (self) {
118 if (onSelected !is null) {
119 if (!onSelected(fromName.str, fromMail.str, folder, edtTitle.str)) return;
121 close();
124 new SpacerWidget(2);
125 with (new ButtonWidget(" Cancel ")) {
126 hsizeId = "okcancel";
127 deftype = Default.Cancel;
128 onAction = delegate (self) {
129 close();
132 new SpringWidget(1);
133 new SpacerWidget(2);
135 new SpacerWidget(4);
137 fromName.str = name;
138 fromMail.str = mail;
139 edtTitle.str = title;
141 relayoutResize();
142 centerWindow();
144 edtTitle.focus();
147 this (string aname, string amail, string afolder, string atitle) {
148 string caption = "Title for "~aname~" <"~amail~">";
149 name = aname;
150 mail = amail;
151 folder = afolder;
152 title = atitle;
153 super(caption);
158 // ////////////////////////////////////////////////////////////////////////// //
159 public class TagOptionsWindow : SubWindow {
160 LabelWidget optPath; // real path
161 LineEditWidget optMonthes;
162 CheckboxWidget optThreaded;
163 CheckboxWidget optAttaches;
164 string tagname;
166 void delegate (const(char)[] tagname) onUpdated;
168 this (string atagname) {
169 tagname = atagname;
170 string caption = "options for '"~atagname~"'";
171 super(caption);
174 override void createWidgets () {
175 optPath = new LabelWidget("", LabelWidget.HAlign.Center);
176 optPath.flex = 1;
178 version(none) {
179 optMonthes = new LineEditWidget("Monthes:");
180 optMonthes.flex = 1;
181 optMonthes.width = optMonthes.titwdt+64;
182 } else {
183 (new HBoxWidget).enter{
184 with (new HotLabelWidget("&Monthes:", LabelWidget.HAlign.Right)) { width = width+2; /*hsizeId = "editors";*/ }
185 new SpacerWidget(4);
186 optMonthes = new LineEditWidget();
187 //optMonthes.flex = 1;
188 optMonthes.width = gxTextWidthUtf("96669");
189 //new SpringWidget(1);
190 }.flex = 1;
193 optThreaded = new CheckboxWidget("&Threaded");
194 optThreaded.flex = 1;
196 optAttaches = new CheckboxWidget("&Attaches");
197 optAttaches.flex = 1;
199 new SpacerWidget(4);
200 (new HBoxWidget).enter{
201 new SpacerWidget(2);
202 new SpringWidget(1);
203 with (new ButtonWidget(" O&k ")) {
204 hsizeId = "okcancel";
205 deftype = Default.Accept;
206 onAction = delegate (self) {
207 if (onUpdated !is null) onUpdated(tagname);
208 close();
211 new SpacerWidget(2);
212 with (new ButtonWidget(" Cancel ")) {
213 hsizeId = "okcancel";
214 deftype = Default.Cancel;
215 onAction = delegate (self) {
216 close();
219 new SpringWidget(1);
220 new SpacerWidget(2);
222 new SpacerWidget(4);
224 optMonthes.focus();
226 optPath.text = "booPath";
227 optMonthes.str = "666";
229 optThreaded.enabled = false;
230 optAttaches.enabled = true;
232 optMonthes.killTextOnChar = true;
234 relayoutResize();
235 centerWindow();
239 // ////////////////////////////////////////////////////////////////////////// //
240 void initConsole () {
241 // //////////////////////////////////////////////////////////////////// //
242 conRegFunc!(() {
243 import core.memory : GC;
244 conwriteln("starting GC collection...");
245 GC.collect();
246 GC.minimize();
247 conwriteln("GC collection complete.");
248 })("gc_collect", "force GC collection cycle");
251 // //////////////////////////////////////////////////////////////////// //
252 conRegFunc!(() {
253 auto qww = new YesNoWindow("Quit?", "Do you really want to quit?", true);
254 qww.onYes = () { concmd("quit"); };
255 qww.addModal();
256 })("quit_prompt", "quit with prompt");
258 conRegFunc!(() {
259 new TitlerWindow("name", "mail", "folder", "title");
260 })("window_titler", "titler window test");
262 conRegFunc!(() {
263 new TagOptionsWindow("xtag");
264 })("window_tagoptions", "tag options window test");
268 // ////////////////////////////////////////////////////////////////////////// //
269 __gshared MainPaneWindow mainPane;
272 final class MainPaneWindow : SubWindow {
273 ProgressBarWidget pbar;
275 this () {
276 super(null, GxPoint(0, 0), GxSize(screenWidth, screenHeight));
277 mType = Type.OnBottom;
279 pbar = new ProgressBarWidget(rootWidget, "progress bar");
280 pbar.setMinMax(0, 100);
281 pbar.width = clientWidth-64;
282 pbar.current = 50;
283 pbar.posy = clientHeight-pbar.height-8;
284 pbar.posx = (clientWidth-pbar.width)/2;
286 add();
289 // //////////////////////////////////////////////////////////////////// //
290 override void onPaint () {
291 if (closed) return;
293 enum guiGroupListWidth = 128;
294 enum guiThreadListHeight = 520;
296 gxFillRect(0, 0, guiGroupListWidth, screenHeight, getColor("grouplist-back"));
297 gxVLine(guiGroupListWidth, 0, screenHeight, getColor("grouplist-divline"));
299 gxFillRect(guiGroupListWidth+1, 0, screenWidth, guiThreadListHeight, getColor("threadlist-back"));
300 gxHLine(guiGroupListWidth+1, guiThreadListHeight, screenWidth, getColor("threadlist-divline"));
302 version(test_round_rect) {
303 gxClipReset();
304 gxFillRoundedRect(lastMouseX-16, lastMouseY-16, 128, 96, rrad, /*gxSolidWhite*/gxRGBA!(0, 255, 0, 127));
305 //gxDrawRoundedRect(lastMouseX-16, lastMouseY-16, 128, 96, rrad, gxRGBA!(0, 255, 0, 127));
308 drawWidgets();
311 version(test_round_rect) {
312 int rrad = 16;
315 override bool onKeyBubble (KeyEvent event) {
316 if (event.pressed) {
317 version(test_round_rect) {
318 if (event == "Plus") { ++rrad; return true; }
319 if (event == "Minus") { --rrad; return true; }
321 if (event == "C-Q") { concmd("quit_prompt"); return true; }
322 if (event == "1") { concmd("window_titler"); return true; }
323 if (event == "2") { concmd("window_tagoptions"); return true; }
324 if (event == "Minus") { pbar.current = pbar.current-1; return true; }
325 if (event == "Plus") { pbar.current = pbar.current+1; return true; }
326 //if (dbg_dump_keynames) conwriteln("key: ", event.toStr, ": ", event.modifierState&ModifierState.windows);
327 //foreach (const ref kv; mainAppKeyBindings.byKeyValue) if (event == kv.key) concmd(kv.value);
329 return false;
332 // returning `false` to avoid screen rebuilding by dispatcher
333 override bool onMouseBubble (MouseEvent event) {
334 if (event.type == MouseEventType.buttonPressed || event.type == MouseEventType.buttonReleased) {
335 postScreenRebuild();
336 } else {
337 // for OpenGL, this rebuilds the whole screen anyway
338 postScreenRepaint();
340 return false;
345 // ////////////////////////////////////////////////////////////////////////// //
346 void main (string[] args) {
347 defaultColorStyle.parseStyle(TestStyle);
348 //egraDefaultFontSize = 48;
350 glconAllowOpenGLRender = false;
352 sdpyWindowClass = "EGUITest";
353 //glconShowKey = "M-Grave";
355 initConsole();
357 conProcessQueue();
358 conProcessArgs!true(args);
360 egraCreateSystemWindow("EGRA Test", allowResize:false);
362 vbwin.addEventListener((QuitEvent evt) {
363 if (vbwin.closed) return;
364 if (isQuitRequested) { vbwin.close(); return; }
365 vbwin.close();
368 static if (is(typeof(&vbwin.closeQuery))) {
369 vbwin.closeQuery = delegate () { concmd("quit"); egraPostDoConCommands(); };
372 mainPane = new MainPaneWindow();
373 //egraSkipScreenClear = true; // main pane is fullscreen
375 postScreenRebuild();
376 repostHideMouse();
378 vbwin.eventLoop(1000*10,
379 delegate () {
380 egraProcessConsole();
382 delegate (KeyEvent event) {
383 if (egraOnKey(event)) return;
385 delegate (MouseEvent event) {
386 if (egraOnMouse(event)) return;
388 delegate (dchar ch) {
389 if (egraOnChar(ch)) return;
393 flushGui();
394 conProcessQueue(int.max/4);