Mercurial > projects > mde
comparison mde/gui/renderer/SimpleRenderer.d @ 41:b3a6ca4516b4
The renderer now controls which parts of the window border allow resizing.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 13 May 2008 12:02:36 +0100 |
parents | 5132301e9ed7 |
children | 1530d9c04d4d |
comparison
equal
deleted
inserted
replaced
40:b28d7adc786b | 41:b3a6ca4516b4 |
---|---|
27 * renderer may also be available. | 27 * renderer may also be available. |
28 * | 28 * |
29 * The renderer is intended to be per-GUI. */ | 29 * The renderer is intended to be per-GUI. */ |
30 class SimpleRenderer : IRenderer | 30 class SimpleRenderer : IRenderer |
31 { | 31 { |
32 BorderDimensions getBorder (BORDER_TYPES type) { | 32 BorderDimensions setSizable (bool wS, bool hS) { |
33 BorderDimensions dims; | 33 wSizable = wS; |
34 with (BORDER_TYPES) with (dims) { | 34 hSizable = hS; |
35 if (type == WINDOW_TOTAL) { | 35 |
36 l = t = r = b = 20; | 36 // Set the border size based on the above |
37 } else if (type == WINDOW_RESIZE) { | 37 with (border) { |
38 r = t = 5; | 38 l = r = t = b = 14; |
39 l = b = 20; | 39 } |
40 with (resize) { | |
41 if (wSizable) | |
42 l = r = 6; | |
43 else | |
44 l = r = 0; | |
45 if (hSizable) { | |
46 t = 2; | |
47 b = 6; | |
48 } else | |
49 t = b = 0; | |
50 } | |
51 border += resize; | |
52 return border; | |
53 } | |
54 | |
55 RESIZE_TYPE getResizeType (int cx, int cy, int w, int h) { | |
56 RESIZE_TYPE resizeType = RESIZE_TYPE.NONE; | |
57 if (cx < resize.l || cx >= w - resize.r || | |
58 cy < resize.t || cy >= h - resize.b) { // window is being resized | |
59 /* check for resizes (different to above; use whole border giving larger area for | |
60 * diagonal resizes). */ | |
61 | |
62 if (wSizable) { | |
63 if (cx < border.l) | |
64 resizeType = RESIZE_TYPE.L; | |
65 else if (cx >= w - border.r) | |
66 resizeType = RESIZE_TYPE.R; | |
67 } | |
68 if (hSizable) { | |
69 if (cy < border.t) | |
70 resizeType |= RESIZE_TYPE.T; | |
71 else if (cy >= h - border.b) | |
72 resizeType |= RESIZE_TYPE.B; | |
40 } | 73 } |
41 } | 74 } |
42 return dims; | 75 return resizeType; |
43 } | 76 } |
44 | 77 |
45 int layoutSpacing () { | 78 int layoutSpacing () { |
46 return 4; | 79 return 4; |
47 } | 80 } |
50 void drawWindow (int x, int y, int w, int h) { | 83 void drawWindow (int x, int y, int w, int h) { |
51 gl.setColor (0f, 0f, .7f); | 84 gl.setColor (0f, 0f, .7f); |
52 gl.drawBox (x,y, w,h); | 85 gl.drawBox (x,y, w,h); |
53 | 86 |
54 gl.setColor (0f, 0f, 1f); | 87 gl.setColor (0f, 0f, 1f); |
55 gl.drawBox (x+20,y+5, w-25,h-25); | 88 gl.drawBox (x+resize.l, y+resize.t, w-resize.l-resize.r, h-resize.t-resize.b); |
56 | 89 |
57 gl.setColor (.3f, .3f, .3f); | 90 gl.setColor (.3f, .3f, .3f); |
58 gl.drawBox (x+20, y+20, w-40, h-40); | 91 gl.drawBox (x+border.l, y+border.t, w-border.l-border.r, h-border.t-border.b); |
59 } | 92 } |
60 | 93 |
61 void drawWidgetBack (int x, int y, int w, int h) {} | 94 void drawWidgetBack (int x, int y, int w, int h) {} |
62 | 95 |
63 void drawButton (int x, int y, int w, int h, bool pushed) { | 96 void drawButton (int x, int y, int w, int h, bool pushed) { |
65 gl.setColor (1f, 0f, 1f); | 98 gl.setColor (1f, 0f, 1f); |
66 else | 99 else |
67 gl.setColor (.6f, 0f, .6f); | 100 gl.setColor (.6f, 0f, .6f); |
68 gl.drawBox (x,y, w,h); | 101 gl.drawBox (x,y, w,h); |
69 } | 102 } |
103 | |
104 protected: | |
105 bool wSizable, hSizable; | |
106 BorderDimensions border; | |
107 BorderDimensions resize; | |
70 } | 108 } |