示例#1
0
void line_edit_control::init( u32 str_buffer_size, init_mode mode )
{
	m_buffer_size = str_buffer_size;
	clamp( m_buffer_size, (int)MIN_BUF_SIZE, (int)MAX_BUF_SIZE );

	xr_free( m_edit_str );	m_edit_str = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	xr_free( m_inserted );	m_inserted = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	xr_free( m_undo_buf );	m_undo_buf = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	
	xr_free( m_buf0 );		m_buf0 = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	xr_free( m_buf1 );		m_buf1 = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	xr_free( m_buf2 );		m_buf2 = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );
	xr_free( m_buf3 );		m_buf3 = (LPSTR)xr_malloc( m_buffer_size * sizeof(char) );

	clear_states();

	for ( u32 i = 0; i < DIK_COUNT; ++i )
	{
		xr_delete( m_actions[i] );
		m_actions[i] = NULL;
	}

	if ( mode == im_read_only )
	{
		assign_callback( DIK_A     , ks_Ctrl, Callback( this, &line_edit_control::select_all_buf       ) );
		assign_callback( DIK_C     , ks_Ctrl, Callback( this, &line_edit_control::copy_to_clipboard    ) );
		assign_callback( DIK_INSERT, ks_Ctrl, Callback( this, &line_edit_control::copy_to_clipboard    ) );

		assign_callback( DIK_HOME  , ks_free, Callback( this, &line_edit_control::move_pos_home        ) );
		assign_callback( DIK_END   , ks_free, Callback( this, &line_edit_control::move_pos_end         ) );
		assign_callback( DIK_LEFT  , ks_free, Callback( this, &line_edit_control::move_pos_left        ) );
		assign_callback( DIK_RIGHT , ks_free, Callback( this, &line_edit_control::move_pos_right       ) );
		assign_callback( DIK_LEFT  , ks_Ctrl, Callback( this, &line_edit_control::move_pos_left_word   ) );
		assign_callback( DIK_RIGHT , ks_Ctrl, Callback( this, &line_edit_control::move_pos_right_word  ) );
	}
	else
	{
		assign_char_pairs( mode );

		assign_callback( DIK_INSERT, ks_free, Callback( this, &line_edit_control::flip_insert_mode     ) );
		assign_callback( DIK_A     , ks_Ctrl, Callback( this, &line_edit_control::select_all_buf       ) );
		assign_callback( DIK_Z     , ks_Ctrl, Callback( this, &line_edit_control::undo_buf             ) );

		assign_callback( DIK_C     , ks_Ctrl, Callback( this, &line_edit_control::copy_to_clipboard    ) );
		assign_callback( DIK_V     , ks_Ctrl, Callback( this, &line_edit_control::paste_from_clipboard ) );
		assign_callback( DIK_X     , ks_Ctrl, Callback( this, &line_edit_control::cut_to_clipboard     ) );

		assign_callback( DIK_INSERT, ks_Ctrl, Callback( this, &line_edit_control::copy_to_clipboard    ) );
		assign_callback( DIK_INSERT, ks_Shift,Callback( this, &line_edit_control::paste_from_clipboard ) );
		assign_callback( DIK_DELETE, ks_Shift,Callback( this, &line_edit_control::cut_to_clipboard     ) );

		assign_callback( DIK_HOME  , ks_free, Callback( this, &line_edit_control::move_pos_home        ) );
		assign_callback( DIK_END   , ks_free, Callback( this, &line_edit_control::move_pos_end         ) );
		assign_callback( DIK_LEFT  , ks_free, Callback( this, &line_edit_control::move_pos_left        ) );
		assign_callback( DIK_RIGHT , ks_free, Callback( this, &line_edit_control::move_pos_right       ) );
		assign_callback( DIK_LEFT  , ks_Ctrl, Callback( this, &line_edit_control::move_pos_left_word   ) );
		assign_callback( DIK_RIGHT , ks_Ctrl, Callback( this, &line_edit_control::move_pos_right_word  ) );

		assign_callback( DIK_BACK  , ks_free, Callback( this, &line_edit_control::delete_selected_back ) );
		assign_callback( DIK_DELETE, ks_free, Callback( this, &line_edit_control::delete_selected_forward ) );
		assign_callback( DIK_BACK  , ks_Ctrl, Callback( this, &line_edit_control::delete_word_back     ) );
		assign_callback( DIK_DELETE, ks_Ctrl, Callback( this, &line_edit_control::delete_word_forward  ) );
	} // if mode

	create_key_state( DIK_LSHIFT  , ks_LShift );
	create_key_state( DIK_RSHIFT  , ks_RShift );
	create_key_state( DIK_LCONTROL, ks_LCtrl  );
	create_key_state( DIK_RCONTROL, ks_RCtrl  );
	create_key_state( DIK_LALT    , ks_LAlt   );
	create_key_state( DIK_RALT    , ks_RAlt   );
}
示例#2
0
void State_Manager::update(double delta)
{
    //check if active state requested for change
    unsigned int next_state_id = m_all_states[0]->get_next_state_id();

    if(next_state_id == game_state::null_state)
    {
        //no change, update the active state
        m_all_states[0]->update(delta);
    }
    else
    {
        //change in state required
        unsigned int current_state_id = m_all_states[0]->get_state_id();

        //menu state
        if(current_state_id == game_state::menu)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::quit)
            {
                clear_states();
            }
        }

        //play state
        else if(current_state_id == game_state::play)
        {
            if(next_state_id == game_state::pause_state)
            {
                create_state(game_state::pause_state);
            }
            else if(next_state_id == game_state::game_over)
            {
                create_state(game_state::game_over);
            }
            else if(next_state_id == game_state::level_win)
            {
                create_state(game_state::level_win);
            }
        }

        //pause state
        else if(current_state_id == game_state::pause_state)
        {
            if(next_state_id == game_state::play)
            {
                remove_state();
                m_all_states[0]->reset_next_state_id();
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //level win state
        else if(current_state_id == game_state::level_win)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //game over state
        else if(current_state_id == game_state::game_over)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        else
            std::cout << "Undefined state requested\n";
    }

}