| 9 | namespace eng { |
| 10 | |
| 11 | std::unique_ptr<RenderQueue> BREW::CreateToggleButtonDrawable( std::shared_ptr<const ToggleButton> 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 | const auto& font_name = GetProperty<std::string>( "FontName", button ); |
| 18 | auto font_size = GetProperty<unsigned int>( "FontSize", button ); |
| 19 | const auto& font = GetResourceManager().GetFont( font_name ); |
| 20 | |
| 21 | if( ( button->GetState() == Button::State::ACTIVE ) || button->IsActive() ) { |
| 22 | border_color_shift = -border_color_shift; |
| 23 | } |
| 24 | |
| 25 | std::unique_ptr<RenderQueue> queue( new RenderQueue ); |
| 26 | |
| 27 | // Pane. |
| 28 | queue->Add( |
| 29 | Renderer::Get().CreatePane( |
| 30 | sf::Vector2f( 0.f, 0.f ), |
| 31 | sf::Vector2f( button->GetAllocation().size.x, button->GetAllocation().size.y ), |
| 32 | border_width, |
| 33 | background_color, |
| 34 | border_color, |
| 35 | border_color_shift |
| 36 | ) |
| 37 | ); |
| 38 | |
| 39 | // Label. |
| 40 | if( button->GetLabel().getSize() > 0 ) { |
| 41 | auto metrics = GetTextStringMetrics( button->GetLabel(), *font, font_size ); |
| 42 | metrics.y = GetFontLineHeight( *font, font_size ); |
| 43 | |
| 44 | sf::Text text( *font, button->GetLabel(), font_size ); |
| 45 | auto offset = ( ( button->GetState() == Button::State::ACTIVE ) || button->IsActive() ) ? border_width : 0.f; |
| 46 | |
| 47 | text.setPosition( |
| 48 | { button->GetAllocation().size.x / 2.f - metrics.x / 2.f + offset, |
| 49 | button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } |
| 50 | ); |
| 51 | |
| 52 | text.setFillColor( color ); |
| 53 | queue->Add( Renderer::Get().CreateText( text ) ); |
| 54 | } |
| 55 | |
| 56 | return queue; |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | } |
no test coverage detected