Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to SFML 3 #100

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: CI

on: [push, pull_request, workflow_dispatch]

concurrency:
group: environment-${{github.ref}}
cancel-in-progress: true

jobs:
build:
name: ${{ matrix.platform.name }} ${{ matrix.config.name }}
Expand All @@ -13,8 +17,8 @@ jobs:
platform:
- { name: Windows VS2019, os: windows-2019 }
- { name: Windows VS2022, os: windows-2022 }
- { name: Linux GCC, os: ubuntu-22.04 }
- { name: Linux Clang, os: ubuntu-22.04, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
- { name: Linux GCC, os: ubuntu-24.04 }
- { name: Linux Clang, os: ubuntu-24.04, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
- { name: macOS x64, os: macos-13 }
- { name: macOS arm64, os: macos-14 }
config:
Expand All @@ -24,7 +28,7 @@ jobs:
steps:
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libfreetype-dev

- name: SFGUI - Checkout Code
uses: actions/checkout@v4
Expand All @@ -34,7 +38,7 @@ jobs:
with:
fetch-depth: 0
repository: SFML/SFML
ref: 2.6.x
ref: 3.0.0
path: SFML

- name: SFML - Configure CMake
Expand All @@ -51,4 +55,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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

Enhancements:

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

## Release 0.4.0

Enhancements:
Expand Down
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 3.2 )
cmake_minimum_required( VERSION 3.22 )

set( SFGUI_MAJOR_VERSION 0 )
set( SFGUI_MINOR_VERSION 4 )
Expand All @@ -8,25 +8,24 @@ set( SFGUI_VERSION ${SFGUI_MAJOR_VERSION}.${SFGUI_MINOR_VERSION}.${SFGUI_REVISIO
project( SFGUI LANGUAGES CXX VERSION ${SFGUI_VERSION} )
set(TARGET SFGUI)

set( CMAKE_CXX_STANDARD 11 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
set( CMAKE_CXX_EXTENSIONS OFF )

### USER INPUT ###

option( SFGUI_BUILD_SHARED_LIBS "Build shared library." ON )
set( BUILD_SHARED_LIBS ${SFGUI_BUILD_SHARED_LIBS} )
option( SFGUI_BUILD_EXAMPLES "Build examples." ON)
option( SFGUI_BUILD_DOC "Generate API documentation." OFF)
option( SFGUI_INCLUDE_FONT "Include default font in library (DejaVuSans)." ON)
option( SFML_STATIC_LIBRARIES "Do you want to link SFML statically?" OFF)
option( SFGUI_BUILD_EXAMPLES "Build examples." ON )
option( SFGUI_BUILD_DOC "Generate API documentation." OFF )
option( SFGUI_INCLUDE_FONT "Include default font in library (DejaVuSans)." ON )
option( SFML_STATIC_LIBRARIES "Do you want to link SFML statically?" OFF )


# Find packages.
find_package( OpenGL REQUIRED )

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

set( INCLUDE_PATH "${PROJECT_SOURCE_DIR}/include/" )
Expand All @@ -44,9 +43,12 @@ endif()
set( LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib" )

add_library( ${TARGET} ${CPPS} ${INLS} ${HPPS} )
target_include_directories( ${TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/libELL/include" "${SOURCE_PATH}" )
target_include_directories( ${TARGET} SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/libELL/include" )
target_include_directories( ${TARGET} PRIVATE "${SOURCE_PATH}" )
target_include_directories( ${TARGET} PUBLIC $<BUILD_INTERFACE:${INCLUDE_PATH}> $<INSTALL_INTERFACE:include/> )

target_compile_features( ${TARGET} PUBLIC cxx_std_17 )

if( NOT SFGUI_BUILD_SHARED_LIBS )
target_compile_definitions( ${TARGET} PUBLIC SFGUI_STATIC )
set_target_properties( ${TARGET} PROPERTIES DEBUG_POSTFIX -s-d )
Expand All @@ -60,7 +62,7 @@ if( SFGUI_INCLUDE_FONT )
target_compile_definitions( ${TARGET} PRIVATE SFGUI_INCLUDE_FONT )
endif()

target_link_libraries( ${TARGET} PUBLIC sfml-graphics sfml-window sfml-system ${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 @@ -108,7 +110,7 @@ if( WIN32 )
set_target_properties( ${TARGET} PROPERTIES IMPORT_SUFFIX ".a" )
endif()

set( SHARE_PATH "." )
set( SHARE_PATH "${CMAKE_INSTALL_PREFIX}" )
set( LIB_PATH "lib" )
elseif( APPLE )
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
Expand All @@ -118,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 @@ -132,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.5 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.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
33 changes: 15 additions & 18 deletions examples/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <SFML/OpenGL.hpp>

#include <cmath>
#include <cstdint>

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 @@ -49,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<sf::Uint32>( 0, 0, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND );
table->Attach( vertical_scrollbar, sf::Rect<sf::Uint32>( 1, 0, 1, 1 ), 0, sfg::Table::FILL );
table->Attach( horizontal_scrollbar, sf::Rect<sf::Uint32>( 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 @@ -88,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 @@ -118,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 @@ -173,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 @@ -227,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
Loading