Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl2/gui_main.c Source File

Freeciv-3.3

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