diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6141e944..a9fae49b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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: @@ -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 @@ -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 @@ -51,4 +55,4 @@ jobs: - name: SFGUI - Build shell: bash - run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install \ No newline at end of file + run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install diff --git a/CHANGELOG.md b/CHANGELOG.md index cc3c2ea8..25b1e1dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index ab03fd5f..a09a7c6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) @@ -8,7 +8,6 @@ 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 ) @@ -16,17 +15,17 @@ set( CMAKE_CXX_EXTENSIONS OFF ) 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/" ) @@ -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 $ $ ) +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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ### diff --git a/cmake/templates/config.cmake.in b/cmake/templates/config.cmake.in index fb8ac39d..676440a8 100644 --- a/cmake/templates/config.cmake.in +++ b/cmake/templates/config.cmake.in @@ -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" ) diff --git a/examples/Box.cpp b/examples/Box.cpp index e890c5b7..7bd3a975 100644 --- a/examples/Box.cpp +++ b/examples/Box.cpp @@ -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(); @@ -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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Buttons.cpp b/examples/Buttons.cpp index a3ead58b..981f04f6 100644 --- a/examples/Buttons.cpp +++ b/examples/Buttons.cpp @@ -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(); @@ -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() ) { return EXIT_SUCCESS; } } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 10926ffa..8596b96a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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} ) @@ -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" ) diff --git a/examples/Canvas.cpp b/examples/Canvas.cpp index db552cb5..f467d25f 100644 --- a/examples/Canvas.cpp +++ b/examples/Canvas.cpp @@ -8,10 +8,11 @@ #include #include +#include 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(); @@ -49,9 +50,9 @@ 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( 0, 0, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); - table->Attach( vertical_scrollbar, sf::Rect( 1, 0, 1, 1 ), 0, sfg::Table::FILL ); - table->Attach( horizontal_scrollbar, sf::Rect( 0, 1, 1, 1 ), sfg::Table::FILL, 0 ); + table->Attach( sfml_scrollable_canvas, sf::Rect( { 0, 0 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); + table->Attach( vertical_scrollbar, sf::Rect( { 1, 0 }, { 1, 1 } ), 0, sfg::Table::FILL ); + table->Attach( horizontal_scrollbar, sf::Rect( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, 0 ); // Add the Canvases to the windows. opengl_window->Add( opengl_canvas ); @@ -59,10 +60,8 @@ int main() { 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 ) ); @@ -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 @@ -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() ) { return EXIT_SUCCESS; } } @@ -173,14 +170,14 @@ int main() { glPushMatrix(); glLoadIdentity(); - glViewport( 0, 0, static_cast( opengl_canvas->GetAllocation().width ), static_cast( opengl_canvas->GetAllocation().height ) ); + glViewport( 0, 0, static_cast( opengl_canvas->GetAllocation().size.x ), static_cast( 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; @@ -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 ); diff --git a/examples/ComboBox.cpp b/examples/ComboBox.cpp index 04070587..171900c1 100644 --- a/examples/ComboBox.cpp +++ b/examples/ComboBox.cpp @@ -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; @@ -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() ) { return EXIT_SUCCESS; } } diff --git a/examples/CustomWidget.cpp b/examples/CustomWidget.cpp index 49b6b980..d9d43327 100644 --- a/examples/CustomWidget.cpp +++ b/examples/CustomWidget.cpp @@ -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, @@ -110,13 +110,13 @@ 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( m_color_distribution( m_generator ) ), - static_cast( m_color_distribution( m_generator ) ), - static_cast( m_color_distribution( m_generator ) ), + static_cast( m_color_distribution( m_generator ) ), + static_cast( m_color_distribution( m_generator ) ), + static_cast( m_color_distribution( m_generator ) ), 255 ), inner_border_color, @@ -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 ); @@ -134,8 +134,8 @@ class MyCustomWidget : public sfg::Widget { auto y_offset = ( GetState() == State::ACTIVE ) ? static_cast( 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. @@ -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 ); @@ -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; @@ -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() ) { return 0; } } diff --git a/examples/Desktop.cpp b/examples/Desktop.cpp index c14d3eac..cdcfce56 100644 --- a/examples/Desktop.cpp +++ b/examples/Desktop.cpp @@ -4,7 +4,7 @@ #include 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; @@ -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.code == sf::Keyboard::Escape) + (event->is()) || + (event->is() && event->getIf()->scancode == sf::Keyboard::Scan::Escape) ) { return 0; } else { - desktop.HandleEvent( event ); + desktop.HandleEvent( *event ); } } diff --git a/examples/Entry.cpp b/examples/Entry.cpp index 70cb683e..4d670f7c 100644 --- a/examples/Entry.cpp +++ b/examples/Entry.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Entry Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Entry Example", sf::Style::Titlebar | sf::Style::Close ); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; @@ -74,14 +74,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/GuessMyNumber.cpp b/examples/GuessMyNumber.cpp index d1d78ae5..c449ec20 100644 --- a/examples/GuessMyNumber.cpp +++ b/examples/GuessMyNumber.cpp @@ -4,10 +4,11 @@ #include #include #include +#include #include int main() { - sf::RenderWindow render_window( sf::VideoMode( 1024, 768, 32 ), "Guess My Number (SFGUI)", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow render_window( sf::VideoMode( { 1024, 768 }, 32 ), "Guess My Number (SFGUI)", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. render_window.resetGLStates(); @@ -94,12 +95,12 @@ int main() { // Layout. auto table = sfg::Table::Create(); - table->Attach( sfg::Label::Create( "Your guess:" ), sf::Rect( 0, 0, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( current_number_entry, sf::Rect( 1, 0, 1, 1 ) ); - table->Attach( sfg::Label::Create( "Tries:" ), sf::Rect( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( tries_label, sf::Rect( 1, 1, 1, 1 ) ); - table->Attach( sfg::Label::Create( "Hint:" ), sf::Rect( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( hint_label, sf::Rect( 1, 2, 1, 1 ) ); + table->Attach( sfg::Label::Create( "Your guess:" ), sf::Rect( { 0, 0 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( current_number_entry, sf::Rect( { 1, 0 }, { 1, 1 } ) ); + table->Attach( sfg::Label::Create( "Tries:" ), sf::Rect( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( tries_label, sf::Rect( { 1, 1 }, { 1, 1 } ) ); + table->Attach( sfg::Label::Create( "Hint:" ), sf::Rect( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( hint_label, sf::Rect( { 1, 2 }, { 1, 1 } ) ); table->SetColumnSpacings( 5.f ); table->SetRowSpacings( 5.f ); @@ -119,26 +120,24 @@ int main() { window->SetPosition( sf::Vector2f( - static_cast( render_window.getSize().x / 2 ) - window->GetAllocation().width / 2.f, - static_cast( render_window.getSize().y / 2 ) - window->GetAllocation().height / 2.f + static_cast( render_window.getSize().x / 2 ) - window->GetAllocation().size.x / 2.f, + static_cast( render_window.getSize().y / 2 ) - window->GetAllocation().size.y / 2.f ) ); // Make sure all properties are applied. window->Refresh(); - 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::KeyPressed && event.key.code == sf::Keyboard::Escape) || - event.type == sf::Event::Closed + (event->is() && event->getIf()->scancode == sf::Keyboard::Scan::Escape) || + event->is() ) { return 0; } - window->HandleEvent( event ); + window->HandleEvent( *event ); } window->Update( 0.f ); diff --git a/examples/HelloWorld.cpp b/examples/HelloWorld.cpp index be09df6d..75862a71 100644 --- a/examples/HelloWorld.cpp +++ b/examples/HelloWorld.cpp @@ -5,7 +5,7 @@ int main() { // Create SFML's window. - sf::RenderWindow render_window( sf::VideoMode( 800, 600 ), "Hello world!" ); + sf::RenderWindow render_window( sf::VideoMode( { 800, 600 } ), "Hello world!" ); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; @@ -37,16 +37,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() ) { return 0; } } diff --git a/examples/Image.cpp b/examples/Image.cpp index 0e2b1b37..0085ef37 100644 --- a/examples/Image.cpp +++ b/examples/Image.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Image Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Image Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -37,14 +37,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Label.cpp b/examples/Label.cpp index be850314..1745cf6f 100644 --- a/examples/Label.cpp +++ b/examples/Label.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Label Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Label Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -38,14 +38,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Layout.cpp b/examples/Layout.cpp index 281c9ee8..fd9a88ce 100644 --- a/examples/Layout.cpp +++ b/examples/Layout.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Layout Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Layout Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -84,14 +84,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Multiview.cpp b/examples/Multiview.cpp index 8a8177e0..c0d8e8b3 100644 --- a/examples/Multiview.cpp +++ b/examples/Multiview.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Multiview Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Multiview Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -45,25 +45,19 @@ int main() { // a pointer to it as the second parameter after the function address. // Our sf::RenderTexture to draw the GUI on. - sf::RenderTexture render_texture; - render_texture.create( 800, 600 ); + sf::RenderTexture render_texture( sf::Vector2u( 800, 600 ) ); render_texture.resetGLStates(); // Our 4 viewport Sprites. - sf::Sprite sprite0; - sf::Sprite sprite1; - sf::Sprite sprite2; - sf::Sprite sprite3; + sf::Sprite sprite0( render_texture.getTexture() ); + sf::Sprite sprite1( render_texture.getTexture() ); + sf::Sprite sprite2( render_texture.getTexture() ); + sf::Sprite sprite3( render_texture.getTexture() ); - sprite0.setPosition( 0.f, 0.f ); - sprite1.setPosition( 400.f, 0.f ); - sprite2.setPosition( 0.f, 300.f ); - sprite3.setPosition( 400.f, 300.f ); - - sprite0.setTexture( render_texture.getTexture() ); - sprite1.setTexture( render_texture.getTexture() ); - sprite2.setTexture( render_texture.getTexture() ); - sprite3.setTexture( render_texture.getTexture() ); + sprite0.setPosition( { 0.f, 0.f } ); + sprite1.setPosition( { 400.f, 0.f } ); + sprite2.setPosition( { 0.f, 300.f } ); + sprite3.setPosition( { 400.f, 300.f } ); // Rectangle to clear the RenderTexture. sf::RectangleShape clear_rect( sf::Vector2f( 400.f, 300.f ) ); @@ -72,27 +66,35 @@ int main() { // Start the game loop while ( app_window.isOpen() ) { // Process events - sf::Event event; - - while ( app_window.pollEvent( event ) ) { + while ( std::optional event = app_window.pollEvent() ) { // Handle events // Because we are doing fancy stuff with multiple // viewports, we need to take care of translating // the SFML window coordinates into our local // viewport coordinates. - if( event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased ) { - event.mouseButton.x %= 400; - event.mouseButton.y %= 300; + if( const auto* mouseButtonPressed = event->getIf() ) { + auto altered_event = *mouseButtonPressed; + altered_event.position.x %= 400; + altered_event.position.y %= 300; + event = altered_event; + } + else if( const auto* mouseButtonReleased = event->getIf() ) { + auto altered_event = *mouseButtonReleased; + altered_event.position.x %= 400; + altered_event.position.y %= 300; + event = altered_event; } - else if( event.type == sf::Event::MouseMoved ) { - event.mouseMove.x %= 400; - event.mouseMove.y %= 300; + else if( const auto* mouseMoved = event->getIf() ) { + auto altered_event = *mouseMoved; + altered_event.position.x %= 400; + altered_event.position.y %= 300; + event = altered_event; } - window->HandleEvent( event ); + window->HandleEvent( *event ); // Close window : exit - if ( event.type == sf::Event::Closed ) { + if ( event->is() ) { return EXIT_SUCCESS; } } diff --git a/examples/Notebook.cpp b/examples/Notebook.cpp index 95351909..e920ffd8 100644 --- a/examples/Notebook.cpp +++ b/examples/Notebook.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Notebook Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Notebook Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -24,8 +24,8 @@ int main() { auto notebook = sfg::Notebook::Create(); // Create a couple of buttons to populate the notebook. - auto button1 = sfg::Button::Create("Hello"); - auto button2 = sfg::Button::Create("World"); + auto button1 = sfg::Button::Create( "Hello" ); + auto button2 = sfg::Button::Create( "World" ); // Add new pages to the notebook with respective tab labels // containing solely the buttons as their children. @@ -53,14 +53,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/OpenGL.cpp b/examples/OpenGL.cpp index c5c91904..b00bb8b1 100644 --- a/examples/OpenGL.cpp +++ b/examples/OpenGL.cpp @@ -4,17 +4,18 @@ #include #include #include +#include int main() { // An sf::Window for raw OpenGL rendering. - sf::Window app_window( sf::VideoMode( 800, 600 ), "SFGUI with OpenGL example", sf::Style::Titlebar | sf::Style::Close ); + sf::Window app_window( sf::VideoMode( { 800, 600 } ), "SFGUI with OpenGL example", sf::Style::Titlebar | sf::Style::Close ); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; // Set the SFML Window's context back to the active one. SFGUI creates // a temporary context on creation that is set active. - app_window.setActive(); + (void)app_window.setActive(); // Initial OpenGL setup. // We have to set up our own OpenGL viewport because we are using an sf::Window. @@ -30,16 +31,16 @@ int main() { table->SetRowSpacings( 5.f ); table->SetColumnSpacings( 5.f ); - table->Attach( sfg::Label::Create( "Change the color of the rect using the scales below." ), sf::Rect( 0, 0, 3, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( sfg::Label::Create( "Red:" ), sf::Rect( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( red_scale, sf::Rect( 1, 1, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); - table->Attach( sfg::Label::Create( "Green:" ), sf::Rect( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( green_scale, sf::Rect( 1, 2, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); - table->Attach( sfg::Label::Create( "Blue:" ), sf::Rect( 0, 3, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( blue_scale, sf::Rect( 1, 3, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); - table->Attach( sfg::Label::Create( "Angle:" ), sf::Rect( 0, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - table->Attach( angle_scale, sf::Rect( 1, 4, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); - table->Attach( auto_check, sf::Rect( 2, 4, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( sfg::Label::Create( "Change the color of the rect using the scales below." ), sf::Rect( { 0, 0 }, { 3, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( sfg::Label::Create( "Red:" ), sf::Rect( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( red_scale, sf::Rect( { 1, 1 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); + table->Attach( sfg::Label::Create( "Green:" ), sf::Rect( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( green_scale, sf::Rect( { 1, 2 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); + table->Attach( sfg::Label::Create( "Blue:" ), sf::Rect( { 0, 3 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( blue_scale, sf::Rect( { 1, 3 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); + table->Attach( sfg::Label::Create( "Angle:" ), sf::Rect( { 0, 4 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + table->Attach( angle_scale, sf::Rect( { 1, 4 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); + table->Attach( auto_check, sf::Rect( { 2, 4 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); auto window = sfg::Window::Create(); window->SetTitle( "SFGUI with OpenGL" ); @@ -69,19 +70,17 @@ int main() { glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); - sf::Event event; - sf::Clock clock; while( app_window.isOpen() ) { auto delta = clock.restart().asSeconds(); - while( app_window.pollEvent( event ) ) { - if( event.type == sf::Event::Closed ) { + while( const std::optional event = app_window.pollEvent() ) { + if( event->is() ) { return 0; } else { - desktop.HandleEvent( event ); + desktop.HandleEvent( *event ); } } diff --git a/examples/ProgressBar.cpp b/examples/ProgressBar.cpp index c1223c86..057db881 100644 --- a/examples/ProgressBar.cpp +++ b/examples/ProgressBar.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Progress Bar Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Progress Bar Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -53,14 +53,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() ) { return 0; } } diff --git a/examples/Range.cpp b/examples/Range.cpp index 0d84f575..b13c0862 100644 --- a/examples/Range.cpp +++ b/examples/Range.cpp @@ -9,7 +9,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Range Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Range Example", sf::Style::Titlebar | sf::Style::Close ); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; @@ -106,14 +106,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/ScrolledWindowViewport.cpp b/examples/ScrolledWindowViewport.cpp index 48da76e1..abf0a4b1 100644 --- a/examples/ScrolledWindowViewport.cpp +++ b/examples/ScrolledWindowViewport.cpp @@ -9,7 +9,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI ScrolledWindow and Viewport Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI ScrolledWindow and Viewport Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -94,14 +94,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() ) { return 0; } } diff --git a/examples/Signals.cpp b/examples/Signals.cpp index 14d986dc..c84bc8e0 100644 --- a/examples/Signals.cpp +++ b/examples/Signals.cpp @@ -65,7 +65,7 @@ void BazClass::Baz() { } int main() { - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Button Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Button Example", sf::Style::Titlebar | sf::Style::Close ); // Create an SFGUI. This is required before doing anything with SFGUI. sfg::SFGUI sfgui; @@ -117,12 +117,10 @@ int main() { // Factory Method Pattern and Abstract Factory Pattern. while ( app_window.isOpen() ) { - sf::Event event; + while ( const std::optional event = app_window.pollEvent() ) { + window->HandleEvent( *event ); - while ( app_window.pollEvent( event ) ) { - window->HandleEvent( event ); - - if ( event.type == sf::Event::Closed ) { + if ( event->is() ) { return EXIT_SUCCESS; } } diff --git a/examples/SpinButton.cpp b/examples/SpinButton.cpp index ff469f37..449afac3 100644 --- a/examples/SpinButton.cpp +++ b/examples/SpinButton.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI SpinButton Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI SpinButton Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -70,14 +70,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Spinner.cpp b/examples/Spinner.cpp index e44addca..1858dec0 100644 --- a/examples/Spinner.cpp +++ b/examples/Spinner.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Spinner Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Spinner Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -59,14 +59,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() ) { return 0; } } diff --git a/examples/Table.cpp b/examples/Table.cpp index 3e5f2828..3c9d770b 100644 --- a/examples/Table.cpp +++ b/examples/Table.cpp @@ -6,9 +6,11 @@ #include +#include + int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Table Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Table Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -43,13 +45,13 @@ int main() { // packing options and the second the vertical packing options. // // The last option is the padding you want to apply to the cell. - table->Attach( foo, sf::Rect( 0, 0, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); + table->Attach( foo, sf::Rect( { 0, 0 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); // Do the same for the other 4 widgets. - table->Attach( bar, sf::Rect( 0, 1, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); - table->Attach( baz, sf::Rect( 0, 2, 1, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); - table->Attach( column_span, sf::Rect( 0, 3, 2, 1 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); - table->Attach( row_span, sf::Rect( 1, 0, 1, 3 ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); + table->Attach( bar, sf::Rect( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); + table->Attach( baz, sf::Rect( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); + table->Attach( column_span, sf::Rect( { 0, 3 }, { 2, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); + table->Attach( row_span, sf::Rect( { 1, 0 }, { 1, 3 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL, sf::Vector2f( 10.f, 10.f ) ); // Because we told our cells to only expand horizontally, // they will only resize if the size of the window changes horizontally. @@ -60,14 +62,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() ) { return EXIT_SUCCESS; } } diff --git a/examples/Test.cpp b/examples/Test.cpp index 82fd677b..108a22f1 100644 --- a/examples/Test.cpp +++ b/examples/Test.cpp @@ -5,9 +5,13 @@ #include #include #include + +#include +#include #include + #include -#include +#include class SampleApp { public: @@ -62,8 +66,8 @@ class SampleApp { sf::Clock m_fps_clock; sf::Texture m_background_texture; - sf::Sprite m_background_sprite; - sf::Sprite m_canvas_sprite; + std::optional m_background_sprite; + std::optional m_canvas_sprite; GLuint m_custom_draw_display_list; }; @@ -101,39 +105,38 @@ void Ouchy::DoOuch() { } SampleApp::SampleApp() : - m_window( sf::VideoMode( 1024, 768, 32 ), "SFGUI test", sf::Style::Default, sf::ContextSettings( 16, 0, 0, 2, 1 ) ), + m_window( sf::VideoMode( { 1024, 768 }, 32 ), "SFGUI test", sf::Style::Default, sf::State::Windowed, sf::ContextSettings{ 16, 0, 0, 2, 1 } ), m_desktop(), - m_custom_draw_display_list( 0 ) + m_custom_draw_display_list( 0 ), + m_background_texture( sf::Vector2u( 1024, 768 ) ) { - m_background_texture.create( 1024, 768 ); - - std::vector pixels( 1024 * 768 * 4 ); + std::vector pixels( 1024 * 768 * 4 ); - sf::Uint8 pixel_value = 139; + std::uint8_t pixel_value = 139; for( std::size_t index = 0; index < 1024 * 768; ++index ) { - pixel_value = static_cast( pixel_value ^ ( index + 809 ) ); - pixel_value = static_cast( pixel_value << ( index % 11 ) ); - pixel_value = static_cast( pixel_value * 233 ); + pixel_value = static_cast( pixel_value ^ ( index + 809 ) ); + pixel_value = static_cast( pixel_value << ( index % 11 ) ); + pixel_value = static_cast( pixel_value * 233 ); - pixels[ index * 4 + 0 ] = static_cast( pixel_value % 16 + 72 ); // R + pixels[ index * 4 + 0 ] = static_cast( pixel_value % 16 + 72 ); // R - pixel_value ^= static_cast( index ); - pixel_value = static_cast( pixel_value * 23 ); + pixel_value ^= static_cast( index ); + pixel_value = static_cast( pixel_value * 23 ); - pixels[ index * 4 + 1 ] = static_cast( pixel_value % 16 + 72 ); // G + pixels[ index * 4 + 1 ] = static_cast( pixel_value % 16 + 72 ); // G - pixel_value ^= static_cast( index ); - pixel_value = static_cast( pixel_value * 193 ); + pixel_value ^= static_cast( index ); + pixel_value = static_cast( pixel_value * 193 ); - pixels[ index * 4 + 2 ] = static_cast( pixel_value % 16 + 72 ); // B + pixels[ index * 4 + 2 ] = static_cast( pixel_value % 16 + 72 ); // B pixels[ index * 4 + 3 ] = 255; // A } m_background_texture.update( pixels.data() ); - m_background_sprite.setTexture( m_background_texture ); + m_background_sprite.emplace( m_background_texture ); } SampleApp::~SampleApp() { @@ -145,11 +148,9 @@ SampleApp::~SampleApp() { } void SampleApp::Run() { - sf::Event event; - //m_window.SetFramerateLimit( 60 ); //m_window.EnableVerticalSync( true ); - m_window.setActive( true ); + (void)m_window.setActive( true ); std::string renderer_string; @@ -175,8 +176,7 @@ void SampleApp::Run() { } // Play around with resource manager. - std::shared_ptr my_font = std::make_shared(); - my_font->loadFromFile( "data/linden_hill.otf" ); + std::shared_ptr my_font = std::make_shared( "data/linden_hill.otf" ); m_desktop.GetEngine().GetResourceManager().AddFont( "custom_font", my_font ); // Set properties. @@ -289,14 +289,14 @@ void SampleApp::Run() { auto separatorv = sfg::Separator::Create( sfg::Separator::Orientation::VERTICAL ); m_table = sfg::Table::Create(); - m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect( 0, 0, 2, 1 ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND ); - m_table->Attach( sfg::Label::Create( L"Username:" ), sf::Rect( 0, 1, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( username_entry, sf::Rect( 1, 1, 1, 1 ), sfg::Table::EXPAND | sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( sfg::Label::Create( L"Password:" ), sf::Rect( 0, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( password, sf::Rect( 1, 2, 1, 1 ), sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( sfg::Button::Create( L"Login" ), sf::Rect( 2, 1, 1, 2 ), sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( separatorv, sf::Rect( 3, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); - m_table->Attach( m_progress_vert, sf::Rect( 4, 0, 1, 3 ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( sfg::Label::Create( L"Please login using your username and password (span example)." ), sf::Rect( { 0, 0 }, { 2, 1 } ), sfg::Table::FILL, sfg::Table::FILL | sfg::Table::EXPAND ); + m_table->Attach( sfg::Label::Create( L"Username:" ), sf::Rect( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( username_entry, sf::Rect( { 1, 1 }, { 1, 1 } ), sfg::Table::EXPAND | sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( sfg::Label::Create( L"Password:" ), sf::Rect( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( password, sf::Rect( { 1, 2 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( sfg::Button::Create( L"Login" ), sf::Rect( { 2, 1 }, { 1, 2 } ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( separatorv, sf::Rect( { 3, 0 }, { 1, 3 } ), sfg::Table::FILL, sfg::Table::FILL ); + m_table->Attach( m_progress_vert, sf::Rect( { 4, 0 }, { 1, 3 } ), sfg::Table::FILL, sfg::Table::FILL ); m_table->SetRowSpacings( 5.f ); m_table->SetColumnSpacings( 5.f ); @@ -510,9 +510,8 @@ void SampleApp::Run() { third_window->SetPosition( sf::Vector2f( 480.f, 20.f ) ); m_desktop.Add( third_window ); - sf::Texture texture; - texture.loadFromImage( sfgui_logo ); - m_canvas_sprite.setTexture( texture ); + const sf::Texture texture( sfgui_logo ); + m_canvas_sprite.emplace( texture ); //auto fourth_window = sfg::Window::Create( sfg::Window::TITLEBAR | sfg::Window::BACKGROUND | sfg::Window::RESIZE ); @@ -535,7 +534,7 @@ void SampleApp::Run() { sf::Clock clock; sf::Clock frame_time_clock; - sf::Int64 frame_times[5000]; + std::int64_t frame_times[5000]; std::size_t frame_times_index = 0; std::fill( std::begin( frame_times ), std::end( frame_times ), 0 ); @@ -543,15 +542,15 @@ void SampleApp::Run() { m_desktop.Update( 0.f ); while( m_window.isOpen() ) { - while( m_window.pollEvent( event ) ) { - if( event.type == sf::Event::Closed ) { + while( const std::optional event = m_window.pollEvent() ) { + if( event->is() ) { return; } - m_desktop.HandleEvent( event ); + m_desktop.HandleEvent( *event ); } - m_window.draw( m_background_sprite ); + m_window.draw( *m_background_sprite ); auto microseconds = clock.getElapsedTime().asMicroseconds(); @@ -573,7 +572,7 @@ void SampleApp::Run() { //m_sfml_canvas->Display(); //m_sfml_canvas->Unbind(); - m_window.setActive( true ); + (void)m_window.setActive( true ); } m_sfgui.Display( m_window ); @@ -589,7 +588,7 @@ void SampleApp::Run() { if( m_fps_clock.getElapsedTime().asMicroseconds() >= 1000000 ) { m_fps_clock.restart(); - sf::Int64 total_time = 0; + std::int64_t total_time = 0; for( std::size_t index = 0; index < 5000; ++index ) { total_time += frame_times[index]; @@ -707,10 +706,10 @@ void SampleApp::OnMirrorImageClick() { for( unsigned int height_index = 0; height_index < image.getSize().y; ++height_index ) { for( unsigned int width_index = 0; width_index < image.getSize().x / 2; ++width_index ) { - auto color0 = image.getPixel( width_index, height_index ); - auto color1 = image.getPixel( image.getSize().x - width_index - 1, height_index ); - image.setPixel( width_index, height_index, color1 ); - image.setPixel( image.getSize().x - width_index - 1, height_index, color0 ); + auto color0 = image.getPixel( { width_index, height_index } ); + auto color1 = image.getPixel( { image.getSize().x - width_index - 1, height_index } ); + image.setPixel( { width_index, height_index }, color1 ); + image.setPixel( { image.getSize().x - width_index - 1, height_index }, color0 ); } } @@ -787,7 +786,7 @@ void SampleApp::RenderCustomGL() { glRotatef( clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f ); glRotatef( clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f ); - glViewport( 0, 0, static_cast( std::floor( m_gl_canvas->GetAllocation().width + .5f ) ), static_cast( std::floor( m_gl_canvas->GetAllocation().height + .5f ) ) ); + glViewport( 0, 0, static_cast( std::floor( m_gl_canvas->GetAllocation().size.x + .5f ) ), static_cast( std::floor( m_gl_canvas->GetAllocation().size.y + .5f ) ) ); if( !m_custom_draw_display_list ) { m_custom_draw_display_list = glGenLists( 1 ); @@ -809,7 +808,7 @@ void SampleApp::RenderCustomGL() { static const auto far_distance = 20.f; // We set the proper aspect ratio using the dimensions of our Canvas. - auto aspect = m_gl_canvas->GetAllocation().width / m_gl_canvas->GetAllocation().height; + auto aspect = m_gl_canvas->GetAllocation().size.x / m_gl_canvas->GetAllocation().size.y; auto frustum_height = std::tan( fov / 360 * pi ) * near_distance; auto frustum_width = frustum_height * aspect; diff --git a/examples/Window.cpp b/examples/Window.cpp index 0d734ad2..1fafa135 100644 --- a/examples/Window.cpp +++ b/examples/Window.cpp @@ -8,7 +8,7 @@ int main() { // Create the main SFML window - sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Window Example", sf::Style::Titlebar | sf::Style::Close ); + sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Window Example", sf::Style::Titlebar | sf::Style::Close ); // We have to do this because we don't use SFML to draw. app_window.resetGLStates(); @@ -35,16 +35,14 @@ 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() ) { // Every frame we have to send SFML events to the window // to enable user interactivity. Without doing this your // GUI is nothing but a big colorful picture ;) - window->HandleEvent( event ); + window->HandleEvent( *event ); // Close window : exit - if ( event.type == sf::Event::Closed ) { + if ( event->is() ) { return EXIT_SUCCESS; } } diff --git a/include/SFGUI/Engine.hpp b/include/SFGUI/Engine.hpp index be76ffe3..5674abc9 100644 --- a/include/SFGUI/Engine.hpp +++ b/include/SFGUI/Engine.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sf { class String; @@ -192,7 +193,7 @@ class SFGUI_API Engine { * @param font_size Font size. * @return Metrics. */ - sf::Vector2f GetTextStringMetrics( const std::basic_string& string, const sf::Font& font, unsigned int font_size ) const; + sf::Vector2f GetTextStringMetrics( const std::u32string& string, const sf::Font& font, unsigned int font_size ) const; /** Get metrics of a text string. * @param string String. @@ -279,7 +280,7 @@ class SFGUI_API Engine { * @param low_bound Lower boundary of the character set, i.e. the glyph with the smallest codepoint. * @param high_bound Higher boundary of the character set, i.e. the glyph with the largest codepoint. */ - void AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ); + void AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ); protected: /** Ctor. @@ -312,7 +313,7 @@ class SFGUI_API Engine { mutable ResourceManager m_resource_manager; - std::vector> m_character_sets; + std::vector> m_character_sets; bool m_auto_refresh; }; diff --git a/include/SFGUI/Entry.hpp b/include/SFGUI/Entry.hpp index 6223607c..a41e4964 100644 --- a/include/SFGUI/Entry.hpp +++ b/include/SFGUI/Entry.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace sfg { @@ -70,12 +71,12 @@ class SFGUI_API Entry : public Widget { /** Hide all characters of the string with the given character. * @param c UTF-32 Character (0 to not hide text). */ - void HideText( sf::Uint32 c ); + void HideText( std::uint32_t c ); /** Get the character that hides all characters of the string. * @return UTF-32 Character. */ - sf::Uint32 GetHideCharacter() const; + std::uint32_t GetHideCharacter() const; /** Get maximum length. * @return Maximum length (0 if disabled). @@ -105,8 +106,8 @@ class SFGUI_API Entry : public Widget { void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override; void HandleUpdate( float seconds ) override; - void HandleTextEvent( sf::Uint32 character ) override; - void HandleKeyEvent( sf::Keyboard::Key key, bool press ) override; + void HandleTextEvent( char32_t character ) override; + void HandleKeyEvent( sf::Keyboard::Key key, sf::Keyboard::Scancode scancode, bool press ) override; void HandleSizeChange() override; void HandleFocusChange( Widget::Ptr focused_widget ) override; @@ -137,7 +138,7 @@ class SFGUI_API Entry : public Widget { mutable int m_visible_offset; // The UTF-32 character which hides each character of the string - sf::Uint32 m_text_placeholder; + std::uint32_t m_text_placeholder; // The maximum text length. If it equals to 0, it disables this limit int m_max_length; diff --git a/include/SFGUI/Renderer.hpp b/include/SFGUI/Renderer.hpp index 8ee7bd8b..d10be953 100644 --- a/include/SFGUI/Renderer.hpp +++ b/include/SFGUI/Renderer.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace sf { class Window; @@ -149,7 +150,7 @@ class SFGUI_API Renderer { * @param rotation_turns Turns to rotate the texture by in COUNTERCLOCKWISE direction. 1 turn is 90 degrees, -1 turn is -90 degrees etc. 0 to not rotate. * @return New sprite primitive. */ - std::shared_ptr CreateSprite( const sf::FloatRect& rect, std::shared_ptr texture, const sf::FloatRect& subrect = sf::FloatRect( 0.f, 0.f, 0.f, 0.f ), int rotation_turns = 0 ); + std::shared_ptr CreateSprite( const sf::FloatRect& rect, std::shared_ptr texture, const sf::FloatRect& subrect = sf::FloatRect( { 0.f, 0.f }, { 0.f, 0.f } ), int rotation_turns = 0 ); /** Create and register a new line primitive with the renderer. * @param begin Starting point of the line. @@ -249,7 +250,7 @@ class SFGUI_API Renderer { * @param low_bound Lower boundary of the character set, i.e. the glyph with the smallest codepoint. * @param high_bound Higher boundary of the character set, i.e. the glyph with the largest codepoint. */ - void AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ); + void AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ); /** Get name of the Renderer. * The name of a Renderer is a descriptive name of the Renderer itself. E.g. @@ -290,7 +291,7 @@ class SFGUI_API Renderer { std::deque m_textures; std::map> m_fonts; - std::vector> m_character_sets; + std::vector> m_character_sets; std::shared_ptr m_pseudo_texture; diff --git a/include/SFGUI/SFGUI.hpp b/include/SFGUI/SFGUI.hpp index 1939307a..2a191ca5 100644 --- a/include/SFGUI/SFGUI.hpp +++ b/include/SFGUI/SFGUI.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace sf { class Window; @@ -62,7 +63,7 @@ class SFGUI_API SFGUI { * @param low_bound Lower boundary of the character set, i.e. the glyph with the smallest codepoint. * @param high_bound Higher boundary of the character set, i.e. the glyph with the largest codepoint. */ - void AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ); + void AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ); }; } diff --git a/include/SFGUI/SpinButton.hpp b/include/SFGUI/SpinButton.hpp index 5bb0a5fc..bdfd9278 100644 --- a/include/SFGUI/SpinButton.hpp +++ b/include/SFGUI/SpinButton.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace sfg { @@ -112,8 +113,8 @@ class SFGUI_API SpinButton : public Entry { void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override; void HandleUpdate( float seconds ) override; - void HandleTextEvent( sf::Uint32 character ) override; - void HandleKeyEvent( sf::Keyboard::Key key, bool press ) override; + void HandleTextEvent( char32_t character ) override; + void HandleKeyEvent( sf::Keyboard::Key key, sf::Keyboard::Scancode scancode, bool press ) override; void HandleSizeChange() override; void HandleFocusChange( Widget::Ptr focused_widget ) override; diff --git a/include/SFGUI/Table.hpp b/include/SFGUI/Table.hpp index 09067522..d0c6274b 100644 --- a/include/SFGUI/Table.hpp +++ b/include/SFGUI/Table.hpp @@ -41,7 +41,7 @@ class SFGUI_API Table : public Container { * @param y_options Pack options for y axis. * @param padding Padding. */ - void Attach( Widget::Ptr widget, const sf::Rect& rect, int x_options = EXPAND | FILL, int y_options = EXPAND | FILL, const sf::Vector2f& padding = sf::Vector2f( 0.f, 0.f ) ); + void Attach( Widget::Ptr widget, const sf::Rect& rect, int x_options = EXPAND | FILL, int y_options = EXPAND | FILL, const sf::Vector2f& padding = sf::Vector2f( 0.f, 0.f ) ); /** Set column spacing. * @param index Column index. diff --git a/include/SFGUI/TableCell.hpp b/include/SFGUI/TableCell.hpp index 36fcc5ed..c5ece044 100644 --- a/include/SFGUI/TableCell.hpp +++ b/include/SFGUI/TableCell.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace sfg { @@ -23,10 +24,10 @@ class TableCell { * @param y_options_ Y options. * @param padding_ Padding. */ - TableCell( std::shared_ptr child_, const sf::Rect& rect_, int x_options_, int y_options_, const sf::Vector2f& padding_ ); + TableCell( std::shared_ptr child_, const sf::Rect& rect_, int x_options_, int y_options_, const sf::Vector2f& padding_ ); std::shared_ptr child; - sf::Rect rect; + sf::Rect rect; int x_options; int y_options; sf::Vector2f padding; diff --git a/include/SFGUI/Widget.hpp b/include/SFGUI/Widget.hpp index cabeafb2..7a418840 100644 --- a/include/SFGUI/Widget.hpp +++ b/include/SFGUI/Widget.hpp @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include namespace sf { class Event; @@ -329,12 +331,12 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this button = {} ) const; /** Set whether the given mouse button is down. * @param button Given mouse button. Defaults to clear button down state for all buttons. */ - void SetMouseButtonDown( sf::Mouse::Button button = sf::Mouse::ButtonCount ); + void SetMouseButtonDown( std::optional button = {} ); // Internal handling methods. @@ -356,7 +358,7 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_thisGetRequisition(); spare_space.x *= 1.f - GetScale().x; spare_space.y *= 1.f - GetScale().y; @@ -64,10 +64,10 @@ void Alignment::UpdateChild() { #endif } - allocation.left = spare_space.x * GetAlignment().x; - allocation.top = spare_space.y * GetAlignment().y; - allocation.width -= spare_space.x; - allocation.height -= spare_space.y; + allocation.position.x = spare_space.x * GetAlignment().x; + allocation.position.y = spare_space.y * GetAlignment().y; + allocation.size.x -= spare_space.x; + allocation.size.y -= spare_space.y; child->SetAllocation( allocation ); } diff --git a/src/SFGUI/Box.cpp b/src/SFGUI/Box.cpp index 3ac3030d..36b3facc 100644 --- a/src/SFGUI/Box.cpp +++ b/src/SFGUI/Box.cpp @@ -2,6 +2,7 @@ #include #include +#include #include namespace sfg { @@ -194,10 +195,10 @@ void Box::AllocateChildren() const { if( num_expand > 0 ) { if( m_orientation == Orientation::HORIZONTAL ) { - extra = std::max( 0.f, GetAllocation().width - GetRequisition().x ) / static_cast( num_expand ); + extra = std::max( 0.f, GetAllocation().size.x - GetRequisition().x ) / static_cast( num_expand ); } else { - extra = std::max( 0.f, GetAllocation().height - GetRequisition().y ) / static_cast( num_expand ); + extra = std::max( 0.f, GetAllocation().size.y - GetRequisition().y ) / static_cast( num_expand ); } } @@ -213,16 +214,16 @@ void Box::AllocateChildren() const { if( m_orientation == Orientation::HORIZONTAL ) { allocation.x = child.widget->GetRequisition().x + ( child.expand ? extra : 0.f ); - allocation.y = GetAllocation().height - 2 * gap; + allocation.y = GetAllocation().size.y - 2 * gap; - child.widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x - ( child.expand && !child.fill ? extra : 0.f ), allocation.y ) ); + child.widget->SetAllocation( sf::FloatRect( position, { allocation.x - ( child.expand && !child.fill ? extra : 0.f ), allocation.y }) ); position.x += allocation.x + GetSpacing(); } else { - allocation.x = GetAllocation().width - 2 * gap; + allocation.x = GetAllocation().size.x - 2 * gap; allocation.y = child.widget->GetRequisition().y + ( child.expand ? extra : 0.f ); - child.widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x, allocation.y - ( child.expand && !child.fill ? extra : 0.f ) ) ); + child.widget->SetAllocation( sf::FloatRect( position, { allocation.x, allocation.y - ( child.expand && !child.fill ? extra : 0.f ) }) ); position.y += allocation.y + GetSpacing(); } @@ -233,8 +234,8 @@ void Box::AllocateChildren() const { bool Box::IsChildInteresting( Widget* child ) const { return child->IsLocallyVisible() && - (child->GetRequisition().x > 0.f || child->GetAllocation().width > 0.0f) && - (child->GetRequisition().y > 0.f || child->GetAllocation().height > 0.0f) + (child->GetRequisition().x > 0.f || child->GetAllocation().size.x > 0.0f) && + (child->GetRequisition().y > 0.f || child->GetAllocation().size.y > 0.0f) ; } diff --git a/src/SFGUI/Button.cpp b/src/SFGUI/Button.cpp index 4d992218..f550ff58 100644 --- a/src/SFGUI/Button.cpp +++ b/src/SFGUI/Button.cpp @@ -64,7 +64,7 @@ void Button::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int / return; } - if( button == sf::Mouse::Left ) { + if( button == sf::Mouse::Button::Left ) { if( press ) { SetState( State::ACTIVE ); } @@ -132,14 +132,14 @@ void Button::AllocateChild() { sf::FloatRect allocation( GetAllocation() ); - allocation.left = padding + border_width; - allocation.top = padding + border_width; - allocation.width = child->GetRequisition().x; - allocation.height -= border_width * 2.f + padding * 2.f; + allocation.position.x = padding + border_width; + allocation.position.y = padding + border_width; + allocation.size.x = child->GetRequisition().x; + allocation.size.y -= border_width * 2.f + padding * 2.f; if( GetState() == State::ACTIVE ) { - allocation.left += border_width; - allocation.top += border_width; + allocation.position.x += border_width; + allocation.position.y += border_width; } child->SetAllocation( allocation ); diff --git a/src/SFGUI/Canvas.cpp b/src/SFGUI/Canvas.cpp index 521e3750..475908ec 100644 --- a/src/SFGUI/Canvas.cpp +++ b/src/SFGUI/Canvas.cpp @@ -199,7 +199,7 @@ void WipeStateCache( sf::RenderTarget& target ) { bool glStatesSet; bool ViewChanged; sf::BlendMode LastBlendMode; - sf::Uint64 LastTextureId; + std::uint64_t LastTextureId; bool UseVertexCache; sf::Vertex VertexCache[4]; }; @@ -285,8 +285,8 @@ void Canvas::HandleSizeChange() { m_custom_viewport->SetSize( sf::Vector2f( - std::floor( allocation.width + .5f ), - std::floor( allocation.height + .5f ) + std::floor( allocation.size.x + .5f ), + std::floor( allocation.size.y + .5f ) ) ); @@ -311,7 +311,7 @@ void Canvas::HandleAbsolutePositionChange() { Container::PtrConst viewport_parent = parent->GetParent(); while( viewport_parent && viewport_parent->GetName() == "Viewport" ) { - parent_position += sf::Vector2f( viewport_parent->GetAllocation().left, viewport_parent->GetAllocation().top ); + parent_position += viewport_parent->GetAllocation().position; viewport_parent = viewport_parent->GetParent(); } @@ -322,7 +322,7 @@ void Canvas::HandleAbsolutePositionChange() { } parent_position += viewport_parent->GetAbsolutePosition(); - parent_position += sf::Vector2f( parent->GetAllocation().left, parent->GetAllocation().top ); + parent_position += parent->GetAllocation().position; break; } @@ -367,14 +367,14 @@ void Canvas::Clear( const sf::Color& color, bool depth ) { m_render_texture = std::make_shared(); - if( !m_render_texture->create( static_cast( std::floor( allocation.width + .5f ) ), static_cast( std::floor( allocation.height + .5f ) ), sf::ContextSettings( m_depth ) ) ) { + if( !m_render_texture->resize( { static_cast( std::floor( allocation.size.x + .5f ) ), static_cast( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) { #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n"; #endif } } else if( m_resize ) { - if( !m_render_texture->create( static_cast( std::floor( allocation.width + .5f ) ), static_cast( std::floor( allocation.height + .5f ) ), sf::ContextSettings( m_depth ) ) ) { + if( !m_render_texture->resize( { static_cast( std::floor( allocation.size.x + .5f ) ), static_cast( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) { #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n"; #endif @@ -383,7 +383,7 @@ void Canvas::Clear( const sf::Color& color, bool depth ) { m_resize = false; - m_render_texture->setActive( true ); + (void)m_render_texture->setActive( true ); WipeStateCache( *m_render_texture ); @@ -443,14 +443,14 @@ void Canvas::Bind() { m_render_texture = std::make_shared(); - if( !m_render_texture->create( static_cast( std::floor( allocation.width + .5f ) ), static_cast( std::floor( allocation.height + .5f ) ), sf::ContextSettings( m_depth ) ) ) { + if( !m_render_texture->resize( { static_cast( std::floor( allocation.size.x + .5f ) ), static_cast( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) { #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n"; #endif } } else if( m_resize ) { - if( !m_render_texture->create( static_cast( std::floor( allocation.width + .5f ) ), static_cast( std::floor( allocation.height + .5f ) ), sf::ContextSettings( m_depth )) ) { + if( !m_render_texture->resize( { static_cast( std::floor( allocation.size.x + .5f ) ), static_cast( std::floor( allocation.size.y + .5f ) ) }, sf::ContextSettings{ m_depth } ) ) { #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: Canvas failed to create internal SFML RenderTexture.\n"; #endif @@ -459,7 +459,7 @@ void Canvas::Bind() { m_resize = false; - m_render_texture->setActive( true ); + (void)m_render_texture->setActive( true ); } void Canvas::Unbind() { @@ -467,7 +467,7 @@ void Canvas::Unbind() { return; } - m_render_texture->setActive( false ); + (void)m_render_texture->setActive( false ); } void Canvas::DrawRenderTexture() { @@ -557,7 +557,7 @@ void Canvas::DrawRenderTexture() { mutable bool pixels_flipped; bool unused7; bool unused8; - sf::Uint64 unused9; + std::uint64_t unused9; }; // Just so that SFML doesn't mess with the texture matrix. diff --git a/src/SFGUI/CheckButton.cpp b/src/SFGUI/CheckButton.cpp index b538a285..11cede59 100644 --- a/src/SFGUI/CheckButton.cpp +++ b/src/SFGUI/CheckButton.cpp @@ -48,10 +48,8 @@ void CheckButton::HandleSizeChange() { if( GetChild() ) { GetChild()->SetAllocation( sf::FloatRect( - box_size + spacing, - GetAllocation().height / 2.f - GetChild()->GetAllocation().height / 2.f, - GetChild()->GetRequisition().x, - GetChild()->GetRequisition().y + { box_size + spacing, GetAllocation().size.y / 2.f - GetChild()->GetAllocation().size.y / 2.f }, + GetChild()->GetRequisition() ) ); } diff --git a/src/SFGUI/ComboBox.cpp b/src/SFGUI/ComboBox.cpp index 454ec3e9..a9161257 100644 --- a/src/SFGUI/ComboBox.cpp +++ b/src/SFGUI/ComboBox.cpp @@ -218,11 +218,10 @@ void ComboBox::HandleMouseMoveEvent( int x, int y ) { if( GetState() == State::ACTIVE ) { if( m_scrollbar ) { - sf::Event event; + sf::Event::MouseMoved event; - event.type = sf::Event::MouseMoved; - event.mouseMove.x = x - static_cast( GetAllocation().left ); - event.mouseMove.y = y - static_cast( GetAllocation().top ); + event.position.x = x - static_cast( GetAllocation().position.x ); + event.position.y = y - static_cast( GetAllocation().position.y ); ReleaseModal(); m_scrollbar->SetActiveWidget(); @@ -231,10 +230,9 @@ void ComboBox::HandleMouseMoveEvent( int x, int y ) { GrabModal(); auto scrollbar_allocation = m_scrollbar->GetAllocation(); - scrollbar_allocation.left += GetAllocation().left; - scrollbar_allocation.top += GetAllocation().top; + scrollbar_allocation.position += GetAllocation().position; - if( scrollbar_allocation.contains( static_cast( x ), static_cast( y ) ) ) { + if( scrollbar_allocation.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_highlighted_item = NONE; Invalidate(); @@ -242,14 +240,14 @@ void ComboBox::HandleMouseMoveEvent( int x, int y ) { } } - if( ( x > GetAllocation().left ) && ( x < GetAllocation().left + GetAllocation().width ) ) { + if( ( x > GetAllocation().position.x ) && ( x < GetAllocation().position.x + GetAllocation().size.x ) ) { float padding( Context::Get().GetEngine().GetProperty( "ItemPadding", shared_from_this() ) ); const std::string& font_name( Context::Get().GetEngine().GetProperty( "FontName", shared_from_this() ) ); unsigned int font_size( Context::Get().GetEngine().GetProperty( "FontSize", shared_from_this() ) ); const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); auto line_y = y; - line_y -= static_cast( GetAllocation().top + GetAllocation().height + padding ); + line_y -= static_cast( GetAllocation().position.y + GetAllocation().size.y + padding ); line_y /= static_cast( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) + 2 * padding ); if( ( line_y < static_cast( GetItemCount() ) ) && ( line_y >= 0 ) ) { @@ -281,29 +279,36 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int if( GetState() == State::ACTIVE ) { if( m_scrollbar ) { - sf::Event event; - - event.type = press ? sf::Event::MouseButtonPressed : sf::Event::MouseButtonReleased; - event.mouseButton.button = button; - event.mouseButton.x = x - static_cast( GetAllocation().left ); - event.mouseButton.y = y - static_cast( GetAllocation().top ); - ReleaseModal(); m_scrollbar->SetActiveWidget(); - m_scrollbar->HandleEvent( event ); + + if ( press ) { + sf::Event::MouseButtonPressed event; + event.button = button; + event.position.x = x - static_cast( GetAllocation().position.x ); + event.position.y = y - static_cast( GetAllocation().position.y ); + m_scrollbar->HandleEvent( event ); + } + else { + sf::Event::MouseButtonReleased event; + event.button = button; + event.position.x = x - static_cast( GetAllocation().position.x ); + event.position.y = y - static_cast( GetAllocation().position.y ); + m_scrollbar->HandleEvent( event ); + } + SetActiveWidget(); GrabModal(); auto scrollbar_allocation = m_scrollbar->GetAllocation(); - scrollbar_allocation.left += GetAllocation().left; - scrollbar_allocation.top += GetAllocation().top; + scrollbar_allocation.position += GetAllocation().position; - if( scrollbar_allocation.contains( static_cast( x ), static_cast( y ) ) ) { + if( scrollbar_allocation.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { return; } } - if( !press || ( button != sf::Mouse::Left ) ) { + if( !press || ( button != sf::Mouse::Button::Left ) ) { return; } @@ -332,7 +337,7 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int return; } - if( press && ( button == sf::Mouse::Left ) && IsMouseInWidget() ) { + if( press && ( button == sf::Mouse::Button::Left ) && IsMouseInWidget() ) { m_highlighted_item = NONE; SetState( State::ACTIVE ); @@ -393,16 +398,16 @@ void ComboBox::HandleStateChange( State old_state ) { const sf::Vector2f item_size( - GetAllocation().width - 2 * border_width, + GetAllocation().size.x - 2 * border_width, line_height + 2 * padding ); m_scrollbar = Scrollbar::Create( Scrollbar::Orientation::VERTICAL ); - auto offset = ( GetState() == State::ACTIVE ? border_width : 0.f ) + GetAllocation().width - padding - line_height; + auto offset = ( GetState() == State::ACTIVE ? border_width : 0.f ) + GetAllocation().size.x - padding - line_height; - m_scrollbar->SetPosition( sf::Vector2f( offset, GetAllocation().height + border_width ) ); - m_scrollbar->SetRequisition( sf::Vector2f( GetAllocation().width - offset, static_cast( GetDisplayedItemCount() ) * item_size.y - 2.f * border_width ) ); + m_scrollbar->SetPosition( sf::Vector2f( offset, GetAllocation().size.y + border_width ) ); + m_scrollbar->SetRequisition( sf::Vector2f( GetAllocation().size.x - offset, static_cast( GetDisplayedItemCount() ) * item_size.y - 2.f * border_width ) ); m_scrollbar->GetAdjustment()->SetPageSize( static_cast( GetDisplayedItemCount() ) ); m_scrollbar->GetAdjustment()->SetLower( 0.f ); @@ -455,7 +460,7 @@ ComboBox::IndexType ComboBox::GetDisplayedItemCount() const { const float line_height( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) ); const sf::Vector2f item_size( - GetAllocation().width - 2 * border_width, + GetAllocation().size.x - 2 * border_width, line_height + 2 * padding ); diff --git a/src/SFGUI/Container.cpp b/src/SFGUI/Container.cpp index 9150edde..88e072f7 100644 --- a/src/SFGUI/Container.cpp +++ b/src/SFGUI/Container.cpp @@ -2,6 +2,8 @@ #include +#include + namespace sfg { void Container::Add( Widget::Ptr widget ) { @@ -61,17 +63,15 @@ void Container::HandleEvent( const sf::Event& event ) { // coordinates if event is a mouse event. sf::Event local_event( event ); - if( local_event.type == sf::Event::MouseMoved ) { - local_event.mouseMove.x -= static_cast( GetAllocation().left ); - local_event.mouseMove.y -= static_cast( GetAllocation().top ); + if( const auto* mouseMoved = local_event.getIf() ) { + local_event = sf::Event::MouseMoved{ mouseMoved->position - sf::Vector2i( GetAllocation().position ) }; } - if( - local_event.type == sf::Event::MouseButtonPressed || - local_event.type == sf::Event::MouseButtonReleased - ) { - local_event.mouseButton.x -= static_cast( GetAllocation().left ); - local_event.mouseButton.y -= static_cast( GetAllocation().top ); + if( const auto* mouseButtonPressed = local_event.getIf()) { + local_event = sf::Event::MouseButtonPressed{ mouseButtonPressed->button, mouseButtonPressed->position - sf::Vector2i( GetAllocation().position ) }; + } + if( const auto* mouseButtonReleased = local_event.getIf()) { + local_event = sf::Event::MouseButtonReleased{ mouseButtonReleased->button, mouseButtonReleased->position - sf::Vector2i( GetAllocation().position ) }; } // Pass event to children. diff --git a/src/SFGUI/DejaVuSansFont.cpp b/src/SFGUI/DejaVuSansFont.cpp index 16b1579e..69a58977 100644 --- a/src/SFGUI/DejaVuSansFont.cpp +++ b/src/SFGUI/DejaVuSansFont.cpp @@ -48,7 +48,7 @@ sf::Font LoadDejaVuSansFont() { font_data_decoded = true; } - if( !font.loadFromMemory( font_data, font_data_len ) ) { + if( !font.openFromMemory( font_data, font_data_len ) ) { #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: Failed to load DejaVuSans.\n"; #endif diff --git a/src/SFGUI/Desktop.cpp b/src/SFGUI/Desktop.cpp index 2214101d..f314340b 100644 --- a/src/SFGUI/Desktop.cpp +++ b/src/SFGUI/Desktop.cpp @@ -2,8 +2,9 @@ #include #include -#include +#include #include +#include namespace sfg { @@ -29,18 +30,22 @@ void Desktop::HandleEvent( const sf::Event& event ) { Widget::Ptr last_receiver( m_last_receiver.lock() ); // If we've got a mouse event, get local mouse position and mark event for being checked against widget's allocation. - if( event.type == sf::Event::MouseMoved ) { - m_last_mouse_pos.x = event.mouseMove.x; - m_last_mouse_pos.y = event.mouseMove.y; - position = sf::Vector2f( static_cast( event.mouseMove.x ), static_cast( event.mouseMove.y ) ); + const auto onMouseButtonPressedOrRelease = [&]( auto& mouseButtonEvent ) { + m_last_mouse_pos = mouseButtonEvent.position; + position = sf::Vector2f( mouseButtonEvent.position ); check_inside = true; - } - else if( event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased ) { - m_last_mouse_pos.x = event.mouseButton.x; - m_last_mouse_pos.y = event.mouseButton.y; - position = sf::Vector2f( static_cast( event.mouseButton.x ), static_cast( event.mouseButton.y ) ); + }; + if( const auto* mouseMoved = event.getIf() ) { + m_last_mouse_pos = mouseMoved->position; + position = sf::Vector2f( mouseMoved->position ); check_inside = true; } + else if( auto* mouseButtonPressed = event.getIf() ) { + onMouseButtonPressedOrRelease( *mouseButtonPressed ); + } + else if( auto* mouseButtonRelease = event.getIf() ) { + onMouseButtonPressedOrRelease( *mouseButtonRelease ); + } for( int index = 0; index < static_cast( m_children.size() ); ++index ) { Widget::Ptr widget( m_children[static_cast( index )] ); @@ -56,7 +61,7 @@ void Desktop::HandleEvent( const sf::Event& event ) { // If there is a modal widget, skip reordering. if( index > 0 && - event.type == sf::Event::MouseButtonPressed && + event.is() && is_inside && !Widget::HasModal() ) { @@ -77,7 +82,7 @@ void Desktop::HandleEvent( const sf::Event& event ) { // that states are reset correctly. Warning, this is a hack, but it worksâ„¢. // The fake event is also sent when the last mouse move event receiver // isn't the current and top one. - if( event.type == sf::Event::MouseMoved && last_receiver && last_receiver != widget && last_receiver != m_children.front() ) { + if( event.is() && last_receiver && last_receiver != widget && last_receiver != m_children.front() ) { SendFakeMouseMoveEvent( last_receiver ); m_last_receiver = widget; last_receiver = widget; @@ -105,7 +110,7 @@ void Desktop::Add( std::shared_ptr widget ) { // Get old focused widget out of State::PRELIGHT state if mouse is inside the new // widget. if( m_children.size() ) { - if( widget->GetAllocation().contains( static_cast( m_last_mouse_pos.x ), static_cast( m_last_mouse_pos.y ) ) ) { + if( widget->GetAllocation().contains( sf::Vector2f( m_last_mouse_pos ) ) ) { SendFakeMouseMoveEvent( m_children.front() ); } } @@ -114,7 +119,7 @@ void Desktop::Add( std::shared_ptr widget ) { RecalculateWidgetLevels(); - if( widget->GetAllocation().contains( static_cast( m_last_mouse_pos.x ), static_cast( m_last_mouse_pos.y ) ) ) { + if( widget->GetAllocation().contains( sf::Vector2f (m_last_mouse_pos ) ) ) { SendFakeMouseMoveEvent( widget, m_last_mouse_pos.x, m_last_mouse_pos.y ); } @@ -140,7 +145,7 @@ void Desktop::Remove( std::shared_ptr widget ) { RecalculateWidgetLevels(); - if( !m_children.empty() && m_children.front()->GetAllocation().contains( static_cast( m_last_mouse_pos.x ), static_cast( m_last_mouse_pos.y ) ) ) { + if( !m_children.empty() && m_children.front()->GetAllocation().contains( sf::Vector2f( m_last_mouse_pos ) ) ) { SendFakeMouseMoveEvent( m_children.front(), m_last_mouse_pos.x, m_last_mouse_pos.y ); } } @@ -188,7 +193,7 @@ void Desktop::BringToFront( std::shared_ptr child ) { return; } - if( child->GetAllocation().contains( static_cast( m_last_mouse_pos.x ), static_cast( m_last_mouse_pos.y ) ) ) { + if( child->GetAllocation().contains( sf::Vector2f( m_last_mouse_pos ) ) ) { SendFakeMouseMoveEvent( m_children.front() ); } @@ -198,17 +203,13 @@ void Desktop::BringToFront( std::shared_ptr child ) { RecalculateWidgetLevels(); - if( child->GetAllocation().contains( static_cast( m_last_mouse_pos.x ), static_cast( m_last_mouse_pos.y ) ) ) { + if( child->GetAllocation().contains( sf::Vector2f( m_last_mouse_pos ) ) ) { SendFakeMouseMoveEvent( ptr, m_last_mouse_pos.x, m_last_mouse_pos.y ); } } void Desktop::SendFakeMouseMoveEvent( std::shared_ptr widget, int x, int y ) const { - sf::Event fake_event; - fake_event.type = sf::Event::MouseMoved; - fake_event.mouseMove.x = x; - fake_event.mouseMove.y = y; - widget->HandleEvent( fake_event ); + widget->HandleEvent( sf::Event::MouseMoved{ { x, y } } ); } void Desktop::RecalculateWidgetLevels() { diff --git a/src/SFGUI/Engine.cpp b/src/SFGUI/Engine.cpp index 97d0f6fe..0e9818d0 100644 --- a/src/SFGUI/Engine.cpp +++ b/src/SFGUI/Engine.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -40,10 +41,10 @@ std::istream& operator>>( std::istream& stream, Color& color ) { auto b_val = std::strtol( buffer.substr( 5, 2 ).c_str(), nullptr, 16 ); auto a_val = std::strtol( buffer.substr( 7, 2 ).c_str(), nullptr, 16 ); - color.r = static_cast( r_val ); - color.g = static_cast( g_val ); - color.b = static_cast( b_val ); - color.a = static_cast( a_val ); + color.r = static_cast( r_val ); + color.g = static_cast( g_val ); + color.b = static_cast( b_val ); + color.a = static_cast( a_val ); return stream; } @@ -73,7 +74,7 @@ sf::Vector2f Engine::GetFontHeightProperties( const sf::Font& font, unsigned int // Since maps allocate everything non-contiguously on the heap we can use void* instead of Page here. mutable std::map unused4; - mutable std::vector unused5; + mutable std::vector unused5; }; // All your font face are belong to us too. @@ -90,18 +91,18 @@ sf::Vector2f Engine::GetFontHeightProperties( const sf::Font& font, unsigned int sf::Vector2f properties( 0.f, 0.f ); if( m_character_sets.empty() ) { - for( sf::Uint32 current_character = 0; current_character < 0x0370; ++current_character ) { + for( std::uint32_t current_character = 0; current_character < 0x0370; ++current_character ) { const auto& glyph = font.getGlyph( current_character, font_size, false ); - properties.x = std::max( properties.x, static_cast( glyph.bounds.height ) ); - properties.y = std::max( properties.y, static_cast( -glyph.bounds.top ) ); + properties.x = std::max( properties.x, static_cast( glyph.bounds.size.y ) ); + properties.y = std::max( properties.y, static_cast( -glyph.bounds.position.y ) ); } } for( const auto character_set : m_character_sets ) { - for( sf::Uint32 current_character = character_set.first; current_character < character_set.second; ++current_character ) { + for( std::uint32_t current_character = character_set.first; current_character < character_set.second; ++current_character ) { const auto& glyph = font.getGlyph( current_character, font_size, false ); - properties.x = std::max( properties.x, static_cast( glyph.bounds.height ) ); - properties.y = std::max( properties.y, static_cast( -glyph.bounds.top ) ); + properties.x = std::max( properties.x, static_cast( glyph.bounds.size.y ) ); + properties.y = std::max( properties.y, static_cast( -glyph.bounds.position.y ) ); } } @@ -122,7 +123,7 @@ float Engine::GetFontLineSpacing( const sf::Font& font, unsigned int font_size ) return static_cast( font.getLineSpacing( font_size ) ); } -sf::Vector2f Engine::GetTextStringMetrics( const std::basic_string& string, const sf::Font& font, unsigned int font_size ) const { +sf::Vector2f Engine::GetTextStringMetrics( const std::u32string& string, const sf::Font& font, unsigned int font_size ) const { // SFML is incapable of giving us the metrics we need so we have to do it ourselves. auto horizontal_spacing = static_cast( font.getGlyph( L' ', font_size, false ).advance ); auto vertical_spacing = static_cast( font.getLineSpacing( font_size ) ); @@ -131,7 +132,7 @@ sf::Vector2f Engine::GetTextStringMetrics( const std::basic_string& const static auto tab_spaces = 2.f; - sf::Uint32 previous_character = 0; + std::uint32_t previous_character = 0; auto longest_line = 0.f; @@ -160,7 +161,7 @@ sf::Vector2f Engine::GetTextStringMetrics( const std::basic_string& const auto& glyph = font.getGlyph( current_character, font_size, false ); metrics.x += static_cast( glyph.advance ); - metrics.y = std::max( metrics.y, static_cast( glyph.bounds.height ) ); + metrics.y = std::max( metrics.y, static_cast( glyph.bounds.size.y ) ); } metrics.x = std::max( longest_line, metrics.x ); @@ -177,7 +178,7 @@ sf::Vector2f Engine::GetTextStringMetrics( const sf::String& string, const sf::F const static auto tab_spaces = 2.f; - sf::Uint32 previous_character = 0; + std::uint32_t previous_character = 0; auto longest_line = 0.f; @@ -206,7 +207,7 @@ sf::Vector2f Engine::GetTextStringMetrics( const sf::String& string, const sf::F const auto& glyph = font.getGlyph( current_character, font_size, false ); metrics.x += static_cast( glyph.advance ); - metrics.y = std::max( metrics.y, static_cast( glyph.bounds.height ) ); + metrics.y = std::max( metrics.y, static_cast( glyph.bounds.size.y ) ); } metrics.x = std::max( longest_line, metrics.x ); @@ -243,13 +244,13 @@ bool Engine::LoadThemeFromFile( const std::string& filename ) { void Engine::ShiftBorderColors( sf::Color& light_color, sf::Color& dark_color, int offset ) const { // TODO: Replace by += and -=. Currently not possible with SFML (see SFML issue #114). - light_color.r = static_cast( std::max( 0, std::min( 255, static_cast( light_color.r ) + offset ) ) ); - light_color.g = static_cast( std::max( 0, std::min( 255, static_cast( light_color.g ) + offset ) ) ); - light_color.b = static_cast( std::max( 0, std::min( 255, static_cast( light_color.b ) + offset ) ) ); + light_color.r = static_cast( std::max( 0, std::min( 255, static_cast( light_color.r ) + offset ) ) ); + light_color.g = static_cast( std::max( 0, std::min( 255, static_cast( light_color.g ) + offset ) ) ); + light_color.b = static_cast( std::max( 0, std::min( 255, static_cast( light_color.b ) + offset ) ) ); - dark_color.r = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.r ) - offset ) ) ); - dark_color.g = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.g ) - offset ) ) ); - dark_color.b = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.b ) - offset ) ) ); + dark_color.r = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.r ) - offset ) ) ); + dark_color.g = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.g ) - offset ) ) ); + dark_color.b = static_cast( std::min( 255, std::max( 0, static_cast( dark_color.b ) - offset ) ) ); } const std::string* Engine::GetValue( const std::string& property, Widget::PtrConst widget ) const { @@ -307,7 +308,7 @@ ResourceManager& Engine::GetResourceManager() const { return m_resource_manager; } -void Engine::AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ) { +void Engine::AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ) { if( high_bound <= low_bound ) { return; } diff --git a/src/SFGUI/Engines/BREW.cpp b/src/SFGUI/Engines/BREW.cpp index a221c1ed..bb0833ff 100644 --- a/src/SFGUI/Engines/BREW.cpp +++ b/src/SFGUI/Engines/BREW.cpp @@ -165,8 +165,8 @@ std::unique_ptr BREW::CreateBorder( const sf::FloatRect& rect, floa // Top queue->Add( Renderer::Get().CreateLine( - sf::Vector2f( rect.left, rect.top ), - sf::Vector2f( rect.left + rect.width, rect.top ), + rect.position, + sf::Vector2f( rect.position.x + rect.size.x, rect.position.y ), light_color, border_width ) @@ -175,8 +175,8 @@ std::unique_ptr BREW::CreateBorder( const sf::FloatRect& rect, floa // Right queue->Add( Renderer::Get().CreateLine( - sf::Vector2f( rect.left + rect.width, rect.top ), - sf::Vector2f( rect.left + rect.width, rect.top + rect.height ), + sf::Vector2f( rect.position.x + rect.size.x, rect.position.y ), + sf::Vector2f( rect.position.x + rect.size.x, rect.position.y + rect.size.y ), dark_color, border_width ) @@ -185,8 +185,8 @@ std::unique_ptr BREW::CreateBorder( const sf::FloatRect& rect, floa // Bottom queue->Add( Renderer::Get().CreateLine( - sf::Vector2f( rect.left + rect.width, rect.top + rect.height ), - sf::Vector2f( rect.left, rect.top + rect.height ), + sf::Vector2f( rect.position.x + rect.size.x, rect.position.y + rect.size.y ), + sf::Vector2f( rect.position.x, rect.position.y + rect.size.y ), dark_color, border_width ) @@ -195,8 +195,8 @@ std::unique_ptr BREW::CreateBorder( const sf::FloatRect& rect, floa // Left queue->Add( Renderer::Get().CreateLine( - sf::Vector2f( rect.left, rect.top + rect.height ), - sf::Vector2f( rect.left, rect.top ), + sf::Vector2f( rect.position.x, rect.position.y + rect.size.y ), + sf::Vector2f( rect.position.x, rect.position.y ), light_color, border_width ) @@ -209,10 +209,10 @@ std::unique_ptr BREW::CreateSlider( const sf::FloatRect& rect, sf:: std::unique_ptr queue( new RenderQueue ); // Align rect to pixels - auto left = std::floor( rect.left + .5f ); - auto top = std::floor( rect.top + .5f ); - auto width = std::floor( rect.width + .5f ); - auto height = std::floor( rect.height + .5f ); + auto left = std::floor( rect.position.x + .5f ); + auto top = std::floor( rect.position.y + .5f ); + auto width = std::floor( rect.size.x + .5f ); + auto height = std::floor( rect.size.y + .5f ); queue->Add( Renderer::Get().CreatePane( @@ -232,10 +232,10 @@ std::unique_ptr BREW::CreateStepper( const sf::FloatRect& rect, sf: std::unique_ptr queue( new RenderQueue ); // Align rect to pixels - auto left = std::floor( rect.left + .5f ); - auto top = std::floor( rect.top + .5f ); - auto width = std::floor( rect.width + .5f ); - auto height = std::floor( rect.height + .5f ); + auto left = std::floor( rect.position.x + .5f ); + auto top = std::floor( rect.position.y + .5f ); + auto width = std::floor( rect.size.x + .5f ); + auto height = std::floor( rect.size.y + .5f ); if( pressed ) { border_color_shift = -border_color_shift; diff --git a/src/SFGUI/Engines/BREW/Button.cpp b/src/SFGUI/Engines/BREW/Button.cpp index a5d4d271..3e1d22da 100644 --- a/src/SFGUI/Engines/BREW/Button.cpp +++ b/src/SFGUI/Engines/BREW/Button.cpp @@ -29,7 +29,7 @@ std::unique_ptr BREW::CreateButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( button->GetAllocation().width, button->GetAllocation().height ), + sf::Vector2f( button->GetAllocation().size.x, button->GetAllocation().size.y ), border_width, background_color, border_color, @@ -42,22 +42,22 @@ std::unique_ptr BREW::CreateButtonDrawable( std::shared_ptrGetLabel(), *font, font_size ); metrics.y = GetFontLineHeight( *font, font_size ); - sf::Text text( button->GetLabel(), *font, font_size ); + sf::Text text( *font, button->GetLabel(), font_size ); auto offset = ( button->GetState() == Button::State::ACTIVE ) ? border_width : 0.f; sfg::Widget::PtrConst child( button->GetChild() ); if( !child ) { text.setPosition( - button->GetAllocation().width / 2.f - metrics.x / 2.f + offset, - button->GetAllocation().height / 2.f - metrics.y / 2.f + offset + { button->GetAllocation().size.x / 2.f - metrics.x / 2.f + offset, + button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } ); } else { - float width( button->GetAllocation().width - spacing - child->GetAllocation().width ); + float width( button->GetAllocation().size.x - spacing - child->GetAllocation().size.x ); text.setPosition( - child->GetAllocation().width + spacing + (width / 2.f - metrics.x / 2.f) + offset, - button->GetAllocation().height / 2.f - metrics.y / 2.f + offset + { child->GetAllocation().size.x + spacing + (width / 2.f - metrics.x / 2.f) + offset, + button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } ); } diff --git a/src/SFGUI/Engines/BREW/CheckButton.cpp b/src/SFGUI/Engines/BREW/CheckButton.cpp index f8f28b2b..45fe6e37 100644 --- a/src/SFGUI/Engines/BREW/CheckButton.cpp +++ b/src/SFGUI/Engines/BREW/CheckButton.cpp @@ -27,7 +27,7 @@ std::unique_ptr BREW::CreateCheckButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( - sf::Vector2f( 0.f, check->GetAllocation().height / 2.f - box_size / 2.f ), + sf::Vector2f( 0.f, check->GetAllocation().size.y / 2.f - box_size / 2.f ), sf::Vector2f( box_size, box_size ), border_width, background_color, @@ -42,10 +42,8 @@ std::unique_ptr BREW::CreateCheckButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - box_size / 2 - check_size / 2, - check->GetAllocation().height / 2.f - box_size / 2.f + diff / 2.f, - check_size - 1.f, - check_size - 1.f + { box_size / 2 - check_size / 2, check->GetAllocation().size.y / 2.f - box_size / 2.f + diff / 2.f }, + { check_size - 1.f, check_size - 1.f } ), check_color ) @@ -57,10 +55,10 @@ std::unique_ptr BREW::CreateCheckButtonDrawable( std::shared_ptrGetLabel(), *font, font_size ); metrics.y = GetFontLineHeight( *font, font_size ); - sf::Text text( check->GetLabel(), *font, font_size ); + sf::Text text( *font, check->GetLabel(), font_size ); text.setPosition( - box_size + spacing, - check->GetAllocation().height / 2.f - metrics.y / 2.f + { box_size + spacing, + check->GetAllocation().size.y / 2.f - metrics.y / 2.f } ); text.setFillColor( color ); queue->Add( Renderer::Get().CreateText( text ) ); diff --git a/src/SFGUI/Engines/BREW/ComboBox.cpp b/src/SFGUI/Engines/BREW/ComboBox.cpp index 8c0f3098..bd46408f 100644 --- a/src/SFGUI/Engines/BREW/ComboBox.cpp +++ b/src/SFGUI/Engines/BREW/ComboBox.cpp @@ -32,7 +32,7 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( combo_box->GetAllocation().width, combo_box->GetAllocation().height ), + sf::Vector2f( combo_box->GetAllocation().size.x, combo_box->GetAllocation().size.y ), border_width, background_color, border_color, @@ -42,12 +42,12 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrIsDropDownDisplayed() ) { const sf::Vector2f item_size( - combo_box->GetAllocation().width - 2 * border_width, + combo_box->GetAllocation().size.x - 2 * border_width, line_height + 2 * padding ); sf::Vector2f item_position( 0.f, - combo_box->GetAllocation().height + combo_box->GetAllocation().size.y ); auto expanded_height = static_cast( combo_box->GetDisplayedItemCount() ) * item_size.y; @@ -55,8 +55,8 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( - sf::Vector2f( 0.f, combo_box->GetAllocation().height ), - sf::Vector2f( combo_box->GetAllocation().width, expanded_height ), + sf::Vector2f( 0.f, combo_box->GetAllocation().size.y ), + sf::Vector2f( combo_box->GetAllocation().size.x, expanded_height ), border_width, background_color, border_color, @@ -75,18 +75,16 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - item_position.x + border_width, - item_position.y + border_width, - item_size.x, - item_size.y - 2.f * border_width + { item_position.x + border_width, item_position.y + border_width }, + { item_size.x, item_size.y - 2.f * border_width } ), highlighted_color ) ); } - sf::Text text( combo_box->GetItem( item_index ), *font, font_size ); - text.setPosition( item_position.x + padding, item_position.y + padding ); + sf::Text text( *font, combo_box->GetItem( item_index ), font_size ); + text.setPosition( { item_position.x + padding, item_position.y + padding } ); text.setFillColor( color ); queue->Add( Renderer::Get().CreateText( text ) ); @@ -95,10 +93,10 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrGetSelectedItem() != ComboBox::NONE ) { - sf::Text text( combo_box->GetSelectedText(), *font, font_size ); + sf::Text text( *font, combo_box->GetSelectedText(), font_size ); text.setPosition( - border_width + padding, - combo_box->GetAllocation().height / 2.f - line_height / 2.f + { border_width + padding, + combo_box->GetAllocation().size.y / 2.f - line_height / 2.f } ); text.setFillColor( color ); queue->Add( Renderer::Get().CreateText( text ) ); @@ -106,7 +104,7 @@ std::unique_ptr BREW::CreateComboBoxDrawable( std::shared_ptrGetState() == ComboBox::State::ACTIVE ? border_width : 0.f ) + combo_box->GetAllocation().width - padding - GetFontLineHeight( *font, font_size ), + ( combo_box->GetState() == ComboBox::State::ACTIVE ? border_width : 0.f ) + combo_box->GetAllocation().size.x - padding - GetFontLineHeight( *font, font_size ), ( combo_box->GetState() == ComboBox::State::ACTIVE ? border_width : 0.f ) + padding ); diff --git a/src/SFGUI/Engines/BREW/Entry.cpp b/src/SFGUI/Engines/BREW/Entry.cpp index 40c7b28d..1227a9f8 100644 --- a/src/SFGUI/Engines/BREW/Entry.cpp +++ b/src/SFGUI/Engines/BREW/Entry.cpp @@ -27,7 +27,7 @@ std::unique_ptr BREW::CreateEntryDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( entry->GetAllocation().width, entry->GetAllocation().height ), + sf::Vector2f( entry->GetAllocation().size.x, entry->GetAllocation().size.y ), border_width, background_color, border_color, @@ -36,9 +36,9 @@ std::unique_ptr BREW::CreateEntryDrawable( std::shared_ptrGetVisibleText(), *font, font_size ); + sf::Text vis_label( *font, entry->GetVisibleText(), font_size ); vis_label.setFillColor( text_color ); - vis_label.setPosition( text_padding, entry->GetAllocation().height / 2.f - line_height / 2.f ); + vis_label.setPosition( { text_padding, entry->GetAllocation().size.y / 2.f - line_height / 2.f } ); queue->Add( Renderer::Get().CreateText( vis_label ) ); @@ -55,10 +55,8 @@ std::unique_ptr BREW::CreateEntryDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - metrics.x + text_padding, - entry->GetAllocation().height / 2.f - line_height / 2.f, - cursor_thickness, - line_height + { metrics.x + text_padding, entry->GetAllocation().size.y / 2.f - line_height / 2.f }, + { cursor_thickness, line_height } ), cursor_color ) diff --git a/src/SFGUI/Engines/BREW/Frame.cpp b/src/SFGUI/Engines/BREW/Frame.cpp index 08079386..f4a405e1 100644 --- a/src/SFGUI/Engines/BREW/Frame.cpp +++ b/src/SFGUI/Engines/BREW/Frame.cpp @@ -24,8 +24,8 @@ std::unique_ptr BREW::CreateFrameDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, line_height / 2.f + border_width / 2.f ), - sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, frame->GetAllocation().height - border_width ), + sf::Vector2f( frame->GetAllocation().size.x - border_width / 2.f, line_height / 2.f + border_width / 2.f ), + sf::Vector2f( frame->GetAllocation().size.x - border_width / 2.f, frame->GetAllocation().size.y - border_width ), border_color, border_width ) @@ -34,8 +34,8 @@ std::unique_ptr BREW::CreateFrameDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, frame->GetAllocation().height - border_width ), - sf::Vector2f( border_width / 2.f, frame->GetAllocation().height - border_width ), + sf::Vector2f( frame->GetAllocation().size.x - border_width / 2.f, frame->GetAllocation().size.y - border_width ), + sf::Vector2f( border_width / 2.f, frame->GetAllocation().size.y - border_width ), border_color, border_width ) @@ -44,7 +44,7 @@ std::unique_ptr BREW::CreateFrameDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( border_width / 2.f, frame->GetAllocation().height - border_width ), + sf::Vector2f( border_width / 2.f, frame->GetAllocation().size.y - border_width ), sf::Vector2f( border_width / 2.f, line_height / 2.f + border_width / 2.f ), border_color, border_width @@ -60,11 +60,11 @@ std::unique_ptr BREW::CreateFrameDrawable( std::shared_ptrGetLabel(), *font, font_size ); metrics.x += 2.f * label_padding; - label_start_x = padding + ( alignment * ( frame->GetAllocation().width - 2.f * padding - metrics.x ) ); + label_start_x = padding + ( alignment * ( frame->GetAllocation().size.x - 2.f * padding - metrics.x ) ); label_end_x = label_start_x + metrics.x; - sf::Text text( frame->GetLabel(), *font, font_size ); - text.setPosition( label_start_x + label_padding, border_width / 2.f ); + sf::Text text( *font, frame->GetLabel(), font_size ); + text.setPosition( { label_start_x + label_padding, border_width / 2.f } ); text.setFillColor( color ); queue->Add( Renderer::Get().CreateText( text ) ); } @@ -83,7 +83,7 @@ std::unique_ptr BREW::CreateFrameDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( sf::Vector2f( label_end_x + .5f * border_width, line_height / 2.f + border_width / 2.f ), - sf::Vector2f( frame->GetAllocation().width - border_width / 2.f, line_height / 2.f + border_width / 2.f ), + sf::Vector2f( frame->GetAllocation().size.x - border_width / 2.f, line_height / 2.f + border_width / 2.f ), border_color, border_width ) diff --git a/src/SFGUI/Engines/BREW/Image.cpp b/src/SFGUI/Engines/BREW/Image.cpp index 4a186b30..b2039823 100644 --- a/src/SFGUI/Engines/BREW/Image.cpp +++ b/src/SFGUI/Engines/BREW/Image.cpp @@ -14,10 +14,8 @@ std::unique_ptr BREW::CreateImageDrawable( std::shared_ptrAdd( Renderer::Get().CreateSprite( sf::FloatRect( - ( image->GetAllocation().width - image->GetRequisition().x ) * image->GetAlignment().x, - ( image->GetAllocation().height - image->GetRequisition().y ) * image->GetAlignment().y, - static_cast( image->GetImage().getSize().x ), - static_cast( image->GetImage().getSize().y ) + (image->GetAllocation().size - image->GetRequisition()).componentWiseMul( image->GetAlignment() ), + sf::Vector2f( image->GetImage().getSize() ) ), texture ) diff --git a/src/SFGUI/Engines/BREW/Label.cpp b/src/SFGUI/Engines/BREW/Label.cpp index 2e2e3918..a8ce9b3e 100644 --- a/src/SFGUI/Engines/BREW/Label.cpp +++ b/src/SFGUI/Engines/BREW/Label.cpp @@ -16,15 +16,15 @@ std::unique_ptr BREW::CreateLabelDrawable( std::shared_ptr queue( new RenderQueue ); - sf::Text vis_label( label->GetWrappedText(), *font, font_size ); + sf::Text vis_label( *font, label->GetWrappedText(), font_size ); vis_label.setFillColor( font_color ); if( !label->GetLineWrap() ) { // Calculate alignment when word wrap is disabled. - sf::Vector2f avail_space( label->GetAllocation().width - label->GetRequisition().x, label->GetAllocation().height - label->GetRequisition().y ); + sf::Vector2f avail_space( label->GetAllocation().size.x - label->GetRequisition().x, label->GetAllocation().size.y - label->GetRequisition().y ); sf::Vector2f position( avail_space.x * label->GetAlignment().x, avail_space.y * label->GetAlignment().y ); - vis_label.setPosition( position.x, position.y ); + vis_label.setPosition( position ); } queue->Add( Renderer::Get().CreateText( vis_label ) ); diff --git a/src/SFGUI/Engines/BREW/Notebook.cpp b/src/SFGUI/Engines/BREW/Notebook.cpp index 8d86b5be..4d33adca 100644 --- a/src/SFGUI/Engines/BREW/Notebook.cpp +++ b/src/SFGUI/Engines/BREW/Notebook.cpp @@ -34,10 +34,10 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetPrelightTab(); // Get size in the dimension all tabs have uniform size. - sf::Vector2f tab_size( notebook->GetNthTabLabel( 0 )->GetAllocation().width, notebook->GetNthTabLabel( 0 )->GetAllocation().height ); + sf::Vector2f tab_size( notebook->GetNthTabLabel( 0 )->GetAllocation().size.x, notebook->GetNthTabLabel( 0 )->GetAllocation().size.y ); // Get size in the dimension all children have uniform size. - sf::Vector2f child_size( notebook->GetNthPage( 0 )->GetAllocation().width, notebook->GetNthPage( 0 )->GetAllocation().height ); + sf::Vector2f child_size( notebook->GetNthPage( 0 )->GetAllocation().size.x, notebook->GetNthPage( 0 )->GetAllocation().size.y ); if( notebook->GetTabPosition() == Notebook::TabPosition::TOP ) { // Tabs are positioned at top. @@ -72,8 +72,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + padding - border_width, label_allocation.top - border_width - padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + padding - border_width, label_allocation.position.y - border_width - padding ), border_color_light, border_width ) @@ -82,8 +82,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left + label_allocation.width - border_width + padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width - border_width + padding, label_allocation.top + label_allocation.height + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x - border_width + padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x - border_width + padding, label_allocation.position.y + label_allocation.size.y + padding ), border_color_dark, border_width ) @@ -93,8 +93,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top + label_allocation.height + border_width + padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y + label_allocation.size.y + border_width + padding ), border_color_light, border_width ) @@ -104,10 +104,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * padding - border_width, - label_allocation.height + 2.f * ( border_width + padding ) + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding - border_width, label_allocation.size.y + 2.f * ( border_width + padding ) } ), background_color ) @@ -118,10 +116,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * padding - border_width, - label_allocation.height + 2.f * padding + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding - border_width, label_allocation.size.y + 2.f * padding } ), ( index == prelight_tab ) ? background_color_prelight : background_color_dark ) @@ -134,7 +130,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() + notebook->GetDisplayedTabCount() ) < notebook->GetPageCount() ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size, 0.f ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size, 0.f ), sf::Vector2f( scroll_button_size, tab_size.y + 2.f * ( padding + border_width ) ), border_width, notebook->IsForwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -145,9 +141,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .66f, .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .66f, .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .33f, .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .66f, .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .66f, .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .33f, .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), arrow_color ) ); @@ -210,8 +206,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - padding, label_allocation.top + label_allocation.height + border_width + padding ), - sf::Vector2f( label_allocation.left + label_allocation.width - border_width + padding, label_allocation.top + label_allocation.height + border_width + padding ), + sf::Vector2f( label_allocation.position.x - padding, label_allocation.position.y + label_allocation.size.y + border_width + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x - border_width + padding, label_allocation.position.y + label_allocation.size.y + border_width + padding ), border_color_dark, border_width ) @@ -220,8 +216,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left + label_allocation.width + padding - border_width, label_allocation.top - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + padding - border_width, label_allocation.top + label_allocation.height + border_width + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + padding - border_width, label_allocation.position.y - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + padding - border_width, label_allocation.position.y + label_allocation.size.y + border_width + padding ), border_color_dark, border_width ) @@ -231,8 +227,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top - padding ), - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top + label_allocation.height + border_width + padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y - padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y + label_allocation.size.y + border_width + padding ), border_color_light, border_width ) @@ -242,10 +238,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding - border_width, - label_allocation.width + 2.f * padding - border_width, - label_allocation.height + 2.f * padding + 2.f * border_width + { label_allocation.position.x - padding, label_allocation.position.y - padding - border_width }, + { label_allocation.size.x + 2.f * padding - border_width, label_allocation.size.y + 2.f * padding + 2.f * border_width } ), background_color ) @@ -256,10 +250,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * padding - border_width, - label_allocation.height + 2.f * padding + border_width + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding - border_width, label_allocation.size.y + 2.f * padding + border_width } ), ( index == prelight_tab ) ? background_color_prelight : background_color_dark ) @@ -272,7 +264,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() + notebook->GetDisplayedTabCount() ) < notebook->GetPageCount() ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size, notebook->GetAllocation().height - ( scroll_button_size + padding ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) ), sf::Vector2f( scroll_button_size, tab_size.y + 2.f * ( padding + border_width ) ), border_width, notebook->IsForwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -283,9 +275,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .66f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .66f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( notebook->GetAllocation().width - scroll_button_size * .33f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .66f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .66f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( notebook->GetAllocation().size.x - scroll_button_size * .33f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), arrow_color ) ); @@ -295,7 +287,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() != 0 ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( 0.f, notebook->GetAllocation().height - ( scroll_button_size + padding ) ), + sf::Vector2f( 0.f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) ), sf::Vector2f( scroll_button_size, tab_size.y + 2.f * ( padding + border_width ) ), border_width, notebook->IsBackwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -306,9 +298,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( scroll_button_size * .66f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( scroll_button_size * .66f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), - sf::Vector2f( scroll_button_size * .33f, notebook->GetAllocation().height - ( scroll_button_size + padding ) + .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( scroll_button_size * .66f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .66f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( scroll_button_size * .66f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .33f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), + sf::Vector2f( scroll_button_size * .33f, notebook->GetAllocation().size.y - ( scroll_button_size + padding ) + .5f * ( tab_size.y + 2.f * ( padding + border_width ) ) ), arrow_color ) ); @@ -348,8 +340,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top + label_allocation.height + padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y + label_allocation.size.y + padding ), border_color_light, border_width ) @@ -358,8 +350,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top + label_allocation.height + padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + ( index == current_page ? border_width : 0.f ) + padding, label_allocation.top + label_allocation.height + padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y + label_allocation.size.y + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + ( index == current_page ? border_width : 0.f ) + padding, label_allocation.position.y + label_allocation.size.y + padding ), border_color_dark, border_width ) @@ -369,8 +361,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - border_width - padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + border_width + padding, label_allocation.top - border_width - padding ), + sf::Vector2f( label_allocation.position.x - border_width - padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + border_width + padding, label_allocation.position.y - border_width - padding ), border_color_light, border_width ) @@ -380,10 +372,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * ( border_width + padding ), - label_allocation.height + 2.f * padding + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * ( border_width + padding ), label_allocation.size.y + 2.f * padding } ), background_color ) @@ -394,10 +384,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * padding, - label_allocation.height + 2.f * padding - border_width + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding, label_allocation.size.y + 2.f * padding - border_width } ), ( index == prelight_tab ) ? background_color_prelight : background_color_dark ) @@ -410,7 +398,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() + notebook->GetDisplayedTabCount() ) < notebook->GetPageCount() ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( 0.f, notebook->GetAllocation().height - ( scroll_button_size ) ), + sf::Vector2f( 0.f, notebook->GetAllocation().size.y - ( scroll_button_size ) ), sf::Vector2f( tab_size.x + 2.f * ( padding + border_width ), scroll_button_size ), border_width, notebook->IsForwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -421,9 +409,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .33f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), - sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .33f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), - sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .66f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), + sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .33f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), + sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .33f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), + sf::Vector2f( ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .66f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), arrow_color ) ); @@ -486,8 +474,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left + label_allocation.width + border_width + padding, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + border_width + padding, label_allocation.top + label_allocation.height + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + border_width + padding, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + border_width + padding, label_allocation.position.y + label_allocation.size.y + padding ), border_color_dark, border_width ) @@ -496,8 +484,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - padding, label_allocation.top + label_allocation.height + padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + border_width + padding, label_allocation.top + label_allocation.height + padding ), + sf::Vector2f( label_allocation.position.x - padding, label_allocation.position.y + label_allocation.size.y + padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + border_width + padding, label_allocation.position.y + label_allocation.size.y + padding ), border_color_dark, border_width ) @@ -507,8 +495,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( label_allocation.left - padding - border_width, label_allocation.top - border_width - padding ), - sf::Vector2f( label_allocation.left + label_allocation.width + padding, label_allocation.top - border_width - padding ), + sf::Vector2f( label_allocation.position.x - padding - border_width, label_allocation.position.y - border_width - padding ), + sf::Vector2f( label_allocation.position.x + label_allocation.size.x + padding, label_allocation.position.y - border_width - padding ), border_color_light, border_width ) @@ -518,10 +506,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding - border_width, - label_allocation.top - padding, - label_allocation.width + 2.f * padding + 2.f * border_width, - label_allocation.height + 2.f * padding + { label_allocation.position.x - padding - border_width, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding + 2.f * border_width, label_allocation.size.y + 2.f * padding } ), background_color ) @@ -532,10 +518,8 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - label_allocation.left - padding, - label_allocation.top - padding, - label_allocation.width + 2.f * padding + border_width, - label_allocation.height + 2.f * padding + { label_allocation.position.x - padding, label_allocation.position.y - padding }, + { label_allocation.size.x + 2.f * padding + border_width, label_allocation.size.y + 2.f * padding } ), (index == prelight_tab) ? background_color_prelight : background_color_dark ) @@ -548,7 +532,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() + notebook->GetDisplayedTabCount() ) < notebook->GetPageCount() ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * padding + border_width ), notebook->GetAllocation().height - ( scroll_button_size ) ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * padding + border_width ), notebook->GetAllocation().size.y - ( scroll_button_size ) ), sf::Vector2f( tab_size.x + 2.f * ( padding + border_width ), scroll_button_size ), border_width, notebook->IsForwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -559,9 +543,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .33f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .33f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .66f * scroll_button_size + notebook->GetAllocation().height - scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .33f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .33f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .66f * scroll_button_size + notebook->GetAllocation().size.y - scroll_button_size ), arrow_color ) ); @@ -571,7 +555,7 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrGetFirstDisplayedTab() != 0 ) { queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * padding + border_width ), 0.f ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * padding + border_width ), 0.f ), sf::Vector2f( tab_size.x + 2.f * ( padding + border_width ), scroll_button_size ), border_width, notebook->IsBackwardScrollPrelight() ? scroll_button_prelight : background_color, @@ -582,9 +566,9 @@ std::unique_ptr BREW::CreateNotebookDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .66f * scroll_button_size ), - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .66f * scroll_button_size ), - sf::Vector2f( notebook->GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .33f * scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .6f, .66f * scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .4f, .66f * scroll_button_size ), + sf::Vector2f( notebook->GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) * .5f, .33f * scroll_button_size ), arrow_color ) ); diff --git a/src/SFGUI/Engines/BREW/ProgressBar.cpp b/src/SFGUI/Engines/BREW/ProgressBar.cpp index e9e75eb7..72a218ef 100644 --- a/src/SFGUI/Engines/BREW/ProgressBar.cpp +++ b/src/SFGUI/Engines/BREW/ProgressBar.cpp @@ -24,7 +24,7 @@ std::unique_ptr BREW::CreateProgressBarDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( progress_bar->GetAllocation().width, progress_bar->GetAllocation().height ), + sf::Vector2f( progress_bar->GetAllocation().size.x, progress_bar->GetAllocation().size.y ), border_width, background_color, border_color, @@ -36,31 +36,27 @@ std::unique_ptr BREW::CreateProgressBarDrawable( std::shared_ptrGetOrientation() == ProgressBar::Orientation::HORIZONTAL ) { - float frac_width( std::max( 2.f * bar_border_width, progress_bar->GetAllocation().width * progress_bar->GetFraction() ) ); + float frac_width( std::max( 2.f * bar_border_width, progress_bar->GetAllocation().size.x * progress_bar->GetFraction() ) ); bar_rect = sf::FloatRect( - border_width, - border_width, - std::max( 0.f, frac_width - 2.f * border_width ), - std::max( 0.f, progress_bar->GetAllocation().height - 2.f * border_width ) + { border_width, border_width }, + { std::max( 0.f, frac_width - 2.f * border_width ), std::max( 0.f, progress_bar->GetAllocation().size.y - 2.f * border_width ) } ); } else { - float frac_height( std::max( 2.f * bar_border_width, progress_bar->GetAllocation().height * progress_bar->GetFraction() ) ); + float frac_height( std::max( 2.f * bar_border_width, progress_bar->GetAllocation().size.y * progress_bar->GetFraction() ) ); bar_rect = sf::FloatRect( - border_width, - std::max( 0.f, progress_bar->GetAllocation().height - frac_height + border_width ), - std::max( 0.f, progress_bar->GetAllocation().width - 2.f * border_width ), - std::max( 0.f, frac_height - 2.f * border_width ) + { border_width, std::max( 0.f, progress_bar->GetAllocation().size.y - frac_height + border_width ) }, + { std::max( 0.f, progress_bar->GetAllocation().size.x - 2.f * border_width ), std::max( 0.f, frac_height - 2.f * border_width ) } ); } // Bar Pane. queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( bar_rect.left, bar_rect.top ), - sf::Vector2f( bar_rect.width, bar_rect.height ), + sf::Vector2f( bar_rect.position.x, bar_rect.position.y ), + sf::Vector2f( bar_rect.size.x, bar_rect.size.y ), bar_border_width, progress_color, bar_border_color, diff --git a/src/SFGUI/Engines/BREW/Scale.cpp b/src/SFGUI/Engines/BREW/Scale.cpp index 1b1d2477..6d1c0090 100644 --- a/src/SFGUI/Engines/BREW/Scale.cpp +++ b/src/SFGUI/Engines/BREW/Scale.cpp @@ -25,10 +25,8 @@ std::unique_ptr BREW::CreateScaleDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - slider_rect.width / 2.f, - ( scale->GetAllocation().height - trough_thickness ) / 2.f, - scale->GetAllocation().width - slider_rect.width, - trough_thickness + { slider_rect.size.x / 2.f, ( scale->GetAllocation().size.y - trough_thickness ) / 2.f }, + { scale->GetAllocation().size.x - slider_rect.size.x, trough_thickness } ), trough_color ) @@ -39,10 +37,8 @@ std::unique_ptr BREW::CreateScaleDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - ( scale->GetAllocation().width - trough_thickness ) / 2.f, - slider_rect.height / 2.f, - trough_thickness, - scale->GetAllocation().height - slider_rect.height + { ( scale->GetAllocation().size.x - trough_thickness ) / 2.f, slider_rect.size.y / 2.f }, + { trough_thickness, scale->GetAllocation().size.y - slider_rect.size.y } ), trough_color ) diff --git a/src/SFGUI/Engines/BREW/Scrollbar.cpp b/src/SFGUI/Engines/BREW/Scrollbar.cpp index 81920706..cc6b1bd1 100644 --- a/src/SFGUI/Engines/BREW/Scrollbar.cpp +++ b/src/SFGUI/Engines/BREW/Scrollbar.cpp @@ -21,16 +21,14 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrGetOrientation(); if( orientation == Scrollbar::Orientation::HORIZONTAL ) { - auto stepper_length = scrollbar->GetAllocation().height; + auto stepper_length = scrollbar->GetAllocation().size.y; // Trough queue->Add( Renderer::Get().CreateRect( sf::FloatRect( - stepper_length, - 0.f, - scrollbar->GetAllocation().width - 2.f * stepper_length, - scrollbar->GetAllocation().height + { stepper_length, 0.f }, + { scrollbar->GetAllocation().size.x - 2.f * stepper_length, scrollbar->GetAllocation().size.y } ), trough_color ) @@ -40,10 +38,8 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( CreateStepper( sf::FloatRect( - 0.f, - 0.f, - stepper_length, - scrollbar->GetAllocation().height + { 0.f, 0.f }, + { stepper_length, scrollbar->GetAllocation().size.y } ), stepper_color, border_width, @@ -55,9 +51,9 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( stepper_length * .66f, scrollbar->GetAllocation().height * .33f ), - sf::Vector2f( stepper_length * .33f, scrollbar->GetAllocation().height * .5f ), - sf::Vector2f( stepper_length * .66f, scrollbar->GetAllocation().height * .66f ), + sf::Vector2f( stepper_length * .66f, scrollbar->GetAllocation().size.y * .33f ), + sf::Vector2f( stepper_length * .33f, scrollbar->GetAllocation().size.y * .5f ), + sf::Vector2f( stepper_length * .66f, scrollbar->GetAllocation().size.y * .66f ), stepper_arrow_color ) ); @@ -66,10 +62,8 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( CreateStepper( sf::FloatRect( - scrollbar->GetAllocation().width - stepper_length, - 0.f, - stepper_length, - scrollbar->GetAllocation().height + { scrollbar->GetAllocation().size.x - stepper_length, 0.f }, + { stepper_length, scrollbar->GetAllocation().size.y } ), stepper_color, border_width, @@ -81,24 +75,22 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( scrollbar->GetAllocation().width - stepper_length * .66f, scrollbar->GetAllocation().height * .66f ), - sf::Vector2f( scrollbar->GetAllocation().width - stepper_length * .33f, scrollbar->GetAllocation().height * .5f ), - sf::Vector2f( scrollbar->GetAllocation().width - stepper_length * .66f, scrollbar->GetAllocation().height * .33f ), + sf::Vector2f( scrollbar->GetAllocation().size.x - stepper_length * .66f, scrollbar->GetAllocation().size.y * .66f ), + sf::Vector2f( scrollbar->GetAllocation().size.x - stepper_length * .33f, scrollbar->GetAllocation().size.y * .5f ), + sf::Vector2f( scrollbar->GetAllocation().size.x - stepper_length * .66f, scrollbar->GetAllocation().size.y * .33f ), stepper_arrow_color ) ); } else { - auto stepper_length = scrollbar->GetAllocation().width; + auto stepper_length = scrollbar->GetAllocation().size.x; // Trough queue->Add( Renderer::Get().CreateRect( sf::FloatRect( - 0.f, - stepper_length, - scrollbar->GetAllocation().width, - scrollbar->GetAllocation().height - 2.f * stepper_length + { 0.f, stepper_length }, + { scrollbar->GetAllocation().size.x, scrollbar->GetAllocation().size.y - 2.f * stepper_length } ), trough_color ) @@ -108,10 +100,8 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( CreateStepper( sf::FloatRect( - 0.f, - 0.f, - scrollbar->GetAllocation().width, - stepper_length + { 0.f, 0.f }, + { scrollbar->GetAllocation().size.x, stepper_length } ), stepper_color, border_width, @@ -123,9 +113,9 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( scrollbar->GetAllocation().width * .33f, stepper_length * .66f ), - sf::Vector2f( scrollbar->GetAllocation().width * .66f, stepper_length * .66f ), - sf::Vector2f( scrollbar->GetAllocation().width * .5f, stepper_length * .33f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .33f, stepper_length * .66f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .66f, stepper_length * .66f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .5f, stepper_length * .33f ), stepper_arrow_color ) ); @@ -134,10 +124,8 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( CreateStepper( sf::FloatRect( - 0.f, - scrollbar->GetAllocation().height - stepper_length, - scrollbar->GetAllocation().width, - stepper_length + { 0.f, scrollbar->GetAllocation().size.y - stepper_length }, + { scrollbar->GetAllocation().size.x, stepper_length } ), stepper_color, border_width, @@ -149,9 +137,9 @@ std::unique_ptr BREW::CreateScrollbarDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( scrollbar->GetAllocation().width * .33f, scrollbar->GetAllocation().height - stepper_length * .66f ), - sf::Vector2f( scrollbar->GetAllocation().width * .5f, scrollbar->GetAllocation().height - stepper_length * .33f ), - sf::Vector2f( scrollbar->GetAllocation().width * .66f, scrollbar->GetAllocation().height - stepper_length * .66f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .33f, scrollbar->GetAllocation().size.y - stepper_length * .66f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .5f, scrollbar->GetAllocation().size.y - stepper_length * .33f ), + sf::Vector2f( scrollbar->GetAllocation().size.x * .66f, scrollbar->GetAllocation().size.y - stepper_length * .66f ), stepper_arrow_color ) ); diff --git a/src/SFGUI/Engines/BREW/ScrolledWindow.cpp b/src/SFGUI/Engines/BREW/ScrolledWindow.cpp index 910aafff..ee6e1eee 100644 --- a/src/SFGUI/Engines/BREW/ScrolledWindow.cpp +++ b/src/SFGUI/Engines/BREW/ScrolledWindow.cpp @@ -19,18 +19,16 @@ std::unique_ptr BREW::CreateScrolledWindowDrawable( std::shared_ptr auto rect = scrolled_window->GetContentAllocation(); - rect.left -= ( border_width + scrolled_window->GetAllocation().left ); - rect.top -= ( border_width + scrolled_window->GetAllocation().top ); - rect.width += 2.f * border_width; - rect.height += 2.f * border_width; + rect.position.x -= ( border_width + scrolled_window->GetAllocation().position.x ); + rect.position.y -= ( border_width + scrolled_window->GetAllocation().position.y ); + rect.size.x += 2.f * border_width; + rect.size.y += 2.f * border_width; queue->Add( CreateBorder( sf::FloatRect( - 0.f, - 0.f, - rect.width, - rect.height + { 0.f, 0.f }, + rect.size ), border_width, border_color_dark, diff --git a/src/SFGUI/Engines/BREW/Separator.cpp b/src/SFGUI/Engines/BREW/Separator.cpp index 36f393eb..584be007 100644 --- a/src/SFGUI/Engines/BREW/Separator.cpp +++ b/src/SFGUI/Engines/BREW/Separator.cpp @@ -14,8 +14,8 @@ std::unique_ptr BREW::CreateSeparatorDrawable( std::shared_ptrGetOrientation() == Separator::Orientation::HORIZONTAL ) { queue->Add( Renderer::Get().CreateLine( - sf::Vector2f( 0.f, separator->GetAllocation().height / 2.f ), - sf::Vector2f( separator->GetAllocation().width, separator->GetAllocation().height / 2.f ), + sf::Vector2f( 0.f, separator->GetAllocation().size.y / 2.f ), + sf::Vector2f( separator->GetAllocation().size.x, separator->GetAllocation().size.y / 2.f ), color, 1.f ) @@ -24,8 +24,8 @@ std::unique_ptr BREW::CreateSeparatorDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( - sf::Vector2f( separator->GetAllocation().width / 2.f, 0.f ), - sf::Vector2f( separator->GetAllocation().width / 2.f, separator->GetAllocation().height ), + sf::Vector2f( separator->GetAllocation().size.x / 2.f, 0.f ), + sf::Vector2f( separator->GetAllocation().size.x / 2.f, separator->GetAllocation().size.y ), color, 1.f ) diff --git a/src/SFGUI/Engines/BREW/SpinButton.cpp b/src/SFGUI/Engines/BREW/SpinButton.cpp index 82183635..fc184341 100644 --- a/src/SFGUI/Engines/BREW/SpinButton.cpp +++ b/src/SFGUI/Engines/BREW/SpinButton.cpp @@ -31,7 +31,7 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( spinbutton->GetAllocation().width, spinbutton->GetAllocation().height ), + sf::Vector2f( spinbutton->GetAllocation().size.x, spinbutton->GetAllocation().size.y ), border_width, background_color, border_color, @@ -39,13 +39,13 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrGetAllocation().height / 2.f ) * stepper_aspect_ratio; + auto button_width = ( spinbutton->GetAllocation().size.y / 2.f ) * stepper_aspect_ratio; // Up Stepper. queue->Add( Renderer::Get().CreatePane( - sf::Vector2f( spinbutton->GetAllocation().width - button_width - border_width, border_width ), - sf::Vector2f( button_width, spinbutton->GetAllocation().height / 2.f - border_width ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width - border_width, border_width ), + sf::Vector2f( button_width, spinbutton->GetAllocation().size.y / 2.f - border_width ), border_width, stepper_color, stepper_border_color, @@ -56,9 +56,9 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 2.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 6.f ), - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f * 3.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 3.f ), - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().height / 3.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 2.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().size.y / 6.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 4.f * 3.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().size.y / 3.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 4.f - border_width, ( spinbutton->IsIncreaseStepperPressed() ? 1.f : 0.f ) + border_width + spinbutton->GetAllocation().size.y / 3.f ), stepper_arrow_color ) ); @@ -66,8 +66,8 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( - sf::Vector2f( spinbutton->GetAllocation().width - button_width - border_width, spinbutton->GetAllocation().height / 2.f ), - sf::Vector2f( button_width, spinbutton->GetAllocation().height / 2.f - border_width ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width - border_width, spinbutton->GetAllocation().size.y / 2.f ), + sf::Vector2f( button_width, spinbutton->GetAllocation().size.y / 2.f - border_width ), border_width, stepper_color, stepper_border_color, @@ -78,17 +78,17 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreateTriangle( - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 2.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 6.f ), - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 3.f ), - sf::Vector2f( spinbutton->GetAllocation().width - button_width / 4.f * 3.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().height - border_width - spinbutton->GetAllocation().height / 3.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 2.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().size.y - border_width - spinbutton->GetAllocation().size.y / 6.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 4.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().size.y - border_width - spinbutton->GetAllocation().size.y / 3.f ), + sf::Vector2f( spinbutton->GetAllocation().size.x - button_width / 4.f * 3.f - border_width, ( spinbutton->IsDecreaseStepperPressed() ? 1.f : 0.f ) + spinbutton->GetAllocation().size.y - border_width - spinbutton->GetAllocation().size.y / 3.f ), stepper_arrow_color ) ); auto line_height = GetFontLineHeight( *font, font_size ); - sf::Text vis_label( spinbutton->GetVisibleText(), *font, font_size ); + sf::Text vis_label( *font, spinbutton->GetVisibleText(), font_size ); vis_label.setFillColor( text_color ); - vis_label.setPosition( text_padding, spinbutton->GetAllocation().height / 2.f - line_height / 2.f ); + vis_label.setPosition( { text_padding, spinbutton->GetAllocation().size.y / 2.f - line_height / 2.f } ); queue->Add( Renderer::Get().CreateText( vis_label ) ); @@ -105,10 +105,8 @@ std::unique_ptr BREW::CreateSpinButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - metrics.x + text_padding, - spinbutton->GetAllocation().height / 2.f - line_height / 2.f, - cursor_thickness, - line_height + { metrics.x + text_padding, spinbutton->GetAllocation().size.y / 2.f - line_height / 2.f }, + { cursor_thickness, line_height } ), cursor_color ) diff --git a/src/SFGUI/Engines/BREW/Spinner.cpp b/src/SFGUI/Engines/BREW/Spinner.cpp index 2a3de363..2bc01d0f 100644 --- a/src/SFGUI/Engines/BREW/Spinner.cpp +++ b/src/SFGUI/Engines/BREW/Spinner.cpp @@ -17,7 +17,7 @@ std::unique_ptr BREW::CreateSpinnerDrawable( std::shared_ptr( "InnerRadius", spinner ); auto rod_thickness = GetProperty( "RodThickness", spinner ); auto stopped_alpha = GetProperty( "StoppedAlpha", spinner ); - auto radius = std::min( spinner->GetAllocation().width, spinner->GetAllocation().height ) / 2.f; + auto radius = std::min( spinner->GetAllocation().size.x, spinner->GetAllocation().size.y ) / 2.f; std::unique_ptr queue( new RenderQueue ); @@ -27,16 +27,16 @@ std::unique_ptr BREW::CreateSpinnerDrawable( std::shared_ptrGetAllocation().width / 2.f, spinner->GetAllocation().height / 2.f ); + sf::Vector2f center_offset( spinner->GetAllocation().size.x / 2.f, spinner->GetAllocation().size.y / 2.f ); // We just have to produce the spinner in stopped state. // The class itself will take care of the started state. auto blend = ( 255.f - static_cast( stopped_alpha ) ) / 255.f; sf::Color stop_color( - static_cast( static_cast( color.r ) * ( 1.f - blend ) + static_cast( background_color.r ) * blend ), - static_cast( static_cast( color.g ) * ( 1.f - blend ) + static_cast( background_color.g ) * blend ), - static_cast( static_cast( color.b ) * ( 1.f - blend ) + static_cast( background_color.b ) * blend ) + static_cast( static_cast( color.r ) * ( 1.f - blend ) + static_cast( background_color.r ) * blend ), + static_cast( static_cast( color.g ) * ( 1.f - blend ) + static_cast( background_color.g ) * blend ), + static_cast( static_cast( color.b ) * ( 1.f - blend ) + static_cast( background_color.b ) * blend ) ); auto started = spinner->Started(); @@ -59,9 +59,9 @@ std::unique_ptr BREW::CreateSpinnerDrawable( std::shared_ptr( rod_stage ) / ( static_cast( steps ) - 1.f ); sf::Color rod_color( - static_cast( static_cast( color.r ) * ( 1.f - rod_alpha ) + static_cast( background_color.r ) * rod_alpha ), - static_cast( static_cast( color.g ) * ( 1.f - rod_alpha ) + static_cast( background_color.g ) * rod_alpha ), - static_cast( static_cast( color.b ) * ( 1.f - rod_alpha ) + static_cast( background_color.b ) * rod_alpha ) + static_cast( static_cast( color.r ) * ( 1.f - rod_alpha ) + static_cast( background_color.r ) * rod_alpha ), + static_cast( static_cast( color.g ) * ( 1.f - rod_alpha ) + static_cast( background_color.g ) * rod_alpha ), + static_cast( static_cast( color.b ) * ( 1.f - rod_alpha ) + static_cast( background_color.b ) * rod_alpha ) ); queue->Add( diff --git a/src/SFGUI/Engines/BREW/ToggleButton.cpp b/src/SFGUI/Engines/BREW/ToggleButton.cpp index ef0ba095..0194fcf4 100644 --- a/src/SFGUI/Engines/BREW/ToggleButton.cpp +++ b/src/SFGUI/Engines/BREW/ToggleButton.cpp @@ -28,7 +28,7 @@ std::unique_ptr BREW::CreateToggleButtonDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( button->GetAllocation().width, button->GetAllocation().height ), + sf::Vector2f( button->GetAllocation().size.x, button->GetAllocation().size.y ), border_width, background_color, border_color, @@ -41,12 +41,12 @@ std::unique_ptr BREW::CreateToggleButtonDrawable( std::shared_ptrGetLabel(), *font, font_size ); metrics.y = GetFontLineHeight( *font, font_size ); - sf::Text text( button->GetLabel(), *font, font_size ); + sf::Text text( *font, button->GetLabel(), font_size ); auto offset = ( ( button->GetState() == Button::State::ACTIVE ) || button->IsActive() ) ? border_width : 0.f; text.setPosition( - button->GetAllocation().width / 2.f - metrics.x / 2.f + offset, - button->GetAllocation().height / 2.f - metrics.y / 2.f + offset + { button->GetAllocation().size.x / 2.f - metrics.x / 2.f + offset, + button->GetAllocation().size.y / 2.f - metrics.y / 2.f + offset } ); text.setFillColor( color ); diff --git a/src/SFGUI/Engines/BREW/Window.cpp b/src/SFGUI/Engines/BREW/Window.cpp index c8e7084d..dce39f35 100644 --- a/src/SFGUI/Engines/BREW/Window.cpp +++ b/src/SFGUI/Engines/BREW/Window.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -20,7 +21,7 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptr( "TitlePadding", window ); auto shadow_distance = GetProperty( "ShadowDistance", window ); auto handle_size = GetProperty( "HandleSize", window ); - auto shadow_alpha = GetProperty( "ShadowAlpha", window ); + auto shadow_alpha = GetProperty( "ShadowAlpha", window ); auto title_font_size = GetProperty( "FontSize", window ); auto close_height = GetProperty( "CloseHeight", window ); auto close_thickness = GetProperty( "CloseThickness", window ); @@ -36,10 +37,8 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrGetAllocation().width, - window->GetAllocation().height + { shadow_distance, shadow_distance }, + window->GetAllocation().size ); queue->Add( @@ -55,7 +54,7 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrAdd( Renderer::Get().CreatePane( sf::Vector2f( 0.f, 0.f ), - sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ), + sf::Vector2f( window->GetAllocation().size.x, window->GetAllocation().size.y ), border_width, background_color, border_color, @@ -67,9 +66,9 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrHasStyle( Window::RESIZE ) ) { queue->Add( Renderer::Get().CreateTriangle( - sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height - handle_size ), - sf::Vector2f( window->GetAllocation().width - handle_size, window->GetAllocation().height ), - sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ), + sf::Vector2f( window->GetAllocation().size.x, window->GetAllocation().size.y - handle_size ), + sf::Vector2f( window->GetAllocation().size.x - handle_size, window->GetAllocation().size.y ), + sf::Vector2f( window->GetAllocation().size.x, window->GetAllocation().size.y ), title_background_color ) ); @@ -84,10 +83,8 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrAdd( Renderer::Get().CreateRect( sf::FloatRect( - border_width + .1f, - border_width + .1f, - window->GetAllocation().width - 2 * border_width, - title_size + { border_width + .1f, border_width + .1f }, + { window->GetAllocation().size.x - 2 * border_width, title_size } ), title_background_color ) @@ -100,11 +97,11 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( sf::Vector2f( - std::floor( window->GetAllocation().width - border_width - button_margin - close_height + corner_extent + .5f ), + std::floor( window->GetAllocation().size.x - border_width - button_margin - close_height + corner_extent + .5f ), std::floor( border_width + button_margin + corner_extent + .5f ) ), sf::Vector2f( - std::floor( window->GetAllocation().width - border_width - button_margin - corner_extent + .5f ), + std::floor( window->GetAllocation().size.x - border_width - button_margin - corner_extent + .5f ), std::floor( border_width + title_size - button_margin - corner_extent + .5f ) ), title_text_color, @@ -115,11 +112,11 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrAdd( Renderer::Get().CreateLine( sf::Vector2f( - std::floor( window->GetAllocation().width - border_width - button_margin - close_height + corner_extent + .5f ), + std::floor( window->GetAllocation().size.x - border_width - button_margin - close_height + corner_extent + .5f ), std::floor( border_width + title_size - button_margin - corner_extent + .5f ) ), sf::Vector2f( - std::floor( window->GetAllocation().width - border_width - button_margin - corner_extent + .5f ), + std::floor( window->GetAllocation().size.x - border_width - button_margin - corner_extent + .5f ), std::floor( border_width + button_margin + corner_extent + .5f ) ), title_text_color, @@ -129,16 +126,16 @@ std::unique_ptr BREW::CreateWindowDrawable( std::shared_ptrGetAllocation().width - 2.f * border_width - 2.f * title_padding - ( window->HasStyle( Window::CLOSE ) ? title_size : 0 ) ); + float avail_width( window->GetAllocation().size.x - 2.f * border_width - 2.f * title_padding - ( window->HasStyle( Window::CLOSE ) ? title_size : 0 ) ); - sf::Text title_text( window->GetTitle(), *title_font, title_font_size ); + sf::Text title_text( *title_font, window->GetTitle(), title_font_size ); - if( title_text.getLocalBounds().width > avail_width ) { - sf::Text dots( "...", *title_font, title_font_size ); + if( title_text.getLocalBounds().size.x > avail_width ) { + sf::Text dots( *title_font, "...", title_font_size ); const sf::String& title_string( window->GetTitle() ); sf::String visible_title; - avail_width = window->GetAllocation().width - 2.f * border_width - 2.f * title_padding - dots.getLocalBounds().width; + avail_width = window->GetAllocation().size.x - 2.f * border_width - 2.f * title_padding - dots.getLocalBounds().size.x; for( const auto& character : title_string ) { avail_width -= static_cast( title_font->getGlyph( character, title_font_size, false ).advance ); diff --git a/src/SFGUI/Entry.cpp b/src/SFGUI/Entry.cpp index a1153843..a6591175 100644 --- a/src/SFGUI/Entry.cpp +++ b/src/SFGUI/Entry.cpp @@ -63,7 +63,7 @@ void Entry::SetCursorPosition( int new_position ) { MoveCursor( delta ); } -void Entry::HideText( sf::Uint32 c ) { +void Entry::HideText( std::uint32_t c ) { if( c == 0x00 || ( c > 0x1f && c != 0x7f ) ) { // not a control character m_text_placeholder = c; @@ -71,7 +71,7 @@ void Entry::HideText( sf::Uint32 c ) { } } -sf::Uint32 Entry::GetHideCharacter() const { +std::uint32_t Entry::GetHideCharacter() const { return m_text_placeholder; } @@ -81,9 +81,9 @@ int Entry::GetPositionFromMouseX( int mouse_pos_x ) { const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); float text_padding( Context::Get().GetEngine().GetProperty( "Padding", shared_from_this() ) ); - std::basic_string string( m_visible_string.begin(), m_visible_string.end() ); + std::u32string string( m_visible_string.begin(), m_visible_string.end() ); - auto text_start = GetAllocation().left + text_padding; + auto text_start = GetAllocation().position.x + text_padding; auto last_delta = std::fabs( text_start - static_cast( mouse_pos_x ) ); int cursor_position = 0; auto length = static_cast( string.size() ); @@ -115,7 +115,7 @@ void Entry::RecalculateVisibleString() const { return; } - std::basic_string string( m_string.begin(), m_string.end() ); + std::u32string string( m_string.begin(), m_string.end() ); string.erase( 0, static_cast( m_visible_offset ) ); if( m_text_placeholder != 0 ) { @@ -127,7 +127,7 @@ void Entry::RecalculateVisibleString() const { // While the string is too long for the given space keep chopping off characters // on the right end of the string until the cursor is reached, then start // chopping off characters on the left side of the string. - while( !string.empty() && (GetAllocation().width - m_text_margin > 0) && (length > GetAllocation().width - m_text_margin - (2.f * text_padding)) ) { + while( !string.empty() && (GetAllocation().size.x - m_text_margin > 0) && (length > GetAllocation().size.x - m_text_margin - (2.f * text_padding)) ) { if( ( m_cursor_position - m_visible_offset ) < static_cast( string.size() ) ) { string.erase( string.size() - 1, 1 ); } @@ -159,7 +159,7 @@ void Entry::MoveCursor( int delta ) { } } -void Entry::HandleTextEvent( sf::Uint32 character ) { +void Entry::HandleTextEvent( char32_t character ) { if( m_max_length > 0 && static_cast( m_string.getSize() ) >= m_max_length ) { return; } @@ -173,13 +173,13 @@ void Entry::HandleTextEvent( sf::Uint32 character ) { } } -void Entry::HandleKeyEvent( sf::Keyboard::Key key, bool press ) { +void Entry::HandleKeyEvent( sf::Keyboard::Key /*key*/, sf::Keyboard::Scancode scancode, bool press ) { if( !press || !HasFocus() ) { return; } - switch( key ) { - case sf::Keyboard::BackSpace: { // backspace + switch( scancode ) { + case sf::Keyboard::Scan::Backspace: { // backspace if( ( m_string.getSize() > 0 ) && ( m_cursor_position > 0 ) ) { m_string.erase( static_cast( m_cursor_position - 1 ) ); @@ -202,7 +202,7 @@ void Entry::HandleKeyEvent( sf::Keyboard::Key key, bool press ) { GetSignals().Emit( OnTextChanged ); } } break; - case sf::Keyboard::Delete: { + case sf::Keyboard::Scan::Delete: { if( ( m_string.getSize() > 0 ) && ( m_cursor_position < static_cast( m_string.getSize() ) ) ) { m_string.erase( static_cast( m_cursor_position ) ); @@ -224,22 +224,22 @@ void Entry::HandleKeyEvent( sf::Keyboard::Key key, bool press ) { GetSignals().Emit( OnTextChanged ); } } break; - case sf::Keyboard::Home: { + case sf::Keyboard::Scan::Home: { if( m_string.getSize() > 0 ) { m_visible_offset = 0; SetCursorPosition( 0 ); } } break; - case sf::Keyboard::End: { + case sf::Keyboard::Scan::End: { if( m_string.getSize() > 0 ) { m_visible_offset = 0; SetCursorPosition( static_cast( m_string.getSize() ) ); } } break; - case sf::Keyboard::Left: { + case sf::Keyboard::Scan::Left: { MoveCursor( -1 ); } break; - case sf::Keyboard::Right: { + case sf::Keyboard::Scan::Right: { MoveCursor( 1 ); } break; default: break; @@ -263,7 +263,7 @@ void Entry::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, return; } - if( button != sf::Mouse::Left ) { + if( button != sf::Mouse::Button::Left ) { // TODO: Maybe some more support for right clicking in the future. return; } diff --git a/src/SFGUI/FileResourceLoader.cpp b/src/SFGUI/FileResourceLoader.cpp index ae27decf..7214d13e 100644 --- a/src/SFGUI/FileResourceLoader.cpp +++ b/src/SFGUI/FileResourceLoader.cpp @@ -9,7 +9,7 @@ namespace sfg { std::shared_ptr FileResourceLoader::LoadFont( const std::string& path ) const { auto font = std::make_shared(); - if( !font->loadFromFile( path ) ) { + if( !font->openFromFile( path ) ) { return std::shared_ptr(); } diff --git a/src/SFGUI/Frame.cpp b/src/SFGUI/Frame.cpp index 5dbda45d..f53291e4 100644 --- a/src/SFGUI/Frame.cpp +++ b/src/SFGUI/Frame.cpp @@ -67,10 +67,10 @@ void Frame::HandleSizeChange() { sf::FloatRect allocation( GetAllocation() ); - allocation.left = padding + 2 * border_width; - allocation.top = line_height + padding + 2 * border_width; - allocation.width -= 2 * padding + 4 * border_width; - allocation.height -= line_height + 2 * padding + 4 * border_width; + allocation.position.x = padding + 2 * border_width; + allocation.position.y = line_height + padding + 2 * border_width; + allocation.size.x -= 2 * padding + 4 * border_width; + allocation.size.y -= line_height + 2 * padding + 4 * border_width; child->SetAllocation( allocation ); } diff --git a/src/SFGUI/GLCheck.cpp b/src/SFGUI/GLCheck.cpp index e6cc5957..b8209f9d 100644 --- a/src/SFGUI/GLCheck.cpp +++ b/src/SFGUI/GLCheck.cpp @@ -33,7 +33,7 @@ void DoCheckGLError( const char* file, unsigned int line, const char* call ) { std::cerr << "GL_OUT_OF_MEMORY"; break; default: - std::cerr << "0x" << std::setw(4) << std::setfill('0') << std::hex << error; + std::cerr << "0x" << std::setw( 4 ) << std::setfill( '0' ) << std::hex << error; break; } diff --git a/src/SFGUI/Label.cpp b/src/SFGUI/Label.cpp index 49dd3576..279db9df 100644 --- a/src/SFGUI/Label.cpp +++ b/src/SFGUI/Label.cpp @@ -72,17 +72,17 @@ void Label::WrapText() { unsigned int font_size( Context::Get().GetEngine().GetProperty( "FontSize", shared_from_this() ) ); const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); - std::basic_string wrapped_text; - std::basic_string text( m_text.begin(), m_text.end() ); + std::u32string wrapped_text; + std::u32string text( m_text.begin(), m_text.end() ); - std::basic_string line; + std::u32string line; while( !text.empty() ) { auto next_newline = text.find( L'\n' ); line = text.substr( 0, next_newline ); - if( next_newline != std::basic_string::npos ) { + if( next_newline != std::u32string::npos ) { text.erase( 0, next_newline + 1 ); } else { @@ -94,7 +94,7 @@ void Label::WrapText() { } // Check if line needs to be wrapped. - if( Context::Get().GetEngine().GetTextStringMetrics( line, font, font_size ).x <= GetAllocation().width ) { + if( Context::Get().GetEngine().GetTextStringMetrics( line, font, font_size ).x <= GetAllocation().size.x ) { wrapped_text += line; } else { @@ -102,17 +102,17 @@ void Label::WrapText() { while( !line.empty() ) { auto last_space = line.size(); - while( Context::Get().GetEngine().GetTextStringMetrics( line.substr( 0, last_space ), font, font_size ).x > GetAllocation().width ) { + while( Context::Get().GetEngine().GetTextStringMetrics( line.substr( 0, last_space ), font, font_size ).x > GetAllocation().size.x ) { last_space = line.find_last_of( L' ', last_space - 1 ); - if( last_space == std::basic_string::npos ) { + if( last_space == std::u32string::npos ) { wrapped_text += line; line.clear(); break; } } - if( last_space != std::basic_string::npos ) { + if( last_space != std::u32string::npos ) { wrapped_text += line.substr( 0, last_space ); line.erase( 0, last_space ); } @@ -149,7 +149,7 @@ void Label::HandleRequisitionChange() { } void Label::HandleSizeChange() { - if( !m_wrap || ( GetAllocation().width <= 0 ) ) { + if( !m_wrap || ( GetAllocation().size.x <= 0 ) ) { return; } @@ -179,14 +179,14 @@ sf::Vector2f Label::CalculateRequisition() { metrics.y = Context::Get().GetEngine().GetFontLineHeight( font, font_size ); sf::String wrapped_text( GetWrappedText() ); - std::basic_string text( wrapped_text.begin(), wrapped_text.end() ); + std::u32string text( wrapped_text.begin(), wrapped_text.end() ); std::size_t lines = 1; do { auto next_newline = text.find( L'\n' ); - if( next_newline != std::basic_string::npos ) { + if( next_newline != std::u32string::npos ) { text.erase( 0, next_newline + 1 ); } else { diff --git a/src/SFGUI/Notebook.cpp b/src/SFGUI/Notebook.cpp index 9c53cc59..221c0304 100644 --- a/src/SFGUI/Notebook.cpp +++ b/src/SFGUI/Notebook.cpp @@ -3,6 +3,8 @@ #include #include +#include + namespace sfg { // Signals. @@ -364,7 +366,7 @@ void Notebook::HandleMouseMoveEvent( int x, int y ) { return; } - sf::Vector2f tab_size( GetNthTabLabel( 0 )->GetAllocation().width, GetNthTabLabel( 0 )->GetAllocation().height ); + sf::Vector2f tab_size( GetNthTabLabel( 0 )->GetAllocation().size.x, GetNthTabLabel( 0 )->GetAllocation().size.y ); sf::FloatRect scroll_button_allocation( GetAllocation() ); @@ -372,32 +374,32 @@ void Notebook::HandleMouseMoveEvent( int x, int y ) { // Handle backward scrolling button. switch( GetTabPosition() ) { case TabPosition::TOP: - scroll_button_allocation.left += 0.f; - scroll_button_allocation.top += 0.f; - scroll_button_allocation.width = scroll_button_size; - scroll_button_allocation.height = tab_size.y + 2.f * ( padding + border_width ); + scroll_button_allocation.position.x += 0.f; + scroll_button_allocation.position.y += 0.f; + scroll_button_allocation.size.x = scroll_button_size; + scroll_button_allocation.size.y = tab_size.y + 2.f * ( padding + border_width ); break; case TabPosition::BOTTOM: - scroll_button_allocation.left += 0.f; - scroll_button_allocation.top += GetAllocation().height - ( scroll_button_size + padding ); - scroll_button_allocation.width = scroll_button_size; - scroll_button_allocation.height = tab_size.y + 2.f * ( padding + border_width ); + scroll_button_allocation.position.x += 0.f; + scroll_button_allocation.position.y += GetAllocation().size.y - ( scroll_button_size + padding ); + scroll_button_allocation.size.x = scroll_button_size; + scroll_button_allocation.size.y = tab_size.y + 2.f * ( padding + border_width ); break; case TabPosition::LEFT: - scroll_button_allocation.left += 0.f; - scroll_button_allocation.top += 0.f; - scroll_button_allocation.width = tab_size.x + 2.f * ( padding + border_width ); - scroll_button_allocation.height = scroll_button_size; + scroll_button_allocation.position.x += 0.f; + scroll_button_allocation.position.y += 0.f; + scroll_button_allocation.size.x = tab_size.x + 2.f * ( padding + border_width ); + scroll_button_allocation.size.y = scroll_button_size; break; case TabPosition::RIGHT: - scroll_button_allocation.left += ( GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) ); - scroll_button_allocation.top += 0.f; - scroll_button_allocation.width = tab_size.x + 2.f * ( padding + border_width ); - scroll_button_allocation.height = scroll_button_size; + scroll_button_allocation.position.x += ( GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) ); + scroll_button_allocation.position.y += 0.f; + scroll_button_allocation.size.x = tab_size.x + 2.f * ( padding + border_width ); + scroll_button_allocation.size.y = scroll_button_size; break; } - if( scroll_button_allocation.contains( static_cast( x ), static_cast( y ) ) ) { + if( scroll_button_allocation.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_backward_scroll_prelight = true; } } @@ -406,32 +408,32 @@ void Notebook::HandleMouseMoveEvent( int x, int y ) { // Handle forward scrolling button. switch( GetTabPosition() ) { case TabPosition::TOP: - scroll_button_allocation.left += ( GetAllocation().width - scroll_button_size ); - scroll_button_allocation.top += 0.f; - scroll_button_allocation.width = scroll_button_size; - scroll_button_allocation.height = tab_size.y + 2.f * ( padding + border_width ); + scroll_button_allocation.position.x += ( GetAllocation().size.x - scroll_button_size ); + scroll_button_allocation.position.y += 0.f; + scroll_button_allocation.size.x = scroll_button_size; + scroll_button_allocation.size.y = tab_size.y + 2.f * ( padding + border_width ); break; case TabPosition::BOTTOM: - scroll_button_allocation.left += ( GetAllocation().width - scroll_button_size ); - scroll_button_allocation.top += GetAllocation().height - ( scroll_button_size + padding ); - scroll_button_allocation.width = scroll_button_size; - scroll_button_allocation.height = tab_size.y + 2.f * ( padding + border_width ); + scroll_button_allocation.position.x += ( GetAllocation().size.x - scroll_button_size ); + scroll_button_allocation.position.y += GetAllocation().size.y - ( scroll_button_size + padding ); + scroll_button_allocation.size.x = scroll_button_size; + scroll_button_allocation.size.y = tab_size.y + 2.f * ( padding + border_width ); break; case TabPosition::LEFT: - scroll_button_allocation.left += 0.f; - scroll_button_allocation.top += GetAllocation().height - scroll_button_size; - scroll_button_allocation.width = tab_size.x + 2.f * ( padding + border_width ); - scroll_button_allocation.height = scroll_button_size; + scroll_button_allocation.position.x += 0.f; + scroll_button_allocation.position.y += GetAllocation().size.y - scroll_button_size; + scroll_button_allocation.size.x = tab_size.x + 2.f * ( padding + border_width ); + scroll_button_allocation.size.y = scroll_button_size; break; case TabPosition::RIGHT: - scroll_button_allocation.left += ( GetAllocation().width - ( tab_size.x + 2.f * ( padding + border_width ) ) ); - scroll_button_allocation.top += GetAllocation().height - scroll_button_size; - scroll_button_allocation.width = tab_size.x + 2.f * ( padding + border_width ); - scroll_button_allocation.height = scroll_button_size; + scroll_button_allocation.position.x += ( GetAllocation().size.x - ( tab_size.x + 2.f * ( padding + border_width ) ) ); + scroll_button_allocation.position.y += GetAllocation().size.y - scroll_button_size; + scroll_button_allocation.size.x = tab_size.x + 2.f * ( padding + border_width ); + scroll_button_allocation.size.y = scroll_button_size; break; } - if( scroll_button_allocation.contains( static_cast( x ), static_cast( y ) ) ) { + if( scroll_button_allocation.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_forward_scroll_prelight = true; } } @@ -439,12 +441,12 @@ void Notebook::HandleMouseMoveEvent( int x, int y ) { for( auto index = GetFirstDisplayedTab(); index < GetFirstDisplayedTab() + GetDisplayedTabCount(); ++index ) { auto allocation = m_children[static_cast( index )].tab_label->GetAllocation(); - allocation.left -= padding; - allocation.top -= padding; - allocation.width += 2.f * padding; - allocation.height += 2.f * padding; + allocation.position.x -= padding; + allocation.position.y -= padding; + allocation.size.x += 2.f * padding; + allocation.size.y += 2.f * padding; - if( allocation.contains( sf::Vector2f( static_cast( x ) - GetAllocation().left, static_cast( y ) - GetAllocation().top ) ) ) { + if( allocation.contains( sf::Vector2f( static_cast( x ) - GetAllocation().position.x, static_cast( y ) - GetAllocation().position.y ) ) ) { m_prelight_tab = static_cast( index ); break; } @@ -456,7 +458,7 @@ void Notebook::HandleMouseMoveEvent( int x, int y ) { } void Notebook::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int /*x*/, int /*y*/ ) { - if( ( button != sf::Mouse::Left ) ) { + if( ( button != sf::Mouse::Button::Left ) ) { return; } @@ -581,7 +583,7 @@ void Notebook::RecalculateSize() { auto tab_current_x = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f; for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) { - if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().width ) { + if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().size.x ) { m_num_displayed_tabs = index - GetFirstDisplayedTab(); break; } @@ -590,19 +592,15 @@ void Notebook::RecalculateSize() { m_children[static_cast( index )].child->SetAllocation( sf::FloatRect( - border_width + padding, - m_tab_requisition.y + border_width + padding, - GetAllocation().width - 2.f * ( border_width + padding ), - GetAllocation().height - ( 2.f * ( border_width + padding ) + m_tab_requisition.y ) + { border_width + padding, m_tab_requisition.y + border_width + padding }, + { GetAllocation().size.x - 2.f * ( border_width + padding ), GetAllocation().size.y - ( 2.f * ( border_width + padding ) + m_tab_requisition.y ) } ) ); m_children[static_cast( index )].tab_label->SetAllocation( sf::FloatRect( - tab_current_x + border_width + padding, - border_width + padding, - m_children[static_cast( index )].tab_label->GetRequisition().x, - m_tab_requisition.y - 2.f * padding - border_width + { tab_current_x + border_width + padding, border_width + padding }, + { m_children[static_cast( index )].tab_label->GetRequisition().x, m_tab_requisition.y - 2.f * padding - border_width } ) ); @@ -614,7 +612,7 @@ void Notebook::RecalculateSize() { auto tab_current_x = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f; for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) { - if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().width ) { + if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().size.x ) { m_num_displayed_tabs = index - GetFirstDisplayedTab(); break; } @@ -623,19 +621,18 @@ void Notebook::RecalculateSize() { m_children[static_cast( index )].child->SetAllocation( sf::FloatRect( - border_width + padding, - border_width + padding, - GetAllocation().width - 2.f * ( border_width + padding ), - GetAllocation().height - ( 2.f * ( border_width + padding ) + m_tab_requisition.y ) + { border_width + padding, border_width + padding }, + { GetAllocation().size.x - 2.f * ( border_width + padding ), + GetAllocation().size.y - ( 2.f * ( border_width + padding ) + m_tab_requisition.y ) } ) ); m_children[static_cast( index )].tab_label->SetAllocation( sf::FloatRect( - tab_current_x + border_width + padding, - GetAllocation().height - m_tab_requisition.y + padding, - m_children[static_cast( index )].tab_label->GetRequisition().x, - m_tab_requisition.y - 2.f * padding - border_width + { tab_current_x + border_width + padding, + GetAllocation().size.y - m_tab_requisition.y + padding }, + { m_children[static_cast( index )].tab_label->GetRequisition().x, + m_tab_requisition.y - 2.f * padding - border_width } ) ); @@ -647,7 +644,7 @@ void Notebook::RecalculateSize() { auto tab_current_y = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f; for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) { - if( GetScrollable() && ( tab_current_y + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().y + scroll_button_size ) > GetAllocation().height ) { + if( GetScrollable() && ( tab_current_y + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().y + scroll_button_size ) > GetAllocation().size.y ) { m_num_displayed_tabs = index - GetFirstDisplayedTab(); break; } @@ -656,19 +653,19 @@ void Notebook::RecalculateSize() { m_children[static_cast( index )].child->SetAllocation( sf::FloatRect( - m_tab_requisition.x + border_width + padding, - border_width + padding, - GetAllocation().width - ( 2.f * ( border_width + padding ) + m_tab_requisition.x ), - GetAllocation().height - 2.f * ( border_width + padding ) + { m_tab_requisition.x + border_width + padding, + border_width + padding }, + { GetAllocation().size.x - ( 2.f * ( border_width + padding ) + m_tab_requisition.x ), + GetAllocation().size.y - 2.f * ( border_width + padding ) } ) ); m_children[static_cast( index )].tab_label->SetAllocation( sf::FloatRect( - border_width + padding, - tab_current_y + border_width + padding, - m_tab_requisition.x - 2.f * padding - border_width, - m_children[static_cast( index )].tab_label->GetRequisition().y + { border_width + padding, + tab_current_y + border_width + padding }, + { m_tab_requisition.x - 2.f * padding - border_width, + m_children[static_cast( index )].tab_label->GetRequisition().y } ) ); @@ -680,7 +677,7 @@ void Notebook::RecalculateSize() { auto tab_current_y = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f; for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) { - if( GetScrollable() && ( tab_current_y + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().y + scroll_button_size ) > GetAllocation().height ) { + if( GetScrollable() && ( tab_current_y + border_width + 2.f * padding + m_children[static_cast( index )].tab_label->GetRequisition().y + scroll_button_size ) > GetAllocation().size.y ) { m_num_displayed_tabs = index - GetFirstDisplayedTab(); break; } @@ -689,19 +686,19 @@ void Notebook::RecalculateSize() { m_children[static_cast( index )].child->SetAllocation( sf::FloatRect( - border_width + padding, - border_width + padding, - GetAllocation().width - ( 2.f * ( border_width + padding ) + m_tab_requisition.x ), - GetAllocation().height - 2.f * ( border_width + padding ) + { border_width + padding, + border_width + padding }, + { GetAllocation().size.x - ( 2.f * ( border_width + padding ) + m_tab_requisition.x ), + GetAllocation().size.y - 2.f * ( border_width + padding ) } ) ); m_children[static_cast( index )].tab_label->SetAllocation( sf::FloatRect( - GetAllocation().width - m_tab_requisition.x + padding, - tab_current_y + border_width + padding, - m_tab_requisition.x - 2.f * padding - border_width, - m_children[static_cast( index )].tab_label->GetRequisition().y + { GetAllocation().size.x - m_tab_requisition.x + padding, + tab_current_y + border_width + padding }, + { m_tab_requisition.x - 2.f * padding - border_width, + m_children[static_cast( index )].tab_label->GetRequisition().y } ) ); diff --git a/src/SFGUI/Parsers/ThemeParser/GrammarSelector.cpp b/src/SFGUI/Parsers/ThemeParser/GrammarSelector.cpp index 6caf61df..72270d06 100644 --- a/src/SFGUI/Parsers/ThemeParser/GrammarSelector.cpp +++ b/src/SFGUI/Parsers/ThemeParser/GrammarSelector.cpp @@ -22,8 +22,8 @@ void ThemeGrammar::GrammarSelector() { ) )[ &ThemeGrammar::PushSimpleSelector ]; - selector_combinator_rule = ( ( ch('>') )[ &ThemeGrammar::PushCombinatorChild ] | - ( ch(',') )[ &ThemeGrammar::PushCombinatorGroup ] | + selector_combinator_rule = ( ( ch( '>' ) )[ &ThemeGrammar::PushCombinatorChild ] | + ( ch( ',' ) )[ &ThemeGrammar::PushCombinatorGroup ] | ( eps )[ &ThemeGrammar::PushCombinatorDescendant ] ); selector_rule = ( simple_selector_rule % selector_combinator_rule )[ &ThemeGrammar::PushSelector ]; diff --git a/src/SFGUI/Parsers/ThemeParser/GrammarSimpleSelector.cpp b/src/SFGUI/Parsers/ThemeParser/GrammarSimpleSelector.cpp index 46906507..948a5cc2 100644 --- a/src/SFGUI/Parsers/ThemeParser/GrammarSimpleSelector.cpp +++ b/src/SFGUI/Parsers/ThemeParser/GrammarSimpleSelector.cpp @@ -5,10 +5,10 @@ namespace parser { namespace theme { void ThemeGrammar::GrammarSimpleSelector() { - type_rule = ( identifier_rule | ch('*') )[ &ThemeGrammar::PushType ]; - class_rule = ( ch('.') >> identifier_rule )[ &ThemeGrammar::PushClass ]; - state_rule = ( ch(':') >> identifier_rule )[ &ThemeGrammar::PushState ]; - id_rule = ( ch('#') >> identifier_rule )[ &ThemeGrammar::PushID ]; + type_rule = ( identifier_rule | ch( '*' ) )[ &ThemeGrammar::PushType ]; + class_rule = ( ch( '.' ) >> identifier_rule )[ &ThemeGrammar::PushClass ]; + state_rule = ( ch( ':' ) >> identifier_rule )[ &ThemeGrammar::PushState ]; + id_rule = ( ch( '#' ) >> identifier_rule )[ &ThemeGrammar::PushID ]; type_rule.set_name( "Type or *" ); class_rule.set_name( "Class" ); diff --git a/src/SFGUI/Parsers/ThemeParser/GrammarStatement.cpp b/src/SFGUI/Parsers/ThemeParser/GrammarStatement.cpp index 49a017e3..52c3d312 100644 --- a/src/SFGUI/Parsers/ThemeParser/GrammarStatement.cpp +++ b/src/SFGUI/Parsers/ThemeParser/GrammarStatement.cpp @@ -5,8 +5,8 @@ namespace parser { namespace theme { void ThemeGrammar::GrammarStatement() { - declaration_rule = ( identifier_rule >> ch(':') >> value_rule >> ch(';') )[ &ThemeGrammar::PushDeclaration ]; - rule_rule = ( selector_rule >> ch('{') >> *declaration_rule >> ch('}') )[ &ThemeGrammar::PushRule ]; + declaration_rule = ( identifier_rule >> ch( ':' ) >> value_rule >> ch( ';' ) )[ &ThemeGrammar::PushDeclaration ]; + rule_rule = ( selector_rule >> ch( '{' ) >> *declaration_rule >> ch( '}' ) )[ &ThemeGrammar::PushRule ]; declaration_rule.set_name( "Declaration" ); rule_rule.set_name( "Rule" ); diff --git a/src/SFGUI/Parsers/ThemeParser/GrammarToken.cpp b/src/SFGUI/Parsers/ThemeParser/GrammarToken.cpp index 8ec53e1d..34569070 100644 --- a/src/SFGUI/Parsers/ThemeParser/GrammarToken.cpp +++ b/src/SFGUI/Parsers/ThemeParser/GrammarToken.cpp @@ -10,8 +10,8 @@ void ThemeGrammar::GrammarToken() { end_rule = ell::CharGrammarBase::end; - identifier_rule = lexeme( alpha >> *( alnum | chset("-") ) )[ &ThemeGrammar::PushIdentifier ]; - value_rule = lexeme( +( alnum | chset(".# /-") ) )[ &ThemeGrammar::PushValue ]; + identifier_rule = lexeme( alpha >> *( alnum | chset( "-" ) ) )[ &ThemeGrammar::PushIdentifier ]; + value_rule = lexeme( +( alnum | chset( ".# /-" ) ) )[ &ThemeGrammar::PushValue ]; skipper_rule.set_name( "Skipper" ); comment_rule.set_name( "Comment" ); diff --git a/src/SFGUI/Parsers/ThemeParser/Parse.cpp b/src/SFGUI/Parsers/ThemeParser/Parse.cpp index cd0550a8..687e3ae5 100644 --- a/src/SFGUI/Parsers/ThemeParser/Parse.cpp +++ b/src/SFGUI/Parsers/ThemeParser/Parse.cpp @@ -15,7 +15,7 @@ std::string GetLine( std::string str, std::size_t line ) { for( std::size_t current_line = 1; current_line < line; ++current_line ) { auto position = str.find( '\n' ); if( ( position == std::string::npos ) || ( position == ( str.size() - 1 ) ) ) { - return std::string(""); + return std::string( "" ); } str.erase( 0, position + 1 ); diff --git a/src/SFGUI/RadioButton.cpp b/src/SFGUI/RadioButton.cpp index f9dab071..808f8ccc 100644 --- a/src/SFGUI/RadioButton.cpp +++ b/src/SFGUI/RadioButton.cpp @@ -54,7 +54,7 @@ void RadioButton::SetActive( bool active ) { } void RadioButton::HandleMouseClick( sf::Mouse::Button button, int x, int y ) { - if( !IsActive() && ( button == sf::Mouse::Left ) ) { + if( !IsActive() && ( button == sf::Mouse::Button::Left ) ) { SetActive( true ); } diff --git a/src/SFGUI/Renderer.cpp b/src/SFGUI/Renderer.cpp index 88a65e31..0cf5a6a5 100644 --- a/src/SFGUI/Renderer.cpp +++ b/src/SFGUI/Renderer.cpp @@ -9,10 +9,13 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -46,7 +49,7 @@ Renderer::Renderer() : // Load our "no texture" pseudo-texture. sf::Image pseudo_image; - pseudo_image.create( 2, 2, sf::Color::White ); + pseudo_image.resize( { 2, 2 }, sf::Color::White ); m_pseudo_texture = LoadTexture( pseudo_image ); } @@ -103,7 +106,7 @@ RendererViewport::Ptr Renderer::CreateViewport() { } Primitive::Ptr Renderer::CreateText( const sf::Text& text ) { - const auto& font = *text.getFont(); + const auto& font = text.getFont(); auto character_size = text.getCharacterSize(); auto color = text.getFillColor(); @@ -119,7 +122,7 @@ Primitive::Ptr Renderer::CreateText( const sf::Text& text ) { const static auto tab_spaces = 2.f; - sf::Uint32 previous_character = 0; + std::uint32_t previous_character = 0; auto primitive = std::make_shared( str.getSize() * 4 ); @@ -153,10 +156,10 @@ Primitive::Ptr Renderer::CreateText( const sf::Text& text ) { PrimitiveVertex vertex2; PrimitiveVertex vertex3; - vertex0.position = position + sf::Vector2f( static_cast( glyph.bounds.left ), static_cast( glyph.bounds.top ) ); - vertex1.position = position + sf::Vector2f( static_cast( glyph.bounds.left ), static_cast( glyph.bounds.top + glyph.bounds.height ) ); - vertex2.position = position + sf::Vector2f( static_cast( glyph.bounds.left + glyph.bounds.width ), static_cast( glyph.bounds.top ) ); - vertex3.position = position + sf::Vector2f( static_cast( glyph.bounds.left + glyph.bounds.width ), static_cast( glyph.bounds.top + glyph.bounds.height ) ); + vertex0.position = position + sf::Vector2f( static_cast( glyph.bounds.position.x ), static_cast( glyph.bounds.position.y ) ); + vertex1.position = position + sf::Vector2f( static_cast( glyph.bounds.position.x ), static_cast( glyph.bounds.position.y + glyph.bounds.size.y ) ); + vertex2.position = position + sf::Vector2f( static_cast( glyph.bounds.position.x + glyph.bounds.size.x ), static_cast( glyph.bounds.position.y ) ); + vertex3.position = position + sf::Vector2f( static_cast( glyph.bounds.position.x + glyph.bounds.size.x ), static_cast( glyph.bounds.position.y + glyph.bounds.size.y ) ); vertex0.color = color; vertex1.color = color; @@ -166,10 +169,10 @@ Primitive::Ptr Renderer::CreateText( const sf::Text& text ) { // Let SFML cast the Rect for us. sf::FloatRect texture_rect( glyph.textureRect ); - vertex0.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top ); - vertex1.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top + texture_rect.height ); - vertex2.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top ); - vertex3.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top + texture_rect.height ); + vertex0.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.position.x, texture_rect.position.y ); + vertex1.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.position.x, texture_rect.position.y + texture_rect.size.y ); + vertex2.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.position.x + texture_rect.size.x, texture_rect.position.y ); + vertex3.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.position.x + texture_rect.size.x, texture_rect.position.y + texture_rect.size.y ); character_primitive.Clear(); @@ -353,7 +356,7 @@ Primitive::Ptr Renderer::CreateRect( const sf::Vector2f& top_left, const sf::Vec } Primitive::Ptr Renderer::CreateRect( const sf::FloatRect& rect, const sf::Color& color ) { - return CreateRect( sf::Vector2f( rect.left, rect.top ), sf::Vector2f( rect.left + rect.width, rect.top + rect.height ), color ); + return CreateRect( rect.position, rect.position + rect.size, color ); } Primitive::Ptr Renderer::CreateTriangle( const sf::Vector2f& point0, const sf::Vector2f& point1, const sf::Vector2f& point2, const sf::Color& color ) { @@ -394,10 +397,10 @@ Primitive::Ptr Renderer::CreateSprite( const sf::FloatRect& rect, PrimitiveTextu PrimitiveVertex vertex2; PrimitiveVertex vertex3; - vertex0.position = sf::Vector2f( std::floor( rect.left + .5f ), std::floor( rect.top + .5f ) ); - vertex1.position = sf::Vector2f( std::floor( rect.left + .5f ), std::floor( rect.top + .5f ) + std::floor( rect.height + .5f ) ); - vertex2.position = sf::Vector2f( std::floor( rect.left + .5f ) + std::floor( rect.width + .5f ), std::floor( rect.top + .5f ) ); - vertex3.position = sf::Vector2f( std::floor( rect.left + .5f ) + std::floor( rect.width + .5f ), std::floor( rect.top + .5f ) + std::floor( rect.height + .5f ) ); + vertex0.position = sf::Vector2f( std::floor( rect.position.x + .5f ), std::floor( rect.position.y + .5f ) ); + vertex1.position = sf::Vector2f( std::floor( rect.position.x + .5f ), std::floor( rect.position.y + .5f ) + std::floor( rect.size.y + .5f ) ); + vertex2.position = sf::Vector2f( std::floor( rect.position.x + .5f ) + std::floor( rect.size.x + .5f ), std::floor( rect.position.y + .5f ) ); + vertex3.position = sf::Vector2f( std::floor( rect.position.x + .5f ) + std::floor( rect.size.x + .5f ), std::floor( rect.position.y + .5f ) + std::floor( rect.size.y + .5f ) ); vertex0.color = sf::Color( 255, 255, 255, 255 ); vertex1.color = sf::Color( 255, 255, 255, 255 ); @@ -406,11 +409,11 @@ Primitive::Ptr Renderer::CreateSprite( const sf::FloatRect& rect, PrimitiveTextu sf::Vector2f coords[4]; - if( ( subrect.left != 0.f ) || ( subrect.top != 0.f ) || ( subrect.width != 0.f ) || ( subrect.height != 0.f ) ) { - coords[0] = offset + sf::Vector2f( std::floor( subrect.left + .5f ), std::floor( subrect.top + .5f ) ); - coords[3] = offset + sf::Vector2f( std::floor( subrect.left + .5f ), std::floor( subrect.top + .5f ) ) + sf::Vector2f( 0.f, std::floor( subrect.height + .5f ) ); - coords[1] = offset + sf::Vector2f( std::floor( subrect.left + .5f ), std::floor( subrect.top + .5f ) ) + sf::Vector2f( std::floor( subrect.width + .5f ), 0.f ); - coords[2] = offset + sf::Vector2f( std::floor( subrect.left + .5f ), std::floor( subrect.top + .5f ) ) + sf::Vector2f( std::floor( subrect.width + .5f ), std::floor( subrect.height + .5f ) ); + if( ( subrect.position.x != 0.f ) || ( subrect.position.y != 0.f ) || ( subrect.size.x != 0.f ) || ( subrect.size.y != 0.f ) ) { + coords[0] = offset + sf::Vector2f( std::floor( subrect.position.x + .5f ), std::floor( subrect.position.y + .5f ) ); + coords[3] = offset + sf::Vector2f( std::floor( subrect.position.x + .5f ), std::floor( subrect.position.y + .5f ) ) + sf::Vector2f( 0.f, std::floor( subrect.size.y + .5f ) ); + coords[1] = offset + sf::Vector2f( std::floor( subrect.position.x + .5f ), std::floor( subrect.position.y + .5f ) ) + sf::Vector2f( std::floor( subrect.size.x + .5f ), 0.f ); + coords[2] = offset + sf::Vector2f( std::floor( subrect.position.x + .5f ), std::floor( subrect.position.y + .5f ) ) + sf::Vector2f( std::floor( subrect.size.x + .5f ), std::floor( subrect.size.y + .5f ) ); } else { coords[0] = offset + sf::Vector2f( 0.f, 0.f ); @@ -505,7 +508,7 @@ void Renderer::WipeStateCache( sf::RenderTarget& target ) const { bool glStatesSet; bool ViewChanged; sf::BlendMode LastBlendMode; - sf::Uint64 LastTextureId; + std::uint64_t LastTextureId; bool UseVertexCache; sf::Vertex VertexCache[4]; }; @@ -536,7 +539,7 @@ sf::Vector2f Renderer::LoadFont( const sf::Font& font, unsigned int size ) { // Since maps allocate everything non-contiguously on the heap we can use void* instead of Page here. mutable std::map unused4; - mutable std::vector unused5; + mutable std::vector unused5; }; // All your font face are belong to us too. @@ -552,15 +555,15 @@ sf::Vector2f Renderer::LoadFont( const sf::Font& font, unsigned int size ) { // If the user does not specify their own character sets, make sure all the glyphs we need are loaded. if( m_character_sets.empty() ) { - for( sf::Uint32 codepoint = 0; codepoint < 0x0370; ++codepoint ) { - font.getGlyph( codepoint, size, false ); + for( std::uint32_t codepoint = 0; codepoint < 0x0370; ++codepoint ) { + (void)font.getGlyph( codepoint, size, false ); } } // Make a local copy to avoid unnecessary dereferencing. for( const auto character_set : m_character_sets ) { for( auto codepoint = character_set.first; codepoint < character_set.second; ++codepoint ) { - font.getGlyph( codepoint, size, false ); + (void)font.getGlyph( codepoint, size, false ); } } @@ -628,7 +631,7 @@ PrimitiveTexture::Ptr Renderer::LoadTexture( const sf::Image& image ) { static auto create_maximal = true; if( create_maximal ) { - if( !new_texture->create( 1u, static_cast( max_texture_size ) ) ) { + if( !new_texture->resize( { 1u, static_cast( max_texture_size ) } ) ) { create_maximal = false; } } @@ -639,11 +642,11 @@ PrimitiveTexture::Ptr Renderer::LoadTexture( const sf::Image& image ) { auto current_page = m_texture_atlas[static_cast( current_page_index )].get(); auto old_image = current_page->copyToImage(); - new_image.create( old_image.getSize().x, static_cast( max_texture_size ), sf::Color::White ); - new_image.copy( old_image, 0u, 0u ); - new_image.copy( image, 0u, static_cast( current_page_last_occupied_location ) ); + new_image.resize( { old_image.getSize().x, static_cast( max_texture_size ) }, sf::Color::White ); + (void)new_image.copy( old_image, { 0u, 0u } ); + (void)new_image.copy( image, { 0u, static_cast( current_page_last_occupied_location ) } ); - current_page->loadFromImage( new_image ); + (void)current_page->loadFromImage( new_image ); } // Insert the new page. @@ -661,15 +664,15 @@ PrimitiveTexture::Ptr Renderer::LoadTexture( const sf::Image& image ) { // Image is loaded into atlas after expanding texture atlas. auto old_image = current_page->copyToImage(); - new_image.create( static_cast( std::max( current_page_size_x, required_horizontal_size ) ), static_cast( std::max( current_page_size_y, current_page_last_occupied_location + required_vertical_size ) ), sf::Color::White ); - new_image.copy( old_image, 0u, 0u ); - new_image.copy( image, 0u, static_cast( current_page_last_occupied_location ) ); + new_image.resize( { static_cast( std::max( current_page_size_x, required_horizontal_size ) ), static_cast( std::max( current_page_size_y, current_page_last_occupied_location + required_vertical_size ) ) }, sf::Color::White ); + (void)new_image.copy( old_image, { 0u, 0u } ); + (void)new_image.copy( image, { 0u, static_cast( current_page_last_occupied_location ) } ); - current_page->loadFromImage( new_image ); + (void)current_page->loadFromImage( new_image ); } else { // Image is loaded into atlas. - current_page->update( image, 0u, static_cast( current_page_last_occupied_location ) ); + current_page->update( image, { 0u, static_cast( current_page_last_occupied_location ) } ); } auto offset = sf::Vector2i( 0, current_page_index * max_texture_size + current_page_last_occupied_location ); @@ -725,7 +728,7 @@ void Renderer::UpdateImage( const sf::Vector2f& offset, const sf::Image& data ) auto page = static_cast( int_offset.y / max_texture_size ); - m_texture_atlas[page]->update( data, 0u, static_cast( int_offset.y % max_texture_size ) ); + m_texture_atlas[page]->update( data, { 0u, static_cast( int_offset.y % max_texture_size ) } ); return; } @@ -809,7 +812,7 @@ const sf::Vector2i& Renderer::GetWindowSize() const { return m_last_window_size; } -void Renderer::AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ) { +void Renderer::AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ) { if( high_bound <= low_bound ) { return; } diff --git a/src/SFGUI/Renderers/NonLegacyRenderer.cpp b/src/SFGUI/Renderers/NonLegacyRenderer.cpp index e41e5437..9a48517e 100644 --- a/src/SFGUI/Renderers/NonLegacyRenderer.cpp +++ b/src/SFGUI/Renderers/NonLegacyRenderer.cpp @@ -393,7 +393,7 @@ bool NonLegacyRenderer::IsAvailable() { void NonLegacyRenderer::Display( sf::Window& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); auto blend_enabled = CheckGLError( glIsEnabled( GL_BLEND ) ); @@ -424,7 +424,7 @@ void NonLegacyRenderer::Display( sf::Window& target ) const { void NonLegacyRenderer::Display( sf::RenderWindow& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); } @@ -432,7 +432,7 @@ void NonLegacyRenderer::Display( sf::RenderWindow& target ) const { void NonLegacyRenderer::Display( sf::RenderTexture& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); } @@ -667,7 +667,7 @@ void NonLegacyRenderer::RefreshVBO() { current_batch.max_index = m_vertex_count - 1; current_batch.custom_draw = false; - sf::FloatRect window_viewport( 0.f, 0.f, static_cast( m_window_size.x ), static_cast( m_window_size.y ) ); + sf::FloatRect window_viewport( { 0.f, 0.f }, sf::Vector2f( m_window_size ) ); const auto max_texture_size = GetMaxTextureSize(); const auto default_texture_size = m_texture_atlas[0]->getSize(); @@ -695,10 +695,7 @@ void NonLegacyRenderer::RefreshVBO() { position_transform += ( destination_origin - viewport->GetSourceOrigin() ); if( m_cull ) { - viewport_rect.left = destination_origin.x; - viewport_rect.top = destination_origin.y; - viewport_rect.width = size.x; - viewport_rect.height = size.y; + viewport_rect = { destination_origin, size }; } } @@ -735,7 +732,7 @@ void NonLegacyRenderer::RefreshVBO() { sf::Vector2f position( 0.f, 0.f ); - sf::FloatRect bounding_rect( 0.f, 0.f, 0.f, 0.f ); + sf::FloatRect bounding_rect( { 0.f, 0.f }, { 0.f, 0.f } ); auto atlas_page = 0; @@ -765,25 +762,25 @@ void NonLegacyRenderer::RefreshVBO() { // Update the bounding rect. if( m_cull ) { - if( position.x < bounding_rect.left ) { - bounding_rect.width += bounding_rect.left - position.x; - bounding_rect.left = position.x; + if( position.x < bounding_rect.position.x ) { + bounding_rect.size.x += bounding_rect.position.x - position.x; + bounding_rect.position.x = position.x; } - else if( position.x > bounding_rect.left + bounding_rect.width ) { - bounding_rect.width = position.x - bounding_rect.left; + else if( position.x > bounding_rect.position.x + bounding_rect.size.x ) { + bounding_rect.size.x = position.x - bounding_rect.position.x; } - if( position.y < bounding_rect.top ) { - bounding_rect.height += bounding_rect.top - position.y; - bounding_rect.top = position.y; + if( position.y < bounding_rect.position.y ) { + bounding_rect.size.y += bounding_rect.position.y - position.y; + bounding_rect.position.y = position.y; } - else if( position.y > bounding_rect.top + bounding_rect.height ) { - bounding_rect.height = position.y - bounding_rect.top; + else if( position.y > bounding_rect.position.y + bounding_rect.size.y ) { + bounding_rect.size.y = position.y - bounding_rect.position.y; } } } - if( m_cull && !viewport_rect.intersects( bounding_rect ) ) { + if( m_cull && !viewport_rect.findIntersection( bounding_rect ) ) { m_vertex_data.resize( static_cast( m_last_vertex_count ) ); m_color_data.resize( static_cast( m_last_vertex_count ) ); m_texture_data.resize( static_cast( m_last_vertex_count ) ); diff --git a/src/SFGUI/Renderers/VertexArrayRenderer.cpp b/src/SFGUI/Renderers/VertexArrayRenderer.cpp index afbb7df7..58cf4486 100644 --- a/src/SFGUI/Renderers/VertexArrayRenderer.cpp +++ b/src/SFGUI/Renderers/VertexArrayRenderer.cpp @@ -34,7 +34,7 @@ const std::string& VertexArrayRenderer::GetName() const { void VertexArrayRenderer::Display( sf::Window& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); CheckGLError( glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ) ); CheckGLError( glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT ) ); @@ -59,7 +59,7 @@ void VertexArrayRenderer::Display( sf::Window& target ) const { void VertexArrayRenderer::Display( sf::RenderWindow& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); @@ -69,7 +69,7 @@ void VertexArrayRenderer::Display( sf::RenderWindow& target ) const { void VertexArrayRenderer::Display( sf::RenderTexture& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); @@ -244,7 +244,7 @@ void VertexArrayRenderer::RefreshArray() { current_batch.max_index = m_vertex_count - 1; current_batch.custom_draw = false; - sf::FloatRect window_viewport( 0.f, 0.f, static_cast( m_window_size.x ), static_cast( m_window_size.y ) ); + sf::FloatRect window_viewport( { 0.f, 0.f }, sf::Vector2f( m_window_size ) ); const auto max_texture_size = GetMaxTextureSize(); const auto default_texture_size = m_texture_atlas[0]->getSize(); @@ -272,10 +272,7 @@ void VertexArrayRenderer::RefreshArray() { position_transform += ( destination_origin - viewport->GetSourceOrigin() ); if( m_cull ) { - viewport_rect.left = destination_origin.x; - viewport_rect.top = destination_origin.y; - viewport_rect.width = size.x; - viewport_rect.height = size.y; + viewport_rect = { destination_origin, size }; } } @@ -312,7 +309,7 @@ void VertexArrayRenderer::RefreshArray() { sf::Vector2f position( 0.f, 0.f ); - sf::FloatRect bounding_rect( 0.f, 0.f, 0.f, 0.f ); + sf::FloatRect bounding_rect( { 0.f, 0.f }, { 0.f, 0.f } ); auto atlas_page = 0; @@ -342,25 +339,25 @@ void VertexArrayRenderer::RefreshArray() { // Update the bounding rect. if( m_cull ) { - if( position.x < bounding_rect.left ) { - bounding_rect.width += bounding_rect.left - position.x; - bounding_rect.left = position.x; + if( position.x < bounding_rect.position.x ) { + bounding_rect.size.x += bounding_rect.position.x - position.x; + bounding_rect.position.x = position.x; } - else if( position.x > bounding_rect.left + bounding_rect.width ) { - bounding_rect.width = position.x - bounding_rect.left; + else if( position.x > bounding_rect.position.x + bounding_rect.size.x ) { + bounding_rect.size.x = position.x - bounding_rect.position.x; } - if( position.y < bounding_rect.top ) { - bounding_rect.height += bounding_rect.top - position.y; - bounding_rect.top = position.y; + if( position.y < bounding_rect.position.y ) { + bounding_rect.size.y += bounding_rect.position.y - position.y; + bounding_rect.position.y = position.y; } - else if( position.y > bounding_rect.top + bounding_rect.height ) { - bounding_rect.height = position.y - bounding_rect.top; + else if( position.y > bounding_rect.position.y + bounding_rect.size.y ) { + bounding_rect.size.y = position.y - bounding_rect.position.y; } } } - if( m_cull && !viewport_rect.intersects( bounding_rect ) ) { + if( m_cull && !viewport_rect.findIntersection( bounding_rect ) ) { m_vertex_data.resize( static_cast( m_last_vertex_count ) ); m_color_data.resize( static_cast( m_last_vertex_count ) ); m_texture_data.resize( static_cast( m_last_vertex_count ) ); diff --git a/src/SFGUI/Renderers/VertexBufferRenderer.cpp b/src/SFGUI/Renderers/VertexBufferRenderer.cpp index 7e05a43b..a6d43f1e 100644 --- a/src/SFGUI/Renderers/VertexBufferRenderer.cpp +++ b/src/SFGUI/Renderers/VertexBufferRenderer.cpp @@ -154,7 +154,7 @@ bool VertexBufferRenderer::IsAvailable() { void VertexBufferRenderer::Display( sf::Window& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); CheckGLError( glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ) ); CheckGLError( glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT ) ); @@ -179,7 +179,7 @@ void VertexBufferRenderer::Display( sf::Window& target ) const { void VertexBufferRenderer::Display( sf::RenderWindow& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); @@ -189,7 +189,7 @@ void VertexBufferRenderer::Display( sf::RenderWindow& target ) const { void VertexBufferRenderer::Display( sf::RenderTexture& target ) const { m_window_size = static_cast( target.getSize() ); - target.setActive( true ); + (void)target.setActive( true ); DisplayImpl(); @@ -407,7 +407,7 @@ void VertexBufferRenderer::RefreshVBO() { current_batch.max_index = m_vertex_count - 1; current_batch.custom_draw = false; - sf::FloatRect window_viewport( 0.f, 0.f, static_cast( m_window_size.x ), static_cast( m_window_size.y ) ); + sf::FloatRect window_viewport( { 0.f, 0.f }, sf::Vector2f( m_window_size ) ); const auto max_texture_size = GetMaxTextureSize(); const auto default_texture_size = m_texture_atlas[0]->getSize(); @@ -435,10 +435,7 @@ void VertexBufferRenderer::RefreshVBO() { position_transform += ( destination_origin - viewport->GetSourceOrigin() ); if( m_cull ) { - viewport_rect.left = destination_origin.x; - viewport_rect.top = destination_origin.y; - viewport_rect.width = size.x; - viewport_rect.height = size.y; + viewport_rect = { destination_origin, size }; } } @@ -475,7 +472,7 @@ void VertexBufferRenderer::RefreshVBO() { sf::Vector2f position( 0.f, 0.f ); - sf::FloatRect bounding_rect( 0.f, 0.f, 0.f, 0.f ); + sf::FloatRect bounding_rect( { 0.f, 0.f }, { 0.f, 0.f } ); auto atlas_page = 0; @@ -505,25 +502,25 @@ void VertexBufferRenderer::RefreshVBO() { // Update the bounding rect. if( m_cull ) { - if( position.x < bounding_rect.left ) { - bounding_rect.width += bounding_rect.left - position.x; - bounding_rect.left = position.x; + if( position.x < bounding_rect.position.x ) { + bounding_rect.size.x += bounding_rect.position.x - position.x; + bounding_rect.position.x = position.x; } - else if( position.x > bounding_rect.left + bounding_rect.width ) { - bounding_rect.width = position.x - bounding_rect.left; + else if( position.x > bounding_rect.position.x + bounding_rect.size.x ) { + bounding_rect.size.x = position.x - bounding_rect.position.x; } - if( position.y < bounding_rect.top ) { - bounding_rect.height += bounding_rect.top - position.y; - bounding_rect.top = position.y; + if( position.y < bounding_rect.position.y ) { + bounding_rect.size.y += bounding_rect.position.y - position.y; + bounding_rect.position.y = position.y; } - else if( position.y > bounding_rect.top + bounding_rect.height ) { - bounding_rect.height = position.y - bounding_rect.top; + else if( position.y > bounding_rect.position.y + bounding_rect.size.y ) { + bounding_rect.size.y = position.y - bounding_rect.position.y; } } } - if( m_cull && !viewport_rect.intersects( bounding_rect ) ) { + if( m_cull && !viewport_rect.findIntersection( bounding_rect ) ) { m_vertex_data.resize( static_cast( m_last_vertex_count ) ); m_color_data.resize( static_cast( m_last_vertex_count ) ); m_texture_data.resize( static_cast( m_last_vertex_count ) ); diff --git a/src/SFGUI/SFGUI.cpp b/src/SFGUI/SFGUI.cpp index d88a8b37..bf8960fe 100644 --- a/src/SFGUI/SFGUI.cpp +++ b/src/SFGUI/SFGUI.cpp @@ -44,7 +44,7 @@ bool SFGUI::IsAlive() { return alive; } -void SFGUI::AddCharacterSet( sf::Uint32 low_bound, sf::Uint32 high_bound ) { +void SFGUI::AddCharacterSet( std::uint32_t low_bound, std::uint32_t high_bound ) { Renderer::Get().AddCharacterSet( low_bound, high_bound ); Context::Get().GetEngine().AddCharacterSet( low_bound, high_bound ); } diff --git a/src/SFGUI/Scale.cpp b/src/SFGUI/Scale.cpp index f0ee7f6e..a91efe8a 100644 --- a/src/SFGUI/Scale.cpp +++ b/src/SFGUI/Scale.cpp @@ -30,22 +30,22 @@ Scale::Ptr Scale::Create( float min, float max, float step, Orientation orientat const sf::FloatRect Scale::GetSliderRect() const { auto slider_length = Context::Get().GetEngine().GetProperty( "SliderLength", shared_from_this() ); - auto slider_width = (GetOrientation() == Orientation::HORIZONTAL) ? GetAllocation().height : GetAllocation().width; + auto slider_width = (GetOrientation() == Orientation::HORIZONTAL) ? GetAllocation().size.y : GetAllocation().size.x; auto adjustment = GetAdjustment(); auto current_value = adjustment->GetValue(); auto value_range = adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(); if( GetOrientation() == Orientation::HORIZONTAL ) { - auto slider_x = (GetAllocation().width - slider_length) * (current_value - adjustment->GetLower()) / value_range; - auto slider_y = (GetAllocation().height - slider_width) / 2.f; + auto slider_x = (GetAllocation().size.x - slider_length) * (current_value - adjustment->GetLower()) / value_range; + auto slider_y = (GetAllocation().size.y - slider_width) / 2.f; - return sf::FloatRect( slider_x, slider_y, slider_length, slider_width ); + return sf::FloatRect( { slider_x, slider_y }, { slider_length, slider_width } ); } - auto slider_x = (GetAllocation().width - slider_width) / 2.f; - auto slider_y = (GetAllocation().height - slider_length) * (1 - ((current_value - adjustment->GetLower()) / value_range)); + auto slider_x = (GetAllocation().size.x - slider_width) / 2.f; + auto slider_y = (GetAllocation().size.y - slider_length) * (1 - ((current_value - adjustment->GetLower()) / value_range)); - return sf::FloatRect( slider_x, slider_y, slider_width, slider_length ); + return sf::FloatRect( { slider_x, slider_y }, { slider_width, slider_length } ); } @@ -55,7 +55,7 @@ std::unique_ptr Scale::InvalidateImpl() const { sf::Vector2f Scale::CalculateRequisition() { auto slider_length = Context::Get().GetEngine().GetProperty( "SliderLength", shared_from_this() ); - auto slider_width = std::max( 3.f, ( GetOrientation() == Orientation::HORIZONTAL ) ? GetAllocation().height : GetAllocation().width ); + auto slider_width = std::max( 3.f, ( GetOrientation() == Orientation::HORIZONTAL ) ? GetAllocation().size.y : GetAllocation().size.x ); if( GetOrientation() == Orientation::HORIZONTAL ) { return sf::Vector2f( slider_length * 2.f, slider_width ); @@ -65,7 +65,7 @@ sf::Vector2f Scale::CalculateRequisition() { } void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { - if( button != sf::Mouse::Left ) { + if( button != sf::Mouse::Button::Left ) { return; } @@ -74,12 +74,12 @@ void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, m_dragging = false; } - if( !GetAllocation().contains( static_cast( x ), static_cast( y ) ) ) { + if( !GetAllocation().contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { return; } if( press ) { - if( !GetSliderRect().contains( static_cast( x ) - GetAllocation().left, static_cast( y ) - GetAllocation().top ) ) { + if( !GetSliderRect().contains( sf::Vector2f( sf::Vector2( x, y ) ) - GetAllocation().position ) ) { Adjustment::Ptr adjustment( GetAdjustment() ); auto minor_step = adjustment->GetMinorStep(); @@ -91,13 +91,13 @@ void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, auto trough_length = 0.f; if( GetOrientation() == Orientation::HORIZONTAL ) { - trough_position = static_cast( x ) - ( GetAllocation().left + GetSliderRect().width / 2.f ); - trough_length = GetAllocation().width - GetSliderRect().width; + trough_position = static_cast( x ) - ( GetAllocation().position.x + GetSliderRect().size.x / 2.f ); + trough_length = GetAllocation().size.x - GetSliderRect().size.x; } if( GetOrientation() == Orientation::VERTICAL ) { - trough_position = static_cast( y ) - ( GetAllocation().top + GetSliderRect().height / 2.f ); - trough_length = GetAllocation().height - GetSliderRect().height; + trough_position = static_cast( y ) - ( GetAllocation().position.y + GetSliderRect().size.y / 2.f ); + trough_length = GetAllocation().size.y - GetSliderRect().size.y; } trough_position = std::min( trough_position, trough_length ); @@ -117,8 +117,8 @@ void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, m_dragging = true; m_drag_offset.reset( new sf::Vector2f( - static_cast( x ) - ( GetAllocation().left + GetSliderRect().left + GetSliderRect().width / 2.f ), - static_cast( y ) - ( GetAllocation().top + GetSliderRect().top + GetSliderRect().height / 2.f ) + static_cast( x ) - ( GetAllocation().position.x + GetSliderRect().position.x + GetSliderRect().size.x / 2.f ), + static_cast( y ) - ( GetAllocation().position.y + GetSliderRect().position.y + GetSliderRect().size.y / 2.f ) ) ); } } @@ -135,8 +135,8 @@ void Scale::HandleMouseMoveEvent( int x, int y ) { auto steps = value_range / adjustment->GetMinorStep(); if( GetOrientation() == Orientation::HORIZONTAL ) { - auto slider_center_x = GetAllocation().left + slider_rect.left + slider_rect.width / 2.0f; - auto step_distance = (GetAllocation().width - slider_rect.width) / steps; + auto slider_center_x = GetAllocation().position.x + slider_rect.position.x + slider_rect.size.x / 2.0f; + auto step_distance = (GetAllocation().size.x - slider_rect.size.x) / steps; auto delta = static_cast( x ) - slider_center_x - m_drag_offset->x; while( delta < (-step_distance / 2) ) { @@ -150,8 +150,8 @@ void Scale::HandleMouseMoveEvent( int x, int y ) { } } else { - auto slider_center_y = GetAllocation().top + slider_rect.top + slider_rect.height / 2.0f; - auto step_distance = (GetAllocation().height - slider_rect.height) / steps; + auto slider_center_y = GetAllocation().position.y + slider_rect.getCenter().y; + auto step_distance = (GetAllocation().size.y - slider_rect.size.y) / steps; auto delta = static_cast( y ) - slider_center_y - m_drag_offset->y; while( delta < (-step_distance / 2) ) { diff --git a/src/SFGUI/Scrollbar.cpp b/src/SFGUI/Scrollbar.cpp index 4122dc39..d0d6a930 100644 --- a/src/SFGUI/Scrollbar.cpp +++ b/src/SFGUI/Scrollbar.cpp @@ -42,8 +42,8 @@ const sf::FloatRect Scrollbar::GetSliderRect() const { auto pages = std::max( ( adjustment->GetPageSize() > .0f ) ? ( ( adjustment->GetUpper() - adjustment->GetLower() ) / adjustment->GetPageSize() ) : 1.f, 1.f ); if( GetOrientation() == Orientation::HORIZONTAL ) { - auto stepper_length = GetAllocation().height; - auto trough_length = GetAllocation().width - 2.f * stepper_length; + auto stepper_length = GetAllocation().size.y; + auto trough_length = GetAllocation().size.x - 2.f * stepper_length; auto slider_length = std::max( mimimum_slider_length, trough_length / pages ); auto slider_x = stepper_length; @@ -53,11 +53,11 @@ const sf::FloatRect Scrollbar::GetSliderRect() const { slider_x = stepper_length + ( trough_length - slider_length ) * ( adjustment->GetValue() - adjustment->GetLower() ) / value_range; } - return sf::FloatRect( slider_x, slider_y, slider_length, GetAllocation().height ); + return sf::FloatRect( { slider_x, slider_y }, { slider_length, GetAllocation().size.y } ); } - auto stepper_length = GetAllocation().width; - auto trough_length = GetAllocation().height - 2.f * stepper_length; + auto stepper_length = GetAllocation().size.x; + auto trough_length = GetAllocation().size.y - 2.f * stepper_length; auto slider_length = std::max( mimimum_slider_length, trough_length / pages ); auto slider_x = 0.f; @@ -67,7 +67,7 @@ const sf::FloatRect Scrollbar::GetSliderRect() const { slider_y = stepper_length + ( trough_length - slider_length ) * ( adjustment->GetValue() - adjustment->GetLower() ) / value_range; } - return sf::FloatRect( slider_x, slider_y, GetAllocation().width, slider_length ); + return sf::FloatRect( { slider_x, slider_y }, { GetAllocation().size.x, slider_length } ); } bool Scrollbar::IsDecreaseStepperPressed() const { @@ -93,37 +93,36 @@ sf::Vector2f Scrollbar::CalculateRequisition() { } void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { - if( button != sf::Mouse::Left ) { + if( button != sf::Mouse::Button::Left ) { return; } if( press ) { auto slider_rect = GetSliderRect(); - slider_rect.left += GetAllocation().left; - slider_rect.top += GetAllocation().top; + slider_rect.position += GetAllocation().position; - if( slider_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( slider_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_dragging = true; if( GetOrientation() == Orientation::HORIZONTAL ) { - auto slider_mid = slider_rect.left + slider_rect.width / 2.f; - m_slider_click_offset = static_cast( x ) + GetAllocation().left - slider_mid; + auto slider_mid = slider_rect.getCenter().x; + m_slider_click_offset = static_cast( x ) + GetAllocation().position.x - slider_mid; } else { - auto slider_mid = slider_rect.top + slider_rect.height / 2.f; - m_slider_click_offset = static_cast( y ) + GetAllocation().top - slider_mid; + auto slider_mid = slider_rect.getCenter().y; + m_slider_click_offset = static_cast( y ) + GetAllocation().position.y - slider_mid; } return; } if( GetOrientation() == Orientation::HORIZONTAL ) { - auto stepper_length = GetAllocation().height; + auto stepper_length = GetAllocation().size.y; - sf::FloatRect decrease_stepper_rect( GetAllocation().left, GetAllocation().top, stepper_length, GetAllocation().height ); - sf::FloatRect increase_stepper_rect( GetAllocation().left + GetAllocation().width - stepper_length, GetAllocation().top, stepper_length, GetAllocation().height ); + sf::FloatRect decrease_stepper_rect( GetAllocation().position, {stepper_length, GetAllocation().size.y} ); + sf::FloatRect increase_stepper_rect( { GetAllocation().position.x + GetAllocation().size.x - stepper_length, GetAllocation().position.y }, { stepper_length, GetAllocation().size.y } ); - if( decrease_stepper_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( decrease_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_decrease_pressed = true; GetAdjustment()->Decrement(); m_elapsed_time = 0.f; @@ -132,7 +131,7 @@ void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, in return; } - if( increase_stepper_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( increase_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_increase_pressed = true; GetAdjustment()->Increment(); m_elapsed_time = 0.f; @@ -142,12 +141,12 @@ void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, in } } else { - auto stepper_length = GetAllocation().width; + auto stepper_length = GetAllocation().size.x; - sf::FloatRect decrease_stepper_rect( GetAllocation().left, GetAllocation().top, GetAllocation().width, stepper_length ); - sf::FloatRect increase_stepper_rect( GetAllocation().left, GetAllocation().top + GetAllocation().height - stepper_length, GetAllocation().width, stepper_length ); + sf::FloatRect decrease_stepper_rect( GetAllocation().position, {GetAllocation().size.x, stepper_length} ); + sf::FloatRect increase_stepper_rect( { GetAllocation().position.x, GetAllocation().position.y + GetAllocation().size.y - stepper_length }, { GetAllocation().size.x, stepper_length } ); - if( decrease_stepper_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( decrease_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_decrease_pressed = true; GetAdjustment()->Decrement(); m_elapsed_time = 0.f; @@ -156,7 +155,7 @@ void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, in return; } - if( increase_stepper_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( increase_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_increase_pressed = true; GetAdjustment()->Increment(); m_elapsed_time = 0.f; @@ -166,12 +165,11 @@ void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, in } } - auto slider_center_x = slider_rect.left + slider_rect.width / 2.f; - auto slider_center_y = slider_rect.top + slider_rect.height / 2.f; + auto slider_center = slider_rect.getCenter(); if( GetOrientation() == Orientation::HORIZONTAL ) { - if( GetAllocation().contains( static_cast( x ), static_cast( y ) ) ) { - if( static_cast( x ) < slider_center_x ) { + if( GetAllocation().contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { + if( static_cast( x ) < slider_center.x ) { m_page_decreasing = x; GetAdjustment()->DecrementPage(); m_elapsed_time = 0.f; @@ -190,8 +188,8 @@ void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, in } } else { - if( GetAllocation().contains( static_cast( x ), static_cast( y ) ) ) { - if( static_cast( y ) < slider_center_y ) { + if( GetAllocation().contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { + if( static_cast( y ) < slider_center.y ) { m_page_decreasing = y; GetAdjustment()->DecrementPage(); m_elapsed_time = 0.f; @@ -236,10 +234,10 @@ void Scrollbar::HandleMouseMoveEvent( int x, int y ) { auto steps = value_range / adjustment->GetMinorStep(); if( GetOrientation() == Orientation::HORIZONTAL ) { - auto stepper_length = GetAllocation().height; + auto stepper_length = GetAllocation().size.y; - auto slider_center_x = slider_rect.left + slider_rect.width / 2.0f; - auto step_distance = ( GetAllocation().width - 2.f * stepper_length ) / steps; + auto slider_center_x = slider_rect.getCenter().x; + auto step_distance = ( GetAllocation().size.x - 2.f * stepper_length ) / steps; auto delta = ( static_cast( x ) - (slider_center_x + m_slider_click_offset) @@ -256,10 +254,10 @@ void Scrollbar::HandleMouseMoveEvent( int x, int y ) { } } else { - auto stepper_length = GetAllocation().width; + auto stepper_length = GetAllocation().size.x; - auto slider_center_y = slider_rect.top + slider_rect.height / 2.0f; - auto step_distance = (GetAllocation().height - 2.f * stepper_length) / steps; + auto slider_center_y = slider_rect.getCenter().y; + auto step_distance = (GetAllocation().size.y - 2.f * stepper_length) / steps; auto delta = static_cast( y ) - (slider_center_y + m_slider_click_offset); @@ -285,7 +283,7 @@ void Scrollbar::HandleUpdate( float seconds ) { } if( m_repeat_wait ) { - auto stepper_repeat_delay = Context::Get().GetEngine().GetProperty( "StepperRepeatDelay", shared_from_this() ); + auto stepper_repeat_delay = Context::Get().GetEngine().GetProperty( "StepperRepeatDelay", shared_from_this() ); if( m_elapsed_time < (static_cast( stepper_repeat_delay ) / 1000.f) ) { return; @@ -309,20 +307,20 @@ void Scrollbar::HandleUpdate( float seconds ) { } auto slider_rect = GetSliderRect(); - slider_rect.left += GetAllocation().left; - slider_rect.top += GetAllocation().top; + slider_rect.position.x += GetAllocation().position.x; + slider_rect.position.y += GetAllocation().position.y; // Increment / Decrement page while mouse is pressed on the trough if( m_page_decreasing ) { GetAdjustment()->DecrementPage(); if( GetOrientation() == Orientation::HORIZONTAL ) { - if( slider_rect.left + slider_rect.width < static_cast( m_page_decreasing ) ) { + if( slider_rect.position.x + slider_rect.size.x < static_cast( m_page_decreasing ) ) { m_page_decreasing = 0; } } else { - if( slider_rect.top + slider_rect.height < static_cast( m_page_decreasing ) ) { + if( slider_rect.position.y + slider_rect.size.y < static_cast( m_page_decreasing ) ) { m_page_decreasing = 0; } } @@ -334,12 +332,12 @@ void Scrollbar::HandleUpdate( float seconds ) { GetAdjustment()->IncrementPage(); if( GetOrientation() == Orientation::HORIZONTAL ) { - if( slider_rect.left + slider_rect.width > static_cast( m_page_increasing ) ) { + if( slider_rect.position.x + slider_rect.size.x > static_cast( m_page_increasing ) ) { m_page_increasing = 0; } } else { - if( slider_rect.top + slider_rect.height > static_cast( m_page_increasing ) ) { + if( slider_rect.position.y + slider_rect.size.y > static_cast( m_page_increasing ) ) { m_page_increasing = 0; } } diff --git a/src/SFGUI/ScrolledWindow.cpp b/src/SFGUI/ScrolledWindow.cpp index fb79bf33..e46731b3 100644 --- a/src/SFGUI/ScrolledWindow.cpp +++ b/src/SFGUI/ScrolledWindow.cpp @@ -161,23 +161,23 @@ void ScrolledWindow::RecalculateAdjustments() const { float border_width( Context::Get().GetEngine().GetProperty( "BorderWidth", shared_from_this() ) ); if( GetViewport() && GetViewport()->GetChild() ) { - auto max_horiz_val = std::max( GetViewport()->GetChild()->GetAllocation().width + border_width * 2.f, GetAllocation().width - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + auto max_horiz_val = std::max( GetViewport()->GetChild()->GetAllocation().size.x + border_width * 2.f, GetAllocation().size.x - scrollbar_width - scrollbar_spacing - border_width * 2.f ); auto h_adjustment = m_horizontal_scrollbar->GetAdjustment(); h_adjustment->SetLower( .0f ); h_adjustment->SetUpper( max_horiz_val ); h_adjustment->SetMinorStep( 1.f ); - h_adjustment->SetMajorStep( GetAllocation().width - scrollbar_width - scrollbar_spacing - border_width * 2.f ); - h_adjustment->SetPageSize( GetAllocation().width - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + h_adjustment->SetMajorStep( GetAllocation().size.x - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + h_adjustment->SetPageSize( GetAllocation().size.x - scrollbar_width - scrollbar_spacing - border_width * 2.f ); - auto max_vert_val = std::max( GetViewport()->GetChild()->GetAllocation().height + border_width * 2.f, GetAllocation().height - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + auto max_vert_val = std::max( GetViewport()->GetChild()->GetAllocation().size.y + border_width * 2.f, GetAllocation().size.y - scrollbar_width - scrollbar_spacing - border_width * 2.f ); auto v_adjustment = m_vertical_scrollbar->GetAdjustment(); v_adjustment->SetLower( .0f ); v_adjustment->SetUpper( max_vert_val ); v_adjustment->SetMinorStep( 1.f ); - v_adjustment->SetMajorStep( GetAllocation().height - scrollbar_width - scrollbar_spacing - border_width * 2.f ); - v_adjustment->SetPageSize( GetAllocation().height - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + v_adjustment->SetMajorStep( GetAllocation().size.y - scrollbar_width - scrollbar_spacing - border_width * 2.f ); + v_adjustment->SetPageSize( GetAllocation().size.y - scrollbar_width - scrollbar_spacing - border_width * 2.f ); } RecalculateContentAllocation(); @@ -202,44 +202,40 @@ void ScrolledWindow::RecalculateContentAllocation() const { m_content_allocation = GetAllocation(); - m_content_allocation.left = border_width; - m_content_allocation.top = border_width; - m_content_allocation.width -= 2.f * border_width; - m_content_allocation.height -= 2.f * border_width; + m_content_allocation.position.x = border_width; + m_content_allocation.position.y = border_width; + m_content_allocation.size.x -= 2.f * border_width; + m_content_allocation.size.y -= 2.f * border_width; if( IsVerticalScrollbarVisible() ) { - m_content_allocation.width -= ( m_vertical_scrollbar->GetRequisition().x + scrollbar_spacing ); + m_content_allocation.size.x -= ( m_vertical_scrollbar->GetRequisition().x + scrollbar_spacing ); if( ( m_placement == Placement::TOP_RIGHT ) || ( m_placement == Placement::BOTTOM_RIGHT ) ) { // Content placed at Right - m_content_allocation.left += ( m_vertical_scrollbar->GetRequisition().x + scrollbar_spacing ); + m_content_allocation.position.x += ( m_vertical_scrollbar->GetRequisition().x + scrollbar_spacing ); } } if( IsHorizontalScrollbarVisible() ) { - m_content_allocation.height -= ( m_horizontal_scrollbar->GetRequisition().y + scrollbar_spacing ); + m_content_allocation.size.y -= ( m_horizontal_scrollbar->GetRequisition().y + scrollbar_spacing ); if( ( m_placement == Placement::BOTTOM_RIGHT ) || ( m_placement == Placement::BOTTOM_LEFT ) ) { // Content placed at Bottom - m_content_allocation.top += ( m_horizontal_scrollbar->GetRequisition().y + scrollbar_spacing ); + m_content_allocation.position.y += ( m_horizontal_scrollbar->GetRequisition().y + scrollbar_spacing ); } } if( ( m_placement == Placement::TOP_LEFT ) || ( m_placement == Placement::TOP_RIGHT ) ) { // Content placed at Top m_horizontal_scrollbar->SetAllocation( sf::FloatRect( - m_content_allocation.left - border_width, - m_content_allocation.height + 2.f * border_width + scrollbar_spacing, - m_content_allocation.width + 2.f * border_width, - m_horizontal_scrollbar->GetRequisition().y + { m_content_allocation.position.x - border_width, m_content_allocation.size.y + 2.f * border_width + scrollbar_spacing }, + { m_content_allocation.size.x + 2.f * border_width, m_horizontal_scrollbar->GetRequisition().y } ) ); } else { // Content placed at Bottom m_horizontal_scrollbar->SetAllocation( sf::FloatRect( - m_content_allocation.left - border_width, - 0.f, - m_content_allocation.width + 2.f * border_width, - m_horizontal_scrollbar->GetRequisition().y + { m_content_allocation.position.x - border_width, 0.f }, + { m_content_allocation.size.x + 2.f * border_width, m_horizontal_scrollbar->GetRequisition().y } ) ); } @@ -247,31 +243,27 @@ void ScrolledWindow::RecalculateContentAllocation() const { if( ( m_placement == Placement::TOP_LEFT ) || ( m_placement == Placement::BOTTOM_LEFT ) ) { // Content placed at Left m_vertical_scrollbar->SetAllocation( sf::FloatRect( - m_content_allocation.width + 2.f * border_width + scrollbar_spacing, - m_content_allocation.top - border_width, - m_vertical_scrollbar->GetRequisition().x, - m_content_allocation.height + 2.f * border_width + { m_content_allocation.size.x + 2.f * border_width + scrollbar_spacing, m_content_allocation.position.y - border_width }, + { m_vertical_scrollbar->GetRequisition().x, m_content_allocation.size.y + 2.f * border_width } ) ); } else { // Content placed at Right m_vertical_scrollbar->SetAllocation( sf::FloatRect( - 0.f, - m_content_allocation.top - border_width, - m_vertical_scrollbar->GetRequisition().x, - m_content_allocation.height + 2.f * border_width + { 0.f, m_content_allocation.position.y - border_width }, + { m_vertical_scrollbar->GetRequisition().x, m_content_allocation.size.y + 2.f * border_width } ) ); } // Update Scrollbars and viewport allocation if the content allocation changed. if( GetViewport() ) { - m_horizontal_scrollbar->GetAdjustment()->SetMajorStep( m_content_allocation.width ); - m_horizontal_scrollbar->GetAdjustment()->SetPageSize( m_content_allocation.width ); + m_horizontal_scrollbar->GetAdjustment()->SetMajorStep( m_content_allocation.size.x ); + m_horizontal_scrollbar->GetAdjustment()->SetPageSize( m_content_allocation.size.x ); - m_vertical_scrollbar->GetAdjustment()->SetMajorStep( m_content_allocation.height ); - m_vertical_scrollbar->GetAdjustment()->SetPageSize( m_content_allocation.height ); + m_vertical_scrollbar->GetAdjustment()->SetMajorStep( m_content_allocation.size.y ); + m_vertical_scrollbar->GetAdjustment()->SetPageSize( m_content_allocation.size.y ); GetViewport()->SetAllocation( m_content_allocation ); } @@ -335,8 +327,8 @@ void ScrolledWindow::AddWithViewport( Widget::Ptr widget ) { // Make sure the viewport is offset by the border width. sf::FloatRect allocation( m_viewport->GetAllocation() ); - allocation.left += border_width; - allocation.top += border_width; + allocation.position.x += border_width; + allocation.position.y += border_width; m_viewport->SetAllocation( allocation ); } diff --git a/src/SFGUI/Selector.cpp b/src/SFGUI/Selector.cpp index 0799271d..65924639 100644 --- a/src/SFGUI/Selector.cpp +++ b/src/SFGUI/Selector.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace sfg { Selector::Selector() : @@ -190,8 +192,8 @@ bool Selector::Matches( Widget::PtrConst widget ) const { // Recursion is your friend ;) // Check if current stage is a pass... - if( ( !m_widget.compare("*") && m_id.empty() && m_class.empty() && !m_state ) || // Wildcard - ( ( m_widget.empty() || !m_widget.compare("*") || m_widget == widget->GetName() ) && // + if( ( !m_widget.compare( "*" ) && m_id.empty() && m_class.empty() && !m_state ) || // Wildcard + ( ( m_widget.empty() || !m_widget.compare( "*" ) || m_widget == widget->GetName() ) && // ( m_id.empty() || m_id == widget->GetId() ) && // Selector and widget match ( m_class.empty() || m_class == widget->GetClass() ) && // ( !m_state || *m_state == widget->GetState() ) ) ) { // diff --git a/src/SFGUI/SpinButton.cpp b/src/SFGUI/SpinButton.cpp index 4b48117d..f4694564 100644 --- a/src/SFGUI/SpinButton.cpp +++ b/src/SFGUI/SpinButton.cpp @@ -76,22 +76,21 @@ void SpinButton::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, i float border_width( Context::Get().GetEngine().GetProperty( "BorderWidth", shared_from_this() ) ); float stepper_aspect_ratio( Context::Get().GetEngine().GetProperty( "StepperAspectRatio", shared_from_this() ) ); - if( button != sf::Mouse::Left ) { + if( button != sf::Mouse::Button::Left ) { return; } - auto stepper_height = ( GetAllocation().height / 2.f ) - border_width; - auto stepper_width = ( GetAllocation().height / 2.f ) * stepper_aspect_ratio; + auto stepper_height = ( GetAllocation().size.y / 2.f ) - border_width; + auto stepper_width = ( GetAllocation().size.y / 2.f ) * stepper_aspect_ratio; if( press ) { // Top stepper. sf::FloatRect rect; - rect.left = GetAllocation().left + GetAllocation().width - border_width - stepper_width; - rect.top = GetAllocation().top + border_width; - rect.width = stepper_width; - rect.height = stepper_height; + rect.position.x = GetAllocation().position.x + GetAllocation().size.x - border_width - stepper_width; + rect.position.y = GetAllocation().position.y + border_width; + rect.size = {stepper_width, stepper_height}; - if( rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { GrabFocus( Widget::Ptr() ); m_adjustment->Increment(); @@ -105,9 +104,9 @@ void SpinButton::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, i } // Bottom stepper. - rect.top = GetAllocation().top + border_width + stepper_height; + rect.position.y = GetAllocation().position.y + border_width + stepper_height; - if( rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { GrabFocus( Widget::Ptr() ); m_adjustment->Decrement(); @@ -144,7 +143,7 @@ void SpinButton::HandleUpdate( float seconds ) { } if( m_repeat_wait ) { - sf::Uint32 stepper_repeat_delay( Context::Get().GetEngine().GetProperty( "StepperRepeatDelay", shared_from_this() ) ); + std::uint32_t stepper_repeat_delay( Context::Get().GetEngine().GetProperty( "StepperRepeatDelay", shared_from_this() ) ); if( m_elapsed_time < ( static_cast( stepper_repeat_delay ) / 1000.f ) ) { return; @@ -166,7 +165,7 @@ void SpinButton::HandleUpdate( float seconds ) { } } -void SpinButton::HandleTextEvent( sf::Uint32 character ) { +void SpinButton::HandleTextEvent( char32_t character ) { if( isdigit( static_cast( character ) ) ) { Entry::HandleTextEvent( character ); return; @@ -183,14 +182,14 @@ void SpinButton::HandleTextEvent( sf::Uint32 character ) { } } -void SpinButton::HandleKeyEvent( sf::Keyboard::Key key, bool press ) { - Entry::HandleKeyEvent( key, press ); +void SpinButton::HandleKeyEvent( sf::Keyboard::Key key, sf::Keyboard::Scancode scancode, bool press ) { + Entry::HandleKeyEvent( key, scancode, press ); if( !press || !HasFocus() ) { return; } - if( key == sf::Keyboard::Return ) { + if( scancode == sf::Keyboard::Scancode::Enter ) { GrabFocus( Widget::Ptr() ); } } @@ -198,7 +197,7 @@ void SpinButton::HandleKeyEvent( sf::Keyboard::Key key, bool press ) { void SpinButton::HandleSizeChange() { float stepper_aspect_ratio( Context::Get().GetEngine().GetProperty( "StepperAspectRatio", shared_from_this() ) ); - SetTextMargin( GetAllocation().height / 2.f * stepper_aspect_ratio ); + SetTextMargin( GetAllocation().size.y / 2.f * stepper_aspect_ratio ); Entry::HandleSizeChange(); } diff --git a/src/SFGUI/Table.cpp b/src/SFGUI/Table.cpp index 810298db..f26bb6d6 100644 --- a/src/SFGUI/Table.cpp +++ b/src/SFGUI/Table.cpp @@ -30,18 +30,18 @@ sf::Vector2f Table::CalculateRequisition() { return size; } -void Table::Attach( Widget::Ptr widget, const sf::Rect& rect, int x_options, int y_options, const sf::Vector2f& padding ) { - assert( rect.width > 0 ); - assert( rect.height > 0 ); +void Table::Attach( Widget::Ptr widget, const sf::Rect& rect, int x_options, int y_options, const sf::Vector2f& padding ) { + assert( rect.size.x > 0 ); + assert( rect.size.y > 0 ); // Store widget in a table cell object. priv::TableCell cell( widget, rect, x_options, y_options, padding ); m_cells.push_back( cell ); // Check if we need to enlarge rows/columns. - if( rect.left + rect.width >= m_columns.size() ) { + if( rect.position.x + rect.size.x >= m_columns.size() ) { std::size_t old_size( m_columns.size() ); - m_columns.resize( rect.left + rect.width ); + m_columns.resize( rect.position.x + rect.size.x ); // Set default spacings. for( std::size_t col_index = old_size; col_index < m_columns.size(); ++col_index ) { @@ -49,9 +49,9 @@ void Table::Attach( Widget::Ptr widget, const sf::Rect& rect, int x_ } } - if( rect.top + rect.height >= m_rows.size() ) { + if( rect.position.y + rect.size.y >= m_rows.size() ) { std::size_t old_size( m_rows.size() ); - m_rows.resize( rect.top + rect.height ); + m_rows.resize( rect.position.y + rect.size.y ); // Set default spacings. for( std::size_t row_index = old_size; row_index < m_rows.size(); ++row_index ) { @@ -87,10 +87,10 @@ void Table::UpdateRequisitions() { // Iterate over children and add requisitions to columns and rows. for( const auto& cell : m_cells ) { - auto col_requisition = cell.child->GetRequisition().x / static_cast( cell.rect.width ) + 2 * cell.padding.x; - auto col_bound = cell.rect.left + cell.rect.width; + auto col_requisition = cell.child->GetRequisition().x / static_cast( cell.rect.size.x ) + 2 * cell.padding.x; + auto col_bound = cell.rect.position.x + cell.rect.size.x; - for( sf::Uint32 col_idx = cell.rect.left; col_idx < col_bound; ++col_idx ) { + for( std::uint32_t col_idx = cell.rect.position.x; col_idx < col_bound; ++col_idx ) { m_columns[col_idx].requisition = std::max( m_columns[col_idx].requisition, col_requisition + (col_idx + 1 < m_columns.size() ? m_columns[col_idx].spacing : 0) // Add spacing if not last column. @@ -102,10 +102,10 @@ void Table::UpdateRequisitions() { } } - auto row_requisition = cell.child->GetRequisition().y / static_cast( cell.rect.height ) + 2 * cell.padding.y; - auto row_bound = cell.rect.top + cell.rect.height; + auto row_requisition = cell.child->GetRequisition().y / static_cast( cell.rect.size.y ) + 2 * cell.padding.y; + auto row_bound = cell.rect.position.y + cell.rect.size.y; - for( sf::Uint32 row_idx = cell.rect.top; row_idx < row_bound; ++row_idx ) { + for( std::uint32_t row_idx = cell.rect.position.y; row_idx < row_bound; ++row_idx ) { m_rows[row_idx].requisition = std::max( m_rows[row_idx].requisition, row_requisition + (row_idx + 1 < m_rows.size() ? m_rows[row_idx].spacing : 0) // Add spacing if not last row. @@ -128,7 +128,7 @@ void Table::AllocateChildren() { ); // Calculate column allocations. - auto total_width = GetAllocation().width - 2 * gap; + auto total_width = GetAllocation().size.x - 2 * gap; std::size_t num_expand = 0; // First step is counting number of expandable columns and setting allocation @@ -162,7 +162,7 @@ void Table::AllocateChildren() { } // Calculate row allocations. - auto total_height = 2 * gap + GetAllocation().height; + auto total_height = 2 * gap + GetAllocation().size.y; num_expand = 0; // First step is counting number of expandable rows and setting allocation @@ -200,39 +200,37 @@ void Table::AllocateChildren() { for( const auto& cell : m_cells ) { sf::FloatRect allocation( - m_columns[cell.rect.left].position, - m_rows[cell.rect.top].position, - 0, - 0 + { m_columns[cell.rect.position.x].position, m_rows[cell.rect.position.y].position }, + { 0, 0 } ); - bound = cell.rect.left + cell.rect.width; + bound = cell.rect.position.x + cell.rect.size.x; - for( std::size_t col_idx = cell.rect.left; col_idx < bound; ++col_idx ) { - allocation.width += m_columns[col_idx].allocation; + for( std::size_t col_idx = cell.rect.position.x; col_idx < bound; ++col_idx ) { + allocation.size.x += m_columns[col_idx].allocation; if( col_idx + 1 == bound && col_idx + 1 < m_columns.size() ) { - allocation.width -= m_columns[col_idx].spacing; + allocation.size.x -= m_columns[col_idx].spacing; } } - bound = cell.rect.top + cell.rect.height; + bound = cell.rect.position.y + cell.rect.size.y; - for( std::size_t row_idx = cell.rect.top; row_idx < bound; ++row_idx ) { - allocation.height += m_rows[row_idx].allocation; + for( std::size_t row_idx = cell.rect.position.y; row_idx < bound; ++row_idx ) { + allocation.size.y += m_rows[row_idx].allocation; if( row_idx + 1 == bound && row_idx + 1 < m_rows.size() ) { - allocation.height -= m_rows[row_idx].spacing; + allocation.size.y -= m_rows[row_idx].spacing; } } // Limit size if FILL is not set. if( (cell.x_options & FILL) != FILL ) { - allocation.width = std::min( allocation.width, cell.child->GetRequisition().x ); + allocation.size.x = std::min( allocation.size.x, cell.child->GetRequisition().x ); } if( (cell.y_options & FILL) != FILL ) { - allocation.height = std::min( allocation.height, cell.child->GetRequisition().y ); + allocation.size.y = std::min( allocation.size.y, cell.child->GetRequisition().y ); } cell.child->SetAllocation( allocation ); diff --git a/src/SFGUI/TableCell.cpp b/src/SFGUI/TableCell.cpp index 94f5eebd..a6dad724 100644 --- a/src/SFGUI/TableCell.cpp +++ b/src/SFGUI/TableCell.cpp @@ -4,7 +4,7 @@ namespace sfg { namespace priv { -TableCell::TableCell( Widget::Ptr child_, const sf::Rect& rect_, int x_options_, int y_options_, const sf::Vector2f& padding_ ) : +TableCell::TableCell( Widget::Ptr child_, const sf::Rect& rect_, int x_options_, int y_options_, const sf::Vector2f& padding_ ) : child( child_ ), rect( rect_ ), x_options( x_options_ ), diff --git a/src/SFGUI/ToggleButton.cpp b/src/SFGUI/ToggleButton.cpp index 0fbea395..ac032968 100644 --- a/src/SFGUI/ToggleButton.cpp +++ b/src/SFGUI/ToggleButton.cpp @@ -55,7 +55,7 @@ bool ToggleButton::IsActive() const { } void ToggleButton::HandleMouseClick( sf::Mouse::Button button, int x, int y ) { - if( button == sf::Mouse::Left ) { + if( button == sf::Mouse::Button::Left ) { SetActive( !IsActive() ); } diff --git a/src/SFGUI/Viewport.cpp b/src/SFGUI/Viewport.cpp index 45958f7b..511e51ad 100644 --- a/src/SFGUI/Viewport.cpp +++ b/src/SFGUI/Viewport.cpp @@ -49,8 +49,8 @@ void Viewport::HandleSizeChange() { m_children_viewport->SetSize( sf::Vector2f( - std::floor( allocation.width + .5f ), - std::floor( allocation.height + .5f ) + std::floor( allocation.size.x + .5f ), + std::floor( allocation.size.y + .5f ) ) ); } @@ -78,58 +78,57 @@ void Viewport::HandleEvent( const sf::Event& event ) { // Pass event to child if( GetChild() ) { - auto offset_x = ( -GetAllocation().left + m_horizontal_adjustment->GetValue() ); - auto offset_y = ( -GetAllocation().top + m_vertical_adjustment->GetValue() ); - - switch( event.type ) { - case sf::Event::MouseButtonPressed: - case sf::Event::MouseButtonReleased: { // All MouseButton events - if( !GetAllocation().contains( static_cast( event.mouseButton.x ), static_cast( event.mouseButton.y ) ) ) { - break; + auto offset_x = ( -GetAllocation().position.x + m_horizontal_adjustment->GetValue() ); + auto offset_y = ( -GetAllocation().position.y + m_vertical_adjustment->GetValue() ); + + const auto onMouseButtonPressedOrRelease = [&]( const auto& mouseBottonEvent ) { + if( !GetAllocation().contains( sf::Vector2f( mouseBottonEvent.position ) ) ) { + return; } - sf::Event altered_event( event ); - altered_event.mouseButton.x += static_cast( offset_x ); - altered_event.mouseButton.y += static_cast( offset_y ); + auto altered_event = mouseBottonEvent; + altered_event.position.x += static_cast( offset_x ); + altered_event.position.y += static_cast( offset_y ); GetChild()->HandleEvent( altered_event ); - } break; - case sf::Event::MouseLeft: { - // Nice hack to cause scrolledwindow children to get out of - // prelight state when the mouse leaves the child allocation. - sf::Event altered_event( event ); - altered_event.mouseMove.x = -1; - altered_event.mouseMove.y = -1; - GetChild()->HandleEvent( altered_event ); - } break; - case sf::Event::MouseMoved: { // All MouseMove events - sf::Event altered_event( event ); - if( !GetAllocation().contains( static_cast( event.mouseMove.x ), static_cast( event.mouseMove.y ) ) ) { + }; + + if( const auto* mouseButtonPressed = event.getIf() ) { + onMouseButtonPressedOrRelease( *mouseButtonPressed ); + } + else if( const auto* mouseButtonReleased = event.getIf() ) { + onMouseButtonPressedOrRelease( *mouseButtonReleased ); + } + else if( const auto* mouseLeft = event.getIf() ) { + GetChild()->HandleEvent( *mouseLeft ); + } + else if( const auto* mouseMoved = event.getIf() ) { // All MouseMove events + auto altered_event = *mouseMoved; + if( !GetAllocation().contains( sf::Vector2f( mouseMoved->position ) ) ) { // Nice hack to cause scrolledwindow children to get out of // prelight state when the mouse leaves the child allocation. - altered_event.mouseMove.x = -1; - altered_event.mouseMove.y = -1; + altered_event.position.x = -1; + altered_event.position.y = -1; } else { - altered_event.mouseMove.x += static_cast( offset_x ); - altered_event.mouseMove.y += static_cast( offset_y ); + altered_event.position.x += static_cast( offset_x ); + altered_event.position.y += static_cast( offset_y ); } GetChild()->HandleEvent( altered_event ); - } break; - case sf::Event::MouseWheelMoved: { // All MouseWheel events - if( !GetAllocation().contains( static_cast( event.mouseWheel.x ), static_cast( event.mouseWheel.y ) ) ) { - break; + } + else if( const auto* mouseWheelScrolled = event.getIf() ) { // All MouseWheel events + if( !GetAllocation().contains( sf::Vector2f( mouseWheelScrolled->position ) ) ) { + return; } - sf::Event altered_event( event ); - altered_event.mouseWheel.x += static_cast( offset_x ); - altered_event.mouseWheel.y += static_cast( offset_y ); + auto altered_event = *mouseWheelScrolled; + altered_event.position.x += static_cast( offset_x ); + altered_event.position.y += static_cast( offset_y ); GetChild()->HandleEvent( altered_event ); - } break; - default: { // Pass event unaltered if it is a non-mouse event + } + else { // Pass event unaltered if it is a non-mouse event GetChild()->HandleEvent( event ); - } break; } } } @@ -203,8 +202,8 @@ void Viewport::HandleRequisitionChange() { // and have a virtual screen we give it everything it wants. if( GetChild() ) { auto new_allocation = GetChild()->GetAllocation(); - new_allocation.width = GetChild()->GetRequisition().x; - new_allocation.height = GetChild()->GetRequisition().y; + new_allocation.size.x = GetChild()->GetRequisition().x; + new_allocation.size.y = GetChild()->GetRequisition().y; GetChild()->SetAllocation( new_allocation ); } } diff --git a/src/SFGUI/Widget.cpp b/src/SFGUI/Widget.cpp index 3a25ca2e..ec957ce9 100644 --- a/src/SFGUI/Widget.cpp +++ b/src/SFGUI/Widget.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -125,27 +126,27 @@ void Widget::SetAllocation( const sf::FloatRect& rect ) { sf::FloatRect oldallocation( m_allocation ); // Make sure allocation is pixel-aligned. - m_allocation.left = std::floor( rect.left + .5f ); - m_allocation.top = std::floor( rect.top + .5f ); - m_allocation.width = std::floor( rect.width + .5f ); - m_allocation.height = std::floor( rect.height + .5f ); + m_allocation.position.x = std::floor( rect.position.x + .5f ); + m_allocation.position.y = std::floor( rect.position.y + .5f ); + m_allocation.size.x = std::floor( rect.size.x + .5f ); + m_allocation.size.y = std::floor( rect.size.y + .5f ); if( - oldallocation.top == m_allocation.top && - oldallocation.left == m_allocation.left && - oldallocation.width == m_allocation.width && - oldallocation.height == m_allocation.height + oldallocation.position.y == m_allocation.position.y && + oldallocation.position.x == m_allocation.position.x && + oldallocation.size.x == m_allocation.size.x && + oldallocation.size.y == m_allocation.size.y ) { // Nothing even changed. Save the hierarchy the trouble. return; } - if( ( oldallocation.top != m_allocation.top ) || ( oldallocation.left != m_allocation.left ) ) { + if( ( oldallocation.position.y != m_allocation.position.y ) || ( oldallocation.position.x != m_allocation.position.x ) ) { HandlePositionChange(); HandleAbsolutePositionChange(); } - if( ( oldallocation.width != m_allocation.width ) || ( oldallocation.height != m_allocation.height ) ) { + if( ( oldallocation.size.x != m_allocation.size.x ) || ( oldallocation.size.y != m_allocation.size.y ) ) { HandleSizeChange(); Invalidate(); @@ -179,10 +180,8 @@ void Widget::RequestResize() { } else { sf::FloatRect allocation( - GetAllocation().left, - GetAllocation().top, - std::max( GetAllocation().width, m_requisition.x ), - std::max( GetAllocation().height, m_requisition.y ) + GetAllocation().position, + { std::max( GetAllocation().size.x, m_requisition.x ), std::max( GetAllocation().size.y, m_requisition.y ) } ); SetAllocation( allocation ); @@ -278,10 +277,10 @@ void Widget::SetPosition( const sf::Vector2f& position ) { sf::FloatRect allocation( GetAllocation() ); // Make sure allocation is pixel-aligned. - m_allocation.left = std::floor( position.x + .5f ); - m_allocation.top = std::floor( position.y + .5f ); + m_allocation.position.x = std::floor( position.x + .5f ); + m_allocation.position.y = std::floor( position.y + .5f ); - if( ( allocation.top != m_allocation.top ) || ( allocation.left != m_allocation.left ) ) { + if( ( allocation.position.y != m_allocation.position.y ) || ( allocation.position.x != m_allocation.position.x ) ) { HandlePositionChange(); HandleAbsolutePositionChange(); } @@ -319,148 +318,132 @@ void Widget::HandleEvent( const sf::Event& event ) { auto emit_right_click = false; try { - switch( event.type ) { - case sf::Event::MouseLeft: - if( IsMouseInWidget() ) { - SetMouseInWidget( false ); - - HandleMouseLeave( std::numeric_limits::min(), std::numeric_limits::min() ); - - emit_leave = true; - } - - HandleMouseMoveEvent( std::numeric_limits::min(), std::numeric_limits::min() ); - - SetMouseButtonDown(); - HandleMouseButtonEvent( sf::Mouse::Left, false, std::numeric_limits::min(), std::numeric_limits::min() ); - HandleMouseButtonEvent( sf::Mouse::Right, false, std::numeric_limits::min(), std::numeric_limits::min() ); + if( event.is() ) { + if( IsMouseInWidget() ) { + SetMouseInWidget( false ); - if( emit_leave ) { - GetSignals().Emit( OnMouseLeave ); - } - - break; + HandleMouseLeave( std::numeric_limits::min(), std::numeric_limits::min() ); - case sf::Event::MouseMoved: - // Check if pointer inside of widget's allocation. - if( GetAllocation().contains( static_cast( event.mouseMove.x ), static_cast( event.mouseMove.y ) ) ) { - // Check for enter event. - if( !IsMouseInWidget() ) { - SetMouseInWidget( true ); + emit_leave = true; + } - emit_enter = true; + HandleMouseMoveEvent( std::numeric_limits::min(), std::numeric_limits::min() ); - HandleMouseEnter( event.mouseMove.x, event.mouseMove.y ); - } + SetMouseButtonDown(); + HandleMouseButtonEvent( sf::Mouse::Button::Left, false, std::numeric_limits::min(), std::numeric_limits::min() ); + HandleMouseButtonEvent( sf::Mouse::Button::Right, false, std::numeric_limits::min(), std::numeric_limits::min() ); - emit_move = true; - } - else if( IsMouseInWidget() ) { // Check for leave event. - SetMouseInWidget( false ); + if( emit_leave ) { + GetSignals().Emit( OnMouseLeave ); + } + } + else if( const auto* mouseMoved = event.getIf() ) { + // Check if pointer inside of widget's allocation. + if( GetAllocation().contains( sf::Vector2f( mouseMoved->position ) ) ) { + // Check for enter event. + if( !IsMouseInWidget() ) { + SetMouseInWidget( true ); - emit_leave = true; + emit_enter = true; - HandleMouseLeave( event.mouseMove.x, event.mouseMove.y ); + HandleMouseEnter( mouseMoved->position.x, mouseMoved->position.y ); } - HandleMouseMoveEvent( event.mouseMove.x, event.mouseMove.y ); - - if( emit_move ) { - if( emit_enter ) { - GetSignals().Emit( OnMouseEnter ); - } - - GetSignals().Emit( OnMouseMove ); - } - else if( emit_leave ) { - GetSignals().Emit( OnMouseLeave ); - } + emit_move = true; + } + else if( IsMouseInWidget() ) { // Check for leave event. + SetMouseInWidget( false ); - break; + emit_leave = true; - case sf::Event::MouseButtonPressed: - if( !IsMouseButtonDown() && IsMouseInWidget() ) { - SetMouseButtonDown( event.mouseButton.button ); - } + HandleMouseLeave( mouseMoved->position.x, mouseMoved->position.y ); + } - HandleMouseButtonEvent( event.mouseButton.button, true, event.mouseButton.x, event.mouseButton.y ); + HandleMouseMoveEvent( mouseMoved->position.x, mouseMoved->position.y ); - if( IsMouseInWidget() ) { - if( event.mouseButton.button == sf::Mouse::Left ) { - GetSignals().Emit( OnMouseLeftPress ); - } - else if( event.mouseButton.button == sf::Mouse::Right ) { - GetSignals().Emit( OnMouseRightPress ); - } + if( emit_move ) { + if( emit_enter ) { + GetSignals().Emit( OnMouseEnter ); } - break; - - case sf::Event::MouseButtonReleased: - // Only process as a click when mouse button has been pressed inside the widget before. - if( IsMouseButtonDown( event.mouseButton.button ) ) { - SetMouseButtonDown(); - - // When released inside the widget, the event can be considered a click. - if( IsMouseInWidget() ) { - HandleMouseClick( event.mouseButton.button, event.mouseButton.x, event.mouseButton.y ); - - if( event.mouseButton.button == sf::Mouse::Left ) { - emit_left_click = true; - } - else if( event.mouseButton.button == sf::Mouse::Right ) { - emit_right_click = true; - } - } - } + GetSignals().Emit( OnMouseMove ); + } + else if( emit_leave ) { + GetSignals().Emit( OnMouseLeave ); + } + } + else if( const auto* mouseButtonPressed = event.getIf() ) { + if( !IsMouseButtonDown() && IsMouseInWidget() ) { + SetMouseButtonDown( mouseButtonPressed->button ); + } - HandleMouseButtonEvent( event.mouseButton.button, false, event.mouseButton.x, event.mouseButton.y ); + HandleMouseButtonEvent( mouseButtonPressed->button, true, mouseButtonPressed->position.x, mouseButtonPressed->position.y ); - if( emit_left_click ) { - GetSignals().Emit( OnLeftClick ); + if( IsMouseInWidget() ) { + if( mouseButtonPressed->button == sf::Mouse::Button::Left ) { + GetSignals().Emit( OnMouseLeftPress ); } - else if( emit_right_click ) { - GetSignals().Emit( OnRightClick ); + else if( mouseButtonPressed->button == sf::Mouse::Button::Right ) { + GetSignals().Emit( OnMouseRightPress ); } + } + } + else if( const auto* mouseButtonReleased = event.getIf() ) { + // Only process as a click when mouse button has been pressed inside the widget before. + if( IsMouseButtonDown( mouseButtonReleased->button ) ) { + SetMouseButtonDown(); + // When released inside the widget, the event can be considered a click. if( IsMouseInWidget() ) { - if( event.mouseButton.button == sf::Mouse::Left ) { - GetSignals().Emit( OnMouseLeftRelease ); + HandleMouseClick( mouseButtonReleased->button, mouseButtonReleased->position.x, mouseButtonReleased->position.y ); + + if( mouseButtonReleased->button == sf::Mouse::Button::Left ) { + emit_left_click = true; } - else if( event.mouseButton.button == sf::Mouse::Right ) { - GetSignals().Emit( OnMouseRightRelease ); + else if( mouseButtonReleased->button == sf::Mouse::Button::Right ) { + emit_right_click = true; } } + } - break; - - case sf::Event::KeyPressed: - if( HasFocus() ) { - // TODO: Delegate event too when widget's not active? - HandleKeyEvent( event.key.code, true ); - GetSignals().Emit( OnKeyPress ); - } + HandleMouseButtonEvent( mouseButtonReleased->button, false, mouseButtonReleased->position.x, mouseButtonReleased->position.y ); - break; + if( emit_left_click ) { + GetSignals().Emit( OnLeftClick ); + } + else if( emit_right_click ) { + GetSignals().Emit( OnRightClick ); + } - case sf::Event::KeyReleased: - if( HasFocus() ) { - // TODO: Delegate event too when widget's not active? - HandleKeyEvent( event.key.code, false ); - GetSignals().Emit( OnKeyRelease ); + if( IsMouseInWidget() ) { + if( mouseButtonReleased->button == sf::Mouse::Button::Left ) { + GetSignals().Emit( OnMouseLeftRelease ); } - break; - - case sf::Event::TextEntered: - if( HasFocus() ) { - // TODO: Delegate event too when widget's not active? - HandleTextEvent( event.text.unicode ); - GetSignals().Emit( OnText ); + else if( mouseButtonReleased->button == sf::Mouse::Button::Right ) { + GetSignals().Emit( OnMouseRightRelease ); } - break; - - default: - break; + } + } + else if( const auto* keyPressed = event.getIf() ) { + if( HasFocus() ) { + // TODO: Delegate event too when widget's not active? + HandleKeyEvent( keyPressed->code, keyPressed->scancode, true ); + GetSignals().Emit( OnKeyPress ); + } + } + else if( const auto* keyReleased = event.getIf() ) { + if( HasFocus() ) { + // TODO: Delegate event too when widget's not active? + HandleKeyEvent( keyReleased->code, keyReleased->scancode, false ); + GetSignals().Emit( OnKeyRelease ); + } + } + else if( const auto* textEntered = event.getIf() ) { + if( HasFocus() ) { + // TODO: Delegate event too when widget's not active? + HandleTextEvent( textEntered->unicode ); + GetSignals().Emit( OnText ); + } } } catch( ... ) { @@ -530,18 +513,23 @@ void Widget::SetMouseInWidget( bool in_widget ) { m_mouse_in = in_widget; } -bool Widget::IsMouseButtonDown( sf::Mouse::Button button ) const { +bool Widget::IsMouseButtonDown( std::optional button ) const { // Check if any button is down if requested. - if( button == sf::Mouse::ButtonCount ) { + if( !button.has_value() ) { return m_mouse_button_down != sf::Mouse::ButtonCount; } // Check if requested button is down. - return m_mouse_button_down == button; + return static_cast(m_mouse_button_down) == button; } -void Widget::SetMouseButtonDown( sf::Mouse::Button button ) { - m_mouse_button_down = static_cast( button & 0x3f ); // 6 bits +void Widget::SetMouseButtonDown( std::optional button ) { + if( button.has_value() ) { + m_mouse_button_down = static_cast( static_cast(*button) & 0x3f ); // 6 bits + } + else { + m_mouse_button_down = sf::Mouse::ButtonCount; + } } void Widget::Show( bool show ) { @@ -583,15 +571,15 @@ sf::Vector2f Widget::GetAbsolutePosition() const { PtrConst parent( m_parent.lock() ); if( !parent ) { - return sf::Vector2f( GetAllocation().left, GetAllocation().top ); + return sf::Vector2f( GetAllocation().position.x, GetAllocation().position.y ); } // Get parent's absolute position and add own rel. position to it. sf::Vector2f parent_position( parent->GetAbsolutePosition() ); return sf::Vector2f( - parent_position.x + GetAllocation().left, - parent_position.y + GetAllocation().top + parent_position.x + GetAllocation().position.x, + parent_position.y + GetAllocation().position.y ); } @@ -751,7 +739,7 @@ void Widget::HandleMouseMoveEvent( int /*x*/, int /*y*/ ) { void Widget::HandleMouseButtonEvent( sf::Mouse::Button /*button*/, bool /*press*/, int /*x*/, int /*y*/ ) { } -void Widget::HandleKeyEvent( sf::Keyboard::Key /*key*/, bool /*press*/ ) { +void Widget::HandleKeyEvent( sf::Keyboard::Key /*key*/, sf::Keyboard::Scancode /*scancode*/, bool /*press*/ ) { } void Widget::HandlePositionChange() { @@ -764,7 +752,7 @@ void Widget::HandleStateChange( State /*old_state*/ ) { Invalidate(); } -void Widget::HandleTextEvent( sf::Uint32 /*character*/ ) { +void Widget::HandleTextEvent( char32_t /*character*/ ) { } void Widget::HandleMouseEnter( int /*x*/, int /*y*/ ) { diff --git a/src/SFGUI/Window.cpp b/src/SFGUI/Window.cpp index 323fa837..159ffab3 100644 --- a/src/SFGUI/Window.cpp +++ b/src/SFGUI/Window.cpp @@ -43,14 +43,14 @@ const sf::String& Window::GetTitle() const { } sf::FloatRect Window::GetClientRect() const { - sf::FloatRect clientrect( 0, 0, GetAllocation().width, GetAllocation().height ); + sf::FloatRect clientrect( { 0, 0 }, { GetAllocation().size.x, GetAllocation().size.y } ); float border_width( Context::Get().GetEngine().GetProperty( "BorderWidth", shared_from_this() ) ); float gap( Context::Get().GetEngine().GetProperty( "Gap", shared_from_this() ) ); - clientrect.left += border_width + gap; - clientrect.top += border_width + gap; - clientrect.width -= 2 * border_width + 2 * gap; - clientrect.height -= 2 * border_width + 2 * gap; + clientrect.position.x += border_width + gap; + clientrect.position.y += border_width + gap; + clientrect.size.x -= 2 * border_width + 2 * gap; + clientrect.size.y -= 2 * border_width + 2 * gap; if( HasStyle( TITLEBAR ) ) { unsigned int title_font_size( Context::Get().GetEngine().GetProperty( "FontSize", shared_from_this() ) ); @@ -60,8 +60,8 @@ sf::FloatRect Window::GetClientRect() const { 2 * Context::Get().GetEngine().GetProperty( "TitlePadding", shared_from_this() ) ); - clientrect.top += title_height; - clientrect.height -= title_height; + clientrect.position.y += title_height; + clientrect.size.y -= title_height; } return clientrect; @@ -131,7 +131,7 @@ const std::string& Window::GetName() const { } void Window::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { - if( button != sf::Mouse::Left ) { + if( button != sf::Mouse::Button::Left ) { return; } @@ -150,13 +150,11 @@ void Window::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x // Check for mouse being inside the title area. sf::FloatRect area( - GetAllocation().left, - GetAllocation().top, - GetAllocation().width, - title_height + GetAllocation().position, + { GetAllocation().size.x, title_height } ); - if( area.contains( static_cast( x ), static_cast( y ) ) ) { + if( area.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { if( HasStyle( TITLEBAR ) && !m_dragging ) { if( HasStyle( CLOSE ) ) { auto close_height( Context::Get().GetEngine().GetProperty( "CloseHeight", shared_from_this() ) ); @@ -164,13 +162,11 @@ void Window::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x auto button_margin = ( title_height - close_height ) / 2.f; auto close_rect = sf::FloatRect( - GetAllocation().left + GetAllocation().width - button_margin - close_height, - GetAllocation().top + button_margin, - close_height, - close_height + { GetAllocation().position.x + GetAllocation().size.x - button_margin - close_height, GetAllocation().position.y + button_margin }, + { close_height, close_height } ); - if( close_rect.contains( static_cast( x ), static_cast( y ) ) ) { + if( close_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { GetSignals().Emit( OnCloseButton ); return; } @@ -180,26 +176,26 @@ void Window::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x m_resizing = false; m_drag_offset = sf::Vector2f( - static_cast( x ) - GetAllocation().left, - static_cast( y ) - GetAllocation().top + static_cast( x ) - GetAllocation().position.x, + static_cast( y ) - GetAllocation().position.y ); } } else { float handle_size( Context::Get().GetEngine().GetProperty( "HandleSize", shared_from_this() ) ); - area.left = GetAllocation().left + GetAllocation().width - handle_size; - area.top = GetAllocation().top + GetAllocation().height - handle_size; - area.width = handle_size; - area.height = handle_size; + area.position.x = GetAllocation().position.x + GetAllocation().size.x - handle_size; + area.position.y = GetAllocation().position.y + GetAllocation().size.y - handle_size; + area.size.x = handle_size; + area.size.y = handle_size; - if( area.contains( static_cast( x ), static_cast( y ) ) ) { + if( area.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { m_dragging = false; m_resizing = true; m_drag_offset = sf::Vector2f( - handle_size - static_cast( x ) + GetAllocation().left + GetAllocation().width - handle_size, - handle_size - static_cast( y ) + GetAllocation().top + GetAllocation().height - handle_size + handle_size - static_cast( x ) + GetAllocation().position.x + GetAllocation().size.x - handle_size, + handle_size - static_cast( y ) + GetAllocation().position.y + GetAllocation().size.y - handle_size ); } } @@ -222,10 +218,9 @@ void Window::HandleMouseMoveEvent( int x, int y ) { else if( m_resizing && (GetStyle() & RESIZE) == RESIZE ) { SetAllocation( sf::FloatRect( - GetAllocation().left, - GetAllocation().top, - std::max( GetRequisition().x, static_cast( x ) + m_drag_offset.x - GetAllocation().left ), - std::max( GetRequisition().y, static_cast( y ) + m_drag_offset.y - GetAllocation().top ) + GetAllocation().position, + { std::max( GetRequisition().x, static_cast( x ) + m_drag_offset.x - GetAllocation().position.x ), + std::max( GetRequisition().y, static_cast( y ) + m_drag_offset.y - GetAllocation().position.y ) } ) ); } @@ -237,7 +232,7 @@ bool Window::HandleAdd( Widget::Ptr child ) { } // Reset allocation so the window will be as large as required. - SetAllocation( sf::FloatRect( GetAllocation().left, GetAllocation().top, 1.f, 1.f ) ); + SetAllocation( sf::FloatRect( GetAllocation().position, { 1.f, 1.f } ) ); RequestResize(); return true;