Exemple #1
0
		std::basic_string < Elem, Traits > cell_encode(std::basic_string < Elem, Traits > Str, Elem Sep_, Elem Esc){
			if(Str.find(Sep_) < Str.size() || Str.find(Esc) < Str.size()){
				for(auto itr = Str.begin(); itr != Str.end(); ++itr){
					if(*itr == Esc){
						itr = Str.insert(++itr, Esc);
					}
				}

				Str.insert(Str.begin(), Esc);
				Str.push_back(Esc);
			}

			return std::move(Str);
		}
Exemple #2
0
bool FeOverlay::edit_loop( std::vector<sf::Drawable *> d,
			std::basic_string<sf::Uint32> &str, FeTextPrimative *tp )
{
	const sf::Transform &t = m_fePresent.get_transform();

	const sf::Font *font = tp->getFont();
	sf::Text cursor( "_", *font, tp->getCharacterSize() );
	cursor.setColor( tp->getColor() );
	cursor.setStyle( sf::Text::Bold );
	cursor.setScale( tp->getTextScale() );

	int cursor_pos=str.size();
	cursor.setPosition( tp->setString( str, cursor_pos ) );

	bool redraw=true;
	FeKeyRepeat key_repeat_enabler( m_wnd );

	while ( m_wnd.isOpen() )
	{
		sf::Event ev;
		while (m_wnd.pollEvent(ev))
		{
			switch ( ev.type )
			{
			case sf::Event::Closed:
				return false;

			case sf::Event::TextEntered:

				switch ( ev.text.unicode )
				{
				case 8: // Backspace
					if ( cursor_pos > 0 )
					{
						str.erase( cursor_pos - 1, 1 );
						cursor_pos--;
					}
					redraw = true;
					break;

				case 9: // horizontal tab
				case 10: // linefeed
				case 13: // Return (ignore here, deal with as keypress event)
					break;

				case 127: // Delete
					if ( cursor_pos < (int)str.size() )
						str.erase( cursor_pos, 1 );

					redraw = true;
					break;

				default: // General text entry
					if ( cursor_pos < (int)str.size() )
						str.insert( cursor_pos, 1, ev.text.unicode );
					else
						str += ev.text.unicode;

					cursor_pos++;
					redraw = true;
				}

				break;

			case sf::Event::KeyPressed:
				switch ( ev.key.code )
				{
				case sf::Keyboard::Left:
					if ( cursor_pos > 0 )
						cursor_pos--;

					redraw = true;
					break;

				case sf::Keyboard::Right:
					if ( cursor_pos < (int)str.size() )
						cursor_pos++;

					redraw = true;
					break;

				case sf::Keyboard::Return:
					return true;

				case sf::Keyboard::Escape:
					return false;

				default:
					break;
				}
			default:
			break;
			}

			if ( redraw )
				cursor.setPosition( tp->setString( str, cursor_pos ) );
		}

		if ( m_fePresent.tick( NULL ) )
			redraw = true;

		if ( redraw )
		{
			m_wnd.clear();
			m_wnd.draw( m_fePresent, t );

			for ( std::vector<sf::Drawable *>::iterator itr=d.begin();
					itr < d.end(); ++itr )
				m_wnd.draw( *(*itr), t );

			m_wnd.draw( cursor, t );
			m_wnd.display();

			redraw = false;
		}
		else
			sf::sleep( sf::milliseconds( 30 ) );

	}
	return true;
}