Logo ROOT   6.12/07
Reference Guide
TGProgressBar.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 10/10/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGProgressBar
13 #define ROOT_TGProgressBar
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGProgressBar, TGHProgressBar and TGVProgressBar //
19 // //
20 // The classes in this file implement progress bars. Progress bars can //
21 // be used to show progress of tasks taking more then a few seconds. //
22 // TGProgressBar is an abstract base class, use either TGHProgressBar //
23 // or TGVProgressBar. TGHProgressBar can in addition show the position //
24 // as text in the bar. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TGFrame.h"
29 
30 
31 class TGProgressBar : public TGFrame {
32 
33 public:
37  kBlockSize = 8, kBlockSpace = 2 };
38 
39 protected:
40  Float_t fMin; // logical minimum value (default 0)
41  Float_t fMax; // logical maximum value (default 100)
42  Float_t fPos; // logical position [fMin,fMax]
43  Int_t fPosPix; // position of progress bar in pixel coordinates
44  Int_t fBarWidth; // progress bar width
45  EFillType fFillType; // *OPTION={GetMethod="GetFillType";SetMethod="SetFillType";Items=(kSolidFill=Solid",kBlockFill="Block")}*
46  EBarType fBarType; // *OPTION={GetMethod="GetBarType";SetMethod="SetBarType";Items=(kStandard="Standard",kFancy="Fancy")}*
47  TString fFormat; // format used to show position not in percent
48  Bool_t fShowPos; // show position value (default false)
49  Bool_t fPercent; // show position in percent (default true)
50  Bool_t fDrawBar; // if true draw only bar in DoRedraw()
51  TGGC fBarColorGC; // progress bar drawing context
52  GContext_t fNormGC; // text drawing graphics context
53  FontStruct_t fFontStruct; // font used to draw position text
54 
55  virtual void DoRedraw() = 0;
56 
57  static const TGFont *fgDefaultFont;
58  static TGGC *fgDefaultGC;
59 
60 public:
62  static const TGGC &GetDefaultGC();
63 
64  TGProgressBar(const TGWindow *p, UInt_t w, UInt_t h,
65  Pixel_t back = GetWhitePixel(),
67  GContext_t norm = GetDefaultGC()(),
69  UInt_t options = kDoubleBorder | kSunkenFrame);
70  virtual ~TGProgressBar() { }
71 
72  Float_t GetMin() const { return fMin; }
73  Float_t GetMax() const { return fMax; }
74  Float_t GetPosition() const { return fPos; }
75  EFillType GetFillType() const { return fFillType; }
76  EBarType GetBarType() const { return fBarType; }
77  Bool_t GetShowPos() const { return fShowPos; }
78  TString GetFormat() const { return fFormat; }
79  const char* GetValueFormat() const { return fFormat.Data(); }
80  Bool_t UsePercent() const { return fPercent; }
81  Pixel_t GetBarColor() const { return fBarColorGC.GetForeground(); }
82  GContext_t GetNormGC() const { return fNormGC; }
84 
85  void SetPosition(Float_t pos); //*MENU* *GETTER=GetPosition
86  void SetRange(Float_t min, Float_t max); //*MENU*
87  void Increment(Float_t inc);
88  void SetBarType(EBarType type); //*SUBMENU*
89  void SetFillType(EFillType type); //*SUBMENU*
90  virtual void Percent(Bool_t on) { fPercent = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=UsePercent
91  virtual void ShowPos(Bool_t on) { fShowPos = on; fClient->NeedRedraw(this); } //*TOGGLE* *GETTER=GetShowPos
92  virtual void Format(const char *format = "%.2f"); //*MENU* *GETTER=GetValueFormat
93  void SetMin(Float_t min) { fMin = min; }
94  void SetMax(Float_t max) { fMax = max; }
95  virtual void SetBarColor(Pixel_t color);
96  void SetBarColor(const char *color="blue");
97  virtual void Reset(); //*MENU*
98  virtual void SetForegroundColor(Pixel_t pixel);
99 
100  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
101 
102  ClassDef(TGProgressBar,0) // Progress bar abstract base class
103 };
104 
105 
107 
108 protected:
109  virtual void DoRedraw();
110 
111 public:
112  TGHProgressBar(const TGWindow *p = 0,
114  Pixel_t back = GetWhitePixel(),
116  GContext_t norm = GetDefaultGC()(),
118  UInt_t options = kDoubleBorder | kSunkenFrame);
120  virtual ~TGHProgressBar() { }
121 
122  virtual TGDimension GetDefaultSize() const
123  { return TGDimension(fWidth, fBarWidth); }
124 
125  void ShowPosition(Bool_t set = kTRUE, Bool_t percent = kTRUE,
126  const char *format = "%.2f");
127 
128  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
129 
130  ClassDef(TGHProgressBar,0) // Horizontal progress bar widget
131 };
132 
133 
135 
136 protected:
137  virtual void DoRedraw();
138 
139 public:
140  TGVProgressBar(const TGWindow *p = 0,
142  Pixel_t back = GetWhitePixel(),
144  GContext_t norm = GetDefaultGC()(),
146  UInt_t options = kDoubleBorder | kSunkenFrame);
148  virtual ~TGVProgressBar() { }
149 
150  virtual TGDimension GetDefaultSize() const
151  { return TGDimension(fBarWidth, fHeight); }
152  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
153  void ShowPos(Bool_t) { }
154  void Percent(Bool_t) { }
155 
156  ClassDef(TGVProgressBar,0) // Vertical progress bar widget
157 };
158 
159 #endif
160 
EBarType fBarType
Definition: TGProgressBar.h:46
virtual ~TGVProgressBar()
EBarType GetBarType() const
Definition: TGProgressBar.h:76
Handle_t FontStruct_t
Definition: GuiTypes.h:38
static const TGGC & GetDefaultGC()
Return default graphics context in use.
FontStruct_t GetFontStruct() const
Definition: TGProgressBar.h:83
TString fFormat
Definition: TGProgressBar.h:47
Float_t GetMin() const
Definition: TGProgressBar.h:72
void Increment(Float_t inc)
Increment progress position.
Pixel_t GetBarColor() const
Definition: TGProgressBar.h:81
Float_t GetPosition() const
Definition: TGProgressBar.h:74
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
TH1 * h
Definition: legend2.C:5
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
virtual ~TGHProgressBar()
static const TGFont * fgDefaultFont
Definition: TGProgressBar.h:57
virtual void DoRedraw()=0
Redraw the frame.
Handle_t GContext_t
Definition: GuiTypes.h:37
Basic string class.
Definition: TString.h:125
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t GetShowPos() const
Definition: TGProgressBar.h:77
const char * GetValueFormat() const
Definition: TGProgressBar.h:79
virtual void SetBarColor(Pixel_t color)
Set progress bar color.
TString GetFormat() const
Definition: TGProgressBar.h:78
#define ClassDef(name, id)
Definition: Rtypes.h:320
ULong_t Pixel_t
Definition: GuiTypes.h:39
virtual void Percent(Bool_t on)
Definition: TGProgressBar.h:90
virtual void Format(const char *format="%.2f")
Set format for displaying a value.
virtual void SetForegroundColor(Pixel_t pixel)
Change text color drawing.
virtual void ShowPos(Bool_t on)
Definition: TGProgressBar.h:91
Pixel_t GetForeground() const
Definition: TGGC.h:82
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
void SetBarType(EBarType type)
Set bar type.
void ShowPos(Bool_t)
unsigned int UInt_t
Definition: RtypesCore.h:42
Float_t GetMax() const
Definition: TGProgressBar.h:73
GContext_t fNormGC
Definition: TGProgressBar.h:52
virtual ~TGProgressBar()
Definition: TGProgressBar.h:70
UInt_t fWidth
Definition: TGFrame.h:134
void SetRange(Float_t min, Float_t max)
Set min and max of progress bar.
EFillType GetFillType() const
Definition: TGProgressBar.h:75
void SetPosition(Float_t pos)
Set progress position between [min,max].
int type
Definition: TGX11.cxx:120
Definition: TGFont.h:149
EFillType fFillType
Definition: TGProgressBar.h:45
UInt_t fHeight
Definition: TGFrame.h:135
virtual void Reset()
Reset progress bar (i.e. set pos to 0).
void SetMin(Float_t min)
Definition: TGProgressBar.h:93
Bool_t UsePercent() const
Definition: TGProgressBar.h:80
GContext_t GetNormGC() const
Definition: TGProgressBar.h:82
TGClient * fClient
Definition: TGObject.h:37
static TGGC * fgDefaultGC
Definition: TGProgressBar.h:58
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save progress bar parameters as a C++ statement(s) on output stream out.
void Percent(Bool_t)
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
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)
Create progress bar.
void SetMax(Float_t max)
Definition: TGProgressBar.h:94
const Bool_t kTRUE
Definition: RtypesCore.h:87
Definition: TGGC.h:31
void SetFillType(EFillType type)
Set fill type.
static Pixel_t GetDefaultSelectedBackground()
Get default selected frame background.
Definition: TGFrame.cxx:678
FontStruct_t fFontStruct
Definition: TGProgressBar.h:53
const char * Data() const
Definition: TString.h:345