finalcut/src/fprogressbar.cpp

250 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()
{
2015-09-22 04:18:20 +02:00
setColor ( parentWidget()->getForegroundColor()
, parentWidget()->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);
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;
2015-10-29 21:10:50 +01:00
2015-05-23 13:35:12 +02:00
gotoxy (xpos+xmin-1, ypos+ymin-1);
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
, parentWidget()->getBackgroundColor() );
2015-05-23 13:35:12 +02:00
else
2015-10-10 04:01:22 +02:00
setColor ( wc.progressbar_bg
, parentWidget()->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 (' ');
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);
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 (' ');
}
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();
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;
}