Freeciv-3.2
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/***********************************************************************
15 mapview.c - description
16 -------------------
17 begin : Aug 10 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20***********************************************************************/
21
22#ifdef HAVE_CONFIG_H
23#include <fc_config.h>
24#endif
25
26/* SDL2 */
27#ifdef SDL2_PLAIN_INCLUDE
28#include <SDL.h>
29#else /* SDL2_PLAIN_INCLUDE */
30#include <SDL2/SDL.h>
31#endif /* SDL2_PLAIN_INCLUDE */
32
33/* utility */
34#include "astring.h"
35#include "bugs.h"
36#include "fcintl.h"
37#include "log.h"
38
39/* common */
40#include "calendar.h"
41#include "game.h"
42#include "goto.h"
43#include "government.h"
44#include "movement.h"
45#include "research.h"
46#include "unitlist.h"
47
48/* client */
49#include "citydlg_common.h"
50#include "client_main.h"
51#include "climisc.h"
52#include "overview_common.h"
53#include "pages_g.h"
54#include "text.h"
55
56/* gui-sdl2 */
57#include "colors.h"
58#include "dialogs.h"
59#include "graphics.h"
60#include "gui_id.h"
61#include "gui_main.h"
62#include "gui_mouse.h"
63#include "gui_tilespec.h"
64#include "mapctrl.h"
65#include "sprite.h"
66#include "themespec.h"
67#include "widget.h"
68
69#include "mapview.h"
70
71extern SDL_Rect *info_area;
72
75
76static struct canvas *overview_canvas;
77static struct canvas *city_map_canvas = NULL;
78static struct canvas *terrain_canvas;
79
80/* ================================================================ */
81
83{
84 /* No scrollbars */
85}
86
87static bool is_flush_queued = FALSE;
88
89/**********************************************************************/
92static void flush_mapcanvas(int canvas_x, int canvas_y,
94{
96
97 alphablit(mapview.store->surf, &rect, main_data.map, &rect, 255);
98}
99
100/**********************************************************************/
104{
106 dirty_sdl_rect(rect);
107 } else {
108 static SDL_Rect src, dst;
109
110 if (correct_rect_region(rect)) {
111 static int i = 0;
112
113 dst = *rect;
114 if (C_S_RUNNING == client_state()) {
115 flush_mapcanvas(dst.x, dst.y, dst.w, dst.h);
116 }
117 screen_blit(main_data.map, rect, &dst, 255);
118 if (main_data.guis) {
119 while ((i < main_data.guis_count) && main_data.guis[i]) {
120 src = *rect;
122 dst = *rect;
123 screen_blit(main_data.guis[i++]->surface, &src, &dst, 255);
124 }
125 }
126 i = 0;
127
128 /* flush main buffer to framebuffer */
129#if 0
130 SDL_UpdateRect(main_data.screen, rect->x, rect->y, rect->w, rect->h);
131#endif /* 0 */
132 }
133 }
134}
135
136/**********************************************************************/
146
147/**********************************************************************/
152void queue_flush(void)
153{
154 if (!is_flush_queued) {
155 if (flush_event()) {
157 } else {
158 /* We don't want to set is_flush_queued in this case, since then
159 * the flush code would simply stop working. But this means the
160 * below message may be repeated many times. */
161 bugreport_request(_("Failed to add events to SDL2 event buffer: %s"),
162 SDL_GetError());
163 }
164 }
165}
166
167/**********************************************************************/
177
178/**********************************************************************/
188
189/**********************************************************************/
192void dirty_all(void)
193{
195 queue_flush();
196}
197
198/**********************************************************************/
207
208/**********************************************************************/
212void flush_dirty(void)
213{
214 static int j = 0;
215
216 if (!main_data.rects_count) {
217 return;
218 }
219
221
222 if ((C_S_RUNNING == client_state())
223 && (get_client_page() == PAGE_GAME)) {
226 }
228 if (main_data.guis) {
229 while ((j < main_data.guis_count) && main_data.guis[j]) {
231
232 screen_blit(main_data.guis[j++]->surface, NULL, &dst, 255);
233 }
234 }
235 j = 0;
236
238
239 /* Render to screen */
241 } else {
242 static int i;
243 static SDL_Rect src, dst;
244
245 for (i = 0; i < main_data.rects_count; i++) {
246
247 dst = main_data.rects[i];
248 if (C_S_RUNNING == client_state()) {
249 flush_mapcanvas(dst.x, dst.y, dst.w, dst.h);
250 }
251 screen_blit(main_data.map, &main_data.rects[i], &dst, 255);
252
253 if (main_data.guis) {
254 while ((j < main_data.guis_count) && main_data.guis[j]) {
255 src = main_data.rects[i];
257 dst = main_data.rects[i];
258 screen_blit(main_data.guis[j++]->surface, &src, &dst, 255);
259 }
260 }
261 j = 0;
262
263 /* restore widget info label if it overlaps with this area */
264 dst = main_data.rects[i];
265 if (info_area && !(((dst.x + dst.w) < info_area->x)
266 || (dst.x > (info_area->x + info_area->w))
267 || ((dst.y + dst.h) < info_area->y)
268 || (dst.y > (info_area->y + info_area->h)))) {
270 }
271 }
272
274
275 /* Render to screen */
277#if 0
279#endif
280 }
282}
283
284/**********************************************************************/
287void gui_flush(void)
288{
289 if (C_S_RUNNING == client_state()) {
291 }
292}
293
294/* ===================================================================== */
295
296/**********************************************************************/
302 struct sprite *flake, struct sprite *gov)
303{
304 struct widget *buf = NULL;
305 char cbuf[128];
306
308 FREESURFACE(buf->theme);
309 buf->theme = adj_surf(GET_SURF(sol));
312
314 FREESURFACE(buf->theme);
315 buf->theme = adj_surf(GET_SURF(flake));
318
321
322 if (NULL != client.conn.playing) {
323 fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)\n%s",
324 _("Revolution"), "Ctrl+Shift+G",
326 } else {
327 fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)\n%s",
328 _("Revolution"), "Ctrl+Shift+G",
329 Q_("?gov:None"));
330 }
331 copy_chars_to_utf8_str(buf->info_label, cbuf);
332
335
337 if (!buf->theme) {
339 }
340
342
343 if (NULL == client.conn.playing) {
344 /* TRANS: Research report action */
345 fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)\n%s (%d/%d)", _("Research"), "F6",
346 Q_("?tech:None"), 0, 0);
347 } else {
348 const struct research *presearch = research_get(client_player());
349
350 if (A_UNSET != presearch->researching) {
351 /* TRANS: Research report action */
352 fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)\n%s (%d/%d)",
353 _("Research"), "F6",
355 presearch->researching),
356 presearch->bulbs_researched,
357 presearch->client.researching_cost);
358 } else {
359 /* TRANS: Research report action */
360 fc_snprintf(cbuf, sizeof(cbuf), "%s (%s)\n%s (%d/%d)",
361 _("Research"), "F6",
363 presearch->researching),
364 presearch->bulbs_researched,
365 0);
366 }
367 }
368
369 copy_chars_to_utf8_str(buf->info_label, cbuf);
370
372
375}
376
377/**********************************************************************/
395
396/**********************************************************************/
402{
403 SDL_Color bg_color = {0, 0, 0, 80};
405 char buffer[512];
406#ifdef SMALL_SCREEN
407 SDL_Rect area = {0, 0, 0, 0};
408#else
409 SDL_Rect area = {0, 3, 0, 0};
410#endif
411 struct utf8_str *ptext;
412
414 return;
415 }
416
418
419 /* Set text settings */
420 ptext->style |= TTF_STYLE_BOLD;
422 ptext->bgcol = (SDL_Color) {0, 0, 0, 0};
423
424 if (client_player() != NULL) {
425#ifdef SMALL_SCREEN
426 fc_snprintf(buffer, sizeof(buffer),
427 /* TRANS: "(Obs) Egyptian..." */
428 _("%s%s Population: %s Year: %s "
429 "Gold %d "),
430 /* TRANS: Observer */
431 client.conn.observer ? _("(Obs) ") : "",
436#else /* SMALL_SCREEN */
437 fc_snprintf(buffer, sizeof(buffer),
438 /* TRANS: "(Observer) Egyptian..." */
439 _("%s%s Population: %s Year: %s "
440 "Gold %d Tax: %d Lux: %d Sci: %d "),
441 client.conn.observer ? _("(Observer) ") : "",
449#endif /* SMALL_SCREEN */
450
451 /* Convert to utf8_str and create text surface */
454
455 area.x = (main_window_width() - tmp->w) / 2 - adj_size(5);
456 area.w = tmp->w + adj_size(8);
457 area.h = tmp->h + adj_size(4);
458
461
462 /* Horizontal lines */
464 area.x + 1, area.y, area.x + area.w - 2, area.y,
467 area.x + 1, area.y + area.h - 1, area.x + area.w - 2,
468 area.y + area.h - 1,
470
471 /* Vertical lines */
473 area.x + area.w - 1, area.y + 1, area.x + area.w - 1,
474 area.y + area.h - 2,
477 area.x, area.y + 1, area.x, area.y + area.h - 2,
479
480 /* Blit text to screen */
482 area.y + adj_size(2));
483
484 dirty_sdl_rect(&area);
485
487 }
488
493
495
497
498 queue_flush();
499}
500
501/**********************************************************************/
504static int focus_units_info_callback(struct widget *pwidget)
505{
507 struct unit *punit = pwidget->data.unit;
508
509 if (punit) {
512 }
513 }
514
515 return -1;
516}
517
518/**********************************************************************/
522void redraw_unit_info_label(struct unit_list *punitlist)
523{
524 struct widget *info_window;
525 SDL_Rect src, area;
526 SDL_Rect dest;
528 utf8_str *pstr;
529 struct canvas *destcanvas;
530 struct unit *punit;
531
532 if (punitlist != NULL && unit_list_size(punitlist) > 0) {
534 } else {
535 punit = NULL;
536 }
537
540
541 /* Blit theme surface */
543
544 if (punit) {
545 SDL_Surface *name, *vet_name = NULL, *info, *info2 = NULL;
546 int sy, y, width, height, n;
547 bool right;
548 char buffer[512];
549 struct tile *ptile = unit_tile(punit);
550 const char *vetname;
551
552 /* Get and draw unit name (with veteran status) */
555 pstr->style |= TTF_STYLE_BOLD;
556 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
558
559 pstr->style &= ~TTF_STYLE_BOLD;
560
561 if (info_window->size.w > 1.8 *
562 ((info_window->size.w - info_window->area.w) + DEFAULT_UNITS_W)) {
563 width = info_window->area.w / 2;
564 right = TRUE;
565 } else {
566 width = info_window->area.w;
567 right = FALSE;
568 }
569
572 punit->veteran);
573 if (vetname != NULL) {
578 }
579
580 /* Get and draw other info (MP, terrain, city, etc.) */
581 pstr->style |= SF_CENTER;
582
587
588 if (info_window->size.h >
589 (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h)) || right) {
590 int h = TTF_FontHeight(info_window->string_utf8->font);
591
592 fc_snprintf(buffer, sizeof(buffer), "%s",
594
595 if (info_window->size.h >
596 2 * h + (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h)) || right) {
597 struct city *pcity = tile_city(ptile);
598
599 if (BORDERS_DISABLED != game.info.borders && !pcity) {
601 {"" /* unused, DS_ARMISTICE */, Q_("?nation:Hostile"),
602 "" /* unused, DS_CEASEFIRE */,
603 Q_("?nation:Peaceful"), Q_("?nation:Friendly"),
604 Q_("?nation:Mysterious")};
605
606 if (tile_owner(ptile) == client.conn.playing) {
607 cat_snprintf(buffer, sizeof(buffer), _("\nOur Territory"));
608 } else {
609 if (tile_owner(ptile)) {
610 struct player_diplstate *ds
612 tile_owner(ptile));
613
614 if (DS_CEASEFIRE == ds->type) {
615 int turns = ds->turns_left;
616
617 cat_snprintf(buffer, sizeof(buffer),
618 PL_("\n%s territory (%d turn ceasefire)",
619 "\n%s territory (%d turn ceasefire)", turns),
621 turns);
622 } else if (DS_ARMISTICE == ds->type) {
623 int turns = ds->turns_left;
624
625 cat_snprintf(buffer, sizeof(buffer),
626 PL_("\n%s territory (%d turn armistice)",
627 "\n%s territory (%d turn armistice)", turns),
629 turns);
630 } else {
631 cat_snprintf(buffer, sizeof(buffer), _("\nTerritory of the %s %s"),
634 }
635 } else { /* !tile_owner(ptile) */
636 cat_snprintf(buffer, sizeof(buffer), _("\nUnclaimed territory"));
637 }
638 }
639 } /* BORDERS_DISABLED != game.info.borders && !pcity */
640
641 if (pcity) {
642 /* Look at city owner, not tile owner (the two should be the same, if
643 * borders are in use). */
644 struct player *owner = city_owner(pcity);
645 const char *diplo_city_adjectives[DS_LAST] =
646 {Q_("?city:Neutral"), Q_("?city:Hostile"),
647 Q_("?city:Neutral"), Q_("?city:Peaceful"),
648 Q_("?city:Friendly"), Q_("?city:Mysterious")};
649
650 cat_snprintf(buffer, sizeof(buffer),
651 _("\nCity of %s"),
652 city_name_get(pcity));
653
654#if 0
655 /* This has hardcoded assumption that EFT_LAND_REGEN is always
656 * provided by *building* named *Barracks*. Similar assumptions for
657 * other effects. */
659 barrack = (get_city_bonus(pcity, EFT_LAND_REGEN) > 0);
660 airport = (get_city_bonus(pcity, EFT_AIR_VETERAN) > 0);
661 port = (get_city_bonus(pcity, EFT_SEA_VETERAN) > 0);
662 }
663
664 if (citywall || barrack || airport || port) {
665 cat_snprintf(buffer, sizeof(buffer), Q_("?blistbegin: with "));
666 if (barrack) {
667 cat_snprintf(buffer, sizeof(buffer), _("Barracks"));
668 if (port || airport || citywall) {
669 cat_snprintf(buffer, sizeof(buffer), Q_("?blistmore:, "));
670 }
671 }
672 if (port) {
673 cat_snprintf(buffer, sizeof(buffer), _("Port"));
674 if (airport || citywall) {
675 cat_snprintf(buffer, sizeof(buffer), Q_("?blistmore:, "));
676 }
677 }
678 if (airport) {
679 cat_snprintf(buffer, sizeof(buffer), _("Airport"));
680 if (citywall) {
681 cat_snprintf(buffer, sizeof(buffer), Q_("?blistmore:, "));
682 }
683 }
684 if (citywall) {
685 cat_snprintf(buffer, sizeof(buffer), _("City Walls"));
686 }
687
688 cat_snprintf(buffer, sizeof(buffer), Q_("?blistend:"));
689 }
690#endif /* 0 */
691
692 if (owner && owner != client.conn.playing) {
693 struct player_diplstate *ds
695
696 /* TRANS: (<nation>,<diplomatic_state>)" */
697 cat_snprintf(buffer, sizeof(buffer), _("\n(%s,%s)"),
700 }
701 }
702 }
703
704 if (info_window->size.h >
705 4 * h + (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h)) || right) {
706 cat_snprintf(buffer, sizeof(buffer), _("\nFood/Prod/Trade: %s"),
708 }
709
711
713 }
714
716
717 /* ------------------------------------------- */
718
719 n = unit_list_size(ptile->units);
720 y = 0;
721
722 if (n > 1 && ((!right && info2
723 && (info_window->size.h - (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h)) -
724 info2->h > 52))
725 || (right && info_window->size.h - (DEFAULT_UNITS_H + (info_window->size.h -
726 info_window->area.h)) > 52))) {
727 height = (info_window->size.h - info_window->area.h) + DEFAULT_UNITS_H;
728 } else {
729 height = info_window->size.h;
730 if (info_window->size.h > (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h))) {
731 y = (info_window->size.h - (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h)) -
732 (!right && info2 ? info2->h : 0)) / 2;
733 }
734 }
735
736 sy = y + adj_size(3);
737 area.y = info_window->area.y + sy;
738 area.x = info_window->area.x + BLOCKU_W + (width - name->w - BLOCKU_W) / 2;
739 dest = area;
740 alphablit(name, NULL, info_window->dst->surface, &dest, 255);
741 sy += name->h;
742 if (vet_name) {
743 area.y += name->h - adj_size(3);
744 area.x = info_window->area.x + BLOCKU_W + (width - vet_name->w - BLOCKU_W) / 2;
745 alphablit(vet_name, NULL, info_window->dst->surface, &area, 255);
746 sy += vet_name->h - adj_size(3);
748 }
750
751 /* draw unit sprite */
753 punit->facing),
754 adj_size(80), adj_size(80), 1, TRUE, TRUE);
755
756 src = (SDL_Rect){0, 0, buf_surf->w, buf_surf->h};
757
758 area.x = info_window->area.x + BLOCKU_W - adj_size(4) +
759 ((width - BLOCKU_W + adj_size(3) - src.w) / 2);
760 area.y = info_window->size.y + sy + (DEFAULT_UNITS_H - sy - src.h) / 2;
761 alphablit(buf_surf, &src, info_window->dst->surface, &area, 32);
763
764 /* blit unit info text */
765 area.x = info_window->area.x + BLOCKU_W - adj_size(4) +
766 ((width - BLOCKU_W + adj_size(4) - info->w) / 2);
767 area.y = info_window->size.y + sy + (DEFAULT_UNITS_H - sy - info->h) / 2;
768
769 alphablit(info, NULL, info_window->dst->surface, &area, 255);
770 FREESURFACE(info);
771
772 if (info2) {
773 if (right) {
774 area.x = info_window->area.x + width + (width - info2->w) / 2;
775 area.y = info_window->area.y + (height - info2->h) / 2;
776 } else {
777 area.y = info_window->area.y + DEFAULT_UNITS_H + y;
778 area.x = info_window->area.x + BLOCKU_W +
779 (width - BLOCKU_W - info2->w) / 2;
780 }
781
782 /* blit unit info text */
783 alphablit(info2, NULL, info_window->dst->surface, &area, 255);
784
785 if (right) {
786 sy = (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h));
787 } else {
788 sy = area.y - info_window->size.y + info2->h;
789 }
791 } else {
792 sy = (DEFAULT_UNITS_H + (info_window->size.h - info_window->area.h));
793 }
794
795 if (n > 1 && (info_window->size.h - sy > 52)) {
796 struct advanced_dialog *dlg = info_window->private_data.adv_dlg;
797 struct widget *buf = NULL, *end = NULL, *dock;
798 struct city *home_city;
799 const struct unit_type *putype;
800 int num_w, num_h;
801
804 }
805 num_w = (info_window->area.w - BLOCKU_W) / 68;
806 num_h = (info_window->area.h - sy) / 52;
807 dock = info_window;
808 n = 0;
809
810 unit_list_iterate(ptile->units, aunit) {
813
814 if (aunit == punit) {
815 continue;
816 }
817
822 fc_snprintf(buffer, sizeof(buffer),
823 "%s (%d,%d,%s)%s%s\n%s\n(%d/%d)\n%s",
825 putype->attack_strength,
826 putype->defense_strength,
827 move_points_text(putype->move_rate, FALSE),
828 (vetname != NULL ? "\n" : ""),
829 (vetname != NULL ? vetname : ""),
831 aunit->hp, putype->hp,
832 home_city ? city_name_get(home_city) : Q_("?homecity:None"));
834
838
841
842 put_unit(aunit, destcanvas, 1.0, 0, 0);
843
845
847
850
851 if (buf_surf->w > 64) {
852 float zoom = 64.0 / buf_surf->w;
853 SDL_Surface *zoomed = zoomSurface(buf_surf, zoom, zoom, 1);
854
857 }
858
859 pstr = create_utf8_from_char(buffer, 10);
860 pstr->style |= SF_CENTER;
861
865 buf->info_label = pstr;
866 buf->data.unit = aunit;
867 buf->id = ID_ICON;
868 widget_add_as_prev(buf, dock);
869 dock = buf;
870
871 if (!end) {
872 end = buf;
873 }
874
875 if (++n > num_w * num_h) {
877 }
878
881 }
882
884
886
888 dlg->end_active_widget_list = end;
890
891 if (n > num_w * num_h) {
892 if (!dlg->scroll) {
894 } else {
895 dlg->scroll->active = num_h;
896 dlg->scroll->step = num_w;
897 dlg->scroll->count = n;
899 }
900
901 /* create up button */
902 buf = dlg->scroll->up_left_button;
903 buf->size.x = info_window->area.x + info_window->area.w - buf->size.w;
904 buf->size.y = info_window->area.y + sy +
905 (info_window->size.h - sy - num_h * 52) / 2;
906 buf->size.h = (num_h * 52) / 2;
907
908 /* create down button */
910 buf->size.x = dlg->scroll->up_left_button->size.x;
911 buf->size.y = dlg->scroll->up_left_button->size.y +
912 dlg->scroll->up_left_button->size.h;
913 buf->size.h = dlg->scroll->up_left_button->size.h;
914 } else {
915 if (dlg->scroll) {
917 }
918 num_h = (n + num_w - 1) / num_w;
919 }
920
922 info_window->area.x + BLOCKU_W + adj_size(2),
923 info_window->size.y + sy +
924 (info_window->size.h - sy - num_h * 52) / 2,
925 0, 0, dlg->begin_active_widget_list,
927 } else {
928 if (info_window->private_data.adv_dlg->end_active_widget_list) {
929 del_group(info_window->private_data.adv_dlg->begin_active_widget_list,
930 info_window->private_data.adv_dlg->end_active_widget_list);
931 }
932 if (info_window->private_data.adv_dlg->scroll) {
933 hide_scrollbar(info_window->private_data.adv_dlg->scroll);
934 }
935 }
936 } else { /* punit */
937
938 if (info_window->private_data.adv_dlg->end_active_widget_list) {
939 del_group(info_window->private_data.adv_dlg->begin_active_widget_list,
940 info_window->private_data.adv_dlg->end_active_widget_list);
941 }
942 if (info_window->private_data.adv_dlg->scroll) {
943 hide_scrollbar(info_window->private_data.adv_dlg->scroll);
944 }
945
949 char buf[256];
950
951 fc_snprintf(buf, sizeof(buf), "%s\n%s\n%s",
952 _("End of Turn"), _("Press"), _("Shift+Return"));
954 pstr->style = SF_CENTER;
955 pstr->bgcol = (SDL_Color) {0, 0, 0, 0};
957 area.x = info_window->size.x + BLOCKU_W +
958 (info_window->size.w - BLOCKU_W - buf_surf->w) / 2;
959 area.y = info_window->size.y + (info_window->size.h - buf_surf->h) / 2;
960 alphablit(buf_surf, NULL, info_window->dst->surface, &area, 255);
963 /* Fix the bug of child dialogs not showing up when player's turn ends */
964 flush_all();
965 }
966 }
967
968 /* Draw buttons */
969 redraw_group(info_window->private_data.adv_dlg->begin_widget_list,
970 info_window->private_data.adv_dlg->end_widget_list->prev, 0);
971
973 }
974}
975
976/**********************************************************************/
983
984/**********************************************************************/
990void set_unit_icon(int idx, struct unit *punit)
991{
992 /* FIXME */
993 /* update_unit_info_label(punit);*/
994}
995
996/**********************************************************************/
1002{
1003/* Balast */
1004}
1005
1006/**********************************************************************/
1012{
1013 /* Nothing to do */
1014}
1015
1016/**********************************************************************/
1028void update_unit_info_label(struct unit_list *punitlist)
1029{
1030 if (C_S_RUNNING != client_state()) {
1031 return;
1032 }
1033
1034 /* draw unit info window */
1036
1037 if (punitlist) {
1038 if (!is_focus_anim_enabled()) {
1040 }
1041 } else {
1043 }
1044}
1045
1046/**********************************************************************/
1050{
1051 log_debug("MAPVIEW: update_timeout_label : PORT ME");
1052}
1053
1054/**********************************************************************/
1058{
1059 log_debug("MAPVIEW: update_turn_done_button : PORT ME");
1060}
1061
1062/* ===================================================================== */
1063/* ========================== City Descriptions ======================== */
1064/* ===================================================================== */
1065
1066/**********************************************************************/
1070{
1071 /* redraw buffer */
1073 dirty_all();
1074}
1075
1076/* ===================================================================== */
1077/* =============================== Mini Map ============================ */
1078/* ===================================================================== */
1079
1080/**********************************************************************/
1084{
1085 return overview_canvas;
1086}
1087
1088/**********************************************************************/
1093{
1094 /* calculate the dimensions in a way to always get a resulting
1095 overview with a height bigger than or equal to DEFAULT_OVERVIEW_H.
1096 First, the default dimensions are fed to the same formula that
1097 is used in overview_common.c. If the resulting height is
1098 smaller than DEFAULT_OVERVIEW_H, increase OVERVIEW_TILE_SIZE
1099 by 1 until the height condition is met.
1100 */
1102 int xfact = MAP_IS_ISOMETRIC ? 2 : 1;
1103 int shift = (MAP_IS_ISOMETRIC && !current_wrap_has_flag(WRAP_X)) ? -1 : 0;
1104
1106 (DEFAULT_OVERVIEW_H - 1) / wld.map.ysize) + 1;
1107
1108 do {
1110 if (*height < DEFAULT_OVERVIEW_H) {
1112 }
1113 } while (*height < DEFAULT_OVERVIEW_H);
1114
1116
1118}
1119
1120/**********************************************************************/
1125{
1126 struct widget *minimap;
1128
1131
1133 minimap->area.x + overview_start_x, minimap->area.x + overview_start_y,
1134 overview_canvas->surf->w, overview_canvas->surf->h
1135 };
1136
1137 alphablit(overview_canvas->surf, NULL, minimap->dst->surface,
1138 &overview_area, 255);
1139
1141 }
1142}
1143
1144/**********************************************************************/
1149{
1150 /* No scrollbars. */
1151}
1152
1153/**********************************************************************/
1156void put_cross_overlay_tile(struct tile *ptile)
1157{
1158 log_debug("MAPVIEW: put_cross_overlay_tile : PORT ME");
1159}
1160
1161/**********************************************************************/
1164void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h)
1165{
1166 /* PORTME */
1168 canvas_x, canvas_y, w, h,
1170}
1171
1172/**********************************************************************/
1176{
1177 /* PORTME */
1178 /* Here you should do any necessary redraws (for instance, the city
1179 * dialogs usually need to be resized). */
1181}
1182
1183/* =====================================================================
1184 City MAP
1185 ===================================================================== */
1186
1187/**********************************************************************/
1191{
1192 if (city_map_canvas != NULL) {
1195 }
1196}
1197
1198/**********************************************************************/
1202{
1203 /* City map dimensions might have changed, so create a new canvas each time */
1205
1208
1210
1211 return city_map_canvas->surf;
1212}
1213
1214/**********************************************************************/
1218{
1219 /* Tileset dimensions might have changed, so create a new canvas each time */
1220
1221 if (terrain_canvas) {
1223 }
1224
1227
1228 put_terrain(ptile, terrain_canvas, 1.0, 0, 0);
1229
1230 return terrain_canvas->surf;
1231}
1232
1233/**********************************************************************/
1237{
1238 /* TODO: PORTME. */
1239}
1240
1241/**********************************************************************/
1244void start_turn(void)
1245{}
1246
1247/**********************************************************************/
1251{
1252 /* Needed only with full screen zoom mode.
1253 * Not needed, nor implemented, in this client. */
1255}
SDL_Surface * zoomSurface(SDL_Surface *src, double zoomx, double zoomy, int smooth)
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
void astr_free(struct astring *astr)
Definition astring.c:153
#define n
Definition astring.c:77
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
void bugreport_request(const char *reason_format,...)
Definition bugs.c:31
const char * calendar_text(void)
Definition calendar.c:141
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
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 struct sprite int int int width
Definition canvas_g.h:44
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_owner(_pcity_)
Definition city.h:563
int get_citydlg_canvas_width(void)
void city_dialog_redraw_map(struct city *pcity, struct canvas *pcanvas)
int get_citydlg_canvas_height(void)
bool client_is_observer(void)
struct civclient client
enum client_states client_state(void)
#define client_player()
@ C_S_RUNNING
Definition client_main.h:47
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
char * incite_cost
Definition comments.c:75
void unit_focus_set(struct unit *punit)
Definition control.c:506
void request_new_unit_activity(struct unit *punit, enum unit_activity act)
Definition control.c:1929
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
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
@ O_GOLD
Definition fc_types.h:101
@ BORDERS_DISABLED
Definition fc_types.h:1037
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:734
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
int civ_population(const struct player *pplayer)
Definition game.c:74
struct city * game_city_by_number(int id)
Definition game.c:107
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
void canvas_free(struct canvas *store)
Definition canvas.c:44
struct canvas * canvas_create(int width, int height)
Definition canvas.c:28
struct city * owner
Definition citydlg.c:226
void popdown_all_game_dialogs(void)
Definition dialogs.c:1514
GtkWidget * overview_canvas
Definition gui_main.c:111
void update_timeout_label(void)
Definition mapview.c:118
void flush_dirty(void)
Definition mapview.c:468
void update_info_label(void)
Definition mapview.c:138
void update_turn_done_button(bool do_restore)
Definition mapview.c:76
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 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
void gui_flush(void)
Definition mapview.c:480
void update_map_canvas_scrollbars(void)
Definition mapview.c:681
void overview_size_changed(void)
Definition mapview.c:326
void map_canvas_size_refresh(void)
Definition mapview.c:414
struct canvas * get_overview_window(void)
Definition mapview.c:337
void set_indicator_icons(struct sprite *bulb, struct sprite *sol, struct sprite *flake, struct sprite *gov)
Definition mapview.c:302
enum client_pages get_current_client_page(void)
Definition pages.c:3345
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
const char * sdl_get_tile_defense_info_text(struct tile *ptile)
Definition dialogs.c:1306
int main_window_width(void)
Definition graphics.c:685
void update_main_screen(void)
Definition graphics.c:669
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1379
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:223
struct sdl2_data main_data
Definition graphics.c:57
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
bool correct_rect_region(SDL_Rect *prect)
Definition graphics.c:888
void screen_rect_to_layer_rect(struct gui_layer *gui_layer, SDL_Rect *dest_rect)
Definition graphics.c:173
void create_frame(SDL_Surface *dest, Sint16 left, Sint16 top, Sint16 width, Sint16 height, SDL_Color *pcolor)
Definition graphics.c:1348
int main_window_height(void)
Definition graphics.c:693
SDL_Surface * resize_surface_box(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth, bool scale_up, bool absolute_dimensions)
Definition graphics.c:1257
#define FREESURFACE(ptr)
Definition graphics.h:322
#define RECT_LIMIT
Definition graphics.h:45
#define adj_surf(surf)
Definition graphics.h:200
#define map_rgba(format, color)
Definition graphics.h:315
@ ID_COOLING_ICON
Definition gui_id.h:138
@ ID_WARMING_ICON
Definition gui_id.h:139
@ ID_ICON
Definition gui_id.h:33
void enable_focus_animation(void)
Definition gui_main.c:1195
bool flush_event(void)
Definition gui_main.c:1340
void disable_focus_animation(void)
Definition gui_main.c:1204
Uint32 sdl2_client_flags
Definition gui_main.c:101
#define CF_FOCUS_ANIMATION
Definition gui_main.h:51
#define CF_OVERVIEW_SHOWN
Definition gui_main.h:48
#define adj_size(size)
Definition gui_main.h:141
#define PRESSED_EVENT(event)
Definition gui_main.h:71
#define CF_UNITINFO_SHOWN
Definition gui_main.h:47
void draw_mouse_cursor(void)
Definition gui_mouse.c:100
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
void change_fonto_utf8(utf8_str *pstr, enum font_origin origin)
Definition gui_string.c:584
utf8_str * create_utf8_str_fonto(char *in_text, size_t n_alloc, enum font_origin origin)
Definition gui_string.c:241
SDL_Surface * create_text_surf_smaller_than_w(utf8_str *pstr, int w)
Definition gui_string.c:539
#define create_utf8_from_char(string_in, ptsize)
Definition gui_string.h:103
#define FREEUTF8STR(pstr)
Definition gui_string.h:93
#define SF_CENTER
Definition gui_string.h:40
@ FONTO_HEADING
Definition gui_string.h:69
@ FONTO_DEFAULT
Definition gui_string.h:65
@ FONTO_ATTENTION
Definition gui_string.h:67
#define create_utf8_from_char_fonto(string_in, fonto)
Definition gui_string.h:108
static SDL_Surface * get_tax_surface(Output_type_id otype)
static SDL_Surface * get_unittype_surface(const struct unit_type *punittype, enum direction8 facing)
struct widget * get_minimap_window_widget(void)
Definition mapctrl.c:2203
struct widget * get_research_widget(void)
Definition mapctrl.c:2219
int resize_minimap(void)
Definition mapctrl.c:554
struct widget * get_unit_info_window_widget(void)
Definition mapctrl.c:2195
struct widget * get_revolution_widget(void)
Definition mapctrl.c:2227
struct widget * get_tax_rates_widget(void)
Definition mapctrl.c:2211
#define DEFAULT_UNITS_W
Definition mapctrl.h:55
#define DEFAULT_UNITS_H
Definition mapctrl.h:56
#define BLOCKU_W
Definition mapctrl.h:52
#define DEFAULT_OVERVIEW_W
Definition mapctrl.h:53
#define DEFAULT_OVERVIEW_H
Definition mapctrl.h:54
void real_focus_units_changed(void)
Definition mapview.c:1011
void set_unit_icons_more_arrow(bool onoff)
Definition mapview.c:1001
void set_unit_icon(int idx, struct unit *punit)
Definition mapview.c:990
static bool is_focus_anim_enabled(void)
Definition mapview.c:979
SDL_Surface * create_city_map(struct city *pcity)
Definition mapview.c:1201
static void flush_mapcanvas(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Definition mapview.c:92
void refresh_overview(void)
Definition mapview.c:1124
static bool is_flush_queued
Definition mapview.c:87
void flush_rect(SDL_Rect *rect, bool force_flush)
Definition mapview.c:103
SDL_Surface * get_terrain_surface(struct tile *ptile)
Definition mapview.c:1217
void dirty_sdl_rect(SDL_Rect *Rect)
Definition mapview.c:181
void queue_flush(void)
Definition mapview.c:152
static int focus_units_info_callback(struct widget *pwidget)
Definition mapview.c:504
SDL_Rect * info_area
Definition widget.c:49
void redraw_unit_info_label(struct unit_list *punitlist)
Definition mapview.c:522
int overview_start_x
Definition mapview.c:73
void unqueue_flush(void)
Definition mapview.c:140
static struct canvas * terrain_canvas
Definition mapview.c:78
void city_map_canvas_free(void)
Definition mapview.c:1190
int overview_start_y
Definition mapview.c:74
void flush_all(void)
Definition mapview.c:201
#define GET_SURF(m_sprite)
Definition sprite.h:29
@ COLOR_THEME_MAPVIEW_UNITINFO_VETERAN_TEXT
Definition themecolors.h:96
@ COLOR_THEME_MAPVIEW_INFO_TEXT
Definition themecolors.h:94
@ COLOR_THEME_MAPVIEW_INFO_FRAME
Definition themecolors.h:93
@ COLOR_THEME_SELECTIONRECTANGLE
Definition themecolors.h:36
@ COLOR_THEME_MAPVIEW_UNITINFO_TEXT
Definition themecolors.h:95
void redraw_widget_info_label(SDL_Rect *rect)
Definition widget.c:467
struct widget * get_widget_pointer_from_main_list(Uint16 id)
Definition widget.c:578
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock)
Definition widget.c:602
int setup_vertical_widgets_position(int step, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h, struct widget *begin, struct widget *end)
Definition widget.c:1051
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:720
@ FC_WS_NORMAL
Definition widget.h:96
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_FREE_THEME
Definition widget.h:72
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
#define del_group(begin_group_widget_list, end_group_widget_list)
Definition widget.h:389
struct widget * create_icon2(SDL_Surface *icon, struct gui_layer *pdest, Uint32 flags)
void set_new_icon2_theme(struct widget *icon_widget, SDL_Surface *new_theme, bool free_old_theme)
Uint32 create_vertical_scrollbar(struct advanced_dialog *dlg, Uint8 step, Uint8 active, bool create_scrollbar, bool create_buttons)
#define hide_scrollbar(scrollbar)
#define show_scrollbar(scrollbar)
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
#define MAP_IS_ISOMETRIC
Definition map.h:42
#define current_wrap_has_flag(flag)
Definition map.h:51
void redraw_selection_rectangle(void)
void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
struct view mapview
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void show_city_descriptions(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
bool map_canvas_resized(int width, int height)
dirty_rect
Definition mapview_g.h:47
int int int pixel_width
Definition mapview_g.h:48
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1015
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
struct client_options gui_options
Definition options.c:71
int OVERVIEW_TILE_SIZE
#define OVERVIEW_TILE_WIDTH
#define OVERVIEW_TILE_HEIGHT
enum client_pages get_client_page(void)
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
#define is_human(plr)
Definition player.h:229
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
struct research * research_get(const struct player *pplayer)
Definition research.c:128
#define MIN(x, y)
Definition shared.h:55
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_active_widget_list
Definition widget.h:185
struct widget * active_widget_list
Definition widget.h:186
struct scroll_bar * scroll
Definition widget.h:187
SDL_Surface * surf
Definition canvas.h:27
Definition city.h:320
struct packet_game_info info
Definition game.h:89
int xsize
Definition map_types.h:78
int ysize
Definition map_types.h:78
struct connection conn
Definition client_main.h:96
struct overview overview
Definition options.h:425
bool ai_manual_turn_done
Definition options.h:154
struct player * playing
Definition connection.h:151
bool observer
Definition connection.h:147
SDL_Surface * surface
Definition graphics.h:229
SDL_Rect dest_rect
Definition graphics.h:228
int width
Definition options.h:94
int height
Definition options.h:94
enum borders_mode borders
struct player_economic economic
Definition player.h:282
bool phase_done
Definition player.h:261
struct widget * up_left_button
struct widget * down_right_button
int guis_count
Definition graphics.h:207
struct gui_layer * gui
Definition graphics.h:215
int rects_count
Definition graphics.h:206
SDL_Event event
Definition graphics.h:217
SDL_Rect rects[RECT_LIMIT]
Definition graphics.h:208
struct gui_layer ** guis
Definition graphics.h:216
SDL_Window * screen
Definition graphics.h:209
SDL_Surface * map
Definition graphics.h:210
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:138
enum direction8 facing
Definition unit.h:142
int veteran
Definition unit.h:152
int store_width
int store_height
struct canvas * store
union widget::@194 data
struct unit * unit
Definition widget.h:129
SDL_Rect area
Definition widget.h:149
SDL_Rect size
Definition widget.h:145
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define A_UNSET
Definition tech.h:48
const char * get_tile_output_text(const struct tile *ptile)
Definition text.c:63
const char * get_unit_info_label_text2(struct unit_list *punits, int linebreaks)
Definition text.c:1079
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define TILE_LB_RESOURCE_POLL
Definition tile.h:177
#define tile_owner(_tile)
Definition tile.h:96
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:789
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
void unit_activity_astr(const struct unit *punit, struct astring *astr)
Definition unit.c:1155
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const char * utype_veteran_name_translation(const struct unit_type *punittype, int level)
Definition unittype.c:2610
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560