Freeciv-3.2
Loading...
Searching...
No Matches
canvas.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2005 - Freeciv Development 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/* gui-gtk-3.22 */
19#include "colors.h"
20#include "gui_main.h"
21#include "mapview.h"
22
23#include "canvas.h"
24
25/************************************************************************/
29{
30 struct canvas *result = fc_malloc(sizeof(*result));
31
33 width, height);
34 result->drawable = NULL;
35 result->zoom = 1.0;
36
37 return result;
38}
39
40/************************************************************************/
44void canvas_free(struct canvas *store)
45{
47 free(store);
48}
49
50/************************************************************************/
53void canvas_set_zoom(struct canvas *store, float zoom)
54{
55 store->zoom = zoom;
56}
57
58/************************************************************************/
62{
63 return TRUE;
64}
65
66/************************************************************************/
69void canvas_mapview_init(struct canvas *store)
70{
71}
72
73/************************************************************************/
76void canvas_copy(struct canvas *dest, struct canvas *src,
77 int src_x, int src_y, int dest_x, int dest_y,
78 int width, int height)
79{
80 cairo_t *cr;
81
82 if (!dest->drawable) {
83 cr = cairo_create(dest->surface);
84 } else {
85 cr = dest->drawable;
86 cairo_save(cr);
87 }
88
89 cairo_scale(cr, dest->zoom / src->zoom, dest->zoom / src->zoom);
93 cairo_fill(cr);
94
95 if (!dest->drawable) {
96 cairo_destroy(cr);
97 } else {
98 cairo_restore(cr);
99 }
100}
101
102/************************************************************************/
107 struct sprite *sprite, int offset_x, int offset_y,
108 int width, int height)
109{
110 int sswidth, ssheight;
111 cairo_t *cr;
112
114
115 if (!pcanvas->drawable) {
117 } else {
118 cr = pcanvas->drawable;
119 }
120
121 if (pcanvas->drawable) {
122 cairo_save(cr);
123 }
124
129 MIN(width, MAX(0, sswidth - offset_x)),
130 MIN(height, MAX(0, ssheight - offset_y)));
131 cairo_fill(cr);
132
133 if (!pcanvas->drawable) {
134 cairo_destroy(cr);
135 } else {
136 cairo_restore(cr);
137 }
138}
139
140/************************************************************************/
153
154/************************************************************************/
158 int canvas_x, int canvas_y,
159 int canvas_w, int canvas_h,
160 struct sprite *sprite)
161{
162 /* This should never be called as we have not enabled support
163 * in this client yet. */
165}
166
167/************************************************************************/
171 int canvas_x, int canvas_y,
172 struct sprite *psprite,
173 bool fog, int fog_x, int fog_y)
174{
176 psprite, fog);
177}
178
179/************************************************************************/
184 int canvas_x, int canvas_y, int width, int height)
185{
186 cairo_t *cr;
187
188 if (!pcanvas->drawable) {
190 } else {
191 cr = pcanvas->drawable;
192 cairo_save(cr);
193 }
194
199 cairo_fill(cr);
200
201 if (!pcanvas->drawable) {
202 cairo_destroy(cr);
203 } else {
204 cairo_restore(cr);
205 }
206}
207
208/************************************************************************/
219
220/************************************************************************/
226 enum line_type ltype, int start_x, int start_y,
227 int dx, int dy)
228{
229 cairo_t *cr;
230 double dashes[2] = {4.0, 4.0};
231
232 if (!pcanvas->drawable) {
234 } else {
235 cr = pcanvas->drawable;
236 cairo_save(cr);
237 }
238
239 switch (ltype) {
240 case LINE_NORMAL:
241 cairo_set_line_width(cr, 1.);
242 break;
243 case LINE_BORDER:
245 cairo_set_dash(cr, dashes, 2, 0);
246 break;
247 case LINE_TILE_FRAME:
248 cairo_set_line_width(cr, 2.);
249 break;
250 case LINE_GOTO:
251 cairo_set_line_width(cr, 2.);
252 break;
253 case LINE_SELECT_RECT:
254 cairo_set_line_width(cr, 2.);
255 cairo_set_dash(cr, dashes, 2, 0);
257 break;
258 }
259
261 cairo_move_to(cr, start_x, start_y);
262 cairo_line_to(cr, start_x + dx, start_y + dy);
263 cairo_stroke(cr);
264
265 if (!pcanvas->drawable) {
266 cairo_destroy(cr);
267 } else {
268 cairo_restore(cr);
269 }
270}
271
272/************************************************************************/
277 enum line_type ltype, int start_x, int start_y,
278 int dx, int dy)
279{
280 int end_x = start_x + dx;
281 int end_y = start_y + dy;
282 cairo_t *cr;
283 double dashes[2] = {4.0, 4.0};
284
285 if (!pcanvas->drawable) {
287 } else {
288 cr = pcanvas->drawable;
289 cairo_save(cr);
290 }
291
292 switch (ltype) {
293 case LINE_NORMAL:
294 cairo_set_line_width(cr, 1.);
295 break;
296 case LINE_BORDER:
297 cairo_set_dash(cr, dashes, 2, 0);
299 break;
300 case LINE_TILE_FRAME:
301 cairo_set_line_width(cr, 2.);
302 break;
303 case LINE_GOTO:
304 cairo_set_line_width(cr, 2.);
305 break;
306 case LINE_SELECT_RECT:
307 cairo_set_line_width(cr, 2.);
308 cairo_set_dash(cr, dashes, 2, 0);
310 break;
311 }
312
314 cairo_move_to(cr, start_x, start_y);
315 cairo_curve_to(cr, end_x, start_y, start_x, end_y, end_x, end_y);
316 cairo_stroke(cr);
317
318 if (!pcanvas->drawable) {
319 cairo_destroy(cr);
320 } else {
321 cairo_restore(cr);
322 }
323}
324
326static struct {
329} fonts[FONT_COUNT] = {
334#define FONT(font) (*fonts[font].styles)
335
336/************************************************************************/
341void get_text_size(int *width, int *height,
342 enum client_font font, const char *text)
343{
344 PangoRectangle rect;
345
346 if (!layout) {
348 }
349
351 pango_layout_set_text(layout, text, -1);
352
354 if (width) {
355 *width = rect.width;
356 }
357 if (height) {
358 *height = rect.height;
359 }
360}
361
362/************************************************************************/
369 enum client_font font, struct color *pcolor,
370 const char *text)
371{
372 cairo_t *cr;
373
374 if (!pcanvas->drawable) {
376 } else {
377 cr = pcanvas->drawable;
378 cairo_save(cr);
379 }
380
382 font, pcolor, text);
383
384 if (!pcanvas->drawable) {
385 cairo_destroy(cr);
386 } else {
387 cairo_restore(cr);
388 }
389}
390
391/************************************************************************/
396void surface_put_text(cairo_t *cr, int x, int y, float zoom,
397 enum client_font font, struct color *pcolor,
398 const char *text)
399{
400 if (!layout) {
402 }
403
405 pango_layout_set_text(layout, text, -1);
406
407 if (fonts[font].shadowed) {
408 /* Suppress drop shadow for black text */
409 const GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
410
411 if (!gdk_rgba_equal(&pcolor->color, &black)) {
413 cairo_move_to(cr, x * zoom + 1,
414 y * zoom + 1);
416 }
417 }
418
419 cairo_move_to(cr, x * zoom, y * zoom);
422}
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
@ LINE_SELECT_RECT
Definition canvas_g.h:26
@ LINE_GOTO
Definition canvas_g.h:26
@ LINE_TILE_FRAME
Definition canvas_g.h:26
@ LINE_BORDER
Definition canvas_g.h:26
@ LINE_NORMAL
Definition canvas_g.h:26
char * incite_cost
Definition comments.c:75
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
bool shadowed
Definition canvas.c:328
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
#define FONT(font)
Definition canvas.c:334
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
static PangoLayout * layout
Definition canvas.c:325
void surface_put_text(cairo_t *cr, int x, int y, float zoom, enum client_font font, struct color *pcolor, const char *text)
Definition canvas.c:396
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
PangoFontDescription * city_productions_style
Definition gui_main.c:134
PangoFontDescription * city_names_style
Definition gui_main.c:133
PangoFontDescription * reqtree_text_style
Definition gui_main.c:135
void pixmap_put_overlay_tile_draw(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *ssprite, bool fog)
Definition mapview.c:566
#define fc_assert(condition)
Definition log.h:176
#define BORDER_WIDTH
#define fc_malloc(sz)
Definition mem.h:34
Definition fonts.h:26
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
float zoom
Definition canvas.h:25
cairo_surface_t * surface
Definition canvas.h:23
cairo_t * drawable
Definition canvas.h:24
Definition colors.h:21
cairo_surface_t * surface
Definition sprite.h:23
static struct nation_style * styles
Definition style.c:29
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47