ROOT logo
// @(#)root/gui:$Id: TGProgressBar.h 23115 2008-04-10 13:35:37Z rdm $
// Author: Fons Rademakers   10/10/2000

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGProgressBar
#define ROOT_TGProgressBar


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGProgressBar, TGHProgressBar and TGVProgressBar                     //
//                                                                      //
// The classes in this file implement progress bars. Progress bars can  //
// be used to show progress of tasks taking more then a few seconds.    //
// TGProgressBar is an abstract base class, use either TGHProgressBar   //
// or TGVProgressBar. TGHProgressBar can in addition show the position  //
// as text in the bar.                                                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGFrame
#include "TGFrame.h"
#endif


class TGProgressBar : public TGFrame {

public:
   enum EBarType { kStandard, kFancy };
   enum EFillType { kSolidFill, kBlockFill };
   enum { kProgressBarStandardWidth = 16, kProgressBarTextWidth = 24,
          kBlockSize = 8, kBlockSpace = 2 };

protected:
   Float_t       fMin;          // logical minimum value (default 0)
   Float_t       fMax;          // logical maximum value (default 100)
   Float_t       fPos;          // logical position [fMin,fMax]
   Int_t         fPosPix;       // position of progress bar in pixel coordinates
   Int_t         fBarWidth;     // progress bar width
   EFillType     fFillType;     // *OPTION={GetMethod="GetFillType";SetMethod="SetFillType";Items=(kSolidFill=Solid",kBlockFill="Block")}*
   EBarType      fBarType;      // *OPTION={GetMethod="GetBarType";SetMethod="SetBarType";Items=(kStandard="Standard",kFancy="Fancy")}*
   TString       fFormat;       // format used to show position not in percent
   Bool_t        fShowPos;      // show position value (default false)
   Bool_t        fPercent;      // show position in percent (default true)
   Bool_t        fDrawBar;      // if true draw only bar in DoRedraw()
   TGGC          fBarColorGC;   // progress bar drawing context
   GContext_t    fNormGC;       // text drawing graphics context
   FontStruct_t  fFontStruct;   // font used to draw position text

   virtual void DoRedraw() = 0;

   static const TGFont *fgDefaultFont;
   static TGGC         *fgDefaultGC;

public:
   static FontStruct_t  GetDefaultFontStruct();
   static const TGGC   &GetDefaultGC();

   TGProgressBar(const TGWindow *p, UInt_t w, UInt_t h,
                 Pixel_t back = GetWhitePixel(),
                 Pixel_t barcolor = GetDefaultSelectedBackground(),
                 GContext_t norm = GetDefaultGC()(),
                 FontStruct_t font = GetDefaultFontStruct(),
                 UInt_t options = kDoubleBorder | kSunkenFrame);
   virtual ~TGProgressBar() { }

   Float_t      GetMin() const { return fMin; }
   Float_t      GetMax() const { return fMax; }
   Float_t      GetPosition() const { return fPos; }
   EFillType    GetFillType() const { return fFillType; }
   EBarType     GetBarType() const { return fBarType; }
   Bool_t       GetShowPos() const { return fShowPos; }
   TString      GetFormat() const { return fFormat; }
   const char*  GetValueFormat() const { return fFormat.Data(); }
   Bool_t       UsePercent() const { return fPercent; }
   Pixel_t      GetBarColor() const { return fBarColorGC.GetForeground(); }
   GContext_t   GetNormGC() const { return fNormGC; }
   FontStruct_t GetFontStruct() const { return fFontStruct; }

   void         SetPosition(Float_t pos);                //*MENU*  *GETTER=GetPosition
   void         SetRange(Float_t min, Float_t max);      //*MENU*
   void         Increment(Float_t inc);
   void         SetBarType(EBarType type);               //*SUBMENU*
   void         SetFillType(EFillType type);             //*SUBMENU*
   virtual void Percent(Bool_t on) { fPercent = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=UsePercent
   virtual void ShowPos(Bool_t on) { fShowPos = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=GetShowPos
   virtual void Format(const char *format = "%.2f");     //*MENU* *GETTER=GetValueFormat
   void         SetMin(Float_t min) { fMin = min; }
   void         SetMax(Float_t max) { fMax = max; }
   virtual void SetBarColor(Pixel_t color);
   void         SetBarColor(const char *color="blue");
   virtual void Reset();                                 //*MENU*
   virtual void SetForegroundColor(Pixel_t pixel);

   virtual void SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGProgressBar,0)  // Progress bar abstract base class
};


class TGHProgressBar : public TGProgressBar {

protected:
   virtual void DoRedraw();

public:
   TGHProgressBar(const TGWindow *p = 0,
                  UInt_t w = 4, UInt_t h = kProgressBarTextWidth,
                  Pixel_t back = GetWhitePixel(),
                  Pixel_t barcolor = GetDefaultSelectedBackground(),
                  GContext_t norm = GetDefaultGC()(),
                  FontStruct_t font = GetDefaultFontStruct(),
                  UInt_t options = kDoubleBorder | kSunkenFrame);
   TGHProgressBar(const TGWindow *p, EBarType type, UInt_t w);
   virtual ~TGHProgressBar() { }

   virtual TGDimension GetDefaultSize() const
                     { return TGDimension(fWidth, fBarWidth); }

   void ShowPosition(Bool_t set = kTRUE, Bool_t percent = kTRUE,
                     const char *format = "%.2f");

   virtual void SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGHProgressBar,0)  // Horizontal progress bar widget
};


class TGVProgressBar : public TGProgressBar {

protected:
   virtual void DoRedraw();

public:
   TGVProgressBar(const TGWindow *p = 0,
                  UInt_t w = kProgressBarTextWidth, UInt_t h = 4,
                  Pixel_t back = GetWhitePixel(),
                  Pixel_t barcolor = GetDefaultSelectedBackground(),
                  GContext_t norm = GetDefaultGC()(),
                  FontStruct_t font = GetDefaultFontStruct(),
                  UInt_t options = kDoubleBorder | kSunkenFrame);
   TGVProgressBar(const TGWindow *p, EBarType type, UInt_t h);
   virtual ~TGVProgressBar() { }

   virtual TGDimension GetDefaultSize() const
                     { return TGDimension(fBarWidth, fHeight); }
   virtual void SavePrimitive(ostream &out, Option_t *option = "");
   void ShowPos(Bool_t) { }
   void Percent(Bool_t) { }

   ClassDef(TGVProgressBar,0)  // Vertical progress bar widget
};

#endif

 TGProgressBar.h:1
 TGProgressBar.h:2
 TGProgressBar.h:3
 TGProgressBar.h:4
 TGProgressBar.h:5
 TGProgressBar.h:6
 TGProgressBar.h:7
 TGProgressBar.h:8
 TGProgressBar.h:9
 TGProgressBar.h:10
 TGProgressBar.h:11
 TGProgressBar.h:12
 TGProgressBar.h:13
 TGProgressBar.h:14
 TGProgressBar.h:15
 TGProgressBar.h:16
 TGProgressBar.h:17
 TGProgressBar.h:18
 TGProgressBar.h:19
 TGProgressBar.h:20
 TGProgressBar.h:21
 TGProgressBar.h:22
 TGProgressBar.h:23
 TGProgressBar.h:24
 TGProgressBar.h:25
 TGProgressBar.h:26
 TGProgressBar.h:27
 TGProgressBar.h:28
 TGProgressBar.h:29
 TGProgressBar.h:30
 TGProgressBar.h:31
 TGProgressBar.h:32
 TGProgressBar.h:33
 TGProgressBar.h:34
 TGProgressBar.h:35
 TGProgressBar.h:36
 TGProgressBar.h:37
 TGProgressBar.h:38
 TGProgressBar.h:39
 TGProgressBar.h:40
 TGProgressBar.h:41
 TGProgressBar.h:42
 TGProgressBar.h:43
 TGProgressBar.h:44
 TGProgressBar.h:45
 TGProgressBar.h:46
 TGProgressBar.h:47
 TGProgressBar.h:48
 TGProgressBar.h:49
 TGProgressBar.h:50
 TGProgressBar.h:51
 TGProgressBar.h:52
 TGProgressBar.h:53
 TGProgressBar.h:54
 TGProgressBar.h:55
 TGProgressBar.h:56
 TGProgressBar.h:57
 TGProgressBar.h:58
 TGProgressBar.h:59
 TGProgressBar.h:60
 TGProgressBar.h:61
 TGProgressBar.h:62
 TGProgressBar.h:63
 TGProgressBar.h:64
 TGProgressBar.h:65
 TGProgressBar.h:66
 TGProgressBar.h:67
 TGProgressBar.h:68
 TGProgressBar.h:69
 TGProgressBar.h:70
 TGProgressBar.h:71
 TGProgressBar.h:72
 TGProgressBar.h:73
 TGProgressBar.h:74
 TGProgressBar.h:75
 TGProgressBar.h:76
 TGProgressBar.h:77
 TGProgressBar.h:78
 TGProgressBar.h:79
 TGProgressBar.h:80
 TGProgressBar.h:81
 TGProgressBar.h:82
 TGProgressBar.h:83
 TGProgressBar.h:84
 TGProgressBar.h:85
 TGProgressBar.h:86
 TGProgressBar.h:87
 TGProgressBar.h:88
 TGProgressBar.h:89
 TGProgressBar.h:90
 TGProgressBar.h:91
 TGProgressBar.h:92
 TGProgressBar.h:93
 TGProgressBar.h:94
 TGProgressBar.h:95
 TGProgressBar.h:96
 TGProgressBar.h:97
 TGProgressBar.h:98
 TGProgressBar.h:99
 TGProgressBar.h:100
 TGProgressBar.h:101
 TGProgressBar.h:102
 TGProgressBar.h:103
 TGProgressBar.h:104
 TGProgressBar.h:105
 TGProgressBar.h:106
 TGProgressBar.h:107
 TGProgressBar.h:108
 TGProgressBar.h:109
 TGProgressBar.h:110
 TGProgressBar.h:111
 TGProgressBar.h:112
 TGProgressBar.h:113
 TGProgressBar.h:114
 TGProgressBar.h:115
 TGProgressBar.h:116
 TGProgressBar.h:117
 TGProgressBar.h:118
 TGProgressBar.h:119
 TGProgressBar.h:120
 TGProgressBar.h:121
 TGProgressBar.h:122
 TGProgressBar.h:123
 TGProgressBar.h:124
 TGProgressBar.h:125
 TGProgressBar.h:126
 TGProgressBar.h:127
 TGProgressBar.h:128
 TGProgressBar.h:129
 TGProgressBar.h:130
 TGProgressBar.h:131
 TGProgressBar.h:132
 TGProgressBar.h:133
 TGProgressBar.h:134
 TGProgressBar.h:135
 TGProgressBar.h:136
 TGProgressBar.h:137
 TGProgressBar.h:138
 TGProgressBar.h:139
 TGProgressBar.h:140
 TGProgressBar.h:141
 TGProgressBar.h:142
 TGProgressBar.h:143
 TGProgressBar.h:144
 TGProgressBar.h:145
 TGProgressBar.h:146
 TGProgressBar.h:147
 TGProgressBar.h:148
 TGProgressBar.h:149
 TGProgressBar.h:150
 TGProgressBar.h:151
 TGProgressBar.h:152
 TGProgressBar.h:153
 TGProgressBar.h:154
 TGProgressBar.h:155
 TGProgressBar.h:156
 TGProgressBar.h:157
 TGProgressBar.h:158
 TGProgressBar.h:159
 TGProgressBar.h:160
 TGProgressBar.h:161
 TGProgressBar.h:162