Exemple #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;
}
/*----------------------------------------------------------------------------------------------
	Measure the given text.
----------------------------------------------------------------------------------------------*/
HRESULT VwGraphicsCairo::GetTextExtent(int cch, const OLECHAR * prgch, int * pdx, int * pdy)
{
#if DEBUG
	if (m_loggingFile != NULL)
	{
		UnicodeString8 text(prgch, (int)cch);
		fprintf(m_loggingFile, "GetTextExtent %p %d \"%s\"\n", this, cch, text.c_str());
		fflush(m_loggingFile);
	}
#endif
 BEGIN_COM_METHOD;
	CheckDc();

	int x,y;
	if (cch)
	{
		GetTextExtentHelper(cch, prgch, &x,&y, pdx, pdy);
	}
	else
	{
		*pdx = 0;
		*pdy = GetFontLineHeight();
	}

 END_COM_METHOD(g_fact, IID_IVwGraphics);
}
Exemple #3
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;
}
Exemple #4
0
RenderQueue* BREW::CreateToggleButtonDrawable( SharedPtr<const ToggleButton> button ) const {
	sf::Color border_color( GetProperty<sf::Color>( "BorderColor", button ) );
	int border_color_shift( GetProperty<int>( "BorderColorShift", button ) );
	sf::Color background_color( GetProperty<sf::Color>( "BackgroundColor", button ) );
	sf::Color color( GetProperty<sf::Color>( "Color", button ) );
	float border_width( GetProperty<float>( "BorderWidth", button ) );
	const std::string& font_name( GetProperty<std::string>( "FontName", button ) );
	unsigned int font_size( GetProperty<unsigned int>( "FontSize", button ) );
	const sf::Font& font( *GetResourceManager().GetFont( font_name ) );

	if( ( button->GetState() == Button::ACTIVE ) || button->IsActive() ) {
		border_color_shift = -border_color_shift;
	}

	RenderQueue* queue( new RenderQueue );

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

	// Label.
	if( button->GetLabel().getSize() > 0 ) {
		sf::Vector2f metrics = GetTextMetrics( button->GetLabel(), font, font_size );
		metrics.y = GetFontLineHeight( font, font_size );

		sf::Text text( button->GetLabel(), font, font_size );
		float offset = ( ( button->GetState() == Button::ACTIVE ) || button->IsActive() ) ? border_width : 0.f;

		text.setPosition(
			button->GetAllocation().width / 2.f - metrics.x / 2.f + offset,
			button->GetAllocation().height / 2.f - metrics.y / 2.f + offset
		);

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

	return queue;
}
Exemple #5
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;
}
Exemple #6
0
RenderQueue* BREW::CreateWindowDrawable( SharedPtr<const Window> window ) const {
	RenderQueue* queue( new RenderQueue );
	sf::Color background_color( GetProperty<sf::Color>( "BackgroundColor", window ) );
	sf::Color border_color( GetProperty<sf::Color>( "BorderColor", window ) );
	sf::Color title_background_color( GetProperty<sf::Color>( "TitleBackgroundColor", window ) );
	sf::Color title_text_color( GetProperty<sf::Color>( "Color", window ) );
	int border_color_shift( GetProperty<int>( "BorderColorShift", window ) );
	float border_width( GetProperty<float>( "BorderWidth", window ) );
	float title_padding( GetProperty<float>( "TitlePadding", window ) );
	float shadow_distance( GetProperty<float>( "ShadowDistance", window ) );
	float handle_size( GetProperty<float>( "HandleSize", window ) );
	sf::Uint8 shadow_alpha( GetProperty<sf::Uint8>( "ShadowAlpha", window ) );
	unsigned int title_font_size( GetProperty<unsigned int>( "FontSize", window ) );
	const sf::Font& title_font( *GetResourceManager().GetFont( GetProperty<std::string>( "FontName", window ) ) );
	float title_size( GetFontLineHeight( title_font, title_font_size ) + 2 * title_padding );

	if( window->HasStyle( Window::SHADOW ) ) {
		// Shadow.
		sf::Color shadow_color( 0, 0, 0, shadow_alpha );

		sf::FloatRect shadow_rect(
			shadow_distance,
			shadow_distance,
			window->GetAllocation().width,
			window->GetAllocation().height
		);

		queue->Add(
			Renderer::Get().CreateRect(
				shadow_rect,
				shadow_color
			)
		);
	}

	if( window->HasStyle( Window::BACKGROUND ) ) {
		// Pane.
		queue->Add(
			Renderer::Get().CreatePane(
				sf::Vector2f( 0.f, 0.f ),
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ),
				border_width,
				background_color,
				border_color,
				border_color_shift
			)
		);
	}

	if( window->HasStyle( Window::RESIZE ) ) {
		queue->Add(
			Renderer::Get().CreateTriangle(
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height - handle_size ),
				sf::Vector2f( window->GetAllocation().width - handle_size, window->GetAllocation().height ),
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ),
				title_background_color
			)
		);
	}


	if( !window->HasStyle( Window::TITLEBAR ) ) {
		title_size = 0;
	}

	if( title_size > 0 ) {
		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					border_width + .1f,
					border_width + .1f,
					window->GetAllocation().width - 2 * border_width,
					title_size
				),
				title_background_color
			)
		);

		// Find out visible text, count in "...".
		float avail_width( window->GetAllocation().width - 2.f * border_width - 2.f * title_padding );

		sf::Text title_text( window->GetTitle(), title_font, title_font_size );

		if( title_text.getLocalBounds().width > avail_width ) {
			sf::Text dots( "...", title_font, title_font_size );
			const sf::String& title_string( window->GetTitle() );
			sf::String visible_title;

			avail_width = window->GetAllocation().width - 2.f * border_width - 2.f * title_padding - dots.getLocalBounds().width;

			for( std::size_t ch_index = 0; ch_index < title_string.getSize(); ++ch_index ) {
				avail_width -= static_cast<float>( title_font.getGlyph( title_string[ch_index], title_font_size, false ).advance );

				if( avail_width < 0.f ) {
					visible_title += "...";
					break;
				}

				visible_title += title_string[ch_index];
			}

			title_text.setString( visible_title );
		}

		// Calculate title text position.
		sf::Vector2f title_position(
			border_width + title_padding,
			border_width + title_size / 2.f - static_cast<float>( title_font_size ) / 2.f
		);

		title_text.setPosition( title_position );
		title_text.setColor( title_text_color );

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

	return queue;
}
Exemple #7
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;
}
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;
}
Exemple #9
0
std::unique_ptr<RenderQueue> BREW::CreateComboBoxDrawable( std::shared_ptr<const ComboBox> combo_box ) const {
	auto border_color = GetProperty<sf::Color>( "BorderColor", combo_box );
	auto border_color_shift = GetProperty<int>( "BorderColorShift", combo_box );
	auto background_color = GetProperty<sf::Color>( "BackgroundColor", combo_box );
	auto highlighted_color = GetProperty<sf::Color>( "HighlightedColor", combo_box );
	auto color = GetProperty<sf::Color>( "Color", combo_box );
	auto arrow_color = GetProperty<sf::Color>( "ArrowColor", combo_box );
	auto border_width = GetProperty<float>( "BorderWidth", combo_box );
	const auto& font_name = GetProperty<std::string>( "FontName", combo_box );
	auto font_size = GetProperty<unsigned int>( "FontSize", combo_box );
	auto padding = GetProperty<float>( "ItemPadding", combo_box );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto line_height = GetFontLineHeight( *font, font_size );

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

	if( combo_box->GetState() == ComboBox::State::ACTIVE ) {
		border_color_shift = -border_color_shift;
	}

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

	if( combo_box->IsDropDownDisplayed() ) {
		const sf::Vector2f item_size(
			combo_box->GetAllocation().width - 2 * border_width,
			line_height + 2 * padding
		);
		sf::Vector2f item_position(
			0.f,
			combo_box->GetAllocation().height
		);

		auto expanded_height = static_cast<float>( combo_box->GetDisplayedItemCount() ) * item_size.y;

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

		// Labels.
		for( ComboBox::IndexType item_index = combo_box->GetDisplayedItemStart(); item_index < combo_box->GetDisplayedItemStart() + combo_box->GetDisplayedItemCount(); ++item_index ) {
			if( combo_box->GetItem( item_index ).getSize() == 0 ) {
				continue;
			}

			if( item_index == combo_box->GetHighlightedItem() ) {
				// Highlighted item background.
				queue->Add(
					Renderer::Get().CreateRect(
						sf::FloatRect(
							item_position.x + border_width,
							item_position.y + border_width,
							item_size.x,
							item_size.y - 2.f * border_width
						),
						highlighted_color
					)
				);
			}

			sf::Text text( combo_box->GetItem( item_index ), *font, font_size );
			text.setPosition( item_position.x + padding, item_position.y + padding );
			text.setColor( color );
			queue->Add( Renderer::Get().CreateText( text ) );

			item_position.y += item_size.y;
		}
	}

	if( combo_box->GetSelectedItem() != ComboBox::NONE ) {
		sf::Text text( combo_box->GetSelectedText(), *font, font_size );
		text.setPosition(
			border_width + padding,
			combo_box->GetAllocation().height / 2.f - line_height / 2.f
		);
		text.setColor( color );
		queue->Add( Renderer::Get().CreateText( text ) );
	}

	// Arrow.
	sf::Vector2f position(
		( combo_box->GetState() == ComboBox::State::ACTIVE ? border_width : 0.f ) + combo_box->GetAllocation().width - padding - GetFontLineHeight( *font, font_size ),
		( combo_box->GetState() == ComboBox::State::ACTIVE ? border_width : 0.f ) + padding
	);

	queue->Add(
		Renderer::Get().CreateTriangle(
			position + sf::Vector2f(
				GetFontLineHeight( *font, font_size ) / 2.f,
				GetFontLineHeight( *font, font_size ) * 3.f / 4.f
			),
			position + sf::Vector2f(
				GetFontLineHeight( *font, font_size ) * 3.f / 4.f,
				GetFontLineHeight( *font, font_size ) / 4.f
			),
			position + sf::Vector2f(
				GetFontLineHeight( *font, font_size ) / 4.f,
				GetFontLineHeight( *font, font_size ) / 4.f
			),
			arrow_color
		)
	);

	return queue;
}