MCPcopy Create free account
hub / github.com/TankOs/SFGUI / CreateCheckButtonDrawable

Method CreateCheckButtonDrawable

src/SFGUI/Engines/BREW/CheckButton.cpp:11–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9namespace eng {
10
11std::unique_ptr<RenderQueue> BREW::CreateCheckButtonDrawable( std::shared_ptr<const CheckButton> check ) const {
12 auto border_color = GetProperty<sf::Color>( "BorderColor", check );
13 auto background_color = GetProperty<sf::Color>( "BackgroundColor", check );
14 auto color = GetProperty<sf::Color>( "Color", check );
15 auto check_color = GetProperty<sf::Color>( "CheckColor", check );
16 auto border_color_shift = GetProperty<int>( "BorderColorShift", check );
17 auto border_width = GetProperty<float>( "BorderWidth", check );
18 auto box_size = GetProperty<float>( "BoxSize", check );
19 auto spacing = GetProperty<float>( "Spacing", check );
20 auto check_size = std::min( box_size, GetProperty<float>( "CheckSize", check ) );
21 const auto& font_name = GetProperty<std::string>( "FontName", check );
22 auto font_size = GetProperty<unsigned int>( "FontSize", check );
23 const auto& font = GetResourceManager().GetFont( font_name );
24
25 std::unique_ptr<RenderQueue> queue( new RenderQueue );
26
27 // Check Pane.
28 queue->Add(
29 Renderer::Get().CreatePane(
30 sf::Vector2f( 0.f, check->GetAllocation().size.y / 2.f - box_size / 2.f ),
31 sf::Vector2f( box_size, box_size ),
32 border_width,
33 background_color,
34 border_color,
35 -border_color_shift
36 )
37 );
38
39 if( check->IsActive() ) {
40 float diff( box_size - check_size );
41
42 queue->Add(
43 Renderer::Get().CreateRect(
44 sf::FloatRect(
45 { box_size / 2 - check_size / 2, check->GetAllocation().size.y / 2.f - box_size / 2.f + diff / 2.f },
46 { check_size - 1.f, check_size - 1.f }
47 ),
48 check_color
49 )
50 );
51 }
52
53 // Label.
54 if( check->GetLabel().getSize() > 0 ) {
55 auto metrics = GetTextStringMetrics( check->GetLabel(), *font, font_size );
56 metrics.y = GetFontLineHeight( *font, font_size );
57
58 sf::Text text( *font, check->GetLabel(), font_size );
59 text.setPosition(
60 { box_size + spacing,
61 check->GetAllocation().size.y / 2.f - metrics.y / 2.f }
62 );
63 text.setFillColor( color );
64 queue->Add( Renderer::Get().CreateText( text ) );
65 }
66
67 return queue;
68}

Callers 1

InvalidateImplMethod · 0.80

Calls 6

GetFontMethod · 0.80
CreatePaneMethod · 0.80
IsActiveMethod · 0.80
CreateRectMethod · 0.80
CreateTextMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected