From e0f23561023090cf21863d3c60ea37b58e1e9f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Wed, 21 Apr 2021 01:02:18 +0200 Subject: [PATCH] Fix conversion warnings for Unix - Fix conversion & shadowing warnings - For the System & Window module --- include/SFML/System/Utf.inl | 2 +- src/SFML/System/FileInputStream.cpp | 2 +- src/SFML/System/MemoryInputStream.cpp | 2 +- src/SFML/System/Time.cpp | 2 +- src/SFML/System/Unix/ClockImpl.cpp | 2 +- src/SFML/System/Unix/SleepImpl.cpp | 2 +- src/SFML/Window/EglContext.cpp | 12 ++-- src/SFML/Window/GlContext.cpp | 20 +++---- src/SFML/Window/JoystickManager.cpp | 2 +- src/SFML/Window/Unix/ClipboardImpl.cpp | 12 ++-- src/SFML/Window/Unix/CursorImpl.cpp | 26 ++++---- src/SFML/Window/Unix/GlxContext.cpp | 10 ++-- src/SFML/Window/Unix/JoystickImpl.cpp | 32 +++++----- src/SFML/Window/Unix/VideoModeImpl.cpp | 14 +++-- src/SFML/Window/Unix/WindowImplX11.cpp | 82 +++++++++++++------------- src/SFML/Window/Unix/WindowImplX11.hpp | 2 +- src/SFML/Window/Window.cpp | 6 +- src/SFML/Window/WindowBase.cpp | 4 +- src/SFML/Window/WindowImpl.cpp | 2 +- 19 files changed, 122 insertions(+), 114 deletions(-) diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index 3f0c81f3..ee7d3fa1 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -293,7 +293,7 @@ In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement) if ((second >= 0xDC00) && (second <= 0xDFFF)) { // The second element is valid: convert the two elements to a UTF-32 character - output = ((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000; + output = ((first - 0xD800u) << 10) + (second - 0xDC00) + 0x0010000; } else { diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index f2d85399..8ef1c573 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -80,7 +80,7 @@ Int64 FileInputStream::read(void* data, Int64 size) return m_file->read(data, size); #else if (m_file) - return std::fread(data, 1, static_cast(size), m_file); + return static_cast(std::fread(data, 1, static_cast(size), m_file)); else return -1; #endif diff --git a/src/SFML/System/MemoryInputStream.cpp b/src/SFML/System/MemoryInputStream.cpp index f81e1a07..6aa8f497 100644 --- a/src/SFML/System/MemoryInputStream.cpp +++ b/src/SFML/System/MemoryInputStream.cpp @@ -44,7 +44,7 @@ m_offset(0) void MemoryInputStream::open(const void* data, std::size_t sizeInBytes) { m_data = static_cast(data); - m_size = sizeInBytes; + m_size = static_cast(sizeInBytes); m_offset = 0; } diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index b9b627f1..f13183ca 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -44,7 +44,7 @@ m_microseconds(0) //////////////////////////////////////////////////////////// float Time::asSeconds() const { - return m_microseconds / 1000000.f; + return static_cast(static_cast(m_microseconds) / 1000000.0); } diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp index d3b367d1..7f6a97aa 100644 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ b/src/SFML/System/Unix/ClockImpl.cpp @@ -54,7 +54,7 @@ Time ClockImpl::getCurrentTime() // POSIX implementation timespec time; clock_gettime(CLOCK_MONOTONIC, &time); - return sf::microseconds(static_cast(time.tv_sec) * 1000000 + time.tv_nsec / 1000); + return sf::microseconds(time.tv_sec * 1000000 + time.tv_nsec / 1000); #endif } diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp index 1c395b5b..6bed85de 100644 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -37,7 +37,7 @@ namespace priv //////////////////////////////////////////////////////////// void sleepImpl(Time time) { - Uint64 usecs = time.asMicroseconds(); + Int64 usecs = time.asMicroseconds(); // Construct the time to wait timespec ti; diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 013c376f..f9b50c8f 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -163,7 +163,7 @@ m_config (NULL) #if !defined(SFML_SYSTEM_ANDROID) // Create EGL surface (except on Android because the window is created // asynchronously, its activity manager will call it for us) - createSurface((EGLNativeWindowType)owner->getSystemHandle()); + createSurface(owner->getSystemHandle()); #endif } @@ -215,7 +215,7 @@ GlFunctionPointer EglContext::getFunction(const char* name) { EglContextImpl::ensureInit(); - return reinterpret_cast(eglGetProcAddress(name)); + return eglGetProcAddress(name); } @@ -306,7 +306,7 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe EGL_BUFFER_SIZE, static_cast(bitsPerPixel), EGL_DEPTH_SIZE, static_cast(settings.depthBits), EGL_STENCIL_SIZE, static_cast(settings.stencilBits), - EGL_SAMPLE_BUFFERS, static_cast(settings.antialiasingLevel ? 1 : 0), + EGL_SAMPLE_BUFFERS, settings.antialiasingLevel ? 1 : 0, EGL_SAMPLES, static_cast(settings.antialiasingLevel), EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, @@ -337,21 +337,21 @@ void EglContext::updateSettings() if (result == EGL_FALSE) err() << "Failed to retrieve EGL_DEPTH_SIZE" << std::endl; - m_settings.depthBits = tmp; + m_settings.depthBits = static_cast(tmp); eglCheck(result = eglGetConfigAttrib(m_display, m_config, EGL_STENCIL_SIZE, &tmp)); if (result == EGL_FALSE) err() << "Failed to retrieve EGL_STENCIL_SIZE" << std::endl; - m_settings.stencilBits = tmp; + m_settings.stencilBits = static_cast(tmp); eglCheck(result = eglGetConfigAttrib(m_display, m_config, EGL_SAMPLES, &tmp)); if (result == EGL_FALSE) err() << "Failed to retrieve EGL_SAMPLES" << std::endl; - m_settings.antialiasingLevel = tmp; + m_settings.antialiasingLevel = static_cast(tmp); m_settings.majorVersion = 1; m_settings.minorVersion = 1; diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 97ad8af0..9ed2315e 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -291,14 +291,14 @@ namespace { std::size_t prefixLength = std::strlen(prefix); - if ((std::strlen(version) >= (prefixLength + 3)) && - (std::strncmp(version, prefix, prefixLength) == 0) && - std::isdigit(version[prefixLength]) && - (version[prefixLength + 1] == '.') && - std::isdigit(version[prefixLength + 2])) - { - major = version[prefixLength] - '0'; - minor = version[prefixLength + 2] - '0'; + if ((std::strlen(version) >= (prefixLength + 3)) && + (std::strncmp(version, prefix, prefixLength) == 0) && + std::isdigit(version[prefixLength]) && + (version[prefixLength + 1] == '.') && + std::isdigit(version[prefixLength + 2])) + { + major = static_cast(version[prefixLength] - '0'); + minor = static_cast(version[prefixLength + 2] - '0'); return true; } @@ -923,8 +923,8 @@ void GlContext::checkSettings(const ContextSettings& requestedSettings) } } - int version = m_settings.majorVersion * 10 + m_settings.minorVersion; - int requestedVersion = requestedSettings.majorVersion * 10 + requestedSettings.minorVersion; + int version = static_cast(m_settings.majorVersion * 10u + m_settings.minorVersion); + int requestedVersion = static_cast(requestedSettings.majorVersion * 10u + requestedSettings.minorVersion); if ((m_settings.attributeFlags != requestedSettings.attributeFlags) || (version < requestedVersion) || diff --git a/src/SFML/Window/JoystickManager.cpp b/src/SFML/Window/JoystickManager.cpp index e6d1b04c..457b2aff 100644 --- a/src/SFML/Window/JoystickManager.cpp +++ b/src/SFML/Window/JoystickManager.cpp @@ -64,7 +64,7 @@ const Joystick::Identification& JoystickManager::getIdentification(unsigned int //////////////////////////////////////////////////////////// void JoystickManager::update() { - for (int i = 0; i < Joystick::Count; ++i) + for (unsigned int i = 0; i < Joystick::Count; ++i) { Item& item = m_joysticks[i]; diff --git a/src/SFML/Window/Unix/ClipboardImpl.cpp b/src/SFML/Window/Unix/ClipboardImpl.cpp index e99f3d72..fbb72f23 100644 --- a/src/SFML/Window/Unix/ClipboardImpl.cpp +++ b/src/SFML/Window/Unix/ClipboardImpl.cpp @@ -209,7 +209,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) // Notification that the current selection owner // has responded to our request - XSelectionEvent& selectionEvent = *reinterpret_cast(&windowEvent.xselection); + XSelectionEvent& selectionEvent = windowEvent.xselection; m_clipboardContents.clear(); @@ -274,7 +274,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) case SelectionRequest: { // Respond to a request for our clipboard contents - XSelectionRequestEvent& selectionRequestEvent = *reinterpret_cast(&windowEvent.xselectionrequest); + XSelectionRequestEvent& selectionRequestEvent = windowEvent.xselectionrequest; // Our reply XSelectionEvent selectionEvent; @@ -307,7 +307,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) 32, PropModeReplace, reinterpret_cast(&targets[0]), - targets.size() + static_cast(targets.size()) ); // Notify the requestor that they can read the targets from their window property @@ -330,7 +330,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) 8, PropModeReplace, reinterpret_cast(data.c_str()), - data.size() + static_cast(data.size()) ); // Notify the requestor that they can read the data from their window property @@ -353,8 +353,8 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) m_utf8String, 8, PropModeReplace, - reinterpret_cast(data.c_str()), - data.size() + data.c_str(), + static_cast(data.size()) ); // Notify the requestor that they can read the data from their window property diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index 4ceac562..95cc6ff9 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -73,17 +73,17 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot bool CursorImpl::loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u hotspot) { // Create cursor image, convert from RGBA to ARGB. - XcursorImage* cursorImage = XcursorImageCreate(size.x, size.y); + XcursorImage* cursorImage = XcursorImageCreate(static_cast(size.x), static_cast(size.y)); cursorImage->xhot = hotspot.x; cursorImage->yhot = hotspot.y; const std::size_t numPixels = size.x * size.y; for (std::size_t pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex) { - cursorImage->pixels[pixelIndex] = pixels[pixelIndex * 4 + 2] + - (pixels[pixelIndex * 4 + 1] << 8) + - (pixels[pixelIndex * 4 + 0] << 16) + - (pixels[pixelIndex * 4 + 3] << 24); + cursorImage->pixels[pixelIndex] = static_cast(pixels[pixelIndex * 4 + 2] + + (pixels[pixelIndex * 4 + 1] << 8) + + (pixels[pixelIndex * 4 + 0] << 16) + + (pixels[pixelIndex * 4 + 3] << 24)); } // Create the cursor. @@ -119,26 +119,30 @@ bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Ve // Turn on pixel that are not transparent Uint8 opacity = pixels[pixelIndex * 4 + 3] > 0 ? 1 : 0; - mask[byteIndex] |= opacity << bitIndex; + mask[byteIndex] |= static_cast(opacity << bitIndex); // Choose between black/background & white/foreground color for each pixel, // based on the pixel color intensity: on average, if a channel is "active" // at 50%, the bit is white. int intensity = (pixels[pixelIndex * 4 + 0] + pixels[pixelIndex * 4 + 1] + pixels[pixelIndex * 4 + 2]) / 3; Uint8 bit = intensity > 128 ? 1 : 0; - data[byteIndex] |= bit << bitIndex; + data[byteIndex] |= static_cast(bit << bitIndex); } } Pixmap maskPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display), - (char*)&mask[0], size.x, size.y); + reinterpret_cast(&mask[0]), size.x, size.y); Pixmap dataPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display), - (char*)&data[0], size.x, size.y); + reinterpret_cast(&data[0]), size.x, size.y); // Define the foreground color as white and the background as black. XColor fg, bg; - fg.red = fg.blue = fg.green = -1; - bg.red = bg.blue = bg.green = 0; + fg.red = 0xFFFF; + fg.blue = 0xFFFF; + fg.green = 0xFFFF; + bg.red = 0x0000; + bg.blue = 0x0000; + bg.green = 0x0000; // Create the monochrome cursor. m_cursor = XCreatePixmapCursor(m_display, diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 843b37e1..e422b6b5 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -149,7 +149,7 @@ m_ownsWindow(false) ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface from the owner window - createSurface(static_cast< ::Window>(owner->getSystemHandle())); + createSurface(owner->getSystemHandle()); // Create the context createContext(shared); @@ -224,7 +224,7 @@ GlxContext::~GlxContext() //////////////////////////////////////////////////////////// GlFunctionPointer GlxContext::getFunction(const char* name) { - return reinterpret_cast(glXGetProcAddress(reinterpret_cast(name))); + return glXGetProcAddress(reinterpret_cast(name)); } @@ -439,7 +439,7 @@ void GlxContext::updateSettingsFromVisualInfo(XVisualInfo* visualInfo) m_settings.depthBits = static_cast(depth); m_settings.stencilBits = static_cast(stencil); - m_settings.antialiasingLevel = multiSampling ? samples : 0; + m_settings.antialiasingLevel = multiSampling ? static_cast(samples) : 0; m_settings.sRgbCapable = (sRgb == True); } @@ -683,9 +683,9 @@ void GlxContext::createContext(GlxContext* shared) if ((m_settings.majorVersion > 1) || ((m_settings.majorVersion == 1) && (m_settings.minorVersion > 1))) { attributes.push_back(GLX_CONTEXT_MAJOR_VERSION_ARB); - attributes.push_back(m_settings.majorVersion); + attributes.push_back(static_cast(m_settings.majorVersion)); attributes.push_back(GLX_CONTEXT_MINOR_VERSION_ARB); - attributes.push_back(m_settings.minorVersion); + attributes.push_back(static_cast(m_settings.minorVersion)); } // Check if setting the profile is supported diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index 8223a10a..99ce355b 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -155,12 +155,12 @@ namespace // If not mapped before and it got added, map it now const char* syspath = udev_device_get_syspath(udevDevice); - JoystickRecord record; - record.deviceNode = devnode; - record.systemPath = syspath ? syspath : ""; - record.plugged = true; + JoystickRecord newRecord; + newRecord.deviceNode = devnode; + newRecord.systemPath = syspath ? syspath : ""; + newRecord.plugged = true; - joystickList.push_back(record); + joystickList.push_back(newRecord); } else if (std::strstr(action, "remove")) { @@ -211,12 +211,12 @@ namespace udev_list_entry_foreach(device, devices) { const char* syspath = udev_list_entry_get_name(device); - udev_device* udevDevice = udev_device_new_from_syspath(udevContext, syspath); + udev_device* newUdevDevice = udev_device_new_from_syspath(udevContext, syspath); - if (udevDevice && isJoystick(udevDevice)) + if (newUdevDevice && isJoystick(newUdevDevice)) { // Since isJoystick returned true, this has to succeed - const char* devnode = udev_device_get_devnode(udevDevice); + const char* devnode = udev_device_get_devnode(newUdevDevice); JoystickList::iterator record; @@ -233,16 +233,16 @@ namespace // If not mapped before, map it now if (record == joystickList.end()) { - JoystickRecord record; - record.deviceNode = devnode; - record.systemPath = syspath; - record.plugged = true; + JoystickRecord nweRecord; + nweRecord.deviceNode = devnode; + nweRecord.systemPath = syspath; + nweRecord.plugged = true; - joystickList.push_back(record); + joystickList.push_back(nweRecord); } } - udev_device_unref(udevDevice); + udev_device_unref(newUdevDevice); } udev_enumerate_unref(udevEnumerator); @@ -602,7 +602,7 @@ JoystickCaps JoystickImpl::getCapabilities() const // Get the number of buttons char buttonCount; ioctl(m_file, JSIOCGBUTTONS, &buttonCount); - caps.buttonCount = buttonCount; + caps.buttonCount = static_cast(buttonCount); if (caps.buttonCount > Joystick::ButtonCount) caps.buttonCount = Joystick::ButtonCount; @@ -649,7 +649,7 @@ JoystickState JoystickImpl::JoystickImpl::update() // pop events from the joystick file js_event joyState; - int result = read(m_file, &joyState, sizeof(joyState)); + ssize_t result = read(m_file, &joyState, sizeof(joyState)); while (result > 0) { switch (joyState.type & ~JS_EVENT_INIT) diff --git a/src/SFML/Window/Unix/VideoModeImpl.cpp b/src/SFML/Window/Unix/VideoModeImpl.cpp index f1b86a90..87563b6e 100644 --- a/src/SFML/Window/Unix/VideoModeImpl.cpp +++ b/src/SFML/Window/Unix/VideoModeImpl.cpp @@ -73,7 +73,9 @@ std::vector VideoModeImpl::getFullscreenModes() for (int j = 0; j < nbSizes; ++j) { // Convert to VideoMode - VideoMode mode(sizes[j].width, sizes[j].height, depths[i]); + VideoMode mode(static_cast(sizes[j].width), + static_cast(sizes[j].height), + static_cast(depths[i])); Rotation currentRotation; XRRConfigRotations(config, ¤tRotation); @@ -149,12 +151,14 @@ VideoMode VideoModeImpl::getDesktopMode() XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); if (sizes && (nbSizes > 0)) { - desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen)); + desktopMode = VideoMode(static_cast(sizes[currentMode].width), + static_cast(sizes[currentMode].height), + static_cast(DefaultDepth(display, screen))); - Rotation currentRotation; - XRRConfigRotations(config, ¤tRotation); + Rotation modeRotation; + XRRConfigRotations(config, &modeRotation); - if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) + if (modeRotation == RR_Rotate_90 || modeRotation == RR_Rotate_270) std::swap(desktopMode.width, desktopMode.height); } diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index cc73877b..f46d9df7 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -81,10 +81,10 @@ namespace static const unsigned int maxTrialsCount = 5; - // Predicate we use to find key repeat events in processEvent - struct KeyRepeatFinder - { - KeyRepeatFinder(unsigned int keycode, Time time) : keycode(keycode), time(time) {} + // Predicate we use to find key repeat events in processEvent + struct KeyRepeatFinder + { + KeyRepeatFinder(unsigned int initalKeycode, Time initialTime) : keycode(initalKeycode), time(initialTime) {} // Predicate operator that checks event type, keycode and timestamp bool operator()(const XEvent& event) @@ -117,11 +117,11 @@ namespace std::size_t offset = 0; ssize_t result = 0; - while ((result = read(file, &buffer[offset], 256)) > 0) - { - buffer.resize(buffer.size() + result, 0); - offset += result; - } + while ((result = read(file, &buffer[offset], 256)) > 0) + { + buffer.resize(buffer.size() + static_cast(result), 0); + offset += static_cast(result); + } ::close(file); @@ -335,7 +335,7 @@ namespace { gotFrameExtents = true; - long* extents = (long*) data; + long* extents = reinterpret_cast(data); xFrameExtent = extents[0]; // Left. yFrameExtent = extents[2]; // Top. @@ -573,12 +573,12 @@ m_lastInputTime (0) } else { - windowPosition.x = (DisplayWidth(m_display, m_screen) - mode.width) / 2; - windowPosition.y = (DisplayWidth(m_display, m_screen) - mode.height) / 2; + windowPosition.x = (DisplayWidth(m_display, m_screen) - static_cast(mode.width)) / 2; + windowPosition.y = (DisplayWidth(m_display, m_screen) - static_cast(mode.height)) / 2; } - int width = mode.width; - int height = mode.height; + unsigned int width = mode.width; + unsigned int height = mode.height; Visual* visual = NULL; int depth = 0; @@ -626,11 +626,11 @@ m_lastInputTime (0) setProtocols(); // Set the WM initial state to the normal state - XWMHints* hints = XAllocWMHints(); - hints->flags = StateHint; - hints->initial_state = NormalState; - XSetWMHints(m_display, m_window, hints); - XFree(hints); + XWMHints* xHints = XAllocWMHints(); + xHints->flags = StateHint; + xHints->initial_state = NormalState; + XSetWMHints(m_display, m_window, xHints); + XFree(xHints); // If not in fullscreen, set the window's style (tell the window manager to // change our window's decorations and functions according to the requested style) @@ -705,8 +705,8 @@ m_lastInputTime (0) m_useSizeHints = true; XSizeHints* sizeHints = XAllocSizeHints(); sizeHints->flags = PMinSize | PMaxSize | USPosition; - sizeHints->min_width = sizeHints->max_width = width; - sizeHints->min_height = sizeHints->max_height = height; + sizeHints->min_width = sizeHints->max_width = static_cast(width); + sizeHints->min_height = sizeHints->max_height = static_cast(height); sizeHints->x = windowPosition.x; sizeHints->y = windowPosition.y; XSetWMNormalHints(m_display, m_window, sizeHints); @@ -867,7 +867,7 @@ Vector2i WindowImplX11::getPosition() const { // Get final X/Y coordinates: subtract EWMH frame extents from // absolute window position. - return Vector2i((xAbsRelToRoot - xFrameExtent), (yAbsRelToRoot - yFrameExtent)); + return Vector2i((xAbsRelToRoot - static_cast(xFrameExtent)), (yAbsRelToRoot - static_cast(yFrameExtent))); } // CASE 3: EWMH frame extents were not available, use geometry. @@ -917,7 +917,7 @@ Vector2u WindowImplX11::getSize() const { XWindowAttributes attributes; XGetWindowAttributes(m_display, m_window, &attributes); - return Vector2u(attributes.width, attributes.height); + return Vector2u(Vector2i(attributes.width, attributes.height)); } @@ -929,8 +929,8 @@ void WindowImplX11::setSize(const Vector2u& size) { XSizeHints* sizeHints = XAllocSizeHints(); sizeHints->flags = PMinSize | PMaxSize; - sizeHints->min_width = sizeHints->max_width = size.x; - sizeHints->min_height = sizeHints->max_height = size.y; + sizeHints->min_width = sizeHints->max_width = static_cast(size.x); + sizeHints->min_height = sizeHints->max_height = static_cast(size.y); XSetWMNormalHints(m_display, m_window, sizeHints); XFree(sizeHints); } @@ -955,12 +955,12 @@ void WindowImplX11::setTitle(const String& title) // Set the _NET_WM_NAME atom, which specifies a UTF-8 encoded window title. Atom wmName = getAtom("_NET_WM_NAME", false); XChangeProperty(m_display, m_window, wmName, useUtf8, 8, - PropModeReplace, utf8Title.c_str(), utf8Title.size()); + PropModeReplace, utf8Title.c_str(), static_cast(utf8Title.size())); // Set the _NET_WM_ICON_NAME atom, which specifies a UTF-8 encoded window title. Atom wmIconName = getAtom("_NET_WM_ICON_NAME", false); XChangeProperty(m_display, m_window, wmIconName, useUtf8, 8, - PropModeReplace, utf8Title.c_str(), utf8Title.size()); + PropModeReplace, utf8Title.c_str(), static_cast(utf8Title.size())); // Set the non-Unicode title as a fallback for window managers who don't support _NET_WM_NAME. #ifdef X_HAVE_UTF8_STRING @@ -1003,8 +1003,8 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // Create the icon pixmap Visual* defVisual = DefaultVisual(m_display, m_screen); - unsigned int defDepth = DefaultDepth(m_display, m_screen); - XImage* iconImage = XCreateImage(m_display, defVisual, defDepth, ZPixmap, 0, (char*)iconPixels, width, height, 32, 0); + unsigned int defDepth = static_cast(DefaultDepth(m_display, m_screen)); + XImage* iconImage = XCreateImage(m_display, defVisual, defDepth, ZPixmap, 0, reinterpret_cast(iconPixels), width, height, 32, 0); if (!iconImage) { err() << "Failed to set the window's icon" << std::endl; @@ -1036,12 +1036,12 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 if (i * 8 + k < width) { Uint8 opacity = (pixels[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0; - maskPixels[i + j * pitch] |= (opacity << k); + maskPixels[i + j * pitch] |= static_cast(opacity << k); } } } } - m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, (char*)&maskPixels[0], width, height, 1, 0, 1); + m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(&maskPixels[0]), width, height, 1, 0, 1); // Send our new icon to the window through the WMHints XWMHints* hints = XAllocWMHints(); @@ -1061,10 +1061,10 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 for (std::size_t i = 0; i < width * height; ++i) { - *ptr++ = (pixels[i * 4 + 2] << 0 ) | - (pixels[i * 4 + 1] << 8 ) | - (pixels[i * 4 + 0] << 16) | - (pixels[i * 4 + 3] << 24); + *ptr++ = static_cast((pixels[i * 4 + 2] << 0 ) | + (pixels[i * 4 + 1] << 8 ) | + (pixels[i * 4 + 0] << 16) | + (pixels[i * 4 + 3] << 24)); } Atom netWmIcon = getAtom("_NET_WM_ICON"); @@ -1076,7 +1076,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 32, PropModeReplace, reinterpret_cast(&icccmIconPixels[0]), - 2 + width * height); + static_cast(2 + width * height)); XFlush(m_display); } @@ -1269,7 +1269,7 @@ void WindowImplX11::grabFocus() event.xclient.format = 32; event.xclient.message_type = netActiveWindow; event.xclient.data.l[0] = 1; // Normal application - event.xclient.data.l[1] = m_lastInputTime; + event.xclient.data.l[1] = static_cast(m_lastInputTime); event.xclient.data.l[2] = 0; // We don't know the currently active window int result = XSendEvent(m_display, @@ -1504,7 +1504,7 @@ void WindowImplX11::switchToFullscreen() event.xclient.format = 32; event.xclient.message_type = netWmState; event.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD - event.xclient.data.l[1] = netWmStateFullscreen; + event.xclient.data.l[1] = static_cast(netWmStateFullscreen); event.xclient.data.l[2] = 0; // No second property event.xclient.data.l[3] = 1; // Normal window @@ -1579,7 +1579,7 @@ void WindowImplX11::setProtocols() 32, PropModeReplace, reinterpret_cast(&atoms[0]), - atoms.size()); + static_cast(atoms.size())); } else { @@ -1819,8 +1819,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) { Event event; event.type = Event::Resized; - event.size.width = windowEvent.xconfigure.width; - event.size.height = windowEvent.xconfigure.height; + event.size.width = static_cast(windowEvent.xconfigure.width); + event.size.height = static_cast(windowEvent.xconfigure.height); pushEvent(event); m_previousSize.x = windowEvent.xconfigure.width; diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index 255e0064..ea8aec86 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -307,7 +307,7 @@ private: XIC m_inputContext; ///< Input context used to get unicode input in our window std::deque m_events; ///< Queue we use to store pending events for this window bool m_isExternal; ///< Tell whether the window has been created externally or by SFML - int m_oldVideoMode; ///< Video mode in use before we switch to fullscreen + RRMode m_oldVideoMode; ///< Video mode in use before we switch to fullscreen RRCrtc m_oldRRCrtc; ///< RRCrtc in use before we switch to fullscreen ::Cursor m_hiddenCursor; ///< As X11 doesn't provide cursor hiding, we must create a transparent one ::Cursor m_lastCursor; ///< Last cursor used -- this data is not owned by the window and is required to be always valid diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 27013d9d..1c2cf65e 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -88,7 +88,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con if (getFullscreenWindow()) { err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~Style::Fullscreen; + style &= ~static_cast(Style::Fullscreen); } else { @@ -107,7 +107,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con // Check validity of style according to the underlying platform #if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) if (style & Style::Fullscreen) - style &= ~Style::Titlebar; + style &= ~static_cast(Style::Titlebar); else style |= Style::Titlebar; #else @@ -183,7 +183,7 @@ void Window::setVerticalSyncEnabled(bool enabled) void Window::setFramerateLimit(unsigned int limit) { if (limit > 0) - m_frameTimeLimit = seconds(1.f / limit); + m_frameTimeLimit = seconds(1.f / static_cast(limit)); else m_frameTimeLimit = Time::Zero; } diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index fc6f780d..1b6c9486 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -90,7 +90,7 @@ void WindowBase::create(VideoMode mode, const String& title, Uint32 style) if (getFullscreenWindow()) { err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~Style::Fullscreen; + style &= ~static_cast(Style::Fullscreen); } else { @@ -109,7 +109,7 @@ void WindowBase::create(VideoMode mode, const String& title, Uint32 style) // Check validity of style according to the underlying platform #if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) if (style & Style::Fullscreen) - style &= ~Style::Titlebar; + style &= ~static_cast(Style::Titlebar); else style |= Style::Titlebar; #else diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 93ddbeda..a13ce40d 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -208,7 +208,7 @@ void WindowImpl::processJoystickEvents() Joystick::Axis axis = static_cast(j); float prevPos = m_previousAxes[i][axis]; float currPos = m_joystickStates[i].axes[axis]; - if (fabs(currPos - prevPos) >= m_joystickThreshold) + if (std::abs(currPos - prevPos) >= m_joystickThreshold) { Event event; event.type = Event::JoystickMoved;