| 9 | namespace eng { |
| 10 | |
| 11 | std::unique_ptr<RenderQueue> BREW::CreateButtonDrawable( std::shared_ptr<const Button> button ) const { |
| 12 | auto border_color = GetProperty<sf::Color>( "BorderColor", button ); |
| 13 | auto border_color_shift = GetProperty<int>( "BorderColorShift", button ); |
| 14 | auto background_color = GetProperty<sf::Color>( "BackgroundColor", button ); |
| 15 | auto color = GetProperty<sf::Color>( "Color", button ); |
| 16 | auto border_width = GetProperty<float>( "BorderWidth", button ); |
| 17 | auto spacing = GetProperty<float>( "Spacing", button ); |
| 18 | const auto& font_name = GetProperty<std::string>( "FontName", button ); |
| 19 | auto font_size = GetProperty<unsigned int>( "FontSize", button ); |
| 20 | const auto& font = GetResourceManager().GetFont( font_name ); |
| 21 | |
| 22 | if( button->GetState() == Button::State::ACTIVE ) { |
| 23 | border_color_shift = -border_color_shift; |
| 24 | } |
| 25 | |
| 26 | std::unique_ptr<RenderQueue> queue( new RenderQueue ); |
| 27 | |
| 28 | // Pane. |
| 29 | queue->Add( |
| 30 | Renderer::Get().CreatePane( |
| 31 | sf::Vector2f( 0.f, 0.f ), |
| 32 | sf::Vector2f( button->GetAllocation().size.x, button->GetAllocation().size.y ), |
| 33 | border_width, |
| 34 | background_color, |
| 35 | border_color, |
| 36 | border_color_shift |
| 37 | ) |
| 38 | ); |
| 39 | |
| 40 | // Label. |
| 41 | if( button->GetLabel().getSize() > 0 ) { |
| 42 | auto metrics = GetTextStringMetrics( button->GetLabel(), *font, font_size ); |
| 43 | metrics.y = GetFontLineHeight( *font, font_size ); |
| 44 | |
| 45 | sf::Text text( *font, button->GetLabel(), font_size ); |
| 46 | auto offset = ( button->GetState() == Button::State::ACTIVE ) ? border_width : 0.f; |
| 47 | sfg::Widget::PtrConst child( button->GetChild() ); |
| 48 | |
| 49 | if( !child ) { |
| 50 | text.setPosition( |
| 51 | { button->GetAllocation().size.x / 2.f - metrics.x / 2.f + offset, |
| 52 | button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } |
| 53 | ); |
| 54 | } |
| 55 | else { |
| 56 | float width( button->GetAllocation().size.x - spacing - child->GetAllocation().size.x ); |
| 57 | |
| 58 | text.setPosition( |
| 59 | { child->GetAllocation().size.x + spacing + (width / 2.f - metrics.x / 2.f) + offset, |
| 60 | button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | text.setFillColor( color ); |
| 65 | queue->Add( Renderer::Get().CreateText( text ) ); |
| 66 | } |
| 67 | |
| 68 | return queue; |
no test coverage detected