Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:57

0001 // @(#)root/gui:$Id$
0002 // Author: Valeriy Onuchin & Fons Rademakers   18/10/2000
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGImageMap
0013 #define ROOT_TGImageMap
0014 
0015 
0016 #include "TGButton.h"
0017 #include "TPoint.h"
0018 #include "TGDimension.h"
0019 
0020 
0021 class TGRegionData;
0022 class TGPopupMenu;
0023 class TGToolTip;
0024 class TArrayS;
0025 
0026 
0027 class TGRegion : public TObject {
0028 
0029 protected:
0030    TGRegionData   *fData;  // data describing region
0031 
0032    TGRegion(Bool_t);
0033    TGRegion CopyRegion() const;
0034 
0035 public:
0036    enum ERegionType { kRectangle, kEllipse };
0037 
0038    TGRegion();
0039    TGRegion(Int_t x, Int_t y, UInt_t w, UInt_t h, ERegionType = kRectangle);
0040    TGRegion(Int_t n, TPoint *points, Bool_t winding = kFALSE);
0041    TGRegion(Int_t n, Int_t *x, Int_t *y, Bool_t winding = kFALSE);
0042    TGRegion(const TArrayS &x, const TArrayS &y, Bool_t winding = kFALSE);
0043    TGRegion(const TGRegion &reg);
0044    ~TGRegion() override;
0045 
0046    Bool_t      Contains(const TPoint &p) const;
0047    Bool_t      Contains(Int_t x, Int_t y) const;
0048    TGRegion    Unite(const TGRegion &r) const;
0049    TGRegion    Intersect(const TGRegion &r) const;
0050    TGRegion    Subtract(const TGRegion &r) const;
0051    TGRegion    Eor(const TGRegion &r) const;
0052    TGDimension GetDimension() const;
0053    TGPosition  GetPosition() const;
0054    Bool_t      IsNull() const;
0055    Bool_t      IsEmpty() const;
0056 
0057    TGRegion operator|(const TGRegion &r) const { return Unite(r); }
0058    TGRegion operator+(const TGRegion &r) const { return Unite(r); }
0059    TGRegion operator&(const TGRegion &r) const { return Intersect(r); }
0060    TGRegion operator-(const TGRegion &r) const { return Subtract(r); }
0061    TGRegion operator^(const TGRegion &r) const { return Eor(r); }
0062    TGRegion& operator|=(const TGRegion &r) { return *this = *this | r; }
0063    TGRegion& operator+=(const TGRegion &r) { return *this = *this + r; }
0064    TGRegion& operator&=(const TGRegion &r) { return *this = *this & r; }
0065    TGRegion& operator-=(const TGRegion &r) { return *this = *this - r; }
0066    TGRegion& operator^=(const TGRegion &r) { return *this = *this ^ r; }
0067    Bool_t operator==(const TGRegion &r)  const;
0068    Bool_t operator!=(const TGRegion &r) const { return !(operator==(r)); }
0069    TGRegion &operator=(const TGRegion &r);
0070 
0071    ClassDefOverride(TGRegion,0) // Describes a region
0072 };
0073 
0074 
0075 class TGRegionWithId : public TGRegion {
0076 
0077 private:
0078 
0079    TGRegionWithId& operator=(const TGRegionWithId&) = delete;
0080 
0081 protected:
0082    Int_t         fId;      ///< region id
0083    TGToolTip    *fTip;     ///< tooltip
0084    TGPopupMenu  *fPopup;   ///< popup menu
0085 
0086 public:
0087    TGRegionWithId();
0088    TGRegionWithId(Int_t id, Int_t x, Int_t y, UInt_t w, UInt_t h,
0089                   ERegionType = kRectangle);
0090    TGRegionWithId(Int_t id, Int_t n, TPoint *points, Bool_t winding = kFALSE);
0091    TGRegionWithId(const TGRegionWithId &reg);
0092    TGRegionWithId(const TGRegion &reg, Int_t id);
0093    ~TGRegionWithId() override;
0094 
0095    Int_t        GetId() const { return fId; }
0096    TGToolTip   *GetToolTipText() const { return fTip; }
0097    void         SetToolTipText(const char *text, Long_t delayms,
0098                                const TGFrame *frame);
0099    TGPopupMenu *GetPopup() const { return fPopup; }
0100    void         SetPopup(TGPopupMenu *popup) { fPopup = popup; }
0101    void         DisplayPopup();
0102 
0103    ClassDefOverride(TGRegionWithId,0) // Region with id, tooltip text and popup menu
0104 };
0105 
0106 
0107 class TGImageMap : public TGPictureButton {
0108 
0109 private:
0110 
0111    TGImageMap(const TGImageMap&) = delete;
0112    TGImageMap& operator=(const TGImageMap&) = delete;
0113 
0114 public:
0115    enum ENavMode { kNavRegions, kNavGrid };
0116 
0117 protected:
0118    TList      *fListOfRegions;   ///< list of regions
0119    ENavMode    fNavMode;         ///< navigation mode
0120    ECursor     fCursorMouseOver; ///< cursor shape in regions
0121    ECursor     fCursorMouseOut;  ///< cursor shape out of regions
0122    Int_t       fLastVisited;     ///< id of the last visited region
0123    TGToolTip  *fMainTip;         ///< tooltip text for main region
0124    TList      *fTrash;           ///< collect all objects that need to be cleaned up
0125 
0126 public:
0127    TGImageMap(const TGWindow *p = nullptr, const TGPicture *pic = nullptr);
0128    TGImageMap(const TGWindow *p, const TString &pic);
0129    ~TGImageMap() override;
0130 
0131    Bool_t HandleButton(Event_t *event) override;
0132    Bool_t HandleDoubleClick(Event_t *event) override;
0133    Bool_t HandleMotion(Event_t *event) override;
0134 
0135    ENavMode       GetNavMode() { return fNavMode; }
0136    void           AddRegion(const TGRegion &region, Int_t id);
0137    TGPopupMenu   *CreatePopup(Int_t id);
0138    TGPopupMenu   *GetPopup(Int_t id);
0139 
0140    void SetToolTipText(const char *text, Long_t delayms = 300) override;
0141    void SetToolTipText(Int_t id, const char *text, Long_t delayms = 300);
0142    void SetCursor(ECursor cursor = kHand) { fCursorMouseOver = cursor; }
0143    void SetPicture(const TGPicture * /*new_pic*/) override { } // disabled
0144 
0145    virtual void RegionClicked(Int_t id); // *SIGNAL*
0146    virtual void DoubleClicked(Int_t id); // *SIGNAL*
0147    virtual void DoubleClicked();         // *SIGNAL*
0148    virtual void OnMouseOver(Int_t id);   // *SIGNAL*
0149    virtual void OnMouseOut(Int_t id);    // *SIGNAL*
0150 
0151    ClassDefOverride(TGImageMap,0)  // Clickable image (like MAP in HTML)
0152 };
0153 
0154 R__EXTERN TGRegionWithId *gCurrentRegion;
0155 
0156 #endif