31 const TGFont *TGProgressBar::fgDefaultFont = 0;
32 TGGC *TGProgressBar::fgDefaultGC = 0;
35 ClassImp(TGProgressBar);
36 ClassImp(TGHProgressBar);
37 ClassImp(TGVProgressBar);
42 TGProgressBar::TGProgressBar(
const TGWindow *p, UInt_t w, UInt_t h,
43 ULong_t back, ULong_t barcolor, GContext_t norm,
44 FontStruct_t font, UInt_t options) :
45 TGFrame(p, w, h, options | kOwnBackground, back)
51 fFillType = kSolidFill;
57 fBarColorGC.SetFillStyle(kFillSolid);
58 fBarColorGC.SetForeground(barcolor);
59 fBarWidth = kProgressBarStandardWidth;
66 void TGProgressBar::SetRange(Float_t min, Float_t max)
69 Error(
"SetRange",
"max must be > min");
76 if (fPos < min) fPos = min;
77 if (fPos > max) fPos = max;
92 void TGProgressBar::SetPosition(Float_t pos)
94 if (pos < fMin) pos = fMin;
95 if (pos > fMax) pos = fMax;
110 void TGProgressBar::Increment(Float_t inc)
116 if (fPos > fMax) fPos = fMax;
126 void TGProgressBar::Reset()
130 fClient->NeedRedraw(
this);
136 void TGProgressBar::SetFillType(EFillType type)
140 fClient->NeedRedraw(
this);
146 void TGProgressBar::SetBarType(EBarType type)
150 fClient->NeedRedraw(
this);
156 void TGProgressBar::SetBarColor(ULong_t color)
158 fBarColorGC.SetForeground(color);
160 fClient->NeedRedraw(
this);
166 void TGProgressBar::SetBarColor(
const char *color)
169 fClient->GetColorByName(color, ic);
170 fBarColorGC.SetForeground(ic);
171 fClient->NeedRedraw(
this);
177 void TGProgressBar::Format(
const char *format)
181 fClient->NeedRedraw(
this);
187 FontStruct_t TGProgressBar::GetDefaultFontStruct()
190 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
191 return fgDefaultFont->GetFontStruct();
197 const TGGC &TGProgressBar::GetDefaultGC()
200 fgDefaultGC =
new TGGC(*gClient->GetResourcePool()->GetFrameGC());
207 void TGProgressBar::SetForegroundColor(Pixel_t pixel)
209 TGGC *gc = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC);
214 gc->SetForeground(pixel);
215 fNormGC = gc->GetGC();
217 fClient->NeedRedraw(
this);
223 TGHProgressBar::TGHProgressBar(
const TGWindow *p, UInt_t w, UInt_t h,
224 Pixel_t back, Pixel_t barcolor,
225 GContext_t norm, FontStruct_t font, UInt_t options) :
226 TGProgressBar(p, w, h, back, barcolor, norm, font, options)
229 fEditDisabled = kEditDisableHeight;
238 TGHProgressBar::TGHProgressBar(
const TGWindow *p, EBarType type, UInt_t w)
239 : TGProgressBar(p, w, type == kStandard ? kProgressBarStandardWidth :
240 kProgressBarTextWidth, type == kStandard ? GetDefaultFrameBackground() :
241 fgWhitePixel, fgDefaultSelectedBackground, GetDefaultGC()(),
242 GetDefaultFontStruct(),
243 type == kStandard ? kSunkenFrame : kDoubleBorder | kSunkenFrame)
246 fBarWidth = (type == kStandard) ? kProgressBarStandardWidth : kProgressBarTextWidth;
247 fEditDisabled = kEditDisableHeight;
253 void TGHProgressBar::ShowPosition(Bool_t set, Bool_t percent,
const char *format)
259 fClient->NeedRedraw(
this);
265 void TGHProgressBar::DoRedraw()
272 fPosPix = Int_t(((Float_t)fWidth - (fBorderWidth << 1)) *
273 (fPos - fMin) / (fMax - fMin) +
276 Int_t pospix = fPosPix;
278 if (fFillType == kSolidFill)
279 gVirtualX->FillRectangle(fId, fBarColorGC(), fBorderWidth,
280 fBorderWidth, fPosPix - fBorderWidth, fBarWidth -
281 (fBorderWidth << 1));
283 Int_t blocksize = kBlockSize;
284 Int_t delta = kBlockSpace;
285 Int_t pos = fBorderWidth;
286 while (pos < fPosPix) {
287 if (pos + blocksize > Int_t(fWidth)-fBorderWidth)
288 blocksize = fWidth-fBorderWidth-pos;
289 gVirtualX->FillRectangle(fId, fBarColorGC(), pos,
290 fBorderWidth, blocksize, fBarWidth -
291 (fBorderWidth << 1));
292 if (fDrawBar && fShowPos)
293 gVirtualX->ClearArea(fId, pos+blocksize, fBorderWidth,
294 delta, fBarWidth - (fBorderWidth << 1));
296 pos += blocksize + delta;
298 pospix = pos - delta;
304 buf = TString::Format(
"%d%%", Int_t((fPos-fMin)/(fMax-fMin)*100.));
306 buf = TString::Format(fFormat.Data(), fPos);
308 Int_t x, y, max_ascent, max_descent;
309 UInt_t twidth = gVirtualX->TextWidth(fFontStruct, buf.Data(), buf.Length());
310 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
311 UInt_t theight = max_ascent + max_descent;
313 x = (fWidth - twidth) >> 1;
314 y = (fHeight - theight) >> 1;
316 if (fDrawBar && fPosPix < Int_t(x+twidth))
317 gVirtualX->ClearArea(fId, pospix, fBorderWidth,
318 fWidth - pospix - fBorderWidth,
319 fBarWidth - (fBorderWidth << 1));
321 gVirtualX->DrawString(fId, fNormGC, x, y + max_ascent, buf.Data(), buf.Length());
330 TGVProgressBar::TGVProgressBar(
const TGWindow *p, UInt_t w, UInt_t h,
331 Pixel_t back, Pixel_t barcolor, GContext_t norm,
332 FontStruct_t font,UInt_t options) :
333 TGProgressBar(p, w, h, back, barcolor, norm, font, options)
336 fEditDisabled = kEditDisableWidth;
345 TGVProgressBar::TGVProgressBar(
const TGWindow *p, EBarType type, UInt_t h)
346 : TGProgressBar(p, type == kStandard ? kProgressBarStandardWidth :
347 kProgressBarTextWidth, h, type == kStandard ? GetDefaultFrameBackground() :
348 fgWhitePixel, fgDefaultSelectedBackground, GetDefaultGC()(),
349 GetDefaultFontStruct(),
350 type == kStandard ? kSunkenFrame : kDoubleBorder | kSunkenFrame)
353 fBarWidth = (type == kStandard) ? kProgressBarStandardWidth : kProgressBarTextWidth;
355 fEditDisabled = kEditDisableWidth;
361 void TGVProgressBar::DoRedraw()
368 fPosPix = Int_t(((Float_t)fHeight - (fBorderWidth << 1)) *
369 (fPos - fMin) / (fMax - fMin) +
372 if (fFillType == kSolidFill)
373 gVirtualX->FillRectangle(fId, fBarColorGC(), fBorderWidth,
374 fHeight - fPosPix, fBarWidth - (fBorderWidth << 1),
375 fPosPix - fBorderWidth);
377 Int_t blocksize = kBlockSize;
378 Int_t delta = kBlockSpace;
379 Int_t pos = fBorderWidth;
380 while (pos < fPosPix) {
381 if (pos + blocksize > Int_t(fHeight)-fBorderWidth)
382 blocksize = fHeight-fBorderWidth-pos;
383 gVirtualX->FillRectangle(fId, fBarColorGC(), fBorderWidth,
384 fHeight - pos - blocksize, fBarWidth - (fBorderWidth << 1),
386 pos += blocksize + delta;
400 void TGProgressBar::SavePrimitive(std::ostream &out, Option_t *option )
402 const char *barcolor;
406 if (GetOptions() != (kSunkenFrame | kDoubleBorder | kOwnBackground))
407 out <<
" " << GetName() <<
"->ChangeOptions(" << GetOptionString()
408 <<
");" << std::endl;
409 if (GetBackground() != GetWhitePixel()) {
410 SaveUserColor(out, option);
411 out <<
" " << GetName() <<
"->SetBackgroundColor(ucolor);" << std::endl;
416 if (GetOptions() != (kSunkenFrame | kOwnBackground))
417 out <<
" " << GetName() <<
"->ChangeOptions(" << GetOptionString()
418 <<
");" << std::endl;
419 if (GetBackground() != GetDefaultFrameBackground()) {
420 SaveUserColor(out, option);
421 out <<
" " << GetName() <<
"->SetBackgroundColor(ucolor);" << std::endl;
426 if (fBarColorGC.GetForeground() != GetDefaultSelectedBackground()) {
427 barcolor = TColor::PixelAsHexString(fBarColorGC.GetForeground());
428 out <<
" " << GetName() <<
"->SetBarColor(" << quote << barcolor << quote
429 <<
");" << std::endl;
432 if (fMin != 0 && fMax != 100)
433 out <<
" " << GetName() <<
"->SetRange(" << fMin <<
"," << fMax <<
");" << std::endl;
435 out <<
" "<< GetName() <<
"->SetPosition("<< fPos <<
");"<< std::endl;
442 void TGVProgressBar::SavePrimitive(std::ostream &out, Option_t *option )
445 out <<
" TGVProgressBar *";
446 out << GetName() <<
" = new TGVProgressBar(" << fParent->GetName();
448 if ((fBarType == kFancy) && (fBarWidth == kProgressBarTextWidth)) {
449 out <<
",TGProgressBar::kFancy";
450 }
else if ((fBarType == kStandard) && (fBarWidth == kProgressBarStandardWidth)){
451 out <<
",TGProgressBar::kStandard";
454 out <<
"," << GetHeight() <<
");" << std::endl;
456 if (option && strstr(option,
"keep_names"))
457 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
459 if (GetFillType() == kBlockFill)
460 out <<
" " << GetName() <<
"->SetFillType(TGProgressBar::kBlockFill);"<< std::endl;
462 TGProgressBar::SavePrimitive(out, option);
468 void TGHProgressBar::SavePrimitive(std::ostream &out, Option_t *option )
472 out <<
" TGHProgressBar *";
473 out << GetName() <<
" = new TGHProgressBar("<< fParent->GetName();
475 if ((fBarType == kFancy) && (fBarWidth == kProgressBarTextWidth)) {
476 out <<
",TGProgressBar::kFancy";
477 }
else if ((fBarType == kStandard) && (fBarWidth == kProgressBarStandardWidth)){
478 out <<
",TGProgressBar::kStandard";
481 if (option && strstr(option,
"keep_names"))
482 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
484 out <<
"," << GetWidth() <<
");" << std::endl;
486 if (GetFillType() == kBlockFill)
487 out <<
" " << GetName() <<
"->SetFillType(TGProgressBar::kBlockFill);"<< std::endl;
490 out <<
" " << GetName() <<
"->ShowPosition(kTRUE,";
496 out << quote << GetFormat() << quote <<
");"<< std::endl;
498 }
else if (UsePercent() && !GetFillType()) {
499 out <<
" " << GetName() <<
"->ShowPosition();" << std::endl;
501 TGProgressBar::SavePrimitive(out, option);