hintbox: add possibility for more control of timeout bar

So we can enable/disable directly with setTimeOut() method.
Usefully to disable timeout bar if not required.
This commit is contained in:
2020-01-21 12:07:48 +01:00
parent 21bd65bfa2
commit 1e76f6ef44
2 changed files with 25 additions and 18 deletions

View File

@@ -190,6 +190,7 @@ void CHintBox::init( const std::string& Text,
y_hint_obj = CC_CENTERED; y_hint_obj = CC_CENTERED;
//initialize timeout bar and its timer //initialize timeout bar and its timer
enable_timeout_bar = false;
timeout_pb = NULL; timeout_pb = NULL;
timeout_pb_timer= NULL; timeout_pb_timer= NULL;
@@ -206,7 +207,7 @@ CHintBox::~CHintBox()
void CHintBox::enableTimeOutBar(bool enable) void CHintBox::enableTimeOutBar(bool enable)
{ {
if(!enable){ if(!enable_timeout_bar){
if(timeout_pb_timer){ if(timeout_pb_timer){
delete timeout_pb_timer; timeout_pb_timer = NULL; delete timeout_pb_timer; timeout_pb_timer = NULL;
} }
@@ -217,24 +218,28 @@ void CHintBox::enableTimeOutBar(bool enable)
} }
return; return;
} }
else
if(timeout_pb){ if (enable_timeout_bar && enable)
timeout_pb->setValues(timeout_pb->getValue()+1, 10*timeout); {
timeout_pb->paint0(); if(timeout_pb){
}else{ timeout_pb->setValues(timeout_pb->getValue()+1, 10*timeout);
timeout_pb = new CProgressBar(); timeout_pb->paint0();
timeout_pb->setType(CProgressBar::PB_TIMESCALE); }else{
timeout_pb->setDimensionsAll(ccw_body->getRealXPos(), ccw_body->getRealYPos(), ccw_body->getWidth(), TIMEOUT_BAR_HEIGHT); timeout_pb = new CProgressBar();
timeout_pb->setValues(timeout/10, timeout); timeout_pb->setType(CProgressBar::PB_TIMESCALE);
if (!timeout_pb_timer) { timeout_pb->setDimensionsAll(ccw_body->getRealXPos(), ccw_body->getRealYPos(), ccw_body->getWidth(), TIMEOUT_BAR_HEIGHT);
timeout_pb_timer = new CComponentsTimer(100); timeout_pb->setValues(timeout/10, timeout);
const string tn = cc_item_type.name + ":timeout_bar:"; if (!timeout_pb_timer) {
timeout_pb_timer->setThreadName(tn); timeout_pb_timer = new CComponentsTimer(100);
const string tn = cc_item_type.name + ":timeout_bar:";
timeout_pb_timer->setThreadName(tn);
}
sl_tbar_on_timer.disconnect();
sl_tbar_on_timer = sigc::mem_fun0(this, &CHintBox::showTimeOutBar);
timeout_pb_timer->OnTimer.connect(sl_tbar_on_timer);
timeout_pb_timer->startTimer();
} }
sl_tbar_on_timer.disconnect();
sl_tbar_on_timer = sigc::mem_fun0(this, &CHintBox::showTimeOutBar);
timeout_pb_timer->OnTimer.connect(sl_tbar_on_timer);
timeout_pb_timer->startTimer();
} }
} }

View File

@@ -64,6 +64,7 @@ class CHintBox : public CComponentsWindow
int w_indentation; int w_indentation;
bool enable_txt_scroll; bool enable_txt_scroll;
sigc::slot0<void> sl_tbar_on_timer; sigc::slot0<void> sl_tbar_on_timer;
bool enable_timeout_bar;
Font* hb_font; Font* hb_font;
@@ -208,8 +209,9 @@ class CHintBox : public CComponentsWindow
* Timeout is enabled with parameter1 = DEFAULT_TIMEOUT (-1) or any other value > 0 * Timeout is enabled with parameter1 = DEFAULT_TIMEOUT (-1) or any other value > 0
* To disable timeout use NO_TIMEOUT (0) * To disable timeout use NO_TIMEOUT (0)
* @param[in] Timeout as int as seconds * @param[in] Timeout as int as seconds
* @param[in] enable_Timeout_Bar as bool, default = true
*/ */
virtual void setTimeOut(const int& Timeout){timeout = Timeout;} virtual void setTimeOut(const int& Timeout, const bool& enable_Timeout_Bar = true){timeout = Timeout; enable_timeout_bar = enable_Timeout_Bar;}
/** /**
* enable/disable visualized timeout as progressbar under titlebar * enable/disable visualized timeout as progressbar under titlebar