1212
1313int main () {
1414 // Create the main SFML window
15- sf::RenderWindow app_window ( sf::VideoMode ( 800 , 600 ), " SFGUI Canvas Example" , sf::Style::Titlebar | sf::Style::Close );
15+ sf::RenderWindow app_window ( sf::VideoMode ( { 800 , 600 } ), " SFGUI Canvas Example" , sf::Style::Titlebar | sf::Style::Close );
1616
1717 // We have to do this because we don't use SFML to draw.
1818 app_window.resetGLStates ();
@@ -50,20 +50,18 @@ int main() {
5050
5151 // Create a table to put the scrollbars and scrollable canvas in.
5252 auto table = sfg::Table::Create ();
53- table->Attach ( sfml_scrollable_canvas, sf::Rect<std::uint32_t >( ( 0 , 0 ), ( 1 , 1 ) ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
54- table->Attach ( vertical_scrollbar, sf::Rect<std::uint32_t >( ( 1 , 0 ), ( 1 , 1 ) ), 0 , sfg::Table::FILL );
55- table->Attach ( horizontal_scrollbar, sf::Rect<std::uint32_t >( ( 0 , 1 ), ( 1 , 1 ) ), sfg::Table::FILL, 0 );
53+ table->Attach ( sfml_scrollable_canvas, sf::Rect<std::uint32_t >( { 0 , 0 }, { 1 , 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
54+ table->Attach ( vertical_scrollbar, sf::Rect<std::uint32_t >( { 1 , 0 }, { 1 , 1 } ), 0 , sfg::Table::FILL );
55+ table->Attach ( horizontal_scrollbar, sf::Rect<std::uint32_t >( { 0 , 1 }, { 1 , 1 } ), sfg::Table::FILL, 0 );
5656
5757 // Add the Canvases to the windows.
5858 opengl_window->Add ( opengl_canvas );
5959 sfml_window->Add ( sfml_canvas );
6060 sfml_scrollable_window->Add ( table );
6161
6262 // Create an sf::Sprite for demonstration purposes.
63- sf::Texture texture;
64- texture.loadFromFile ( " data/sfgui.png" );
65- sf::Sprite sprite;
66- sprite.setTexture ( texture );
63+ const sf::Texture texture ( " data/sfgui.png" );
64+ const sf::Sprite sprite ( texture );
6765
6866 // Create an sf::RectangleShape for demonstration purposes.
6967 sf::RectangleShape rectangle_shape ( sf::Vector2f ( 218 .f * 20 , 84 .f * 20 ) );
@@ -89,11 +87,11 @@ int main() {
8987 vertical_adjustment->SetPageSize ( scrollable_canvas_size );
9088
9189 horizontal_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &horizontal_adjustment]() {
92- view.setCenter ( horizontal_adjustment->GetValue (), view.getCenter ().y );
90+ view.setCenter ( { horizontal_adjustment->GetValue (), view.getCenter ().y } );
9391 } );
9492
9593 vertical_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &vertical_adjustment]() {
96- view.setCenter ( view.getCenter ().x , vertical_adjustment->GetValue () );
94+ view.setCenter ( { view.getCenter ().x , vertical_adjustment->GetValue ()} );
9795 } );
9896
9997 // Because Canvases provide a virtual surface to draw
@@ -119,14 +117,12 @@ int main() {
119117 // Start the game loop
120118 while ( app_window.isOpen () ) {
121119 // Process events
122- sf::Event event;
123-
124- while ( app_window.pollEvent ( event ) ) {
120+ while ( const std::optional event = app_window.pollEvent () ) {
125121 // Handle events
126- desktop.HandleEvent ( event );
122+ desktop.HandleEvent ( * event );
127123
128124 // Close window : exit
129- if ( event. type == sf::Event::Closed ) {
125+ if ( event-> is < sf::Event::Closed>() ) {
130126 return EXIT_SUCCESS;
131127 }
132128 }
@@ -174,14 +170,14 @@ int main() {
174170 glPushMatrix ();
175171 glLoadIdentity ();
176172
177- glViewport ( 0 , 0 , static_cast <int >( opengl_canvas->GetAllocation ().width ), static_cast <int >( opengl_canvas->GetAllocation ().height ) );
173+ glViewport ( 0 , 0 , static_cast <int >( opengl_canvas->GetAllocation ().size . x ), static_cast <int >( opengl_canvas->GetAllocation ().size . y ) );
178174
179175 static const auto pi = 3 .1415926535897932384626433832795f ;
180176 static const auto fov = 90 .f ;
181177 static const auto near_distance = 1 .f ;
182178 static const auto far_distance = 20 .f ;
183179
184- auto aspect = opengl_canvas->GetAllocation ().width / opengl_canvas->GetAllocation ().height ;
180+ auto aspect = opengl_canvas->GetAllocation ().size . x / opengl_canvas->GetAllocation ().size . y ;
185181 auto frustum_height = std::tan ( fov / 360 * pi ) * near_distance;
186182 auto frustum_width = frustum_height * aspect;
187183
@@ -228,7 +224,7 @@ int main() {
228224 sfml_scrollable_canvas->Unbind ();
229225
230226 // This is important.
231- app_window.setActive ( true );
227+ ( void ) app_window.setActive ( true );
232228
233229 // Draw the GUI
234230 sfgui.Display ( app_window );
0 commit comments