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
;
31 // ////////////////////////////////////////////////////////////////////////// //
32 static immutable string TestStyle
= `
34 grouplist-divline: white;
37 threadlist-divline: white;
38 threadlist-back: #222;
53 // ////////////////////////////////////////////////////////////////////////// //
54 //__gshared int lastWinWidth, lastWinHeight;
57 // ////////////////////////////////////////////////////////////////////////// //
58 public class TitlerWindow
: SubWindow
{
60 LineEditWidget edtTitle
;
61 LineEditWidget fromName
;
62 LineEditWidget fromMail
;
70 bool delegate (dynstring name
, dynstring mail
, dynstring folder
, dynstring title
) onSelected
;
72 override void createWidgets () {
76 fromName
= new LineEditWidget("Name:");
80 fromMail
= new LineEditWidget("Mail:");
84 edtTitle
= new LineEditWidget("Title:");
87 (new HBoxWidget
).enter{
88 with (new HotLabelWidget("&Name:", LabelWidget
.HAlign
.Right
)) { width
= width
+2; hsizeId
= "editors"; }
90 fromName
= new LineEditWidget();
95 (new HBoxWidget
).enter{
96 with (new HotLabelWidget("&Mail:", LabelWidget
.HAlign
.Right
)) { width
= width
+2; hsizeId
= "editors"; }
98 fromMail
= new LineEditWidget();
103 (new HBoxWidget
).enter{
104 with (new HotLabelWidget("&Title:", LabelWidget
.HAlign
.Right
)) { width
= width
+2; hsizeId
= "editors"; }
106 edtTitle
= new LineEditWidget();
112 (new HBoxWidget
).enter{
115 with (new ButtonWidget(" O&k ")) {
116 hsizeId
= "okcancel";
117 deftype
= Default
.Accept
;
118 onAction
= delegate (self
) {
119 if (onSelected
!is null) {
120 if (!onSelected(fromName
.str, fromMail
.str, folder
, edtTitle
.str)) return;
126 with (new ButtonWidget(" Cancel ")) {
127 hsizeId
= "okcancel";
128 deftype
= Default
.Cancel
;
129 onAction
= delegate (self
) {
140 edtTitle
.str = title
;
148 this (const(char)[] aname
, const(char)[] amail
, const(char)[] afolder
, const(char)[] atitle
) {
149 dynstring caption
= "Title for "~aname
~" <"~amail
~">";
159 // ////////////////////////////////////////////////////////////////////////// //
160 public class TagOptionsWindow
: SubWindow
{
163 void delegate (const(char)[] tagname
) onUpdated
;
165 this (const(char)[] atagname
) {
167 dynstring caption
= "options for '"~atagname
~"'";
171 override void createWidgets () {
172 LabelWidget optPath
= new LabelWidget("", LabelWidget
.HAlign
.Center
);
175 LineEditWidget optMonthes
;
176 (new HBoxWidget
).enter{
177 with (new HotLabelWidget("&Monthes:", LabelWidget
.HAlign
.Right
)) { width
= width
+2; /*hsizeId = "editors";*/ }
179 optMonthes
= new LineEditWidget();
180 //optMonthes.flex = 1;
181 optMonthes
.width
= gxTextWidthUtf("96669");
182 conwriteln("ISMYSEL: ", optMonthes
.isMySelector(" Widget#. "));
183 conwriteln("ISMYSEL: ", optMonthes
.isMySelector(" HBoxWidget LineEditWidget#. "));
184 conwriteln("ISMYSEL: ", optMonthes
.isMySelector(" HBoxWidget> #. "));
185 conwriteln("ISMYSEL: ", optMonthes
.isMySelector(" SubWindow HBoxWidget LineEditWidget#. "));
186 //new SpringWidget(1);
189 CheckboxWidget optThreaded
= new CheckboxWidget("&Threaded");
190 optThreaded
.flex
= 1;
192 CheckboxWidget optAttaches
= new CheckboxWidget("&Attaches");
193 optAttaches
.flex
= 1;
196 (new HBoxWidget
).enter{
199 with (new ButtonWidget(" O&k ")) {
200 hsizeId
= "okcancel";
201 deftype
= Default
.Accept
;
202 onAction
= delegate (self
) {
203 if (onUpdated
!is null) onUpdated(tagname
);
208 with (new ButtonWidget(" Cancel ")) {
209 hsizeId
= "okcancel";
210 deftype
= Default
.Cancel
;
211 onAction
= delegate (self
) {
216 with (new ButtonWidget(" ... ")) {
217 hsizeId
= "okcancel";
219 onAction
= delegate (self
) {
220 (new SelectCompletionWindow("", buildAutoCompletion("/home/ketmar/"), aspath
:true)).onSelected
= (str) {
221 conwriteln("SELECTED: <", str.getData
, ">");
233 optPath
.text
= "booPath";
234 optMonthes
.str = "666";
236 optThreaded
.enabled
= false;
237 optAttaches
.enabled
= true;
239 optMonthes
.killTextOnChar
= true;
243 //add(); // for "focused"
245 forEachSelector("SubWindow > RootWidget CheckboxWidget", (EgraStyledClass w
) {
246 import iv
.vfs
.io
; writeln("LEW=", typeid(w
).name
, "; text=", (cast(CheckboxWidget
)w
).title
.getData
);
250 forEachSelector("SubWindow > RootWidget :focused", (EgraStyledClass w
) {
251 import iv
.vfs
.io
; writeln("FOCUSED=", typeid(w
).name
);
255 foreach (HotLabelWidget c
; querySelectorAll
!HotLabelWidget("SubWindow > RootWidget HotLabelWidget")) {
257 writeln("LBL: <", c
.text
.getData
, ">");
261 Widget qf
= querySelector(":focused");
262 if (qf
!is null) writeln("QFOCUSED=", typeid(qf
).name
); else writeln("FUCK!");
267 // ////////////////////////////////////////////////////////////////////////// //
268 void initConsole () {
269 // //////////////////////////////////////////////////////////////////// //
271 import core
.memory
: GC
;
272 conwriteln("starting GC collection...");
275 conwriteln("GC collection complete.");
276 })("gc_collect", "force GC collection cycle");
279 // //////////////////////////////////////////////////////////////////// //
281 auto qww
= new YesNoWindow("Quit?", "Do you really want to quit?", true);
282 qww
.onYes
= () { concmd("quit"); };
284 })("quit_prompt", "quit with prompt");
287 new TitlerWindow("name", "mail", "folder", "title");
288 })("window_titler", "titler window test");
291 new TagOptionsWindow("xtag");
292 })("window_tagoptions", "tag options window test");
296 // ////////////////////////////////////////////////////////////////////////// //
297 __gshared MainPaneWindow mainPane
;
300 final class MainPaneWindow
: SubWindow
{
301 ProgressBarWidget pbar
;
303 AGGTesselation deftess
;
305 int lastMX
= -10000, lastMY
= -10000;
308 super(null, GxPoint(0, 0), GxSize(screenWidth
, screenHeight
));
309 mType
= Type
.OnBottom
;
311 pbar
= new ProgressBarWidget(rootWidget
, "progress bar");
312 pbar
.setMinMax(0, 100);
313 pbar
.width
= clientWidth
-64;
315 pbar
.posy
= clientHeight
-pbar
.height
-8;
316 pbar
.posx
= (clientWidth
-pbar
.width
)/2;
318 deftess
= gxagg
.tesselator
;
323 // //////////////////////////////////////////////////////////////////// //
324 override void onPaint () {
327 enum guiGroupListWidth
= 128;
328 enum guiThreadListHeight
= 520;
330 gxFillRect(0, 0, guiGroupListWidth
, screenHeight
, getColor("grouplist-back"));
331 gxVLine(guiGroupListWidth
, 0, screenHeight
, getColor("grouplist-divline"));
333 gxFillRect(guiGroupListWidth
+1, 0, screenWidth
, guiThreadListHeight
, getColor("threadlist-back"));
334 gxHLine(guiGroupListWidth
+1, guiThreadListHeight
, screenWidth
, getColor("threadlist-divline"));
337 import core
.stdc
.math
: roundf
;
340 if (tessType
> AGGTesselation
.max
) tessType
= AGGTesselation
.max
;
341 gxagg
.tesselator
= cast(AGGTesselation
)tessType
;
343 gxagg
.tesselator
= deftess
;
348 //gxagg.width = 1.0f;
350 float baphx
= roundf((screenWidth
-gxagg
.BaphometDims
)*0.5f)+0.5f;
351 float baphy
= roundf((screenHeight
-gxagg
.BaphometDims
)*0.5f)+0.5f;
359 foreach (; 0..1000) {
361 immutable tstt
= clockMicro();
362 gxagg
.renderBaphomet(baphx
, baphy
);
363 estt
+= (clockMicro()-tstt
);
367 gxagg
.renderBaphomet(baphx
, baphy
);
369 immutable tstt
= clockMicro();
370 gxagg
.renderBaphomet(baphx
, baphy
);
371 estt
= clockMicro()-tstt
;
376 .moveTo(baphx
-1, baphy
-1)
377 .lineTo(baphx
+gxagg
.BaphometDims
, baphy
-1)
378 .lineTo(baphx
+gxagg
.BaphometDims
, baphy
+gxagg
.BaphometDims
)
379 .lineTo(baphx
-1, baphy
+gxagg
.BaphometDims
)
380 .lineTo(baphx
-1, baphy
-1);
383 gxagg
.roundedRect(baphx
-1, baphy
-1, gxagg
.BaphometDims
+1, gxagg
.BaphometDims
+1, 16.0f);
398 hit
= gxagg
.hitTest(lastMX
, lastMY
);
399 gxagg
.endFrame(gxrgba(255, 0, 0, (tessType
>= 0 ?
255 : 66)));
402 import std
.format
: format
;
403 string s
= "tess: %s level: %d; mcsecs: %s".format(gxagg
.tesselator
, gxagg
.bezierLimit
, estt
);
404 gxDrawTextUtf(200, 20, s
, GxColors
.k8orange
);
406 s
= "hit: %3s".format(hit
);
407 gxDrawTextUtf(200, 40, s
, GxColors
.k8orange
);
417 .rotate(deg2rad(35.0f))
422 .translate(0.5f, 0.5f)
425 gxagg
.withTransform(tmt
, {
426 gxagg
.moveTo(50, 50);
427 gxagg
.lineTo(60, 60);
428 gxagg
.moveTo(100, 100);
429 gxagg
.lineTo(140, 120);
431 gxagg
.moveTo(200, 200);
432 gxagg
.lineTo(200, 100);
433 gxagg
.lineTo(100, 100);
434 gxagg
.lineTo(100, 200);
435 gxagg
.lineTo(200, 200);
437 gxagg
.moveTo(100, 100);
438 gxagg
.lineTo(200, 100);
439 gxagg
.lineTo(200, 200);
440 gxagg
.lineTo(100, 200);
443 //gxagg.dumpVertices();
448 gxagg
.render(gxrgba(0, 127, 0, 127));
451 //gxagg.dumpVertices();
453 gxagg
.render(gxrgba(127, 0, 0, 255));
461 //gxagg.dashContour();
462 gxagg
.render(gxrgba(255, 255, 0, 255));
466 // not working properly yet
467 gxagg
.setupContour(6);
469 gxagg
.render(gxrgba(255, 255, 0, 255));
473 // not working properly yet
474 gxagg
.setupContour(6);
478 gxagg
.render(gxrgba(255, 255, 0, 255));
481 //gxagg.render(gxrgba(0, 127, 0, 127));
486 version(test_round_rect
) {
488 gxFillRoundedRect(lastMouseX
-16, lastMouseY
-16, 128, 96, rrad
, /*gxSolidWhite*/gxRGBA
!(0, 255, 0, 127));
489 //gxDrawRoundedRect(lastMouseX-16, lastMouseY-16, 128, 96, rrad, gxRGBA!(0, 255, 0, 127));
495 version(test_round_rect
) {
499 override bool onKeyBubble (KeyEvent event
) {
501 version(test_round_rect
) {
502 if (event
== "Plus") { ++rrad
; return true; }
503 if (event
== "Minus") { --rrad
; return true; }
505 if (event
== "C-Q") { concmd("quit_prompt"); return true; }
506 if (event
== "1") { concmd("window_titler"); return true; }
507 if (event
== "2") { concmd("window_tagoptions"); return true; }
508 if (event
== "Minus") { pbar
.current
= pbar
.current
-1; return true; }
509 if (event
== "Plus") { pbar
.current
= pbar
.current
+1; return true; }
511 if (event
== "Q") { if (gxagg
.bezierLimit
> 1) { --gxagg
.bezierLimit
; widgetChanged(); } return true; }
512 if (event
== "W") { if (gxagg
.bezierLimit
< 1000) { ++gxagg
.bezierLimit
; widgetChanged(); } return true; }
514 if (event
== "Z") { --tessType
; if (tessType
< -1) tessType
= -1; widgetChanged(); return true; }
515 if (event
== "X") { ++tessType
; widgetChanged(); return true; }
517 if (event
== "T") { timetest
= true; widgetChanged(); return true; }
518 //if (dbg_dump_keynames) conwriteln("key: ", event.toStr, ": ", event.modifierState&ModifierState.windows);
519 //foreach (const ref kv; mainAppKeyBindings.byKeyValue) if (event == kv.key) concmd(kv.value);
524 // returning `false` to avoid screen rebuilding by dispatcher
525 override bool onMouseBubble (MouseEvent event
) {
526 if (event
.type
== MouseEventType
.buttonPressed || event
.type
== MouseEventType
.buttonReleased
) {
527 if (lastMX
!= event
.x || lastMY
!= event
.y
) {
533 } else if (event
.modifierState
) {
534 // for OpenGL, this rebuilds the whole screen anyway
544 // ////////////////////////////////////////////////////////////////////////// //
545 void main (string
[] args
) {
546 defaultColorStyle
.parseStyle(TestStyle
);
547 //egraDefaultFontSize = 48;
549 glconAllowOpenGLRender
= false;
551 sdpyWindowClass
= "EGUITest";
552 //glconShowKey = "M-Grave";
557 conProcessArgs
!true(args
);
559 egraCreateSystemWindow("EGRA Test", allowResize
:false);
561 vbwin
.addEventListener((QuitEvent evt
) {
562 if (vbwin
.closed
) return;
563 if (isQuitRequested
) { vbwin
.close(); return; }
567 static if (is(typeof(&vbwin
.closeQuery
))) {
568 vbwin
.closeQuery
= delegate () { concmd("quit"); egraPostDoConCommands(); };
571 mainPane
= new MainPaneWindow();
572 //egraSkipScreenClear = true; // main pane is fullscreen
577 vbwin
.eventLoop(1000*10,
579 egraProcessConsole();
581 delegate (KeyEvent event
) {
582 if (egraOnKey(event
)) return;
584 delegate (MouseEvent event
) {
585 if (egraOnMouse(event
)) return;
587 delegate (dchar ch
) {
588 if (egraOnChar(ch
)) return;
593 conProcessQueue(int.max
/4);