From 9f6c5d27b423832637a98aba6dfbf7d4a211ab36 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 12 May 2023 23:41:21 +0300 Subject: [PATCH 27/27] gui API: Add 'svgflag' parameter to load_gfxfile() See osdn #48033 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/pages.c | 2 +- client/gui-gtk-3.22/sprite.c | 2 +- client/gui-gtk-4.0/pages.c | 2 +- client/gui-gtk-4.0/sprite.c | 34 +++++++++++++++++----------------- client/gui-qt/qtg_cxxside.h | 2 +- client/gui-qt/sprite.cpp | 6 +++--- client/gui-sdl2/sprite.c | 6 +++--- client/gui-sdl2/themespec.c | 8 ++++---- client/gui-stub/sprite.c | 6 +++--- client/gui_interface.c | 4 ++-- client/gui_interface.h | 2 +- client/include/sprite_g.h | 12 ++++++++---- client/svgflag.h | 2 +- client/tilespec.c | 18 ++++++++++-------- 14 files changed, 56 insertions(+), 50 deletions(-) diff --git a/client/gui-gtk-3.22/pages.c b/client/gui-gtk-3.22/pages.c index 75df105a5f..97c20235ad 100644 --- a/client/gui-gtk-3.22/pages.c +++ b/client/gui-gtk-3.22/pages.c @@ -248,7 +248,7 @@ GtkWidget *create_main_page(void) gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT); gtk_container_add(GTK_CONTAINER(vbox), frame); - intro_in = load_gfxfile(tileset_main_intro_filename(tileset)); + intro_in = load_gfxfile(tileset_main_intro_filename(tileset), FALSE); get_sprite_dimensions(intro_in, &width, &height); sh = screen_height(); diff --git a/client/gui-gtk-3.22/sprite.c b/client/gui-gtk-3.22/sprite.c index 85b6ed99b0..7262e01416 100644 --- a/client/gui-gtk-3.22/sprite.c +++ b/client/gui-gtk-3.22/sprite.c @@ -167,7 +167,7 @@ static void surf_destroy_callback(void *data) entire image file, which may later be broken up into individual sprites with crop_sprite(). ****************************************************************************/ -struct sprite *load_gfxfile(const char *filename) +struct sprite *load_gfxfile(const char *filename, bool svgflag) { struct sprite *spr; GError *err = NULL; diff --git a/client/gui-gtk-4.0/pages.c b/client/gui-gtk-4.0/pages.c index 09c7f9c502..e30b93dd9e 100644 --- a/client/gui-gtk-4.0/pages.c +++ b/client/gui-gtk-4.0/pages.c @@ -254,7 +254,7 @@ GtkWidget *create_main_page(void) gtk_widget_set_halign(frame, GTK_ALIGN_CENTER); gtk_grid_attach(GTK_GRID(vgrid), frame, 0, grid_row++, 1, 1); - intro_in = load_gfxfile(tileset_main_intro_filename(tileset)); + intro_in = load_gfxfile(tileset_main_intro_filename(tileset), FALSE); get_sprite_dimensions(intro_in, &width, &height); sh = screen_height(); diff --git a/client/gui-gtk-4.0/sprite.c b/client/gui-gtk-4.0/sprite.c index f87472fbae..69c5c53b96 100644 --- a/client/gui-gtk-4.0/sprite.c +++ b/client/gui-gtk-4.0/sprite.c @@ -167,7 +167,7 @@ static void surf_destroy_callback(void *data) entire image file, which may later be broken up into individual sprites with crop_sprite(). ****************************************************************************/ -struct sprite *load_gfxfile(const char *filename) +struct sprite *load_gfxfile(const char *filename, bool svgflag) { struct sprite *spr; GError *err = NULL; @@ -275,7 +275,7 @@ struct sprite *load_gfxfile(const char *filename) /************************************************************************//** Free a sprite and all associated image data. ****************************************************************************/ -void free_sprite(struct sprite * s) +void free_sprite(struct sprite *s) { if (s->surface != NULL) { cairo_surface_destroy(s->surface); @@ -318,8 +318,8 @@ struct sprite *sprite_scale(struct sprite *src, int new_w, int new_h) object/mask. The bounding box contains the border (pixel which have unset pixel as neighbours) pixel. ****************************************************************************/ -void sprite_get_bounding_box(struct sprite * sprite, int *start_x, - int *start_y, int *end_x, int *end_y) +void sprite_get_bounding_box(struct sprite *sprite, int *start_x, + int *start_y, int *end_x, int *end_y) { unsigned char *data = cairo_image_surface_get_data(sprite->surface); int width = cairo_image_surface_get_width(sprite->surface); @@ -335,46 +335,46 @@ void sprite_get_bounding_box(struct sprite * sprite, int *start_x, fc_assert(cairo_image_surface_get_format(sprite->surface) == CAIRO_FORMAT_ARGB32); - /* parses mask image for the first column that contains a visible pixel */ + /* Parses mask image for the first column that contains a visible pixel */ *start_x = -1; for (i = 0; i < width && *start_x == -1; i++) { for (j = 0; j < height; j++) { if (data[(j * width + i) * 4 + endian]) { - *start_x = i; - break; + *start_x = i; + break; } } } - /* parses mask image for the last column that contains a visible pixel */ + /* Parses mask image for the last column that contains a visible pixel */ *end_x = -1; for (i = width - 1; i >= *start_x && *end_x == -1; i--) { for (j = 0; j < height; j++) { if (data[(j * width + i) * 4 + endian]) { - *end_x = i; - break; + *end_x = i; + break; } } } - /* parses mask image for the first row that contains a visible pixel */ + /* Parses mask image for the first row that contains a visible pixel */ *start_y = -1; for (i = 0; i < height && *start_y == -1; i++) { for (j = *start_x; j <= *end_x; j++) { if (data[(i * width + j) * 4 + endian]) { - *start_y = i; - break; + *start_y = i; + break; } } } - /* parses mask image for the last row that contains a visible pixel */ + /* Parses mask image for the last row that contains a visible pixel */ *end_y = -1; for (i = height - 1; i >= *end_y && *end_y == -1; i--) { for (j = *start_x; j <= *end_x; j++) { if (data[(i * width + j) * 4 + endian]) { - *end_y = i; - break; + *end_y = i; + break; } } } @@ -429,7 +429,7 @@ GdkPixbuf *surface_get_pixbuf(cairo_surface_t *surf, int width, int height) rowstride = gdk_pixbuf_get_rowstride(pb); tmpsurf = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32, - width, height, rowstride); + width, height, rowstride); cr = cairo_create(tmpsurf); cairo_save(cr); diff --git a/client/gui-qt/qtg_cxxside.h b/client/gui-qt/qtg_cxxside.h index 50f02a7fa1..06a9b88018 100644 --- a/client/gui-qt/qtg_cxxside.h +++ b/client/gui-qt/qtg_cxxside.h @@ -41,7 +41,7 @@ void qtg_real_output_window_append(const char *astring, bool qtg_is_view_supported(enum ts_type type); void qtg_tileset_type_set(enum ts_type type); -struct sprite *qtg_load_gfxfile(const char *filename); +struct sprite *qtg_load_gfxfile(const char *filename, bool svgflag); struct sprite *qtg_load_gfxnumber(int num); struct sprite *qtg_create_sprite(int width, int height, struct color *pcolor); void qtg_get_sprite_dimensions(struct sprite *sprite, int *width, int *height); diff --git a/client/gui-qt/sprite.cpp b/client/gui-qt/sprite.cpp index 36ec24eefc..8dc11af7d6 100644 --- a/client/gui-qt/sprite.cpp +++ b/client/gui-qt/sprite.cpp @@ -60,11 +60,11 @@ const char **gfx_fileextensions(void) } /************************************************************************//** - Load the given graphics file into a sprite. This function loads an + Load the given graphics file into a sprite. This function loads an entire image file, which may later be broken up into individual sprites - with crop_sprite. + with crop_sprite(). ****************************************************************************/ -struct sprite *qtg_load_gfxfile(const char *filename) +struct sprite *qtg_load_gfxfile(const char *filename, bool svgflag) { sprite *entire = new sprite; QPixmap *pm = new QPixmap; diff --git a/client/gui-sdl2/sprite.c b/client/gui-sdl2/sprite.c index b573556d5c..4cf05a2adc 100644 --- a/client/gui-sdl2/sprite.c +++ b/client/gui-sdl2/sprite.c @@ -66,11 +66,11 @@ const char **gfx_fileextensions(void) } /************************************************************************//** - Load the given graphics file into a sprite. This function loads an + Load the given graphics file into a sprite. This function loads an entire image file, which may later be broken up into individual sprites - with crop_sprite. + with crop_sprite(). ****************************************************************************/ -struct sprite *load_gfxfile(const char *filename) +struct sprite *load_gfxfile(const char *filename, bool svgflag) { SDL_Surface *pbuf = NULL; diff --git a/client/gui-sdl2/themespec.c b/client/gui-sdl2/themespec.c index 07cd335db1..d37e5bf699 100644 --- a/client/gui-sdl2/themespec.c +++ b/client/gui-sdl2/themespec.c @@ -448,7 +448,7 @@ void themespec_reread(const char *new_theme_name) Loads the given graphics file (found in the data path) into a newly allocated sprite. ****************************************************************************/ -static struct sprite *load_gfx_file(const char *gfx_filename) +static struct sprite *load_sdl2_gfx_file(const char *gfx_filename) { const char **gfx_fileexts = gfx_fileextensions(), *gfx_fileext; struct sprite *s; @@ -462,7 +462,7 @@ static struct sprite *load_gfx_file(const char *gfx_filename) sprintf(full_name, "%s.%s", gfx_filename, gfx_fileext); if ((real_full_name = fileinfoname(get_data_dirs(), full_name))) { log_debug("trying to load gfx file \"%s\".", real_full_name); - s = load_gfxfile(real_full_name); + s = load_gfxfile(real_full_name, FALSE); if (s) { return s; } @@ -502,7 +502,7 @@ static void theme_ensure_big_sprite(struct specfile *sf) gfx_filename = secfile_lookup_str(file, "file.gfx"); - sf->big_sprite = load_gfx_file(gfx_filename); + sf->big_sprite = load_sdl2_gfx_file(gfx_filename); if (!sf->big_sprite) { log_fatal("Could not load gfx file for the spec file \"%s\".", @@ -856,7 +856,7 @@ static struct sprite *theme_load_sprite(struct theme *t, const char *tag_name) /* If the sprite hasn't been loaded already, then load it. */ fc_assert_ret_val(ss->ref_count == 0, NULL); if (ss->file) { - ss->sprite = load_gfx_file(ss->file); + ss->sprite = load_sdl2_gfx_file(ss->file); if (!ss->sprite) { log_fatal("Couldn't load gfx file \"%s\" for sprite '%s'.", ss->file, tag_name); diff --git a/client/gui-stub/sprite.c b/client/gui-stub/sprite.c index 23b6da97b0..4377fe9a3a 100644 --- a/client/gui-stub/sprite.c +++ b/client/gui-stub/sprite.c @@ -42,11 +42,11 @@ const char **gfx_fileextensions(void) } /************************************************************************//** - Load the given graphics file into a sprite. This function loads an + Load the given graphics file into a sprite. This function loads an entire image file, which may later be broken up into individual sprites - with crop_sprite. + with crop_sprite(). ****************************************************************************/ -struct sprite *gui_load_gfxfile(const char *filename) +struct sprite *gui_load_gfxfile(const char *filename, bool svgflag) { /* PORTME */ return NULL; diff --git a/client/gui_interface.c b/client/gui_interface.c index afdb294ea8..c61f53d964 100644 --- a/client/gui_interface.c +++ b/client/gui_interface.c @@ -122,9 +122,9 @@ void tileset_type_set(enum ts_type type) /**********************************************************************//** Call load_gfxfile callback **************************************************************************/ -struct sprite *load_gfxfile(const char *filename) +struct sprite *load_gfxfile(const char *filename, bool svgflag) { - return funcs.load_gfxfile(filename); + return funcs.load_gfxfile(filename, svgflag); } /**********************************************************************//** diff --git a/client/gui_interface.h b/client/gui_interface.h index aa8a084ee1..9c77a2233b 100644 --- a/client/gui_interface.h +++ b/client/gui_interface.h @@ -49,7 +49,7 @@ struct gui_funcs { bool (*is_view_supported)(enum ts_type type); void (*tileset_type_set)(enum ts_type type); - struct sprite * (*load_gfxfile)(const char *filename); + struct sprite * (*load_gfxfile)(const char *filename, bool svgflag); struct sprite * (*load_gfxnumber)(int num); struct sprite * (*create_sprite)(int width, int height, struct color *pcolor); void (*get_sprite_dimensions)(struct sprite *sprite, int *width, int *height); diff --git a/client/include/sprite_g.h b/client/include/sprite_g.h index 64f8887f2c..dff91657ba 100644 --- a/client/include/sprite_g.h +++ b/client/include/sprite_g.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team 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 @@ -13,15 +13,19 @@ #ifndef FC__SPRITE_G_H #define FC__SPRITE_G_H +/* utility */ #include "support.h" + +/* client */ #include "gui_proto_constructor.h" -struct sprite; /* opaque type, real type is gui-dep */ +struct sprite; /* Opaque type, real type is gui-dep */ struct color; GUI_FUNC_PROTO(const char **, gfx_fileextensions, void) -GUI_FUNC_PROTO(struct sprite *, load_gfxfile, const char *filename) +GUI_FUNC_PROTO(struct sprite *, load_gfxfile, const char *filename, + bool svgflag) GUI_FUNC_PROTO(struct sprite *, load_gfxnumber, int num) GUI_FUNC_PROTO(struct sprite *, crop_sprite, struct sprite *source, int x, int y, int width, int height, @@ -33,4 +37,4 @@ GUI_FUNC_PROTO(void, get_sprite_dimensions, struct sprite *sprite, int *width, int *height) GUI_FUNC_PROTO(void, free_sprite, struct sprite *s) -#endif /* FC__SPRITE_G_H */ +#endif /* FC__SPRITE_G_H */ diff --git a/client/svgflag.h b/client/svgflag.h index 3aedf56f06..0ebc198080 100644 --- a/client/svgflag.h +++ b/client/svgflag.h @@ -18,7 +18,7 @@ extern "C" { #endif /* __cplusplus */ struct canvas; - + struct area_rect { int x, y, w, h; diff --git a/client/tilespec.c b/client/tilespec.c index 5ac6e26c2d..ed81cab2fa 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -1534,12 +1534,12 @@ void tilespec_reread_frozen_refresh(const char *tname) Loads the given graphics file (found in the data path) into a newly allocated sprite. ****************************************************************************/ -static struct sprite *load_gfx_file(const char *gfx_filename, bool flag) +static struct sprite *load_gfx_file(const char *gfx_filename, bool svgflag) { const char **gfx_fileexts, *gfx_fileext; struct sprite *s; - if (flag) { + if (svgflag) { gfx_fileexts = ordered_gfx_fextensions(); } else { gfx_fileexts = gfx_fileextensions(); @@ -1554,7 +1554,8 @@ static struct sprite *load_gfx_file(const char *gfx_filename, bool flag) sprintf(full_name, "%s.%s", gfx_filename, gfx_fileext); if ((real_full_name = fileinfoname(get_data_dirs(), full_name))) { log_debug("trying to load gfx file \"%s\".", real_full_name); - s = load_gfxfile(real_full_name); + s = load_gfxfile(real_full_name, + svgflag && !strcmp("svg", gfx_fileext)); if (s) { return s; } @@ -2691,7 +2692,7 @@ static char *valid_index_str(const struct tileset *t, int idx) other scaling algorithm than nearest neighbor. ****************************************************************************/ static struct sprite *load_sprite(struct tileset *t, const char *tag_name, - bool scale, bool smooth, bool flag) + bool scale, bool smooth, bool svgflag) { struct small_sprite *ss; float sprite_scale = 1.0f; @@ -2713,7 +2714,7 @@ static struct sprite *load_sprite(struct tileset *t, const char *tag_name, struct sprite *s; if (scale) { - s = load_gfx_file(ss->file, flag); + s = load_gfx_file(ss->file, svgflag); if (s != NULL) { get_sprite_dimensions(s, &w, &h); @@ -2722,7 +2723,7 @@ static struct sprite *load_sprite(struct tileset *t, const char *tag_name, free_sprite(s); } } else { - ss->sprite = load_gfx_file(ss->file, flag); + ss->sprite = load_gfx_file(ss->file, svgflag); } if (!ss->sprite) { @@ -4424,14 +4425,15 @@ void tileset_setup_nation_flag(struct tileset *t, int i; struct sprite *flag = NULL, *shield = NULL; char buf[1024]; + bool svgflag = is_svg_flag_enabled(); for (i = 0; tags[i] && !flag; i++) { fc_snprintf(buf, sizeof(buf), "f.%s", tags[i]); - flag = load_sprite(t, buf, TRUE, TRUE, TRUE); + flag = load_sprite(t, buf, TRUE, TRUE, svgflag); } for (i = 0; tags[i] && !shield; i++) { fc_snprintf(buf, sizeof(buf), "f.shield.%s", tags[i]); - shield = load_sprite(t, buf, TRUE, TRUE, TRUE); + shield = load_sprite(t, buf, TRUE, TRUE, svgflag); } if (!flag || !shield) { /* Should never get here because of the f.unknown fallback. */ -- 2.39.2