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,9 +50,9 @@ 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 );
@@ -61,9 +61,8 @@ int main() {
6161
6262 // Create an sf::Sprite for demonstration purposes.
6363 sf::Texture texture;
64- texture.loadFromFile ( " data/sfgui.png" );
65- sf::Sprite sprite;
66- sprite.setTexture ( texture );
64+ (void )texture.loadFromFile ( " data/sfgui.png" );
65+ sf::Sprite sprite ( texture );
6766
6867 // Create an sf::RectangleShape for demonstration purposes.
6968 sf::RectangleShape rectangle_shape ( sf::Vector2f ( 218 .f * 20 , 84 .f * 20 ) );
@@ -89,11 +88,11 @@ int main() {
8988 vertical_adjustment->SetPageSize ( scrollable_canvas_size );
9089
9190 horizontal_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &horizontal_adjustment]() {
92- view.setCenter ( horizontal_adjustment->GetValue (), view.getCenter ().y );
91+ view.setCenter ( { horizontal_adjustment->GetValue (), view.getCenter ().y } );
9392 } );
9493
9594 vertical_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &vertical_adjustment]() {
96- view.setCenter ( view.getCenter ().x , vertical_adjustment->GetValue () );
95+ view.setCenter ( { view.getCenter ().x , vertical_adjustment->GetValue ()} );
9796 } );
9897
9998 // Because Canvases provide a virtual surface to draw
@@ -119,14 +118,12 @@ int main() {
119118 // Start the game loop
120119 while ( app_window.isOpen () ) {
121120 // Process events
122- sf::Event event;
123-
124- while ( app_window.pollEvent ( event ) ) {
121+ while ( const std::optional event = app_window.pollEvent () ) {
125122 // Handle events
126- desktop.HandleEvent ( event );
123+ desktop.HandleEvent ( * event );
127124
128125 // Close window : exit
129- if ( event. type == sf::Event::Closed ) {
126+ if ( event-> is < sf::Event::Closed>() ) {
130127 return EXIT_SUCCESS;
131128 }
132129 }
@@ -174,14 +171,14 @@ int main() {
174171 glPushMatrix ();
175172 glLoadIdentity ();
176173
177- glViewport ( 0 , 0 , static_cast <int >( opengl_canvas->GetAllocation ().width ), static_cast <int >( opengl_canvas->GetAllocation ().height ) );
174+ glViewport ( 0 , 0 , static_cast <int >( opengl_canvas->GetAllocation ().size . x ), static_cast <int >( opengl_canvas->GetAllocation ().size . y ) );
178175
179176 static const auto pi = 3 .1415926535897932384626433832795f ;
180177 static const auto fov = 90 .f ;
181178 static const auto near_distance = 1 .f ;
182179 static const auto far_distance = 20 .f ;
183180
184- auto aspect = opengl_canvas->GetAllocation ().width / opengl_canvas->GetAllocation ().height ;
181+ auto aspect = opengl_canvas->GetAllocation ().size . x / opengl_canvas->GetAllocation ().size . y ;
185182 auto frustum_height = std::tan ( fov / 360 * pi ) * near_distance;
186183 auto frustum_width = frustum_height * aspect;
187184
@@ -228,7 +225,7 @@ int main() {
228225 sfml_scrollable_canvas->Unbind ();
229226
230227 // This is important.
231- app_window.setActive ( true );
228+ ( void ) app_window.setActive ( true );
232229
233230 // Draw the GUI
234231 sfgui.Display ( app_window );
0 commit comments