Embedded window icon (cross platform)

This commit is contained in:
2024-01-29 15:16:25 +01:00
parent 998cdceb16
commit c67345268e
6 changed files with 42961 additions and 9 deletions

View File

@ -8,12 +8,14 @@
#include <SDL_ttf.h>
#include <iostream>
#include "SDL.h"
#include "icon.h"
class SdlWrapper {
private:
const uint8_t fps = 60;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Surface *iconSurface;
protected:
SDL_Point screenSize;
bool running = true;
@ -30,15 +32,30 @@ public:
std::cerr << "Failed to initialize TTF: " << TTF_GetError() << std::endl;
exit(-1);
}
window = SDL_CreateWindow(
title,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
screenSize.x,
screenSize.y,
0
);
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenSize.x, screenSize.y,
0);
if (window == nullptr) {
std::cerr << "Failed to create SDL_Window with error: " << SDL_GetError() << std::endl;
exit(-1);
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == nullptr) {
std::cerr << "Failed to create SDL_Renderer with error: " << SDL_GetError() << std::endl;
exit(-1);
}
SDL_RWops *ops = SDL_RWFromConstMem(icon, iconLength);
if (ops == nullptr) {
std::cerr << "Failed to load from constant memory with error: " << SDL_GetError() << std::endl;
exit(-1);
}
iconSurface = SDL_LoadBMP_RW(ops, 1);
if (iconSurface == nullptr) {
std::cerr << "Failed to load BMP from SDL_RWops with error: " << SDL_GetError() << std::endl;
exit(-1);
}
SDL_SetWindowIcon(window, iconSurface);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
@ -48,6 +65,7 @@ public:
virtual ~SdlWrapper() {
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_FreeSurface(iconSurface);
SDL_Quit();
}

42864
src/icon.cpp Normal file

File diff suppressed because it is too large Load Diff

6
src/icon.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <cstddef>
extern const unsigned char icon[];
extern const size_t iconLength;