// @topic W040103 FLTK FLUID -- timer
// @brief class CTimerWindow implementation
// CTimerWindow.cpp
#include <sstream>
#include <string>
#include "CTimerWindow.h"
CTimerWindow::CTimerWindow()
{
m_is_animated = false;
m_count = 0;
}
void CTimerWindow::show()
{
m_btn_start->callback( (Fl_Callback*) cb_btn_start_callback, this );
m_btn_stop->callback( (Fl_Callback*) cb_btn_stop_callback, this );
m_win_timer->show();
}
void CTimerWindow::cb_btn_start_callback( Fl_Widget* btn, void* userdata )
{
CTimerWindow* window = ( CTimerWindow* ) userdata;
window->m_win_timer->label( "start" ); // set window title
window->m_is_animated = true;
Fl::add_timeout( TIMER_TIMEOUT, timer_event, window );
}
void CTimerWindow::cb_btn_stop_callback( Fl_Widget* btn, void* userdata )
{
CTimerWindow* window = ( CTimerWindow* ) userdata;
window->m_is_animated = false;
window->m_win_timer->label( "stop" );
}
void CTimerWindow::timer_event( void* userdata )
{
CTimerWindow* window = ( CTimerWindow* ) userdata;
if ( window->m_is_animated ) {
++( window->m_count );
std::stringstream buffer;
buffer << window->m_count;
window->m_win_timer->label( buffer.str().c_str() );
Fl::add_timeout( TIMER_TIMEOUT, timer_event, window );
}
}