Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl3/canvas.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
canvas.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/* SDL3 */
19#include <SDL3/SDL.h>
20#include <SDL3_ttf/SDL_ttf.h>
21
22/* utility */
23#include "log.h"
24#include "mem.h"
25
26/* client/gui-sdl3 */
27#include "colors.h"
28#include "graphics.h"
29#include "gui_main.h"
30#include "gui_string.h"
31#include "sprite.h"
32
33#include "canvas.h"
34
35/**********************************************************************/
38 struct canvas *canvas_create(int width, int height)
39{
40 struct canvas *result = fc_malloc(sizeof(*result));
41
42 result->surf = create_surf(width, height, SDL_SWSURFACE);
43
44 return result;
45}
46
47/**********************************************************************/
51 void canvas_free(struct canvas *store)
52{
53 FREESURFACE(store->surf);
54 free(store);
55}
56
57/**********************************************************************/
60 void canvas_set_zoom(struct canvas *store, float zoom)
61{
62 /* sdl3-client has no zoom support */
63}
64
65/**********************************************************************/
68 bool has_zoom_support(void)
69{
70 return FALSE;
71}
72
73/**********************************************************************/
76 void canvas_mapview_init(struct canvas *store)
77{
78 SDL_SetSurfaceBlendMode(store->surf, SDL_BLENDMODE_NONE);
79}
80
81/**********************************************************************/
84 void canvas_copy(struct canvas *dest, struct canvas *src,
85 int src_x, int src_y, int dest_x, int dest_y, int width,
86 int height)
87{
88 SDL_Rect src_rect = {src_x, src_y, width, height};
89 SDL_Rect dest_rect = {dest_x, dest_y, width, height};
90
91 alphablit(src->surf, &src_rect, dest->surf, &dest_rect, 255);
92}
93
94/**********************************************************************/
97 void canvas_put_sprite(struct canvas *pcanvas,
98 int canvas_x, int canvas_y,
99 struct sprite *sprite,
100 int offset_x, int offset_y, int width, int height)
101{
102 SDL_Rect src = {offset_x, offset_y, width, height};
103 SDL_Rect dst = {canvas_x + offset_x, canvas_y + offset_y, 0, 0};
104
105 alphablit(GET_SURF(sprite), &src, pcanvas->surf, &dst, 255);
106}
107
108/**********************************************************************/
111 void canvas_put_sprite_full(struct canvas *pcanvas,
112 int canvas_x, int canvas_y,
113 struct sprite *sprite)
114{
115 SDL_Rect dst = {canvas_x, canvas_y, 0, 0};
116
117 alphablit(GET_SURF(sprite), NULL, pcanvas->surf, &dst, 255);
118}
119
120/************************************************************************/
123 void canvas_put_sprite_full_scaled(struct canvas *pcanvas,
124 int canvas_x, int canvas_y,
125 int canvas_w, int canvas_h,
126 struct sprite *sprite)
127{
128 /* This should never be called as we have not enabled support
129 * in this client yet. */
130 fc_assert(FALSE);
131}
132
133/**********************************************************************/
137 void canvas_put_sprite_fogged(struct canvas *pcanvas,
138 int canvas_x, int canvas_y,
139 struct sprite *psprite,
140 bool fog, int fog_x, int fog_y)
141{
142 SDL_Rect dst = {canvas_x, canvas_y, 0, 0};
143
144 if (fog) {
145 alphablit(GET_SURF(psprite), NULL, pcanvas->surf, &dst, 160);
146 } else {
147 canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, psprite);
148 }
149}
150
151/**********************************************************************/
154 void canvas_put_rectangle(struct canvas *pcanvas, struct color *pcolor,
155 int canvas_x, int canvas_y, int width, int height)
156{
157 SDL_Rect dst = {canvas_x, canvas_y, width, height};
158
159 SDL_FillSurfaceRect(pcanvas->surf, &dst,
160 SDL_MapRGBA(pcanvas->surf->format,
161 pcolor->color->r,
162 pcolor->color->g,
163 pcolor->color->b,
164 pcolor->color->a));
165}
166
167/**********************************************************************/
170 void canvas_fill_sprite_area(struct canvas *pcanvas,
171 struct sprite *psprite, struct color *pcolor,
172 int canvas_x, int canvas_y)
173{
174 SDL_Rect dst = {canvas_x, canvas_y,
175 GET_SURF(psprite)->w,
176 GET_SURF(psprite)->h};
177
178 SDL_FillSurfaceRect(pcanvas->surf, &dst,
179 SDL_MapRGBA(pcanvas->surf->format,
180 pcolor->color->r,
181 pcolor->color->g,
182 pcolor->color->b,
183 pcolor->color->a));
184}
185
186/**********************************************************************/
189 void canvas_put_line(struct canvas *pcanvas, struct color *pcolor,
190 enum line_type ltype, int start_x, int start_y,
191 int dx, int dy)
192{
193 create_line(pcanvas->surf, start_x, start_y, start_x + dx, start_y + dy, pcolor->color);
194}
195
196/**********************************************************************/
199 void canvas_put_curved_line(struct canvas *pcanvas, struct color *pcolor,
200 enum line_type ltype, int start_x, int start_y,
201 int dx, int dy)
202{
203 /* FIXME: Implement curved line drawing. */
204 canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
205}
206
207/**********************************************************************/
212 void get_text_size(int *width, int *height,
213 enum client_font font, const char *text)
214{
215 utf8_str *ptext = create_utf8_str(NULL, 0, *client_font_sizes[font]);
216 SDL_Rect size;
217
218 fc_assert(width != NULL || height != NULL);
219
220 copy_chars_to_utf8_str(ptext, text);
221 utf8_str_size(ptext, &size);
222
223 if (width) {
224 *width = size.w;
225 }
226
227 if (height) {
228 *height = size.h;
229 }
230
231 FREEUTF8STR(ptext);
232}
233
234/**********************************************************************/
239 void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
240 enum client_font font, struct color *pcolor,
241 const char *text)
242{
243 SDL_Surface *ptmp;
244 utf8_str *ptext = create_utf8_str(NULL, 0, *client_font_sizes[font]);
245
246 copy_chars_to_utf8_str(ptext, text);
247
248 ptext->fgcol = *pcolor->color;
249 ptext->bgcol = (SDL_Color) {0, 0, 0, 0};
250
251 ptmp = create_text_surf_from_utf8(ptext);
252
253 blit_entire_src(ptmp, pcanvas->surf, canvas_x, canvas_y);
254
255 FREEUTF8STR(ptext);
256 FREESURFACE(ptmp);
257}
height
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
pcolor
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
canvas_put_rectangle
struct canvas int int int int struct sprite *sprite canvas_put_rectangle
Definition canvas_g.h:55
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_put_line
struct canvas int int int int struct sprite *sprite struct canvas struct color int int int int height canvas_put_line
Definition canvas_g.h:62
canvas_put_sprite
canvas_put_sprite
Definition canvas_g.h:42
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
canvas_put_text
canvas_put_text
Definition canvas_g.h:80
offset_y
struct canvas int int struct sprite int int offset_y
Definition canvas_g.h:44
offset_x
struct canvas int int struct sprite int offset_x
Definition canvas_g.h:44
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
line_type
line_type
Definition canvas_g.h:25
incite_cost
char * incite_cost
Definition comments.c:74
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
canvas_set_zoom
void canvas_set_zoom(struct canvas *store, float zoom)
Definition canvas.c:53
canvas_mapview_init
void canvas_mapview_init(struct canvas *store)
Definition canvas.c:69
canvas_fill_sprite_area
void canvas_fill_sprite_area(struct canvas *pcanvas, struct sprite *psprite, struct color *pcolor, int canvas_x, int canvas_y)
Definition canvas.c:211
get_text_size
void get_text_size(int *width, int *height, enum client_font font, const char *text)
Definition canvas.c:341
canvas_free
void canvas_free(struct canvas *store)
Definition canvas.c:44
canvas_put_curved_line
void canvas_put_curved_line(struct canvas *pcanvas, struct color *pcolor, enum line_type ltype, int start_x, int start_y, int dx, int dy)
Definition canvas.c:276
has_zoom_support
bool has_zoom_support(void)
Definition canvas.c:61
canvas_copy
void canvas_copy(struct canvas *dest, struct canvas *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.c:76
canvas_create
struct canvas * canvas_create(int width, int height)
Definition canvas.c:28
canvas_put_sprite_fogged
void canvas_put_sprite_fogged(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *psprite, bool fog, int fog_x, int fog_y)
Definition canvas.c:170
create_line
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1381
alphablit
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
blit_entire_src
int blit_entire_src(SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
Definition graphics.c:417
create_surf
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
client_font_sizes
int * client_font_sizes[FONT_COUNT]
Definition gui_main.c:115
utf8_str_size
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
copy_chars_to_utf8_str
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
create_text_surf_from_utf8
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
create_utf8_str
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
Definition gui_string.c:206
FREEUTF8STR
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
GET_SURF
#define GET_SURF(m_sprite)
Definition sprite.h:29
gui_string.h
canvas.h
colors.h
graphics.h
gui_main.h
sprite.h
log.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
size
size_t size
Definition specvec.h:72
canvas
Definition canvas.h:22
canvas::zoom
float zoom
Definition canvas.h:25
canvas::surf
SDL_Surface * surf
Definition canvas.h:27
color
Definition colors.h:21
sprite
Definition sprite.h:22
utf8_str
Definition gui_string.h:52
FALSE
#define FALSE
Definition support.h:47