comparison mde/gui/widget/miscWidgets.d @ 95:2a364c7d82c9

Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes. Fixed a minor bug where layouts with the same id but without shared alignments would be messed up. Tracked down the "nothing trawn until a resize" bug (see jobs.txt). If widgets throw during creation they're now replaced by debug widgets. Function pointers are converted to delegates using a safer method.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 06 Nov 2008 11:07:18 +0000
parents 4d5d53e4f881
children b16a534f5302
comparison
equal deleted inserted replaced
94:9520cc0448e5 95:2a364c7d82c9
74 mgr.renderer.drawBlank (x,y, w,h); 74 mgr.renderer.drawBlank (x,y, w,h);
75 } 75 }
76 } 76 }
77 77
78 /// First interactible widget 78 /// First interactible widget
79 class ButtonWidget : FixedWidget 79 class ButtonWidget : AButtonWidget
80 { 80 {
81 bool pushed = false; // true if button is pushed in (visually)
82 // pushed is not the same as the button being clicked but not yet released.
83 // it is whether the mouse is over the button after being clicked.
84
85 this (IWidgetManager mgr, widgetID id, WidgetData data) { 81 this (IWidgetManager mgr, widgetID id, WidgetData data) {
86 WDCheck (data, 3); 82 WDCheck (data, 3);
83 w = mw = cast(wdim) data.ints[1];
84 h = mh = cast(wdim) data.ints[2];
87 super (mgr, id, data); 85 super (mgr, id, data);
88 } 86 }
89 87
90 void draw () { 88 void activated () {
91 mgr.renderer.drawButton (x,y, w,h, pushed); 89 Stdout ("Button clicked!").newline;
92 }
93
94 void clickEvent (wdabs, wdabs, ubyte b, bool state) {
95 if (b == 1 && state == true) {
96 pushed = true;
97 mgr.requestRedraw;
98 mgr.addClickCallback (&clickWhileHeld);
99 mgr.addMotionCallback (&motionWhileHeld);
100 }
101 }
102 // Called when a mouse motion/click event occurs while (held == true)
103 bool clickWhileHeld (wdabs cx, wdabs cy, ubyte b, bool state) {
104 if (b == 1 && state == false) {
105 if (cx >= x && cx < x+w && cy >= y && cy < y+h) // button event
106 Stdout ("Button clicked!").newline;
107
108 pushed = false;
109 mgr.requestRedraw;
110 mgr.removeCallbacks (cast(void*) this);
111
112 return true;
113 }
114 return false;
115 }
116 void motionWhileHeld (wdabs cx, wdabs cy) {
117 bool oldPushed = pushed;
118 if (cx >= x && cx < x+w && cy >= y && cy < y+h) pushed = true;
119 else pushed = false;
120 if (oldPushed != pushed)
121 mgr.requestRedraw;
122 } 90 }
123 } 91 }