8
8
#include < SFML/OpenGL.hpp>
9
9
10
10
#include < cmath>
11
+ #include < cstdint>
11
12
12
13
int main () {
13
14
// 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 );
15
16
16
17
// We have to do this because we don't use SFML to draw.
17
18
app_window.resetGLStates ();
@@ -49,20 +50,18 @@ int main() {
49
50
50
51
// Create a table to put the scrollbars and scrollable canvas in.
51
52
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 );
55
56
56
57
// Add the Canvases to the windows.
57
58
opengl_window->Add ( opengl_canvas );
58
59
sfml_window->Add ( sfml_canvas );
59
60
sfml_scrollable_window->Add ( table );
60
61
61
62
// 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 );
66
65
67
66
// Create an sf::RectangleShape for demonstration purposes.
68
67
sf::RectangleShape rectangle_shape ( sf::Vector2f ( 218 .f * 20 , 84 .f * 20 ) );
@@ -88,11 +87,11 @@ int main() {
88
87
vertical_adjustment->SetPageSize ( scrollable_canvas_size );
89
88
90
89
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 } );
92
91
} );
93
92
94
93
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 () } );
96
95
} );
97
96
98
97
// Because Canvases provide a virtual surface to draw
@@ -118,14 +117,12 @@ int main() {
118
117
// Start the game loop
119
118
while ( app_window.isOpen () ) {
120
119
// Process events
121
- sf::Event event;
122
-
123
- while ( app_window.pollEvent ( event ) ) {
120
+ while ( const std::optional event = app_window.pollEvent () ) {
124
121
// Handle events
125
- desktop.HandleEvent ( event );
122
+ desktop.HandleEvent ( * event );
126
123
127
124
// Close window : exit
128
- if ( event. type == sf::Event::Closed ) {
125
+ if ( event-> is < sf::Event::Closed>() ) {
129
126
return EXIT_SUCCESS;
130
127
}
131
128
}
@@ -173,14 +170,14 @@ int main() {
173
170
glPushMatrix ();
174
171
glLoadIdentity ();
175
172
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 ) );
177
174
178
175
static const auto pi = 3 .1415926535897932384626433832795f ;
179
176
static const auto fov = 90 .f ;
180
177
static const auto near_distance = 1 .f ;
181
178
static const auto far_distance = 20 .f ;
182
179
183
- auto aspect = opengl_canvas->GetAllocation ().width / opengl_canvas->GetAllocation ().height ;
180
+ auto aspect = opengl_canvas->GetAllocation ().size . x / opengl_canvas->GetAllocation ().size . y ;
184
181
auto frustum_height = std::tan ( fov / 360 * pi ) * near_distance;
185
182
auto frustum_width = frustum_height * aspect;
186
183
@@ -227,7 +224,7 @@ int main() {
227
224
sfml_scrollable_canvas->Unbind ();
228
225
229
226
// This is important.
230
- app_window.setActive ( true );
227
+ ( void ) app_window.setActive ( true );
231
228
232
229
// Draw the GUI
233
230
sfgui.Display ( app_window );
0 commit comments