// @topic W010405 FLTK FLUID -- maze navigation v2
// @brief class CWindowMaze implementation

void CWindowMaze::cb_btn_right( Fl_Widget* btn, void* userdata ) {
    CWindowMaze* pwin = static_cast< CWindowMaze* >( userdata );
    pwin->m_canvas->turn_head_right();
    Fl::redraw();
}

void CWindowMaze::cb_btn_left( Fl_Widget* btn, void* userdata ) {
    CWindowMaze* pwin = static_cast< CWindowMaze* >( userdata );
    pwin->m_canvas->turn_head_left();
    Fl::redraw();
}

/**
timer animation
*/
void CWindowMaze::animation_begin( Fl_Widget* widg, void* userdata ) {
    CWindowMaze* pwin = static_cast< CWindowMaze* >( userdata );
    if ( pwin->m_canvas->animate_door_entry() ) {
        Fl::add_timeout( TICK_TIMEOUT, animation_continue, userdata );
    }
}

void CWindowMaze::animation_continue( void* userdata ) {
    CWindowMaze* pwin = static_cast< CWindowMaze* >( userdata );
    if ( pwin->m_canvas->animate_door_entry() ) {
        Fl::redraw();
        Fl::add_timeout( TICK_TIMEOUT, animation_continue, userdata );
    } else {
        Fl::redraw();
    }
}

void CWindowMaze::show( Room* entry_room ) {
    // set the callbacks
    m_canvas->callback( (Fl_Callback*)animation_begin, (void*)(this) );
    m_btn_right->callback( (Fl_Callback*)cb_btn_right, (void*)(this) );
    m_btn_left->callback( (Fl_Callback*)cb_btn_left, (void*)(this) );

    // configure the canvas widget
    m_canvas->initialize_room( entry_room );

    // display the window
    m_double_window->show();
}