summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-21 01:25:49 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-21 01:26:31 -0300
commit67e532a767139a5bfa018959c67d865c0ce2b282 (patch)
tree37ac8bbc53c51253d8eecd39dbbae156f7c8bfd3 /gui
parent1e9a00d75484668e08350e4af4cf92960287361f (diff)
downloadeeshow-67e532a767139a5bfa018959c67d865c0ce2b282.tar.gz
eeshow-67e532a767139a5bfa018959c67d865c0ce2b282.tar.bz2
eeshow-67e532a767139a5bfa018959c67d865c0ce2b282.zip
eeshow/: add icon loader and icons for "delta" and "diff"
Diffstat (limited to 'gui')
-rw-r--r--gui/gui.c1
-rw-r--r--gui/icons.c73
-rw-r--r--gui/icons.h25
3 files changed, 99 insertions, 0 deletions
diff --git a/gui/gui.c b/gui/gui.c
index 229a14d..acfabf4 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -430,6 +430,7 @@ int gui(unsigned n_args, char **args, bool recurse, int limit)
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
+ icons_init();
sheet_setup(&ctx);
render_setup(&ctx);
diff --git a/gui/icons.c b/gui/icons.c
new file mode 100644
index 0000000..df59a8d
--- /dev/null
+++ b/gui/icons.c
@@ -0,0 +1,73 @@
+/*
+ * gui/icons.c - Icons
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <cairo/cairo.h>
+
+#include "gui/icons.h"
+
+
+cairo_surface_t *icon_delta;
+cairo_surface_t *icon_diff;
+
+
+struct read_ctx {
+ uint8_t *data;
+ unsigned left;
+};
+
+
+static uint8_t data_delta[] = {
+#include "icons/delta.hex"
+};
+
+static uint8_t data_diff[] = {
+#include "icons/diff.hex"
+};
+
+
+static cairo_status_t read_data(void *user, unsigned char *data,
+ unsigned length)
+{
+ struct read_ctx *read_ctx = user;
+
+ if (!read_ctx->left)
+ return CAIRO_STATUS_READ_ERROR;
+ if (length > read_ctx->left)
+ length = read_ctx->left;
+ memcpy(data, read_ctx->data, length);
+ read_ctx->data += length;
+ read_ctx->left -= length;
+ return CAIRO_STATUS_SUCCESS;
+}
+
+
+static cairo_surface_t *get_icon(uint8_t *data, unsigned size)
+{
+ struct read_ctx read_ctx = {
+ .data = data,
+ .left = size,
+ };
+
+
+ return cairo_image_surface_create_from_png_stream(read_data, &read_ctx);
+}
+
+
+void icons_init(void)
+{
+ icon_delta = get_icon(data_delta, sizeof(data_delta));
+ icon_diff = get_icon(data_diff, sizeof(data_diff));
+
+}
diff --git a/gui/icons.h b/gui/icons.h
new file mode 100644
index 0000000..fa712a9
--- /dev/null
+++ b/gui/icons.h
@@ -0,0 +1,25 @@
+/*
+ * gui/icons.h - Icons
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GUI_ICONS_H
+#define GUI_ICONS_H
+
+#include <cairo/cairo.h>
+
+
+extern cairo_surface_t *icon_delta;
+extern cairo_surface_t *icon_diff;
+
+
+void icons_init(void);
+
+#endif /* !GUI_ICONS_H */