Logo ROOT  
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:
34  enum EBarType { kStandard, kFancy };
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 
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; }
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 
TGHProgressBar::TGHProgressBar
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)
Horizontal progress bar constructor.
Definition: TGProgressBar.cxx:223
TGProgressBar::fFillType
EFillType fFillType
Definition: TGProgressBar.h:51
TGProgressBar::ShowPos
virtual void ShowPos(Bool_t on)
Definition: TGProgressBar.h:97
TGHProgressBar::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGProgressBar.h:122
TGProgressBar::GetDefaultFontStruct
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
Definition: TGProgressBar.cxx:187
TGWindow
Definition: TGWindow.h:31
TGProgressBar::kBlockSize
@ kBlockSize
Definition: TGProgressBar.h:43
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGProgressBar::Reset
virtual void Reset()
Reset progress bar (i.e. set pos to 0).
Definition: TGProgressBar.cxx:126
TGProgressBar::SetPosition
void SetPosition(Float_t pos)
Set progress position between [min,max].
Definition: TGProgressBar.cxx:92
TGGC::GetForeground
Pixel_t GetForeground() const
Definition: TGGC.h:82
TGDimension
Definition: TGDimension.h:27
TGProgressBar::fgDefaultFont
static const TGFont * fgDefaultFont
Definition: TGProgressBar.h:63
TString::Data
const char * Data() const
Definition: TString.h:369
TGProgressBar::GetMin
Float_t GetMin() const
Definition: TGProgressBar.h:78
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGProgressBar::kSolidFill
@ kSolidFill
Definition: TGProgressBar.h:41
TGFrame::fWidth
UInt_t fWidth
Definition: TGFrame.h:112
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
TGProgressBar::kBlockSpace
@ kBlockSpace
Definition: TGProgressBar.h:43
TGVProgressBar::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a vertical progress bar as a C++ statement(s) on output stream out.
Definition: TGProgressBar.cxx:442
TGProgressBar::fPercent
Bool_t fPercent
Definition: TGProgressBar.h:55
Float_t
float Float_t
Definition: RtypesCore.h:57
TGProgressBar::fPos
Float_t fPos
Definition: TGProgressBar.h:48
TGVProgressBar
Definition: TGProgressBar.h:134
TGVProgressBar::~TGVProgressBar
virtual ~TGVProgressBar()
Definition: TGProgressBar.h:148
TGProgressBar::SetRange
void SetRange(Float_t min, Float_t max)
Set min and max of progress bar.
Definition: TGProgressBar.cxx:66
TGProgressBar::GetFormat
TString GetFormat() const
Definition: TGProgressBar.h:84
TGProgressBar::kBlockFill
@ kBlockFill
Definition: TGProgressBar.h:41
TGProgressBar::EFillType
EFillType
Definition: TGProgressBar.h:41
TString
Definition: TString.h:136
TGFrame
Definition: TGFrame.h:105
TGProgressBar::fBarType
EBarType fBarType
Definition: TGProgressBar.h:52
TGProgressBar::GetMax
Float_t GetMax() const
Definition: TGProgressBar.h:79
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
kDoubleBorder
@ kDoubleBorder
Definition: GuiTypes.h:385
TGProgressBar::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save progress bar parameters as a C++ statement(s) on output stream out.
Definition: TGProgressBar.cxx:400
bool
TGHProgressBar::~TGHProgressBar
virtual ~TGHProgressBar()
Definition: TGProgressBar.h:120
GContext_t
Handle_t GContext_t
Definition: GuiTypes.h:37
TGProgressBar::fgDefaultGC
static TGGC * fgDefaultGC
Definition: TGProgressBar.h:64
TGProgressBar::UsePercent
Bool_t UsePercent() const
Definition: TGProgressBar.h:86
TGVProgressBar::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGProgressBar.h:150
TGProgressBar::Format
virtual void Format(const char *format="%.2f")
Set format for displaying a value.
Definition: TGProgressBar.cxx:177
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
kSunkenFrame
@ kSunkenFrame
Definition: GuiTypes.h:383
TGHProgressBar
Definition: TGProgressBar.h:106
TGProgressBar::kStandard
@ kStandard
Definition: TGProgressBar.h:46
TGProgressBar::SetFillType
void SetFillType(EFillType type)
Set fill type.
Definition: TGProgressBar.cxx:136
TGProgressBar::Percent
virtual void Percent(Bool_t on)
Definition: TGProgressBar.h:96
TGProgressBar::fFormat
TString fFormat
Definition: TGProgressBar.h:53
TGProgressBar::GetBarType
EBarType GetBarType() const
Definition: TGProgressBar.h:82
h
#define h(i)
Definition: RSha256.hxx:124
TGGC
Definition: TGGC.h:31
TGProgressBar::GetBarColor
Pixel_t GetBarColor() const
Definition: TGProgressBar.h:87
TGProgressBar::kFancy
@ kFancy
Definition: TGProgressBar.h:46
TGProgressBar::GetDefaultGC
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Definition: TGProgressBar.cxx:197
TGProgressBar::fMax
Float_t fMax
Definition: TGProgressBar.h:47
TGFrame.h
TGProgressBar::GetFillType
EFillType GetFillType() const
Definition: TGProgressBar.h:81
TGProgressBar::~TGProgressBar
virtual ~TGProgressBar()
Definition: TGProgressBar.h:76
TGProgressBar::GetFontStruct
FontStruct_t GetFontStruct() const
Definition: TGProgressBar.h:89
TGProgressBar::SetMax
void SetMax(Float_t max)
Definition: TGProgressBar.h:100
TGVProgressBar::DoRedraw
virtual void DoRedraw()
Draw vertical progress bar.
Definition: TGProgressBar.cxx:361
TGProgressBar::fShowPos
Bool_t fShowPos
Definition: TGProgressBar.h:54
TGProgressBar::GetPosition
Float_t GetPosition() const
Definition: TGProgressBar.h:80
TGProgressBar::fFontStruct
FontStruct_t fFontStruct
Definition: TGProgressBar.h:59
TGVProgressBar::Percent
void Percent(Bool_t)
Definition: TGProgressBar.h:154
TGProgressBar::kProgressBarStandardWidth
@ kProgressBarStandardWidth
Definition: TGProgressBar.h:42
TGHProgressBar::DoRedraw
virtual void DoRedraw()
Draw horizontal progress bar.
Definition: TGProgressBar.cxx:265
unsigned int
TGVProgressBar::ShowPos
void ShowPos(Bool_t)
Definition: TGProgressBar.h:153
TGHProgressBar::ShowPosition
void ShowPosition(Bool_t set=kTRUE, Bool_t percent=kTRUE, const char *format="%.2f")
Show postion text, either in percent or formatted according format.
Definition: TGProgressBar.cxx:253
TGProgressBar::SetBarType
void SetBarType(EBarType type)
Set bar type.
Definition: TGProgressBar.cxx:146
TGProgressBar::fNormGC
GContext_t fNormGC
Definition: TGProgressBar.h:58
TGClient::NeedRedraw
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:373
TGProgressBar::fPosPix
Int_t fPosPix
Definition: TGProgressBar.h:49
TGProgressBar
Definition: TGProgressBar.h:31
TGHProgressBar::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a horizontal progress bar as a C++ statement(s) on output stream out.
Definition: TGProgressBar.cxx:468
TGObject::fClient
TGClient * fClient
Definition: TGObject.h:37
TGProgressBar::TGProgressBar
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.
Definition: TGProgressBar.cxx:42
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGProgressBar::fMin
Float_t fMin
Definition: TGProgressBar.h:46
TGProgressBar::fBarColorGC
TGGC fBarColorGC
Definition: TGProgressBar.h:57
TGProgressBar::fDrawBar
Bool_t fDrawBar
Definition: TGProgressBar.h:56
TGFrame::GetWhitePixel
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:694
TGFrame::GetDefaultSelectedBackground
static Pixel_t GetDefaultSelectedBackground()
Get default selected frame background.
Definition: TGFrame.cxx:681
TGProgressBar::fBarWidth
Int_t fBarWidth
Definition: TGProgressBar.h:50
TGProgressBar::GetShowPos
Bool_t GetShowPos() const
Definition: TGProgressBar.h:83
TGFrame::fHeight
UInt_t fHeight
Definition: TGFrame.h:113
TGVProgressBar::TGVProgressBar
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)
cconstructor
Definition: TGProgressBar.cxx:330
type
int type
Definition: TGX11.cxx:121
TGFont
Definition: TGFont.h:149
TGProgressBar::kProgressBarTextWidth
@ kProgressBarTextWidth
Definition: TGProgressBar.h:42
TGProgressBar::DoRedraw
virtual void DoRedraw()=0
Redraw the frame.
TGProgressBar::SetForegroundColor
virtual void SetForegroundColor(Pixel_t pixel)
Change text color drawing.
Definition: TGProgressBar.cxx:207
TGProgressBar::Increment
void Increment(Float_t inc)
Increment progress position.
Definition: TGProgressBar.cxx:110
TGProgressBar::SetBarColor
virtual void SetBarColor(Pixel_t color)
Set progress bar color.
Definition: TGProgressBar.cxx:156
TGProgressBar::GetNormGC
GContext_t GetNormGC() const
Definition: TGProgressBar.h:88
TGProgressBar::GetValueFormat
const char * GetValueFormat() const
Definition: TGProgressBar.h:85
TGProgressBar::EBarType
EBarType
Definition: TGProgressBar.h:40
TGProgressBar::SetMin
void SetMin(Float_t min)
Definition: TGProgressBar.h:99
int