Freeciv-3.1
Loading...
Searching...
No Matches
gui_main.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 gui_main.c - description
16 -------------------
17 begin : Sun Jun 30 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#include "fc_prehdrs.h"
27
28#include <errno.h>
29
30#ifdef HAVE_LOCALE_H
31#include <locale.h>
32#endif
33
34#ifdef HAVE_UNISTD_H
35#include <unistd.h>
36#endif
37
38/* SDL2 */
39#ifdef SDL2_PLAIN_INCLUDE
40#include <SDL.h>
41#else /* SDL2_PLAIN_INCLUDE */
42#include <SDL2/SDL.h>
43#endif /* SDL2_PLAIN_INCLUDE */
44
45/* utility */
46#include "fc_cmdline.h"
47#include "fciconv.h"
48#include "fcintl.h"
49#include "log.h"
50#include "netintf.h"
51
52/* common */
53#include "unitlist.h"
54
55/* client */
56#include "client_main.h"
57#include "climisc.h"
58#include "clinet.h"
59#include "editgui_g.h"
60#include "tilespec.h"
61#include "update_queue.h"
62#include "zoom.h"
63
64/* gui-sdl2 */
65#include "chatline.h"
66#include "citydlg.h"
67#include "cityrep.h"
68#include "diplodlg.h"
69#include "graphics.h"
70#include "gui_id.h"
71#include "gui_mouse.h"
72#include "gui_tilespec.h"
73#include "inteldlg.h"
74#include "mapctrl.h"
75#include "mapview.h"
76#include "menu.h"
77#include "messagewin.h"
78#include "optiondlg.h"
79#include "repodlgs.h"
80#include "themespec.h"
81#include "spaceshipdlg.h"
82#include "widget.h"
83
84#include "gui_main.h"
85
86#define UNITS_TIMER_INTERVAL 128 /* milliseconds */
87#define MAP_SCROLL_TIMER_INTERVAL 500
88
89const char *client_string = "gui-sdl2";
90
91/* The real GUI character encoding is UTF-16 which is not supported by
92 * fciconv code at this time. Conversion between UTF-8 and UTF-16 is done
93 * in gui_iconv.c */
94const char * const gui_character_encoding = "UTF-8";
96
98
102extern bool draw_goto_patrol_lines;
106bool LCTRL;
107bool RCTRL;
108bool LALT;
109static int city_names_font_size = 10;
111int *client_font_sizes[FONT_COUNT] = {
112 &city_names_font_size, /* FONT_CITY_NAME */
113 &city_productions_font_size, /* FONT_CITY_PROD */
114 &city_productions_font_size /* FONT_REQTREE_TEXT; not used yet */
115};
116
117static unsigned font_size_parameter = 0;
118
119/* ================================ Private ============================ */
120static int net_socket = -1;
121static bool autoconnect = FALSE;
123static enum direction8 scroll_dir;
124
127
128static SDL_Event __net_user_event;
129static SDL_Event __anim_user_event;
130static SDL_Event __info_user_event;
131static SDL_Event __flush_user_event;
132static SDL_Event __map_scroll_user_event;
133
134static SDL_Event *net_user_event = NULL;
135static SDL_Event *anim_user_event = NULL;
136static SDL_Event *info_user_event = NULL;
137static SDL_Event *flush_user_event = NULL;
138static SDL_Event *map_scroll_user_event = NULL;
139
140static void print_usage(void);
141static bool parse_options(int argc, char **argv);
142static int check_scroll_area(int x, int y);
143
145
156
157struct callback {
158 void (*callback)(void *data);
159 void *data;
160};
161
162#define SPECLIST_TAG callback
163#define SPECLIST_TYPE struct callback
164#include "speclist.h"
165
166struct callback_list *callbacks = NULL;
167
168/* =========================================================== */
169
170/**********************************************************************/
174static void print_usage(void)
175{
176 /* Add client-specific usage information here */
177 fc_fprintf(stderr,
178 _(" -f, --fullscreen\tStart Client in Fullscreen mode\n"));
179 fc_fprintf(stderr,
180 _(" -F, --Font SIZE\tUse SIZE as the base font size\n"));
181 fc_fprintf(stderr, _(" -s, --swrenderer\tUse SW renderer\n"));
182 fc_fprintf(stderr, _(" -t, --theme THEME\tUse GUI theme THEME\n"));
183
184 /* TRANS: No full stop after the URL, could cause confusion. */
185 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
186}
187
188/**********************************************************************/
191static bool parse_options(int argc, char **argv)
192{
193 int i = 1;
194 char *option = NULL;
195
196 while (i < argc) {
197 if (is_option("--help", argv[i])) {
198 print_usage();
199
200 return FALSE;
201 } else if (is_option("--fullscreen", argv[i])) {
203 } else if (is_option("--swrenderer", argv[i])) {
205 } else if ((option = get_option_malloc("--Font", argv, &i, argc, FALSE))) {
207 fc_fprintf(stderr, _("Invalid font size %s"), option);
208 exit(EXIT_FAILURE);
209 }
210 free(option);
211 } else if ((option = get_option_malloc("--theme", argv, &i, argc, FALSE))) {
213 free(option);
214 } else {
215 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
216 exit(EXIT_FAILURE);
217 }
218
219 i++;
220 }
221
222 return TRUE;
223}
224
225/**********************************************************************/
228static Uint16 main_key_down_handler(SDL_Keysym key, void *data)
229{
230 static struct widget *pwidget;
231
232 if ((pwidget = find_next_widget_for_key(NULL, key)) != NULL) {
233 return widget_pressed_action(pwidget);
234 } else {
235 if (key.sym == SDLK_TAB) {
236 /* input */
238 } else {
240 && C_S_RUNNING == client_state()) {
241 switch (key.sym) {
242 case SDLK_RETURN:
243 case SDLK_KP_ENTER:
244 if (LSHIFT || RSHIFT) {
246 key_end_turn();
247 } else {
248 struct unit *punit;
249 struct city *pcity;
250
251 if (NULL != (punit = head_of_units_in_focus())
252 && (pcity = tile_city(unit_tile(punit))) != NULL
253 && city_owner(pcity) == client.conn.playing) {
254 popup_city_dialog(pcity);
255 }
256 }
257 return ID_ERROR;
258
259 case SDLK_F2:
261 return ID_ERROR;
262
263 case SDLK_F4:
265 return ID_ERROR;
266
267 case SDLK_F7:
269 return ID_ERROR;
270
271 case SDLK_F8:
273 return ID_ERROR;
274
275 case SDLK_F9:
276 if (meswin_dialog_is_open()) {
278 } else {
280 }
281 flush_dirty();
282 return ID_ERROR;
283
284 case SDLK_F11:
286 return ID_ERROR;
287
288 case SDLK_F12:
290 return ID_ERROR;
291
292 case SDLK_ASTERISK:
294 return ID_ERROR;
295
296 default:
297 return ID_ERROR;
298 }
299 }
300 }
301 }
302
303 return ID_ERROR;
304}
305
306/**********************************************************************/
309static Uint16 main_key_up_handler(SDL_Keysym key, void *data)
310{
311 if (selected_widget) {
313 }
314
315 return ID_ERROR;
316}
317/**********************************************************************/
320static Uint16 main_finger_down_handler(SDL_TouchFingerEvent *touch_event,
321 void *data)
322{
323 struct widget *pwidget;
324 /* Touch event coordinates are normalized (0...1). */
325 int x = touch_event->x * main_window_width();
326 int y = touch_event->y * main_window_height();
327
328 if ((pwidget = find_next_widget_at_pos(NULL, x, y)) != NULL) {
329 if (get_wstate(pwidget) != FC_WS_DISABLED) {
330 return widget_pressed_action(pwidget);
331 }
332 } else {
333 /* No visible widget at this position; map pressed. */
335 /* Start counting. */
341 }
342 }
343 return ID_ERROR;
344}
345/**********************************************************************/
349 void *data)
350{
351 /* Touch event coordinates are normalized (0...1). */
352 int x = touch_event->x * main_window_width();
353 int y = touch_event->y * main_window_height();
354 /* Screen wasn't pressed over a widget. */
356 && !find_next_widget_at_pos(NULL, x, y)) {
359 }
360
363
365
366 return ID_ERROR;
367}
368
369/**********************************************************************/
373 void *data)
374{
375 struct widget *pwidget;
376
377 if ((pwidget = find_next_widget_at_pos(NULL,
378 button_event->x,
379 button_event->y)) != NULL) {
380 if (get_wstate(pwidget) != FC_WS_DISABLED) {
381 return widget_pressed_action(pwidget);
382 }
383 } else {
384 /* no visible widget at this position -> map click */
385#ifdef UNDER_CE
387#endif
389 /* start counting */
395 mouse_zoom);
396 }
397#ifdef UNDER_CE
398 }
399#endif
400 }
401
402 return ID_ERROR;
403}
404
405/**********************************************************************/
424
425#ifdef UNDER_CE
426 #define SCROLL_MAP_AREA 8
427#else
428 #define SCROLL_MAP_AREA 1
429#endif
430
431/**********************************************************************/
435 void *data)
436{
437 static struct widget *pwidget;
438 struct tile *ptile;
439
440 /* stop evaluating button hold time when moving to another tile in medium
441 * hold state or above */
443 ptile = canvas_pos_to_tile(motion_event->x, motion_event->y,
444 mouse_zoom);
447 }
448 }
449
451 update_line(motion_event->x, motion_event->y);
452 }
453
454#ifndef UNDER_CE
456 check_scroll_area(motion_event->x, motion_event->y);
457 }
458#endif /* UNDER_CE */
459
460 if ((pwidget = find_next_widget_at_pos(NULL,
461 motion_event->x,
462 motion_event->y)) != NULL) {
464 if (get_wstate(pwidget) != FC_WS_DISABLED) {
465 widget_selected_action(pwidget);
466 }
467 } else {
468 if (selected_widget) {
470 } else {
471 control_mouse_cursor(canvas_pos_to_tile(motion_event->x, motion_event->y,
472 mouse_zoom));
473 }
474 }
475
477
478 return ID_ERROR;
479}
480
481/**********************************************************************/
486{
487 /* button pressed */
489 if (((SDL_GetTicks() - button_behavior.button_down_ticks) >= MB_MEDIUM_HOLD_DELAY)
490 && ((SDL_GetTicks() - button_behavior.button_down_ticks) < MB_LONG_HOLD_DELAY)) {
491
495 }
496
497 } else if (((SDL_GetTicks() - button_behavior.button_down_ticks)
498 >= MB_LONG_HOLD_DELAY)) {
499
503 }
504 }
505 }
506
507 return;
508}
509
510/**********************************************************************/
513static int check_scroll_area(int x, int y)
514{
515 SDL_Rect rect_north = {0, 0, main_data.map->w, SCROLL_MAP_AREA};
516 SDL_Rect rect_east = {main_data.map->w - SCROLL_MAP_AREA, 0, SCROLL_MAP_AREA, main_data.map->h};
517 SDL_Rect rect_south = {0, main_data.map->h - SCROLL_MAP_AREA, main_data.map->w, SCROLL_MAP_AREA};
518 SDL_Rect rect_west = {0, 0, SCROLL_MAP_AREA, main_data.map->h};
519
520 if (is_in_rect_area(x, y, rect_north)) {
522 if (is_in_rect_area(x, y, rect_west)) {
523 scroll_dir = DIR8_NORTHWEST;
524 } else if (is_in_rect_area(x, y, rect_east)) {
525 scroll_dir = DIR8_NORTHEAST;
526 } else {
527 scroll_dir = DIR8_NORTH;
528 }
529 } else if (is_in_rect_area(x, y, rect_south)) {
531 if (is_in_rect_area(x, y, rect_west)) {
532 scroll_dir = DIR8_SOUTHWEST;
533 } else if (is_in_rect_area(x, y, rect_east)) {
534 scroll_dir = DIR8_SOUTHEAST;
535 } else {
536 scroll_dir = DIR8_SOUTH;
537 }
538 } else if (is_in_rect_area(x, y, rect_east)) {
540 scroll_dir = DIR8_EAST;
541 } else if (is_in_rect_area(x, y, rect_west)) {
543 scroll_dir = DIR8_WEST;
544 } else {
546 }
547
548 return is_map_scrolling;
549}
550
551/* ============================ Public ========================== */
552
553/**********************************************************************/
557{
558 SDL_Event event;
559
560 event.type = user_event_type;
561 event.user.code = EXIT_FROM_EVENT_LOOP;
562 event.user.data1 = NULL;
563 event.user.data2 = NULL;
564
565 SDL_PushEvent(&event);
566}
567
568/**********************************************************************/
572int FilterMouseMotionEvents(void *data, SDL_Event *event)
573{
574 if (event->type == SDL_MOUSEMOTION) {
575 static int x = 0, y = 0;
576
577 if (((MOVE_STEP_X > 0) && (abs(event->motion.x - x) >= MOVE_STEP_X))
578 || ((MOVE_STEP_Y > 0) && (abs(event->motion.y - y) >= MOVE_STEP_Y)) ) {
579 x = event->motion.x;
580 y = event->motion.y;
581 return 1; /* Catch it */
582 } else {
583 return 0; /* Drop it, we've handled it */
584 }
585 }
586
587 return 1;
588}
589
590/**********************************************************************/
593Uint16 gui_event_loop(void *data,
594 void (*loop_action)(void *data),
595 Uint16 (*key_down_handler)(SDL_Keysym key, void *data),
596 Uint16 (*key_up_handler)(SDL_Keysym key, void *data),
597 Uint16 (*textinput_handler)(char *text, void *data),
598 Uint16 (*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data),
599 Uint16 (*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data),
600 Uint16 (*finger_motion_handler)(SDL_TouchFingerEvent *touch_event,
601 void *data),
602 Uint16 (*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event,
603 void *data),
604 Uint16 (*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event,
605 void *data),
606 Uint16 (*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event,
607 void *data))
608{
609 Uint16 ID;
610 static fc_timeval tv;
611 static fd_set civfdset;
612 Uint32 t_current, t_last_unit_anim, t_last_map_scrolling;
613 Uint32 real_timer_next_call;
614 static int result;
615
616 ID = ID_ERROR;
617 t_last_map_scrolling = t_last_unit_anim = real_timer_next_call = SDL_GetTicks();
618 while (ID == ID_ERROR) {
619 /* ========================================= */
620 /* Net check with 10ms delay event loop */
621 if (net_socket >= 0) {
622 FD_ZERO(&civfdset);
623
624 if (net_socket >= 0) {
625 FD_SET(net_socket, &civfdset);
626 }
627
628 tv.tv_sec = 0;
629 tv.tv_usec = 10000; /* 10ms*/
630
631 result = fc_select(net_socket + 1, &civfdset, NULL, NULL, &tv);
632 if (result < 0) {
633 if (errno != EINTR) {
634 break;
635 } else {
636 continue;
637 }
638 } else {
639 if (result > 0) {
640 if ((net_socket >= 0) && FD_ISSET(net_socket, &civfdset)) {
641 SDL_PushEvent(net_user_event);
642 }
643 }
644 }
645 } else { /* If connection is not establish */
646 SDL_Delay(10);
647 }
648 /* ========================================= */
649
650 t_current = SDL_GetTicks();
651
652 if (t_current > real_timer_next_call) {
653 real_timer_next_call = t_current + (real_timer_callback() * 1000);
654 }
655
656 if ((t_current - t_last_unit_anim) > UNITS_TIMER_INTERVAL) {
657 if (autoconnect) {
659 SDL_PushEvent(anim_user_event);
660 } else {
661 SDL_PushEvent(anim_user_event);
662 }
663
664 t_last_unit_anim = SDL_GetTicks();
665 }
666
667 if (is_map_scrolling) {
668 if ((t_current - t_last_map_scrolling) > MAP_SCROLL_TIMER_INTERVAL) {
669 SDL_PushEvent(map_scroll_user_event);
670 t_last_map_scrolling = SDL_GetTicks();
671 }
672 } else {
673 t_last_map_scrolling = SDL_GetTicks();
674 }
675
676 if (widget_info_counter > 0) {
677 SDL_PushEvent(info_user_event);
679 }
680
681 /* ========================================= */
682
683 if (loop_action) {
684 loop_action(data);
685 }
686
687 /* ========================================= */
688
689 while (SDL_PollEvent(&main_data.event) == 1) {
690
691 if (main_data.event.type == user_event_type) {
692 switch (main_data.event.user.code) {
693 case NET:
695 break;
696 case ANIM:
700 break;
703 break;
704 case TRY_AUTO_CONNECT:
705 if (try_to_autoconnect()) {
708 }
709 break;
710 case FLUSH:
712 break;
713 case MAP_SCROLL:
715 break;
717 return MAX_ID;
718 break;
719 default:
720 break;
721 }
722
723 } else {
724
725 switch (main_data.event.type) {
726
727 case SDL_QUIT:
728 return MAX_ID;
729 break;
730
731 case SDL_KEYUP:
732 switch (main_data.event.key.keysym.sym) {
733 /* find if Shifts are released */
734 case SDLK_RSHIFT:
735 RSHIFT = FALSE;
736 break;
737 case SDLK_LSHIFT:
738 LSHIFT = FALSE;
739 break;
740 case SDLK_LCTRL:
741 LCTRL = FALSE;
742 break;
743 case SDLK_RCTRL:
744 RCTRL = FALSE;
745 break;
746 case SDLK_LALT:
747 LALT = FALSE;
748 break;
749 default:
750 if (key_up_handler) {
751 ID = key_up_handler(main_data.event.key.keysym, data);
752 }
753 break;
754 }
755 break;
756
757 case SDL_KEYDOWN:
758 switch (main_data.event.key.keysym.sym) {
759#if 0
760 case SDLK_PRINT:
761 fc_snprintf(schot, sizeof(schot), "fc_%05d.bmp", schot_nr++);
762 log_normal(_("Making screenshot %s"), schot);
763 SDL_SaveBMP(main_data.screen, schot);
764 break;
765#endif /* 0 */
766
767 case SDLK_RSHIFT:
768 /* Right Shift is Pressed */
769 RSHIFT = TRUE;
770 break;
771
772 case SDLK_LSHIFT:
773 /* Left Shift is Pressed */
774 LSHIFT = TRUE;
775 break;
776
777 case SDLK_LCTRL:
778 /* Left CTRL is Pressed */
779 LCTRL = TRUE;
780 break;
781
782 case SDLK_RCTRL:
783 /* Right CTRL is Pressed */
784 RCTRL = TRUE;
785 break;
786
787 case SDLK_LALT:
788 /* Left ALT is Pressed */
789 LALT = TRUE;
790 break;
791
792 default:
793 if (key_down_handler) {
794 ID = key_down_handler(main_data.event.key.keysym, data);
795 }
796 break;
797 }
798 break;
799
800 case SDL_TEXTINPUT:
801 if (textinput_handler) {
802 ID = textinput_handler(main_data.event.text.text, data);
803 }
804 break;
805
806 case SDL_FINGERDOWN:
807 if (finger_down_handler) {
808 ID = finger_down_handler(&main_data.event.tfinger, data);
809 }
810 break;
811
812 case SDL_FINGERUP:
813 if (finger_up_handler) {
814 ID = finger_up_handler(&main_data.event.tfinger, data);
815 }
816 break;
817
818 case SDL_FINGERMOTION:
819 if (finger_motion_handler) {
820 ID = finger_motion_handler(&main_data.event.tfinger, data);
821 }
822 break;
823
824 case SDL_MOUSEBUTTONDOWN:
825 if (mouse_button_down_handler) {
826 ID = mouse_button_down_handler(&main_data.event.button, data);
827 }
828 break;
829
830 case SDL_MOUSEBUTTONUP:
831 if (mouse_button_up_handler) {
832 ID = mouse_button_up_handler(&main_data.event.button, data);
833 }
834 break;
835
836 case SDL_MOUSEMOTION:
837 if (mouse_motion_handler) {
838 ID = mouse_motion_handler(&main_data.event.motion, data);
839 }
840 break;
841 }
842 }
843 }
844
845 if (ID == ID_ERROR) {
846 if (callbacks && callback_list_size(callbacks) > 0) {
847 struct callback *cb = callback_list_get(callbacks, 0);
848
849 callback_list_remove(callbacks, cb);
850 (cb->callback)(cb->data);
851 free(cb);
852 }
853 }
854
856 }
857
858 return ID;
859}
860
861/* ============ Freeciv native game function =========== */
862
863/**********************************************************************/
866void ui_init(void)
867{
868 Uint32 sdl_flags;
869
873 button_behavior.event = fc_calloc(1, sizeof(SDL_MouseButtonEvent));
874
876 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
877
878 init_sdl(sdl_flags);
879}
880
881/**********************************************************************/
885{
886 struct widget *widget;
887
888 if (C_S_RUNNING == client_state()) {
889 /* Move units window to botton-right corner. */
891 /* Move minimap window to botton-left corner. */
893
894 /* Move cooling/warming icons to botton-right corner. */
897 - (widget->size.w * 2)), widget->size.y);
898
901 - widget->size.w), widget->size.y);
902
906 center_on_something(); /* With redrawing full map. */
908 } else {
910 dirty_all();
911 }
912
913 flush_all();
914}
915
916/**********************************************************************/
923
924/**********************************************************************/
950
951/**********************************************************************/
956{
957 struct option *poption;
958
959#define option_var_set_callback(var, callback) \
960 if ((poption = optset_option_by_name(client_optset, #var))) { \
961 option_set_changed_callback(poption, callback); \
962 } else { \
963 log_error("Didn't find option %s!", #var); \
964 }
965
966 option_var_set_callback(gui_sdl2_fullscreen, fullscreen_callback);
968#undef option_var_set_callback
969}
970
971/**********************************************************************/
976{
977 int i;
978
979 /* clear double call */
980 for (i = 0; i <= event_type_max(); i++) {
981 if (messages_where[i] & MW_MESSAGES) {
982 messages_where[i] &= ~MW_OUTPUT;
983 }
984 }
985}
986
987/**********************************************************************/
992int main(int argc, char **argv)
993{
994 return client_main(argc, argv, FALSE);
995}
996
997/**********************************************************************/
1001{
1002 log_normal(_("Migrating options from sdl to sdl2 client"));
1003
1004#define MIGRATE_OPTION(opt) gui_options.gui_sdl2_##opt = gui_options.gui_sdl_##opt;
1005
1006 /* Default theme name is never migrated */
1007 MIGRATE_OPTION(fullscreen);
1008 MIGRATE_OPTION(screen);
1009 MIGRATE_OPTION(do_cursor_animation);
1010 MIGRATE_OPTION(use_color_cursors);
1011
1012#undef MIGRATE_OPTION
1013
1015}
1016
1017/**********************************************************************/
1021int ui_main(int argc, char *argv[])
1022{
1023 Uint32 flags = 0;
1024
1025 if (parse_options(argc, argv)) {
1028 }
1029
1031 flags |= SDL_WINDOW_FULLSCREEN;
1032 } else {
1033 flags &= ~SDL_WINDOW_FULLSCREEN;
1034 }
1035 log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver());
1038 flags)) {
1039 return EXIT_FAILURE;
1040 }
1041
1042 user_event_type = SDL_RegisterEvents(1);
1043
1044 SDL_zero(__net_user_event);
1046 __net_user_event.user.code = NET;
1047 __net_user_event.user.data1 = NULL;
1048 __net_user_event.user.data2 = NULL;
1050
1051 SDL_zero(__anim_user_event);
1053 __anim_user_event.user.code = EVENT_ERROR;
1054 __anim_user_event.user.data1 = NULL;
1055 __anim_user_event.user.data2 = NULL;
1057
1058 SDL_zero(__info_user_event);
1061 __info_user_event.user.data1 = NULL;
1062 __info_user_event.user.data2 = NULL;
1064
1065 SDL_zero(__flush_user_event);
1067 __flush_user_event.user.code = FLUSH;
1068 __flush_user_event.user.data1 = NULL;
1069 __flush_user_event.user.data2 = NULL;
1071
1072 SDL_zero(__map_scroll_user_event);
1075 __map_scroll_user_event.user.data1 = NULL;
1076 __map_scroll_user_event.user.data2 = NULL;
1078
1080
1086
1090
1091 load_cursors();
1092
1093 callbacks = callback_list_new();
1094
1097
1099
1101
1102 /* This need correct main_data.screen size */
1104
1106
1107 /* Main game loop */
1113
1114#if defined UNDER_CE && defined SMALL_SCREEN
1115 /* Change back to window mode to restore the title bar */
1116 set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT);
1117#endif
1118
1120
1122
1124
1127
1128 callback_list_destroy(callbacks);
1129 callbacks = NULL;
1130
1132
1133 free(button_behavior.event);
1134 button_behavior.event = NULL;
1135
1137
1138 del_main_list();
1139
1142 active_theme = NULL;
1143
1144 quit_sdl();
1145 }
1146
1147 return EXIT_SUCCESS;
1148}
1149
1150/**********************************************************************/
1153void ui_exit(void)
1154{
1155}
1156
1157/**********************************************************************/
1160enum gui_type get_gui_type(void)
1161{
1162 return GUI_SDL2;
1163}
1164
1165/**********************************************************************/
1169void sound_bell(void)
1170{
1171 log_debug("sound_bell : PORT ME");
1172}
1173
1174/**********************************************************************/
1178{
1179 anim_user_event->user.code = ANIM;
1181}
1182
1183/**********************************************************************/
1187{
1188 sdl2_client_flags &= ~CF_FOCUS_ANIMATION;
1189}
1190
1191/**********************************************************************/
1195void add_net_input(int sock)
1196{
1197 log_debug("Connection UP (%d)", sock);
1198 net_socket = sock;
1201}
1202
1203/**********************************************************************/
1207{
1208 log_debug("Connection DOWN... ");
1209 net_socket = (-1);
1213}
1214
1215/**********************************************************************/
1220void add_idle_callback(void (callback)(void *), void *data)
1221{
1222 if (callbacks != NULL) {
1223 struct callback *cb = fc_malloc(sizeof(*cb));
1224
1225 cb->callback = callback;
1226 cb->data = data;
1227
1228 callback_list_prepend(callbacks, cb);
1229 }
1230}
1231
1232/**********************************************************************/
1236{}
1237
1238/**********************************************************************/
1242{}
1243
1244/**********************************************************************/
1247void editgui_popup_properties(const struct tile_list *tiles, int objtype)
1248{}
1249
1250/**********************************************************************/
1254{}
1255
1256/**********************************************************************/
1259void editgui_notify_object_changed(int objtype, int object_id, bool removal)
1260{}
1261
1262/**********************************************************************/
1266{}
1267
1268/**********************************************************************/
1271void gui_update_font(const char *font_name, const char *font_value)
1272{
1273#define CHECK_FONT(client_font, action) \
1274 do { \
1275 if (strcmp(#client_font, font_name) == 0) { \
1276 char *end; \
1277 long size = strtol(font_value, &end, 10); \
1278 if (end && *end == '\0' && size > 0) { \
1279 *client_font_sizes[client_font] = size; \
1280 action; \
1281 } \
1282 } \
1283 } while (FALSE)
1284
1287 /* FONT_REQTREE_TEXT not used yet */
1288
1289#undef CHECK_FONT
1290}
1291
1292/**********************************************************************/
1295unsigned default_font_size(struct theme *act_theme)
1296{
1298 theme_default_font_size(act_theme);
1299}
1300
1301/**********************************************************************/
1304void update_font_from_theme(int theme_font_size)
1305{
1306 *client_font_sizes[FONT_CITY_NAME] = theme_font_size;
1307 *client_font_sizes[FONT_CITY_PROD] = theme_font_size;
1308}
1309
1310/**********************************************************************/
1313void insert_client_build_info(char *outbuf, size_t outlen)
1314{
1315 /* PORTME */
1316}
1317
1318/**********************************************************************/
1321bool flush_event(void)
1322{
1323 return SDL_PushEvent(flush_user_event) >= 0;
1324}
FONT_CITY_NAME
Definition canvas_g.h:70
FONT_CITY_PROD
Definition canvas_g.h:71
#define city_owner(_pcity_)
Definition city.h:543
void popup_city_dialog(struct city *pcity)
double real_timer_callback(void)
int client_main(int argc, char *argv[], bool postpone_tileset)
struct civclient client
enum client_states client_state(void)
void send_report_request(enum report_type type)
void start_quitting(void)
void set_client_state(enum client_states newstate)
@ C_S_DISCONNECTED
Definition client_main.h:45
@ C_S_RUNNING
Definition client_main.h:47
void center_on_something(void)
Definition climisc.c:424
double try_to_autoconnect(void)
Definition clinet.c:492
void input_from_server(int fd)
Definition clinet.c:406
struct unit_list * get_units_in_focus(void)
Definition control.c:177
void key_end_turn(void)
Definition control.c:3153
struct unit * head_of_units_in_focus(void)
Definition control.c:411
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1214
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:73
int objtype
Definition editgui_g.h:28
editgui_notify_object_changed
Definition editgui_g.h:27
enum event_type event
Definition events.c:81
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
char * get_option_malloc(const char *option_name, char **argv, int *i, int argc, bool gc)
Definition fc_cmdline.c:50
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define _(String)
Definition fcintl.h:67
void city_report_dialog_popup(bool raise)
Definition cityrep.c:292
void diplomacy_dialog_init(void)
Definition diplodlg.c:1175
void diplomacy_dialog_done(void)
Definition diplodlg.c:1184
void load_cursors(void)
Definition graphics.c:78
int ui_main(int argc, char **argv)
Definition gui_main.c:1702
const char * client_string
Definition gui_main.c:104
static void print_usage(void)
Definition gui_main.c:249
#define option_var_set_callback(var, callback)
void ui_exit(void)
Definition gui_main.c:1872
enum gui_type get_gui_type(void)
Definition gui_main.c:1883
int main(int argc, char **argv)
Definition gui_main.c:1627
void ui_init(void)
Definition gui_main.c:1618
void add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.c:2210
void options_extra_init(void)
Definition gui_main.c:2284
void insert_client_build_info(char *outbuf, size_t outlen)
Definition gui_main.c:2343
void remove_net_input(void)
Definition gui_main.c:2116
void sound_bell(void)
Definition gui_main.c:1891
const char *const gui_character_encoding
Definition gui_main.c:160
void add_net_input(int sock)
Definition gui_main.c:2098
static bool parse_options(int argc, char **argv)
Definition gui_main.c:286
#define MIGRATE_OPTION(opt)
const bool gui_use_transliteration
Definition gui_main.c:161
void intel_dialog_done(void)
Definition inteldlg.c:127
void intel_dialog_init(void)
Definition inteldlg.c:118
void flush_dirty(void)
Definition mapview.c:450
void update_info_label(void)
Definition mapview.c:121
void dirty_all(void)
Definition mapview.c:438
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:258
void update_city_descriptions(void)
Definition mapview.c:470
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:240
void meswin_dialog_popdown(void)
Definition messagewin.c:431
void meswin_dialog_popup(bool raise)
Definition messagewin.c:416
bool meswin_dialog_is_open(void)
Definition messagewin.c:442
void units_report_dialog_popup(bool raise)
Definition repodlgs.c:1765
void popup_spaceship_dialog(struct player *pplayer)
void popup_input_line(void)
Definition chatline.c:358
bool set_video_mode(unsigned width, unsigned height, unsigned flags_in)
Definition graphics.c:636
bool is_in_rect_area(int x, int y, SDL_Rect rect)
Definition graphics.c:925
int main_window_width(void)
Definition graphics.c:685
void init_sdl(int flags)
Definition graphics.c:506
void update_main_screen(void)
Definition graphics.c:669
void quit_sdl(void)
Definition graphics.c:622
struct sdl2_data main_data
Definition graphics.c:57
bool create_surfaces(int width, int height)
Definition graphics.c:556
int main_window_height(void)
Definition graphics.c:693
static int city_names_font_size
Definition gui_main.c:109
static Uint16 main_key_down_handler(SDL_Keysym key, void *data)
Definition gui_main.c:228
static SDL_Event __anim_user_event
Definition gui_main.c:129
static void migrate_options_from_sdl(void)
Definition gui_main.c:1000
static SDL_Event * net_user_event
Definition gui_main.c:134
static int check_scroll_area(int x, int y)
Definition gui_main.c:513
static void resize_window_callback(struct option *poption)
Definition gui_main.c:919
static void fullscreen_callback(struct option *poption)
Definition gui_main.c:927
void editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition gui_main.c:1247
void editgui_notify_object_created(int tag, int id)
Definition gui_main.c:1265
#define CHECK_FONT(client_font, action)
static struct mouse_button_behavior button_behavior
Definition gui_main.c:126
bool is_unit_move_blocked
Definition gui_main.c:103
static SDL_Event __info_user_event
Definition gui_main.c:130
bool LSHIFT
Definition gui_main.c:104
static SDL_Event __flush_user_event
Definition gui_main.c:131
int FilterMouseMotionEvents(void *data, SDL_Event *event)
Definition gui_main.c:572
static SDL_Event * info_user_event
Definition gui_main.c:136
static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event, void *data)
Definition gui_main.c:372
static SDL_Event __net_user_event
Definition gui_main.c:128
void enable_focus_animation(void)
Definition gui_main.c:1177
void editgui_popdown_all(void)
Definition gui_main.c:1253
bool flush_event(void)
Definition gui_main.c:1321
#define MAP_SCROLL_TIMER_INTERVAL
Definition gui_main.c:87
static void real_resize_window_callback(void *data)
Definition gui_main.c:884
bool draw_goto_patrol_lines
Definition mapctrl.c:104
#define UNITS_TIMER_INTERVAL
Definition gui_main.c:86
static void update_button_hold_state(void)
Definition gui_main.c:485
static bool is_map_scrolling
Definition gui_main.c:122
static SDL_Event * map_scroll_user_event
Definition gui_main.c:138
bool RSHIFT
Definition gui_main.c:105
int MOVE_STEP_Y
Definition gui_main.c:101
Uint16 gui_event_loop(void *data, void(*loop_action)(void *data), Uint16(*key_down_handler)(SDL_Keysym key, void *data), Uint16(*key_up_handler)(SDL_Keysym key, void *data), Uint16(*textinput_handler)(char *text, void *data), Uint16(*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_motion_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event, void *data))
Definition gui_main.c:593
static Uint16 main_finger_down_handler(SDL_TouchFingerEvent *touch_event, void *data)
Definition gui_main.c:320
#define SCROLL_MAP_AREA
Definition gui_main.c:428
Uint32 widget_info_counter
Definition gui_main.c:99
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event, void *data)
Definition gui_main.c:434
static SDL_Event * anim_user_event
Definition gui_main.c:135
static bool autoconnect
Definition gui_main.c:121
static int net_socket
Definition gui_main.c:120
static Uint16 main_finger_up_handler(SDL_TouchFingerEvent *touch_event, void *data)
Definition gui_main.c:348
void update_font_from_theme(int theme_font_size)
Definition gui_main.c:1304
static int city_productions_font_size
Definition gui_main.c:110
bool LALT
Definition gui_main.c:108
bool LCTRL
Definition gui_main.c:106
unsigned default_font_size(struct theme *act_theme)
Definition gui_main.c:1295
static void clear_double_messages_call(void)
Definition gui_main.c:975
void force_exit_from_event_loop(void)
Definition gui_main.c:556
void disable_focus_animation(void)
Definition gui_main.c:1186
static enum direction8 scroll_dir
Definition gui_main.c:123
static unsigned font_size_parameter
Definition gui_main.c:117
int * client_font_sizes[FONT_COUNT]
Definition gui_main.c:111
void editgui_refresh(void)
Definition gui_main.c:1241
int user_event_type
Definition gui_main.c:144
static SDL_Event __map_scroll_user_event
Definition gui_main.c:132
Uint32 sdl2_client_flags
Definition gui_main.c:97
static SDL_Event * flush_user_event
Definition gui_main.c:137
struct callback_list * callbacks
Definition gui_main.c:166
USER_EVENT_ID
Definition gui_main.c:146
@ NET
Definition gui_main.c:148
@ ANIM
Definition gui_main.c:149
@ TRY_AUTO_CONNECT
Definition gui_main.c:150
@ MAP_SCROLL
Definition gui_main.c:153
@ FLUSH
Definition gui_main.c:152
@ EVENT_ERROR
Definition gui_main.c:147
@ EXIT_FROM_EVENT_LOOP
Definition gui_main.c:154
@ SHOW_WIDGET_INFO_LABEL
Definition gui_main.c:151
static Uint16 main_key_up_handler(SDL_Keysym key, void *data)
Definition gui_main.c:309
void editgui_tileset_changed(void)
Definition gui_main.c:1235
static Uint16 main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event, void *data)
Definition gui_main.c:408
int MOVE_STEP_X
Definition gui_main.c:100
bool RCTRL
Definition gui_main.c:107
#define CF_FOCUS_ANIMATION
Definition gui_main.h:48
#define CF_DRAW_PLAYERS_ALLIANCE_STATUS
Definition gui_main.h:59
#define CF_DRAW_PLAYERS_CEASEFIRE_STATUS
Definition gui_main.h:57
#define CF_SWRENDERER
Definition gui_main.h:61
#define CF_DRAW_PLAYERS_PEACE_STATUS
Definition gui_main.h:58
@ MB_HOLD_LONG
Definition gui_main.h:77
@ MB_HOLD_MEDIUM
Definition gui_main.h:76
@ MB_HOLD_SHORT
Definition gui_main.h:75
#define MB_MEDIUM_HOLD_DELAY
Definition gui_main.h:64
struct widget * selected_widget
Definition widget.c:48
#define CF_DRAW_PLAYERS_NEUTRAL_STATUS
Definition gui_main.h:60
#define adj_size(size)
Definition gui_main.h:138
#define DEFAULT_MOVE_STEP
Definition gui_main.h:110
#define MB_LONG_HOLD_DELAY
Definition gui_main.h:65
#define CF_DRAW_PLAYERS_WAR_STATUS
Definition gui_main.h:56
void button_down_on_map(struct mouse_button_behavior *button_behavior)
Definition mapctrl.c:2280
void button_up_on_map(struct mouse_button_behavior *button_behavior)
Definition mapctrl.c:2351
void finger_up_on_map(struct finger_behavior *finger_behavior)
Definition mapctrl.c:2267
bool map_event_handler(SDL_Keysym key)
Definition mapctrl.c:2445
void set_new_minimap_window_pos(void)
Definition mapctrl.c:1386
void set_new_unitinfo_window_pos(void)
Definition mapctrl.c:1332
void unqueue_flush(void)
Definition mapview.c:140
void city_map_canvas_free(void)
Definition mapview.c:1190
void flush_all(void)
Definition mapview.c:201
void update_order_widgets(void)
Definition menu.c:970
@ ID_COOLING_ICON
Definition gui_id.h:139
@ ID_ERROR
Definition gui_id.h:26
@ ID_WARMING_ICON
Definition gui_id.h:140
const char * font_name
Definition gui_main_g.h:43
gui_update_font
Definition gui_main_g.h:43
void animate_mouse_cursor(void)
Definition gui_mouse.c:182
void unload_cursors(void)
Definition gui_mouse.c:164
void draw_mouse_cursor(void)
Definition gui_mouse.c:100
void free_font_system(void)
Definition gui_string.c:698
void setup_auxiliary_tech_icons(void)
void draw_intro_gfx(void)
void free_auxiliary_tech_icons(void)
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
void update_line(int canvas_x, int canvas_y)
void scroll_mapview(enum direction8 gui_dir)
void init_mapcanvas_and_overview(void)
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
void free_mapcanvas_and_overview(void)
bool map_canvas_resized(int width, int height)
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_malloc(sz)
Definition mem.h:34
int fc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fc_timeval *timeout)
Definition netintf.c:125
struct timeval fc_timeval
Definition netintf.h:90
int messages_where[E_COUNT]
Definition options.c:5028
struct client_options gui_options
Definition options.c:71
#define MW_MESSAGES
Definition options.h:555
@ REPORT_WONDERS_OF_THE_WORLD
Definition packets.h:74
@ REPORT_DEMOGRAPHIC
Definition packets.h:76
@ REPORT_TOP_5_CITIES
Definition packets.h:75
@ REPORT_ACHIEVEMENTS
Definition packets.h:77
bool str_to_uint(const char *str, unsigned int *pint)
Definition shared.c:545
void * data
Definition gui_main.c:2189
void(* callback)(void *data)
Definition gui_main.c:2188
Definition city.h:309
struct connection conn
Definition client_main.h:96
bool gui_sdl2_migrated_from_sdl
Definition options.h:132
struct video_mode gui_sdl2_screen
Definition options.h:377
char gui_sdl2_default_theme_name[512]
Definition options.h:375
bool gui_sdl2_fullscreen
Definition options.h:376
struct player * playing
Definition connection.h:156
Uint32 finger_down_ticks
Definition gui_main.h:82
struct tile * ptile
Definition gui_main.h:85
SDL_TouchFingerEvent event
Definition gui_main.h:84
enum mouse_button_hold_state hold_state
Definition gui_main.h:83
enum mouse_button_hold_state hold_state
Definition gui_main.h:91
SDL_MouseButtonEvent * event
Definition gui_main.h:92
struct tile * ptile
Definition gui_main.h:93
SDL_Event event
Definition graphics.h:217
SDL_Window * screen
Definition graphics.h:209
SDL_Surface * map
Definition graphics.h:210
Definition tile.h:49
Definition unit.h:138
int height
Definition options.h:47
int width
Definition options.h:46
SDL_Keycode key
Definition widget.h:153
union widget::@214 data
struct widget * widget
Definition widget.h:132
struct container * cont
Definition widget.h:127
SDL_Rect size
Definition widget.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void theme_free(struct theme *ftheme)
Definition themespec.c:316
int theme_default_font_size(const struct theme *t)
Definition themespec.c:177
struct theme * active_theme
Definition themespec.c:154
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:87
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3448
void tileset_use_preferred_theme(const struct tileset *t)
Definition tilespec.c:6764
void tileset_init(struct tileset *t)
Definition tilespec.c:6823
@ CURSOR_DEFAULT
Definition tilespec.h:297
#define unit_tile(_pu)
Definition unit.h:395
void update_queue_add(uq_callback_t callback, void *data)
struct widget * find_next_widget_for_key(struct widget *start_widget, SDL_Keysym key)
Definition widget.c:251
Uint16 widget_pressed_action(struct widget *pwidget)
Definition widget.c:295
void widget_selected_action(struct widget *pwidget)
Definition widget.c:442
struct widget * get_widget_pointer_from_main_list(Uint16 id)
Definition widget.c:577
struct widget * find_next_widget_at_pos(struct widget *start_widget, int x, int y)
Definition widget.c:222
void unselect_widget_action(void)
Definition widget.c:417
void del_main_list(void)
Definition widget.c:690
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
#define MAX_ID
Definition widget.h:38
@ FC_WS_DISABLED
Definition widget.h:99
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
#define draw_widget_info_label()
Definition widget.h:246
float mouse_zoom
Definition zoom.c:28