25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
28 #include "NCProgressBar.h"
31 NCProgressBar::NCProgressBar( YWidget * parent,
32 const std::string & nlabel,
34 : YProgressBar( parent, nlabel, maxValue )
42 yuiDebug() << std::endl;
57 NCProgressBar::~NCProgressBar()
61 yuiDebug() << std::endl;
65 int NCProgressBar::preferredWidth()
67 return wGetDefsze().W;
71 int NCProgressBar::preferredHeight()
73 return wGetDefsze().H;
80 YProgressBar::setEnabled( do_bv );
84 void NCProgressBar::setSize(
int newwidth,
int newheight )
86 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
90 void NCProgressBar::setDefsze()
92 defsze =
wsze( label.height() + 1,
93 label.width() < 5 ? 5 : label.width() );
97 void NCProgressBar::wCreate(
const wrect & newrect )
99 NCWidget::wCreate( newrect );
104 wrect lrect( 0, wsze::min( newrect.Sze,
105 wsze( label.height(), newrect.Sze.W ) ) );
107 wrect trect( 0,
wsze( 1, newrect.Sze.W ) );
109 if ( lrect.Sze.H == newrect.Sze.H )
112 trect.Pos.L = lrect.Sze.H > 0 ? lrect.Sze.H : 0;
115 lrect.Sze.H, lrect.Sze.W,
116 lrect.Pos.L, lrect.Pos.C,
120 trect.Sze.H, trect.Sze.W,
121 trect.Pos.L, trect.Pos.C,
126 void NCProgressBar::wDelete()
136 void NCProgressBar::setLabel(
const std::string & nlabel )
140 YProgressBar::setLabel( nlabel );
145 void NCProgressBar::setValue(
int newValue )
151 else if ( cval > maxval )
156 YProgressBar::setValue( newValue );
160 void NCProgressBar::wRedraw()
166 chtype bg = wStyle().dumb.text;
172 label.drawAt( *lwin, bg, bg );
178 void NCProgressBar::tUpdate()
183 double split = double( twin->
maxx() + 1 ) * cval / maxval;
185 int cp = int( split );
187 if ( cp == 0 && split > 0.0 )
192 twin->
bkgdset( style.bar.chattr );
196 if ( cp <= twin->maxx() )
198 twin->
bkgdset( NCattribute::getNonChar( style.nonbar.chattr ) );
201 for (
int i = 0; i < twin->
width() - cp; ++i )
203 twin->
addch( NCattribute::getChar( style.nonbar.chattr ) );
207 if ( twin->
maxx() >= 6 )
209 Value_t pc = 100 * cval / maxval;
210 Value_t off = twin->
maxx() / 2 - ( pc == 100 ? 2
214 sprintf( buf,
"%lld%%", pc );
215 twin->
move( 0, off );
217 for (
char * ch = buf; *ch; ++ch )
219 chtype a = twin->
inch();
220 NCattribute::setChar( a, *ch );
virtual void setEnabled(bool do_bv)