Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:37:50

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,
0037 // clang++ <v20 (-Wshadow) complains about shadowing Buttons.h global enum EEditMode. Let's silence warning:
0038 #if defined(__clang__) && __clang_major__ < 20
0039 #pragma clang diagnostic push
0040 #pragma clang diagnostic ignored "-Wshadow"
0041 #endif
0042       kEllipse };
0043 #if defined(__clang__) && __clang_major__ < 20
0044 #pragma clang diagnostic pop
0045 #endif
0046 
0047    TGRegion();
0048    TGRegion(Int_t x, Int_t y, UInt_t w, UInt_t h, ERegionType = kRectangle);
0049    TGRegion(Int_t n, TPoint *points, Bool_t winding = kFALSE);
0050    TGRegion(Int_t n, Int_t *x, Int_t *y, Bool_t winding = kFALSE);
0051    TGRegion(const TArrayS &x, const TArrayS &y, Bool_t winding = kFALSE);
0052    TGRegion(const TGRegion &reg);
0053    ~TGRegion() override;
0054 
0055    Bool_t      Contains(const TPoint &p) const;
0056    Bool_t      Contains(Int_t x, Int_t y) const;
0057    TGRegion    Unite(const TGRegion &r) const;
0058    TGRegion    Intersect(const TGRegion &r) const;
0059    TGRegion    Subtract(const TGRegion &r) const;
0060    TGRegion    Eor(const TGRegion &r) const;
0061    TGDimension GetDimension() const;
0062    TGPosition  GetPosition() const;
0063    Bool_t      IsNull() const;
0064    Bool_t      IsEmpty() const;
0065 
0066    TGRegion operator|(const TGRegion &r) const { return Unite(r); }
0067    TGRegion operator+(const TGRegion &r) const { return Unite(r); }
0068    TGRegion operator&(const TGRegion &r) const { return Intersect(r); }
0069    TGRegion operator-(const TGRegion &r) const { return Subtract(r); }
0070    TGRegion operator^(const TGRegion &r) const { return Eor(r); }
0071    TGRegion& operator|=(const TGRegion &r) { return *this = *this | r; }
0072    TGRegion& operator+=(const TGRegion &r) { return *this = *this + r; }
0073    TGRegion& operator&=(const TGRegion &r) { return *this = *this & r; }
0074    TGRegion& operator-=(const TGRegion &r) { return *this = *this - r; }
0075    TGRegion& operator^=(const TGRegion &r) { return *this = *this ^ r; }
0076    Bool_t operator==(const TGRegion &r)  const;
0077    Bool_t operator!=(const TGRegion &r) const { return !(operator==(r)); }
0078    TGRegion &operator=(const TGRegion &r);
0079 
0080    ClassDefOverride(TGRegion,0) // Describes a region
0081 };
0082 
0083 
0084 class TGRegionWithId : public TGRegion {
0085 
0086 private:
0087 
0088    TGRegionWithId& operator=(const TGRegionWithId&) = delete;
0089 
0090 protected:
0091    Int_t         fId;      ///< region id
0092    TGToolTip    *fTip;     ///< tooltip
0093    TGPopupMenu  *fPopup;   ///< popup menu
0094 
0095 public:
0096    TGRegionWithId();
0097    TGRegionWithId(Int_t id, Int_t x, Int_t y, UInt_t w, UInt_t h,
0098                   ERegionType = kRectangle);
0099    TGRegionWithId(Int_t id, Int_t n, TPoint *points, Bool_t winding = kFALSE);
0100    TGRegionWithId(const TGRegionWithId &reg);
0101    TGRegionWithId(const TGRegion &reg, Int_t id);
0102    ~TGRegionWithId() override;
0103 
0104    Int_t        GetId() const { return fId; }
0105    TGToolTip   *GetToolTipText() const { return fTip; }
0106    void         SetToolTipText(const char *text, Long_t delayms,
0107                                const TGFrame *frame);
0108    TGPopupMenu *GetPopup() const { return fPopup; }
0109    void         SetPopup(TGPopupMenu *popup) { fPopup = popup; }
0110    void         DisplayPopup();
0111 
0112    ClassDefOverride(TGRegionWithId,0) // Region with id, tooltip text and popup menu
0113 };
0114 
0115 
0116 class TGImageMap : public TGPictureButton {
0117 
0118 private:
0119 
0120    TGImageMap(const TGImageMap&) = delete;
0121    TGImageMap& operator=(const TGImageMap&) = delete;
0122 
0123 public:
0124    enum ENavMode { kNavRegions, kNavGrid };
0125 
0126 protected:
0127    TList      *fListOfRegions;   ///< list of regions
0128    ENavMode    fNavMode;         ///< navigation mode
0129    ECursor     fCursorMouseOver; ///< cursor shape in regions
0130    ECursor     fCursorMouseOut;  ///< cursor shape out of regions
0131    Int_t       fLastVisited;     ///< id of the last visited region
0132    TGToolTip  *fMainTip;         ///< tooltip text for main region
0133    TList      *fTrash;           ///< collect all objects that need to be cleaned up
0134 
0135 public:
0136    TGImageMap(const TGWindow *p = nullptr, const TGPicture *pic = nullptr);
0137    TGImageMap(const TGWindow *p, const TString &pic);
0138    ~TGImageMap() override;
0139 
0140    Bool_t HandleButton(Event_t *event) override;
0141    Bool_t HandleDoubleClick(Event_t *event) override;
0142    Bool_t HandleMotion(Event_t *event) override;
0143 
0144    ENavMode       GetNavMode() { return fNavMode; }
0145    void           AddRegion(const TGRegion &region, Int_t id);
0146    TGPopupMenu   *CreatePopup(Int_t id);
0147    TGPopupMenu   *GetPopup(Int_t id);
0148 
0149    void SetToolTipText(const char *text, Long_t delayms = 300) override;
0150    void SetToolTipText(Int_t id, const char *text, Long_t delayms = 300);
0151    void SetCursor(ECursor cursor = kHand) { fCursorMouseOver = cursor; }
0152    void SetPicture(const TGPicture * /*new_pic*/) override { } // disabled
0153 
0154    virtual void RegionClicked(Int_t id); // *SIGNAL*
0155    virtual void DoubleClicked(Int_t id); // *SIGNAL*
0156    virtual void DoubleClicked();         // *SIGNAL*
0157    virtual void OnMouseOver(Int_t id);   // *SIGNAL*
0158    virtual void OnMouseOut(Int_t id);    // *SIGNAL*
0159 
0160    ClassDefOverride(TGImageMap,0)  // Clickable image (like MAP in HTML)
0161 };
0162 
0163 R__EXTERN TGRegionWithId *gCurrentRegion;
0164 
0165 #endif