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/**********************************************************************/
39{
40 struct canvas *result = fc_malloc(sizeof(*result));
41
42 result->surf = create_surf(width, height);
43
44 return result;
45}
46
47/**********************************************************************/
51void canvas_free(struct canvas *store)
52{
53 FREESURFACE(store->surf);
54 free(store);
55}
56
57/**********************************************************************/
60void canvas_set_zoom(struct canvas *store, float zoom)
61{
62 /* sdl3-client has no zoom support */
63}
64
65/**********************************************************************/
69{
70 return FALSE;
71}
72
73/**********************************************************************/
80
81/**********************************************************************/
84void 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{
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/**********************************************************************/
98 int canvas_x, int canvas_y,
99 struct sprite *sprite,
100 int offset_x, int offset_y, int width, int height)
101{
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/**********************************************************************/
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/************************************************************************/
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. */
131}
132
133/**********************************************************************/
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 {
148 }
149}
150
151/**********************************************************************/
155 int canvas_x, int canvas_y, int width, int height)
156{
158
161 NULL,
162 pcolor->color->r,
163 pcolor->color->g,
164 pcolor->color->b,
165 pcolor->color->a));
166}
167
168/**********************************************************************/
172 struct sprite *psprite, struct color *pcolor,
173 int canvas_x, int canvas_y)
174{
175 SDL_Rect dst = {canvas_x, canvas_y,
176 GET_SURF(psprite)->w,
177 GET_SURF(psprite)->h};
178
181 NULL,
182 pcolor->color->r,
183 pcolor->color->g,
184 pcolor->color->b,
185 pcolor->color->a));
186}
187
188/**********************************************************************/
192 enum line_type ltype, int start_x, int start_y,
193 int dx, int dy)
194{
195 create_line(pcanvas->surf, start_x, start_y, start_x + dx, start_y + dy, pcolor->color);
196}
197
198/**********************************************************************/
202 enum line_type ltype, int start_x, int start_y,
203 int dx, int dy)
204{
205 /* FIXME: Implement curved line drawing. */
206 canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
207}
208
209/**********************************************************************/
214void get_text_size(int *width, int *height,
215 enum client_font font, const char *text)
216{
219
220 fc_assert(width != NULL || height != NULL);
221
224
225 if (width) {
226 *width = size.w;
227 }
228
229 if (height) {
230 *height = size.h;
231 }
232
234}
235
236/**********************************************************************/
242 enum client_font font, struct color *pcolor,
243 const char *text)
244{
247
249
250 ptext->fgcol = *pcolor->color;
251 ptext->bgcol = (SDL_Color) {0, 0, 0, 0};
252
254
256
259}
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 int int struct sprite *sprite canvas_put_rectangle
Definition canvas_g.h:55
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
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
Definition canvas_g.h:42
struct canvas int int int canvas_w
Definition canvas_g.h:49
struct canvas int int int int canvas_h
Definition canvas_g.h:49
struct canvas * pcanvas
Definition canvas_g.h:42
canvas_put_sprite_full_scaled
Definition canvas_g.h:48
canvas_put_text
Definition canvas_g.h:80
struct canvas int int struct sprite int int offset_y
Definition canvas_g.h:44
struct canvas int int struct sprite int offset_x
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
line_type
Definition canvas_g.h:25
char * incite_cost
Definition comments.c:76
void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite)
Definition canvas.c:144
void canvas_set_zoom(struct canvas *store, float zoom)
Definition canvas.c:53
void canvas_mapview_init(struct canvas *store)
Definition canvas.c:69
void canvas_fill_sprite_area(struct canvas *pcanvas, struct sprite *psprite, struct color *pcolor, int canvas_x, int canvas_y)
Definition canvas.c:211
void get_text_size(int *width, int *height, enum client_font font, const char *text)
Definition canvas.c:341
void canvas_free(struct canvas *store)
Definition canvas.c:44
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
bool has_zoom_support(void)
Definition canvas.c:61
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
struct canvas * canvas_create(int width, int height)
Definition canvas.c:28
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
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1381
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
int blit_entire_src(SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
Definition graphics.c:417
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:351
#define FREESURFACE(ptr)
Definition graphics.h:322
int * client_font_sizes[FONT_COUNT]
Definition gui_main.c:116
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
utf8_str * copy_chars_to_utf8_str(utf8_str *pstr, const char *pchars)
Definition gui_string.c:251
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
utf8_str * create_utf8_str(char *in_text, size_t n_alloc, Uint16 ptsize)
Definition gui_string.c:206
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
#define GET_SURF(m_sprite)
Definition sprite.h:29
#define fc_assert(condition)
Definition log.h:177
#define fc_malloc(sz)
Definition mem.h:34
size_t size
Definition specvec.h:72
float zoom
Definition canvas.h:25
SDL_Surface * surf
Definition canvas.h:27
Definition colors.h:21
#define FALSE
Definition support.h:47