Compare commits

..

No commits in common. "910514871e905d3c014a03cfb6bfdef77d609f7f" and "a71d6bc078d653c719e7ad96b3812028a81749b2" have entirely different histories.

45 changed files with 126 additions and 141 deletions

View File

@ -29,6 +29,7 @@ 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,6 +214,9 @@ 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 {static_cast<std::uint8_t>(r), static_cast<std::uint8_t>(g), static_cast<std::uint8_t>(b)};
return sf::Color(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 {crossProduct.x, crossProduct.y};
return sf::Vector2f(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 {clampedAdd(left.r, right.r),
return Color(clampedAdd(left.r, right.r),
clampedAdd(left.g, right.g),
clampedAdd(left.b, right.b),
clampedAdd(left.a, right.a)};
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 {clampedSub(left.r, right.r),
return Color(clampedSub(left.r, right.r),
clampedSub(left.g, right.g),
clampedSub(left.b, right.b),
clampedSub(left.a, right.a)};
clampedSub(left.a, right.a));
}
@ -109,7 +109,10 @@ constexpr Color operator*(const Color& left, const Color& right)
return static_cast<std::uint8_t>(uint16Result / 255u);
};
return {scaledMul(left.r, right.r), scaledMul(left.g, right.g), scaledMul(left.b, right.b), scaledMul(left.a, right.a)};
return Color(scaledMul(left.r, right.r),
scaledMul(left.g, right.g),
scaledMul(left.b, right.b),
scaledMul(left.a, right.a));
}

View File

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

View File

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

View File

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

View File

@ -63,7 +63,7 @@ constexpr Transform Transform::getInverse() const
if (det != 0.f)
{
// clang-format off
return {(m_matrix[15] * m_matrix[5] - m_matrix[7] * m_matrix[13]) / det,
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,
@ -71,7 +71,7 @@ constexpr Transform Transform::getInverse() const
-(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};
(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 {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 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]);
}
@ -115,7 +115,7 @@ constexpr FloatRect Transform::transformRect(const FloatRect& rectangle) const
// clang-format on
}
return {{left, top}, {right - left, bottom - top}};
return FloatRect({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 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<float>(amount));
return Time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<float>(amount)));
}
////////////////////////////////////////////////////////////
constexpr Time milliseconds(std::int32_t amount)
{
return std::chrono::milliseconds(amount);
return Time(std::chrono::milliseconds(amount));
}
////////////////////////////////////////////////////////////
constexpr Time microseconds(std::int64_t amount)
{
return std::chrono::microseconds(amount);
return Time(std::chrono::microseconds(amount));
}

View File

@ -208,7 +208,7 @@ private:
////////////////////////////////////////////////////////////
/// \brief Get access to the underlying implementation
///
/// This is primarily designed for sf::WindowBase::setMouseCursor,
/// This is primarily designed for sf::Window::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::WindowBase::setMouseCursor().
/// cursor can be changed with sf::Window::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::WindowBase::setMouseCursor
/// \see sf::Window::setMouseCursor
///
////////////////////////////////////////////////////////////

View File

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

View File

@ -27,8 +27,6 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/ConvexShape.hpp>
#include <cassert>
namespace sf
{
@ -57,7 +55,6 @@ 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();
}
@ -66,7 +63,6 @@ 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 {{0, 0}, {2, 2}};
return IntRect({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 {{0, 0}, {2, 2}};
return IntRect({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 {pixel[0], pixel[1], pixel[2], pixel[3]};
return Color(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 {0, 0};
return Vector2f(0, 0);
case 1:
return {m_size.x, 0};
return Vector2f(m_size.x, 0);
case 2:
return {m_size.x, m_size.y};
return Vector2f(m_size.x, m_size.y);
case 3:
return {0, m_size.y};
return Vector2f(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 {{0.f, 0.f}, {width, height}};
return FloatRect({0.f, 0.f}, {width, height});
}

View File

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

View File

@ -28,8 +28,6 @@
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <cassert>
namespace sf
{
@ -53,7 +51,6 @@ 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];
}
@ -61,7 +58,6 @@ 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];
}
@ -128,12 +124,12 @@ FloatRect VertexArray::getBounds() const
bottom = position.y;
}
return {{left, top}, {right - left, bottom - top}};
return FloatRect({left, top}, {right - left, bottom - top});
}
else
{
// Array is empty
return {};
return FloatRect();
}
}

View File

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

View File

@ -31,7 +31,6 @@
#include <iterator>
#include <utility>
#include <cassert>
#include <cstring>
@ -214,7 +213,6 @@ 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];
}
@ -222,7 +220,6 @@ 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 {};
return String();
}

View File

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

View File

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

View File

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

View File

@ -68,7 +68,7 @@ WindowHandle WindowImplDRM::getNativeHandle() const
////////////////////////////////////////////////////////////
Vector2i WindowImplDRM::getPosition() const
{
return {0, 0};
return Vector2i(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 {};
return XVisualInfo();
}
}

View File

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

View File

@ -407,7 +407,7 @@ std::string getJoystickName(unsigned int index)
::close(fd);
if (result >= 0)
return name;
return std::string(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 {product};
return std::string(product);
}
}
sf::err() << "Unable to get name for joystick " << devnode << std::endl;
return "Unknown Joystick";
return std::string("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 {unicode};
return String(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 {0, 0, 0};
return Vector3f(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 WindowImplX11Impl
namespace WindowsImplX11Impl
{
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 WindowImplX11Impl
} // namespace WindowsImplX11Impl
} // namespace
@ -434,7 +434,7 @@ struct XDeleter<XRRCrtcInfo>
////////////////////////////////////////////////////////////
WindowImplX11::WindowImplX11(WindowHandle handle) : m_isExternal(true)
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// 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 WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// Open a connection with the X server
m_display = openDisplay();
@ -678,7 +678,7 @@ m_cursorGrabbed(m_fullscreen)
////////////////////////////////////////////////////////////
WindowImplX11::~WindowImplX11()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// Cleanup graphical resources
cleanup();
@ -729,7 +729,7 @@ WindowHandle WindowImplX11::getNativeHandle() const
////////////////////////////////////////////////////////////
void WindowImplX11::processEvents()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
XEvent event;
@ -800,7 +800,7 @@ void WindowImplX11::processEvents()
////////////////////////////////////////////////////////////
Vector2i WindowImplX11::getPosition() const
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// 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 {xAbsRelToRoot, yAbsRelToRoot};
return Vector2i(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 {(xAbsRelToRoot - static_cast<int>(xFrameExtent)), (yAbsRelToRoot - static_cast<int>(yFrameExtent))};
return Vector2i((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 {xRelToRoot, yRelToRoot};
return Vector2i(xRelToRoot, yRelToRoot);
}
@ -928,7 +928,8 @@ 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.
const std::basic_string<std::uint8_t> utf8Title = title.toUtf8();
std::basic_string<std::uint8_t> utf8Title;
Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title));
const Atom useUtf8 = getAtom("UTF8_STRING", false);
@ -1125,7 +1126,7 @@ void WindowImplX11::setMouseCursor(const CursorImpl& cursor)
////////////////////////////////////////////////////////////
void WindowImplX11::setMouseCursorGrabbed(bool grabbed)
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// This has no effect in fullscreen mode
if (m_fullscreen || (m_cursorGrabbed == grabbed))
@ -1170,7 +1171,7 @@ void WindowImplX11::setKeyRepeatEnabled(bool enabled)
////////////////////////////////////////////////////////////
void WindowImplX11::requestFocus()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// 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
@ -1235,7 +1236,7 @@ bool WindowImplX11::hasFocus() const
////////////////////////////////////////////////////////////
void WindowImplX11::grabFocus()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
Atom netActiveWindow = None;
@ -1284,7 +1285,7 @@ void WindowImplX11::grabFocus()
////////////////////////////////////////////////////////////
void WindowImplX11::setVideoMode(const VideoMode& mode)
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// Skip mode switching if the new mode is equal to the desktop mode
if (mode == VideoMode::getDesktopMode())
@ -1376,7 +1377,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
////////////////////////////////////////////////////////////
void WindowImplX11::resetVideoMode()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
if (fullscreenWindow == this)
{
@ -1438,7 +1439,7 @@ void WindowImplX11::resetVideoMode()
////////////////////////////////////////////////////////////
void WindowImplX11::switchToFullscreen()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
grabFocus();
@ -1494,7 +1495,7 @@ void WindowImplX11::switchToFullscreen()
////////////////////////////////////////////////////////////
void WindowImplX11::setProtocols()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
const Atom wmProtocols = getAtom("WM_PROTOCOLS");
const Atom wmDeleteWindow = getAtom("WM_DELETE_WINDOW");
@ -1562,7 +1563,7 @@ void WindowImplX11::setProtocols()
////////////////////////////////////////////////////////////
void WindowImplX11::initialize()
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// Create the input context
m_inputMethod = openXim();
@ -1678,7 +1679,7 @@ void WindowImplX11::cleanup()
////////////////////////////////////////////////////////////
bool WindowImplX11::processEvent(XEvent& windowEvent)
{
using namespace WindowImplX11Impl;
using namespace WindowsImplX11Impl;
// 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 {point.x, point.y};
return Vector2i(point.x, point.y);
}
@ -660,11 +660,11 @@ Vector2i InputImpl::getMousePosition(const WindowBase& relativeTo)
POINT point;
GetCursorPos(&point);
ScreenToClient(handle, &point);
return {point.x, point.y};
return Vector2i(point.x, point.y);
}
else
{
return {};
return Vector2i();
}
}
@ -701,7 +701,7 @@ bool InputImpl::isTouchDown(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
{
// Not applicable
return {};
return Vector2i();
}
@ -709,7 +709,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
{
// Not applicable
return {};
return Vector2i();
}
} // namespace sf::priv

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -71,7 +71,7 @@ void JoystickImpl::close()
JoystickCaps JoystickImpl::getCapabilities() const
{
// Not implemented
return {};
return JoystickCaps();
}
@ -79,7 +79,7 @@ JoystickCaps JoystickImpl::getCapabilities() const
Joystick::Identification JoystickImpl::getIdentification() const
{
// Not implemented
return {};
return Joystick::Identification();
}
@ -87,7 +87,7 @@ Joystick::Identification JoystickImpl::getIdentification() const
JoystickState JoystickImpl::update()
{
// Not implemented
return {};
return JoystickState();
}
} // 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 {static_cast<int>(origin.x * static_cast<double>(m_backingScale)),
static_cast<int>(origin.y * static_cast<double>(m_backingScale))};
return Vector2i(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 {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 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)));
}

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 {static_cast<char32_t>(unicode)};
return String(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() << "Detected a keyboard without any keys." << std::endl;
err() << "We got 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 {};
return Vector2i();
// 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 {};
return Vector2i();
}
@ -258,7 +258,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/)
Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase& /*relativeTo*/)
{
// Not applicable
return {};
return Vector2i();
}
} // namespace sf::priv

View File

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

View File

@ -7,8 +7,7 @@ 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_SHALLOW ON)
GIT_TAG v3.4.0)
FetchContent_MakeAvailable(Catch2)
include(Catch)

View File

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

View File

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