Logo ROOT   6.14/05
Reference Guide
TGImageMap.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Valeriy Onuchin & Fons Rademakers 18/10/2000
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_TGImageMap
13 #define ROOT_TGImageMap
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TGImageMap (with TGRegion and TGRegionWithId help classes) //
18 // //
19 // A TGImageMap provides the functionality like a clickable image in //
20 // a web browser with sensitive regions (MAP HTML tag). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TGButton.h"
25 #include "TPoint.h"
26 #include "TGDimension.h"
27 
28 
29 class TGRegionData;
30 class TGPopupMenu;
31 class TGToolTip;
32 class TArrayS;
33 
34 
35 class TGRegion : public TObject {
36 
37 protected:
38  TGRegionData *fData; // data describing region
39 
41  TGRegion CopyRegion() const;
42 
43 public:
45 
46  TGRegion();
48  TGRegion(Int_t n, TPoint *points, Bool_t winding = kFALSE);
49  TGRegion(Int_t n, Int_t *x, Int_t *y, Bool_t winding = kFALSE);
50  TGRegion(const TArrayS &x, const TArrayS &y, Bool_t winding = kFALSE);
51  TGRegion(const TGRegion &reg);
52  virtual ~TGRegion();
53 
54  Bool_t Contains(const TPoint &p) const;
55  Bool_t Contains(Int_t x, Int_t y) const;
56  TGRegion Unite(const TGRegion &r) const;
57  TGRegion Intersect(const TGRegion &r) const;
58  TGRegion Subtract(const TGRegion &r) const;
59  TGRegion Eor(const TGRegion &r) const;
60  TGDimension GetDimension() const;
61  TGPosition GetPosition() const;
62  Bool_t IsNull() const;
63  Bool_t IsEmpty() const;
64 
65  TGRegion operator|(const TGRegion &r) const { return Unite(r); }
66  TGRegion operator+(const TGRegion &r) const { return Unite(r); }
67  TGRegion operator&(const TGRegion &r) const { return Intersect(r); }
68  TGRegion operator-(const TGRegion &r) const { return Subtract(r); }
69  TGRegion operator^(const TGRegion &r) const { return Eor(r); }
70  TGRegion& operator|=(const TGRegion &r) { return *this = *this | r; }
71  TGRegion& operator+=(const TGRegion &r) { return *this = *this + r; }
72  TGRegion& operator&=(const TGRegion &r) { return *this = *this & r; }
73  TGRegion& operator-=(const TGRegion &r) { return *this = *this - r; }
74  TGRegion& operator^=(const TGRegion &r) { return *this = *this ^ r; }
75  Bool_t operator==(const TGRegion &r) const;
76  Bool_t operator!=(const TGRegion &r) const { return !(operator==(r)); }
77  TGRegion &operator=(const TGRegion &r);
78 
79  ClassDef(TGRegion,0) // Describes a region
80 };
81 
82 
83 class TGRegionWithId : public TGRegion {
84 
85 private:
86 
87  TGRegionWithId& operator=(const TGRegionWithId&); // Not implemented
88 
89 protected:
90  Int_t fId; // region id
91  TGToolTip *fTip; // tooltip
92  TGPopupMenu *fPopup; // popup menu
93 
94 public:
99  TGRegionWithId(const TGRegionWithId &reg);
100  TGRegionWithId(const TGRegion &reg, Int_t id);
101  virtual ~TGRegionWithId();
102 
103  Int_t GetId() const { return fId; }
104  TGToolTip *GetToolTipText() const { return fTip; }
105  void SetToolTipText(const char *text, Long_t delayms,
106  const TGFrame *frame);
107  TGPopupMenu *GetPopup() const { return fPopup; }
108  void SetPopup(TGPopupMenu *popup) { fPopup = popup; }
109  void DisplayPopup();
110 
111  ClassDef(TGRegionWithId,0) // Region with id, tooltip text and popup menu
112 };
113 
114 
115 class TGImageMap : public TGPictureButton {
116 
117 private:
118 
119  TGImageMap(const TGImageMap&); // Not implemented
120  TGImageMap& operator=(const TGImageMap&); // Not implemented
121 
122 public:
123  enum ENavMode { kNavRegions, kNavGrid };
124 
125 protected:
126  TList *fListOfRegions; // list of regions
127  ENavMode fNavMode; // navigation mode
128  ECursor fCursorMouseOver; // cursor shape in regions
129  ECursor fCursorMouseOut; // cursor shape out of regions
130  Int_t fLastVisited; // id of the last visited region
131  TGToolTip *fMainTip; // tooltip text for main region
132  TList *fTrash; // collect all objects that need to be cleaned up
133 
134 public:
135  TGImageMap(const TGWindow *p = 0, const TGPicture *pic = 0);
136  TGImageMap(const TGWindow *p, const TString &pic);
137  virtual ~TGImageMap();
138 
139  virtual Bool_t HandleButton(Event_t *event);
140  virtual Bool_t HandleDoubleClick(Event_t *event);
141  virtual Bool_t HandleMotion(Event_t *event);
142 
143  ENavMode GetNavMode() { return fNavMode; }
144  void AddRegion(const TGRegion &region, Int_t id);
145  TGPopupMenu *CreatePopup(Int_t id);
146  TGPopupMenu *GetPopup(Int_t id);
147 
148  void SetToolTipText(const char *text, Long_t delayms = 300);
149  void SetToolTipText(Int_t id, const char *text, Long_t delayms = 300);
150  void SetCursor(ECursor cursor = kHand) { fCursorMouseOver = cursor; }
151  void SetPicture(const TGPicture * /*new_pic*/) { } // disabled
152 
153  virtual void RegionClicked(Int_t id); // *SIGNAL*
154  virtual void DoubleClicked(Int_t id); // *SIGNAL*
155  virtual void DoubleClicked(); // *SIGNAL*
156  virtual void OnMouseOver(Int_t id); // *SIGNAL*
157  virtual void OnMouseOut(Int_t id); // *SIGNAL*
158 
159  ClassDef(TGImageMap,0) // Clickable image (like MAP in HTML)
160 };
161 
163 
164 #endif
TGRegion CopyRegion() const
Copy a region.
Definition: TGImageMap.cxx:208
void SetCursor(ECursor cursor=kHand)
Definition: TGImageMap.h:150
TGRegion & operator-=(const TGRegion &r)
Definition: TGImageMap.h:73
TGRegion Eor(const TGRegion &r) const
Returns a region which is the difference between the union and intersection this region and r...
Definition: TGImageMap.cxx:281
TGRegion Subtract(const TGRegion &r) const
Returns a region which is r subtracted from this region.
Definition: TGImageMap.cxx:270
TList * fListOfRegions
Definition: TGImageMap.h:126
TList * fTrash
Definition: TGImageMap.h:132
TGRegion operator|(const TGRegion &r) const
Definition: TGImageMap.h:65
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual ~TGRegion()
Delete a region.
Definition: TGImageMap.cxx:179
TGRegion & operator^=(const TGRegion &r)
Definition: TGImageMap.h:74
R__EXTERN TGRegionWithId * gCurrentRegion
Definition: TGImageMap.h:162
ECursor
Definition: TVirtualX.h:44
TGToolTip * fTip
Definition: TGImageMap.h:91
ECursor fCursorMouseOver
Definition: TGImageMap.h:128
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:320
void SetPopup(TGPopupMenu *popup)
Definition: TGImageMap.h:108
TGRegion operator &(const TGRegion &r) const
Definition: TGImageMap.h:67
TGRegion()
Create a region object.
Definition: TGImageMap.cxx:74
TGRegion & operator &=(const TGRegion &r)
Definition: TGImageMap.h:72
TGPopupMenu * GetPopup() const
Definition: TGImageMap.h:107
TGRegion Unite(const TGRegion &r) const
Return the union of this region with r.
Definition: TGImageMap.cxx:250
TGRegion operator^(const TGRegion &r) const
Definition: TGImageMap.h:69
Bool_t Contains(const TPoint &p) const
Return true if point p is contained in the region.
Definition: TGImageMap.cxx:234
Definition: TPoint.h:31
A doubly linked list.
Definition: TList.h:44
point * points
Definition: X3DBuffer.c:20
TGRegion & operator=(const TGRegion &r)
Region assignment operator.
Definition: TGImageMap.cxx:190
Int_t fLastVisited
Definition: TGImageMap.h:130
TGRegion & operator|=(const TGRegion &r)
Definition: TGImageMap.h:70
TGPosition GetPosition() const
Return position of region (x, y).
Definition: TGImageMap.cxx:301
TGRegion & operator+=(const TGRegion &r)
Definition: TGImageMap.h:71
ROOT::R::TRInterface & r
Definition: Object.C:4
void SetPicture(const TGPicture *)
Change a picture in a picture button.
Definition: TGImageMap.h:151
Array of shorts (16 bits per element).
Definition: TArrayS.h:27
Bool_t IsNull() const
Return true if region is not set.
Definition: TGImageMap.cxx:218
Int_t GetId() const
Definition: TGImageMap.h:103
TGRegion operator+(const TGRegion &r) const
Definition: TGImageMap.h:66
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t operator==(const TGRegion &r) const
Region == operator.
Definition: TGImageMap.cxx:311
TGPopupMenu * fPopup
Definition: TGImageMap.h:92
ENavMode fNavMode
Definition: TGImageMap.h:127
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:88
ECursor fCursorMouseOut
Definition: TGImageMap.h:129
TGRegionData * fData
Definition: TGImageMap.h:38
long Long_t
Definition: RtypesCore.h:50
Bool_t operator!=(const TGRegion &r) const
Definition: TGImageMap.h:76
TText * text
Double_t y[n]
Definition: legend1.C:17
TGToolTip * fMainTip
Definition: TGImageMap.h:131
TGDimension GetDimension() const
Return dimension of region (widht, height).
Definition: TGImageMap.cxx:291
Bool_t IsEmpty() const
Return true if region is empty.
Definition: TGImageMap.cxx:226
Mother of all ROOT objects.
Definition: TObject.h:37
TGRegion Intersect(const TGRegion &r) const
Returns a region which is the intersection of this region and r.
Definition: TGImageMap.cxx:260
#define R__EXTERN
Definition: DllImport.h:27
TGRegion operator-(const TGRegion &r) const
Definition: TGImageMap.h:68
ENavMode GetNavMode()
Definition: TGImageMap.h:143
TGToolTip * GetToolTipText() const
Definition: TGImageMap.h:104
const Int_t n
Definition: legend1.C:16