1 ////////////////////////////////////////////////////////////////////////// 2 // 3 // pgAdmin III - PostgreSQL Tools 4 // 5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team 6 // This software is released under the PostgreSQL Licence 7 // 8 // hdMultiRect.h - hdRect improved class with new needed functionalities for allowing multiple displaybox for same figure 9 // 10 ////////////////////////////////////////////////////////////////////////// 11 12 #ifndef HDMULTIPOSRECT_H 13 #define HDMULTIPOSRECT_H 14 #include "hotdraw/main/hdObject.h" 15 #include "hotdraw/utilities/hdPoint.h" 16 #include "hotdraw/utilities/hdRect.h" 17 18 #define MAXPOS 1 19 20 class hdMultiPosRect : public hdObject 21 { 22 public: hdMultiPosRect()23 hdMultiPosRect() 24 : width(0), height(0) 25 { 26 init(); 27 } 28 hdMultiPosRect(int xx,int yy,int ww,int hh)29 hdMultiPosRect(int xx, int yy, int ww, int hh) 30 : width(ww), height(hh) 31 { 32 init(xx, yy); 33 } 34 35 hdMultiPosRect(int posIdx, const wxPoint &topLeft, const wxPoint &bottomRight); 36 hdMultiPosRect(hdPoint * point)37 hdMultiPosRect(hdPoint *point) 38 : width(0), height(0) 39 { 40 init(point->x, point->y); 41 } 42 hdMultiPosRect(hdPoint & point)43 hdMultiPosRect(hdPoint &point) 44 : width(0), height(0) 45 { 46 init(point.x, point.y); 47 } 48 hdMultiPosRect(const wxPoint & pt,const wxSize & size)49 hdMultiPosRect(const wxPoint &pt, const wxSize &size) 50 : width(size.x), height(size.y) 51 { 52 init(pt.x, pt.y); 53 } 54 hdMultiPosRect(const wxSize & size)55 hdMultiPosRect(const wxSize &size) 56 : width(size.x), height(size.y) 57 { 58 init(0, 0); 59 } 60 // default copy ctor and assignment operators ok 61 GetX(int posIdx)62 int GetX(int posIdx) const 63 { 64 return x[posIdx]; 65 } SetX(int posIdx,int xx)66 void SetX(int posIdx, int xx) 67 { 68 x[posIdx] = xx; 69 } 70 GetY(int posIdx)71 int GetY(int posIdx) const 72 { 73 return y[posIdx]; 74 } SetY(int posIdx,int yy)75 void SetY(int posIdx, int yy) 76 { 77 y[posIdx] = yy; 78 } 79 GetWidth()80 int GetWidth() const 81 { 82 return width; 83 } SetWidth(int w)84 void SetWidth(int w) 85 { 86 width = w; 87 } 88 GetHeight()89 int GetHeight() const 90 { 91 return height; 92 } SetHeight(int h)93 void SetHeight(int h) 94 { 95 height = h; 96 } 97 GetPosition(int posIdx)98 wxPoint GetPosition(int posIdx) const 99 { 100 return wxPoint(x[posIdx], y[posIdx]); 101 } SetPosition(int posIdx,const wxPoint & p)102 void SetPosition( int posIdx, const wxPoint &p ) 103 { 104 x[posIdx] = p.x; 105 y[posIdx] = p.y; 106 } 107 GetSize()108 wxSize GetSize() const 109 { 110 return wxSize(width, height); 111 } SetSize(const wxSize & s)112 void SetSize( const wxSize &s ) 113 { 114 width = s.GetWidth(); 115 height = s.GetHeight(); 116 } 117 IsEmpty()118 bool IsEmpty() const 119 { 120 return (width <= 0) || (height <= 0); 121 } 122 GetLeft(int posIdx)123 int GetLeft(int posIdx) const 124 { 125 return x[posIdx]; 126 } GetTop(int posIdx)127 int GetTop(int posIdx) const 128 { 129 return y[posIdx]; 130 } GetBottom(int posIdx)131 int GetBottom(int posIdx) const 132 { 133 return y[posIdx] + height - 1; 134 } GetRight(int posIdx)135 int GetRight(int posIdx) const 136 { 137 return x[posIdx] + width - 1; 138 } 139 SetLeft(int posIdx,int left)140 void SetLeft(int posIdx, int left) 141 { 142 x[posIdx] = left; 143 } SetRight(int posIdx,int right)144 void SetRight(int posIdx, int right) 145 { 146 width = right - x[posIdx] + 1; 147 } SetTop(int posIdx,int top)148 void SetTop(int posIdx, int top) 149 { 150 y[posIdx] = top; 151 } SetBottom(int posIdx,int bottom)152 void SetBottom(int posIdx, int bottom) 153 { 154 height = bottom - y[posIdx] + 1; 155 } 156 GetTopLeft(int posIdx)157 wxPoint GetTopLeft(int posIdx) const 158 { 159 return GetPosition(posIdx); 160 } GetLeftTop(int posIdx)161 wxPoint GetLeftTop(int posIdx) const 162 { 163 return GetTopLeft(posIdx); 164 } SetTopLeft(int posIdx,const wxPoint & p)165 void SetTopLeft(int posIdx, const wxPoint &p) 166 { 167 SetPosition(posIdx, p); 168 } SetLeftTop(int posIdx,const wxPoint & p)169 void SetLeftTop(int posIdx, const wxPoint &p) 170 { 171 SetTopLeft(posIdx, p); 172 } 173 GetBottomRight(int posIdx)174 wxPoint GetBottomRight(int posIdx) const 175 { 176 return wxPoint(GetRight(posIdx), GetBottom(posIdx)); 177 } GetRightBottom(int posIdx)178 wxPoint GetRightBottom(int posIdx) const 179 { 180 return GetBottomRight(posIdx); 181 } SetBottomRight(int posIdx,const wxPoint & p)182 void SetBottomRight(int posIdx, const wxPoint &p) 183 { 184 SetRight(posIdx, p.x); 185 SetBottom(posIdx, p.y); 186 } SetRightBottom(int posIdx,const wxPoint & p)187 void SetRightBottom(int posIdx, const wxPoint &p) 188 { 189 SetBottomRight(posIdx, p); 190 } 191 GetTopRight(int posIdx)192 wxPoint GetTopRight(int posIdx) const 193 { 194 return wxPoint(GetRight(posIdx), GetTop(posIdx)); 195 } GetRightTop(int posIdx)196 wxPoint GetRightTop(int posIdx) const 197 { 198 return GetTopRight(posIdx); 199 } SetTopRight(int posIdx,const wxPoint & p)200 void SetTopRight(int posIdx, const wxPoint &p) 201 { 202 SetRight(posIdx, p.x); 203 SetTop(posIdx, p.y); 204 } SetRightTop(int posIdx,const wxPoint & p)205 void SetRightTop(int posIdx, const wxPoint &p) 206 { 207 SetTopLeft(posIdx, p); 208 } 209 GetBottomLeft(int posIdx)210 wxPoint GetBottomLeft(int posIdx) const 211 { 212 return wxPoint(GetLeft(posIdx), GetBottom(posIdx)); 213 } GetLeftBottom(int posIdx)214 wxPoint GetLeftBottom(int posIdx) const 215 { 216 return GetBottomLeft(posIdx); 217 } SetBottomLeft(int posIdx,const wxPoint & p)218 void SetBottomLeft(int posIdx, const wxPoint &p) 219 { 220 SetLeft(posIdx, p.x); 221 SetBottom(posIdx, p.y); 222 } SetLeftBottom(int posIdx,const wxPoint & p)223 void SetLeftBottom(int posIdx, const wxPoint &p) 224 { 225 SetBottomLeft(posIdx, p); 226 } 227 228 // operations with rect 229 hdMultiPosRect &Inflate(int posIdx, wxCoord dx, wxCoord dy); Inflate(int posIdx,const wxSize & d)230 hdMultiPosRect &Inflate(int posIdx, const wxSize &d) 231 { 232 return Inflate(posIdx, d.x, d.y); 233 } Inflate(int posIdx,wxCoord d)234 hdMultiPosRect &Inflate(int posIdx, wxCoord d) 235 { 236 return Inflate(posIdx, d, d); 237 } 238 Inflate(int posIdx,wxCoord dx,wxCoord dy)239 hdMultiPosRect Inflate(int posIdx, wxCoord dx, wxCoord dy) const 240 { 241 hdMultiPosRect r = *this; 242 r.Inflate(posIdx, dx, dy); 243 return r; 244 } 245 Deflate(int posIdx,wxCoord dx,wxCoord dy)246 hdMultiPosRect &Deflate(int posIdx, wxCoord dx, wxCoord dy) 247 { 248 return Inflate(posIdx, -dx, -dy); 249 } Deflate(int posIdx,const wxSize & d)250 hdMultiPosRect &Deflate(int posIdx, const wxSize &d) 251 { 252 return Inflate(posIdx, -d.x, -d.y); 253 } Deflate(int posIdx,wxCoord d)254 hdMultiPosRect &Deflate(int posIdx, wxCoord d) 255 { 256 return Inflate(posIdx, -d); 257 } 258 Deflate(int posIdx,wxCoord dx,wxCoord dy)259 hdMultiPosRect Deflate(int posIdx, wxCoord dx, wxCoord dy) const 260 { 261 hdMultiPosRect r = *this; 262 r.Deflate(posIdx, dx, dy); 263 return r; 264 } 265 266 Offset(int posIdx,wxCoord dx,wxCoord dy)267 void Offset(int posIdx, wxCoord dx, wxCoord dy) 268 { 269 x[posIdx] += dx; 270 y[posIdx] += dy; 271 } Offset(int posIdx,const wxPoint & pt)272 void Offset(int posIdx, const wxPoint &pt) 273 { 274 Offset(posIdx, pt.x, pt.y); 275 } 276 277 hdMultiPosRect &Intersect(int posIdx, const hdMultiPosRect &rect); 278 Intersect(int posIdx,const hdMultiPosRect & rect)279 hdMultiPosRect Intersect(int posIdx, const hdMultiPosRect &rect) const 280 { 281 hdMultiPosRect r = *this; 282 r.Intersect(posIdx, rect); 283 return r; 284 } 285 286 hdMultiPosRect &Union(int posIdx, const hdMultiPosRect &rect); 287 288 Union(int posIdx,const hdMultiPosRect & rect)289 hdMultiPosRect Union(int posIdx, const hdMultiPosRect &rect) const 290 { 291 hdMultiPosRect r = *this; 292 r.Union(posIdx, rect); 293 return r; 294 } 295 296 // return true if the point is (not strcitly) inside the rect 297 bool Contains(int posIdx, int x, int y) const; Contains(int posIdx,const wxPoint & pt)298 bool Contains(int posIdx, const wxPoint &pt) const 299 { 300 return Contains(posIdx, pt.x, pt.y); 301 } 302 // return true if the rectangle is (not strcitly) inside the rect 303 bool Contains(int posIdx, const hdRect &rect) const; 304 305 // return true if the rectangles have a non empty intersection 306 bool Intersects(int posIdx, const hdMultiPosRect &rect) const; 307 308 // centre this rectangle in the given (usually, but not necessarily, 309 // larger) one 310 hdMultiPosRect CentreIn(int posIdxThis, const hdMultiPosRect &r, int posIdxr, int dir = wxBOTH) const 311 { 312 return hdMultiPosRect(dir & wxHORIZONTAL ? r.x[posIdxr] + (r.width - width) / 2 : x[posIdxThis], 313 dir & wxVERTICAL ? r.y[posIdxr] + (r.height - height) / 2 : y[posIdxThis], 314 width, height); 315 } 316 317 hdMultiPosRect CenterIn(int posIdxThis, const hdMultiPosRect &r, int posIdxr, int dir = wxBOTH) const 318 { 319 return CentreIn(posIdxThis, r, posIdxr, dir); 320 } 321 322 void add (int posIdx, int newX, int netY); 323 void add (int posIdx, hdRect *newRect); 324 void add (int posIdx, hdRect newRect); 325 void add (int posIdx, hdPoint *p); 326 hdPoint center(int posIdx); gethdRect(int posIdx)327 hdRect gethdRect(int posIdx) 328 { 329 return hdRect(x[posIdx], y[posIdx], width, height); 330 } 331 int CountPositions(); 332 void addNewXYPosition(); 333 void removeXYPosition(int posIdx); 334 wxArrayInt x, y; 335 int width, height; 336 337 private: 338 void init(int valX = 0, int valY = 0); 339 hdPoint point; 340 }; 341 #endif 342 343