Mercurial > projects > mde
comparison mde/gui/widget/Floating.d @ 158:f132e599043f
Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Enabling window raise on hover is simple now (make an option?), clicking on a sub-widget won't raise (bug).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 24 Apr 2009 17:35:53 +0100 |
parents | a86f8445ccc8 |
children | b06b04c75e86 |
comparison
equal
deleted
inserted
replaced
157:a86f8445ccc8 | 158:f132e599043f |
---|---|
36 * Data: Each string item is interpreted as a sub-widget widgetID to add as a floating window. | 36 * Data: Each string item is interpreted as a sub-widget widgetID to add as a floating window. |
37 * Ints consist of widget type followed by a border type (flags from IRenderer.Border.BTYPE) for | 37 * Ints consist of widget type followed by a border type (flags from IRenderer.Border.BTYPE) for |
38 * each sub-widget. */ | 38 * each sub-widget. */ |
39 class FloatingAreaWidget : AParentWidget | 39 class FloatingAreaWidget : AParentWidget |
40 { | 40 { |
41 static this () { | |
42 raiseOnHover = ; | |
43 } | |
44 | |
41 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { | 45 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { |
42 if (data.ints.length != 1 + data.strings.length) | 46 if (data.ints.length != 1 + data.strings.length) |
43 throw new WidgetDataException (this); | 47 throw new WidgetDataException (this); |
44 super (mgr, parent, id); | 48 super (mgr, parent, id); |
45 | 49 |
166 } | 170 } |
167 | 171 |
168 override IChildWidget getWidget (wdim cx, wdim cy) { | 172 override IChildWidget getWidget (wdim cx, wdim cy) { |
169 debug scope (failure) | 173 debug scope (failure) |
170 logger.warn ("getWidget: failure; values: click; pos; width: {},{}; {},{}; {},{}", cx, cy, x, y, w, h); | 174 logger.warn ("getWidget: failure; values: click; pos; width: {},{}; {},{}; {},{}", cx, cy, x, y, w, h); |
171 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)"); | 175 |
172 | 176 size_t event = getFloatingWidget (cx,cy, raiseOnHover); |
173 foreach_reverse (j,i; sWOrder) with (sWData[i]) { | 177 if (event > sWData.length) |
178 return this; // no match | |
179 | |
180 with (sWData[event]) { | |
174 wdim lx = cx - (this.x + x); | 181 wdim lx = cx - (this.x + x); |
175 wdim ly = cy - (this.y + y); | 182 wdim ly = cy - (this.y + y); |
176 if (lx >= 0 && lx < w && | 183 if (lx >= border.x1 && lx < w-border.x2 && |
177 ly >= 0 && ly < h) | 184 ly >= border.y1 && ly < h-border.y2) |
178 { | 185 return subWidgets[event].getWidget (cx,cy); |
179 /+ code to raise widget | 186 return this; |
180 sWOrder[j..$-1] = sWOrder[j+1..$].dup; | 187 } |
181 sWOrder[$-1] = i; | |
182 mgr.requestRedraw; +/ | |
183 if (lx >= border.x1 && lx < w-border.x2 && | |
184 ly >= border.y1 && ly < h-border.y2) | |
185 return subWidgets[i].getWidget (cx,cy); | |
186 event = i; | |
187 return this; | |
188 } | |
189 } | |
190 event = size_t.max; | |
191 return this; // no match | |
192 } | 188 } |
193 | 189 |
194 override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { | 190 override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { |
195 if (event > subWidgets.length) return 0; | 191 size_t event = getFloatingWidget (cx,cy, true); |
192 if (event > subWidgets.length) return 0; | |
196 if (b == 1 && state == true) { | 193 if (b == 1 && state == true) { |
197 active = event; | 194 active = event; |
198 with (sWData[active]) { | 195 with (sWData[active]) { |
199 resizeType = border.getResize (cx - this.x - x, cy - this.y - y, w,h); | 196 resizeType = border.getResize (cx - this.x - x, cy - this.y - y, w,h); |
200 alias border.RESIZE RESIZE; | 197 alias border.RESIZE RESIZE; |
224 } | 221 } |
225 return 0; | 222 return 0; |
226 } | 223 } |
227 | 224 |
228 protected: | 225 protected: |
226 /** Return the index of the floating object under (cx,cy). If no widget is, | |
227 * return size_t.max. | |
228 * | |
229 * Params: | |
230 * raiseWidget = if true, the widget returned is raised to be the top- | |
231 * most floating widget. */ | |
232 size_t getFloatingWidget (wdim cx, wdim cy, bool raiseWidget = false) { | |
233 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)"); | |
234 | |
235 foreach_reverse (j,i; sWOrder) with (sWData[i]) { | |
236 wdim lx = cx - (this.x + x); | |
237 wdim ly = cy - (this.y + y); | |
238 if (lx >= 0 && lx < w && ly >= 0 && ly < h) { | |
239 if (raiseWidget) { | |
240 sWOrder[j..$-1] = sWOrder[j+1..$].dup; | |
241 sWOrder[$-1] = i; | |
242 mgr.requestRedraw; | |
243 } | |
244 return i; | |
245 } | |
246 } | |
247 return size_t.max; // no match | |
248 } | |
249 | |
229 void moveCallback (wdabs cx, wdabs cy) { | 250 void moveCallback (wdabs cx, wdabs cy) { |
230 with (sWData[active]) { | 251 with (sWData[active]) { |
231 x = cx-xDrag; | 252 x = cx-xDrag; |
232 y = cy-yDrag; | 253 y = cy-yDrag; |
233 | 254 |
307 size_t[] sWOrder; // indexes for draw order (top widget at end of list) | 328 size_t[] sWOrder; // indexes for draw order (top widget at end of list) |
308 | 329 |
309 // Click/drag information: | 330 // Click/drag information: |
310 alias IRenderer.Border.BTYPE BTYPE; | 331 alias IRenderer.Border.BTYPE BTYPE; |
311 alias IRenderer.Border.RESIZE RESIZE; | 332 alias IRenderer.Border.RESIZE RESIZE; |
312 size_t event = size_t.max; // Border with last click/release: size_t.max: main area (no subwidget), i: subwidget[i] | 333 size_t active = size_t.max; // refers to widget being moved/resized |
313 size_t active = size_t.max; // Like event, but refers to widget being moved/resized | |
314 wdim xDrag, yDrag; // where a drag starts relative to x and y | 334 wdim xDrag, yDrag; // where a drag starts relative to x and y |
315 RESIZE resizeType; // Type of current resize | 335 RESIZE resizeType; // Type of current resize |
336 | |
337 static BoolContent raiseOnHover; | |
316 } | 338 } |