Compare commits

...

10 Commits

Author SHA1 Message Date
Chris Thrasher
910514871e Remove unnecessary CI step
clang-format is already installed in GitHub's Ubuntu image
2023-09-18 09:06:35 -06:00
Chris Thrasher
1b257c8ea8 Fix nested namespace name 2023-09-18 09:06:18 -06:00
Chris Thrasher
6b503a726d Use sf::String::toUtf8() 2023-09-17 17:18:14 -06:00
Chris Thrasher
9dc2e541e8 Add clang-tidy modernize-return-braced-init-list check 2023-09-17 15:47:33 -06:00
Chris Thrasher
434effd6a1 Fix awkward error phrasing 2023-09-17 13:21:40 -06:00
Chris Thrasher
f9e6f673dd Fix references to sf::WindowBase::setMouseCursor
This function does exist in sf::Window via inheritence but it's
more accurate to refer to the base implementation in sf::WindowBase
2023-09-17 13:01:37 -06:00
Chris Thrasher
d56e1838a0 Shallow clone Catch2
This takes a 4 second configuration time for the entire project with
examples and tests and turns that into 3! Whopping 25% reduction in
configuration time. This effect is likely to be even larger on machines
without exceptionally good internet connections.

Before:
  $ hyperfine 'rm -rf build && cmake --preset dev'
  Benchmark 1: rm -rf build && cmake --preset dev
    Time (mean ± σ):      4.076 s ±  0.130 s    [User: 2.148 s, System: 1.376 s]
    Range (min … max):    3.963 s …  4.321 s    10 runs

After:
  $ hyperfine 'rm -rf build && cmake --preset dev'
  Benchmark 1: rm -rf build && cmake --preset dev
    Time (mean ± σ):      3.007 s ±  0.313 s    [User: 1.061 s, System: 1.160 s]
    Range (min … max):    2.783 s …  3.805 s    10 runs

Co-authored-by: binary1248 <binary1248@hotmail.com>
2023-09-15 16:07:52 -06:00
Chris Thrasher
f6f95b03a5 Assert in-bounds access when using operator[]
Out of bounds array access is undefined behavior so let's be sure
to catch potential UB in debug builds. It's too easy to accidentally
provide an invalid index to one of these public APIs.
2023-09-13 16:48:50 -06:00
Chris Thrasher
d6079ce526 Reenable sf::Cursor tests
A fun thing about runDisplayTests() is that it means that the tests
won't get run in CI on the DRM code. Technically you can run the
display tests locally when buidling with DRM so these tests will
still fail under those circumstances. Regardless I think this is a
net positive to run the tests in CI.
2023-09-13 16:19:18 -06:00
Vittorio Romeo
5cfbf912c7 Do not ignore '[[nodiscard]]` functions in example code 2023-09-13 16:06:23 -06:00
45 changed files with 141 additions and 126 deletions

View File

@ -29,7 +29,6 @@ Checks: >
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-return-braced-init-list,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-inefficient-string-concatenation,

View File

@ -214,9 +214,6 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Dependencies
run: sudo apt-get install clang-format-14
- name: Format Code
run: cmake -DCLANG_FORMAT_EXECUTABLE=clang-format-14 -P cmake/Format.cmake

View File

@ -341,7 +341,7 @@ float getMoisture(unsigned int x, unsigned int y)
////////////////////////////////////////////////////////////
sf::Color colorFromFloats(float r, float g, float b)
{
return sf::Color(static_cast<std::uint8_t>(r), static_cast<std::uint8_t>(g), static_cast<std::uint8_t>(b));
return {static_cast<std::uint8_t>(r), static_cast<std::uint8_t>(g), static_cast<std::uint8_t>(b)};
}
sf::Color getLowlandsTerrainColor(float moisture)
@ -451,7 +451,7 @@ sf::Vector2f computeNormal(float left, float right, float bottom, float top)
crossProduct /= crossProduct.z;
// Return "compressed" normal
return sf::Vector2f(crossProduct.x, crossProduct.y);
return {crossProduct.x, crossProduct.y};
}

View File

@ -77,10 +77,10 @@ constexpr Color operator+(const Color& left, const Color& right)
return static_cast<std::uint8_t>(intResult < 255 ? intResult : 255);
};
return Color(clampedAdd(left.r, right.r),
clampedAdd(left.g, right.g),
clampedAdd(left.b, right.b),
clampedAdd(left.a, right.a));
return {clampedAdd(left.r, right.r),
clampedAdd(left.g, right.g),
clampedAdd(left.b, right.b),
clampedAdd(left.a, right.a)};
}
@ -93,10 +93,10 @@ constexpr Color operator-(const Color& left, const Color& right)
return static_cast<std::uint8_t>(intResult > 0 ? intResult : 0);
};
return Color(clampedSub(left.r, right.r),
clampedSub(left.g, right.g),
clampedSub(left.b, right.b),
clampedSub(left.a, right.a));
return {clampedSub(left.r, right.r),
clampedSub(left.g, right.g),
clampedSub(left.b, right.b),
clampedSub(left.a, right.a)};
}
@ -109,10 +109,7 @@ constexpr Color operator*(const Color& left, const Color& right)
return static_cast<std::uint8_t>(uint16Result / 255u);
};
return Color(scaledMul(left.r, right.r),
scaledMul(left.g, right.g),
scaledMul(left.b, right.b),
scaledMul(left.a, right.a));
return {scaledMul(left.r, right.r), scaledMul(left.g, right.g), scaledMul(left.b, right.b), scaledMul(left.a, right.a)};
}

View File

@ -265,7 +265,10 @@ private:
/// \code
/// // Declare and load a texture
/// sf::Texture texture;
/// texture.loadFromFile("texture.png");
/// if (!texture.loadFromFile("texture.png"))
/// {
/// // Handle error...
/// }
///
/// // Create a sprite
/// sf::Sprite sprite(texture);

View File

@ -464,7 +464,10 @@ private:
/// \code
/// // Declare and load a font
/// sf::Font font;
/// font.loadFromFile("arial.ttf");
/// if (!font.loadFromFile("arial.ttf"))
/// {
/// // Handle error...
/// }
///
/// // Create a text
/// sf::Text text(font, "hello");

View File

@ -120,8 +120,10 @@ public:
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromFile(filename);
/// texture.loadFromImage(image, area);
/// if (!image.loadFromFile(filename))
/// return false;
/// if (!texture.loadFromImage(image, area))
/// return false;
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle
@ -151,8 +153,10 @@ public:
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromMemory(data, size);
/// texture.loadFromImage(image, area);
/// if (!image.loadFromMemory(data, size))
/// return false;
/// if (!texture.loadFromImage(image, area))
/// return false;
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle
@ -183,8 +187,10 @@ public:
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromStream(stream);
/// texture.loadFromImage(image, area);
/// if (!image.loadFromStream(stream))
/// return false;
/// if (!texture.loadFromImage(image, area))
/// return false;
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle

View File

@ -63,15 +63,15 @@ constexpr Transform Transform::getInverse() const
if (det != 0.f)
{
// clang-format off
return Transform( (m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) / det,
-(m_matrix[15] * m_matrix[4] - m_matrix[7] * m_matrix[12]) / det,
(m_matrix[13] * m_matrix[4] - m_matrix[5] * m_matrix[12]) / det,
-(m_matrix[15] * m_matrix[1] - m_matrix[3] * m_matrix[13]) / det,
(m_matrix[15] * m_matrix[0] - m_matrix[3] * m_matrix[12]) / det,
-(m_matrix[13] * m_matrix[0] - m_matrix[1] * m_matrix[12]) / det,
(m_matrix[7] * m_matrix[1] - m_matrix[3] * m_matrix[5]) / det,
-(m_matrix[7] * m_matrix[0] - m_matrix[3] * m_matrix[4]) / det,
(m_matrix[5] * m_matrix[0] - m_matrix[1] * m_matrix[4]) / det);
return {(m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) / det,
-(m_matrix[15] * m_matrix[4] - m_matrix[7] * m_matrix[12]) / det,
(m_matrix[13] * m_matrix[4] - m_matrix[5] * m_matrix[12]) / det,
-(m_matrix[15] * m_matrix[1] - m_matrix[3] * m_matrix[13]) / det,
(m_matrix[15] * m_matrix[0] - m_matrix[3] * m_matrix[12]) / det,
-(m_matrix[13] * m_matrix[0] - m_matrix[1] * m_matrix[12]) / det,
(m_matrix[7] * m_matrix[1] - m_matrix[3] * m_matrix[5]) / det,
-(m_matrix[7] * m_matrix[0] - m_matrix[3] * m_matrix[4]) / det,
(m_matrix[5] * m_matrix[0] - m_matrix[1] * m_matrix[4]) / det};
// clang-format on
}
else
@ -84,8 +84,8 @@ constexpr Transform Transform::getInverse() const
////////////////////////////////////////////////////////////
constexpr Vector2f Transform::transformPoint(const Vector2f& point) const
{
return Vector2f(m_matrix[0] * point.x + m_matrix[4] * point.y + m_matrix[12],
m_matrix[1] * point.x + m_matrix[5] * point.y + m_matrix[13]);
return {m_matrix[0] * point.x + m_matrix[4] * point.y + m_matrix[12],
m_matrix[1] * point.x + m_matrix[5] * point.y + m_matrix[13]};
}
@ -115,7 +115,7 @@ constexpr FloatRect Transform::transformRect(const FloatRect& rectangle) const
// clang-format on
}
return FloatRect({left, top}, {right - left, bottom - top});
return {{left, top}, {right - left, bottom - top}};
}

View File

@ -73,21 +73,21 @@ constexpr Time::operator std::chrono::duration<Rep, Period>() const
////////////////////////////////////////////////////////////
constexpr Time seconds(float amount)
{
return Time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<float>(amount)));
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<float>(amount));
}
////////////////////////////////////////////////////////////
constexpr Time milliseconds(std::int32_t amount)
{
return Time(std::chrono::milliseconds(amount));
return std::chrono::milliseconds(amount);
}
////////////////////////////////////////////////////////////
constexpr Time microseconds(std::int64_t amount)
{
return Time(std::chrono::microseconds(amount));
return std::chrono::microseconds(amount);
}

View File

@ -208,7 +208,7 @@ private:
////////////////////////////////////////////////////////////
/// \brief Get access to the underlying implementation
///
/// This is primarily designed for sf::Window::setMouseCursor,
/// This is primarily designed for sf::WindowBase::setMouseCursor,
/// hence the friendship.
///
/// \return a reference to the OS-specific implementation
@ -238,7 +238,7 @@ private:
///
/// After loading the cursor the graphical appearance
/// with either loadFromPixels() or loadFromSystem(), the
/// cursor can be changed with sf::Window::setMouseCursor().
/// cursor can be changed with sf::WindowBase::setMouseCursor().
///
/// The behaviour is undefined if the cursor is destroyed while
/// in use by the window.
@ -254,6 +254,6 @@ private:
/// window.setMouseCursor(cursor);
/// \endcode
///
/// \see sf::Window::setMouseCursor
/// \see sf::WindowBase::setMouseCursor
///
////////////////////////////////////////////////////////////

View File

@ -79,7 +79,7 @@ Vector2f CircleShape::getPoint(std::size_t index) const
////////////////////////////////////////////////////////////
Vector2f CircleShape::getGeometricCenter() const
{
return Vector2f(m_radius, m_radius);
return {m_radius, m_radius};
}
} // namespace sf

View File

@ -27,6 +27,8 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/ConvexShape.hpp>
#include <cassert>
namespace sf
{
@ -55,6 +57,7 @@ std::size_t ConvexShape::getPointCount() const
////////////////////////////////////////////////////////////
void ConvexShape::setPoint(std::size_t index, const Vector2f& point)
{
assert(index < m_points.size() && "Index is out of bounds");
m_points[index] = point;
update();
}
@ -63,6 +66,7 @@ void ConvexShape::setPoint(std::size_t index, const Vector2f& point)
////////////////////////////////////////////////////////////
Vector2f ConvexShape::getPoint(std::size_t index) const
{
assert(index < m_points.size() && "Index is out of bounds");
return m_points[index];
}

View File

@ -755,7 +755,7 @@ IntRect Font::findGlyphRect(Page& page, const Vector2u& size) const
if (!newTexture.create(textureSize * 2u))
{
err() << "Failed to create new page texture" << std::endl;
return IntRect({0, 0}, {2, 2});
return {{0, 0}, {2, 2}};
}
newTexture.setSmooth(m_isSmooth);
@ -767,7 +767,7 @@ IntRect Font::findGlyphRect(Page& page, const Vector2u& size) const
// Oops, we've reached the maximum texture size...
err() << "Failed to add a new character to the font: the maximum texture size has been reached"
<< std::endl;
return IntRect({0, 0}, {2, 2});
return {{0, 0}, {2, 2}};
}
}

View File

@ -275,7 +275,7 @@ void Image::setPixel(const Vector2u& coords, const Color& color)
Color Image::getPixel(const Vector2u& coords) const
{
const std::uint8_t* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4];
return Color(pixel[0], pixel[1], pixel[2], pixel[3]);
return {pixel[0], pixel[1], pixel[2], pixel[3]};
}

View File

@ -68,13 +68,13 @@ Vector2f RectangleShape::getPoint(std::size_t index) const
{
default:
case 0:
return Vector2f(0, 0);
return {0, 0};
case 1:
return Vector2f(m_size.x, 0);
return {m_size.x, 0};
case 2:
return Vector2f(m_size.x, m_size.y);
return {m_size.x, m_size.y};
case 3:
return Vector2f(0, m_size.y);
return {0, m_size.y};
}
}

View File

@ -116,7 +116,7 @@ FloatRect Sprite::getLocalBounds() const
const auto width = static_cast<float>(std::abs(m_textureRect.width));
const auto height = static_cast<float>(std::abs(m_textureRect.height));
return FloatRect({0.f, 0.f}, {width, height});
return {{0.f, 0.f}, {width, height}};
}

View File

@ -365,7 +365,7 @@ Image Texture::copyToImage() const
{
// Easy case: empty texture
if (!m_texture)
return Image();
return {};
const TransientContextLock lock;

View File

@ -28,6 +28,8 @@
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <cassert>
namespace sf
{
@ -51,6 +53,7 @@ std::size_t VertexArray::getVertexCount() const
////////////////////////////////////////////////////////////
Vertex& VertexArray::operator[](std::size_t index)
{
assert(index < m_vertices.size() && "Index is out of bounds");
return m_vertices[index];
}
@ -58,6 +61,7 @@ Vertex& VertexArray::operator[](std::size_t index)
////////////////////////////////////////////////////////////
const Vertex& VertexArray::operator[](std::size_t index) const
{
assert(index < m_vertices.size() && "Index is out of bounds");
return m_vertices[index];
}
@ -124,12 +128,12 @@ FloatRect VertexArray::getBounds() const
bottom = position.y;
}
return FloatRect({left, top}, {right - left, bottom - top});
return {{left, top}, {right - left, bottom - top}};
}
else
{
// Array is empty
return FloatRect();
return {};
}
}

View File

@ -209,7 +209,7 @@ Ftp::Response Ftp::keepAlive()
////////////////////////////////////////////////////////////
Ftp::DirectoryResponse Ftp::getWorkingDirectory()
{
return DirectoryResponse(sendCommand("PWD"));
return {sendCommand("PWD")};
}
@ -234,7 +234,7 @@ Ftp::ListingResponse Ftp::getDirectoryListing(const std::string& directory)
}
}
return ListingResponse(response, directoryData.str());
return {response, directoryData.str()};
}

View File

@ -31,6 +31,7 @@
#include <iterator>
#include <utility>
#include <cassert>
#include <cstring>
@ -213,6 +214,7 @@ String& String::operator+=(const String& right)
////////////////////////////////////////////////////////////
char32_t String::operator[](std::size_t index) const
{
assert(index < m_string.size() && "Index is out of bounds");
return m_string[index];
}
@ -220,6 +222,7 @@ char32_t String::operator[](std::size_t index) const
////////////////////////////////////////////////////////////
char32_t& String::operator[](std::size_t index)
{
assert(index < m_string.size() && "Index is out of bounds");
return m_string[index];
}

View File

@ -39,7 +39,7 @@ namespace sf::priv
String ClipboardImpl::getString()
{
sf::err() << "Clipboard API not implemented for Android.\n";
return String();
return {};
}

View File

@ -71,7 +71,7 @@ void JoystickImpl::close()
JoystickCaps JoystickImpl::getCapabilities() const
{
// To implement
return JoystickCaps();
return {};
}
@ -86,7 +86,7 @@ Joystick::Identification JoystickImpl::getIdentification() const
JoystickState JoystickImpl::update()
{
// To implement
return JoystickState();
return {};
}
} // namespace sf::priv

View File

@ -125,7 +125,7 @@ void WindowImplAndroid::processEvents()
Vector2i WindowImplAndroid::getPosition() const
{
// Not applicable
return Vector2i(0, 0);
return {};
}

View File

@ -682,7 +682,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger)
return slot.pos;
}
return Vector2i();
return {};
}

View File

@ -68,7 +68,7 @@ WindowHandle WindowImplDRM::getNativeHandle() const
////////////////////////////////////////////////////////////
Vector2i WindowImplDRM::getPosition() const
{
return Vector2i(0, 0);
return {0, 0};
}

View File

@ -400,7 +400,7 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe
// Should never happen...
err() << "No GLX visual found. You should check your graphics driver" << std::endl;
return XVisualInfo();
return {};
}
}

View File

@ -138,7 +138,7 @@ Vector2i InputImpl::getMousePosition()
// Close the connection with the X server
closeDisplay(display);
return Vector2i(gx, gy);
return {gx, gy};
}
@ -165,11 +165,11 @@ Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
// Close the connection with the X server
closeDisplay(display);
return Vector2i(x, y);
return {x, y};
}
else
{
return Vector2i();
return {};
}
}
@ -218,7 +218,7 @@ bool InputImpl::isTouchDown(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
{
// Not applicable
return Vector2i();
return {};
}
@ -226,7 +226,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
{
// Not applicable
return Vector2i();
return {};
}
} // namespace sf::priv

View File

@ -407,7 +407,7 @@ std::string getJoystickName(unsigned int index)
::close(fd);
if (result >= 0)
return std::string(name);
return name;
}
// Fall back to manual USB chain walk via udev
@ -421,13 +421,13 @@ std::string getJoystickName(unsigned int index)
udev_device_unref(udevDevice);
if (product)
return std::string(product);
return {product};
}
}
sf::err() << "Unable to get name for joystick " << devnode << std::endl;
return std::string("Unknown Joystick");
return "Unknown Joystick";
}
} // namespace

View File

@ -677,7 +677,7 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
const char32_t unicode = keysymToUnicode(keysym);
if (unicode != 0)
return String(unicode);
return {unicode};
}
// Fallback to our best guess for the keys that are known to be independent of the layout.

View File

@ -71,7 +71,7 @@ void SensorImpl::close()
Vector3f SensorImpl::update()
{
// To be implemented
return Vector3f(0, 0, 0);
return {0, 0, 0};
}

View File

@ -78,7 +78,7 @@ using ContextType = sf::priv::GlxContext;
namespace
{
// A nested named namespace is used here to allow unity builds of SFML.
namespace WindowsImplX11Impl
namespace WindowImplX11Impl
{
sf::priv::WindowImplX11* fullscreenWindow = nullptr;
std::vector<sf::priv::WindowImplX11*> allWindows;
@ -381,7 +381,7 @@ bool isWMAbsolutePositionGood()
std::end(wmAbsPosGood),
[&](const sf::String& name) { return name == windowManagerName; });
}
} // namespace WindowsImplX11Impl
} // namespace WindowImplX11Impl
} // namespace
@ -434,7 +434,7 @@ struct XDeleter<XRRCrtcInfo>
////////////////////////////////////////////////////////////
WindowImplX11::WindowImplX11(WindowHandle handle) : m_isExternal(true)
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Open a connection with the X server
m_display = openDisplay();
@ -470,7 +470,7 @@ m_isExternal(false),
m_fullscreen((style & Style::Fullscreen) != 0),
m_cursorGrabbed(m_fullscreen)
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Open a connection with the X server
m_display = openDisplay();
@ -678,7 +678,7 @@ m_cursorGrabbed(m_fullscreen)
////////////////////////////////////////////////////////////
WindowImplX11::~WindowImplX11()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Cleanup graphical resources
cleanup();
@ -729,7 +729,7 @@ WindowHandle WindowImplX11::getNativeHandle() const
////////////////////////////////////////////////////////////
void WindowImplX11::processEvents()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
XEvent event;
@ -800,7 +800,7 @@ void WindowImplX11::processEvents()
////////////////////////////////////////////////////////////
Vector2i WindowImplX11::getPosition() const
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Get absolute position of our window relative to root window. This
// takes into account all information that X11 has, including X11
@ -818,7 +818,7 @@ Vector2i WindowImplX11::getPosition() const
// it to, even with decorations and such, which get shifted back.
// In these rare cases, we can use the absolute value directly.
if (isWMAbsolutePositionGood())
return Vector2i(xAbsRelToRoot, yAbsRelToRoot);
return {xAbsRelToRoot, yAbsRelToRoot};
// CASE 2: most modern WMs support EWMH and can define _NET_FRAME_EXTENTS
// with the exact frame size to subtract, so if present, we prefer it and
@ -830,7 +830,7 @@ Vector2i WindowImplX11::getPosition() const
{
// Get final X/Y coordinates: subtract EWMH frame extents from
// absolute window position.
return Vector2i((xAbsRelToRoot - static_cast<int>(xFrameExtent)), (yAbsRelToRoot - static_cast<int>(yFrameExtent)));
return {(xAbsRelToRoot - static_cast<int>(xFrameExtent)), (yAbsRelToRoot - static_cast<int>(yFrameExtent))};
}
// CASE 3: EWMH frame extents were not available, use geometry.
@ -866,7 +866,7 @@ Vector2i WindowImplX11::getPosition() const
XGetGeometry(m_display, ancestor, &root, &xRelToRoot, &yRelToRoot, &width, &height, &borderWidth, &depth);
return Vector2i(xRelToRoot, yRelToRoot);
return {xRelToRoot, yRelToRoot};
}
@ -928,8 +928,7 @@ void WindowImplX11::setTitle(const String& title)
// There is however an option to tell the window manager your Unicode title via hints.
// Convert to UTF-8 encoding.
std::basic_string<std::uint8_t> utf8Title;
Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title));
const std::basic_string<std::uint8_t> utf8Title = title.toUtf8();
const Atom useUtf8 = getAtom("UTF8_STRING", false);
@ -1126,7 +1125,7 @@ void WindowImplX11::setMouseCursor(const CursorImpl& cursor)
////////////////////////////////////////////////////////////
void WindowImplX11::setMouseCursorGrabbed(bool grabbed)
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// This has no effect in fullscreen mode
if (m_fullscreen || (m_cursorGrabbed == grabbed))
@ -1171,7 +1170,7 @@ void WindowImplX11::setKeyRepeatEnabled(bool enabled)
////////////////////////////////////////////////////////////
void WindowImplX11::requestFocus()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Focus is only stolen among SFML windows, not between applications
// Check the global list of windows to find out whether an SFML window has the focus
@ -1236,7 +1235,7 @@ bool WindowImplX11::hasFocus() const
////////////////////////////////////////////////////////////
void WindowImplX11::grabFocus()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
Atom netActiveWindow = None;
@ -1285,7 +1284,7 @@ void WindowImplX11::grabFocus()
////////////////////////////////////////////////////////////
void WindowImplX11::setVideoMode(const VideoMode& mode)
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Skip mode switching if the new mode is equal to the desktop mode
if (mode == VideoMode::getDesktopMode())
@ -1377,7 +1376,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
////////////////////////////////////////////////////////////
void WindowImplX11::resetVideoMode()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
if (fullscreenWindow == this)
{
@ -1439,7 +1438,7 @@ void WindowImplX11::resetVideoMode()
////////////////////////////////////////////////////////////
void WindowImplX11::switchToFullscreen()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
grabFocus();
@ -1495,7 +1494,7 @@ void WindowImplX11::switchToFullscreen()
////////////////////////////////////////////////////////////
void WindowImplX11::setProtocols()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
const Atom wmProtocols = getAtom("WM_PROTOCOLS");
const Atom wmDeleteWindow = getAtom("WM_DELETE_WINDOW");
@ -1563,7 +1562,7 @@ void WindowImplX11::setProtocols()
////////////////////////////////////////////////////////////
void WindowImplX11::initialize()
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Create the input context
m_inputMethod = openXim();
@ -1679,7 +1678,7 @@ void WindowImplX11::cleanup()
////////////////////////////////////////////////////////////
bool WindowImplX11::processEvent(XEvent& windowEvent)
{
using namespace WindowsImplX11Impl;
using namespace WindowImplX11Impl;
// Convert the X11 event to a sf::Event
switch (windowEvent.type)

View File

@ -647,7 +647,7 @@ Vector2i InputImpl::getMousePosition()
{
POINT point;
GetCursorPos(&point);
return Vector2i(point.x, point.y);
return {point.x, point.y};
}
@ -660,11 +660,11 @@ Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
POINT point;
GetCursorPos(&point);
ScreenToClient(handle, &point);
return Vector2i(point.x, point.y);
return {point.x, point.y};
}
else
{
return Vector2i();
return {};
}
}
@ -701,7 +701,7 @@ bool InputImpl::isTouchDown(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
{
// Not applicable
return Vector2i();
return {};
}
@ -709,7 +709,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
{
// Not applicable
return Vector2i();
return {};
}
} // namespace sf::priv

View File

@ -71,7 +71,7 @@ void SensorImpl::close()
Vector3f SensorImpl::update()
{
// To be implemented
return Vector3f(0, 0, 0);
return {};
}

View File

@ -116,7 +116,7 @@ String getErrorString(DWORD errorCode)
std::ostringstream ss;
ss << "Error " << errorCode;
return String(ss.str());
return {ss.str()};
}

View File

@ -302,7 +302,7 @@ Vector2i WindowImplWin32::getPosition() const
RECT rect;
GetWindowRect(m_handle, &rect);
return Vector2i(rect.left, rect.top);
return {rect.left, rect.top};
}
@ -322,7 +322,7 @@ Vector2u WindowImplWin32::getSize() const
RECT rect;
GetClientRect(m_handle, &rect);
return Vector2u(static_cast<unsigned int>(rect.right - rect.left), static_cast<unsigned int>(rect.bottom - rect.top));
return Vector2u(Vector2<LONG>(rect.right - rect.left, rect.bottom - rect.top));
}

View File

@ -49,7 +49,7 @@ String ClipboardImpl::getString()
}
else
{
return String();
return {};
}
}

View File

@ -84,7 +84,7 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button /* button */)
////////////////////////////////////////////////////////////
Vector2i InputImpl::getMousePosition()
{
return Vector2i(0, 0);
return {};
}

View File

@ -71,7 +71,7 @@ void JoystickImpl::close()
JoystickCaps JoystickImpl::getCapabilities() const
{
// Not implemented
return JoystickCaps();
return {};
}
@ -79,7 +79,7 @@ JoystickCaps JoystickImpl::getCapabilities() const
Joystick::Identification JoystickImpl::getIdentification() const
{
// Not implemented
return Joystick::Identification();
return {};
}
@ -87,7 +87,7 @@ Joystick::Identification JoystickImpl::getIdentification() const
JoystickState JoystickImpl::update()
{
// Not implemented
return JoystickState();
return {};
}
} // namespace sf::priv

View File

@ -109,8 +109,8 @@ WindowHandle WindowImplUIKit::getNativeHandle() const
Vector2i WindowImplUIKit::getPosition() const
{
const CGPoint origin = m_window.frame.origin;
return Vector2i(static_cast<int>(origin.x * static_cast<double>(m_backingScale)),
static_cast<int>(origin.y * static_cast<double>(m_backingScale)));
return {static_cast<int>(origin.x * static_cast<double>(m_backingScale)),
static_cast<int>(origin.y * static_cast<double>(m_backingScale))};
}
@ -124,8 +124,8 @@ void WindowImplUIKit::setPosition(const Vector2i& /* position */)
Vector2u WindowImplUIKit::getSize() const
{
const CGRect physicalFrame = m_window.frame;
return Vector2u(static_cast<unsigned int>(physicalFrame.size.width * static_cast<double>(m_backingScale)),
static_cast<unsigned int>(physicalFrame.size.height * static_cast<double>(m_backingScale)));
return {static_cast<unsigned int>(physicalFrame.size.width * static_cast<double>(m_backingScale)),
static_cast<unsigned int>(physicalFrame.size.height * static_cast<double>(m_backingScale))};
}

View File

@ -691,7 +691,7 @@ String HIDInputManager::getDescription(Keyboard::Scancode code)
// Phase 2: Try to convert the key to unicode
const UniChar unicode = toUnicode(localize(code));
if (unicode != 0x00)
return String(static_cast<char32_t>(unicode));
return {static_cast<char32_t>(unicode)};
}
// Phase 3: Return final fallback
@ -771,7 +771,7 @@ void HIDInputManager::loadKeyboard(IOHIDDeviceRef keyboard)
CFArrayRef underlying = IOHIDDeviceCopyMatchingElements(keyboard, nullptr, kIOHIDOptionsTypeNone);
if ((underlying == nullptr) || (CFArrayGetCount(underlying) == 0))
{
err() << "We got a keyboard without any keys." << std::endl;
err() << "Detected a keyboard without any keys." << std::endl;
return;
}

View File

@ -191,7 +191,7 @@ Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
// No view ?
if (view == nil)
return Vector2i();
return {};
// Use -cursorPositionFromEvent: with nil.
const NSPoint pos = [view cursorPositionFromEvent:nil];
@ -250,7 +250,7 @@ bool InputImpl::isTouchDown(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
{
// Not applicable
return Vector2i();
return {};
}
@ -258,7 +258,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
{
// Not applicable
return Vector2i();
return {};
}
} // namespace sf::priv

View File

@ -71,7 +71,7 @@ void SensorImpl::close()
Vector3f SensorImpl::update()
{
// To be implemented
return Vector3f(0, 0, 0);
return {0, 0, 0};
}

View File

@ -7,7 +7,8 @@ set(CATCH_CONFIG_FAST_COMPILE ON CACHE BOOL "")
set(CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ON CACHE BOOL "")
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0)
GIT_TAG v3.4.0
GIT_SHALLOW ON)
FetchContent_MakeAvailable(Catch2)
include(Catch)

View File

@ -24,11 +24,11 @@ public:
{
default:
case 0:
return sf::Vector2f(m_size.x / 2, 0);
return {m_size.x / 2, 0};
case 1:
return sf::Vector2f(0, m_size.y);
return {0, m_size.y};
case 2:
return sf::Vector2f(m_size.x, m_size.y);
return {m_size.x, m_size.y};
}
}

View File

@ -6,8 +6,7 @@
#include <array>
#include <type_traits>
// Skip these tests with [.display] because they fail when using DRM which hasn't implemented sf::Cursor
TEST_CASE("[Window] sf::Cursor", "[.display]")
TEST_CASE("[Window] sf::Cursor", runDisplayTests())
{
SECTION("Type traits")
{