From e33f7551793780e437ea8f7eb447097b2a02bc2c Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Aug 2016 01:25:49 -0300 Subject: [PATCH] eeshow/: add icon loader and icons for "delta" and "diff" --- eeshow/Makefile | 17 +++++++++- eeshow/gui/gui.c | 1 + eeshow/gui/icons.c | 73 ++++++++++++++++++++++++++++++++++++++++++ eeshow/gui/icons.h | 25 +++++++++++++++ eeshow/icons/delta.fig | 15 +++++++++ eeshow/icons/diff.fig | 15 +++++++++ 6 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 eeshow/gui/icons.c create mode 100644 eeshow/gui/icons.h create mode 100644 eeshow/icons/delta.fig create mode 100644 eeshow/icons/diff.fig diff --git a/eeshow/Makefile b/eeshow/Makefile index 5a6d0a7..6dc7654 100644 --- a/eeshow/Makefile +++ b/eeshow/Makefile @@ -10,18 +10,22 @@ # (at your option) any later version. # +SHELL = /bin/bash + NAME = eeshow OBJS = main.o version.o \ kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \ kicad/lib-render.o kicad/dwg.o kicad/delta.o \ gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \ gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \ - gui/help.o \ + gui/help.o gui/icons.o \ file/file.o file/git-util.o file/git-file.o file/git-hist.o \ gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \ gfx/text.o gfx/misc.o \ misc/diag.o +ICONS = delta diff + CFLAGS = -g -Wall -Wextra -Wno-unused-parameter -Wshadow \ -Wmissing-prototypes -Wmissing-declarations \ -I. \ @@ -64,6 +68,17 @@ gui/help.c: help.inc clean:: rm -f help.inc +icons/%.hex: icons/%.fig + $(BUILD) fig2dev -L png -S 4 -Z 0.48 $< | \ + convert - -transparent white - | \ + hexdump -v -e '/1 "0x%x, "' >$@; \ + [ "$${PIPESTATUS[*]}" = "0 0 0" ] || { rm -f $@; exit 1; } + +gui/icons.c: $(ICONS:%=icons/%.hex) + +clean:: + rm -f $(ICONS:%=icons/%.hex) + #----- Test sheet ------------------------------------------------------------- sch: diff --git a/eeshow/gui/gui.c b/eeshow/gui/gui.c index 229a14d..acfabf4 100644 --- a/eeshow/gui/gui.c +++ b/eeshow/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/eeshow/gui/icons.c b/eeshow/gui/icons.c new file mode 100644 index 0000000..df59a8d --- /dev/null +++ b/eeshow/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 +#include + +#include + +#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/eeshow/gui/icons.h b/eeshow/gui/icons.h new file mode 100644 index 0000000..fa712a9 --- /dev/null +++ b/eeshow/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 + + +extern cairo_surface_t *icon_delta; +extern cairo_surface_t *icon_diff; + + +void icons_init(void); + +#endif /* !GUI_ICONS_H */ diff --git a/eeshow/icons/delta.fig b/eeshow/icons/delta.fig new file mode 100644 index 0000000..b3e6ee2 --- /dev/null +++ b/eeshow/icons/delta.fig @@ -0,0 +1,15 @@ +#FIG 3.2 Produced by xfig version 3.2.5c +Landscape +Center +Metric +A4 +100.00 +Single +-2 +1200 2 +2 3 0 0 0 0 50 -1 20 0.000 1 0 -1 0 0 4 + 4950 6075 5535 4725 6300 6075 4950 6075 +2 3 0 1 0 7 40 -1 20 0.000 1 0 -1 0 0 4 + 5130 5940 5490 5085 5985 5940 5130 5940 +2 2 0 1 7 7 100 -1 -1 0.000 0 0 -1 0 0 5 + 4950 6075 6300 6075 6300 4725 4950 4725 4950 6075 diff --git a/eeshow/icons/diff.fig b/eeshow/icons/diff.fig new file mode 100644 index 0000000..75c30f6 --- /dev/null +++ b/eeshow/icons/diff.fig @@ -0,0 +1,15 @@ +#FIG 3.2 Produced by xfig version 3.2.5c +Landscape +Center +Metric +A4 +100.00 +Single +-2 +1200 2 +2 2 0 1 7 7 100 -1 -1 0.000 0 0 -1 0 0 5 + 4950 6075 6300 6075 6300 4725 4950 4725 4950 6075 +2 3 0 10 4 7 50 -1 -1 0.000 1 0 -1 0 0 4 + 4995 6030 5400 5085 5850 6030 4995 6030 +2 3 0 12 12 7 40 -1 -1 0.000 1 0 7 0 0 4 + 5400 5760 5805 4815 6255 5760 5400 5760