Freeciv-3.3
Loading...
Searching...
No Matches
mapview.c
Go to the documentation of this file.
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.
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#include <stdio.h>
19
20#ifdef HAVE_UNISTD_H
21#include <unistd.h>
22#endif
23
24#include <gtk/gtk.h>
25
26/* utility */
27#include "fcintl.h"
28#include "log.h"
29#include "mem.h"
30#include "rand.h"
31#include "support.h"
32#include "timing.h"
33
34/* common */
35#include "game.h"
36#include "government.h" /* government_graphic() */
37#include "map.h"
38#include "nation.h"
39#include "player.h"
40
41/* client */
42#include "client_main.h"
43#include "climap.h"
44#include "climisc.h"
45#include "colors.h"
46#include "control.h" /* get_unit_in_focus() */
47#include "editor.h"
48#include "options.h"
49#include "overview_common.h"
50#include "tilespec.h"
51#include "text.h"
52#include "zoom.h"
53
54/* client/gui-gtk-5.0 */
55#include "citydlg.h" /* For reset_city_dialogs() */
56#include "editgui.h"
57#include "graphics.h"
58#include "gui_main.h"
59#include "gui_stuff.h"
60#include "mapctrl.h"
61#include "repodlgs.h"
62#include "wldlg.h"
63
64#include "mapview.h"
65
67static int cursor_timer_id = 0, cursor_type = -1, cursor_frame = 0;
68static int mapview_frozen_level = 0;
69
70static int mc_actual_width = -1;
71static int mc_actual_height = -1;
72
73/**********************************************************************/
80{
81 static bool flip = FALSE;
82
84 return;
85 }
86
87 if ((do_restore && flip) || !do_restore) {
89
90 if (tdb_provider == NULL) {
92
94 ".td_lighted {\n"
95 "color: rgba(235, 127, 235, 255);\n"
96 "background-color: rgba(127, 127, 127, 255);\n"
97 "}\n",
98 -1);
99
100 /* Turn Done button is persistent, so we only need to do this
101 * once too. */
106 }
107
108 if (flip) {
110 } else {
112 }
113
114 flip = !flip;
115 }
116}
117
118/**********************************************************************/
122{
124
125 if (current_turn_timeout() > 0) {
127 _("Time to forced turn change,\n"
128 "or estimated time to finish turn change "
129 "processing."));
130 } else {
132 _("Turn timeout disabled.\n"
133 "Between turns this shows estimated time "
134 "to finish turn change processing."));
135 }
136}
137
138/**********************************************************************/
142{
143 GtkWidget *label;
144 const struct player *pplayer = client_player();
145
147 if (pplayer != NULL) {
148 const gchar *name;
149 gunichar c;
150
151 /* Capitalize the first character of the translated nation
152 * plural name so that the frame label looks good. */
155 if ((gunichar) -1 != c && (gunichar) -2 != c) {
156 const char *obstext = NULL;
157 int obstextlen = 0;
158
159 if (client_is_observer()) {
160 obstext = _(" (observer)");
162 }
163
164 {
166 gchar *next;
167 gint len;
168
170 nation[len] = '\0';
172 if (NULL != next) {
173 sz_strlcat(nation, next);
174 }
175 if (obstext != NULL) {
177 }
179 }
180 } else {
182 }
183 } else {
184 gtk_label_set_text(GTK_LABEL(label), "-");
185 }
186
189
194
195 if (NULL != pplayer) {
196 int d = 0;
197
198 for (; d < pplayer->economic.luxury / 10; d++) {
200
202 }
203
204 for (; d < (pplayer->economic.science
205 + pplayer->economic.luxury) / 10; d++) {
207
209 }
210
211 for (; d < 10; d++) {
213
215 }
216 }
217
219
220 /* Update tooltips. */
222 _("Shows your current luxury/science/tax rates; "
223 "click to toggle them."));
224
229}
230
231/**********************************************************************/
235{
236 if (!cursor_timer_id) {
237 return FALSE;
238 }
239
240 cursor_frame++;
242 cursor_frame = 0;
243 }
244
247 cursor_timer_id = 0;
248 return FALSE;
249 }
250
254 return TRUE;
255}
256
257/**********************************************************************/
267
268/**********************************************************************/
291
292/**********************************************************************/
299
300/**********************************************************************/
313
314/**********************************************************************/
325
326/**********************************************************************/
336
337/**********************************************************************/
341{
342#if 0
343 static struct canvas store;
345
346 store.surface = NULL;
348
349 return &store;
350#endif /* 0 */
353 }
354
355 return NULL;
356}
357
358/**********************************************************************/
374
375/**********************************************************************/
379{
381}
382
383/**********************************************************************/
386void mapview_thaw(void)
387{
388 if (1 < mapview_frozen_level) {
390 } else {
393 dirty_all();
394 }
395}
396
397/**********************************************************************/
401{
402 return (0 < mapview_frozen_level);
403}
404
405/**********************************************************************/
416
417/**********************************************************************/
425
426/**********************************************************************/
430 int width, int height, gpointer data)
431{
433 /* First we mark the area to be updated as dirty. Then we unqueue
434 * any pending updates, to make sure only the most up-to-date data
435 * is written (otherwise drawing bugs happen when old data is copied
436 * to screen). Then we draw all changed areas to the screen. */
440 cairo_paint(cr);
441 }
442}
443
444/**********************************************************************/
449 int pixel_width, int pixel_height)
450{
451 dirty_all();
452}
453
454/**********************************************************************/
463
464/**********************************************************************/
469void flush_dirty(void)
470{
471}
472
473/**********************************************************************/
482
483/**********************************************************************/
490
491/**********************************************************************/
495{
496 struct canvas store = FC_STATIC_CANVAS_INIT;
497 int width;
498
499 if (height <= 0) {
501 }
503
505 width, height);
506
507 put_unit(punit, &store, 1.0, 0, 0);
508
511}
512
513/**********************************************************************/
520 int height,
521 int *upkeep_cost, int happy_cost)
522{
523 struct canvas store = FC_STATIC_CANVAS_INIT;
525
527 width, height);
528
529 put_unit(punit, &store, 1.0, 0, 0);
530
532 upkeep_cost, happy_cost);
533
536}
537
538/**********************************************************************/
542 int canvas_x, int canvas_y,
543 struct sprite *ssprite)
544{
545#if 0
546 cairo_t *cr;
548
549 if (!ssprite) {
550 return;
551 }
552
556 cairo_scale(cr, zoom, zoom);
558 cairo_paint(cr);
560#endif
561}
562
563/**********************************************************************/
567 int canvas_x, int canvas_y,
568 struct sprite *ssprite,
569 bool fog)
570{
571 cairo_t *cr;
572 int sswidth, ssheight;
573 const double bright = 0.65; /* Fogged brightness compared to unfogged */
574
575 if (!ssprite) {
576 return;
577 }
578
580
581 if (fog) {
582 struct color *fogcol = color_alloc(0.0, 0.0, 0.0); /* black */
584 struct sprite *fogged;
585 unsigned char *mask_in;
586 unsigned char *mask_out;
587 int i, j;
588
589 /* Create sprites initially fully transparent */
590 fogcol->color.alpha = 0.0;
593
594 /* Calculate black fog mask from the original sprite's alpha channel;
595 * we don't want to blacken transparent parts of the sprite. */
598
599 for (i = 0; i < sswidth; i++) {
600 for (j = 0; j < ssheight; j++) {
601 /* In order to darken pixels of ssprite to 'bright' fraction of
602 * their original value, we need to overlay blackness of
603 * (1-bright) transparency. */
604 if (!is_bigendian()) {
605 mask_out[(j * sswidth + i) * 4 + 3]
606 = (1-bright) * mask_in[(j * sswidth + i) * 4 + 3];
607 } else {
608 mask_out[(j * sswidth + i) * 4 + 0]
609 = (1-bright) * mask_in[(j * sswidth + i) * 4 + 0];
610 }
611 }
612 }
613
615
616 /* First copy original sprite canvas to intermediate sprite canvas */
617 cr = cairo_create(fogged->surface);
618 cairo_set_source_surface(cr, ssprite->surface, 0, 0);
619 cairo_paint(cr);
620
621 /* Then apply created fog to the intermediate sprite to darken it */
623 cairo_paint(cr);
624 cairo_destroy(cr);
625
626 /* Put intermediate sprite to the target canvas */
628 fogged, 0, 0, sswidth, ssheight);
629
630 /* Free intermediate stuff */
634 } else {
636 ssprite, 0, 0, sswidth, ssheight);
637 }
638}
639
640/**********************************************************************/
655
656/**********************************************************************/
679
680/**********************************************************************/
694
695/**********************************************************************/
721
722/**********************************************************************/
743
744/**********************************************************************/
753void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
754{
755 struct color *pcolor;
756
757 if (w == 0 || h == 0) {
758 return;
759 }
760
762 if (!pcolor) {
763 return;
764 }
765
767 canvas_x, canvas_y, w, 0);
769 canvas_x, canvas_y, 0, h);
771 canvas_x, canvas_y + h, w, 0);
773 canvas_x + w, canvas_y, 0, h);
774}
775
776/**********************************************************************/
780{
786
787 /* Keep the icon of the executable on Windows (see PR#36491) */
788#ifndef FREECIV_MSWINDOWS
789 {
790 /* Only call this after tileset_load_tiles is called. */
792 }
793#endif /* FREECIV_MSWINDOWS */
794}
795
796/**********************************************************************/
799void start_turn(void)
800{}
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 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 * pcanvas
Definition canvas_g.h:42
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
@ LINE_SELECT_RECT
Definition canvas_g.h:26
bool client_is_observer(void)
bool can_client_change_view(void)
#define client_player()
struct sprite * client_warming_sprite(void)
Definition climisc.c:377
struct sprite * client_cooling_sprite(void)
Definition climisc.c:394
struct sprite * client_research_sprite(void)
Definition climisc.c:354
struct sprite * client_government_sprite(void)
Definition climisc.c:412
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:76
void update_unit_pix_label(struct unit_list *punitlist)
Definition control.c:985
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1215
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
bool get_turn_done_button_state()
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
#define _(String)
Definition fcintl.h:67
int current_turn_timeout(void)
Definition game.c:853
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
void reset_city_dialogs(void)
Definition citydlg.c:365
struct color * color_alloc(int r, int g, int b)
Definition colors.c:38
void color_free(struct color *color)
Definition colors.c:53
void editgui_tileset_changed(void)
Definition editgui.c:1862
static GtkWidget * source
Definition gotodlg.c:58
GdkCursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
Definition graphics.c:48
GtkWidget * map_vertical_scrollbar
Definition gui_main.c:110
GtkWidget * main_label_info
Definition gui_main.c:139
GtkWidget * unit_info_label
Definition gui_main.c:152
GtkWidget * timeout_label
Definition gui_main.c:149
GtkWidget * overview_scrolled_window
Definition gui_main.c:113
GtkWidget * government_label
Definition gui_main.c:148
GtkWidget * sun_label
Definition gui_main.c:146
GtkWidget * turn_done_button
Definition gui_main.c:150
void reset_unit_table(void)
Definition gui_main.c:1024
GtkWidget * unit_info_frame
Definition gui_main.c:154
GtkWidget * flake_label
Definition gui_main.c:147
GtkWidget * bulb_label
Definition gui_main.c:145
GtkWidget * overview_canvas
Definition gui_main.c:112
GtkWidget * toplevel
Definition gui_main.c:126
GtkWidget * map_horizontal_scrollbar
Definition gui_main.c:109
GtkWidget * map_canvas
Definition gui_main.c:108
GtkWidget * econ_label[10]
Definition gui_main.c:144
int overview_canvas_store_width
Definition gui_main.c:123
int overview_canvas_store_height
Definition gui_main.c:124
GtkWidget * main_frame_civ_name
Definition gui_main.c:138
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
void update_timeout_label(void)
Definition mapview.c:118
void flush_dirty(void)
Definition mapview.c:468
static int cursor_frame
Definition mapview.c:67
void update_info_label(void)
Definition mapview.c:138
void update_turn_done_button(bool do_restore)
Definition mapview.c:76
void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar)
Definition mapview.c:721
void dirty_all(void)
Definition mapview.c:456
void tileset_changed(void)
Definition mapview.c:782
void put_cross_overlay_tile(struct tile *ptile)
Definition mapview.c:643
void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
Definition mapview.c:749
void update_map_canvas_scrollbars_size(void)
Definition mapview.c:696
void get_overview_area_dimensions(int *width, int *height)
Definition mapview.c:317
void mapview_freeze(void)
Definition mapview.c:373
GdkPixbuf * get_thumb_pixbuf(int onoff)
Definition mapview.c:292
void start_turn(void)
Definition mapview.c:805
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:275
void update_overview_scroll_window_pos(int x, int y)
Definition mapview.c:657
void update_city_descriptions(void)
Definition mapview.c:488
gboolean map_canvas_draw(GtkWidget *w, cairo_t *cr, gpointer data)
Definition mapview.c:424
void pixmap_put_overlay_tile(GdkWindow *pixmap, float zoom, int canvas_x, int canvas_y, struct sprite *ssprite)
Definition mapview.c:543
void gui_flush(void)
Definition mapview.c:480
void pixmap_put_overlay_tile_draw(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *ssprite, bool fog)
Definition mapview.c:566
void update_map_canvas_scrollbars(void)
Definition mapview.c:681
bool mapview_is_frozen(void)
Definition mapview.c:395
static gboolean anim_cursor_cb(gpointer data)
Definition mapview.c:231
void overview_size_changed(void)
Definition mapview.c:326
void map_canvas_size_refresh(void)
Definition mapview.c:414
static int cursor_timer_id
Definition mapview.c:67
static GtkAdjustment * map_vadj
Definition mapview.c:66
static int mapview_frozen_level
Definition mapview.c:68
void mapview_thaw(void)
Definition mapview.c:381
struct canvas * get_overview_window(void)
Definition mapview.c:337
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:257
static GtkAdjustment * map_hadj
Definition mapview.c:66
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.c:302
gboolean overview_canvas_draw(GtkWidget *w, cairo_t *cr, gpointer data)
Definition mapview.c:356
#define CURSOR_INTERVAL
Definition mapview.h:32
void science_report_dialog_redraw(void)
Definition repodlgs.c:761
void free_sprite(struct sprite *s)
Definition sprite.c:278
struct sprite * create_sprite(int width, int height, struct color *pcolor)
Definition sprite.c:84
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
void blank_max_unit_size(void)
Definition wldlg.c:79
GtkWidget * econ_widget
Definition gui_main.c:155
static int mc_actual_width
Definition mapview.c:70
static int mc_actual_height
Definition mapview.c:71
void map_canvas_resize(GtkWidget *w, int width, int height, gpointer data)
Definition mapview.c:408
void put_unit_picture_city_overlays(struct unit *punit, GtkPicture *p, int height, int *upkeep_cost, int happy_cost)
Definition mapview.c:519
void put_unit_picture(struct unit *punit, GtkPicture *p, int height)
Definition mapview.c:494
void picture_set_from_surface(GtkPicture *pic, cairo_surface_t *surf)
Definition sprite.c:544
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:177
bool map_is_empty(void)
Definition map.c:148
const char * get_timeout_label_text()
Definition text.c:1604
void update_map_canvas_visible(void)
struct view mapview
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void get_mapview_scroll_pos(int *scroll_x, int *scroll_y)
void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax, float *ymax, int *xsize, int *ysize)
void unqueue_mapview_updates(bool write_to_screen)
void get_mapview_scroll_step(int *xstep, int *ystep)
void set_mapview_scroll_pos(int scroll_x, int scroll_y, float zoom)
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
bool map_canvas_resized(int width, int height)
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom, const struct tile *ptile)
dirty_rect
Definition mapview_g.h:47
int int int pixel_width
Definition mapview_g.h:48
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
struct client_options gui_options
Definition options.c:71
#define GUI_GTK_OVERVIEW_MIN_XSIZE
Definition options.h:634
#define GUI_GTK_OVERVIEW_MIN_YSIZE
Definition options.h:635
int len
Definition packhand.c:127
const char * get_government_tooltip(void)
Definition text.c:1525
const char * get_nuclear_winter_tooltip(void)
Definition text.c:1498
const char * get_bulb_tooltip(void)
Definition text.c:1414
const char * get_info_label_text(bool)
Definition text.c:964
const char * get_global_warming_tooltip(void)
Definition text.c:1471
#define MIN(x, y)
Definition shared.h:55
#define BOOL_VAL(x)
Definition shared.h:70
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
struct overview overview
Definition options.h:462
Definition colors.h:21
int width
Definition options.h:94
struct canvas * window
Definition options.h:100
int height
Definition options.h:94
struct player_economic economic
Definition player.h:284
struct nation_type * nation
Definition player.h:260
cairo_surface_t * surface
Definition sprite.h:23
Definition tile.h:50
Definition unit.h:140
struct canvas * store
static bool is_bigendian(void)
Definition support.h:235
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
const char * get_unit_info_label_text2(struct unit_list *punits, int linebreaks)
Definition text.c:1126
const char * get_unit_info_label_text1(struct unit_list *punits)
Definition text.c:1101
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:7214
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:815
int tileset_unit_layout_offset_y(const struct tileset *t)
Definition tilespec.c:908
struct sprite * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Definition tilespec.c:7133
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:802
struct sprite * get_tax_sprite(const struct tileset *t, Output_type_id otype)
Definition tilespec.c:7103
#define NUM_CURSOR_FRAMES
Definition tilespec.h:305
cursor_type
Definition tilespec.h:289
@ CURSOR_DEFAULT
Definition tilespec.h:302
float mouse_zoom
Definition zoom.c:28
float map_zoom
Definition zoom.c:25