Freeciv-3.2
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 "xpm",
50 NULL
51 };
52
53 return ext;
54}
55
56/************************************************************************/
61struct sprite *load_gfxfile(const char *filename, bool svgflag)
62{
64
65 if ((pbuf = IMG_Load(filename)) == NULL) {
66 log_error(_("load_gfxfile: Unable to load graphic file %s!"), filename);
67 return NULL; /* Should I use abort() ? */
68 }
69
70 if (pbuf->format->palette != NULL) {
72
74 pbuf = pnew;
75 }
76
77 return ctor_sprite(pbuf);
78}
79
80/************************************************************************/
106 int x, int y, int width, int height,
107 struct sprite *mask,
109 float scale, bool smooth)
110{
114
115 if (mask) {
118 return ctor_sprite(pdest);
119 }
120
121 return ctor_sprite(psrc);
122}
123
124/************************************************************************/
127struct sprite *create_sprite(int width, int height, struct color *pcolor)
128{
130
134
135 if (is_bigendian()) {
137 0x0000FF00, 0x00FF0000,
138 0xFF000000, 0x000000FF);
139 } else {
141 0x00FF0000, 0x0000FF00,
142 0x000000FF, 0xFF000000);
143 }
144
146 SDL_MapRGBA(mypixbuf->format,
147 pcolor->color->r,
148 pcolor->color->g,
149 pcolor->color->b,
150 pcolor->color->a));
151
152 return ctor_sprite(mypixbuf);
153}
154
155/************************************************************************/
159{
160 *width = GET_SURF(sprite)->w;
161 *height = GET_SURF(sprite)->h;
162}
163
164/************************************************************************/
167void free_sprite(struct sprite *s)
168{
169 fc_assert_ret(s != NULL);
171 FC_FREE(s);
172}
173
174/************************************************************************/
177static struct sprite *ctor_sprite(SDL_Surface *surf)
178{
179 struct sprite *result = fc_malloc(sizeof(struct sprite));
180
181 result->psurface = surf;
182
183 return result;
184}
185
186/************************************************************************/
189struct sprite *load_gfxnumber(int num)
190{
191 /* Not supported in sdl2-client */
192 return NULL;
193}
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:75
#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:177
#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:191
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
#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