Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 };
35  enum EFillType { kSolidFill, kBlockFill };
36  enum { kProgressBarStandardWidth = 16, kProgressBarTextWidth = 24,
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:
61  static FontStruct_t GetDefaultFontStruct();
62  static const TGGC &GetDefaultGC();
63 
64  TGProgressBar(const TGWindow *p, UInt_t w, UInt_t h,
65  Pixel_t back = GetWhitePixel(),
66  Pixel_t barcolor = GetDefaultSelectedBackground(),
67  GContext_t norm = GetDefaultGC()(),
68  FontStruct_t font = GetDefaultFontStruct(),
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; }
83  FontStruct_t GetFontStruct() const { return fFontStruct; }
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 
106 class TGHProgressBar : public TGProgressBar {
107 
108 protected:
109  virtual void DoRedraw();
110 
111 public:
112  TGHProgressBar(const TGWindow *p = 0,
113  UInt_t w = 4, UInt_t h = kProgressBarTextWidth,
114  Pixel_t back = GetWhitePixel(),
115  Pixel_t barcolor = GetDefaultSelectedBackground(),
116  GContext_t norm = GetDefaultGC()(),
117  FontStruct_t font = GetDefaultFontStruct(),
118  UInt_t options = kDoubleBorder | kSunkenFrame);
119  TGHProgressBar(const TGWindow *p, EBarType type, UInt_t w);
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 
134 class TGVProgressBar : public TGProgressBar {
135 
136 protected:
137  virtual void DoRedraw();
138 
139 public:
140  TGVProgressBar(const TGWindow *p = 0,
141  UInt_t w = kProgressBarTextWidth, UInt_t h = 4,
142  Pixel_t back = GetWhitePixel(),
143  Pixel_t barcolor = GetDefaultSelectedBackground(),
144  GContext_t norm = GetDefaultGC()(),
145  FontStruct_t font = GetDefaultFontStruct(),
146  UInt_t options = kDoubleBorder | kSunkenFrame);
147  TGVProgressBar(const TGWindow *p, EBarType type, UInt_t h);
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