Logo ROOT  
Reference Guide
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 "RtypesCore.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 
37  { return ((fWidth == b.fWidth) && (fHeight == b.fHeight)); }
39  { return TGDimension(fWidth - b.fWidth, fHeight - b.fHeight); }
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)); }
57  { return TGPosition(fX - b.fX, fY - b.fY); }
59  { return TGPosition(fX + b.fX, fY + b.fY); }
60 };
61 
62 
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 
73  { return ((fX == b.fX) && (fY == b.fY)); }
75  { return TGLongPosition(fX - b.fX, fY - b.fY); }
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(); }
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)); }
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); }
126  { return TGDimension(fW, fH); }
128  { return TGPosition(fX, fY); }
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
TGPosition::operator-
TGPosition operator-(const TGPosition &b) const
Definition: TGDimension.h:56
TGDimension::TGDimension
TGDimension(UInt_t width, UInt_t height)
Definition: TGDimension.h:33
TGPosition::fY
Int_t fY
Definition: TGDimension.h:48
TGLongPosition::operator==
Bool_t operator==(const TGLongPosition &b) const
Definition: TGDimension.h:72
TGDimension
Definition: TGDimension.h:27
TGRectangle::Size
TGDimension Size() const
Definition: TGDimension.h:125
TGInsets
Definition: TGDimension.h:81
TGRectangle::LeftTop
TGPosition LeftTop() const
Definition: TGDimension.h:127
TGRectangle::IsEmpty
Bool_t IsEmpty() const
Definition: TGDimension.h:133
TGPosition::TGPosition
TGPosition(Int_t xc, Int_t yc)
Definition: TGDimension.h:51
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TGPosition::TGPosition
TGPosition()
Definition: TGDimension.h:50
TGInsets::operator==
Bool_t operator==(const TGInsets &in) const
Definition: TGDimension.h:93
TGRectangle::TGRectangle
TGRectangle(Int_t rx, Int_t ry, UInt_t rw, UInt_t rh)
Definition: TGDimension.h:107
TGRectangle::Contains
Bool_t Contains(Int_t px, Int_t py) const
Definition: TGDimension.h:114
TGInsets::fT
Int_t fT
Definition: TGDimension.h:85
TGInsets::TGInsets
TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt)
Definition: TGDimension.h:89
TGLongPosition::fY
Long_t fY
Definition: TGDimension.h:66
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TGDimension::operator==
Bool_t operator==(const TGDimension &b) const
Definition: TGDimension.h:36
TGRectangle::fY
Int_t fY
Definition: TGDimension.h:101
TGInsets::fB
Int_t fB
Definition: TGDimension.h:86
TGLongPosition::TGLongPosition
TGLongPosition()
Definition: TGDimension.h:68
TGInsets::fR
Int_t fR
Definition: TGDimension.h:84
TGPosition::operator==
Bool_t operator==(const TGPosition &b) const
Definition: TGDimension.h:54
b
#define b(i)
Definition: RSha256.hxx:100
bool
TGPosition::operator+
TGPosition operator+(const TGPosition &b) const
Definition: TGDimension.h:58
TGRectangle::Contains
Bool_t Contains(const TGPosition &p) const
Definition: TGDimension.h:117
TGDimension::~TGDimension
~TGDimension()=default
TGDimension::operator+
TGDimension operator+(const TGDimension &b) const
Definition: TGDimension.h:40
TGRectangle
Definition: TGDimension.h:98
TGLongPosition::TGLongPosition
TGLongPosition(Long_t xc, Long_t yc)
Definition: TGDimension.h:69
TGInsets::~TGInsets
~TGInsets()=default
TGInsets::TGInsets
TGInsets()
Definition: TGDimension.h:88
TGLongPosition::operator+
TGLongPosition operator+(const TGLongPosition &b) const
Definition: TGDimension.h:76
TGPosition::fX
Int_t fX
Definition: TGDimension.h:47
TGDimension::fHeight
UInt_t fHeight
Definition: TGDimension.h:30
TGLongPosition::~TGLongPosition
~TGLongPosition()=default
TGRectangle::Intersects
Bool_t Intersects(const TGRectangle &r) const
Definition: TGDimension.h:120
TGInsets::fL
Int_t fL
Definition: TGDimension.h:83
TGLongPosition::fX
Long_t fX
Definition: TGDimension.h:65
TGLongPosition::operator-
TGLongPosition operator-(const TGLongPosition &b) const
Definition: TGDimension.h:74
Long_t
long Long_t
Definition: RtypesCore.h:54
TGDimension::fWidth
UInt_t fWidth
Definition: TGDimension.h:29
TGRectangle::fX
Int_t fX
Definition: TGDimension.h:100
TGDimension::TGDimension
TGDimension()
Definition: TGDimension.h:32
TGRectangle::Area
Int_t Area() const
Definition: TGDimension.h:123
TGRectangle::RightBottom
TGPosition RightBottom() const
Definition: TGDimension.h:129
unsigned int
TGLongPosition
Definition: TGDimension.h:63
TGRectangle::fW
UInt_t fW
Definition: TGDimension.h:102
TGRectangle::~TGRectangle
~TGRectangle()=default
TGPosition::~TGPosition
~TGPosition()=default
TGDimension::operator-
TGDimension operator-(const TGDimension &b) const
Definition: TGDimension.h:38
RtypesCore.h
TGRectangle::TGRectangle
TGRectangle(const TGPosition &p, const TGDimension &d)
Definition: TGDimension.h:109
d
#define d(i)
Definition: RSha256.hxx:102
TGRectangle::TGRectangle
TGRectangle()
Definition: TGDimension.h:106
TGRectangle::Empty
void Empty()
Definition: TGDimension.h:132
TGPosition
Definition: TGDimension.h:45
TGRectangle::fH
UInt_t fH
Definition: TGDimension.h:103
TGRectangle::Merge
void Merge(const TGRectangle &r)
Definition: TGDimension.cxx:36
int