Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-sdl2/gui_main.c Source File

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
89 const 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 */
94 const char * const gui_character_encoding = "UTF-8";
95 const bool gui_use_transliteration = FALSE;
96
97Uint32 sdl2_client_flags = 0;
98
99Uint32 widget_info_counter = 0;
100 int MOVE_STEP_X = DEFAULT_MOVE_STEP;
101 int MOVE_STEP_Y = DEFAULT_MOVE_STEP;
102extern bool draw_goto_patrol_lines;
103 bool is_unit_move_blocked;
104 bool LSHIFT;
105 bool RSHIFT;
106 bool LCTRL;
107 bool RCTRL;
108 bool LALT;
109 static int city_names_font_size = 10;
110 static int city_productions_font_size = 10;
111 int *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
117 static unsigned font_size_parameter = 0;
118
119/* ================================ Private ============================ */
120 static int net_socket = -1;
121 static bool autoconnect = FALSE;
122 static bool is_map_scrolling = FALSE;
123 static enum direction8 scroll_dir;
124
125 static struct finger_behavior finger_behavior;
126 static struct mouse_button_behavior button_behavior;
127
128 static SDL_Event __net_user_event;
129 static SDL_Event __anim_user_event;
130 static SDL_Event __info_user_event;
131 static SDL_Event __flush_user_event;
132 static SDL_Event __map_scroll_user_event;
133
134 static SDL_Event *net_user_event = NULL;
135 static SDL_Event *anim_user_event = NULL;
136 static SDL_Event *info_user_event = NULL;
137 static SDL_Event *flush_user_event = NULL;
138 static 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
144 int user_event_type;
145
146 enum USER_EVENT_ID {
147 EVENT_ERROR = 0,
148 NET,
149 ANIM,
150 TRY_AUTO_CONNECT,
151 SHOW_WIDGET_INFO_LABEL,
152 FLUSH,
153 MAP_SCROLL,
154 EXIT_FROM_EVENT_LOOP
155};
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
166 struct callback_list *callbacks = NULL;
167
168/* =========================================================== */
169
170/**********************************************************************/
174 static 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/**********************************************************************/
191 static 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])) {
202 gui_options.gui_sdl2_fullscreen = TRUE;
203 } else if (is_option("--swrenderer", argv[i])) {
204 sdl2_client_flags |= CF_SWRENDERER;
205 } else if ((option = get_option_malloc("--Font", argv, &i, argc, FALSE))) {
206 if (!str_to_uint(option, &font_size_parameter)) {
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))) {
212 sz_strlcpy(gui_options.gui_sdl2_default_theme_name, option);
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/**********************************************************************/
228 static 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 */
237 popup_input_line();
238 } else {
239 if (map_event_handler(key)
240 && C_S_RUNNING == client_state()) {
241 switch (key.sym) {
242 case SDLK_RETURN:
243 case SDLK_KP_ENTER:
244 if (LSHIFT || RSHIFT) {
245 disable_focus_animation();
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:
260 units_report_dialog_popup(FALSE);
261 return ID_ERROR;
262
263 case SDLK_F4:
264 city_report_dialog_popup(FALSE);
265 return ID_ERROR;
266
267 case SDLK_F7:
268 send_report_request(REPORT_WONDERS_OF_THE_WORLD);
269 return ID_ERROR;
270
271 case SDLK_F8:
272 send_report_request(REPORT_TOP_5_CITIES);
273 return ID_ERROR;
274
275 case SDLK_F9:
276 if (meswin_dialog_is_open()) {
277 meswin_dialog_popdown();
278 } else {
279 meswin_dialog_popup(TRUE);
280 }
281 flush_dirty();
282 return ID_ERROR;
283
284 case SDLK_F11:
285 send_report_request(REPORT_DEMOGRAPHIC);
286 return ID_ERROR;
287
288 case SDLK_F12:
289 popup_spaceship_dialog(client.conn.playing);
290 return ID_ERROR;
291
292 case SDLK_ASTERISK:
293 send_report_request(REPORT_ACHIEVEMENTS);
294 return ID_ERROR;
295
296 default:
297 return ID_ERROR;
298 }
299 }
300 }
301 }
302
303 return ID_ERROR;
304}
305
306/**********************************************************************/
309 static Uint16 main_key_up_handler(SDL_Keysym key, void *data)
310{
311 if (selected_widget) {
312 unselect_widget_action();
313 }
314
315 return ID_ERROR;
316}
317/**********************************************************************/
320 static 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. */
334 if (!finger_behavior.counting) {
335 /* Start counting. */
336 finger_behavior.counting = TRUE;
337 finger_behavior.finger_down_ticks = SDL_GetTicks();
338 finger_behavior.event = *touch_event;
339 finger_behavior.hold_state = MB_HOLD_SHORT;
340 finger_behavior.ptile = canvas_pos_to_tile(x, y, mouse_zoom);
341 }
342 }
343 return ID_ERROR;
344}
345/**********************************************************************/
348 static Uint16 main_finger_up_handler(SDL_TouchFingerEvent *touch_event,
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. */
355 if (finger_behavior.finger_down_ticks
356 && !find_next_widget_at_pos(NULL, x, y)) {
357 finger_behavior.event = *touch_event;
358 finger_up_on_map(&finger_behavior);
359 }
360
361 finger_behavior.counting = FALSE;
362 finger_behavior.finger_down_ticks = 0;
363
364 is_map_scrolling = FALSE;
365
366 return ID_ERROR;
367}
368
369/**********************************************************************/
372 static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event,
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
386 if (!check_scroll_area(button_event->x, button_event->y)) {
387#endif
388 if (!button_behavior.counting) {
389 /* start counting */
390 button_behavior.counting = TRUE;
391 button_behavior.button_down_ticks = SDL_GetTicks();
392 *button_behavior.event = *button_event;
393 button_behavior.hold_state = MB_HOLD_SHORT;
394 button_behavior.ptile = canvas_pos_to_tile(button_event->x, button_event->y,
395 mouse_zoom);
396 }
397#ifdef UNDER_CE
398 }
399#endif
400 }
401
402 return ID_ERROR;
403}
404
405/**********************************************************************/
408 static Uint16 main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event,
409 void *data)
410{
411 if (button_behavior.button_down_ticks /* button wasn't pressed over a widget */
412 && !find_next_widget_at_pos(NULL, button_event->x, button_event->y)) {
413 *button_behavior.event = *button_event;
414 button_up_on_map(&button_behavior);
415 }
416
417 button_behavior.counting = FALSE;
418 button_behavior.button_down_ticks = 0;
419
420 is_map_scrolling = FALSE;
421
422 return ID_ERROR;
423}
424
425#ifdef UNDER_CE
426 #define SCROLL_MAP_AREA 8
427#else
428 #define SCROLL_MAP_AREA 1
429#endif
430
431/**********************************************************************/
434 static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event,
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 */
442 if (button_behavior.counting && (button_behavior.hold_state >= MB_HOLD_MEDIUM)) {
443 ptile = canvas_pos_to_tile(motion_event->x, motion_event->y,
444 mouse_zoom);
445 if (tile_index(ptile) != tile_index(button_behavior.ptile)) {
446 button_behavior.counting = FALSE;
447 }
448 }
449
450 if (draw_goto_patrol_lines) {
451 update_line(motion_event->x, motion_event->y);
452 }
453
454#ifndef UNDER_CE
455 if (gui_options.gui_sdl2_fullscreen) {
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) {
463 update_mouse_cursor(CURSOR_DEFAULT);
464 if (get_wstate(pwidget) != FC_WS_DISABLED) {
465 widget_selected_action(pwidget);
466 }
467 } else {
468 if (selected_widget) {
469 unselect_widget_action();
470 } else {
471 control_mouse_cursor(canvas_pos_to_tile(motion_event->x, motion_event->y,
472 mouse_zoom));
473 }
474 }
475
476 draw_mouse_cursor();
477
478 return ID_ERROR;
479}
480
481/**********************************************************************/
485 static void update_button_hold_state(void)
486{
487 /* button pressed */
488 if (button_behavior.counting) {
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
492 if (button_behavior.hold_state != MB_HOLD_MEDIUM) {
493 button_behavior.hold_state = MB_HOLD_MEDIUM;
494 button_down_on_map(&button_behavior);
495 }
496
497 } else if (((SDL_GetTicks() - button_behavior.button_down_ticks)
498 >= MB_LONG_HOLD_DELAY)) {
499
500 if (button_behavior.hold_state != MB_HOLD_LONG) {
501 button_behavior.hold_state = MB_HOLD_LONG;
502 button_down_on_map(&button_behavior);
503 }
504 }
505 }
506
507 return;
508}
509
510/**********************************************************************/
513 static 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)) {
521 is_map_scrolling = TRUE;
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)) {
530 is_map_scrolling = TRUE;
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)) {
539 is_map_scrolling = TRUE;
540 scroll_dir = DIR8_EAST;
541 } else if (is_in_rect_area(x, y, rect_west)) {
542 is_map_scrolling = TRUE;
543 scroll_dir = DIR8_WEST;
544 } else {
545 is_map_scrolling = FALSE;
546 }
547
548 return is_map_scrolling;
549}
550
551/* ============================ Public ========================== */
552
553/**********************************************************************/
556 void force_exit_from_event_loop(void)
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/**********************************************************************/
572 int 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) {
658 widget_info_counter++;
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);
678 widget_info_counter = 0;
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:
694 input_from_server(net_socket);
695 break;
696 case ANIM:
697 update_button_hold_state();
698 animate_mouse_cursor();
699 draw_mouse_cursor();
700 break;
701 case SHOW_WIDGET_INFO_LABEL:
702 draw_widget_info_label();
703 break;
704 case TRY_AUTO_CONNECT:
705 if (try_to_autoconnect()) {
706 info_user_event->user.code = SHOW_WIDGET_INFO_LABEL;
707 autoconnect = FALSE;
708 }
709 break;
710 case FLUSH:
711 unqueue_flush();
712 break;
713 case MAP_SCROLL:
714 scroll_mapview(scroll_dir);
715 break;
716 case EXIT_FROM_EVENT_LOOP:
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
855 update_main_screen();
856 }
857
858 return ID;
859}
860
861/* ============ Freeciv native game function =========== */
862
863/**********************************************************************/
866 void ui_init(void)
867{
868 Uint32 sdl_flags;
869
870 button_behavior.counting = FALSE;
871 button_behavior.button_down_ticks = 0;
872 button_behavior.hold_state = MB_HOLD_SHORT;
873 button_behavior.event = fc_calloc(1, sizeof(SDL_MouseButtonEvent));
874
875 sdl2_client_flags = 0;
876 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
877
878 init_sdl(sdl_flags);
879}
880
881/**********************************************************************/
884 static void real_resize_window_callback(void *data)
885{
886 struct widget *widget;
887
888 if (C_S_RUNNING == client_state()) {
889 /* Move units window to botton-right corner. */
890 set_new_unitinfo_window_pos();
891 /* Move minimap window to botton-left corner. */
892 set_new_minimap_window_pos();
893
894 /* Move cooling/warming icons to botton-right corner. */
895 widget = get_widget_pointer_from_main_list(ID_WARMING_ICON);
896 widget_set_position(widget, (main_window_width() - adj_size(10)
897 - (widget->size.w * 2)), widget->size.y);
898
899 widget = get_widget_pointer_from_main_list(ID_COOLING_ICON);
900 widget_set_position(widget, (main_window_width() - adj_size(10)
901 - widget->size.w), widget->size.y);
902
903 map_canvas_resized(main_window_width(), main_window_height());
904 update_info_label();
905 update_unit_info_label(get_units_in_focus());
906 center_on_something(); /* With redrawing full map. */
907 update_order_widgets();
908 } else {
909 draw_intro_gfx();
910 dirty_all();
911 }
912
913 flush_all();
914}
915
916/**********************************************************************/
919 static void resize_window_callback(struct option *poption)
920{
921 update_queue_add(real_resize_window_callback, NULL);
922}
923
924/**********************************************************************/
927 static void fullscreen_callback(struct option *poption)
928{
929 SDL_DisplayMode mode;
930
931 if (gui_options.gui_sdl2_fullscreen) {
932 SDL_SetWindowFullscreen(main_data.screen, SDL_WINDOW_FULLSCREEN_DESKTOP);
933 } else {
934 SDL_SetWindowFullscreen(main_data.screen, 0);
935 }
936
937 SDL_GetWindowDisplayMode(main_data.screen, &mode);
938
939 if (!create_surfaces(mode.w, mode.h)) {
940 /* Try to revert */
941 if (!gui_options.gui_sdl2_fullscreen) {
942 SDL_SetWindowFullscreen(main_data.screen, SDL_WINDOW_FULLSCREEN_DESKTOP);
943 } else {
944 SDL_SetWindowFullscreen(main_data.screen, 0);
945 }
946 }
947
948 update_queue_add(real_resize_window_callback, NULL);
949}
950
951/**********************************************************************/
955 void options_extra_init(void)
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);
967 option_var_set_callback(gui_sdl2_screen, resize_window_callback);
968#undef option_var_set_callback
969}
970
971/**********************************************************************/
975 static void clear_double_messages_call(void)
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/**********************************************************************/
992 int main(int argc, char **argv)
993{
994 return client_main(argc, argv, FALSE);
995}
996
997/**********************************************************************/
1000 static void migrate_options_from_sdl(void)
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
1014 gui_options.gui_sdl2_migrated_from_sdl = TRUE;
1015}
1016
1017/**********************************************************************/
1021 int ui_main(int argc, char *argv[])
1022{
1023 Uint32 flags = 0;
1024
1025 if (parse_options(argc, argv)) {
1026 if (!gui_options.gui_sdl2_migrated_from_sdl) {
1027 migrate_options_from_sdl();
1028 }
1029
1030 if (gui_options.gui_sdl2_fullscreen) {
1031 flags |= SDL_WINDOW_FULLSCREEN;
1032 } else {
1033 flags &= ~SDL_WINDOW_FULLSCREEN;
1034 }
1035 log_normal(_("Using Video Output: %s"), SDL_GetCurrentVideoDriver());
1036 if (!set_video_mode(gui_options.gui_sdl2_screen.width,
1037 gui_options.gui_sdl2_screen.height,
1038 flags)) {
1039 return EXIT_FAILURE;
1040 }
1041
1042 user_event_type = SDL_RegisterEvents(1);
1043
1044 SDL_zero(__net_user_event);
1045 __net_user_event.type = user_event_type;
1046 __net_user_event.user.code = NET;
1047 __net_user_event.user.data1 = NULL;
1048 __net_user_event.user.data2 = NULL;
1049 net_user_event = &__net_user_event;
1050
1051 SDL_zero(__anim_user_event);
1052 __anim_user_event.type = user_event_type;
1053 __anim_user_event.user.code = EVENT_ERROR;
1054 __anim_user_event.user.data1 = NULL;
1055 __anim_user_event.user.data2 = NULL;
1056 anim_user_event = &__anim_user_event;
1057
1058 SDL_zero(__info_user_event);
1059 __info_user_event.type = user_event_type;
1060 __info_user_event.user.code = SHOW_WIDGET_INFO_LABEL;
1061 __info_user_event.user.data1 = NULL;
1062 __info_user_event.user.data2 = NULL;
1063 info_user_event = &__info_user_event;
1064
1065 SDL_zero(__flush_user_event);
1066 __flush_user_event.type = user_event_type;
1067 __flush_user_event.user.code = FLUSH;
1068 __flush_user_event.user.data1 = NULL;
1069 __flush_user_event.user.data2 = NULL;
1070 flush_user_event = &__flush_user_event;
1071
1072 SDL_zero(__map_scroll_user_event);
1073 __map_scroll_user_event.type = user_event_type;
1074 __map_scroll_user_event.user.code = MAP_SCROLL;
1075 __map_scroll_user_event.user.data1 = NULL;
1076 __map_scroll_user_event.user.data2 = NULL;
1077 map_scroll_user_event = &__map_scroll_user_event;
1078
1079 is_unit_move_blocked = FALSE;
1080
1081 sdl2_client_flags |= (CF_DRAW_PLAYERS_NEUTRAL_STATUS
1082 |CF_DRAW_PLAYERS_WAR_STATUS
1083 |CF_DRAW_PLAYERS_CEASEFIRE_STATUS
1084 |CF_DRAW_PLAYERS_PEACE_STATUS
1085 |CF_DRAW_PLAYERS_ALLIANCE_STATUS);
1086
1087 tileset_init(tileset);
1088 tileset_load_tiles(tileset);
1089 tileset_use_preferred_theme(tileset);
1090
1091 load_cursors();
1092
1093 callbacks = callback_list_new();
1094
1095 diplomacy_dialog_init();
1096 intel_dialog_init();
1097
1098 clear_double_messages_call();
1099
1100 setup_auxiliary_tech_icons();
1101
1102 /* This need correct main_data.screen size */
1103 init_mapcanvas_and_overview();
1104
1105 set_client_state(C_S_DISCONNECTED);
1106
1107 /* Main game loop */
1108 gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler, NULL,
1109 main_finger_down_handler, main_finger_up_handler, NULL,
1110 main_mouse_button_down_handler, main_mouse_button_up_handler,
1111 main_mouse_motion_handler);
1112 start_quitting();
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
1119 city_map_canvas_free();
1120
1121 free_mapcanvas_and_overview();
1122
1123 free_auxiliary_tech_icons();
1124
1125 diplomacy_dialog_done();
1126 intel_dialog_done();
1127
1128 callback_list_destroy(callbacks);
1129 callbacks = NULL;
1130
1131 unload_cursors();
1132
1133 free(button_behavior.event);
1134 button_behavior.event = NULL;
1135
1136 meswin_dialog_popdown();
1137
1138 del_main_list();
1139
1140 free_font_system();
1141 theme_free(active_theme);
1142 active_theme = NULL;
1143
1144 quit_sdl();
1145 }
1146
1147 return EXIT_SUCCESS;
1148}
1149
1150/**********************************************************************/
1153 void ui_exit(void)
1154{
1155}
1156
1157/**********************************************************************/
1160 enum gui_type get_gui_type(void)
1161{
1162 return GUI_SDL2;
1163}
1164
1165/**********************************************************************/
1169 void sound_bell(void)
1170{
1171 log_debug("sound_bell : PORT ME");
1172}
1173
1174/**********************************************************************/
1177 void enable_focus_animation(void)
1178{
1179 anim_user_event->user.code = ANIM;
1180 sdl2_client_flags |= CF_FOCUS_ANIMATION;
1181}
1182
1183/**********************************************************************/
1186 void disable_focus_animation(void)
1187{
1188 sdl2_client_flags &= ~CF_FOCUS_ANIMATION;
1189}
1190
1191/**********************************************************************/
1195 void add_net_input(int sock)
1196{
1197 log_debug("Connection UP (%d)", sock);
1198 net_socket = sock;
1199 autoconnect = FALSE;
1200 enable_focus_animation();
1201}
1202
1203/**********************************************************************/
1206 void remove_net_input(void)
1207{
1208 log_debug("Connection DOWN... ");
1209 net_socket = (-1);
1210 disable_focus_animation();
1211 draw_goto_patrol_lines = FALSE;
1212 update_mouse_cursor(CURSOR_DEFAULT);
1213}
1214
1215/**********************************************************************/
1220 void 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/**********************************************************************/
1235 void editgui_tileset_changed(void)
1236{}
1237
1238/**********************************************************************/
1241 void editgui_refresh(void)
1242{}
1243
1244/**********************************************************************/
1247 void editgui_popup_properties(const struct tile_list *tiles, int objtype)
1248{}
1249
1250/**********************************************************************/
1253 void editgui_popdown_all(void)
1254{}
1255
1256/**********************************************************************/
1259 void editgui_notify_object_changed(int objtype, int object_id, bool removal)
1260{}
1261
1262/**********************************************************************/
1265 void editgui_notify_object_created(int tag, int id)
1266{}
1267
1268/**********************************************************************/
1271 void 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
1285 CHECK_FONT(FONT_CITY_NAME, update_city_descriptions());
1286 CHECK_FONT(FONT_CITY_PROD, update_city_descriptions());
1287 /* FONT_REQTREE_TEXT not used yet */
1288
1289#undef CHECK_FONT
1290}
1291
1292/**********************************************************************/
1295 unsigned default_font_size(struct theme *act_theme)
1296{
1297 return font_size_parameter > 0 ? font_size_parameter :
1298 theme_default_font_size(act_theme);
1299}
1300
1301/**********************************************************************/
1304 void 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/**********************************************************************/
1313 void insert_client_build_info(char *outbuf, size_t outlen)
1314{
1315 /* PORTME */
1316}
1317
1318/**********************************************************************/
1321 bool flush_event(void)
1322{
1323 return SDL_PushEvent(flush_user_event) >= 0;
1324}
FONT_CITY_NAME
FONT_CITY_NAME
Definition canvas_g.h:70
FONT_CITY_PROD
FONT_CITY_PROD
Definition canvas_g.h:71
city_owner
#define city_owner(_pcity_)
Definition city.h:543
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:1183
client_main
int client_main(int argc, char *argv[], bool postpone_tileset)
Definition client_main.c:344
client
struct civclient client
Definition client_main.c:149
client_state
enum client_states client_state(void)
Definition client_main.c:1029
send_report_request
void send_report_request(enum report_type type)
Definition client_main.c:839
start_quitting
void start_quitting(void)
Definition client_main.c:1645
set_client_state
void set_client_state(enum client_states newstate)
Definition client_main.c:847
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:424
climisc.h
try_to_autoconnect
double try_to_autoconnect(void)
Definition clinet.c:492
input_from_server
void input_from_server(int fd)
Definition clinet.c:406
clinet.h
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:3126
head_of_units_in_focus
struct unit * head_of_units_in_focus(void)
Definition control.c:406
control_mouse_cursor
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1188
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:73
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:1173
diplomacy_dialog_done
void diplomacy_dialog_done(void)
Definition diplodlg.c:1182
load_cursors
void load_cursors(void)
Definition graphics.c:78
ui_main
int ui_main(int argc, char **argv)
Definition gui_main.c:1702
client_string
const char * client_string
Definition gui_main.c:104
print_usage
static void print_usage(void)
Definition gui_main.c:249
option_var_set_callback
#define option_var_set_callback(var, callback)
ui_exit
void ui_exit(void)
Definition gui_main.c:1872
get_gui_type
enum gui_type get_gui_type(void)
Definition gui_main.c:1883
main
int main(int argc, char **argv)
Definition gui_main.c:1627
ui_init
void ui_init(void)
Definition gui_main.c:1618
add_idle_callback
void add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.c:2210
options_extra_init
void options_extra_init(void)
Definition gui_main.c:2284
insert_client_build_info
void insert_client_build_info(char *outbuf, size_t outlen)
Definition gui_main.c:2343
remove_net_input
void remove_net_input(void)
Definition gui_main.c:2116
sound_bell
void sound_bell(void)
Definition gui_main.c:1891
gui_character_encoding
const char *const gui_character_encoding
Definition gui_main.c:160
add_net_input
void add_net_input(int sock)
Definition gui_main.c:2098
parse_options
static bool parse_options(int argc, char **argv)
Definition gui_main.c:286
MIGRATE_OPTION
#define MIGRATE_OPTION(opt)
gui_use_transliteration
const bool gui_use_transliteration
Definition gui_main.c:161
intel_dialog_done
void intel_dialog_done(void)
Definition inteldlg.c:127
intel_dialog_init
void intel_dialog_init(void)
Definition inteldlg.c:118
flush_dirty
void flush_dirty(void)
Definition mapview.c:450
update_info_label
void update_info_label(void)
Definition mapview.c:121
dirty_all
void dirty_all(void)
Definition mapview.c:438
update_unit_info_label
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:258
update_city_descriptions
void update_city_descriptions(void)
Definition mapview.c:470
update_mouse_cursor
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:240
meswin_dialog_popdown
void meswin_dialog_popdown(void)
Definition messagewin.c:431
meswin_dialog_popup
void meswin_dialog_popup(bool raise)
Definition messagewin.c:416
meswin_dialog_is_open
bool meswin_dialog_is_open(void)
Definition messagewin.c:442
units_report_dialog_popup
void units_report_dialog_popup(bool raise)
Definition repodlgs.c:1765
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:358
set_video_mode
bool set_video_mode(unsigned width, unsigned height, unsigned flags_in)
Definition graphics.c:636
is_in_rect_area
bool is_in_rect_area(int x, int y, SDL_Rect rect)
Definition graphics.c:925
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
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
city_names_font_size
static int city_names_font_size
Definition gui_main.c:109
main_key_down_handler
static Uint16 main_key_down_handler(SDL_Keysym key, void *data)
Definition gui_main.c:228
__anim_user_event
static SDL_Event __anim_user_event
Definition gui_main.c:129
migrate_options_from_sdl
static void migrate_options_from_sdl(void)
Definition gui_main.c:1000
net_user_event
static SDL_Event * net_user_event
Definition gui_main.c:134
check_scroll_area
static int check_scroll_area(int x, int y)
Definition gui_main.c:513
resize_window_callback
static void resize_window_callback(struct option *poption)
Definition gui_main.c:919
fullscreen_callback
static void fullscreen_callback(struct option *poption)
Definition gui_main.c:927
editgui_popup_properties
void editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition gui_main.c:1247
editgui_notify_object_created
void editgui_notify_object_created(int tag, int id)
Definition gui_main.c:1265
CHECK_FONT
#define CHECK_FONT(client_font, action)
button_behavior
static struct mouse_button_behavior button_behavior
Definition gui_main.c:126
is_unit_move_blocked
bool is_unit_move_blocked
Definition gui_main.c:103
__info_user_event
static SDL_Event __info_user_event
Definition gui_main.c:130
LSHIFT
bool LSHIFT
Definition gui_main.c:104
__flush_user_event
static SDL_Event __flush_user_event
Definition gui_main.c:131
FilterMouseMotionEvents
int FilterMouseMotionEvents(void *data, SDL_Event *event)
Definition gui_main.c:572
info_user_event
static SDL_Event * info_user_event
Definition gui_main.c:136
main_mouse_button_down_handler
static Uint16 main_mouse_button_down_handler(SDL_MouseButtonEvent *button_event, void *data)
Definition gui_main.c:372
__net_user_event
static SDL_Event __net_user_event
Definition gui_main.c:128
enable_focus_animation
void enable_focus_animation(void)
Definition gui_main.c:1177
editgui_popdown_all
void editgui_popdown_all(void)
Definition gui_main.c:1253
flush_event
bool flush_event(void)
Definition gui_main.c:1321
MAP_SCROLL_TIMER_INTERVAL
#define MAP_SCROLL_TIMER_INTERVAL
Definition gui_main.c:87
real_resize_window_callback
static void real_resize_window_callback(void *data)
Definition gui_main.c:884
draw_goto_patrol_lines
bool draw_goto_patrol_lines
Definition mapctrl.c:104
UNITS_TIMER_INTERVAL
#define UNITS_TIMER_INTERVAL
Definition gui_main.c:86
update_button_hold_state
static void update_button_hold_state(void)
Definition gui_main.c:485
is_map_scrolling
static bool is_map_scrolling
Definition gui_main.c:122
map_scroll_user_event
static SDL_Event * map_scroll_user_event
Definition gui_main.c:138
RSHIFT
bool RSHIFT
Definition gui_main.c:105
MOVE_STEP_Y
int MOVE_STEP_Y
Definition gui_main.c:101
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:593
main_finger_down_handler
static Uint16 main_finger_down_handler(SDL_TouchFingerEvent *touch_event, void *data)
Definition gui_main.c:320
SCROLL_MAP_AREA
#define SCROLL_MAP_AREA
Definition gui_main.c:428
widget_info_counter
Uint32 widget_info_counter
Definition gui_main.c:99
main_mouse_motion_handler
static Uint16 main_mouse_motion_handler(SDL_MouseMotionEvent *motion_event, void *data)
Definition gui_main.c:434
anim_user_event
static SDL_Event * anim_user_event
Definition gui_main.c:135
autoconnect
static bool autoconnect
Definition gui_main.c:121
net_socket
static int net_socket
Definition gui_main.c:120
main_finger_up_handler
static Uint16 main_finger_up_handler(SDL_TouchFingerEvent *touch_event, void *data)
Definition gui_main.c:348
update_font_from_theme
void update_font_from_theme(int theme_font_size)
Definition gui_main.c:1304
city_productions_font_size
static int city_productions_font_size
Definition gui_main.c:110
LALT
bool LALT
Definition gui_main.c:108
LCTRL
bool LCTRL
Definition gui_main.c:106
default_font_size
unsigned default_font_size(struct theme *act_theme)
Definition gui_main.c:1295
clear_double_messages_call
static void clear_double_messages_call(void)
Definition gui_main.c:975
force_exit_from_event_loop
void force_exit_from_event_loop(void)
Definition gui_main.c:556
disable_focus_animation
void disable_focus_animation(void)
Definition gui_main.c:1186
scroll_dir
static enum direction8 scroll_dir
Definition gui_main.c:123
font_size_parameter
static unsigned font_size_parameter
Definition gui_main.c:117
client_font_sizes
int * client_font_sizes[FONT_COUNT]
Definition gui_main.c:111
editgui_refresh
void editgui_refresh(void)
Definition gui_main.c:1241
user_event_type
int user_event_type
Definition gui_main.c:144
__map_scroll_user_event
static SDL_Event __map_scroll_user_event
Definition gui_main.c:132
sdl2_client_flags
Uint32 sdl2_client_flags
Definition gui_main.c:97
flush_user_event
static SDL_Event * flush_user_event
Definition gui_main.c:137
callbacks
struct callback_list * callbacks
Definition gui_main.c:166
USER_EVENT_ID
USER_EVENT_ID
Definition gui_main.c:146
NET
@ NET
Definition gui_main.c:148
ANIM
@ ANIM
Definition gui_main.c:149
TRY_AUTO_CONNECT
@ TRY_AUTO_CONNECT
Definition gui_main.c:150
MAP_SCROLL
@ MAP_SCROLL
Definition gui_main.c:153
FLUSH
@ FLUSH
Definition gui_main.c:152
EVENT_ERROR
@ EVENT_ERROR
Definition gui_main.c:147
EXIT_FROM_EVENT_LOOP
@ EXIT_FROM_EVENT_LOOP
Definition gui_main.c:154
SHOW_WIDGET_INFO_LABEL
@ SHOW_WIDGET_INFO_LABEL
Definition gui_main.c:151
main_key_up_handler
static Uint16 main_key_up_handler(SDL_Keysym key, void *data)
Definition gui_main.c:309
editgui_tileset_changed
void editgui_tileset_changed(void)
Definition gui_main.c:1235
main_mouse_button_up_handler
static Uint16 main_mouse_button_up_handler(SDL_MouseButtonEvent *button_event, void *data)
Definition gui_main.c:408
MOVE_STEP_X
int MOVE_STEP_X
Definition gui_main.c:100
RCTRL
bool RCTRL
Definition gui_main.c:107
CF_FOCUS_ANIMATION
#define CF_FOCUS_ANIMATION
Definition gui_main.h:48
CF_DRAW_PLAYERS_ALLIANCE_STATUS
#define CF_DRAW_PLAYERS_ALLIANCE_STATUS
Definition gui_main.h:59
CF_DRAW_PLAYERS_CEASEFIRE_STATUS
#define CF_DRAW_PLAYERS_CEASEFIRE_STATUS
Definition gui_main.h:57
CF_SWRENDERER
#define CF_SWRENDERER
Definition gui_main.h:61
CF_DRAW_PLAYERS_PEACE_STATUS
#define CF_DRAW_PLAYERS_PEACE_STATUS
Definition gui_main.h:58
MB_HOLD_LONG
@ MB_HOLD_LONG
Definition gui_main.h:77
MB_HOLD_MEDIUM
@ MB_HOLD_MEDIUM
Definition gui_main.h:76
MB_HOLD_SHORT
@ MB_HOLD_SHORT
Definition gui_main.h:75
MB_MEDIUM_HOLD_DELAY
#define MB_MEDIUM_HOLD_DELAY
Definition gui_main.h:64
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:60
adj_size
#define adj_size(size)
Definition gui_main.h:138
DEFAULT_MOVE_STEP
#define DEFAULT_MOVE_STEP
Definition gui_main.h:110
MB_LONG_HOLD_DELAY
#define MB_LONG_HOLD_DELAY
Definition gui_main.h:65
CF_DRAW_PLAYERS_WAR_STATUS
#define CF_DRAW_PLAYERS_WAR_STATUS
Definition gui_main.h:56
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:970
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
spaceshipdlg.h
gui_id.h
ID_COOLING_ICON
@ ID_COOLING_ICON
Definition gui_id.h:139
ID_ERROR
@ ID_ERROR
Definition gui_id.h:26
ID_WARMING_ICON
@ ID_WARMING_ICON
Definition gui_id.h:140
font_name
const char * font_name
Definition gui_main_g.h:43
gui_update_font
gui_update_font
Definition gui_main_g.h:43
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
gui_mouse.h
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:380
draw_intro_gfx
void draw_intro_gfx(void)
Definition gui_tilespec.c:485
free_auxiliary_tech_icons
void free_auxiliary_tech_icons(void)
Definition gui_tilespec.c:420
gui_tilespec.h
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:662
scroll_mapview
void scroll_mapview(enum direction8 gui_dir)
Definition mapctrl_common.c:549
init_mapcanvas_and_overview
void init_mapcanvas_and_overview(void)
Definition mapview_common.c:3684
canvas_pos_to_tile
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
Definition mapview_common.c:751
free_mapcanvas_and_overview
void free_mapcanvas_and_overview(void)
Definition mapview_common.c:3693
map_canvas_resized
bool map_canvas_resized(int width, int height)
Definition mapview_common.c:3593
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:5028
gui_options
struct client_options gui_options
Definition options.c:71
MW_MESSAGES
#define MW_MESSAGES
Definition options.h:555
REPORT_WONDERS_OF_THE_WORLD
@ REPORT_WONDERS_OF_THE_WORLD
Definition packets.h:74
REPORT_DEMOGRAPHIC
@ REPORT_DEMOGRAPHIC
Definition packets.h:76
REPORT_TOP_5_CITIES
@ REPORT_TOP_5_CITIES
Definition packets.h:75
REPORT_ACHIEVEMENTS
@ REPORT_ACHIEVEMENTS
Definition packets.h:77
str_to_uint
bool str_to_uint(const char *str, unsigned int *pint)
Definition shared.c:545
speclist.h
callback
Definition gui_main.c:2187
callback::data
void * data
Definition gui_main.c:2189
callback::callback
void(* callback)(void *data)
Definition gui_main.c:2188
city
Definition city.h:309
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:132
client_options::gui_sdl2_screen
struct video_mode gui_sdl2_screen
Definition options.h:377
client_options::gui_sdl2_default_theme_name
char gui_sdl2_default_theme_name[512]
Definition options.h:375
client_options::gui_sdl2_fullscreen
bool gui_sdl2_fullscreen
Definition options.h:376
connection::playing
struct player * playing
Definition connection.h:156
finger_behavior
Definition gui_main.h:80
finger_behavior::finger_down_ticks
Uint32 finger_down_ticks
Definition gui_main.h:82
finger_behavior::counting
bool counting
Definition gui_main.h:81
finger_behavior::ptile
struct tile * ptile
Definition gui_main.h:85
finger_behavior::event
SDL_TouchFingerEvent event
Definition gui_main.h:84
finger_behavior::hold_state
enum mouse_button_hold_state hold_state
Definition gui_main.h:83
mouse_button_behavior
Definition gui_main.h:88
mouse_button_behavior::hold_state
enum mouse_button_hold_state hold_state
Definition gui_main.h:91
mouse_button_behavior::counting
bool counting
Definition gui_main.h:89
mouse_button_behavior::button_down_ticks
Uint32 button_down_ticks
Definition gui_main.h:90
mouse_button_behavior::event
SDL_MouseButtonEvent * event
Definition gui_main.h:92
mouse_button_behavior::ptile
struct tile * ptile
Definition gui_main.h:93
option
Definition options.c:454
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:49
tileset
Definition tilespec.c:459
unit
Definition unit.h:138
video_mode::height
int height
Definition options.h:47
video_mode::width
int width
Definition options.h:46
widget
Definition widget.h:112
widget::key
SDL_Keycode key
Definition widget.h:153
widget::data
union widget::@214 data
widget::widget
struct widget * widget
Definition widget.h:132
widget::cont
struct container * cont
Definition widget.h:127
widget::size
SDL_Rect size
Definition widget.h:145
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
theme_free
void theme_free(struct theme *ftheme)
Definition themespec.c:316
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
themespec.h
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tileset_load_tiles
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3452
tileset_use_preferred_theme
void tileset_use_preferred_theme(const struct tileset *t)
Definition tilespec.c:6768
tileset_init
void tileset_init(struct tileset *t)
Definition tilespec.c:6827
tilespec.h
CURSOR_DEFAULT
@ CURSOR_DEFAULT
Definition tilespec.h:297
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unitlist.h
update_queue_add
void update_queue_add(uq_callback_t callback, void *data)
Definition update_queue.c:345
update_queue.h
find_next_widget_for_key
struct widget * find_next_widget_for_key(struct widget *start_widget, SDL_Keysym key)
Definition widget.c:251
widget_pressed_action
Uint16 widget_pressed_action(struct widget *pwidget)
Definition widget.c:295
widget_selected_action
void widget_selected_action(struct widget *pwidget)
Definition widget.c:442
get_widget_pointer_from_main_list
struct widget * get_widget_pointer_from_main_list(Uint16 id)
Definition widget.c:577
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:417
del_main_list
void del_main_list(void)
Definition widget.c:690
widget.h
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
mouse_zoom
float mouse_zoom
Definition zoom.c:28
zoom.h