finalcut/src/fprogressbar.cpp

267 lines
5.4 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()
{
setColor ( getParentWidget()->getForegroundColor()
, getParentWidget()->getBackgroundColor() );
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(true);
2015-05-23 13:35:12 +02:00
gotoxy (xpos+xmin+width-5, ypos+ymin-2);
2015-05-23 13:35:12 +02:00
if ( percentage < 0 || percentage > 100 )
print ("--- %");
else
printf ("%3d %%", percentage);
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void FProgressbar::drawBar()
{
int i = 1;
float length = float(BarLength*percentage)/100;
gotoxy (xpos+xmin-1, ypos+ymin-1);
2015-05-23 13:35:12 +02:00
if ( isMonochron() )
{
if ( round(length) >= 1)
{
setReverse(false);
2015-10-11 21:56:16 +02:00
print (' ');
setReverse(true);
2015-05-23 13:35:12 +02:00
}
else
print (fc::MediumShade); // ▒
}
else if ( getMaxColor() < 16 )
{
2015-10-10 04:01:22 +02:00
setColor ( wc.progressbar_bg
, wc.progressbar_fg );
2015-05-23 13:35:12 +02:00
if ( round(length) >= 1)
print (' ');
else
print (fc::MediumShade);
}
if ( round(length) >= 1)
2015-10-10 04:01:22 +02:00
setColor ( wc.progressbar_fg
, getParentWidget()->getBackgroundColor() );
2015-05-23 13:35:12 +02:00
else
2015-10-10 04:01:22 +02:00
setColor ( wc.progressbar_bg
, getParentWidget()->getBackgroundColor() );
2015-05-23 13:35:12 +02:00
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); // ▐
}
2015-10-10 04:01:22 +02:00
setColor ( wc.progressbar_bg
, wc.progressbar_fg );
2015-05-23 13:35:12 +02:00
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
setReverse(false);
2015-05-23 13:35:12 +02:00
for (; i < trunc(length); i++)
print (' ');
2015-05-23 13:35:12 +02:00
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
setReverse(true);
2015-05-23 13:35:12 +02:00
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(false);
2015-10-11 21:56:16 +02:00
print (' ');
setReverse(true);
2015-05-23 13:35:12 +02:00
}
else
print (' ');
}
else
{
setColor (wc.progressbar_fg, wc.progressbar_bg);
2015-05-23 13:35:12 +02:00
print (fc::LeftHalfBlock); // ▌
}
2015-05-23 13:35:12 +02:00
i++;
}
setColor (wc.progressbar_fg, wc.progressbar_bg);
2015-05-23 13:35:12 +02:00
if ( getMaxColor() < 16 )
{
for (; i < BarLength; i++)
print (fc::MediumShade); // ▒
}
else
{
for (; i < BarLength; i++)
print (' ');
}
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
2015-10-23 23:57:00 +02:00
2015-05-23 13:35:12 +02:00
updateTerminal();
flush_out();
}
// protected methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::draw()
{
setUpdateVTerm(false);
drawPercentage();
drawBar();
2016-01-24 14:53:09 +01:00
if ( (flags & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
drawShadow ();
2015-05-23 13:35:12 +02:00
setUpdateVTerm(true);
flush_out();
}
// public methods of FProgressbar
//----------------------------------------------------------------------
void FProgressbar::hide()
{
int s, size;
short fg, bg;
2015-05-23 13:35:12 +02:00
char* blank;
FWidget::hide();
fg = getParentWidget()->getForegroundColor();
bg = getParentWidget()->getBackgroundColor();
2015-05-23 13:35:12 +02:00
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;
2015-05-23 13:35:12 +02:00
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);
2015-05-23 13:35:12 +02:00
if ( isVisible() )
{
drawPercentage();
drawBar();
}
2015-05-23 13:35:12 +02:00
setUpdateVTerm(true);
updateTerminal();
}
//----------------------------------------------------------------------
void FProgressbar::reset()
{
setUpdateVTerm(false);
percentage = -1;
2015-05-23 13:35:12 +02:00
if ( isVisible() )
{
drawPercentage();
drawBar();
}
2015-05-23 13:35:12 +02:00
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 )
2016-01-24 14:53:09 +01:00
flags |= fc::active;
2015-05-23 13:35:12 +02:00
else
2016-01-24 14:53:09 +01:00
flags &= ~fc::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 )
2016-01-24 14:53:09 +01:00
flags |= fc::shadow;
2015-05-23 13:35:12 +02:00
else
2016-01-24 14:53:09 +01:00
flags &= ~fc::shadow;
2015-05-23 13:35:12 +02:00
return on;
}