2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fprogressbar.cpp - Widget FProgressbar *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-09-12 22:51:15 +02:00
|
|
|
* Copyright 2014-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fprogressbar.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FProgressbar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FProgressbar::FProgressbar(FWidget* parent)
|
|
|
|
: FWidget(parent)
|
2018-10-18 23:50:06 +02:00
|
|
|
, percentage(NOT_SET)
|
2016-09-27 00:46:05 +02:00
|
|
|
, bar_length(getWidth())
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
unsetFocusable();
|
2016-09-04 18:31:31 +02:00
|
|
|
setShadow();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FProgressbar::~FProgressbar() // destructor
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FProgressbar
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-18 23:50:06 +02:00
|
|
|
void FProgressbar::setPercentage (std::size_t percentage_value)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( percentage_value == NOT_SET )
|
|
|
|
percentage = NOT_SET;
|
|
|
|
else if ( percentage_value > 100 )
|
2016-11-02 00:37:58 +01:00
|
|
|
percentage = 100;
|
2018-10-18 23:50:06 +02:00
|
|
|
else if ( percentage_value <= percentage && percentage != NOT_SET )
|
|
|
|
return;
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
percentage = percentage_value;
|
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
{
|
|
|
|
drawPercentage();
|
|
|
|
drawBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
void FProgressbar::setGeometry (int x, int y, std::size_t w, std::size_t h, bool adjust)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Set the progress bar geometry
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::setGeometry (x, y, w, h, adjust);
|
|
|
|
bar_length = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FProgressbar::setShadow (bool on)
|
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( on
|
2018-05-06 21:41:55 +02:00
|
|
|
&& getEncoding() != fc::VT100
|
|
|
|
&& getEncoding() != fc::ASCII )
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags |= fc::shadow;
|
2017-01-26 00:31:07 +01:00
|
|
|
setShadowSize(1,1);
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2017-01-26 00:31:07 +01:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
flags &= ~fc::shadow;
|
2017-01-26 00:31:07 +01:00
|
|
|
setShadowSize(0,0);
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FProgressbar::hide()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t s, size;
|
2016-11-02 00:37:58 +01:00
|
|
|
short fg, bg;
|
|
|
|
FWidget* parent_widget = getParentWidget();
|
|
|
|
|
|
|
|
FWidget::hide();
|
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
{
|
|
|
|
fg = parent_widget->getForegroundColor();
|
|
|
|
bg = parent_widget->getBackgroundColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fg = wc.dialog_fg;
|
|
|
|
bg = wc.dialog_bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
setColor (fg, bg);
|
|
|
|
s = hasShadow() ? 1 : 0;
|
|
|
|
size = getWidth() + s;
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( size == 0 )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
char* blank = createBlankArray(size + 1);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
for (std::size_t y = 0; y < getHeight() + s; y++)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
setPrintPos (1, 1 + int(y));
|
2016-11-02 00:37:58 +01:00
|
|
|
print (blank);
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
destroyBlankArray (blank);
|
2018-10-14 06:25:33 +02:00
|
|
|
setPrintPos (int(getWidth()) - 4, 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
print (" "); // hide percentage
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FProgressbar::reset()
|
|
|
|
{
|
2018-10-18 23:50:06 +02:00
|
|
|
percentage = NOT_SET;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( isVisible() )
|
|
|
|
{
|
|
|
|
drawPercentage();
|
|
|
|
drawBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateTerminal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// private methods of FProgressbar
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FProgressbar::draw()
|
|
|
|
{
|
|
|
|
drawPercentage();
|
|
|
|
drawBar();
|
|
|
|
|
|
|
|
if ( (flags & fc::shadow) != 0 )
|
|
|
|
drawShadow ();
|
|
|
|
|
|
|
|
flush_out();
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FProgressbar::drawPercentage()
|
|
|
|
{
|
2016-08-21 21:27:44 +02:00
|
|
|
FWidget* parent_widget = getParentWidget();
|
|
|
|
|
|
|
|
if ( parent_widget )
|
|
|
|
setColor ( parent_widget->getForegroundColor()
|
|
|
|
, parent_widget->getBackgroundColor() );
|
|
|
|
else
|
|
|
|
setColor ( wc.dialog_fg, wc.dialog_bg );
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-11 21:56:16 +02:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
setPrintPos (int(getWidth()) - 3, 0);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( percentage > 100 )
|
2015-05-23 13:35:12 +02:00
|
|
|
print ("--- %");
|
|
|
|
else
|
|
|
|
printf ("%3d %%", percentage);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-10-11 21:56:16 +02:00
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FProgressbar::drawBar()
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
std::size_t i = 0;
|
2018-10-18 23:50:06 +02:00
|
|
|
double length;
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1,1);
|
2015-10-10 04:01:22 +02:00
|
|
|
setColor ( wc.progressbar_bg
|
|
|
|
, wc.progressbar_fg );
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( percentage == NOT_SET )
|
|
|
|
length = double(-0/100);
|
|
|
|
else
|
|
|
|
length = double(bar_length * percentage) / 100;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( isMonochron() )
|
2015-10-11 21:56:16 +02:00
|
|
|
setReverse(false);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
for (; i < trunc(length); i++)
|
|
|
|
print (' ');
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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
|
|
|
|
2018-10-18 23:50:06 +02:00
|
|
|
if ( percentage > 0 && percentage <= 100 && trunc(length) < bar_length )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-11-26 22:37:18 +01:00
|
|
|
if ( round(length) > trunc(length) || getMaxColor() < 16 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2016-01-08 01:00:05 +01:00
|
|
|
setColor (wc.progressbar_fg, wc.progressbar_bg);
|
2017-09-11 03:06:02 +02:00
|
|
|
print (fc::LeftHalfBlock); // ▌
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
setColor (wc.progressbar_fg, wc.progressbar_bg);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( getMaxColor() < 16 )
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
for (; i < bar_length; i++)
|
2015-05-23 13:35:12 +02:00
|
|
|
print (fc::MediumShade); // ▒
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
for (; i < bar_length; i++)
|
2015-05-23 13:35:12 +02:00
|
|
|
print (' ');
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
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();
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|