Add an SDL window icon for Windows

This commit is contained in:
Cameron Gutman
2018-07-22 17:07:45 -07:00
parent 83b81aad4b
commit 9d840afdfb
2 changed files with 28 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
QT += core quick network quickcontrols2 QT += core quick network quickcontrols2 svg
CONFIG += c++11 CONFIG += c++11
unix:!macx { unix:!macx {
+27
View File
@@ -19,11 +19,16 @@
#define SDL_OS_FULLSCREEN_FLAG SDL_WINDOW_FULLSCREEN #define SDL_OS_FULLSCREEN_FLAG SDL_WINDOW_FULLSCREEN
#endif #endif
#define ICON_SIZE 32
#include <openssl/rand.h> #include <openssl/rand.h>
#include <QtEndian> #include <QtEndian>
#include <QCoreApplication> #include <QCoreApplication>
#include <QThreadPool> #include <QThreadPool>
#include <QSvgRenderer>
#include <QPainter>
#include <QImage>
CONNECTION_LISTENER_CALLBACKS Session::k_ConnCallbacks = { CONNECTION_LISTENER_CALLBACKS Session::k_ConnCallbacks = {
Session::clStageStarting, Session::clStageStarting,
@@ -615,6 +620,25 @@ void Session::exec()
SDL_SetWindowSize(m_Window, width, height); SDL_SetWindowSize(m_Window, width, height);
} }
QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg"));
QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888);
svgImage.fill(0);
QPainter svgPainter(&svgImage);
svgIconRenderer.render(&svgPainter);
SDL_Surface* iconSurface = SDL_CreateRGBSurfaceWithFormatFrom((void*)svgImage.constBits(),
svgImage.width(),
svgImage.height(),
32,
4 * svgImage.width(),
SDL_PIXELFORMAT_RGBA32);
#ifdef Q_OS_WIN32
// Other platforms seem to preserve our Qt icon when creating a new window
if (iconSurface != nullptr) {
SDL_SetWindowIcon(m_Window, iconSurface);
}
#endif
#ifndef QT_DEBUG #ifndef QT_DEBUG
// Capture the mouse by default on release builds only. // Capture the mouse by default on release builds only.
// This prevents the mouse from becoming trapped inside // This prevents the mouse from becoming trapped inside
@@ -741,6 +765,9 @@ DispatchDeferredCleanup:
SDL_AtomicUnlock(&m_DecoderLock); SDL_AtomicUnlock(&m_DecoderLock);
SDL_DestroyWindow(m_Window); SDL_DestroyWindow(m_Window);
if (iconSurface != nullptr) {
SDL_FreeSurface(iconSurface);
}
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_assert(!SDL_WasInit(SDL_INIT_VIDEO)); SDL_assert(!SDL_WasInit(SDL_INIT_VIDEO));