InvalidateImpl is called by SFGUI whenever something happens that might make the widget look different. It returns an sfg::RenderQueue containing the graphical elements that will be rendered to display the widget on the screen.
| 57 | // sfg::RenderQueue containing the graphical elements that will |
| 58 | // be rendered to display the widget on the screen. |
| 59 | std::unique_ptr<sfg::RenderQueue> InvalidateImpl() const override { |
| 60 | // In order to support engine themes, you should not hard-code |
| 61 | // graphical parameters, but instead retrieve the properties you need |
| 62 | // from the currently active engine. These properties determine |
| 63 | // what your widget looks like and can be adjusted to affect a |
| 64 | // large number of widgets at the same time. |
| 65 | auto background_color = sfg::Context::Get().GetEngine().GetProperty<sf::Color>( "BackgroundColor", shared_from_this() ); |
| 66 | const auto& font_name = sfg::Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ); |
| 67 | auto font_size = sfg::Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ); |
| 68 | |
| 69 | // Fonts are stored in the engine resource manager. Once you have the name |
| 70 | // of a font that has been loaded, you can get it from the resource manager. |
| 71 | const auto& font = sfg::Context::Get().GetEngine().GetResourceManager().GetFont( font_name ); |
| 72 | |
| 73 | std::unique_ptr<sfg::RenderQueue> queue( new sfg::RenderQueue ); |
| 74 | |
| 75 | if( GetLabel().getSize() > 0 ) { |
| 76 | auto metrics = sfg::Context::Get().GetEngine().GetTextStringMetrics( GetLabel(), *font, font_size ); |
| 77 | metrics.y = sfg::Context::Get().GetEngine().GetFontLineHeight( *font, font_size ); |
| 78 | |
| 79 | // SFGUI widgets are made out of elementary pieces. |
| 80 | // You have to request the renderer to give you each of |
| 81 | // these pieces through one of the Create* methods. |
| 82 | // You add these pieces to the RenderQueue that you return and it |
| 83 | // will be rendered where the widget is displayed on the screen |
| 84 | |
| 85 | // Refer to the sfg::Renderer documentation for more information |
| 86 | // on the Create* methods. |
| 87 | |
| 88 | auto inverted_color = sf::Color::White - background_color; |
| 89 | inverted_color.a = 255; |
| 90 | |
| 91 | // Outer pane. |
| 92 | queue->Add( |
| 93 | sfg::Renderer::Get().CreatePane( |
| 94 | sf::Vector2f( 0.f, 0.f ), |
| 95 | GetAllocation().size, |
| 96 | 5.f, |
| 97 | inverted_color, |
| 98 | background_color, |
| 99 | 20.f |
| 100 | ) |
| 101 | ); |
| 102 | |
| 103 | auto inner_border_color = sf::Color::Green; |
| 104 | |
| 105 | // If the widget is active (currently pressed) change the inner border to red |
| 106 | if( GetState() == State::ACTIVE ) { |
| 107 | inner_border_color = sf::Color::Red; |
| 108 | } |
| 109 | |
| 110 | // Inner pane. |
| 111 | queue->Add( |
| 112 | sfg::Renderer::Get().CreatePane( |
| 113 | GetAllocation().size / 4.f, |
| 114 | GetAllocation().size / 2.f, |
| 115 | 5.f, |
| 116 | sf::Color( |
nothing calls this directly
no test coverage detected