TGProgressBar.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGProgressBar.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Fons Rademakers   10/10/2000
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGProgressBar
00013 #define ROOT_TGProgressBar
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGProgressBar, TGHProgressBar and TGVProgressBar                     //
00019 //                                                                      //
00020 // The classes in this file implement progress bars. Progress bars can  //
00021 // be used to show progress of tasks taking more then a few seconds.    //
00022 // TGProgressBar is an abstract base class, use either TGHProgressBar   //
00023 // or TGVProgressBar. TGHProgressBar can in addition show the position  //
00024 // as text in the bar.                                                  //
00025 //                                                                      //
00026 //////////////////////////////////////////////////////////////////////////
00027 
00028 #ifndef ROOT_TGFrame
00029 #include "TGFrame.h"
00030 #endif
00031 
00032 
00033 class TGProgressBar : public TGFrame {
00034 
00035 public:
00036    enum EBarType { kStandard, kFancy };
00037    enum EFillType { kSolidFill, kBlockFill };
00038    enum { kProgressBarStandardWidth = 16, kProgressBarTextWidth = 24,
00039           kBlockSize = 8, kBlockSpace = 2 };
00040 
00041 protected:
00042    Float_t       fMin;          // logical minimum value (default 0)
00043    Float_t       fMax;          // logical maximum value (default 100)
00044    Float_t       fPos;          // logical position [fMin,fMax]
00045    Int_t         fPosPix;       // position of progress bar in pixel coordinates
00046    Int_t         fBarWidth;     // progress bar width
00047    EFillType     fFillType;     // *OPTION={GetMethod="GetFillType";SetMethod="SetFillType";Items=(kSolidFill=Solid",kBlockFill="Block")}*
00048    EBarType      fBarType;      // *OPTION={GetMethod="GetBarType";SetMethod="SetBarType";Items=(kStandard="Standard",kFancy="Fancy")}*
00049    TString       fFormat;       // format used to show position not in percent
00050    Bool_t        fShowPos;      // show position value (default false)
00051    Bool_t        fPercent;      // show position in percent (default true)
00052    Bool_t        fDrawBar;      // if true draw only bar in DoRedraw()
00053    TGGC          fBarColorGC;   // progress bar drawing context
00054    GContext_t    fNormGC;       // text drawing graphics context
00055    FontStruct_t  fFontStruct;   // font used to draw position text
00056 
00057    virtual void DoRedraw() = 0;
00058 
00059    static const TGFont *fgDefaultFont;
00060    static TGGC         *fgDefaultGC;
00061 
00062 public:
00063    static FontStruct_t  GetDefaultFontStruct();
00064    static const TGGC   &GetDefaultGC();
00065 
00066    TGProgressBar(const TGWindow *p, UInt_t w, UInt_t h,
00067                  Pixel_t back = GetWhitePixel(),
00068                  Pixel_t barcolor = GetDefaultSelectedBackground(),
00069                  GContext_t norm = GetDefaultGC()(),
00070                  FontStruct_t font = GetDefaultFontStruct(),
00071                  UInt_t options = kDoubleBorder | kSunkenFrame);
00072    virtual ~TGProgressBar() { }
00073 
00074    Float_t      GetMin() const { return fMin; }
00075    Float_t      GetMax() const { return fMax; }
00076    Float_t      GetPosition() const { return fPos; }
00077    EFillType    GetFillType() const { return fFillType; }
00078    EBarType     GetBarType() const { return fBarType; }
00079    Bool_t       GetShowPos() const { return fShowPos; }
00080    TString      GetFormat() const { return fFormat; }
00081    const char*  GetValueFormat() const { return fFormat.Data(); }
00082    Bool_t       UsePercent() const { return fPercent; }
00083    Pixel_t      GetBarColor() const { return fBarColorGC.GetForeground(); }
00084    GContext_t   GetNormGC() const { return fNormGC; }
00085    FontStruct_t GetFontStruct() const { return fFontStruct; }
00086 
00087    void         SetPosition(Float_t pos);                //*MENU*  *GETTER=GetPosition
00088    void         SetRange(Float_t min, Float_t max);      //*MENU*
00089    void         Increment(Float_t inc);
00090    void         SetBarType(EBarType type);               //*SUBMENU*
00091    void         SetFillType(EFillType type);             //*SUBMENU*
00092    virtual void Percent(Bool_t on) { fPercent = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=UsePercent
00093    virtual void ShowPos(Bool_t on) { fShowPos = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=GetShowPos
00094    virtual void Format(const char *format = "%.2f");     //*MENU* *GETTER=GetValueFormat
00095    void         SetMin(Float_t min) { fMin = min; }
00096    void         SetMax(Float_t max) { fMax = max; }
00097    virtual void SetBarColor(Pixel_t color);
00098    void         SetBarColor(const char *color="blue");
00099    virtual void Reset();                                 //*MENU*
00100    virtual void SetForegroundColor(Pixel_t pixel);
00101 
00102    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00103 
00104    ClassDef(TGProgressBar,0)  // Progress bar abstract base class
00105 };
00106 
00107 
00108 class TGHProgressBar : public TGProgressBar {
00109 
00110 protected:
00111    virtual void DoRedraw();
00112 
00113 public:
00114    TGHProgressBar(const TGWindow *p = 0,
00115                   UInt_t w = 4, UInt_t h = kProgressBarTextWidth,
00116                   Pixel_t back = GetWhitePixel(),
00117                   Pixel_t barcolor = GetDefaultSelectedBackground(),
00118                   GContext_t norm = GetDefaultGC()(),
00119                   FontStruct_t font = GetDefaultFontStruct(),
00120                   UInt_t options = kDoubleBorder | kSunkenFrame);
00121    TGHProgressBar(const TGWindow *p, EBarType type, UInt_t w);
00122    virtual ~TGHProgressBar() { }
00123 
00124    virtual TGDimension GetDefaultSize() const
00125                      { return TGDimension(fWidth, fBarWidth); }
00126 
00127    void ShowPosition(Bool_t set = kTRUE, Bool_t percent = kTRUE,
00128                      const char *format = "%.2f");
00129 
00130    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00131 
00132    ClassDef(TGHProgressBar,0)  // Horizontal progress bar widget
00133 };
00134 
00135 
00136 class TGVProgressBar : public TGProgressBar {
00137 
00138 protected:
00139    virtual void DoRedraw();
00140 
00141 public:
00142    TGVProgressBar(const TGWindow *p = 0,
00143                   UInt_t w = kProgressBarTextWidth, UInt_t h = 4,
00144                   Pixel_t back = GetWhitePixel(),
00145                   Pixel_t barcolor = GetDefaultSelectedBackground(),
00146                   GContext_t norm = GetDefaultGC()(),
00147                   FontStruct_t font = GetDefaultFontStruct(),
00148                   UInt_t options = kDoubleBorder | kSunkenFrame);
00149    TGVProgressBar(const TGWindow *p, EBarType type, UInt_t h);
00150    virtual ~TGVProgressBar() { }
00151 
00152    virtual TGDimension GetDefaultSize() const
00153                      { return TGDimension(fBarWidth, fHeight); }
00154    virtual void SavePrimitive(ostream &out, Option_t *option = "");
00155    void ShowPos(Bool_t) { }
00156    void Percent(Bool_t) { }
00157 
00158    ClassDef(TGVProgressBar,0)  // Vertical progress bar widget
00159 };
00160 
00161 #endif
00162 

Generated on Tue Jul 5 14:20:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1