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/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#include <SDL_ttf.h>
22#else /* SDL2_PLAIN_INCLUDE */
23#include <SDL2/SDL.h>
24#include <SDL2/SDL_ttf.h>
25#endif /* SDL2_PLAIN_INCLUDE */
26
27/* utility */
28#include "log.h"
29#include "mem.h"
30
31/* client/gui-sdl2 */
32#include "colors.h"
33#include "graphics.h"
34#include "gui_main.h"
35#include "gui_string.h"
36#include "sprite.h"
37
38#include "canvas.h"
39
40/**********************************************************************/
44{
45 struct canvas *result = fc_malloc(sizeof(*result));
46
48
49 return result;
50}
51
52/**********************************************************************/
56void canvas_free(struct canvas *store)
57{
58 FREESURFACE(store->surf);
59 free(store);
60}
61
62/**********************************************************************/
65void canvas_set_zoom(struct canvas *store, float zoom)
66{
67 /* sdl2-client has no zoom support */
68}
69
70/**********************************************************************/
74{
75 return FALSE;
76}
77
78/**********************************************************************/
85
86/**********************************************************************/
89void canvas_copy(struct canvas *dest, struct canvas *src,
90 int src_x, int src_y, int dest_x, int dest_y, int width,
91 int height)
92{
94 SDL_Rect dest_rect = {dest_x, dest_y, width, height};
95
96 alphablit(src->surf, &src_rect, dest->surf, &dest_rect, 255);
97}
98
99/**********************************************************************/
103 int canvas_x, int canvas_y,
104 struct sprite *sprite,
105 int offset_x, int offset_y, int width, int height)
106{
108 SDL_Rect dst = {canvas_x + offset_x, canvas_y + offset_y, 0, 0};
109
110 alphablit(GET_SURF(sprite), &src, pcanvas->surf, &dst, 255);
111}
112
113/**********************************************************************/
117 int canvas_x, int canvas_y,
118 struct sprite *sprite)
119{
120 SDL_Rect dst = {canvas_x, canvas_y, 0, 0};
121
122 alphablit(GET_SURF(sprite), NULL, pcanvas->surf, &dst, 255);
123}
124
125/************************************************************************/
129 int canvas_x, int canvas_y,
130 int canvas_w, int canvas_h,
131 struct sprite *sprite)
132{
133 /* This should never be called as we have not enabled support
134 * in this client yet. */
136}
137
138/**********************************************************************/
143 int canvas_x, int canvas_y,
144 struct sprite *psprite,
145 bool fog, int fog_x, int fog_y)
146{
147 SDL_Rect dst = {canvas_x, canvas_y, 0, 0};
148
149 if (fog) {
150 alphablit(GET_SURF(psprite), NULL, pcanvas->surf, &dst, 160);
151 } else {
153 }
154}
155
156/**********************************************************************/
160 int canvas_x, int canvas_y, int width, int height)
161{
163
165 pcolor->color->r,
166 pcolor->color->g,
167 pcolor->color->b,
168 pcolor->color->a));
169}
170
171/**********************************************************************/
175 struct sprite *psprite, struct color *pcolor,
176 int canvas_x, int canvas_y)
177{
178 SDL_Rect dst = {canvas_x, canvas_y,
179 GET_SURF(psprite)->w,
180 GET_SURF(psprite)->h};
181
183 pcolor->color->r,
184 pcolor->color->g,
185 pcolor->color->b,
186 pcolor->color->a));
187}
188
189/**********************************************************************/
193 enum line_type ltype, int start_x, int start_y,
194 int dx, int dy)
195{
196 create_line(pcanvas->surf, start_x, start_y, start_x + dx, start_y + dy, pcolor->color);
197}
198
199/**********************************************************************/
203 enum line_type ltype, int start_x, int start_y,
204 int dx, int dy)
205{
206 /* FIXME: Implement curved line drawing. */
207 canvas_put_line(pcanvas, pcolor, ltype, start_x, start_y, dx, dy);
208}
209
210/**********************************************************************/
215void get_text_size(int *width, int *height,
216 enum client_font font, const char *text)
217{
220
221 fc_assert(width != NULL || height != NULL);
222
225
226 if (width) {
227 *width = size.w;
228 }
229
230 if (height) {
231 *height = size.h;
232 }
233
235}
236
237/**********************************************************************/
243 enum client_font font, struct color *pcolor,
244 const char *text)
245{
248
250
251 ptext->fgcol = *pcolor->color;
252 ptext->bgcol = (SDL_Color) {0, 0, 0, 0};
253
255
257
260}
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