Skip to content

Commit

Permalink
Load Window Icon from the Resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Feb 23, 2024
1 parent d4652fb commit ae93067
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/musializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -46,7 +52,6 @@ int main(void)

CloseAudioDevice();
CloseWindow();
UnloadImage(logo);

return 0;
}
24 changes: 12 additions & 12 deletions src/plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 2 additions & 0 deletions src/plug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down

0 comments on commit ae93067

Please sign in to comment.