Do not return NULL as boolean from wonder_is_lost() nor wonder_is_built()
[freeciv.git] / client / gui-gtk-2.0 / graphics.c
blob378f8469552a6fac62a3656f064eb23775c037c0
1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
22 #include <gtk/gtk.h>
24 #include "gtkpixcomm.h"
26 /* utility */
27 #include "log.h"
28 #include "mem.h"
29 #include "shared.h"
30 #include "support.h"
32 /* common */
33 #include "game.h"
34 #include "movement.h"
35 #include "unit.h"
36 #include "version.h"
38 /* client */
39 #include "climisc.h"
40 #include "colors.h"
41 #include "mapview_g.h"
42 #include "options.h"
43 #include "tilespec.h"
45 /* client/gui-gtk-2.0 */
46 #include "gui_main.h"
48 #include "graphics.h"
50 struct sprite *intro_gfx_sprite;
51 struct sprite *radar_gfx_sprite;
53 GdkCursor *fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES];
55 /***************************************************************************
56 Returns TRUE to indicate that gtk2-client supports given view type
57 ***************************************************************************/
58 bool is_view_supported(enum ts_type type)
60 switch (type) {
61 case TS_ISOMETRIC:
62 case TS_OVERHEAD:
63 return TRUE;
66 return FALSE;
69 #define COLOR_MOTTO_FACE_R 0x2D
70 #define COLOR_MOTTO_FACE_G 0x71
71 #define COLOR_MOTTO_FACE_B 0xE3
73 /**************************************************************************
74 Draw string with shadow
75 **************************************************************************/
76 void gtk_draw_shadowed_string(GdkDrawable *drawable,
77 GdkGC *black_gc,
78 GdkGC *white_gc,
79 gint x, gint y, PangoLayout *layout)
81 gdk_draw_layout(drawable, black_gc, x + 1, y + 1, layout);
82 gdk_draw_layout(drawable, white_gc, x, y, layout);
85 /***************************************************************************
86 Load cursor sprites
87 ***************************************************************************/
88 void load_cursors(void)
90 enum cursor_type cursor;
91 GdkDisplay *display = gdk_display_get_default();
92 int frame;
94 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
95 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
96 int hot_x, hot_y;
97 struct sprite *sprite
98 = get_cursor_sprite(tileset, cursor, &hot_x, &hot_y, frame);
99 GdkPixbuf *pixbuf = sprite_get_pixbuf(sprite);
101 fc_cursors[cursor][frame] = gdk_cursor_new_from_pixbuf(display, pixbuf,
102 hot_x, hot_y);
107 /***************************************************************************
108 Put unit sprite to canvas
109 ***************************************************************************/
110 void create_overlay_unit(struct canvas *pcanvas, struct unit_type *punittype,
111 enum direction8 facing)
113 int x1, x2, y1, y2;
114 int width, height;
115 struct sprite *sprite = get_unittype_sprite(tileset, punittype,
116 facing,
117 TRUE);
119 sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2);
120 if (pcanvas->type == CANVAS_PIXBUF) {
121 width = gdk_pixbuf_get_width(pcanvas->v.pixbuf);
122 height = gdk_pixbuf_get_height(pcanvas->v.pixbuf);
123 gdk_pixbuf_fill(pcanvas->v.pixbuf, 0x00000000);
124 } else {
125 if (pcanvas->type == CANVAS_PIXCOMM) {
126 gtk_pixcomm_clear(pcanvas->v.pixcomm);
129 /* Guess */
130 width = tileset_full_tile_width(tileset);
131 height = tileset_full_tile_height(tileset);
134 /* Finally, put a picture of the unit in the tile */
135 canvas_put_sprite(pcanvas, 0, 0, sprite,
136 (x2 + x1 - width) / 2, (y1 + y2 - height) / 2,
137 tileset_full_tile_width(tileset) - (x2 + x1 - width) / 2,
138 tileset_full_tile_height(tileset) - (y1 + y2 - height) / 2);
141 /***************************************************************************
142 This function is so that packhand.c can be gui-independent, and
143 not have to deal with Sprites itself.
144 ***************************************************************************/
145 void free_intro_radar_sprites(void)
147 if (intro_gfx_sprite) {
148 free_sprite(intro_gfx_sprite);
149 intro_gfx_sprite=NULL;
151 if (radar_gfx_sprite) {
152 free_sprite(radar_gfx_sprite);
153 radar_gfx_sprite=NULL;