Freeciv-3.3
Loading...
Searching...
No Matches
sprite.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/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#include <SDL_image.h>
22#else /* SDL2_PLAIN_INCLUDE */
23#include <SDL2/SDL.h>
24#include <SDL2/SDL_image.h>
25#endif /* SDL2_PLAIN_INCLUDE */
26
27/* utility */
28#include "fcintl.h"
29#include "log.h"
30#include "mem.h"
31
32/* client/gui-sdl2 */
33#include "colors.h"
34#include "graphics.h"
35
36#include "sprite.h"
37
38static struct sprite *ctor_sprite(SDL_Surface *surf);
39
40/************************************************************************/
45const char **gfx_fileextensions(void)
46{
47 static const char *ext[] = {
48 "png",
49 "gif",
50 "jpeg",
51 "xpm",
52 "qoi",
53 "tga",
54 "bmp",
55 "xcf",
56 "pcx",
57 "lbm",
58 "ppm",
59 "pgm",
60 "pbm",
61 "svg",
62 NULL
63 };
64
65 return ext;
66}
67
68/************************************************************************/
73struct sprite *load_gfxfile(const char *filename, bool svgflag)
74{
76
77 if ((pbuf = IMG_Load(filename)) == NULL) {
78 log_error(_("load_gfxfile: Unable to load graphic file %s!"), filename);
79 return NULL; /* Should I use abort() ? */
80 }
81
82 if (pbuf->format->palette != NULL) {
84
86 pbuf = pnew;
87 }
88
89 return ctor_sprite(pbuf);
90}
91
92/************************************************************************/
118 int x, int y, int width, int height,
119 struct sprite *mask,
121 float scale, bool smooth)
122{
126
127 if (mask) {
130 return ctor_sprite(pdest);
131 }
132
133 return ctor_sprite(psrc);
134}
135
136/************************************************************************/
139struct sprite *create_sprite(int width, int height, struct color *pcolor)
140{
142
146
147 if (is_bigendian()) {
149 0x0000FF00, 0x00FF0000,
150 0xFF000000, 0x000000FF);
151 } else {
153 0x00FF0000, 0x0000FF00,
154 0x000000FF, 0xFF000000);
155 }
156
158 SDL_MapRGBA(mypixbuf->format,
159 pcolor->color->r,
160 pcolor->color->g,
161 pcolor->color->b,
162 pcolor->color->a));
163
164 return ctor_sprite(mypixbuf);
165}
166
167/************************************************************************/
171{
172 *width = GET_SURF(sprite)->w;
173 *height = GET_SURF(sprite)->h;
174}
175
176/************************************************************************/
179void free_sprite(struct sprite *s)
180{
181 fc_assert_ret(s != NULL);
183 FC_FREE(s);
184}
185
186/************************************************************************/
189static struct sprite *ctor_sprite(SDL_Surface *surf)
190{
191 struct sprite *result = fc_malloc(sizeof(struct sprite));
192
193 result->psurface = surf;
194
195 return result;
196}
197
198/************************************************************************/
201struct sprite *load_gfxnumber(int num)
202{
203 /* Not supported in sdl2-client */
204 return NULL;
205}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:76
#define _(String)
Definition fcintl.h:67
static GtkWidget * source
Definition gotodlg.c:58
void free_sprite(struct sprite *s)
Definition sprite.c:278
struct sprite * create_sprite(int width, int height, struct color *pcolor)
Definition sprite.c:84
struct sprite * load_gfxnumber(int num)
Definition sprite.c:526
struct sprite * load_gfxfile(const char *filename, bool svgflag)
Definition sprite.c:170
const char ** gfx_fileextensions(void)
Definition sprite.c:117
SDL_Surface * mask_surface(SDL_Surface *src, SDL_Surface *mask, int mask_offset_x, int mask_offset_y)
Definition graphics.c:262
SDL_Surface * crop_rect_from_surface(SDL_Surface *psource, SDL_Rect *prect)
Definition graphics.c:236
SDL_Surface * convert_surf(SDL_Surface *surf_in)
Definition graphics.c:359
#define FREESURFACE(ptr)
Definition graphics.h:322
static struct sprite * ctor_sprite(SDL_Surface *surf)
Definition sprite.c:189
#define GET_SURF(m_sprite)
Definition sprite.h:29
#define GET_SURF_REAL(m_sprite)
Definition sprite.h:26
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_error(message,...)
Definition log.h:104
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
struct sprite int int int int struct sprite * mask
Definition sprite_g.h:32
struct sprite int int y
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct sprite int int int int struct sprite int mask_offset_x
Definition sprite_g.h:32
struct sprite int x
Definition sprite_g.h:31
crop_sprite
Definition sprite_g.h:30
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
struct sprite int int int int struct sprite int int mask_offset_y
Definition sprite_g.h:32
Definition colors.h:21
struct SDL_Surface * psurface
Definition sprite.h:21
static bool is_bigendian(void)
Definition support.h:235