Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:03

0001 // @(#)root/gui:$Id$
0002 // Author: Fons Rademakers   10/10/2000
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, 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_TGProgressBar
0013 #define ROOT_TGProgressBar
0014 
0015 
0016 #include "TGFrame.h"
0017 
0018 
0019 class TGProgressBar : public TGFrame {
0020 
0021 public:
0022    enum EBarType { kStandard, kFancy };
0023    enum EFillType { kSolidFill, kBlockFill };
0024    enum { kProgressBarStandardWidth = 16, kProgressBarTextWidth = 24,
0025           kBlockSize = 8, kBlockSpace = 2 };
0026 
0027 protected:
0028    Float_t       fMin;          ///< logical minimum value (default 0)
0029    Float_t       fMax;          ///< logical maximum value (default 100)
0030    Float_t       fPos;          ///< logical position [fMin,fMax]
0031    Int_t         fPosPix;       ///< position of progress bar in pixel coordinates
0032    Int_t         fBarWidth;     ///< progress bar width
0033    EFillType     fFillType;     ///< *OPTION={GetMethod="GetFillType";SetMethod="SetFillType";Items=(kSolidFill=Solid",kBlockFill="Block")}*
0034    EBarType      fBarType;      ///< *OPTION={GetMethod="GetBarType";SetMethod="SetBarType";Items=(kStandard="Standard",kFancy="Fancy")}*
0035    TString       fFormat;       ///< format used to show position not in percent
0036    Bool_t        fShowPos;      ///< show position value (default false)
0037    Bool_t        fPercent;      ///< show position in percent (default true)
0038    Bool_t        fDrawBar;      ///< if true draw only bar in DoRedraw()
0039    TGGC          fBarColorGC;   ///< progress bar drawing context
0040    GContext_t    fNormGC;       ///< text drawing graphics context
0041    FontStruct_t  fFontStruct;   ///< font used to draw position text
0042 
0043    void DoRedraw() override = 0;
0044 
0045    static const TGFont *fgDefaultFont;
0046    static TGGC         *fgDefaultGC;
0047 
0048 public:
0049    static FontStruct_t  GetDefaultFontStruct();
0050    static const TGGC   &GetDefaultGC();
0051 
0052    TGProgressBar(const TGWindow *p, UInt_t w, UInt_t h,
0053                  Pixel_t back = GetWhitePixel(),
0054                  Pixel_t barcolor = GetDefaultSelectedBackground(),
0055                  GContext_t norm = GetDefaultGC()(),
0056                  FontStruct_t font = GetDefaultFontStruct(),
0057                  UInt_t options = kDoubleBorder | kSunkenFrame);
0058    ~TGProgressBar() override { }
0059 
0060    Float_t      GetMin() const { return fMin; }
0061    Float_t      GetMax() const { return fMax; }
0062    Float_t      GetPosition() const { return fPos; }
0063    EFillType    GetFillType() const { return fFillType; }
0064    EBarType     GetBarType() const { return fBarType; }
0065    Bool_t       GetShowPos() const { return fShowPos; }
0066    TString      GetFormat() const { return fFormat; }
0067    const char*  GetValueFormat() const { return fFormat.Data(); }
0068    Bool_t       UsePercent() const { return fPercent; }
0069    Pixel_t      GetBarColor() const { return fBarColorGC.GetForeground(); }
0070    GContext_t   GetNormGC() const { return fNormGC; }
0071    FontStruct_t GetFontStruct() const { return fFontStruct; }
0072 
0073    void         SetPosition(Float_t pos);                //*MENU*  *GETTER=GetPosition
0074    void         SetRange(Float_t min, Float_t max);      //*MENU*
0075    void         Increment(Float_t inc);
0076    void         SetBarType(EBarType type);               //*SUBMENU*
0077    void         SetFillType(EFillType type);             //*SUBMENU*
0078    virtual void Percent(Bool_t on) { fPercent = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=UsePercent
0079    virtual void ShowPos(Bool_t on) { fShowPos = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=GetShowPos
0080    virtual void Format(const char *format = "%.2f");     //*MENU* *GETTER=GetValueFormat
0081    void         SetMin(Float_t min) { fMin = min; }
0082    void         SetMax(Float_t max) { fMax = max; }
0083    virtual void SetBarColor(Pixel_t color);
0084    void         SetBarColor(const char *color="blue");
0085    virtual void Reset();                                 //*MENU*
0086    void         SetForegroundColor(Pixel_t pixel) override;
0087 
0088    void         SavePrimitive(std::ostream &out, Option_t *option = "") override;
0089 
0090    ClassDefOverride(TGProgressBar,0)  // Progress bar abstract base class
0091 };
0092 
0093 
0094 class TGHProgressBar : public TGProgressBar {
0095 
0096 protected:
0097    void DoRedraw() override;
0098 
0099 public:
0100    TGHProgressBar(const TGWindow *p = nullptr,
0101                   UInt_t w = 4, UInt_t h = kProgressBarTextWidth,
0102                   Pixel_t back = GetWhitePixel(),
0103                   Pixel_t barcolor = GetDefaultSelectedBackground(),
0104                   GContext_t norm = GetDefaultGC()(),
0105                   FontStruct_t font = GetDefaultFontStruct(),
0106                   UInt_t options = kDoubleBorder | kSunkenFrame);
0107    TGHProgressBar(const TGWindow *p, EBarType type, UInt_t w);
0108    ~TGHProgressBar() override { }
0109 
0110    TGDimension GetDefaultSize() const override
0111                { return TGDimension(fWidth, fBarWidth); }
0112 
0113    void ShowPosition(Bool_t set = kTRUE, Bool_t percent = kTRUE,
0114                      const char *format = "%.2f");
0115 
0116    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0117 
0118    ClassDefOverride(TGHProgressBar,0)  // Horizontal progress bar widget
0119 };
0120 
0121 
0122 class TGVProgressBar : public TGProgressBar {
0123 
0124 protected:
0125    void DoRedraw() override;
0126 
0127 public:
0128    TGVProgressBar(const TGWindow *p = nullptr,
0129                   UInt_t w = kProgressBarTextWidth, UInt_t h = 4,
0130                   Pixel_t back = GetWhitePixel(),
0131                   Pixel_t barcolor = GetDefaultSelectedBackground(),
0132                   GContext_t norm = GetDefaultGC()(),
0133                   FontStruct_t font = GetDefaultFontStruct(),
0134                   UInt_t options = kDoubleBorder | kSunkenFrame);
0135    TGVProgressBar(const TGWindow *p, EBarType type, UInt_t h);
0136    ~TGVProgressBar() override { }
0137 
0138    TGDimension GetDefaultSize() const override
0139                 { return TGDimension(fBarWidth, fHeight); }
0140    void SavePrimitive(std::ostream &out, Option_t *option = "") override;
0141    void ShowPos(Bool_t) override { }
0142    void Percent(Bool_t) override { }
0143 
0144    ClassDefOverride(TGVProgressBar,0)  // Vertical progress bar widget
0145 };
0146 
0147 #endif
0148