Changeset 58:d43523ed4b62
- Timestamp:
- 06/14/08 12:15:06
(7 months ago)
- Author:
- Diggory Hardy <diggory.hardy@gmail.com>
- branch:
- default
- Message:
Included a wdim typedef for all variables to do with window position or size instead of just using int.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r57 |
r58 |
|
| 53 | 53 | |
|---|
| 54 | 54 | Done (for mercurial log message): |
|---|
| 55 | | Coloured and alpha-blended text is now supported. |
|---|
| 56 | | TextWidgets get text colour from argument. |
|---|
| r47 |
r58 |
|
| 148 | 148 | debug scope (failure) |
|---|
| 149 | 149 | logger.warn ("clickEvent: failed!"); |
|---|
| | 150 | |
|---|
| 150 | 151 | // NOTE: buttons receive the up-event even when drag-callbacks are in place. |
|---|
| 151 | 152 | foreach (dg; clickCallbacks) |
|---|
| 152 | | if (dg (cx, cy, b, state)) return; // See IGui.addClickCallback's documentation |
|---|
| | 153 | if (dg (cast(wdabs)cx, cast(wdabs)cy, b, state)) return; // See IGui.addClickCallback's documentation |
|---|
| 153 | 154 | |
|---|
| 154 | 155 | foreach (i,w; windows) { |
|---|
| 155 | | IWidget widg = w.getWidget (cx,cy); |
|---|
| | 156 | IWidget widg = w.getWidget (cast(wdabs)cx,cast(wdabs)cy); |
|---|
| 156 | 157 | if (widg !is null) { |
|---|
| 157 | 158 | // Bring to front |
|---|
| 158 | 159 | windows = w ~ windows[0..i] ~ windows[i+1..$]; |
|---|
| 159 | 160 | |
|---|
| 160 | | widg.clickEvent (cx,cy,b,state); |
|---|
| | 161 | widg.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state); |
|---|
| 161 | 162 | return; // only pass to first window |
|---|
| 162 | 163 | } |
|---|
| … | … | |
| 171 | 172 | logger.warn ("motionEvent: failed!"); |
|---|
| 172 | 173 | foreach (dg; motionCallbacks) |
|---|
| 173 | | dg (cx, cy); |
|---|
| | 174 | dg (cast(wdabs)cx, cast(wdabs)cy); |
|---|
| 174 | 175 | } |
|---|
| 175 | 176 | |
|---|
| … | … | |
| 185 | 186 | } |
|---|
| 186 | 187 | |
|---|
| 187 | | void addClickCallback (bool delegate(ushort, ushort, ubyte, bool) dg) { |
|---|
| | 188 | void addClickCallback (bool delegate(wdabs, wdabs, ubyte, bool) dg) { |
|---|
| 188 | 189 | clickCallbacks[dg.ptr] = dg; |
|---|
| 189 | 190 | } |
|---|
| 190 | | void addMotionCallback (void delegate(ushort, ushort) dg) { |
|---|
| | 191 | void addMotionCallback (void delegate(wdabs, wdabs) dg) { |
|---|
| 191 | 192 | motionCallbacks[dg.ptr] = dg; |
|---|
| 192 | 193 | } |
|---|
| … | … | |
| 203 | 204 | |
|---|
| 204 | 205 | // callbacks indexed by their frame pointers: |
|---|
| 205 | | bool delegate(ushort cx, ushort cy, ubyte b, bool state) [void*] clickCallbacks; |
|---|
| 206 | | void delegate(ushort cx, ushort cy) [void*] motionCallbacks; |
|---|
| | 206 | bool delegate(wdabs cx, wdabs cy, ubyte b, bool state) [void*] clickCallbacks; |
|---|
| | 207 | void delegate(wdabs cx, wdabs cy) [void*] motionCallbacks; |
|---|
| 207 | 208 | } |
|---|
| r41 |
r58 |
|
| 14 | 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
|---|
| 15 | 15 | |
|---|
| | 16 | /** Contains the IGui interface and some basic types used by the gui package. */ |
|---|
| 16 | 17 | module mde.gui.IGui; |
|---|
| | 18 | |
|---|
| | 19 | /** Window coordinate and dimension/size type (int). |
|---|
| | 20 | * |
|---|
| | 21 | * Used to disambiguate between general integers and coordinates; all widget positions/sizes should |
|---|
| | 22 | * use this type (or one of the aliases below). */ |
|---|
| | 23 | typedef int wdim; |
|---|
| | 24 | |
|---|
| | 25 | /** Aliases of wdim providing extra information about what their contents hold: absolute position, |
|---|
| | 26 | * position relative to the containing widget (wdrel should not be used if relative to anything |
|---|
| | 27 | * else), or size. Their use instead of wdim is optional (and in some cases wdim values aren't of |
|---|
| | 28 | * any of these types). Also don't use these aliases for variables which may also be used to other |
|---|
| | 29 | * effects, e.g. if they can have special values with special meanings. */ |
|---|
| | 30 | alias wdim wdabs; |
|---|
| | 31 | alias wdim wdrel; /// ditto |
|---|
| | 32 | alias wdim wdsize; /// ditto |
|---|
| | 33 | |
|---|
| | 34 | /// A pair of wdim variables, and strictly no other data (methods may be added if deemed useful). |
|---|
| | 35 | struct wdimPair { |
|---|
| | 36 | wdim x, y; /// data |
|---|
| | 37 | } |
|---|
| 17 | 38 | |
|---|
| 18 | 39 | /** The Gui interface. |
|---|
| … | … | |
| 37 | 58 | * Note that this is not a mechanism to prevent unwanted event handling, and in the future may |
|---|
| 38 | 59 | * be removed (so event handling cannot be cut short). */ |
|---|
| 39 | | void addClickCallback (bool delegate (ushort cx, ushort cy, ubyte b, bool state) dg); |
|---|
| | 60 | void addClickCallback (bool delegate (wdabs cx, wdabs cy, ubyte b, bool state) dg); |
|---|
| 40 | 61 | /** Add a mouse motion callback: delegate will be called for all motion events recieved. */ |
|---|
| 41 | | void addMotionCallback (void delegate (ushort cx, ushort cy) dg); |
|---|
| | 62 | void addMotionCallback (void delegate (wdabs cx, wdabs cy) dg); |
|---|
| 42 | 63 | /** Remove all event callbacks with _frame pointer frame. */ |
|---|
| 43 | 64 | void removeCallbacks (void* frame); |
|---|
| r43 |
r58 |
|
| 17 | 17 | module mde.gui.renderer.IRenderer; |
|---|
| 18 | 18 | |
|---|
| | 19 | public import mde.gui.IGui; // wdim type is used by just about everything including this |
|---|
| | 20 | |
|---|
| 19 | 21 | /** Interface for renderers. |
|---|
| 20 | 22 | * |
|---|
| … | … | |
| 30 | 32 | struct BorderDimensions { |
|---|
| 31 | 33 | /// The dimensions: left, top, right, bottom |
|---|
| 32 | | ubyte l, t, r, b; |
|---|
| | 34 | wdim l, t, r, b; |
|---|
| 33 | 35 | |
|---|
| 34 | 36 | void opAddAssign (BorderDimensions d) { |
|---|
| … | … | |
| 62 | 64 | * RESIZE_TYPE = NONE for a move, an or'd combination of L/R/T/B for resizing. |
|---|
| 63 | 65 | */ |
|---|
| 64 | | RESIZE_TYPE getResizeType (int cx, int cy, int w, int h); |
|---|
| | 66 | RESIZE_TYPE getResizeType (wdim cx, wdim cy, wdim w, wdim h); |
|---|
| 65 | 67 | |
|---|
| 66 | 68 | /** Return the renderer's between-widget spacing (for layout widgets). */ |
|---|
| 67 | | int layoutSpacing (); |
|---|
| | 69 | wdim layoutSpacing (); |
|---|
| 68 | 70 | //END Get dimensions |
|---|
| 69 | 71 | |
|---|
| 70 | 72 | //BEGIN draw routines |
|---|
| 71 | 73 | /** Draw a window border plus background. */ |
|---|
| 72 | | void drawWindow (int x, int y, int w, int h); |
|---|
| | 74 | void drawWindow (wdim x, wdim y, wdim w, wdim h); |
|---|
| 73 | 75 | |
|---|
| 74 | 76 | /** Draws a widget background. Usually doesn't do anything since backgrounds are transparent. */ |
|---|
| 75 | | void drawWidgetBack (int x, int y, int w, int h); |
|---|
| | 77 | void drawWidgetBack (wdim x, wdim y, wdim w, wdim h); |
|---|
| 76 | 78 | |
|---|
| 77 | 79 | /** Draws a blank widget (temporary) */ |
|---|
| 78 | | void drawBlank (int x, int y, int w, int h); |
|---|
| | 80 | void drawBlank (wdim x, wdim y, wdim w, wdim h); |
|---|
| 79 | 81 | |
|---|
| 80 | 82 | /** Draws a button frame, in if pushed == true. */ |
|---|
| 81 | | void drawButton (int x, int y, int w, int h, bool pushed); |
|---|
| | 83 | void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed); |
|---|
| 82 | 84 | //END draw routines |
|---|
| 83 | 85 | } |
|---|
| r43 |
r58 |
|
| 44 | 44 | l = r = 0; |
|---|
| 45 | 45 | if (hSizable) { |
|---|
| 46 | | t = 2; |
|---|
| 47 | | b = 6; |
|---|
| | 46 | t = b = 6; |
|---|
| 48 | 47 | } else |
|---|
| 49 | 48 | t = b = 0; |
|---|
| … | … | |
| 53 | 52 | } |
|---|
| 54 | 53 | |
|---|
| 55 | | RESIZE_TYPE getResizeType (int cx, int cy, int w, int h) { |
|---|
| | 54 | RESIZE_TYPE getResizeType (wdim cx, wdim cy, wdim w, wdim h) { |
|---|
| 56 | 55 | RESIZE_TYPE resizeType = RESIZE_TYPE.NONE; |
|---|
| 57 | 56 | if (cx < resize.l || cx >= w - resize.r || |
|---|
| … | … | |
| 76 | 75 | } |
|---|
| 77 | 76 | |
|---|
| 78 | | int layoutSpacing () { |
|---|
| | 77 | wdim layoutSpacing () { |
|---|
| 79 | 78 | return 4; |
|---|
| 80 | 79 | } |
|---|
| 81 | 80 | |
|---|
| 82 | 81 | |
|---|
| 83 | | void drawWindow (int x, int y, int w, int h) { |
|---|
| | 82 | void drawWindow (wdim x, wdim y, wdim w, wdim h) { |
|---|
| 84 | 83 | gl.setColor (0f, 0f, .7f); |
|---|
| 85 | 84 | gl.drawBox (x,y, w,h); |
|---|
| … | … | |
| 92 | 91 | } |
|---|
| 93 | 92 | |
|---|
| 94 | | void drawWidgetBack (int x, int y, int w, int h) {} |
|---|
| | 93 | void drawWidgetBack (wdim x, wdim y, wdim w, wdim h) {} |
|---|
| 95 | 94 | |
|---|
| 96 | | void drawBlank (int x, int y, int w, int h) { |
|---|
| | 95 | void drawBlank (wdim x, wdim y, wdim w, wdim h) { |
|---|
| 97 | 96 | gl.setColor (.4f, .4f, .4f); |
|---|
| 98 | 97 | gl.drawBox (x,y, w,h); |
|---|
| 99 | 98 | } |
|---|
| 100 | 99 | |
|---|
| 101 | | void drawButton (int x, int y, int w, int h, bool pushed) { |
|---|
| | 100 | void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed) { |
|---|
| 102 | 101 | if (pushed) |
|---|
| 103 | 102 | gl.setColor (1f, 0f, 1f); |
|---|
| r48 |
r58 |
|
| 117 | 117 | /** Calculate the minimal size the widget could be shrunk to (or its fixed size), taking into |
|---|
| 118 | 118 | * account child-widgets or other contents. */ |
|---|
| 119 | | void getMinimalSize (out int w, out int h); |
|---|
| | 119 | void getMinimalSize (out wdim w, out wdim h); |
|---|
| 120 | 120 | |
|---|
| 121 | 121 | /** Get the current size of the widget. */ |
|---|
| 122 | | void getCurrentSize (out int w, out int h); |
|---|
| | 122 | void getCurrentSize (out wdim w, out wdim h); |
|---|
| 123 | 123 | |
|---|
| 124 | 124 | /** Used to adjust the size. |
|---|
| … | … | |
| 140 | 140 | * If the actual size is needed, call getCurrentSize afterwards. setPosition must be called |
|---|
| 141 | 141 | * afterwards if the widget might be a layout widget. */ |
|---|
| 142 | | void setWidth (int nw, int dir); |
|---|
| 143 | | void setHeight (int nh, int dir); /// ditto |
|---|
| | 142 | void setWidth (wdim nw, int dir); |
|---|
| | 143 | void setHeight (wdim nh, int dir); /// ditto |
|---|
| 144 | 144 | |
|---|
| 145 | 145 | /** Set the current position (i.e. called on init and move). */ |
|---|
| 146 | | void setPosition (int x, int y); |
|---|
| | 146 | void setPosition (wdim x, wdim y); |
|---|
| 147 | 147 | //END Size and position |
|---|
| 148 | 148 | |
|---|
| … | … | |
| 157 | 157 | * |
|---|
| 158 | 158 | * Note: use global coordinates (x,y) not coordinates relative to the widget. */ |
|---|
| 159 | | IWidget getWidget (int x, int y); |
|---|
| | 159 | IWidget getWidget (wdim x, wdim y); |
|---|
| 160 | 160 | |
|---|
| 161 | 161 | /** Receive a mouse click event. |
|---|
| … | … | |
| 165 | 165 | * |
|---|
| 166 | 166 | * Widget may assume coordinates are on the widget (caller must check). */ |
|---|
| 167 | | void clickEvent (ushort cx, ushort cy, ubyte b, bool state); |
|---|
| | 167 | void clickEvent (wdabs cx, wdabs cy, ubyte b, bool state); |
|---|
| 168 | 168 | //END Events |
|---|
| 169 | 169 | |
|---|
| r46 |
r58 |
|
| 62 | 62 | |
|---|
| 63 | 63 | /* Return minimal/fixed size. */ |
|---|
| 64 | | void getMinimalSize (out int a, out int b) { |
|---|
| | 64 | void getMinimalSize (out wdim a, out wdim b) { |
|---|
| 65 | 65 | a = mw; |
|---|
| 66 | 66 | b = mh; |
|---|
| 67 | 67 | } |
|---|
| 68 | 68 | |
|---|
| 69 | | void getCurrentSize (out int cw, out int ch) { |
|---|
| | 69 | void getCurrentSize (out wdim cw, out wdim ch) { |
|---|
| 70 | 70 | cw = w; |
|---|
| 71 | 71 | ch = h; |
|---|
| … | … | |
| 74 | 74 | /* Set size: minimal size is (mw,mh). Note that both resizable and fixed widgets should allow |
|---|
| 75 | 75 | * enlarging, so in both cases this is a correct implementation. */ |
|---|
| 76 | | void setWidth (int nw, int) { |
|---|
| | 76 | void setWidth (wdim nw, int) { |
|---|
| 77 | 77 | w = (nw >= mw ? nw : mw); |
|---|
| 78 | 78 | } |
|---|
| 79 | | void setHeight (int nh, int) { |
|---|
| | 79 | void setHeight (wdim nh, int) { |
|---|
| 80 | 80 | h = (nh >= mh ? nh : mh); |
|---|
| 81 | 81 | } |
|---|
| 82 | 82 | |
|---|
| 83 | | void setPosition (int nx, int ny) { |
|---|
| | 83 | void setPosition (wdim nx, wdim ny) { |
|---|
| 84 | 84 | x = nx; |
|---|
| 85 | 85 | y = ny; |
|---|
| … | … | |
| 90 | 90 | /* This method is only called when the location is over this widget; hence for all widgets |
|---|
| 91 | 91 | * without children this method is valid. */ |
|---|
| 92 | | IWidget getWidget (int,int) { |
|---|
| | 92 | IWidget getWidget (wdim,wdim) { |
|---|
| 93 | 93 | return this; |
|---|
| 94 | 94 | } |
|---|
| 95 | 95 | |
|---|
| 96 | 96 | /* Dummy event method (suitable for all widgets which don't respond to events). */ |
|---|
| 97 | | void clickEvent (ushort cx, ushort cy, ubyte b, bool state) {} |
|---|
| | 97 | void clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) {} |
|---|
| 98 | 98 | //END Events |
|---|
| 99 | 99 | |
|---|
| … | … | |
| 106 | 106 | final int widgetType; // the type (stored for saving) |
|---|
| 107 | 107 | IWindow window; // the enclosing window |
|---|
| 108 | | int x, y; // position |
|---|
| 109 | | int w, h; // size |
|---|
| 110 | | int mw = 0, mh = 0; // minimal or fixed size, depending on whether the widget is |
|---|
| | 108 | wdim x, y; // position |
|---|
| | 109 | wdim w, h; // size |
|---|
| | 110 | wdim mw = 0, mh = 0; // minimal or fixed size, depending on whether the widget is |
|---|
| 111 | 111 | // resizible; both types of widgets should actually be expandable. |
|---|
| 112 | 112 | } |
|---|
| … | … | |
| 116 | 116 | // Check data.length is at least 3 before calling! |
|---|
| 117 | 117 | this (IWindow wind, int[] data) { |
|---|
| 118 | | mw = data[1]; |
|---|
| 119 | | mh = data[2]; |
|---|
| | 118 | mw = cast(wdim) data[1]; |
|---|
| | 119 | mh = cast(wdim) data[2]; |
|---|
| 120 | 120 | super (wind, data); |
|---|
| 121 | 121 | w = mw; |
|---|
| r46 |
r58 |
|
| 76 | 76 | |
|---|
| 77 | 77 | // Note: this should return an empty array, but we shouldn't make a fuss if it's not empty: |
|---|
| 78 | | widget.adjust (mutableData); // adjust/set size, etc., depends on rend |
|---|
| | 78 | if ((widget.adjust (mutableData)).length != 0) // adjust/set size, etc., depends on rend |
|---|
| | 79 | logger.warn ("Local widget position data is invalid!"); |
|---|
| 79 | 80 | mutableData = null; // no longer needed |
|---|
| 80 | 81 | |
|---|
| … | … | |
| 108 | 109 | } else if (tp == INT) { |
|---|
| 109 | 110 | if (id == X && x == -1) { |
|---|
| 110 | | x = parseTo!(int) (dt); |
|---|
| | 111 | x = cast(wdim) parseTo!(int) (dt); |
|---|
| 111 | 112 | } else if (id == Y && y == -1) { |
|---|
| 112 | | y = parseTo!(int) (dt); |
|---|
| | 113 | y = cast(wdim) parseTo!(int) (dt); |
|---|
| 113 | 114 | } |
|---|
| 114 | 115 | } |
|---|
| … | … | |
| 211 | 212 | } |
|---|
| 212 | 213 | |
|---|
| 213 | | void getMinimalSize (out int wM, out int hM) { |
|---|
| | 214 | void getMinimalSize (out wdim wM, out wdim hM) { |
|---|
| 214 | 215 | // mw/mh are calculated by finalise(); |
|---|
| 215 | 216 | wM = mw; |
|---|
| 216 | 217 | hM = mh; |
|---|
| 217 | 218 | } |
|---|
| 218 | | void getCurrentSize (out int cw, out int ch) { |
|---|
| | 219 | void getCurrentSize (out wdim cw, out wdim ch) { |
|---|
| 219 | 220 | cw = w; |
|---|
| 220 | 221 | ch = h; |
|---|
| 221 | 222 | } |
|---|
| 222 | 223 | |
|---|
| 223 | | void setWidth (int nw, int dir) { |
|---|
| | 224 | void setWidth (wdim nw, int dir) { |
|---|
| 224 | 225 | if (nw < mw) w = mw; // clamp |
|---|
| 225 | 226 | else w = nw; |
|---|
| … | … | |
| 227 | 228 | widget.setWidth (w - border.l - border.r, dir); |
|---|
| 228 | 229 | } |
|---|
| 229 | | void setHeight (int nh, int dir) { |
|---|
| | 230 | void setHeight (wdim nh, int dir) { |
|---|
| 230 | 231 | if (nh < mh) h = mh; // clamp |
|---|
| 231 | 232 | else h = nh; |
|---|
| … | … | |
| 234 | 235 | } |
|---|
| 235 | 236 | |
|---|
| 236 | | void setPosition (int nx, int ny) { |
|---|
| | 237 | void setPosition (wdim nx, wdim ny) { |
|---|
| 237 | 238 | x = nx; |
|---|
| 238 | 239 | y = ny; |
|---|
| … | … | |
| 249 | 250 | } |
|---|
| 250 | 251 | |
|---|
| 251 | | IWidget getWidget (int cx, int cy) { |
|---|
| | 252 | IWidget getWidget (wdim cx, wdim cy) { |
|---|
| 252 | 253 | if (cx < x || cx >= xw || cy < y || cy >= yh) // not over window |
|---|
| 253 | 254 | return null; |
|---|
| … | … | |
| 258 | 259 | return this; |
|---|
| 259 | 260 | } |
|---|
| 260 | | void clickEvent (ushort cx, ushort cy, ubyte b, bool state) { |
|---|
| | 261 | void clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { |
|---|
| 261 | 262 | if (b == 1 && state == true) { |
|---|
| 262 | 263 | resizeType = rend.getResizeType (cx-x, cy-y, w,h); |
|---|
| … | … | |
| 301 | 302 | |
|---|
| 302 | 303 | //BEGIN Window moving and resizing |
|---|
| 303 | | void moveCallback (ushort cx, ushort cy) { |
|---|
| | 304 | void moveCallback (wdabs cx, wdabs cy) { |
|---|
| 304 | 305 | setPosition (cx-xDrag, cy-yDrag); |
|---|
| 305 | 306 | } |
|---|
| 306 | | void resizeCallback (ushort cx, ushort cy) { |
|---|
| | 307 | void resizeCallback (wdabs cx, wdabs cy) { |
|---|
| 307 | 308 | debug scope(failure) |
|---|
| 308 | 309 | logger.trace ("resizeCallback: failure"); |
|---|
| … | … | |
| 313 | 314 | |
|---|
| 314 | 315 | if (resizeType & RESIZE_TYPE.L) { |
|---|
| 315 | | int xSize = xDrag - cx; |
|---|
| | 316 | wdim xSize = xDrag - cx; |
|---|
| 316 | 317 | if (xSize < mw) xSize = mw; // clamp |
|---|
| 317 | 318 | x += w - xSize; |
|---|
| … | … | |
| 322 | 323 | } |
|---|
| 323 | 324 | if (resizeType & RESIZE_TYPE.T) { |
|---|
| 324 | | int ySize = yDrag - cy; |
|---|
| | 325 | wdim ySize = yDrag - cy; |
|---|
| 325 | 326 | if (ySize < mh) ySize = mh; |
|---|
| 326 | 327 | y += h - ySize; |
|---|
| … | … | |
| 335 | 336 | setPosition (x, y); |
|---|
| 336 | 337 | } |
|---|
| 337 | | bool endCallback (ushort cx, ushort cy, ubyte b, bool state) { |
|---|
| | 338 | bool endCallback (wdabs cx, wdabs cy, ubyte b, bool state) { |
|---|
| 338 | 339 | if (b == 1 && state == false) { |
|---|
| 339 | 340 | // The mouse shouldn't have moved since the motion callback |
|---|
| … | … | |
| 345 | 346 | return false; // we haven't handled it |
|---|
| 346 | 347 | } |
|---|
| 347 | | int xDrag, yDrag; // where a drag starts relative to x and y |
|---|
| | 348 | wdim xDrag, yDrag; // where a drag starts relative to x and y |
|---|
| 348 | 349 | IRenderer.RESIZE_TYPE resizeType; // Type of current resize |
|---|
| 349 | 350 | //END Window moving and resizing |
|---|
| … | … | |
| 362 | 363 | IWidget widget; // The primary widget in this window. |
|---|
| 363 | 364 | |
|---|
| 364 | | int x = -1, y = -1; // Window position |
|---|
| 365 | | int w,h; // Window size (calculated from Widgets) |
|---|
| 366 | | int xw, yh; // x+w, y+h (frequent use by clickEvent) |
|---|
| 367 | | int widgetX, widgetY; // Widget position (= window position plus BORDER_WIDTH) |
|---|
| 368 | | int mw = -1, mh = -1; // minimal size (negative means requires calculation) |
|---|
| | 365 | wdim x = -1, y = -1; // Window position |
|---|
| | 366 | wdsize w,h; // Window size (calculated from Widgets) |
|---|
| | 367 | wdim xw, yh; // x+w, y+h (frequent use by clickEvent) |
|---|
| | 368 | wdim widgetX, widgetY; // Widget position (= window position plus BORDER_WIDTH) |
|---|
| | 369 | wdim mw = -1, mh = -1; // minimal size (negative means requires calculation) |
|---|
| 369 | 370 | |
|---|
| 370 | 371 | BorderDimensions border; // Total border size (move plus resize) |
|---|
| r46 |
r58 |
|
| 84 | 84 | } else { // sufficient data |
|---|
| 85 | 85 | lenUsed = rows+cols; |
|---|
| 86 | | col.setCheck (data[0..cols]); |
|---|
| 87 | | row.setCheck (data[cols..lenUsed]); |
|---|
| | 86 | col.setCheck (cast(wdim[])data[0..cols]); |
|---|
| | 87 | row.setCheck (cast(wdim[])data[cols..lenUsed]); |
|---|
| 88 | 88 | } |
|---|
| 89 | 89 | |
|---|
| … | … | |
| 120 | 120 | ret ~= widget.getMutableData; |
|---|
| 121 | 121 | |
|---|
| 122 | | ret ~= col.width ~ row.width; |
|---|
| 123 | | return ret; |
|---|
| | 122 | return ret ~ cast(int[])col.width ~ cast(int[])row.width; |
|---|
| 124 | 123 | } |
|---|
| 125 | 124 | //END Creation & saving |
|---|
| … | … | |
| 134 | 133 | |
|---|
| 135 | 134 | /* Calculates the minimal size from all rows and columns of widgets. */ |
|---|
| 136 | | void getMinimalSize (out int mw, out int mh) { |
|---|
| | 135 | void getMinimalSize (out wdim mw, out wdim mh) { |
|---|
| 137 | 136 | mw = this.mw; |
|---|
| 138 | 137 | mh = this.mh; |
|---|
| 139 | 138 | } |
|---|
| 140 | 139 | |
|---|
| 141 | | void setWidth (int nw, int dir) { |
|---|
| | 140 | void setWidth (wdim nw, int dir) { |
|---|
| 142 | 141 | if (nw == w) return; |
|---|
| 143 | 142 | |
|---|
| … | … | |
| 146 | 145 | // Note: setPosition must be called after! |
|---|
| 147 | 146 | } |
|---|
| 148 | | void setHeight (int nh, int dir) { |
|---|
| | 147 | void setHeight (wdim nh, int dir) { |
|---|
| 149 | 148 | if (nh == h) return; |
|---|
| 150 | 149 | |
|---|
| … | … | |
| 154 | 153 | } |
|---|
| 155 | 154 | |
|---|
| 156 | | void setPosition (int x, int y) { |
|---|
| | 155 | void setPosition (wdim x, wdim y) { |
|---|
| 157 | 156 | this.x = x; |
|---|
| 158 | 157 | this.y = y; |
|---|
| … | … | |
| 165 | 164 | |
|---|
| 166 | 165 | // Find the relevant widget. |
|---|
| 167 | | IWidget getWidget (int cx, int cy) { |
|---|
| | 166 | IWidget getWidget (wdim cx, wdim cy) { |
|---|
| 168 | 167 | debug scope (failure) |
|---|
| 169 | 168 | logger.warn ("getWidget: failure"); |
|---|
| … | … | |
| 179 | 178 | |
|---|
| 180 | 179 | // Resizing columns & rows |
|---|
| 181 | | void clickEvent (ushort cx, ushort cy, ubyte b, bool state) { |
|---|
| | 180 | void clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { |
|---|
| 182 | 181 | debug scope (failure) |
|---|
| 183 | 182 | logger.warn ("clickEvent: failure"); |
|---|
| … | … | |
| 217 | 216 | // Calculate the minimal column and row sizes: |
|---|
| 218 | 217 | // set length, making sure the arrays are initialised to zero: |
|---|
| 219 | | col.minWidth = new int[cols]; |
|---|
| 220 | | row.minWidth = new int[rows]; |
|---|
| 221 | | int ww, wh; // sub-widget minimal sizes |
|---|
| | 218 | col.minWidth = new wdim[cols]; |
|---|
| | 219 | row.minWidth = new wdim[rows]; |
|---|
| | 220 | wdim ww, wh; // sub-widget minimal sizes |
|---|
| 222 | 221 | foreach (i,widget; subWidgets) { |
|---|
| 223 | 222 | widget.getMinimalSize (ww, wh); |
|---|
| … | … | |
| 233 | 232 | // Calculate the overall minimal size, starting with the spacing: |
|---|
| 234 | 233 | mh = window.renderer.layoutSpacing; // use mh temporarily |
|---|
| 235 | | mw = mh * (cols - 1); |
|---|
| 236 | | mh *= (rows - 1); |
|---|
| | 234 | mw = mh * cast(wdim)(cols - 1); |
|---|
| | 235 | mh *= cast(wdim)(rows - 1); |
|---|
| 237 | 236 | |
|---|
| 238 | 237 | foreach (x; col.minWidth) // add the column/row's dimensions |
|---|
| … | … | |
| 276 | 275 | |
|---|
| 277 | 276 | |
|---|
| 278 | | void setColWidth (myIt i, int w, int dir) { |
|---|
| | 277 | void setColWidth (myIt i, wdim w, int dir) { |
|---|
| 279 | 278 | for (myIt j = 0; j < rows; ++j) { |
|---|
| 280 | 279 | subWidgets[i + cols*j].setWidth (w, dir); |
|---|
| 281 | 280 | } |
|---|
| 282 | 281 | } |
|---|
| 283 | | void setRowHeight (myIt j, int h, int dir) { |
|---|
| | 282 | void setRowHeight (myIt j, wdim h, int dir) { |
|---|
| 284 | 283 | for (myIt i = 0; i < cols; ++i) { |
|---|
| 285 | 284 | subWidgets[i + cols*j].setHeight (h, dir); |
|---|
| … | … | |
| 289 | 288 | |
|---|
| 290 | 289 | //BEGIN Col/row resizing callback |
|---|
| 291 | | void resizeCallback (ushort cx, ushort cy) { |
|---|
| | 290 | void resizeCallback (wdim cx, wdim cy) { |
|---|
| 292 | 291 | col.resize (cx - dragX); |
|---|
| 293 | 292 | row.resize (cy - dragY); |
|---|
| … | … | |
| 302 | 301 | window.requestRedraw; |
|---|
| 303 | 302 | } |
|---|
| 304 | | bool endCallback (ushort cx, ushort cy, ubyte b, bool state) { |
|---|
| | 303 | bool endCallback (wdabs cx, wdabs cy, ubyte b, bool state) { |
|---|
| 305 | 304 | if (b == 1 && state == false) { |
|---|
| 306 | 305 | window.gui.removeCallbacks (cast(void*) this); |
|---|
| … | … | |
| 312 | 311 | protected: |
|---|
| 313 | 312 | // Data for resizing cols/rows: |
|---|
| 314 | | int dragX, dragY; // coords where drag starts |
|---|
| | 313 | wdim dragX, dragY; // coords where drag starts |
|---|
| 315 | 314 | //END Col/row resizing callback |
|---|
| 316 | 315 | |
|---|
| … | … | |
| 329 | 328 | * Most notation corresponds to horizontal layout (columns), simply for easy of naming. */ |
|---|
| 330 | 329 | struct CellDimensions { |
|---|
| 331 | | int[] pos, // relative position (cumulative width[i-1] plus spacing) |
|---|
| | 330 | wdim[] pos, // relative position (cumulative width[i-1] plus spacing) |
|---|
| 332 | 331 | width, // current widths |
|---|
| 333 | 332 | minWidth; // minimal widths (set by genCachedConstructionData) |
|---|
| … | … | |
| 337 | 336 | myDiff resizeD, // resize down from this index (<0 if not resizing) |
|---|
| 338 | 337 | resizeU; // and up from this index |
|---|
| 339 | | int spacing; // used by genPositions (which cannot access the layout class's data) |
|---|
| | 338 | wdim spacing; // used by genPositions (which cannot access the layout class's data) |
|---|
| 340 | 339 | /* This is a delegate to a enclosing class's function, since: |
|---|
| 341 | 340 | * a different implementation is needed for cols or rows |
|---|
| 342 | 341 | * we're unable to access enclosing class members directly */ |
|---|
| 343 | | void delegate (myIt,int,int) setColWidth; // set width of a column, with resize direction |
|---|
| | 342 | void delegate (myIt,wdim,int) setColWidth; // set width of a column, with resize direction |
|---|
| 344 | 343 | |
|---|
| 345 | 344 | void dupMin () { |
|---|
| 346 | 345 | width = minWidth.dup; |
|---|
| 347 | 346 | } |
|---|
| 348 | | void setCheck (int[] data) { |
|---|
| | 347 | void setCheck (wdim[] data) { |
|---|
| 349 | 348 | // Set to provided data: |
|---|
| 350 | 349 | width = data; |
|---|
| … | … | |
| 357 | 356 | |
|---|
| 358 | 357 | // Generate position infomation and return total width (i.e. widget width/height) |
|---|
| 359 | | int genPositions () { |
|---|
| | 358 | wdim genPositions () { |
|---|
| 360 | 359 | pos.length = minWidth.length; |
|---|
| 361 | 360 | |
|---|
| 362 | | int x = 0; |
|---|
| | 361 | wdim x = 0; |
|---|
| 363 | 362 | foreach (i, w; width) { |
|---|
| 364 | 363 | pos[i] = x; |
|---|
| … | … | |
| 370 | 369 | // Get the row/column a click occured in |
|---|
| 371 | 370 | // Returns -i if in space to left of col i, or i if on col i |
|---|
| 372 | | myDiff getCell (int l) { |
|---|
| | 371 | myDiff getCell (wdim l) { |
|---|
| 373 | 372 | myDiff i = minWidth.length - 1; // starting from right... |
|---|
| 374 | 373 | while (l < pos[i]) { // decrement while left of this column |
|---|
| … | … | |
| 382 | 381 | |
|---|
| 383 | 382 | // Calculate resizeU/resizeD, and return true if unable to resize. |
|---|
| 384 | | bool findResize (int l) { |
|---|
| | 383 | bool findResize (wdim l) { |
|---|
| 385 | 384 | resizeU = -getCell (l); // potential start for upward-resizes |
|---|
| 386 | 385 | if (resizeU <= 0) return true; // not on a space between cells |
|---|
| … | … | |
| 419 | 418 | * index is passed, this should get increased (if diff > 0) but not decreased. |
|---|
| 420 | 419 | */ |
|---|
| 421 | | int adjustCellSizes (int diff, myDiff start, int incr) |
|---|
| | 420 | wdim adjustCellSizes (wdim diff, myDiff start, int incr) |
|---|
| 422 | 421 | in { |
|---|
| 423 | 422 | // Could occur if adjust isn't called first, but this would be a code error: |
|---|
| … | … | |
| 436 | 435 | } |
|---|
| 437 | 436 | else if (diff < 0) { // decrease |
|---|
| 438 | | int rd = diff; // running diff |
|---|
| | 437 | wdim rd = diff; // running diff |
|---|
| 439 | 438 | aCSwhile: |
|---|
| 440 | 439 | while (true) { |
|---|
| … | … | |
| 469 | 468 | } |
|---|
| 470 | 469 | |
|---|
| 471 | | void resize (int diff) { |
|---|
| | 470 | void resize (wdim diff) { |
|---|
| 472 | 471 | if (resizeU <= 0) return; |
|---|
| 473 | 472 | |
|---|
| … | … | |
| 485 | 484 | |
|---|
| 486 | 485 | // Index types. Note that in some cases they need to hold negative values. |
|---|
| 487 | | // Int is used for resizing direction (although ptrdiff_t would be more appropriate), |
|---|
| | 486 | // int is used for resizing direction (although ptrdiff_t would be more appropriate), |
|---|
| 488 | 487 | // since the value must always be -1 or +1 and int is smaller on X86_64. |
|---|
| 489 | 488 | alias size_t myIt; |
|---|
| r57 |
r58 |
|
| 72 | 72 | } |
|---|
| 73 | 73 | |
|---|
| 74 | | void clickEvent (ushort, ushort, ubyte b, bool state) { |
|---|
| | 74 | void clickEvent (wdabs, wdabs, ubyte b, bool state) { |
|---|
| 75 | 75 | if (b == 1 && state == true) { |
|---|
| 76 | 76 | pushed = true; |
|---|
| … | … | |
| 81 | 81 | } |
|---|
| 82 | 82 | // Called when a mouse motion/click event occurs while (held == true) |
|---|
| 83 | | bool clickWhileHeld (ushort cx, ushort cy, ubyte b, bool state) { |
|---|
| | 83 | bool clickWhileHeld (wdabs cx, wdabs cy, ubyte b, bool state) { |
|---|
| 84 | 84 | if (b == 1 && state == false) { |
|---|
| 85 | 85 | if (cx >= x && cx < x+w && cy >= y && cy < y+h) // button event |
|---|
| … | … | |
| 94 | 94 | return false; |
|---|
| 95 | 95 | } |
|---|
| 96 | | void motionWhileHeld (ushort cx, ushort cy) { |
|---|
| | 96 | void motionWhileHeld (wdabs cx, wdabs cy) { |
|---|
| 97 | 97 | bool oldPushed = pushed; |
|---|
| 98 | 98 | if (cx >= x && cx < x+w && cy >= y && cy < y+h) pushed = true; |
|---|
| … | … | |
| 110 | 110 | if (font is null) font = FontStyle.get("default"); |
|---|
| 111 | 111 | font.updateBlock (str, textCache); |
|---|
| 112 | | mw = textCache.w; |
|---|
| 113 | | mh = textCache.h; |
|---|
| | 112 | mw = cast(wdim) textCache.w; |
|---|
| | 113 | mh = cast(wdim) textCache.h; |
|---|
| 114 | 114 | colour = Colour (cast(ubyte) (data[1] >> 16u), |
|---|
| 115 | 115 | cast(ubyte) (data[1] >> 8u), |
|---|