Skip to content

Commit 776f0c5

Browse files
committed
Upgrade to SFML 3
1 parent a7b020b commit 776f0c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1036
-1161
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
with:
3535
fetch-depth: 0
3636
repository: SFML/SFML
37-
ref: 3.0.0-rc.1
37+
ref: 3.0.0
3838
path: SFML
3939

4040
- name: SFML - Configure CMake
@@ -51,4 +51,4 @@ jobs:
5151

5252
- name: SFGUI - Build
5353
shell: bash
54-
run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install
54+
run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Enhancements:
66

7-
* Update SFML version to 2.6.
7+
* Update SFML version to 3.0.
88
* Update CMake version to match SFML's version.
99

1010
## Release 0.4.0

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required( VERSION 3.7.2 )
1+
cmake_minimum_required( VERSION 3.22 )
22

33
set( SFGUI_MAJOR_VERSION 0 )
44
set( SFGUI_MINOR_VERSION 4 )
@@ -24,7 +24,7 @@ option( SFML_STATIC_LIBRARIES "Do you want to link SFML statically?"
2424
# Find packages.
2525
find_package( OpenGL REQUIRED )
2626

27-
if( NOT TARGET sfml-graphics )
27+
if( NOT TARGET SFML::Graphics )
2828
find_package( SFML 3 REQUIRED COMPONENTS Graphics )
2929
endif()
3030

@@ -62,7 +62,7 @@ if( SFGUI_INCLUDE_FONT )
6262
target_compile_definitions( ${TARGET} PRIVATE SFGUI_INCLUDE_FONT )
6363
endif()
6464

65-
target_link_libraries( ${TARGET} PUBLIC SFML::Graphics ${OPENGL_gl_LIBRARY} )
65+
target_link_libraries( ${TARGET} PUBLIC SFML::Graphics OpenGL::GL )
6666

6767
# Tell the compiler to export when necessary.
6868
set_target_properties( ${TARGET} PROPERTIES DEFINE_SYMBOL SFGUI_EXPORTS )
@@ -110,7 +110,7 @@ if( WIN32 )
110110
set_target_properties( ${TARGET} PROPERTIES IMPORT_SUFFIX ".a" )
111111
endif()
112112

113-
set( SHARE_PATH "." )
113+
set( SHARE_PATH ${CMAKE_CURRENT_SOURCE_DIR} )
114114
set( LIB_PATH "lib" )
115115
elseif( APPLE )
116116
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
@@ -120,7 +120,7 @@ elseif( APPLE )
120120
set( LIB_PATH "lib" )
121121
elseif( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
122122
find_package( X11 REQUIRED )
123-
target_link_libraries( ${TARGET} PUBLIC ${X11_LIBRARIES} )
123+
target_link_libraries( ${TARGET} PUBLIC X11::X11 )
124124
set( SHARE_PATH "${CMAKE_INSTALL_PREFIX}/share/SFGUI" )
125125

126126
if( LIB_SUFFIX )
@@ -134,7 +134,7 @@ else()
134134
endif()
135135

136136
if( CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
137-
target_compile_options( SFGUI PRIVATE -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wunused-parameter -Wno-long-long -pedantic )
137+
target_compile_options( SFGUI PRIVATE -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wunused-parameter -pedantic )
138138
endif()
139139

140140
### EXAMPLES ###

cmake/templates/config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Define Alias library @PROJECT_NAME@::@TARGET@
55

66
include( CMakeFindDependencyMacro )
7-
find_dependency( SFML 2.6 COMPONENTS graphics window system)
7+
find_dependency( SFML 3.0 COMPONENTS Graphics)
88
find_dependency( OpenGL )
99

1010
if( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )

examples/Box.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int main() {
1010
// Create the main SFML window
11-
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Box Example", sf::Style::Titlebar | sf::Style::Close );
11+
sf::RenderWindow app_window( sf::VideoMode( {800, 600} ), "SFGUI Box Example", sf::Style::Titlebar | sf::Style::Close );
1212

1313
// We have to do this because we don't use SFML to draw.
1414
app_window.resetGLStates();
@@ -58,14 +58,12 @@ int main() {
5858
// Start the game loop
5959
while ( app_window.isOpen() ) {
6060
// Process events
61-
sf::Event event;
62-
63-
while ( app_window.pollEvent( event ) ) {
61+
while ( const std::optional event = app_window.pollEvent() ) {
6462
// Handle events
65-
window->HandleEvent( event );
63+
window->HandleEvent( *event );
6664

6765
// Close window : exit
68-
if ( event.type == sf::Event::Closed ) {
66+
if ( event->is<sf::Event::Closed>() ) {
6967
return EXIT_SUCCESS;
7068
}
7169
}

examples/Buttons.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int main() {
1010
// Create the main SFML window
11-
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Buttons Example", sf::Style::Titlebar | sf::Style::Close );
11+
sf::RenderWindow app_window( sf::VideoMode( {800, 600} ), "SFGUI Buttons Example", sf::Style::Titlebar | sf::Style::Close );
1212

1313
// We have to do this because we don't use SFML to draw.
1414
app_window.resetGLStates();
@@ -126,14 +126,12 @@ int main() {
126126
// Start the game loop
127127
while ( app_window.isOpen() ) {
128128
// Process events
129-
sf::Event event;
130-
131-
while ( app_window.pollEvent( event ) ) {
129+
while ( const std::optional event = app_window.pollEvent() ) {
132130
// Handle events
133-
window->HandleEvent( event );
131+
window->HandleEvent( *event );
134132

135133
// Close window : exit
136-
if ( event.type == sf::Event::Closed ) {
134+
if ( event->is<sf::Event::Closed>() ) {
137135
return EXIT_SUCCESS;
138136
}
139137
}

examples/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required( VERSION 3.7.2 )
1+
cmake_minimum_required( VERSION 3.22 )
22

33
function( build_example SAMPLE_NAME SOURCES )
44
add_executable( ${SAMPLE_NAME} ${SOURCES} )
@@ -45,19 +45,19 @@ build_example( "SFGUI-Test" "Test.cpp" )
4545
# Don't try to copy if the directories are the same.
4646
if( NOT ( "${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}" ) )
4747
add_custom_command(
48-
TARGET "SFGUI-Test"
48+
TARGET "SFGUI-Test" POST_BUILD
4949
COMMAND "${CMAKE_COMMAND}"
5050
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
5151
)
5252

5353
add_custom_command(
54-
TARGET "Image"
54+
TARGET "Image" POST_BUILD
5555
COMMAND "${CMAKE_COMMAND}"
5656
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
5757
)
5858

5959
add_custom_command(
60-
TARGET "Canvas"
60+
TARGET "Canvas" POST_BUILD
6161
COMMAND "${CMAKE_COMMAND}"
6262
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
6363
)

examples/Canvas.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
int 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 );

examples/ComboBox.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int main() {
1010
// Create the main SFML window
11-
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Combo Box Example", sf::Style::Titlebar | sf::Style::Close );
11+
sf::RenderWindow app_window( sf::VideoMode( {800, 600} ), "SFGUI Combo Box Example", sf::Style::Titlebar | sf::Style::Close );
1212

1313
// Create an SFGUI. This is required before doing anything with SFGUI.
1414
sfg::SFGUI sfgui;
@@ -72,14 +72,12 @@ int main() {
7272
// Start the game loop
7373
while ( app_window.isOpen() ) {
7474
// Process events
75-
sf::Event event;
76-
77-
while ( app_window.pollEvent( event ) ) {
75+
while ( const std::optional event = app_window.pollEvent() ) {
7876
// Handle events
79-
window->HandleEvent( event );
77+
window->HandleEvent( *event );
8078

8179
// Close window : exit
82-
if ( event.type == sf::Event::Closed ) {
80+
if ( event->is<sf::Event::Closed>() ) {
8381
return EXIT_SUCCESS;
8482
}
8583
}

examples/CustomWidget.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class MyCustomWidget : public sfg::Widget {
9292
queue->Add(
9393
sfg::Renderer::Get().CreatePane(
9494
sf::Vector2f( 0.f, 0.f ),
95-
sf::Vector2f( GetAllocation().width, GetAllocation().height ),
95+
GetAllocation().size,
9696
5.f,
9797
inverted_color,
9898
background_color,
@@ -110,8 +110,8 @@ class MyCustomWidget : public sfg::Widget {
110110
// Inner pane.
111111
queue->Add(
112112
sfg::Renderer::Get().CreatePane(
113-
sf::Vector2f( GetAllocation().width / 4.f, GetAllocation().height / 4.f ),
114-
sf::Vector2f( GetAllocation().width / 2.f, GetAllocation().height / 2.f ),
113+
GetAllocation().size / 4.f,
114+
GetAllocation().size / 2.f,
115115
5.f,
116116
sf::Color(
117117
static_cast<std::uint8_t>( m_color_distribution( m_generator ) ),
@@ -124,7 +124,7 @@ class MyCustomWidget : public sfg::Widget {
124124
)
125125
);
126126

127-
sf::Text text( GetLabel(), *font, font_size );
127+
sf::Text text( *font, GetLabel(), font_size );
128128

129129
// Set the text color to white.
130130
text.setFillColor( sf::Color::White );
@@ -134,8 +134,8 @@ class MyCustomWidget : public sfg::Widget {
134134
auto y_offset = ( GetState() == State::ACTIVE ) ? static_cast<float>( m_distribution( m_generator ) ) : 0.f;
135135

136136
text.setPosition(
137-
GetAllocation().width / 2.f - metrics.x / 2.f + x_offset,
138-
GetAllocation().height / 2.f - metrics.y / 2.f + y_offset
137+
{GetAllocation().size.x / 2.f - metrics.x / 2.f + x_offset,
138+
GetAllocation().size.y / 2.f - metrics.y / 2.f + y_offset}
139139
);
140140

141141
// Text.
@@ -202,7 +202,7 @@ class MyCustomWidget : public sfg::Widget {
202202
return;
203203
}
204204

205-
if( button == sf::Mouse::Left ) {
205+
if( button == sf::Mouse::Button::Left ) {
206206
if( press ) {
207207
SetLabel( sf::String( "Mouse Left Press: " + std::to_string( x ) + "," + std::to_string( y ) ) );
208208
SetState( State::ACTIVE );
@@ -223,7 +223,7 @@ class MyCustomWidget : public sfg::Widget {
223223

224224
int main() {
225225
// Create SFML's window.
226-
sf::RenderWindow render_window( sf::VideoMode( 800, 600 ), "Custom Widget" );
226+
sf::RenderWindow render_window( sf::VideoMode( {800, 600} ), "Custom Widget" );
227227

228228
// Create an SFGUI. This is required before doing anything with SFGUI.
229229
sfg::SFGUI sfgui;
@@ -255,16 +255,15 @@ int main() {
255255
render_window.resetGLStates();
256256

257257
// Main loop!
258-
sf::Event event;
259258
sf::Clock clock;
260259

261260
while( render_window.isOpen() ) {
262261
// Event processing.
263-
while( render_window.pollEvent( event ) ) {
264-
desktop.HandleEvent( event );
262+
while( const std::optional event = render_window.pollEvent() ) {
263+
desktop.HandleEvent( *event );
265264

266265
// If window is about to be closed, leave program.
267-
if( event.type == sf::Event::Closed ) {
266+
if( event->is<sf::Event::Closed>() ) {
268267
return 0;
269268
}
270269
}

0 commit comments

Comments
 (0)