Exemplo n.º 1
0
std::unique_ptr<RenderQueue> BREW::CreateCheckButtonDrawable( std::shared_ptr<const CheckButton> check ) const {
	auto border_color = GetProperty<sf::Color>( "BorderColor", check );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", check );
	auto color = GetProperty<sf::Color>( "Color", check );
	auto check_color = GetProperty<sf::Color>( "CheckColor", check );
	auto border_color_shift = GetProperty<int>( "BorderColorShift", check );
	auto border_width = GetProperty<float>( "BorderWidth", check );
	auto box_size = GetProperty<float>( "BoxSize", check );
	auto spacing = GetProperty<float>( "Spacing", check );
	auto check_size = std::min( box_size, GetProperty<float>( "CheckSize", check ) );
	const auto& font_name = GetProperty<std::string>( "FontName", check );
	auto font_size = GetProperty<unsigned int>( "FontSize", check );
	const auto& font = GetResourceManager().GetFont( font_name );

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	// Check Pane.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( 0.f, check->GetAllocation().height / 2.f - box_size / 2.f ),
			sf::Vector2f( box_size, box_size ),
			border_width,
			background_color,
			border_color,
			-border_color_shift
		)
	);

	if( check->IsActive() ) {
		float diff( box_size - check_size );

		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					box_size / 2 - check_size / 2,
					check->GetAllocation().height / 2.f - box_size / 2.f + diff / 2.f,
					check_size - 1.f,
					check_size - 1.f
				),
				check_color
			)
		);
	}

	// Label.
	if( check->GetLabel().getSize() > 0 ) {
		auto metrics = GetTextStringMetrics( check->GetLabel(), *font, font_size );
		metrics.y = GetFontLineHeight( *font, font_size );

		sf::Text text( check->GetLabel(), *font, font_size );
		text.setPosition(
			box_size + spacing,
			check->GetAllocation().height / 2.f - metrics.y / 2.f
		);
		text.setFillColor( color );
		queue->Add( Renderer::Get().CreateText( text ) );
	}

	return queue;
}
Exemplo n.º 2
0
std::unique_ptr<RenderQueue> BREW::CreateEntryDrawable( std::shared_ptr<const Entry> entry ) const {
	auto border_color = GetProperty<sf::Color>( "BorderColor", entry );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", entry );
	auto text_color = GetProperty<sf::Color>( "Color", entry );
	auto cursor_color = GetProperty<sf::Color>( "Color", entry );
	auto text_padding = GetProperty<float>( "Padding", entry );
	auto cursor_thickness = GetProperty<float>( "Thickness", entry );
	auto border_width = GetProperty<float>( "BorderWidth", entry );
	auto border_color_shift = GetProperty<int>( "BorderColorShift", entry );
	const auto& font_name = GetProperty<std::string>( "FontName", entry );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto font_size = GetProperty<unsigned int>( "FontSize", entry );

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	// Pane.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( 0.f, 0.f ),
			sf::Vector2f( entry->GetAllocation().width, entry->GetAllocation().height ),
			border_width,
			background_color,
			border_color,
			-border_color_shift
		)
	);

	auto line_height = GetFontLineHeight( *font, font_size );
	sf::Text vis_label( entry->GetVisibleText(), *font, font_size );
	vis_label.setFillColor( text_color );
	vis_label.setPosition( text_padding, entry->GetAllocation().height / 2.f - line_height / 2.f );

	queue->Add( Renderer::Get().CreateText( vis_label ) );

	// Draw cursor if entry is active and cursor is visible.
	if( entry->HasFocus() && entry->IsCursorVisible() ) {
		sf::String cursor_string( entry->GetVisibleText() );
		if( entry->GetCursorPosition() - entry->GetVisibleOffset() < static_cast<int>( cursor_string.getSize() ) ) {
			cursor_string.erase( static_cast<std::size_t>( entry->GetCursorPosition() - entry->GetVisibleOffset() ), cursor_string.getSize() );
		}

		// Get metrics.
		sf::Vector2f metrics( GetTextStringMetrics( cursor_string, *font, font_size ) );

		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					metrics.x + text_padding,
					entry->GetAllocation().height / 2.f - line_height / 2.f,
					cursor_thickness,
					line_height
				),
				cursor_color
			)
		);
	}

	return queue;
}
Exemplo n.º 3
0
std::unique_ptr<RenderQueue> BREW::CreateSpinButtonDrawable( std::shared_ptr<const SpinButton> spinbutton ) const {
	auto border_color = GetProperty<sf::Color>( "BorderColor", spinbutton );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", spinbutton );
	auto text_color = GetProperty<sf::Color>( "Color", spinbutton );
	auto cursor_color = GetProperty<sf::Color>( "Color", spinbutton );
	auto text_padding = GetProperty<float>( "Padding", spinbutton );
	auto cursor_thickness = GetProperty<float>( "Thickness", spinbutton );
	auto border_width = GetProperty<float>( "BorderWidth", spinbutton );
	auto border_color_shift = GetProperty<int>( "BorderColorShift", spinbutton );
	const auto& font_name = GetProperty<std::string>( "FontName", spinbutton );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto font_size = GetProperty<unsigned int>( "FontSize", spinbutton );
	auto stepper_aspect_ratio = GetProperty<float>( "StepperAspectRatio", spinbutton );
	auto stepper_color = GetProperty<sf::Color>( "StepperBackgroundColor", spinbutton );
	auto stepper_border_color = GetProperty<sf::Color>( "BorderColor", spinbutton );
	auto stepper_arrow_color = GetProperty<sf::Color>( "StepperArrowColor", spinbutton );

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	// Pane.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( 0.f, 0.f ),
			sf::Vector2f( spinbutton->GetAllocation().width, spinbutton->GetAllocation().height ),
			border_width,
			background_color,
			border_color,
			-border_color_shift
		)
	);

	auto button_width = ( spinbutton->GetAllocation().height / 2.f ) * stepper_aspect_ratio;

	// Up Stepper.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( spinbutton->GetAllocation().width - button_width - border_width, border_width ),
			sf::Vector2f( button_width, spinbutton->GetAllocation().height / 2.f - border_width ),
			border_width,
			stepper_color,
			stepper_border_color,
			spinbutton->IsIncreaseStepperPressed() ? -border_color_shift : border_color_shift
		)
	);

	// Up Stepper Triangle.
	queue->Add(
		Renderer::Get().CreateTriangle(
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 2.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 6.f ),
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f * 3.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 3.f ),
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 3.f ),
			stepper_arrow_color
		)
	);

	// Down Stepper.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( spinbutton->GetAllocation().width - button_width - border_width, spinbutton->GetAllocation().height / 2.f ),
			sf::Vector2f( button_width, spinbutton->GetAllocation().height / 2.f - border_width ),
			border_width,
			stepper_color,
			stepper_border_color,
			spinbutton->IsDecreaseStepperPressed() ? -border_color_shift : border_color_shift
		)
	);

	// Down Stepper Triangle.
	queue->Add(
		Renderer::Get().CreateTriangle(
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 2.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 6.f ),
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 3.f ),
			sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f * 3.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 3.f ),
			stepper_arrow_color
		)
	);

	auto line_height = GetFontLineHeight( *font, font_size );
	sf::Text vis_label( spinbutton->GetVisibleText(), *font, font_size );
	vis_label.setFillColor( text_color );
	vis_label.setPosition( text_padding, spinbutton->GetAllocation().height / 2.f - line_height / 2.f );

	queue->Add( Renderer::Get().CreateText( vis_label ) );

	// Draw cursor if spinbutton is active and cursor is visible.
	if( spinbutton->HasFocus() && spinbutton->IsCursorVisible() ) {
		sf::String cursor_string( spinbutton->GetVisibleText() );
		if( spinbutton->GetCursorPosition() - spinbutton->GetVisibleOffset() < static_cast<int>( cursor_string.getSize() ) ) {
			cursor_string.erase( static_cast<std::size_t>( spinbutton->GetCursorPosition() - spinbutton->GetVisibleOffset() ), cursor_string.getSize() );
		}

		// Get metrics.
		sf::Vector2f metrics( GetTextStringMetrics( cursor_string, *font, font_size ) );

		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					metrics.x + text_padding,
					spinbutton->GetAllocation().height / 2.f - line_height / 2.f,
					cursor_thickness,
					line_height
				),
				cursor_color
			)
		);
	}

	return queue;
}
Exemplo n.º 4
0
std::unique_ptr<RenderQueue> BREW::CreateFrameDrawable( std::shared_ptr<const Frame> frame ) const {
	auto border_color = GetProperty<sf::Color>( "BorderColor", frame );
	auto color = GetProperty<sf::Color>( "Color", frame );
	auto border_width = GetProperty<float>( "BorderWidth", frame );
	const auto& font_name = GetProperty<std::string>( "FontName", frame );
	auto font_size = GetProperty<unsigned int>( "FontSize", frame );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto label_padding = GetProperty<float>( "LabelPadding", frame );
	auto line_height = GetFontLineHeight( *font, font_size );

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	// Right
	queue->Add(
		Renderer::Get().CreateLine(
			sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, line_height / 2.f + border_width / 2.f ),
			sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, frame->GetAllocation().height - border_width ),
			border_color,
			border_width
		)
	);

	// Bottom
	queue->Add(
		Renderer::Get().CreateLine(
			sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, frame->GetAllocation().height - border_width ),
			sf::Vector2f( border_width / 2.f, frame->GetAllocation().height - border_width ),
			border_color,
			border_width
		)
	);

	// Left
	queue->Add(
		Renderer::Get().CreateLine(
			sf::Vector2f( border_width / 2.f, frame->GetAllocation().height - border_width ),
			sf::Vector2f( border_width / 2.f, line_height / 2.f + border_width / 2.f ),
			border_color,
			border_width
		)
	);

	auto label_start_x = line_height;
	auto label_end_x = line_height;

	auto alignment = frame->GetAlignment().x;

	if( frame->GetLabel().getSize() > 0 ) {
		auto metrics = GetTextStringMetrics( frame->GetLabel(), *font, font_size );
		metrics.x += ( 2 * label_padding );

		label_start_x += ( alignment * ( frame->GetAllocation().width - 2 * line_height - metrics.x ) );
		label_end_x += ( metrics.x + alignment * ( frame->GetAllocation().width - 2 * line_height - metrics.x ) );

		sf::Text text( frame->GetLabel(), *font, font_size );
		text.setPosition( label_start_x + label_padding, border_width / 2.f );
		text.setColor( color );
		queue->Add( Renderer::Get().CreateText( text ) );
	}

	// Top Left
	queue->Add(
		Renderer::Get().CreateLine(
			sf::Vector2f( border_width / 2.f, line_height / 2.f + border_width / 2.f ),
			sf::Vector2f( label_start_x - .5f * border_width, line_height / 2.f + border_width / 2.f ),
			border_color,
			border_width
		)
	);

	// Top Right
	queue->Add(
		Renderer::Get().CreateLine(
			sf::Vector2f( label_end_x + .5f * border_width, line_height / 2.f + border_width / 2.f ),
			sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, line_height / 2.f + border_width / 2.f ),
			border_color,
			border_width
		)
	);

	return queue;
}
Exemplo n.º 5
0
std::unique_ptr<RenderQueue> BREW::CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const {
    auto border_color = GetProperty<sf::Color>( "BorderColor", listbox );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", listbox );
    auto highlighted_color = GetProperty<sf::Color>( "HighlightedColor", listbox );
    auto selected_color = GetProperty<sf::Color>( "SelectedColor", listbox );
	auto text_color = GetProperty<sf::Color>( "Color", listbox );
	auto text_padding = GetProperty<float>( "Padding", listbox );
	auto border_width = GetProperty<float>( "BorderWidth", listbox );
	auto border_color_shift = GetProperty<int>( "BorderColorShift", listbox );
	const auto& font_name = GetProperty<std::string>( "FontName", listbox );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto font_size = GetProperty<unsigned int>( "FontSize", listbox );

    std::unique_ptr<RenderQueue> queue( new RenderQueue );

    // Pane.
	queue->Add(
		Renderer::Get().CreatePane(
			sf::Vector2f( 0.f, 0.f ),
			sf::Vector2f( listbox->GetAllocation().width, listbox->GetAllocation().height ),
			border_width,
			background_color,
			border_color,
			-border_color_shift
		)
	);

    // Items.
    sf::Vector2f itemPosition = sf::Vector2f( border_width + text_padding, border_width + text_padding );
    for( ListBox::IndexType i = listbox->GetFirstDisplayedItemIndex();
        i < std::min(listbox->GetFirstDisplayedItemIndex() + listbox->GetMaxDisplayedItemsCount(), listbox->GetItemsCount());
        ++i ) {
        auto& itemText = listbox->GetDisplayedItemText( i );

        auto metrics = GetTextStringMetrics( itemText, *font, font_size );
		metrics.y = GetFontLineHeight( *font, font_size ); // Text only size

        auto item_height = listbox->GetItemHeight(); // Height of an item (including the image)

        sf::Text text( itemText, *font, font_size );
        text.setPosition(
            itemPosition.x + ( listbox->GetImagesSize() != sf::Vector2f() ? text_padding + listbox->GetImagesSize().x : 0.f ),
            itemPosition.y + item_height/2.f - metrics.y / 2.f
        );
        text.setColor(text_color);

        if( listbox->IsItemSelected( i ) ) {
            queue->Add(
                Renderer::Get().CreateRect(
                    sf::FloatRect(
                        itemPosition.x - text_padding,
                        itemPosition.y - text_padding,
                        listbox->GetAllocation().width - 2 * border_width,
                        std::min(item_height + text_padding * 2, listbox->GetAllocation().height - (itemPosition.y - text_padding) - border_width)
                        // Avoid the selection box to go further than the widget's height when the last displayed item padding space is not fully displayed.
                    ),
                    selected_color
                )
            );
        } else if( i == listbox->GetHighlightedItem() ) {
            queue->Add(
                Renderer::Get().CreateRect(
                    sf::FloatRect(
                        itemPosition.x - text_padding,
                        itemPosition.y - text_padding,
                        listbox->GetAllocation().width - 2 * border_width,
                        std::min(item_height + text_padding * 2, listbox->GetAllocation().height - (itemPosition.y - text_padding) - border_width)
                        // Avoid the highlight box to go further than the widget's height when the last displayed item padding space is not fully displayed.
                    ),
                    highlighted_color
                )
            );
        }

        if( listbox->GetImagesSize() != sf::Vector2f() && listbox->GetItemImage( i ).getSize() != sf::Vector2u() ) {
            auto texture = Renderer::Get().LoadTexture( listbox->GetItemImage( i ) );
            queue->Add(
        		Renderer::Get().CreateSprite(
        			sf::FloatRect(
        				itemPosition.x,
        				itemPosition.y,
        				listbox->GetImagesSize().x,
        				listbox->GetImagesSize().y
        			),
        			texture
        		)
        	);
        }

        queue->Add( Renderer::Get().CreateText(text) );

        itemPosition += sf::Vector2f( 0.f, item_height + text_padding * 2 );
    }

    return queue;
}