Skip to content

Add sf::State for specifying fullscreen or floating windows#2818

Merged
ChrisThrasher merged 1 commit into
masterfrom
window_state
Jan 16, 2024
Merged

Add sf::State for specifying fullscreen or floating windows#2818
ChrisThrasher merged 1 commit into
masterfrom
window_state

Conversation

@ChrisThrasher
Copy link
Copy Markdown
Member

@ChrisThrasher ChrisThrasher commented Dec 10, 2023

Description

This is the first step towards implementing https://github.com/SFML/SFML/wiki/SD%3A-States-and-Styles

It converts Fullscreen from a Style to a State. While I was touching this code I fixed an inconsistency where sf::Styles were sometimes passed as a std::uint32_t and sometimes an unsigned long.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 10, 2023

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (ddb906a) 42.97% compared to head (9516a5e) 43.02%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2818      +/-   ##
==========================================
+ Coverage   42.97%   43.02%   +0.04%     
==========================================
  Files         252      252              
  Lines       21099    21113      +14     
  Branches     5172     5177       +5     
==========================================
+ Hits         9067     9083      +16     
+ Misses      11221    11093     -128     
- Partials      811      937     +126     
Files Coverage Δ
include/SFML/Graphics/RenderWindow.hpp 66.66% <ø> (ø)
include/SFML/Window/Window.hpp 0.00% <ø> (ø)
include/SFML/Window/WindowBase.hpp 0.00% <ø> (ø)
src/SFML/Window/EglContext.hpp 100.00% <ø> (ø)
src/SFML/Window/Unix/WindowImplX11.cpp 32.44% <100.00%> (+0.17%) ⬆️
src/SFML/Window/Win32/WindowImplWin32.cpp 25.39% <100.00%> (ø)
src/SFML/Window/Win32/WindowImplWin32.hpp 83.33% <ø> (ø)
src/SFML/Window/WindowImpl.cpp 27.53% <100.00%> (ø)
src/SFML/Window/WindowImpl.hpp 50.00% <ø> (ø)
src/SFML/Window/macOS/SFWindowController.mm 34.41% <100.00%> (ø)
... and 6 more

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ddb906a...9516a5e. Read the comment docs.

@ChrisThrasher ChrisThrasher marked this pull request as ready for review December 10, 2023 17:36
@ChrisThrasher
Copy link
Copy Markdown
Member Author

Exploiter and I talked about whether the order of style and state should be reversed. I put state after style for no particular reason. I'm not sure if one parameter order makes more sense than the other.

@ChrisThrasher ChrisThrasher force-pushed the window_state branch 2 times, most recently from 3326083 to c033e61 Compare December 12, 2023 00:20
@ChrisThrasher
Copy link
Copy Markdown
Member Author

Rebased on master. No changes made.

@MarioLiebisch
Copy link
Copy Markdown
Member

Exploiter and I talked about whether the order of style and state should be reversed. I put state after style for no particular reason. I'm not sure if one parameter order makes more sense than the other.

Since it's more likely you want to adjust style than state by default, I'd go with style first.

@eXpl0it3r
Copy link
Copy Markdown
Member

eXpl0it3r commented Dec 19, 2023

While I didn't fully realize or verbalize in the past discussion, I think the main issue is, that you currently have to set a style for fullscreen window, even though the fullscreen window won't have a style.
By reversing the order, you could switch to fullscreen without providing a style (if you don't need a context).
The issue might be slightly mitigated by providing dedicated functions to switch to fullscreen mode without recreating the window.

Currently asking myself if we just need another overload (VideoMode, Title, State = default, ContextSettings = default), which has the style set to the default style.

@Bromeon
Copy link
Copy Markdown
Member

Bromeon commented Dec 19, 2023

Maybe it goes a bit into off-topic (we can gladly discuss it somewhere else), but did we ever consider a fluent builder API for these lengthy constructors?

Instead of

sf::RenderWindow window(
    sf::VideoMode({800, 600}),
    "SFML graphics with OpenGL",
    sf::Style::Default,
    sf::State::Windowed,
    contextSettings);

we'd have

auto window = sf::RenderWindow::builder()
    .videoMode({800, 600})
    .title("SFML graphics with OpenGL")
    .state(sf::State::Windowed),
    .context(contextSettings)
    .build();
// no .style() needed if it's the default

It may be a bit unidiomatic for SFML, but it would solve the "anything can be default" problem. Would also allow overloads on a per-parameter basis, instead of providing a whole new constructor.

@ChrisThrasher
Copy link
Copy Markdown
Member Author

Rebased on master and fixed conflicts

@ChrisThrasher
Copy link
Copy Markdown
Member Author

ChrisThrasher commented Dec 24, 2023

I implemented addition constructor overloads that let users specify a state without specifying a style. While I was looking at the code I found some issues with the docs that needed correcting and added some missing tests so the PR is overall in a better state now.

I'm not sure if we can add extra create() overloads because when I tried that I got compiler errors about hiding base class virtual functions. At least we can add the constructors though.

@ChrisThrasher ChrisThrasher force-pushed the window_state branch 2 times, most recently from 3134b0e to de032bd Compare December 24, 2023 00:28
@ChrisThrasher ChrisThrasher force-pushed the window_state branch 2 times, most recently from 8962cd6 to b68dab2 Compare January 1, 2024 22:58
///
////////////////////////////////////////////////////////////
virtual void create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings);
virtual void create(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're screwing with the API anyway, I'd pull settings in front of style, so both style and state` can have defaults.

@ChrisThrasher
Copy link
Copy Markdown
Member Author

Periodic rebase on master. No changes made.

@ChrisThrasher
Copy link
Copy Markdown
Member Author

Added missing constructor overload to sf::RenderWindow so it matches the constructors that sf::Window and sf::WindowBase have.

@ChrisThrasher ChrisThrasher force-pushed the window_state branch 2 times, most recently from bb1d74b to 3d6e0c8 Compare January 16, 2024 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants