88#include < SFML/OpenGL.hpp>
99
1010#include < cmath>
11+ #include < cstdint>
1112
1213int main () {
1314 // Create the main SFML window
14- 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 );
1516
1617 // We have to do this because we don't use SFML to draw.
1718 app_window.resetGLStates ();
@@ -49,20 +50,18 @@ int main() {
4950
5051 // Create a table to put the scrollbars and scrollable canvas in.
5152 auto table = sfg::Table::Create ();
52- table->Attach ( sfml_scrollable_canvas, sf::Rect<sf::Uint32 >( 0 , 0 , 1 , 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
53- table->Attach ( vertical_scrollbar, sf::Rect<sf::Uint32 >( 1 , 0 , 1 , 1 ), 0 , sfg::Table::FILL );
54- table->Attach ( horizontal_scrollbar, sf::Rect<sf::Uint32 >( 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 );
5556
5657 // Add the Canvases to the windows.
5758 opengl_window->Add ( opengl_canvas );
5859 sfml_window->Add ( sfml_canvas );
5960 sfml_scrollable_window->Add ( table );
6061
6162 // Create an sf::Sprite for demonstration purposes.
62- sf::Texture texture;
63- texture.loadFromFile ( " data/sfgui.png" );
64- sf::Sprite sprite;
65- sprite.setTexture ( texture );
63+ const sf::Texture texture ( " data/sfgui.png" );
64+ const sf::Sprite sprite ( texture );
6665
6766 // Create an sf::RectangleShape for demonstration purposes.
6867 sf::RectangleShape rectangle_shape ( sf::Vector2f ( 218 .f * 20 , 84 .f * 20 ) );
@@ -88,11 +87,11 @@ int main() {
8887 vertical_adjustment->SetPageSize ( scrollable_canvas_size );
8988
9089 horizontal_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &horizontal_adjustment]() {
91- view.setCenter ( horizontal_adjustment->GetValue (), view.getCenter ().y );
90+ view.setCenter ( { horizontal_adjustment->GetValue (), view.getCenter ().y } );
9291 } );
9392
9493 vertical_adjustment->GetSignal ( sfg::Adjustment::OnChange ).Connect ( [&view, &vertical_adjustment]() {
95- view.setCenter ( view.getCenter ().x , vertical_adjustment->GetValue () );
94+ view.setCenter ( { view.getCenter ().x , vertical_adjustment->GetValue () } );
9695 } );
9796
9897 // Because Canvases provide a virtual surface to draw
@@ -118,14 +117,12 @@ int main() {
118117 // Start the game loop
119118 while ( app_window.isOpen () ) {
120119 // Process events
121- sf::Event event;
122-
123- while ( app_window.pollEvent ( event ) ) {
120+ while ( const std::optional event = app_window.pollEvent () ) {
124121 // Handle events
125- desktop.HandleEvent ( event );
122+ desktop.HandleEvent ( * event );
126123
127124 // Close window : exit
128- if ( event. type == sf::Event::Closed ) {
125+ if ( event-> is < sf::Event::Closed>() ) {
129126 return EXIT_SUCCESS;
130127 }
131128 }
@@ -173,14 +170,14 @@ int main() {
173170 glPushMatrix ();
174171 glLoadIdentity ();
175172
176- 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 ) );
177174
178175 static const auto pi = 3 .1415926535897932384626433832795f ;
179176 static const auto fov = 90 .f ;
180177 static const auto near_distance = 1 .f ;
181178 static const auto far_distance = 20 .f ;
182179
183- auto aspect = opengl_canvas->GetAllocation ().width / opengl_canvas->GetAllocation ().height ;
180+ auto aspect = opengl_canvas->GetAllocation ().size . x / opengl_canvas->GetAllocation ().size . y ;
184181 auto frustum_height = std::tan ( fov / 360 * pi ) * near_distance;
185182 auto frustum_width = frustum_height * aspect;
186183
@@ -227,7 +224,7 @@ int main() {
227224 sfml_scrollable_canvas->Unbind ();
228225
229226 // This is important.
230- app_window.setActive ( true );
227+ ( void ) app_window.setActive ( true );
231228
232229 // Draw the GUI
233230 sfgui.Display ( app_window );
0 commit comments