Add an icon to pyrogenesis' application window

Tested By: Imarok (Windows, Ubuntu w. Gnome), s0600204 (Arch w. Xfce),
ffffffff (Kubuntu w. KDE)
Reviewed By: ffffffff, s0600204
Differential Revision: https://code.wildfiregames.com/D768
Trac Tickets: #4363

This was SVN commit r20067.
This commit is contained in:
s0600204 2017-08-28 21:56:54 +00:00
parent 8da0f129ef
commit 27d99765bb
3 changed files with 43 additions and 1 deletions

View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:91638e41ce1347dc11a6c47be34330c9076092fda2103b72d4b6e0a54756d483
size 73199

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -26,9 +26,11 @@
#include "lib/ogl.h"
#include "lib/external_libraries/libsdl.h"
#include "lib/sysdep/gfx.h"
#include "lib/tex/tex.h"
#include "ps/CConsole.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/Filesystem.h"
#include "ps/Game.h"
#include "ps/GameSetup/Config.h"
#include "renderer/Renderer.h"
@ -255,6 +257,8 @@ bool CVideoMode::InitSDL()
m_WindowedH = h;
}
SetWindowIcon();
return true;
}
@ -488,3 +492,36 @@ SDL_Window* CVideoMode::GetWindow()
ENSURE(m_IsInitialised);
return m_Window;
}
void CVideoMode::SetWindowIcon()
{
std::shared_ptr<u8> iconFile;
size_t iconFileSize;
if (g_VFS->LoadFile("art/textures/icons/window.png", iconFile, iconFileSize) != INFO::OK)
{
LOGWARNING("Window icon not found.");
return;
}
Tex iconTexture;
if (iconTexture.decode(iconFile, iconFileSize) != INFO::OK)
return;
// Convert to required BGRA format.
const size_t iconFlags = (iconTexture.m_Flags | TEX_BGR) & ~TEX_DXT;
if (iconTexture.transform_to(iconFlags) != INFO::OK)
return;
void* bgra_img = iconTexture.get_data();
if (!bgra_img)
return;
SDL_Surface *iconSurface = SDL_CreateRGBSurfaceFrom(bgra_img,
iconTexture.m_Width, iconTexture.m_Height, 32, iconTexture.m_Width * 4,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
if (!iconSurface)
return;
SDL_SetWindowIcon(m_Window, iconSurface);
SDL_FreeSurface(iconSurface);
}

View file

@ -80,6 +80,8 @@ public:
SDL_Window* GetWindow();
void SetWindowIcon();
private:
void ReadConfig();
int GetBestBPP();