Mercurial > projects > mde
comparison mde/gui/widget/Window.d @ 45:0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Moved the implementable widgets from mde.gui.widget.Widget to miscWidgets, leaving base widgets in Widget.
Rewrote some of GridLayoutWidget's implementation. Made many operations general to work for either columns or rows. Some optimisations were intended but ended up being removed due to problems.
Allowed layout's to resize from either direction (only with window resizes).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 22 May 2008 11:34:09 +0100 |
parents | b3a6ca4516b4 |
children | 03fa79a48c48 |
comparison
equal
deleted
inserted
replaced
44:07bd1a09e161 | 45:0fd51d2c6c8a |
---|---|
217 void getCurrentSize (out int cw, out int ch) { | 217 void getCurrentSize (out int cw, out int ch) { |
218 cw = w; | 218 cw = w; |
219 ch = h; | 219 ch = h; |
220 } | 220 } |
221 | 221 |
222 void setSize (int nw, int nh) { | 222 void setSize (int nw, int nh, bool wB, bool hB) { |
223 getMinimalSize (w,h); | 223 getMinimalSize (w,h); |
224 if (nw > w) w = nw; // expand if new size is larger, but don't go smaller | 224 if (nw > w) w = nw; // expand if new size is larger, but don't go smaller |
225 if (nh > h) h = nh; | 225 if (nh > h) h = nh; |
226 | 226 |
227 xw = x+w; | 227 xw = x+w; |
228 yh = y+h; | 228 yh = y+h; |
229 | 229 |
230 widget.setSize (w - border.l - border.r, h - border.t - border.b); | 230 widget.setSize (w - border.l - border.r, h - border.t - border.b, wB, hB); |
231 | 231 |
232 gui_.requestRedraw (); // obviously necessary whenever the window's size is changed | 232 gui_.requestRedraw (); // obviously necessary whenever the window's size is changed |
233 } | 233 } |
234 | 234 |
235 void setPosition (int nx, int ny) { | 235 void setPosition (int nx, int ny) { |
301 //BEGIN Window moving and resizing | 301 //BEGIN Window moving and resizing |
302 void moveCallback (ushort cx, ushort cy) { | 302 void moveCallback (ushort cx, ushort cy) { |
303 setPosition (cx-xDrag, cy-yDrag); | 303 setPosition (cx-xDrag, cy-yDrag); |
304 } | 304 } |
305 void resizeCallback (ushort cx, ushort cy) { | 305 void resizeCallback (ushort cx, ushort cy) { |
306 debug scope(failure) | |
307 logger.trace ("resizeCallback: failure"); | |
308 | |
309 // This function is only called if some resize is going to happen. | |
310 // To improve efficiency, store parameters to resize to. | |
311 int xSize = w, ySize = h; // new size | |
312 int xDiff, yDiff; // difference to new position | |
313 bool xHigh, yHigh; // resize from positive side | |
314 | |
306 if (resizeType & RESIZE_TYPE.L) { | 315 if (resizeType & RESIZE_TYPE.L) { |
307 int mw, nw; | 316 getMinimalSize (xDiff, xSize); // (only want xDiff, temporarily used as mw) |
308 getMinimalSize (mw, nw); // (only want mw) | 317 xSize = xDrag - cx; |
309 nw = xDrag - cx; | 318 if (xSize < xDiff) xSize = xDiff; // clamp |
310 if (nw < mw) nw = mw; // clamp | 319 xDiff = w - xSize; // now used as amount to move |
311 mw = x + w - nw; // reuse | |
312 setSize (nw, h); | |
313 setPosition (mw, y); | |
314 } | 320 } |
315 else if (resizeType & RESIZE_TYPE.R) { | 321 else if (resizeType & RESIZE_TYPE.R) { |
316 setSize (xDrag + cx, h); | 322 xSize = xDrag + cx; |
317 setPosition (x, y); // required to call after setSize. | 323 xHigh = true; |
318 } | 324 } |
319 if (resizeType & RESIZE_TYPE.T) { | 325 if (resizeType & RESIZE_TYPE.T) { |
320 int mh, nh; | 326 getMinimalSize (ySize, yDiff); |
321 getMinimalSize (nh, mh); | 327 ySize = yDrag - cy; |
322 nh = yDrag - cy; | 328 if (ySize < yDiff) ySize = yDiff; |
323 if (nh < mh) nh = mh; | 329 yDiff = h - ySize; |
324 mh = y + h - nh; | |
325 setSize (w, nh); | |
326 setPosition (x, mh); | |
327 } | 330 } |
328 else if (resizeType & RESIZE_TYPE.B) { | 331 else if (resizeType & RESIZE_TYPE.B) { |
329 setSize (w, yDrag + cy); | 332 ySize = yDrag + cy; |
330 setPosition (x, y); | 333 yHigh = true; |
331 } | 334 } |
335 | |
336 setSize (xSize, ySize, xHigh, yHigh); | |
337 if (xDiff != 0 || yDiff != 0) | |
338 setPosition (x + xDiff, y + yDiff); | |
332 } | 339 } |
333 bool endCallback (ushort cx, ushort cy, ubyte b, bool state) { | 340 bool endCallback (ushort cx, ushort cy, ubyte b, bool state) { |
334 if (b == 1 && state == false) { | 341 if (b == 1 && state == false) { |
335 // The mouse shouldn't have moved since the motion callback | 342 // The mouse shouldn't have moved since the motion callback |
336 // was last called, so there's nothing else to do now. | 343 // was last called, so there's nothing else to do now. |