Logo ROOT  
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-2021, 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 
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&) = delete;
120  TGImageMap& operator=(const TGImageMap&) = delete;
121 
122 public:
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 = nullptr, const TGPicture *pic = nullptr);
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 
144  void AddRegion(const TGRegion &region, 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::GetPosition
TGPosition GetPosition() const
Return position of region (x, y).
Definition: TGImageMap.cxx:302
n
const Int_t n
Definition: legend1.C:16
TArrayS
Array of shorts (16 bits per element).
Definition: TArrayS.h:27
TGImageMap::HandleDoubleClick
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click events.
Definition: TGImageMap.cxx:553
TGRegion::operator-
TGRegion operator-(const TGRegion &r) const
Definition: TGImageMap.h:68
TGRegion::fData
TGRegionData * fData
Definition: TGImageMap.h:38
TGWindow
Definition: TGWindow.h:31
TGImageMap::kNavRegions
@ kNavRegions
Definition: TGImageMap.h:123
TGRegion::operator^
TGRegion operator^(const TGRegion &r) const
Definition: TGImageMap.h:69
TGImageMap::fListOfRegions
TList * fListOfRegions
Definition: TGImageMap.h:126
TGPicture
Definition: TGPicture.h:36
TGImageMap::AddRegion
void AddRegion(const TGRegion &region, Int_t id)
Add a region to the image map.
Definition: TGImageMap.cxx:476
TGDimension
Definition: TGDimension.h:27
TGImageMap::fMainTip
TGToolTip * fMainTip
Definition: TGImageMap.h:131
TGImageMap::GetNavMode
ENavMode GetNavMode()
Definition: TGImageMap.h:143
ECursor
ECursor
Definition: GuiTypes.h:372
TGRegion::CopyRegion
TGRegion CopyRegion() const
Copy a region.
Definition: TGImageMap.cxx:209
TGImageMap::SetCursor
void SetCursor(ECursor cursor=kHand)
Definition: TGImageMap.h:150
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TGRegionWithId::fTip
TGToolTip * fTip
Definition: TGImageMap.h:91
TGRegionWithId::operator=
TGRegionWithId & operator=(const TGRegionWithId &)=delete
TGRegion::~TGRegion
virtual ~TGRegion()
Delete a region.
Definition: TGImageMap.cxx:180
TGRegion::GetDimension
TGDimension GetDimension() const
Return dimension of region (widht, height).
Definition: TGImageMap.cxx:292
TGRegionWithId::GetId
Int_t GetId() const
Definition: TGImageMap.h:103
Int_t
int Int_t
Definition: RtypesCore.h:45
TGRegion
Definition: TGImageMap.h:35
TGImageMap::kNavGrid
@ kNavGrid
Definition: TGImageMap.h:123
TGDimension.h
TGRegion::operator&=
TGRegion & operator&=(const TGRegion &r)
Definition: TGImageMap.h:72
TGRegion::operator|=
TGRegion & operator|=(const TGRegion &r)
Definition: TGImageMap.h:70
x
Double_t x[n]
Definition: legend1.C:17
TGRegion::operator=
TGRegion & operator=(const TGRegion &r)
Region assignment operator.
Definition: TGImageMap.cxx:191
TGRegionWithId::fPopup
TGPopupMenu * fPopup
Definition: TGImageMap.h:92
TGToolTip
Definition: TGToolTip.h:35
TGRegion::operator==
Bool_t operator==(const TGRegion &r) const
Region == operator.
Definition: TGImageMap.cxx:312
TGImageMap::SetPicture
void SetPicture(const TGPicture *)
Change a picture in a picture button.
Definition: TGImageMap.h:151
TGImageMap::fCursorMouseOut
ECursor fCursorMouseOut
Definition: TGImageMap.h:129
TString
Basic string class.
Definition: TString.h:136
TGImageMap::fCursorMouseOver
ECursor fCursorMouseOver
Definition: TGImageMap.h:128
TGFrame
Definition: TGFrame.h:104
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
text
TText * text
Definition: entrylist_figure1.C:10
TGRegionWithId::TGRegionWithId
TGRegionWithId()
Create GUI region (with id and possible tooltip).
Definition: TGImageMap.cxx:323
TGRegion::operator-=
TGRegion & operator-=(const TGRegion &r)
Definition: TGImageMap.h:73
bool
TGRegion::Eor
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:282
TGRegionWithId::fId
Int_t fId
Definition: TGImageMap.h:90
TGRegion::operator+
TGRegion operator+(const TGRegion &r) const
Definition: TGImageMap.h:66
TGRegion::operator&
TGRegion operator&(const TGRegion &r) const
Definition: TGImageMap.h:67
TGRegion::Subtract
TGRegion Subtract(const TGRegion &r) const
Returns a region which is r subtracted from this region.
Definition: TGImageMap.cxx:271
TGImageMap::RegionClicked
virtual void RegionClicked(Int_t id)
Handle when mouse was clicked on region id.
Definition: TGImageMap.cxx:664
TGRegionWithId::~TGRegionWithId
virtual ~TGRegionWithId()
Cleanup.
Definition: TGImageMap.cxx:378
gCurrentRegion
R__EXTERN TGRegionWithId * gCurrentRegion
Definition: TGImageMap.h:162
h
#define h(i)
Definition: RSha256.hxx:106
TGImageMap::ENavMode
ENavMode
Definition: TGImageMap.h:123
TGRegion::operator!=
Bool_t operator!=(const TGRegion &r) const
Definition: TGImageMap.h:76
TGImageMap::fLastVisited
Int_t fLastVisited
Definition: TGImageMap.h:130
TGRegion::Intersect
TGRegion Intersect(const TGRegion &r) const
Returns a region which is the intersection of this region and r.
Definition: TGImageMap.cxx:261
TGRegion::Contains
Bool_t Contains(const TPoint &p) const
Return true if point p is contained in the region.
Definition: TGImageMap.cxx:235
TGRegion::kEllipse
@ kEllipse
Definition: TGImageMap.h:44
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGRegionWithId::SetPopup
void SetPopup(TGPopupMenu *popup)
Definition: TGImageMap.h:108
Long_t
long Long_t
Definition: RtypesCore.h:54
TGImageMap::GetPopup
TGPopupMenu * GetPopup(Int_t id)
Return popup for regions with specified id.
Definition: TGImageMap.cxx:507
TGImageMap::SetToolTipText
void SetToolTipText(const char *text, Long_t delayms=300)
Set tooltip text for main region.
Definition: TGImageMap.cxx:613
TGRegion::TGRegion
TGRegion()
Create a region object.
Definition: TGImageMap.cxx:75
TGRegionWithId::SetToolTipText
void SetToolTipText(const char *text, Long_t delayms, const TGFrame *frame)
Set tool tip text associated with this region.
Definition: TGImageMap.cxx:396
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGImageMap::fNavMode
ENavMode fNavMode
Definition: TGImageMap.h:127
y
Double_t y[n]
Definition: legend1.C:17
TGRegionWithId::DisplayPopup
void DisplayPopup()
Display popup menu associated with this region.
Definition: TGImageMap.cxx:386
TGRegionWithId
Definition: TGImageMap.h:83
TGImageMap::TGImageMap
TGImageMap(const TGImageMap &)=delete
kHand
@ kHand
Definition: GuiTypes.h:374
unsigned int
TGRegionWithId::GetToolTipText
TGToolTip * GetToolTipText() const
Definition: TGImageMap.h:104
TGRegion::IsEmpty
Bool_t IsEmpty() const
Return true if region is empty.
Definition: TGImageMap.cxx:227
TGImageMap
Definition: TGImageMap.h:115
TGImageMap::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle button events.
Definition: TGImageMap.cxx:579
TGRegionWithId::GetPopup
TGPopupMenu * GetPopup() const
Definition: TGImageMap.h:107
TPoint
Definition: TPoint.h:31
TGRegion::operator+=
TGRegion & operator+=(const TGRegion &r)
Definition: TGImageMap.h:71
TGPictureButton
Definition: TGButton.h:228
TGImageMap::OnMouseOut
virtual void OnMouseOut(Int_t id)
Handle when mouse moves from region id.
Definition: TGImageMap.cxx:652
TGRegion::kRectangle
@ kRectangle
Definition: TGImageMap.h:44
points
point * points
Definition: X3DBuffer.c:22
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TGImageMap::fTrash
TList * fTrash
Definition: TGImageMap.h:132
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
TGPopupMenu
Definition: TGMenu.h:123
Event_t
Event structure.
Definition: GuiTypes.h:174
TGRegion::Unite
TGRegion Unite(const TGRegion &r) const
Return the union of this region with r.
Definition: TGImageMap.cxx:251
TGRegion::operator|
TGRegion operator|(const TGRegion &r) const
Definition: TGImageMap.h:65
R__EXTERN
#define R__EXTERN
Definition: DllImport.h:27
TGImageMap::OnMouseOver
virtual void OnMouseOver(Int_t id)
Handle when mouse moves over region id.
Definition: TGImageMap.cxx:640
TPoint.h
TGImageMap::~TGImageMap
virtual ~TGImageMap()
Cleanup image map widget.
Definition: TGImageMap.cxx:464
TGImageMap::operator=
TGImageMap & operator=(const TGImageMap &)=delete
TGPosition
Definition: TGDimension.h:45
TGImageMap::CreatePopup
TGPopupMenu * CreatePopup(Int_t id)
Create popoup menu or returns existing for regions with specified id.
Definition: TGImageMap.cxx:484
TGRegion::operator^=
TGRegion & operator^=(const TGRegion &r)
Definition: TGImageMap.h:74
TList
A doubly linked list.
Definition: TList.h:44
TGImageMap::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion events.
Definition: TGImageMap.cxx:521
TGRegion::IsNull
Bool_t IsNull() const
Return true if region is not set.
Definition: TGImageMap.cxx:219
TGRegion::ERegionType
ERegionType
Definition: TGImageMap.h:44
TGImageMap::DoubleClicked
virtual void DoubleClicked()
Handle when mouse is double clicked on main map.
Definition: TGImageMap.cxx:673
int