// @(#)root/gui:$Id$
// Author: Fons Rademakers   02/01/98

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGDimension
#define ROOT_TGDimension

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGDimension, TGPosition, TGLongPosition, TGInsets and TGRectangle    //
//                                                                      //
// Several small geometry classes that implement dimensions             //
// (width and height), positions (x and y), insets and rectangles.      //
// They are trivial and their members are public.                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif

class TGDimension {
public:
   UInt_t  fWidth;       // width
   UInt_t  fHeight;      // height

   TGDimension(): fWidth(0), fHeight(0) { }
   TGDimension(UInt_t width, UInt_t height): fWidth(width), fHeight(height) { }
   TGDimension(const TGDimension &d): fWidth(d.fWidth), fHeight(d.fHeight) { }
   virtual ~TGDimension() { }

   Bool_t operator==(const TGDimension &b) const
      { return ((fWidth == b.fWidth) && (fHeight == b.fHeight)); }
   TGDimension operator-(const TGDimension &b) const
      { return TGDimension(fWidth - b.fWidth, fHeight - b.fHeight); }
   TGDimension operator+(const TGDimension &b) const
      { return TGDimension(fWidth + b.fWidth, fHeight + b.fHeight); }

   ClassDef(TGDimension,0)  // Dimension object (width, height)
};


class TGPosition {
public:
   Int_t  fX;         // x position
   Int_t  fY;         // y position

   TGPosition(): fX(0), fY(0) { }
   TGPosition(Int_t xc, Int_t yc): fX(xc), fY(yc) { }
   TGPosition(const TGPosition &p): fX(p.fX), fY(p.fY) { }
   virtual ~TGPosition() { }

   Bool_t operator==(const TGPosition &b) const
      { return ((fX == b.fX) && (fY == b.fY)); }
   TGPosition operator-(const TGPosition &b) const
      { return TGPosition(fX - b.fX, fY - b.fY); }
   TGPosition operator+(const TGPosition &b) const
      { return TGPosition(fX + b.fX, fY + b.fY); }

   ClassDef(TGPosition,0)  // Position object (x and y are Int_t)
};


class TGLongPosition {
public:
   Long_t  fX;         // x position
   Long_t  fY;         // y position

   TGLongPosition(): fX(0), fY(0) { }
   TGLongPosition(Long_t xc, Long_t yc): fX(xc), fY(yc) { }
   TGLongPosition(const TGLongPosition &p): fX(p.fX), fY(p.fY) { }
   virtual ~TGLongPosition() { }

   Bool_t operator==(const TGLongPosition &b) const
      { return ((fX == b.fX) && (fY == b.fY)); }
   TGLongPosition operator-(const TGLongPosition &b) const
      { return TGLongPosition(fX - b.fX, fY - b.fY); }
   TGLongPosition operator+(const TGLongPosition &b) const
      { return TGLongPosition(fX + b.fX, fY + b.fY); }

   ClassDef(TGLongPosition,0)  // Position object (x and y are Long_t)
};


class TGInsets {
public:
   Int_t  fL;    // left
   Int_t  fR;    // right
   Int_t  fT;    // top
   Int_t  fB;    // bottom

   TGInsets(): fL(0), fR(0), fT(0), fB(0) { }
   TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt):
      fL(lf), fR(rg), fT(tp), fB(bt) { }
   TGInsets(const TGInsets &in):
      fL(in.fL), fR(in.fR), fT(in.fT), fB(in.fB) { }
   virtual ~TGInsets() { }

   Bool_t operator==(const TGInsets &in) const
      { return ((fL == in.fL) && (fR == in.fR) && (fT == in.fT) && (fB == in.fB)); }

   ClassDef(TGInsets,0)   // Inset (left, right, top, bottom)
};


class TGRectangle {
public:
   Int_t         fX;    // x position
   Int_t         fY;    // y position
   UInt_t        fW;    // width
   UInt_t        fH;    // height

   // constructors
   TGRectangle(): fX(0), fY(0), fW(0), fH(0) { Empty(); }
   TGRectangle(Int_t rx, Int_t ry, UInt_t rw, UInt_t rh):
                fX(rx), fY(ry), fW(rw), fH(rh) { }
   TGRectangle(const TGPosition &p, const TGDimension &d):
                fX(p.fX), fY(p.fY), fW(d.fWidth), fH(d.fHeight) { }
   TGRectangle(const TGRectangle &r):
                fX(r.fX), fY(r.fY), fW(r.fW), fH(r.fH) { }
   virtual ~TGRectangle() { }

   // methods
   Bool_t Contains(Int_t px, Int_t py) const
                { return ((px >= fX) && (px < fX + (Int_t) fW) &&
                          (py >= fY) && (py < fY + (Int_t) fH)); }
   Bool_t Contains(const TGPosition &p) const
                { return ((p.fX >= fX) && (p.fX < fX + (Int_t) fW) &&
                          (p.fY >= fY) && (p.fY < fY + (Int_t) fH)); }
   Bool_t Intersects(const TGRectangle &r) const
                { return ((fX <= r.fX + (Int_t) r.fW - 1) && (fX + (Int_t) fW - 1 >= r.fX) &&
                          (fY <= r.fY + (Int_t) r.fH - 1) && (fY + (Int_t) fH - 1 >= r.fY)); }
   Int_t Area() const
                { return (fW * fH); }
   TGDimension Size() const
                { return TGDimension(fW, fH); }
   TGPosition LeftTop() const
                { return TGPosition(fX, fY); }
   TGPosition RightBottom() const
                { return TGPosition(fX + (Int_t) fW - 1, fY + (Int_t) fH - 1); }
   void Merge(const TGRectangle &r);
   void Empty() { fX = fY = 0; fW = fH = 0; }
   Bool_t IsEmpty() const { return ((fW == 0) && (fH == 0)); }

   ClassDef(TGRectangle, 0)  // Rectangle object
};

#endif
 TGDimension.h:1
 TGDimension.h:2
 TGDimension.h:3
 TGDimension.h:4
 TGDimension.h:5
 TGDimension.h:6
 TGDimension.h:7
 TGDimension.h:8
 TGDimension.h:9
 TGDimension.h:10
 TGDimension.h:11
 TGDimension.h:12
 TGDimension.h:13
 TGDimension.h:14
 TGDimension.h:15
 TGDimension.h:16
 TGDimension.h:17
 TGDimension.h:18
 TGDimension.h:19
 TGDimension.h:20
 TGDimension.h:21
 TGDimension.h:22
 TGDimension.h:23
 TGDimension.h:24
 TGDimension.h:25
 TGDimension.h:26
 TGDimension.h:27
 TGDimension.h:28
 TGDimension.h:29
 TGDimension.h:30
 TGDimension.h:31
 TGDimension.h:32
 TGDimension.h:33
 TGDimension.h:34
 TGDimension.h:35
 TGDimension.h:36
 TGDimension.h:37
 TGDimension.h:38
 TGDimension.h:39
 TGDimension.h:40
 TGDimension.h:41
 TGDimension.h:42
 TGDimension.h:43
 TGDimension.h:44
 TGDimension.h:45
 TGDimension.h:46
 TGDimension.h:47
 TGDimension.h:48
 TGDimension.h:49
 TGDimension.h:50
 TGDimension.h:51
 TGDimension.h:52
 TGDimension.h:53
 TGDimension.h:54
 TGDimension.h:55
 TGDimension.h:56
 TGDimension.h:57
 TGDimension.h:58
 TGDimension.h:59
 TGDimension.h:60
 TGDimension.h:61
 TGDimension.h:62
 TGDimension.h:63
 TGDimension.h:64
 TGDimension.h:65
 TGDimension.h:66
 TGDimension.h:67
 TGDimension.h:68
 TGDimension.h:69
 TGDimension.h:70
 TGDimension.h:71
 TGDimension.h:72
 TGDimension.h:73
 TGDimension.h:74
 TGDimension.h:75
 TGDimension.h:76
 TGDimension.h:77
 TGDimension.h:78
 TGDimension.h:79
 TGDimension.h:80
 TGDimension.h:81
 TGDimension.h:82
 TGDimension.h:83
 TGDimension.h:84
 TGDimension.h:85
 TGDimension.h:86
 TGDimension.h:87
 TGDimension.h:88
 TGDimension.h:89
 TGDimension.h:90
 TGDimension.h:91
 TGDimension.h:92
 TGDimension.h:93
 TGDimension.h:94
 TGDimension.h:95
 TGDimension.h:96
 TGDimension.h:97
 TGDimension.h:98
 TGDimension.h:99
 TGDimension.h:100
 TGDimension.h:101
 TGDimension.h:102
 TGDimension.h:103
 TGDimension.h:104
 TGDimension.h:105
 TGDimension.h:106
 TGDimension.h:107
 TGDimension.h:108
 TGDimension.h:109
 TGDimension.h:110
 TGDimension.h:111
 TGDimension.h:112
 TGDimension.h:113
 TGDimension.h:114
 TGDimension.h:115
 TGDimension.h:116
 TGDimension.h:117
 TGDimension.h:118
 TGDimension.h:119
 TGDimension.h:120
 TGDimension.h:121
 TGDimension.h:122
 TGDimension.h:123
 TGDimension.h:124
 TGDimension.h:125
 TGDimension.h:126
 TGDimension.h:127
 TGDimension.h:128
 TGDimension.h:129
 TGDimension.h:130
 TGDimension.h:131
 TGDimension.h:132
 TGDimension.h:133
 TGDimension.h:134
 TGDimension.h:135
 TGDimension.h:136
 TGDimension.h:137
 TGDimension.h:138
 TGDimension.h:139
 TGDimension.h:140
 TGDimension.h:141
 TGDimension.h:142
 TGDimension.h:143
 TGDimension.h:144
 TGDimension.h:145
 TGDimension.h:146
 TGDimension.h:147
 TGDimension.h:148
 TGDimension.h:149
 TGDimension.h:150
 TGDimension.h:151
 TGDimension.h:152
 TGDimension.h:153
 TGDimension.h:154
 TGDimension.h:155