Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
40  TGRegion(Bool_t);
41  TGRegion CopyRegion() const;
42 
43 public:
44  enum ERegionType { kRectangle, kEllipse };
45 
46  TGRegion();
47  TGRegion(Int_t x, Int_t y, UInt_t w, UInt_t h, ERegionType = kRectangle);
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:
95  TGRegionWithId();
96  TGRegionWithId(Int_t id, Int_t x, Int_t y, UInt_t w, UInt_t h,
97  ERegionType = kRectangle);
98  TGRegionWithId(Int_t id, Int_t n, TPoint *points, Bool_t winding = kFALSE);
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 
162 R__EXTERN TGRegionWithId *gCurrentRegion;
163 
164 #endif