Root/
| 1 | /* |
| 2 | * gui/icons.c - Icons |
| 3 | * |
| 4 | * Written 2016 by Werner Almesberger |
| 5 | * Copyright 2016 by Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <stdint.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | #include <cairo/cairo.h> |
| 17 | |
| 18 | #include "gui/icons.h" |
| 19 | |
| 20 | |
| 21 | cairo_surface_t *icon_delta; |
| 22 | cairo_surface_t *icon_diff; |
| 23 | |
| 24 | |
| 25 | struct read_ctx { |
| 26 | uint8_t *data; |
| 27 | unsigned left; |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | static uint8_t data_delta[] = { |
| 32 | #include "icons/delta.hex" |
| 33 | }; |
| 34 | |
| 35 | static uint8_t data_diff[] = { |
| 36 | #include "icons/diff.hex" |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | static cairo_status_t read_data(void *user, unsigned char *data, |
| 41 | unsigned length) |
| 42 | { |
| 43 | struct read_ctx *read_ctx = user; |
| 44 | |
| 45 | if (!read_ctx->left) |
| 46 | return CAIRO_STATUS_READ_ERROR; |
| 47 | if (length > read_ctx->left) |
| 48 | length = read_ctx->left; |
| 49 | memcpy(data, read_ctx->data, length); |
| 50 | read_ctx->data += length; |
| 51 | read_ctx->left -= length; |
| 52 | return CAIRO_STATUS_SUCCESS; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | static cairo_surface_t *get_icon(uint8_t *data, unsigned size) |
| 57 | { |
| 58 | struct read_ctx read_ctx = { |
| 59 | .data = data, |
| 60 | .left = size, |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | return cairo_image_surface_create_from_png_stream(read_data, &read_ctx); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void icons_init(void) |
| 69 | { |
| 70 | icon_delta = get_icon(data_delta, sizeof(data_delta)); |
| 71 | icon_diff = get_icon(data_diff, sizeof(data_diff)); |
| 72 | |
| 73 | } |
| 74 |
Branches:
master
