Skip to content

Commit

Permalink
Upgrade to SFML 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Jan 3, 2025
1 parent a7b020b commit f9794a4
Show file tree
Hide file tree
Showing 82 changed files with 1,037 additions and 1,167 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
fetch-depth: 0
repository: SFML/SFML
ref: 3.0.0-rc.1
ref: 3.0.0
path: SFML

- name: SFML - Configure CMake
Expand All @@ -51,4 +51,4 @@ jobs:

- name: SFGUI - Build
shell: bash
run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install
run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Enhancements:

* Update SFML version to 2.6.
* Update SFML version to 3.0.
* Update CMake version to match SFML's version.

## Release 0.4.0
Expand Down
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 3.7.2 )
cmake_minimum_required( VERSION 3.22 )

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

if( NOT TARGET sfml-graphics )
if( NOT TARGET SFML::Graphics )
find_package( SFML 3 REQUIRED COMPONENTS Graphics )
endif()

Expand Down Expand Up @@ -62,7 +62,7 @@ if( SFGUI_INCLUDE_FONT )
target_compile_definitions( ${TARGET} PRIVATE SFGUI_INCLUDE_FONT )
endif()

target_link_libraries( ${TARGET} PUBLIC SFML::Graphics ${OPENGL_gl_LIBRARY} )
target_link_libraries( ${TARGET} PUBLIC SFML::Graphics OpenGL::GL )

# Tell the compiler to export when necessary.
set_target_properties( ${TARGET} PROPERTIES DEFINE_SYMBOL SFGUI_EXPORTS )
Expand Down Expand Up @@ -110,7 +110,7 @@ if( WIN32 )
set_target_properties( ${TARGET} PROPERTIES IMPORT_SUFFIX ".a" )
endif()

set( SHARE_PATH "." )
set( SHARE_PATH ${CMAKE_CURRENT_SOURCE_DIR} )
set( LIB_PATH "lib" )
elseif( APPLE )
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
Expand All @@ -120,7 +120,7 @@ elseif( APPLE )
set( LIB_PATH "lib" )
elseif( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
find_package( X11 REQUIRED )
target_link_libraries( ${TARGET} PUBLIC ${X11_LIBRARIES} )
target_link_libraries( ${TARGET} PUBLIC X11::X11 )
set( SHARE_PATH "${CMAKE_INSTALL_PREFIX}/share/SFGUI" )

if( LIB_SUFFIX )
Expand All @@ -134,7 +134,7 @@ else()
endif()

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

### EXAMPLES ###
Expand Down
2 changes: 1 addition & 1 deletion cmake/templates/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Define Alias library @PROJECT_NAME@::@TARGET@

include( CMakeFindDependencyMacro )
find_dependency( SFML 2.6 COMPONENTS graphics window system)
find_dependency( SFML 3.0 COMPONENTS Graphics)
find_dependency( OpenGL )

if( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
Expand Down
10 changes: 4 additions & 6 deletions examples/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();
Expand Down Expand Up @@ -58,14 +58,12 @@ int main() {
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;

while ( app_window.pollEvent( event ) ) {
while ( const std::optional event = app_window.pollEvent() ) {
// Handle events
window->HandleEvent( event );
window->HandleEvent( *event );

// Close window : exit
if ( event.type == sf::Event::Closed ) {
if ( event->is<sf::Event::Closed>() ) {
return EXIT_SUCCESS;
}
}
Expand Down
10 changes: 4 additions & 6 deletions examples/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();
Expand Down Expand Up @@ -126,14 +126,12 @@ int main() {
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;

while ( app_window.pollEvent( event ) ) {
while ( const std::optional event = app_window.pollEvent() ) {
// Handle events
window->HandleEvent( event );
window->HandleEvent( *event );

// Close window : exit
if ( event.type == sf::Event::Closed ) {
if ( event->is<sf::Event::Closed>() ) {
return EXIT_SUCCESS;
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 3.7.2 )
cmake_minimum_required( VERSION 3.22 )

function( build_example SAMPLE_NAME SOURCES )
add_executable( ${SAMPLE_NAME} ${SOURCES} )
Expand Down Expand Up @@ -45,19 +45,19 @@ build_example( "SFGUI-Test" "Test.cpp" )
# Don't try to copy if the directories are the same.
if( NOT ( "${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}" ) )
add_custom_command(
TARGET "SFGUI-Test"
TARGET "SFGUI-Test" POST_BUILD
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
)

add_custom_command(
TARGET "Image"
TARGET "Image" POST_BUILD
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
)

add_custom_command(
TARGET "Canvas"
TARGET "Canvas" POST_BUILD
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
)
Expand Down
32 changes: 14 additions & 18 deletions examples/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

int main() {
// Create the main SFML window
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );
sf::RenderWindow app_window( sf::VideoMode( {800, 600} ), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );

// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();
Expand Down Expand Up @@ -50,20 +50,18 @@ int main() {

// Create a table to put the scrollbars and scrollable canvas in.
auto table = sfg::Table::Create();
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 );
table->Attach( vertical_scrollbar, sf::Rect<std::uint32_t>( ( 1, 0 ), ( 1, 1 ) ), 0, sfg::Table::FILL );
table->Attach( horizontal_scrollbar, sf::Rect<std::uint32_t>( ( 0, 1 ), ( 1, 1 ) ), sfg::Table::FILL, 0 );
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 );
table->Attach( vertical_scrollbar, sf::Rect<std::uint32_t>( {1, 0}, {1, 1} ), 0, sfg::Table::FILL );
table->Attach( horizontal_scrollbar, sf::Rect<std::uint32_t>( {0, 1}, {1, 1} ), sfg::Table::FILL, 0 );

// Add the Canvases to the windows.
opengl_window->Add( opengl_canvas );
sfml_window->Add( sfml_canvas );
sfml_scrollable_window->Add( table );

// Create an sf::Sprite for demonstration purposes.
sf::Texture texture;
texture.loadFromFile( "data/sfgui.png" );
sf::Sprite sprite;
sprite.setTexture( texture );
const sf::Texture texture( "data/sfgui.png" );
const sf::Sprite sprite( texture );

// Create an sf::RectangleShape for demonstration purposes.
sf::RectangleShape rectangle_shape( sf::Vector2f( 218.f * 20, 84.f * 20 ) );
Expand All @@ -89,11 +87,11 @@ int main() {
vertical_adjustment->SetPageSize( scrollable_canvas_size );

horizontal_adjustment->GetSignal( sfg::Adjustment::OnChange ).Connect( [&view, &horizontal_adjustment]() {
view.setCenter( horizontal_adjustment->GetValue(), view.getCenter().y );
view.setCenter( {horizontal_adjustment->GetValue(), view.getCenter().y} );
} );

vertical_adjustment->GetSignal( sfg::Adjustment::OnChange ).Connect( [&view, &vertical_adjustment]() {
view.setCenter( view.getCenter().x, vertical_adjustment->GetValue() );
view.setCenter( {view.getCenter().x, vertical_adjustment->GetValue()} );
} );

// Because Canvases provide a virtual surface to draw
Expand All @@ -119,14 +117,12 @@ int main() {
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;

while ( app_window.pollEvent( event ) ) {
while ( const std::optional event = app_window.pollEvent() ) {
// Handle events
desktop.HandleEvent( event );
desktop.HandleEvent( *event );

// Close window : exit
if ( event.type == sf::Event::Closed ) {
if ( event->is<sf::Event::Closed>() ) {
return EXIT_SUCCESS;
}
}
Expand Down Expand Up @@ -174,14 +170,14 @@ int main() {
glPushMatrix();
glLoadIdentity();

glViewport( 0, 0, static_cast<int>( opengl_canvas->GetAllocation().width ), static_cast<int>( opengl_canvas->GetAllocation().height ) );
glViewport( 0, 0, static_cast<int>( opengl_canvas->GetAllocation().size.x ), static_cast<int>( opengl_canvas->GetAllocation().size.y ) );

static const auto pi = 3.1415926535897932384626433832795f;
static const auto fov = 90.f;
static const auto near_distance = 1.f;
static const auto far_distance = 20.f;

auto aspect = opengl_canvas->GetAllocation().width / opengl_canvas->GetAllocation().height;
auto aspect = opengl_canvas->GetAllocation().size.x / opengl_canvas->GetAllocation().size.y;
auto frustum_height = std::tan( fov / 360 * pi ) * near_distance;
auto frustum_width = frustum_height * aspect;

Expand Down Expand Up @@ -228,7 +224,7 @@ int main() {
sfml_scrollable_canvas->Unbind();

// This is important.
app_window.setActive( true );
(void)app_window.setActive( true );

// Draw the GUI
sfgui.Display( app_window );
Expand Down
10 changes: 4 additions & 6 deletions examples/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

// Create an SFGUI. This is required before doing anything with SFGUI.
sfg::SFGUI sfgui;
Expand Down Expand Up @@ -72,14 +72,12 @@ int main() {
// Start the game loop
while ( app_window.isOpen() ) {
// Process events
sf::Event event;

while ( app_window.pollEvent( event ) ) {
while ( const std::optional event = app_window.pollEvent() ) {
// Handle events
window->HandleEvent( event );
window->HandleEvent( *event );

// Close window : exit
if ( event.type == sf::Event::Closed ) {
if ( event->is<sf::Event::Closed>() ) {
return EXIT_SUCCESS;
}
}
Expand Down
23 changes: 11 additions & 12 deletions examples/CustomWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MyCustomWidget : public sfg::Widget {
queue->Add(
sfg::Renderer::Get().CreatePane(
sf::Vector2f( 0.f, 0.f ),
sf::Vector2f( GetAllocation().width, GetAllocation().height ),
GetAllocation().size,
5.f,
inverted_color,
background_color,
Expand All @@ -110,8 +110,8 @@ class MyCustomWidget : public sfg::Widget {
// Inner pane.
queue->Add(
sfg::Renderer::Get().CreatePane(
sf::Vector2f( GetAllocation().width / 4.f, GetAllocation().height / 4.f ),
sf::Vector2f( GetAllocation().width / 2.f, GetAllocation().height / 2.f ),
GetAllocation().size / 4.f,
GetAllocation().size / 2.f,
5.f,
sf::Color(
static_cast<std::uint8_t>( m_color_distribution( m_generator ) ),
Expand All @@ -124,7 +124,7 @@ class MyCustomWidget : public sfg::Widget {
)
);

sf::Text text( GetLabel(), *font, font_size );
sf::Text text( *font, GetLabel(), font_size );

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

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

// Text.
Expand Down Expand Up @@ -202,7 +202,7 @@ class MyCustomWidget : public sfg::Widget {
return;
}

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

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

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

// Main loop!
sf::Event event;
sf::Clock clock;

while( render_window.isOpen() ) {
// Event processing.
while( render_window.pollEvent( event ) ) {
desktop.HandleEvent( event );
while( const std::optional event = render_window.pollEvent() ) {
desktop.HandleEvent( *event );

// If window is about to be closed, leave program.
if( event.type == sf::Event::Closed ) {
if( event->is<sf::Event::Closed>() ) {
return 0;
}
}
Expand Down
12 changes: 5 additions & 7 deletions examples/Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <SFML/Graphics.hpp>

int main() {
sf::RenderWindow render_window( sf::VideoMode( 800, 600 ), "SFGUI Desktop Example" );
sf::RenderWindow render_window( sf::VideoMode( {800, 600} ), "SFGUI Desktop Example" );

// Create an SFGUI. This is required before doing anything with SFGUI.
sfg::SFGUI sfgui;
Expand Down Expand Up @@ -75,18 +75,16 @@ int main() {
front_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( [&desktop, &main_window] { desktop.BringToFront( main_window ); } );
} );

sf::Event event;

while( render_window.isOpen() ) {
while( render_window.pollEvent( event ) ) {
while( const std::optional event = render_window.pollEvent() ) {
if(
(event.type == sf::Event::Closed) ||
(event.type == sf::Event::KeyPressed && event.key.scancode == sf::Keyboard::Scan::Escape)
(event->is<sf::Event::Closed>()) ||
(event->is<sf::Event::KeyPressed>() && event->getIf<sf::Event::KeyPressed>()->scancode == sf::Keyboard::Scan::Escape)
) {
return 0;
}
else {
desktop.HandleEvent( event );
desktop.HandleEvent( *event );
}
}

Expand Down
Loading

0 comments on commit f9794a4

Please sign in to comment.