From ae93067b4f40fdc4e0fee7c9311b7918b208c945 Mon Sep 17 00:00:00 2001 From: rexim Date: Fri, 23 Feb 2024 08:09:43 +0700 Subject: [PATCH] Load Window Icon from the Resources --- src/musializer.c | 11 ++++++++--- src/plug.c | 24 ++++++++++++------------ src/plug.h | 2 ++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/musializer.c b/src/musializer.c index 38f9557..423248e 100644 --- a/src/musializer.c +++ b/src/musializer.c @@ -25,11 +25,17 @@ int main(void) if (!reload_libplug()) return 1; - Image logo = LoadImage("./resources/logo/logo-256.png"); SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_ALWAYS_RUN); size_t factor = 80; InitWindow(factor*16, factor*9, "Musializer"); - SetWindowIcon(logo); + { + const char *file_path = "./resources/logo/logo-256.png"; + size_t data_size; + void *data = plug_load_resource(file_path, &data_size); + Image logo = LoadImageFromMemory(GetFileExtension(file_path), data, data_size); + SetWindowIcon(logo); + plug_free_resource(data); + } SetTargetFPS(60); SetExitKey(KEY_NULL); InitAudioDevice(); @@ -46,7 +52,6 @@ int main(void) CloseAudioDevice(); CloseWindow(); - UnloadImage(logo); return 0; } diff --git a/src/plug.c b/src/plug.c index e1e7117..1a6e63f 100644 --- a/src/plug.c +++ b/src/plug.c @@ -19,12 +19,12 @@ #ifndef MUSIALIZER_UNBUNDLE #include "bundle.h" -void free_resource_data(void *data) +void plug_free_resource(void *data) { (void) data; } -void *load_resource_data(const char *file_path, size_t *size) +void *plug_load_resource(const char *file_path, size_t *size) { for (size_t i = 0; i < resources_count; ++i) { if (strcmp(resources[i].file_path, file_path) == 0) { @@ -37,12 +37,12 @@ void *load_resource_data(const char *file_path, size_t *size) #else -void free_resource_data(void *data) +void plug_free_resource(void *data) { UnloadFileData(data); } -void *load_resource_data(const char *file_path, size_t *size) +void *plug_load_resource(const char *file_path, size_t *size) { int dataSize; void *data = LoadFileData(file_path, &dataSize); @@ -246,9 +246,9 @@ static Image assets_image(const char *file_path) item.key = file_path; size_t data_size; - void *data = load_resource_data(file_path, &data_size); + void *data = plug_load_resource(file_path, &data_size); item.value = LoadImageFromMemory(GetFileExtension(file_path), data, data_size); - free_resource_data(data); + plug_free_resource(data); nob_da_append(&p->assets.images, item); return item.value; @@ -1621,9 +1621,9 @@ void plug_init(void) const char *alegreya_path = "./resources/fonts/Alegreya-Regular.ttf"; { size_t data_size; - void *data = load_resource_data(alegreya_path, &data_size); + void *data = plug_load_resource(alegreya_path, &data_size); p->font = LoadFontFromMemory(GetFileExtension(alegreya_path), data, data_size, FONT_SIZE, NULL, 0); - free_resource_data(data); + plug_free_resource(data); } GenTextureMipmaps(&p->font.texture); SetTextureFilter(p->font.texture, TEXTURE_FILTER_BILINEAR); @@ -1635,9 +1635,9 @@ void plug_init(void) // special. { size_t data_size; - void *data = load_resource_data(TextFormat("./resources/shaders/glsl%d/circle.fs", GLSL_VERSION), &data_size); + void *data = plug_load_resource(TextFormat("./resources/shaders/glsl%d/circle.fs", GLSL_VERSION), &data_size); p->circle = LoadShaderFromMemory(NULL, data); - free_resource_data(data); + plug_free_resource(data); } p->circle_radius_location = GetShaderLocation(p->circle, "radius"); p->circle_power_location = GetShaderLocation(p->circle, "power"); @@ -1668,9 +1668,9 @@ void plug_post_reload(Plug *pp) UnloadShader(p->circle); size_t data_size; - void *data = load_resource_data(TextFormat("./resources/shaders/glsl%d/circle.fs", GLSL_VERSION), &data_size); + void *data = plug_load_resource(TextFormat("./resources/shaders/glsl%d/circle.fs", GLSL_VERSION), &data_size); p->circle = LoadShaderFromMemory(NULL, data); - free_resource_data(data); + plug_free_resource(data); p->circle_radius_location = GetShaderLocation(p->circle, "radius"); p->circle_power_location = GetShaderLocation(p->circle, "power"); } diff --git a/src/plug.h b/src/plug.h index bf24e74..89bcfe7 100644 --- a/src/plug.h +++ b/src/plug.h @@ -5,6 +5,8 @@ PLUG(plug_init, void, void) \ PLUG(plug_pre_reload, void*, void) \ PLUG(plug_post_reload, void, void*) \ + PLUG(plug_load_resource, void*, const char*, size_t*) \ + PLUG(plug_free_resource, void, void*) \ PLUG(plug_update, void, void) #define PLUG(name, ret, ...) typedef ret (name##_t)(__VA_ARGS__);