Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl2/themespec.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
themespec.c File Reference
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "capability.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "registry.h"`
`#include "string_vector.h"`
`#include "game.h"`
`#include "citydlg_common.h"`
`#include "client_main.h"`
`#include "dialogs.h"`
`#include "gui_tilespec.h"`
`#include "mapview.h"`
`#include "sprite.h"`
`#include "themespec.h"`
`#include "speclist.h"`
`#include "spechash.h"`

Go to the source code of this file.

## Data Structures

struct | specfile
struct | small_sprite
struct | theme

## Macros

#define | THEMESPEC_SDL2_CAPSTR "+Freeciv-sdl2-3.3-themespec-Devel-2023-Jun-07 duplicates_ok"
#define | SPEC_SDL2_CAPSTR "+Freeciv-sdl2-3.3-spec-Devel-2023-Jun-10"
#define | THEMESPEC_SUFFIX ".themespec"
#define | SPECLIST_TAG specfile
#define | SPECLIST_TYPE struct specfile
#define | specfile_list_iterate(list, pitem) TYPED_LIST_ITERATE(struct specfile, list, pitem)
#define | specfile_list_iterate_end LIST_ITERATE_END
#define | SPECLIST_TAG small_sprite
#define | SPECLIST_TYPE struct small_sprite
#define | small_sprite_list_iterate(list, pitem) TYPED_LIST_ITERATE(struct small_sprite, list, pitem)
#define | small_sprite_list_iterate_end LIST_ITERATE_END
#define | SPECHASH_TAG small_sprite
#define | SPECHASH_IKEY_TYPE char *
#define | SPECHASH_IDATA_TYPE struct small_sprite *
#define | SPECHASH_IKEY_VAL genhash_str_val_func
#define | SPECHASH_IKEY_COMP genhash_str_comp_func
#define | SPECHASH_IKEY_COPY genhash_str_copy_func
#define | SPECHASH_IKEY_FREE genhash_str_free_func
#define | small_sprite_hash_iterate(hash, tag_name, pitem)
#define | small_sprite_hash_iterate_end HASH_ITERATE_END
#define | SET_SPRITE(field, tag)
#define | SET_SPRITE_ALT(field, tag, alt)
#define | SET_SPRITE_OPT(field, tag) t->sprites.field = theme_load_sprite(t, tag)
#define | SET_SPRITE_ALT_OPT(field, tag, alt)
#define | FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)
#define | FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)
#define | ADD_SPRITE(s, draw_fog, x_offset, y_offset)
#define | ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
#define | ADD_SPRITE_FULL(s) ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)

## Functions

const char * | theme_get_name (const struct theme *t)
const char * | theme_font_filename (const struct theme *t)
int | theme_default_font_size (const struct theme *t)
static struct theme * | theme_new (void)
const char ** | get_theme_list (void)
static char * | themespec_fullname (const char *theme_name)
static bool | check_themespec_capabilities (struct section_file *file, const char *which, const char *us_capstr, const char *filename)
static void | theme_free_toplevel (struct theme *t)
void | theme_free (struct theme *ftheme)
void | themespec_try_read (const char *theme_name)
void | themespec_reread (const char *new_theme_name)
static struct sprite * | load_sdl2_gfx_file (const char *gfx_filename)
static void | theme_ensure_big_sprite (struct specfile *sf)
static void | scan_specfile (struct theme *t, struct specfile *sf, bool duplicates_ok)
char * | themespec_gfx_filename (const char *gfx_filename)
struct theme * | theme_read_toplevel (const char *theme_name)
static struct sprite * | theme_load_sprite (struct theme *t, const char *tag_name)
static void | theme_unload_sprite (struct theme *t, const char *tag_name)
static void | theme_lookup_sprite_tags (struct theme *t)
static void | theme_finish_loading_sprites (struct theme *t)
void | theme_load_sprites (struct theme *t)
struct sprite * | theme_lookup_sprite_tag_alt (struct theme *t, enum log_level level, const char *tag, const char *alt, const char *what, const char *name)
static void | theme_unload_all_sprites (struct theme *t)
void | theme_free_sprites (struct theme *t)
struct theme_background_system * | theme_get_background_system (const struct theme *t)
struct theme_color_system * | theme_get_color_system (const struct theme *t)

## Variables

struct theme * | active_theme = NULL

## Macro Definition Documentation

## ◆ ADD_SPRITE

#define ADD_SPRITE | ( |  | s,
|  |  | draw_fog,
|  |  | x_offset,
|  |  | y_offset
| ) |  |

Value:
(fc_assert(s != NULL), \
sprs->sprite = s, \
sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO), \
sprs->offset_x = x_offset, \
sprs->offset_y = y_offset, \
sprs++)
incite_cost
char * incite_cost
Definition comments.c:74
fc_assert
#define fc_assert(condition)
Definition log.h:176

Definition at line 1037 of file themespec.c.

## ◆ ADD_SPRITE_FULL

#define ADD_SPRITE_FULL | ( |  | s | ) | ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)

Definition at line 1045 of file themespec.c.

## ◆ ADD_SPRITE_SIMPLE

#define ADD_SPRITE_SIMPLE | ( |  | s | ) | ADD_SPRITE(s, TRUE, 0, 0)

Definition at line 1044 of file themespec.c.

## ◆ FULL_TILE_X_OFFSET

#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)

Definition at line 1034 of file themespec.c.

## ◆ FULL_TILE_Y_OFFSET

#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)

Definition at line 1035 of file themespec.c.

## ◆ SET_SPRITE

#define SET_SPRITE | ( |  | field,
|  |  | tag
| ) |  |

Value:
do { \
t->sprites.field = theme_load_sprite(t, tag); \
fc_assert_exit_msg(NULL != t->sprites.field, \
"Sprite tag '%s' missing.", tag); \
} while (FALSE)
theme_load_sprite
static struct sprite * theme_load_sprite(struct theme *t, const char *tag_name)
Definition themespec.c:855
FALSE
#define FALSE
Definition support.h:47

Definition at line 925 of file themespec.c.

## ◆ SET_SPRITE_ALT

#define SET_SPRITE_ALT | ( |  | field,
|  |  | tag,
|  |  | alt
| ) |  |

Value:
do { \
t->sprites.field = theme_load_sprite(t, tag); \
if (!t->sprites.field) { \
t->sprites.field = theme_load_sprite(t, alt); \
} \
fc_assert_exit_msg(NULL != t->sprites.field, \
"Sprite tag '%s' and alternate '%s' are " \
"both missing.", tag, alt); \
} while (FALSE)

Definition at line 933 of file themespec.c.

## ◆ SET_SPRITE_ALT_OPT

#define SET_SPRITE_ALT_OPT | ( |  | field,
|  |  | tag,
|  |  | alt
| ) |  |

Value:
do { \
t->sprites.field = theme_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt,\
"sprite", #field); \
} while (FALSE)
theme_lookup_sprite_tag_alt
struct sprite * theme_lookup_sprite_tag_alt(struct theme *t, enum log_level level, const char *tag, const char *alt, const char *what, const char *name)
Definition themespec.c:1000
LOG_VERBOSE
@ LOG_VERBOSE
Definition log.h:33

Definition at line 948 of file themespec.c.

## ◆ SET_SPRITE_OPT

#define SET_SPRITE_OPT | ( |  | field,
|  |  | tag
| ) |  | t->sprites.field = theme_load_sprite(t, tag)

Definition at line 945 of file themespec.c.

## ◆ small_sprite_hash_iterate

#define small_sprite_hash_iterate | ( |  | hash,
|  |  | tag_name,
|  |  | pitem
| ) |  |

Value:
TYPED_HASH_ITERATE(const char *, struct small_sprite *, hash, \
tag_name, pitem)
tag_name
char * tag_name
Definition events.c:77
hash
static GHashTable * hash
Definition wldlg.c:322
TYPED_HASH_ITERATE
#define TYPED_HASH_ITERATE(TYPE_key, TYPE_data, ARG_ht, NAME_key, NAME_data)
Definition spechash.h:726
small_sprite
Definition themespec.c:96

Definition at line 128 of file themespec.c.

## ◆ small_sprite_hash_iterate_end

#define small_sprite_hash_iterate_end HASH_ITERATE_END

Definition at line 131 of file themespec.c.

## ◆ small_sprite_list_iterate

#define small_sprite_list_iterate | ( |  | list,
|  |  | pitem
| ) |  | TYPED_LIST_ITERATE(struct small_sprite, list, pitem)

Definition at line 116 of file themespec.c.

## ◆ small_sprite_list_iterate_end

#define small_sprite_list_iterate_end LIST_ITERATE_END

Definition at line 118 of file themespec.c.

## ◆ SPEC_SDL2_CAPSTR

#define SPEC_SDL2_CAPSTR "+Freeciv-sdl2-3.3-spec-Devel-2023-Jun-10"

Definition at line 62 of file themespec.c.

## ◆ specfile_list_iterate

#define specfile_list_iterate | ( |  | list,
|  |  | pitem
| ) |  | TYPED_LIST_ITERATE(struct specfile, list, pitem)

Definition at line 87 of file themespec.c.

## ◆ specfile_list_iterate_end

#define specfile_list_iterate_end LIST_ITERATE_END

Definition at line 89 of file themespec.c.

## ◆ SPECHASH_IDATA_TYPE

#define SPECHASH_IDATA_TYPE struct small_sprite *

Definition at line 122 of file themespec.c.

## ◆ SPECHASH_IKEY_COMP

#define SPECHASH_IKEY_COMP genhash_str_comp_func

Definition at line 124 of file themespec.c.

## ◆ SPECHASH_IKEY_COPY

#define SPECHASH_IKEY_COPY genhash_str_copy_func

Definition at line 125 of file themespec.c.

## ◆ SPECHASH_IKEY_FREE

#define SPECHASH_IKEY_FREE genhash_str_free_func

Definition at line 126 of file themespec.c.

## ◆ SPECHASH_IKEY_TYPE

#define SPECHASH_IKEY_TYPE char *

Definition at line 121 of file themespec.c.

## ◆ SPECHASH_IKEY_VAL

#define SPECHASH_IKEY_VAL genhash_str_val_func

Definition at line 123 of file themespec.c.

## ◆ SPECHASH_TAG

#define SPECHASH_TAG small_sprite

Definition at line 120 of file themespec.c.

## ◆ SPECLIST_TAG [1/2]

#define SPECLIST_TAG specfile

Definition at line 83 of file themespec.c.

## ◆ SPECLIST_TAG [2/2]

#define SPECLIST_TAG small_sprite

Definition at line 83 of file themespec.c.

## ◆ SPECLIST_TYPE [1/2]

#define SPECLIST_TYPE struct specfile

Definition at line 84 of file themespec.c.

## ◆ SPECLIST_TYPE [2/2]

#define SPECLIST_TYPE struct small_sprite

Definition at line 84 of file themespec.c.

## ◆ THEMESPEC_SDL2_CAPSTR

#define THEMESPEC_SDL2_CAPSTR "+Freeciv-sdl2-3.3-themespec-Devel-2023-Jun-07 duplicates_ok"

Definition at line 50 of file themespec.c.

## ◆ THEMESPEC_SUFFIX

#define THEMESPEC_SUFFIX ".themespec"

Definition at line 69 of file themespec.c.

## Function Documentation

## ◆ check_themespec_capabilities()

static bool check_themespec_capabilities | ( | struct section_file * | file,
|  | const char * | which,
|  | const char * | us_capstr,
|  | const char * | filename
| ) |  |

static

Checks options in filename match what we require and support. Die if not. 'which' should be "themespec" or "spec".

Definition at line 256 of file themespec.c.

Referenced by scan_specfile(), theme_ensure_big_sprite(), and theme_read_toplevel().

## ◆ get_theme_list()

const char ** get_theme_list | ( | void |  | ) |

Returns a static list of themes available on the system by searching all data directories for files matching THEMESPEC_SUFFIX. The list is NULL-terminated.

Definition at line 200 of file themespec.c.

## ◆ load_sdl2_gfx_file()

static struct sprite * load_sdl2_gfx_file | ( | const char * | gfx_filename | ) |

static

Loads the given graphics file (found in the data path) into a newly allocated sprite.

Definition at line 456 of file themespec.c.

Referenced by theme_ensure_big_sprite(), and theme_load_sprite().

## ◆ scan_specfile()

static void scan_specfile | ( | struct theme * | t,
|  | struct specfile * | sf,
|  | bool | duplicates_ok
| ) |  |

static

Scan all sprites declared in the given specfile. This means that the positions of the sprites in the big_sprite are saved in the small_sprite structs.

Definition at line 530 of file themespec.c.

Referenced by theme_read_toplevel().

## ◆ theme_default_font_size()

int theme_default_font_size | ( | const struct theme * | t | ) |

Return theme's default font size.

Definition at line 177 of file themespec.c.

Referenced by default_font_size().

## ◆ theme_ensure_big_sprite()

static void theme_ensure_big_sprite | ( | struct specfile * | sf | ) |

static

Ensure that the big sprite of the given spec file is loaded.

Definition at line 485 of file themespec.c.

Referenced by theme_load_sprite().

## ◆ theme_finish_loading_sprites()

static void theme_finish_loading_sprites | ( | struct theme * | t | ) |

static

Frees any internal buffers which are created by theme_load_sprite. Should be called after the last (for a given period of time) theme_load_sprite call. This saves a fair amount of memory, but it will take extra time the next time we start loading sprites again.

Definition at line 974 of file themespec.c.

Referenced by theme_load_sprites().

## ◆ theme_font_filename()

const char * theme_font_filename | ( | const struct theme * | t | ) |

Return the path within the data directories where the font file can be found. (It is left up to the GUI code to load and unload this file.)

Definition at line 169 of file themespec.c.

Referenced by load_font().

## ◆ theme_free()

void theme_free | ( | struct theme * | ftheme | ) |

Free resources allocated for the theme.

Definition at line 317 of file themespec.c.

Referenced by get_theme_list(), gui_load_theme(), theme_read_toplevel(), themespec_try_read(), and ui_main().

## ◆ theme_free_sprites()

void theme_free_sprites | ( | struct theme * | t | ) |

Free all sprites for the theme.

Definition at line 1065 of file themespec.c.

Referenced by theme_free(), and themespec_reread().

## ◆ theme_free_toplevel()

static void theme_free_toplevel | ( | struct theme * | t | ) |

static

Frees the themespec toplevel data, in preparation for re-reading it.

See themespec_read_toplevel().

Definition at line 294 of file themespec.c.

Referenced by theme_free(), and themespec_reread().

## ◆ theme_get_background_system()

struct theme_background_system * theme_get_background_system | ( | const struct theme * | t | ) |

Return the theme's background system.

Definition at line 1114 of file themespec.c.

Referenced by theme_get_background().

## ◆ theme_get_color_system()

struct theme_color_system * theme_get_color_system | ( | const struct theme * | t | ) |

Return the theme's color system.

Definition at line 1122 of file themespec.c.

Referenced by theme_get_color().

## ◆ theme_get_name()

const char * theme_get_name | ( | const struct theme * | t | ) |

Return the name of the given theme.

Definition at line 160 of file themespec.c.

## ◆ theme_load_sprite()

static struct sprite * theme_load_sprite | ( | struct theme * | t,
|  | const char * | tag_name
| ) |  |

static

Loads the sprite. If the sprite is already loaded a reference counter is increased. Can return NULL if the sprite couldn't be loaded.

Definition at line 855 of file themespec.c.

Referenced by theme_lookup_sprite_tag_alt().

## ◆ theme_load_sprites()

void theme_load_sprites | ( | struct theme * | t | ) |

Load the tiles; requires themespec_read_toplevel() called previously. Leads to tile_sprites being allocated and filled with pointers to sprites. Also sets up and populates sprite_hash, and calls func to initialize 'sprites' structure.

Definition at line 990 of file themespec.c.

Referenced by gui_load_theme(), and themespec_reread().

## ◆ theme_lookup_sprite_tag_alt()

struct sprite * theme_lookup_sprite_tag_alt | ( | struct theme * | t,
|  | enum log_level | level,
|  | const char * | tag,
|  | const char * | alt,
|  | const char * | what,
|  | const char * | name
| ) |  |

Lookup sprite to match tag, or else to match alt if don't find, or else return NULL, and emit log message.

Definition at line 1000 of file themespec.c.

Referenced by tilespec_setup_city_gfx().

## ◆ theme_lookup_sprite_tags()

static void theme_lookup_sprite_tags | ( | struct theme * | t | ) |

static

Initialize 'sprites' structure based on hardwired tags which the client always requires.

Definition at line 958 of file themespec.c.

Referenced by theme_load_sprites().

## ◆ theme_new()

static struct theme * theme_new | ( | void |  | ) |

static

Initialize.

Definition at line 185 of file themespec.c.

Referenced by theme_read_toplevel().

## ◆ theme_read_toplevel()

struct theme * theme_read_toplevel | ( | const char * | theme_name | ) |

Finds and reads the toplevel themespec file based on given name. Sets global variables, including tile sizes and full names for intro files.

Definition at line 721 of file themespec.c.

Referenced by get_theme_list(), themespec_reread(), and themespec_try_read().

## ◆ theme_unload_all_sprites()

static void theme_unload_all_sprites | ( | struct theme * | t | ) |

static

Unload all sprites from theme sprite hash (the hash itself is left intact).

Definition at line 1051 of file themespec.c.

Referenced by theme_free_sprites().

## ◆ theme_unload_sprite()

static void theme_unload_sprite | ( | struct theme * | t,
|  | const char * | tag_name
| ) |  |

static

Unloads the sprite. Decrease the reference counter. If the last reference is removed the sprite is freed.

Definition at line 904 of file themespec.c.

Referenced by theme_unload_all_sprites().

## ◆ themespec_fullname()

static char * themespec_fullname | ( | const char * | theme_name | ) |

static

Gets full filename for themespec file, based on input name. Returned data is allocated, and freed by user as required. Input name may be null, in which case uses default. Falls back to default if can't find specified name; dies if can't find default.

Definition at line 233 of file themespec.c.

Referenced by theme_read_toplevel().

## ◆ themespec_gfx_filename()

char * themespec_gfx_filename | ( | const char * | gfx_filename | ) |

Returns the correct name of the gfx file (with path and extension) Must be free'd when no longer used

Definition at line 690 of file themespec.c.

Referenced by theme_background_system_read().

## ◆ themespec_reread()

void themespec_reread | ( | const char * | new_theme_name | ) |

Read a new themespec in from scratch.

Unlike the initial reading code, which reads pieces one at a time, this gets rid of the old data and reads in the new all at once. If the new theme fails to load the old theme may be reloaded; otherwise the client will exit. If a NULL name is given the current theme will be reread.

It will also call the necessary functions to redraw the graphics.

Definition at line 376 of file themespec.c.

## ◆ themespec_try_read()

void themespec_try_read | ( | const char * | theme_name | ) |

Read a new themespec in when first starting the game.

Call this function with the (guessed) name of the theme, when starting the client.

Definition at line 334 of file themespec.c.

Referenced by gui_load_theme().

## Variable Documentation

## ◆ active_theme

struct theme* active_theme = NULL

Definition at line 154 of file themespec.c.

Referenced by arrange_widgets(), draw_intro_gfx(), economy_report_dialog_popup(), get_theme_color(), gui_load_theme(), load_font(), meswin_dialog_popup(), popup_change_research_dialog(), popup_change_research_goal_dialog(), popup_city_cma_dialog(), popup_conn_list_dialog(), popup_connection_dialog(), popup_government_dialog(), popup_impr_info(), popup_join_game_dialog(), popup_load_game_dialog(), popup_new_user_passwd_dialog(), popup_newcity_dialog(), popup_races_dialog(), popup_tech_info(), popup_unit_info(), popup_user_passwd_dialog(), popup_worklist_editor(), real_activeunits_report_dialog_update(), real_city_dialog_popup(), real_info_city_report_dialog_update(), science_report_dialog_popup(), show_main_page(), spy_steal_popup_shared(), themespec_reread(), themespec_try_read(), tilespec_setup_city_gfx(), and ui_main().