1 /** DGui project file. 2 3 Copyright: Trogu Antonio Davide 2011-2013 4 5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 7 Authors: Trogu Antonio Davide 8 */ 9 module dgui.core.geometry; 10 11 import dgui.core.winapi; 12 13 struct Rect 14 { 15 public union 16 { 17 align(1) struct 18 { 19 uint left = 0; 20 uint top = 0; 21 uint right = 0; 22 uint bottom = 0; 23 } 24 25 RECT rect; 26 } 27 28 public static Rect opCall(Point pt, Size sz) 29 { 30 return opCall(pt.x, pt.y, sz.width, sz.height); 31 } 32 33 public static Rect opCall(uint l, uint t, uint w, uint h) 34 { 35 Rect r = void; //Viene inizializzata sotto. 36 37 r.left = l; 38 r.top = t; 39 r.right = l + w; 40 r.bottom = t + h; 41 42 return r; 43 } 44 45 public const bool opEquals(ref const Rect r) 46 { 47 return this.left == r.left && this.top == r.top && this.right == r.right && this.bottom == r.bottom; 48 } 49 50 @property public int x() 51 { 52 return this.left; 53 } 54 55 @property public void x(int newX) 56 { 57 int w = this.width; 58 59 this.left = newX; 60 this.right = newX + w; 61 } 62 63 @property public int y() 64 { 65 return this.top; 66 } 67 68 @property public void y(int newY) 69 { 70 int h = this.height; 71 72 this.top = newY; 73 this.bottom = newY + h; 74 } 75 76 @property public int width() 77 { 78 if(this.right != CW_USEDEFAULT) 79 { 80 return this.right - this.left; 81 } 82 83 return CW_USEDEFAULT; 84 } 85 86 @property public void width(int w) 87 { 88 this.right = this.left + w; 89 } 90 91 @property public int height() 92 { 93 if(this.bottom != CW_USEDEFAULT) 94 { 95 return this.bottom - this.top; 96 } 97 98 return CW_USEDEFAULT; 99 } 100 101 @property public void height(int h) 102 { 103 this.bottom = this.top + h; 104 } 105 106 @property public Point position() 107 { 108 return Point(this.left, this.top); 109 } 110 111 @property public void position(Point pt) 112 { 113 Size sz = this.size; //Copia dimensioni 114 115 this.left = pt.x; 116 this.top = pt.y; 117 this.right = this.left + sz.width; 118 this.bottom = this.top + sz.height; 119 } 120 121 @property public Size size() 122 { 123 return Size(this.width, this.height); 124 } 125 126 @property public void size(Size sz) 127 { 128 this.right = this.left + sz.width; 129 this.bottom = this.top + sz.height; 130 } 131 132 @property public bool empty() 133 { 134 return this.width <= 0 && this.height <= 0; 135 } 136 137 public static Rect fromRECT(RECT* pWinRect) 138 { 139 Rect r = void; //Inizializzata sotto 140 141 r.rect = *pWinRect; 142 return r; 143 } 144 } 145 146 struct Point 147 { 148 public union 149 { 150 align(1) struct 151 { 152 uint x = 0; 153 uint y = 0; 154 } 155 156 POINT point; 157 } 158 159 public bool inRect(Rect r) 160 { 161 if(point.x < r.left || point.y < r.top || point.x > r.right || point.y > r.bottom) 162 { 163 return false; 164 } 165 166 return true; 167 } 168 169 public bool opEquals(ref const Point pt) const 170 { 171 return this.x == pt.x && this.y == pt.y; 172 } 173 174 public static Point opCall(int x, int y) 175 { 176 Point pt = void; //Viene inizializzata sotto. 177 178 pt.x = x; 179 pt.y = y; 180 return pt; 181 } 182 } 183 184 struct Size 185 { 186 public union 187 { 188 align(1) struct 189 { 190 uint width = 0; 191 uint height = 0; 192 } 193 194 SIZE size; 195 } 196 197 public bool opEquals(ref const Size sz) const 198 { 199 return this.width == sz.width && this.height == sz.height; 200 } 201 202 public static Size opCall(int w, int h) 203 { 204 Size sz = void; 205 206 sz.width = w; 207 sz.height = h; 208 return sz; 209 } 210 } 211 212 public const Rect nullRect; // = Rect.init; 213 public const Point nullPoint; // = Point.init; 214 public const Size nullSize; // = Size.init;