Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/svgflag.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
svgflag.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "mem.h"
21#include "support.h"
22
23/* client */
24#include "canvas_g.h"
25#include "sprite_g.h"
26
27#include "svgflag.h"
28
29
30 bool _prefer_svg = FALSE;
31
32 static const char **ordered_extensions = NULL;
33
34/**********************************************************************/
39 bool svg_flag_enable(void)
40{
41#ifdef FREECIV_SVG_FLAGS
42 _prefer_svg = TRUE;
43
44 return TRUE;
45#else // FREECIV_SVG_FLAGS
46 return FALSE;
47#endif // FREECIV_SVG_FLAGS
48}
49
50/**********************************************************************/
53 const char **ordered_gfx_fextensions(void)
54{
55 const char **incoming;
56
57 if (ordered_extensions != NULL) {
58 return ordered_extensions;
59 }
60
61 incoming = gfx_fileextensions();
62
63 if (is_svg_flag_enabled()) {
64 int count;
65 int svg = -1;
66 int i;
67
68 for (count = 0; incoming[count] != NULL; count++) {
69 if (!fc_strcasecmp("svg", incoming[count])) {
70 svg = count;
71 }
72 }
73
74 if (svg < 0) {
75 /* No svg, disable svg flag features */
76 _prefer_svg = FALSE;
77
78 log_warn(_("Client has no required support for svg. "
79 "Disabled use of svg flags."));
80
81 ordered_extensions = incoming;
82 } else {
83 log_verbose(_("Client is capable of using svg flags."));
84 }
85
86 ordered_extensions = fc_malloc((count + 1) * sizeof(char *));
87
88 /* Put svg first */
89 ordered_extensions[0] = incoming[svg];
90
91 for (i = 0; i < svg; i++) {
92 ordered_extensions[i + 1] = incoming[i];
93 }
94 for (; i < count; i++) {
95 ordered_extensions[i] = incoming[i];
96 }
97 ordered_extensions[i] = NULL;
98
99 } else {
100 ordered_extensions = incoming;
101 }
102
103 return ordered_extensions;
104}
105
106/**********************************************************************/
109 void free_svg_flag_API(void)
110{
111 if (ordered_extensions != NULL) {
112 if (is_svg_flag_enabled()) {
113 free(ordered_extensions);
114 }
115
116 ordered_extensions = NULL;
117 }
118}
119
120/**********************************************************************/
123 void get_flag_dimensions(struct sprite *flag, struct area_rect *rect,
124 int svg_height)
125{
126 get_sprite_dimensions(flag, &(rect->w), &(rect->h));
127
128 if (is_svg_flag_enabled()) {
129 rect->w = rect->w * svg_height / rect->h;
130 rect->h = svg_height;
131 }
132}
133
134/**********************************************************************/
137 void canvas_put_flag_sprite(struct canvas *pcanvas,
138 int canvas_x, int canvas_y, int canvas_w, int canvas_h,
139 struct sprite *flag)
140{
141 if (is_svg_flag_enabled()) {
142 canvas_put_sprite_full_scaled(pcanvas, canvas_x, canvas_y, canvas_w, canvas_h,
143 flag);
144 } else {
145 canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, flag);
146 }
147}
canvas_g.h
canvas_y
struct canvas int int canvas_y
Definition canvas_g.h:43
canvas_x
struct canvas int canvas_x
Definition canvas_g.h:43
canvas_w
struct canvas int int int canvas_w
Definition canvas_g.h:49
canvas_h
struct canvas int int int int canvas_h
Definition canvas_g.h:49
pcanvas
struct canvas * pcanvas
Definition canvas_g.h:42
canvas_put_sprite_full_scaled
canvas_put_sprite_full_scaled
Definition canvas_g.h:48
incite_cost
char * incite_cost
Definition comments.c:74
fcintl.h
_
#define _(String)
Definition fcintl.h:67
canvas_put_sprite_full
void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite)
Definition canvas.c:144
gfx_fileextensions
const char ** gfx_fileextensions(void)
Definition sprite.c:117
log_warn
#define log_warn(message,...)
Definition log.h:105
log_verbose
#define log_verbose(message,...)
Definition log.h:109
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
sprite_g.h
get_sprite_dimensions
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
area_rect
Definition svgflag.h:23
area_rect::w
int w
Definition svgflag.h:24
area_rect::h
int h
Definition svgflag.h:24
canvas
Definition canvas.h:22
sprite
Definition sprite.h:22
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
free_svg_flag_API
void free_svg_flag_API(void)
Definition svgflag.c:109
canvas_put_flag_sprite
void canvas_put_flag_sprite(struct canvas *pcanvas, int canvas_x, int canvas_y, int canvas_w, int canvas_h, struct sprite *flag)
Definition svgflag.c:137
_prefer_svg
bool _prefer_svg
Definition svgflag.c:30
svg_flag_enable
bool svg_flag_enable(void)
Definition svgflag.c:39
ordered_extensions
static const char ** ordered_extensions
Definition svgflag.c:32
ordered_gfx_fextensions
const char ** ordered_gfx_fextensions(void)
Definition svgflag.c:53
get_flag_dimensions
void get_flag_dimensions(struct sprite *flag, struct area_rect *rect, int svg_height)
Definition svgflag.c:123
svgflag.h
is_svg_flag_enabled
#define is_svg_flag_enabled()
Definition svgflag.h:30