finalcut/src/fprogressbar.cpp

243 lines
5.2 KiB
C++
Raw Normal View History

// File: fprogressbar.cpp
// Provides: class FProgressbar
2015-05-23 13:35:12 +02:00
#include "fprogressbar.h"
//----------------------------------------------------------------------
// class FProgressbar
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FProgressbar::FProgressbar(FWidget* parent)
: FWidget(parent)
, percentage(-1)
, BarLength(width)
2015-05-23 13:35:12 +02:00
{
2015-09-22 04:18:20 +02:00
unsetFocusable();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
FProgressbar::~FProgressbar()
2015-09-22 04:18:20 +02:00
{ }
2015-05-23 13:35:12 +02:00
// private methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::drawPercentage()
{
2015-09-22 04:18:20 +02:00
setColor ( parentWidget()->getForegroundColor()
, parentWidget()->getBackgroundColor() );
2015-05-23 13:35:12 +02:00
gotoxy (xpos+xmin+width-5, ypos+ymin-2);
if ( percentage < 0 || percentage > 100 )
print ("--- %");
else
printf ("%3d %%", percentage);
}
//----------------------------------------------------------------------
void FProgressbar::drawBar()
{
int i = 1;
float length = float(BarLength*percentage)/100;
gotoxy (xpos+xmin-1, ypos+ymin-1);
if ( isMonochron() )
{
if ( round(length) >= 1)
{
setReverse(true);
print (' ');
setReverse(false);
}
else
print (fc::MediumShade); // ▒
}
else if ( getMaxColor() < 16 )
{
setColor ( wc.progressbar_bg,
wc.progressbar_fg );
if ( round(length) >= 1)
print (' ');
else
print (fc::MediumShade);
}
if ( round(length) >= 1)
setColor( wc.progressbar_fg,
parentWidget()->getBackgroundColor() );
else
setColor( wc.progressbar_bg,
parentWidget()->getBackgroundColor() );
if ( ! isMonochron() && getMaxColor() >= 16 )
{
// Cygwin terminal use IBM Codepage 850
2015-09-22 04:18:20 +02:00
if ( isCygwinTerminal() )
2015-05-23 13:35:12 +02:00
print (fc::FullBlock); // █
2015-10-07 02:36:38 +02:00
else if ( isTeraTerm() )
print (0xdb);
2015-05-23 13:35:12 +02:00
else
print (fc::RightHalfBlock); // ▐
}
setColor ( wc.progressbar_bg,
wc.progressbar_fg );
if ( isMonochron() )
setReverse(true);
for (; i < trunc(length); i++)
print (' ');
if ( isMonochron() )
setReverse(false);
if ( trunc(length) >= 1 && trunc(length) < BarLength )
{
if ( round(length) > trunc(length)
2015-09-22 04:18:20 +02:00
|| isCygwinTerminal()
2015-05-23 13:35:12 +02:00
|| getMaxColor() < 16 )
{
if ( isMonochron() )
{
setReverse(true);
print (' ');
setReverse(false);
}
else
print (' ');
}
else
{
setColor(wc.progressbar_fg, wc.progressbar_bg);
print (fc::LeftHalfBlock); // ▌
}
i++;
}
setColor(wc.progressbar_fg, wc.progressbar_bg);
if ( getMaxColor() < 16 )
{
for (; i < BarLength; i++)
print (fc::MediumShade); // ▒
}
else
{
for (; i < BarLength; i++)
print (' ');
}
updateTerminal();
flush_out();
}
// protected methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::draw()
{
setUpdateVTerm(false);
drawPercentage();
drawBar();
if ( (flags & SHADOW) != 0 )
drawShadow ();
setUpdateVTerm(true);
flush_out();
}
// public methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::hide()
{
int fg, bg, s, size;
char* blank;
FWidget::hide();
fg = parentWidget()->getForegroundColor();
bg = parentWidget()->getBackgroundColor();
setColor (fg, bg);
s = hasShadow() ? 1 : 0;
size = width + s;
blank = new char[size+1];
memset(blank, ' ', uLong(size));
blank[size] = '\0';
for (int y=0; y < height+s; y++)
{
gotoxy (xpos+xmin-1, ypos+ymin-1+y);
print (blank);
}
delete[] blank;
gotoxy (xpos+xmin+width-5, ypos+ymin-2);
print (" "); // hide percentage
}
//----------------------------------------------------------------------
void FProgressbar::setPercentage (int percentage_value)
{
if ( percentage_value <= percentage )
return;
if ( percentage_value > 100 )
percentage = 100;
else if ( percentage_value < 0 )
percentage = 0;
else
percentage = percentage_value;
setUpdateVTerm(false);
if ( isVisible() )
{
drawPercentage();
drawBar();
}
setUpdateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::reset()
{
setUpdateVTerm(false);
percentage = -1;
if ( isVisible() )
{
drawPercentage();
drawBar();
}
setUpdateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::setGeometry (int x, int y, int w, int h, bool adjust)
{
FWidget::setGeometry (x, y, w, h, adjust);
BarLength = w;
}
//----------------------------------------------------------------------
bool FProgressbar::setEnable (bool on)
{
FWidget::setEnable(on);
if ( on )
2015-09-22 04:18:20 +02:00
flags |= ACTIVE;
2015-05-23 13:35:12 +02:00
else
2015-09-22 04:18:20 +02:00
flags &= ~ACTIVE;
2015-05-23 13:35:12 +02:00
return on;
}
//----------------------------------------------------------------------
bool FProgressbar::setShadow (bool on)
{
2015-10-07 02:36:38 +02:00
if ( on
&& (Encoding != fc::VT100 || isTeraTerm() )
&& Encoding != fc::ASCII )
2015-09-22 04:18:20 +02:00
flags |= SHADOW;
2015-05-23 13:35:12 +02:00
else
2015-09-22 04:18:20 +02:00
flags &= ~SHADOW;
2015-05-23 13:35:12 +02:00
return on;
}