Ticket #4363: set_window_icon.patch

File set_window_icon.patch, 1.5 KB (added by Vladislav Belov, 4 years ago)
  • source/ps/VideoMode.cpp

     
    2626#include "lib/ogl.h"
    2727#include "lib/external_libraries/libsdl.h"
    2828#include "lib/sysdep/gfx.h"
     29#include "lib/tex/tex.h"
    2930#include "ps/CConsole.h"
    3031#include "ps/CLogger.h"
    3132#include "ps/ConfigDB.h"
     33#include "ps/Filesystem.h"
    3234#include "ps/Game.h"
    3335#include "ps/GameSetup/Config.h"
    3436#include "renderer/Renderer.h"
     
    255257        m_WindowedH = h;
    256258    }
    257259
     260#ifdef OS_WIN
     261    const VfsPath iconPath("art/textures/icons/0ad_64.png"); // or load from config
     262#else
     263    // TODO: set path
     264#endif
     265
     266    // Setup the titlebar icon
     267    std::shared_ptr<u8> iconFile;
     268    size_t iconFileSize;
     269    if (g_VFS->LoadFile(iconPath, iconFile, iconFileSize) != INFO::OK)
     270        return false;
     271    Tex iconTexture;
     272    if (iconTexture.decode(iconFile, iconFileSize) != INFO::OK)
     273        return false;
     274
     275    // Convert to required BGRA format.
     276    const size_t iconFlags = (iconTexture.m_Flags | TEX_BGR) & ~TEX_DXT;
     277    if (iconTexture.transform_to(iconFlags) != INFO::OK)
     278        return false;
     279
     280    void* bgra_img = iconTexture.get_data();
     281    if (!bgra_img)
     282        return false;
     283
     284    SDL_Surface *iconSurface = SDL_CreateRGBSurfaceFrom(bgra_img, iconTexture.m_Width, iconTexture.m_Height, 32, iconTexture.m_Width * 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
     285    if (!iconSurface)
     286        return false;
     287    SDL_SetWindowIcon(m_Window, iconSurface);
     288    SDL_FreeSurface(iconSurface);
     289
    258290    return true;
    259291}
    260292