diff options
author | James Magahern <james@magahern.com> | 2019-01-19 16:21:12 -0800 |
---|---|---|
committer | James Magahern <james@magahern.com> | 2019-01-19 16:21:35 -0800 |
commit | c5a1692fe40d3442062d4f1b71f94eaa63f9e494 (patch) | |
tree | 12982bac3783fdee28330d2ef7b6e0de27c09ae4 | |
parent | Started to split x11 stuff to separate files (diff) |
Switch to using gresources for svgs
-rw-r--r-- | meson.build | 28 | ||||
-rw-r--r-- | resources/buzzsaver.gresource.xml | 9 | ||||
-rw-r--r-- | src/render.c | 38 |
3 files changed, 58 insertions, 17 deletions
diff --git a/meson.build b/meson.build index 4849f05..52804bb 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,7 @@ project('buzzlocker', 'c') +gnome = import('gnome') # for gresources + sources = [ 'src/main.c', 'src/render.c', @@ -10,24 +12,20 @@ dependencies = [ dependency('x11'), dependency('cairo'), dependency('librsvg-2.0'), - dependency('pangocairo') + dependency('pangocairo'), + dependency('gio-2.0'), ] -executable('buzzlocker', - sources: sources, - dependencies: dependencies -) - # Resources -configure_file( - input: 'resources/logo.svg', - output: 'logo.svg', - copy: true +resources = gnome.compile_resources( + 'resources', + 'resources/buzzsaver.gresource.xml', + source_dir: 'resources', + c_name: 'as' ) -configure_file( - input: 'resources/asterisk.svg', - output: 'asterisk.svg', - copy: true +executable('buzzlocker', + sources: sources + resources, + dependencies: dependencies, + install: true ) - diff --git a/resources/buzzsaver.gresource.xml b/resources/buzzsaver.gresource.xml new file mode 100644 index 0000000..7523c4a --- /dev/null +++ b/resources/buzzsaver.gresource.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/"> + <file>resources/asterisk.svg</file> + <file>resources/logo.svg</file> +</gresource> +</gresources> + + diff --git a/src/render.c b/src/render.c index e9a5ef3..1439b08 100644 --- a/src/render.c +++ b/src/render.c @@ -5,20 +5,49 @@ */ #include "render.h" +#include "resources.h" +#include <gio/gio.h> static const double kLogoBackgroundWidth = 500.0; +GBytes* get_data_for_resource(const char *resource_path) +{ + GBytes *result = NULL; + GError *error = NULL; + + GResource *resource = as_get_resource(); + result = g_resource_lookup_data( + resource, + resource_path, + G_RESOURCE_LOOKUP_FLAGS_NONE, + &error + ); + + if (error != NULL) { + fprintf(stderr, "Error loading resource %s\n", resource_path); + } + + return result; +} + void draw_logo(saver_state_t *state) { if (state->logo_svg_handle == NULL) { GError *error = NULL; - state->logo_svg_handle = rsvg_handle_new_from_file("logo.svg", &error); + GBytes *bytes = get_data_for_resource("/resources/logo.svg"); + + gsize size = 0; + gconstpointer data = g_bytes_get_data(bytes, &size); + state->logo_svg_handle = rsvg_handle_new_from_data(data, size, &error); + g_bytes_unref(bytes); if (error != NULL) { fprintf(stderr, "Error loading logo SVG\n"); + return; } } + cairo_t *cr = state->ctx; cairo_save(cr); @@ -68,7 +97,12 @@ void draw_password_field(saver_state_t *state) // Draw password asterisks if (state->asterisk_svg_handle == NULL) { GError *error = NULL; - state->asterisk_svg_handle = rsvg_handle_new_from_file("asterisk.svg", &error); + GBytes *bytes = get_data_for_resource("/resources/asterisk.svg"); + + gsize size = 0; + gconstpointer data = g_bytes_get_data(bytes, &size); + state->asterisk_svg_handle = rsvg_handle_new_from_data(data, size, &error); + g_bytes_unref(bytes); if (error != NULL) { fprintf(stderr, "Error loading asterisk SVG\n"); return; |