Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGDimension.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 02/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGDimension
13 #define ROOT_TGDimension
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TGDimension, TGPosition, TGLongPosition, TGInsets and TGRectangle //
18 // //
19 // Several small geometry classes that implement dimensions //
20 // (width and height), positions (x and y), insets and rectangles. //
21 // They are trivial and their members are public. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TObject.h"
26 
27 class TGDimension {
28 public:
29  UInt_t fWidth; // width
30  UInt_t fHeight; // height
31 
32  TGDimension(): fWidth(0), fHeight(0) { }
33  TGDimension(UInt_t width, UInt_t height): fWidth(width), fHeight(height) { }
34  ~TGDimension() = default;
35 
36  Bool_t operator==(const TGDimension &b) const
37  { return ((fWidth == b.fWidth) && (fHeight == b.fHeight)); }
38  TGDimension operator-(const TGDimension &b) const
39  { return TGDimension(fWidth - b.fWidth, fHeight - b.fHeight); }
40  TGDimension operator+(const TGDimension &b) const
41  { return TGDimension(fWidth + b.fWidth, fHeight + b.fHeight); }
42 };
43 
44 
45 class TGPosition {
46 public:
47  Int_t fX; // x position
48  Int_t fY; // y position
49 
50  TGPosition(): fX(0), fY(0) { }
51  TGPosition(Int_t xc, Int_t yc): fX(xc), fY(yc) { }
52  ~TGPosition() = default;
53 
54  Bool_t operator==(const TGPosition &b) const
55  { return ((fX == b.fX) && (fY == b.fY)); }
56  TGPosition operator-(const TGPosition &b) const
57  { return TGPosition(fX - b.fX, fY - b.fY); }
58  TGPosition operator+(const TGPosition &b) const
59  { return TGPosition(fX + b.fX, fY + b.fY); }
60 };
61 
62 
63 class TGLongPosition {
64 public:
65  Long_t fX; // x position
66  Long_t fY; // y position
67 
68  TGLongPosition(): fX(0), fY(0) { }
69  TGLongPosition(Long_t xc, Long_t yc): fX(xc), fY(yc) { }
70  ~TGLongPosition() = default;
71 
72  Bool_t operator==(const TGLongPosition &b) const
73  { return ((fX == b.fX) && (fY == b.fY)); }
74  TGLongPosition operator-(const TGLongPosition &b) const
75  { return TGLongPosition(fX - b.fX, fY - b.fY); }
76  TGLongPosition operator+(const TGLongPosition &b) const
77  { return TGLongPosition(fX + b.fX, fY + b.fY); }
78 };
79 
80 
81 class TGInsets {
82 public:
83  Int_t fL; // left
84  Int_t fR; // right
85  Int_t fT; // top
86  Int_t fB; // bottom
87 
88  TGInsets(): fL(0), fR(0), fT(0), fB(0) { }
89  TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt):
90  fL(lf), fR(rg), fT(tp), fB(bt) { }
91  ~TGInsets() = default;
92 
93  Bool_t operator==(const TGInsets &in) const
94  { return ((fL == in.fL) && (fR == in.fR) && (fT == in.fT) && (fB == in.fB)); }
95 };
96 
97 
98 class TGRectangle {
99 public:
100  Int_t fX; // x position
101  Int_t fY; // y position
102  UInt_t fW; // width
103  UInt_t fH; // height
104 
105  // constructors
106  TGRectangle(): fX(0), fY(0), fW(0), fH(0) { Empty(); }
107  TGRectangle(Int_t rx, Int_t ry, UInt_t rw, UInt_t rh):
108  fX(rx), fY(ry), fW(rw), fH(rh) { }
109  TGRectangle(const TGPosition &p, const TGDimension &d):
110  fX(p.fX), fY(p.fY), fW(d.fWidth), fH(d.fHeight) { }
111  ~TGRectangle() = default;
112 
113  // methods
114  Bool_t Contains(Int_t px, Int_t py) const
115  { return ((px >= fX) && (px < fX + (Int_t) fW) &&
116  (py >= fY) && (py < fY + (Int_t) fH)); }
117  Bool_t Contains(const TGPosition &p) const
118  { return ((p.fX >= fX) && (p.fX < fX + (Int_t) fW) &&
119  (p.fY >= fY) && (p.fY < fY + (Int_t) fH)); }
120  Bool_t Intersects(const TGRectangle &r) const
121  { return ((fX <= r.fX + (Int_t) r.fW - 1) && (fX + (Int_t) fW - 1 >= r.fX) &&
122  (fY <= r.fY + (Int_t) r.fH - 1) && (fY + (Int_t) fH - 1 >= r.fY)); }
123  Int_t Area() const
124  { return (fW * fH); }
125  TGDimension Size() const
126  { return TGDimension(fW, fH); }
127  TGPosition LeftTop() const
128  { return TGPosition(fX, fY); }
129  TGPosition RightBottom() const
130  { return TGPosition(fX + (Int_t) fW - 1, fY + (Int_t) fH - 1); }
131  void Merge(const TGRectangle &r);
132  void Empty() { fX = fY = 0; fW = fH = 0; }
133  Bool_t IsEmpty() const { return ((fW == 0) && (fH == 0)); }
134 };
135 
136 #endif