Freeciv-3.1
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
gui_main.c File Reference
#include "fc_prehdrs.h"
#include <errno.h>
#include <SDL2/SDL.h>
#include "fc_cmdline.h"
#include "fciconv.h"
#include "fcintl.h"
#include "log.h"
#include "netintf.h"
#include "unitlist.h"
#include "client_main.h"
#include "climisc.h"
#include "clinet.h"
#include "editgui_g.h"
#include "tilespec.h"
#include "update_queue.h"
#include "zoom.h"
#include "chatline.h"
#include "citydlg.h"
#include "cityrep.h"
#include "diplodlg.h"
#include "graphics.h"
#include "gui_id.h"
#include "gui_mouse.h"
#include "gui_tilespec.h"
#include "inteldlg.h"
#include "mapctrl.h"
#include "mapview.h"
#include "menu.h"
#include "messagewin.h"
#include "optiondlg.h"
#include "repodlgs.h"
#include "themespec.h"
#include "spaceshipdlg.h"
#include "widget.h"
#include "gui_main.h"
#include "speclist.h"

Go to the source code of this file.

Data Structures

struct  callback
 

Macros

#define UNITS_TIMER_INTERVAL   128 /* milliseconds */
 
#define MAP_SCROLL_TIMER_INTERVAL   500
 
#define SPECLIST_TAG   callback
 
#define SPECLIST_TYPE   struct callback
 
#define SCROLL_MAP_AREA   1
 
#define option_var_set_callback(var, callback)
 
#define MIGRATE_OPTION(opt)   gui_options.gui_sdl2_##opt = gui_options.gui_sdl_##opt;
 
#define CHECK_FONT(client_font, action)
 

Enumerations

enum  USER_EVENT_ID {
  EVENT_ERROR = 0 , NET , ANIM , TRY_AUTO_CONNECT ,
  SHOW_WIDGET_INFO_LABEL , FLUSH , MAP_SCROLL , EXIT_FROM_EVENT_LOOP
}
 

Functions

static void print_usage (void)
 
static bool parse_options (int argc, char **argv)
 
static int check_scroll_area (int x, int y)
 
static Uint16 main_key_down_handler (SDL_Keysym key, void *data)
 
static Uint16 main_key_up_handler (SDL_Keysym key, void *data)
 
static Uint16 main_finger_down_handler (SDL_TouchFingerEvent *touch_event, void *data)
 
static Uint16 main_finger_up_handler (SDL_TouchFingerEvent *touch_event, void *data)
 
static Uint16 main_mouse_button_down_handler (SDL_MouseButtonEvent *button_event, void *data)
 
static Uint16 main_mouse_button_up_handler (SDL_MouseButtonEvent *button_event, void *data)
 
static Uint16 main_mouse_motion_handler (SDL_MouseMotionEvent *motion_event, void *data)
 
static void update_button_hold_state (void)
 
void force_exit_from_event_loop (void)
 
int FilterMouseMotionEvents (void *data, SDL_Event *event)
 
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))
 
void ui_init (void)
 
static void real_resize_window_callback (void *data)
 
static void resize_window_callback (struct option *poption)
 
static void fullscreen_callback (struct option *poption)
 
void options_extra_init (void)
 
static void clear_double_messages_call (void)
 
int main (int argc, char **argv)
 
static void migrate_options_from_sdl (void)
 
int ui_main (int argc, char *argv[])
 
void ui_exit (void)
 
enum gui_type get_gui_type (void)
 
void sound_bell (void)
 
void enable_focus_animation (void)
 
void disable_focus_animation (void)
 
void add_net_input (int sock)
 
void remove_net_input (void)
 
void add_idle_callback (void(callback)(void *), void *data)
 
void editgui_tileset_changed (void)
 
void editgui_refresh (void)
 
void editgui_popup_properties (const struct tile_list *tiles, int objtype)
 
void editgui_popdown_all (void)
 
void editgui_notify_object_changed (int objtype, int object_id, bool removal)
 
void editgui_notify_object_created (int tag, int id)
 
void gui_update_font (const char *font_name, const char *font_value)
 
unsigned default_font_size (struct theme *act_theme)
 
void update_font_from_theme (int theme_font_size)
 
void insert_client_build_info (char *outbuf, size_t outlen)
 
bool flush_event (void)
 

Variables

const char * client_string = "gui-sdl2"
 
const char *const gui_character_encoding = "UTF-8"
 
const bool gui_use_transliteration = FALSE
 
Uint32 sdl2_client_flags = 0
 
Uint32 widget_info_counter = 0
 
int MOVE_STEP_X = DEFAULT_MOVE_STEP
 
int MOVE_STEP_Y = DEFAULT_MOVE_STEP
 
bool draw_goto_patrol_lines
 
bool is_unit_move_blocked
 
bool LSHIFT
 
bool RSHIFT
 
bool LCTRL
 
bool RCTRL
 
bool LALT
 
static int city_names_font_size = 10
 
static int city_productions_font_size = 10
 
int * client_font_sizes [FONT_COUNT]
 
static unsigned font_size_parameter = 0
 
static int net_socket = -1
 
static bool autoconnect = FALSE
 
static bool is_map_scrolling = FALSE
 
static enum direction8 scroll_dir
 
static struct finger_behavior finger_behavior
 
static struct mouse_button_behavior button_behavior
 
static SDL_Event __net_user_event
 
static SDL_Event __anim_user_event
 
static SDL_Event __info_user_event
 
static SDL_Event __flush_user_event
 
static SDL_Event __map_scroll_user_event
 
static SDL_Event * net_user_event = NULL
 
static SDL_Event * anim_user_event = NULL
 
static SDL_Event * info_user_event = NULL
 
static SDL_Event * flush_user_event = NULL
 
static SDL_Event * map_scroll_user_event = NULL
 
int user_event_type
 
struct callback_list * callbacks = NULL
 

Macro Definition Documentation

◆ CHECK_FONT

#define CHECK_FONT (   client_font,
  action 
)
Value:
do { \
if (strcmp(#client_font, font_name) == 0) { \
char *end; \
long size = strtol(font_value, &end, 10); \
if (end && *end == '\0' && size > 0) { \
action; \
} \
} \
} while (FALSE)
struct canvas int int struct sprite bool int int fog_y struct canvas struct sprite struct color int int canvas_y struct canvas struct color enum line_type ltype int start_x int start_y int dx int dy enum client_font
Definition canvas_g.h:69
int * client_font_sizes[FONT_COUNT]
Definition gui_main.c:111
const char * font_name
Definition gui_main_g.h:43
size_t size
Definition specvec.h:72
#define FALSE
Definition support.h:47

◆ MAP_SCROLL_TIMER_INTERVAL

#define MAP_SCROLL_TIMER_INTERVAL   500

Definition at line 87 of file gui_main.c.

◆ MIGRATE_OPTION

#define MIGRATE_OPTION (   opt)    gui_options.gui_sdl2_##opt = gui_options.gui_sdl_##opt;

◆ option_var_set_callback

#define option_var_set_callback (   var,
  callback 
)
Value:
if ((poption = optset_option_by_name(client_optset, #var))) { \
option_set_changed_callback(poption, callback); \
} else { \
log_error("Didn't find option %s!", #var); \
}
const struct option_set * client_optset
Definition options.c:1255
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:406

◆ SCROLL_MAP_AREA

#define SCROLL_MAP_AREA   1

Definition at line 428 of file gui_main.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   callback

Definition at line 162 of file gui_main.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct callback

Definition at line 163 of file gui_main.c.

◆ UNITS_TIMER_INTERVAL

#define UNITS_TIMER_INTERVAL   128 /* milliseconds */

Definition at line 86 of file gui_main.c.

Enumeration Type Documentation

◆ USER_EVENT_ID

Enumerator
EVENT_ERROR 
NET 
ANIM 
TRY_AUTO_CONNECT 
SHOW_WIDGET_INFO_LABEL 
FLUSH 
MAP_SCROLL 
EXIT_FROM_EVENT_LOOP 

Definition at line 146 of file gui_main.c.

Function Documentation

◆ add_idle_callback()

void add_idle_callback ( void(callback)(void *)  ,
void *  data 
)

Enqueue a callback to be called during an idle moment. The 'callback' function should be called sometimes soon, and passed the 'data' pointer as its data.

Definition at line 1220 of file gui_main.c.

◆ add_net_input()

void add_net_input ( int  sock)

Wait for data on the given socket. Call input_from_server() when data is ready to be read.

Definition at line 1195 of file gui_main.c.

◆ check_scroll_area()

static int check_scroll_area ( int  x,
int  y 
)
static

Check if coordinate is in scroll area.

Definition at line 513 of file gui_main.c.

Referenced by main_mouse_button_down_handler(), and main_mouse_motion_handler().

◆ clear_double_messages_call()

static void clear_double_messages_call ( void  )
static

Remove double messages caused by message configured to both MW_MESSAGES and MW_OUTPUT.

Definition at line 975 of file gui_main.c.

Referenced by ui_main().

◆ default_font_size()

unsigned default_font_size ( struct theme act_theme)

Return default font size, from any source.

Definition at line 1295 of file gui_main.c.

Referenced by gui_load_theme().

◆ disable_focus_animation()

void disable_focus_animation ( void  )

Don't show Focused Unit Animation.

Definition at line 1186 of file gui_main.c.

Referenced by end_turn_callback(), main_key_down_handler(), remove_net_input(), and update_unit_info_label().

◆ editgui_notify_object_changed()

void editgui_notify_object_changed ( int  objtype,
int  object_id,
bool  removal 
)

Stub for editor function

Definition at line 1259 of file gui_main.c.

◆ editgui_notify_object_created()

void editgui_notify_object_created ( int  tag,
int  id 
)

Stub for editor function

Definition at line 1265 of file gui_main.c.

◆ editgui_popdown_all()

void editgui_popdown_all ( void  )

Stub for editor function

Definition at line 1253 of file gui_main.c.

◆ editgui_popup_properties()

void editgui_popup_properties ( const struct tile_list *  tiles,
int  objtype 
)

Stub for editor function

Definition at line 1247 of file gui_main.c.

◆ editgui_refresh()

void editgui_refresh ( void  )

Stub for editor function

Definition at line 1241 of file gui_main.c.

◆ editgui_tileset_changed()

void editgui_tileset_changed ( void  )

Stub for editor function

Definition at line 1235 of file gui_main.c.

◆ enable_focus_animation()

void enable_focus_animation ( void  )

Show Focused Unit Animation.

Definition at line 1177 of file gui_main.c.

Referenced by add_net_input(), and update_unit_info_label().

◆ FilterMouseMotionEvents()

int FilterMouseMotionEvents ( void *  data,
SDL_Event *  event 
)

Filter out mouse motion events for too small movement to react to. This function may run in a separate event thread.

Definition at line 572 of file gui_main.c.

Referenced by factor_horiz_cma_callback(), horiz_taxrate_callback(), min_horiz_cma_callback(), move_window(), and vertic_scroll_widget_list().

◆ flush_event()

bool flush_event ( void  )

Queue a flush event to be handled later by SDL.

Definition at line 1321 of file gui_main.c.

Referenced by queue_flush().

◆ force_exit_from_event_loop()

void force_exit_from_event_loop ( void  )

Instruct event loop to exit.

Definition at line 556 of file gui_main.c.

Referenced by exit_callback(), popdown_conn_list_dialog(), and races_toggles_set_sensitive().

◆ fullscreen_callback()

static void fullscreen_callback ( struct option poption)
static

Change fullscreen status after option changed.

Definition at line 927 of file gui_main.c.

Referenced by options_extra_init().

◆ get_gui_type()

enum gui_type get_gui_type ( void  )

Return our GUI type

Definition at line 1160 of file gui_main.c.

◆ gui_event_loop()

Uint16 gui_event_loop ( void *  data,
void(*)(void *data)  loop_action,
Uint16(*)(SDL_Keysym key, void *data)  key_down_handler,
Uint16(*)(SDL_Keysym key, void *data)  key_up_handler,
Uint16(*)(char *text, void *data)  textinput_handler,
Uint16(*)(SDL_TouchFingerEvent *touch_event, void *data)  finger_down_handler,
Uint16(*)(SDL_TouchFingerEvent *touch_event, void *data)  finger_up_handler,
Uint16(*)(SDL_TouchFingerEvent *touch_event, void *data)  finger_motion_handler,
Uint16(*)(SDL_MouseButtonEvent *button_event, void *data)  mouse_button_down_handler,
Uint16(*)(SDL_MouseButtonEvent *button_event, void *data)  mouse_button_up_handler,
Uint16(*)(SDL_MouseMotionEvent *motion_event, void *data)  mouse_motion_handler 
)

◆ gui_update_font()

void gui_update_font ( const char *  font_name,
const char *  font_value 
)

Updates a gui font style.

Definition at line 1271 of file gui_main.c.

◆ insert_client_build_info()

void insert_client_build_info ( char *  outbuf,
size_t  outlen 
)

Insert build information to help

Definition at line 1313 of file gui_main.c.

◆ main()

int main ( int  argc,
char **  argv 
)

Entry point for freeciv client program. SDL has macro magic to turn this in to function named SDL_main() and it provides actual main() itself.

Definition at line 992 of file gui_main.c.

◆ main_finger_down_handler()

static Uint16 main_finger_down_handler ( SDL_TouchFingerEvent *  touch_event,
void *  data 
)
static

Main finger down handler.

Definition at line 320 of file gui_main.c.

Referenced by ui_main().

◆ main_finger_up_handler()

static Uint16 main_finger_up_handler ( SDL_TouchFingerEvent *  touch_event,
void *  data 
)
static

Main finger release handler.

Definition at line 348 of file gui_main.c.

Referenced by ui_main().

◆ main_key_down_handler()

static Uint16 main_key_down_handler ( SDL_Keysym  key,
void *  data 
)
static

Main handler for key presses

Definition at line 228 of file gui_main.c.

Referenced by ui_main().

◆ main_key_up_handler()

static Uint16 main_key_up_handler ( SDL_Keysym  key,
void *  data 
)
static

Main key release handler.

Definition at line 309 of file gui_main.c.

Referenced by ui_main().

◆ main_mouse_button_down_handler()

static Uint16 main_mouse_button_down_handler ( SDL_MouseButtonEvent *  button_event,
void *  data 
)
static

Main mouse click handler.

Definition at line 372 of file gui_main.c.

Referenced by ui_main().

◆ main_mouse_button_up_handler()

static Uint16 main_mouse_button_up_handler ( SDL_MouseButtonEvent *  button_event,
void *  data 
)
static

Main mouse button release handler.

Definition at line 408 of file gui_main.c.

Referenced by ui_main().

◆ main_mouse_motion_handler()

static Uint16 main_mouse_motion_handler ( SDL_MouseMotionEvent *  motion_event,
void *  data 
)
static

Main handler for mouse movement handling.

Definition at line 434 of file gui_main.c.

Referenced by ui_main().

◆ migrate_options_from_sdl()

static void migrate_options_from_sdl ( void  )
static

Migrate sdl2 client specific options from sdl client options.

Definition at line 1000 of file gui_main.c.

Referenced by ui_main().

◆ options_extra_init()

void options_extra_init ( void  )

Extra initializers for client options. Here we make set the callback for the specific gui-sdl2 options.

Definition at line 955 of file gui_main.c.

◆ parse_options()

static bool parse_options ( int  argc,
char **  argv 
)
static

Search for gui-specific command-line options.

Definition at line 191 of file gui_main.c.

◆ print_usage()

static void print_usage ( void  )
static

Print extra usage information, including one line help on each option, to stderr.

Definition at line 174 of file gui_main.c.

◆ real_resize_window_callback()

static void real_resize_window_callback ( void *  data)
static

Really resize the main window.

Definition at line 884 of file gui_main.c.

Referenced by fullscreen_callback(), and resize_window_callback().

◆ remove_net_input()

void remove_net_input ( void  )

Stop waiting for any server network data. See add_net_input().

Definition at line 1206 of file gui_main.c.

◆ resize_window_callback()

static void resize_window_callback ( struct option poption)
static

Resize the main window after option changed.

Definition at line 919 of file gui_main.c.

Referenced by options_extra_init().

◆ sound_bell()

void sound_bell ( void  )

Make a bell noise (beep). This provides low-level sound alerts even if there is no real sound support.

Definition at line 1169 of file gui_main.c.

◆ ui_exit()

void ui_exit ( void  )

Do any necessary UI-specific cleanup

Definition at line 1153 of file gui_main.c.

◆ ui_init()

void ui_init ( void  )

Do any necessary pre-initialization of the UI, if necessary.

Definition at line 866 of file gui_main.c.

◆ ui_main()

int ui_main ( int  argc,
char *  argv[] 
)

The main loop for the UI. This is called from main(), and when it exits the client will exit.

Definition at line 1021 of file gui_main.c.

◆ update_button_hold_state()

static void update_button_hold_state ( void  )
static

This is called every TIMER_INTERVAL milliseconds whilst we are in gui_main_loop() (which is all of the time) TIMER_INTERVAL needs to be .5s

Definition at line 485 of file gui_main.c.

Referenced by gui_event_loop().

◆ update_font_from_theme()

void update_font_from_theme ( int  theme_font_size)

Update font sizes based on theme.

Definition at line 1304 of file gui_main.c.

Referenced by gui_load_theme().

Variable Documentation

◆ __anim_user_event

SDL_Event __anim_user_event
static

Definition at line 129 of file gui_main.c.

Referenced by ui_main().

◆ __flush_user_event

SDL_Event __flush_user_event
static

Definition at line 131 of file gui_main.c.

Referenced by ui_main().

◆ __info_user_event

SDL_Event __info_user_event
static

Definition at line 130 of file gui_main.c.

Referenced by ui_main().

◆ __map_scroll_user_event

SDL_Event __map_scroll_user_event
static

Definition at line 132 of file gui_main.c.

Referenced by ui_main().

◆ __net_user_event

SDL_Event __net_user_event
static

Definition at line 128 of file gui_main.c.

Referenced by ui_main().

◆ anim_user_event

SDL_Event* anim_user_event = NULL
static

Definition at line 135 of file gui_main.c.

Referenced by enable_focus_animation(), gui_event_loop(), and ui_main().

◆ autoconnect

bool autoconnect = FALSE
static

Definition at line 121 of file gui_main.c.

Referenced by add_net_input(), and gui_event_loop().

◆ button_behavior

struct mouse_button_behavior button_behavior
static

◆ callbacks

struct callback_list* callbacks = NULL

Definition at line 166 of file gui_main.c.

Referenced by add_idle_callback(), gui_event_loop(), and ui_main().

◆ city_names_font_size

int city_names_font_size = 10
static

Definition at line 109 of file gui_main.c.

◆ city_productions_font_size

int city_productions_font_size = 10
static

Definition at line 110 of file gui_main.c.

◆ client_font_sizes

int* client_font_sizes[FONT_COUNT]
Initial value:
= {
}
static int city_names_font_size
Definition gui_main.c:109
static int city_productions_font_size
Definition gui_main.c:110

Definition at line 111 of file gui_main.c.

Referenced by canvas_put_text(), get_text_size(), and update_font_from_theme().

◆ client_string

const char* client_string = "gui-sdl2"

Definition at line 89 of file gui_main.c.

◆ draw_goto_patrol_lines

bool draw_goto_patrol_lines
extern

◆ finger_behavior

Definition at line 125 of file gui_main.c.

◆ flush_user_event

SDL_Event* flush_user_event = NULL
static

Definition at line 137 of file gui_main.c.

Referenced by flush_event(), and ui_main().

◆ font_size_parameter

unsigned font_size_parameter = 0
static

Definition at line 117 of file gui_main.c.

Referenced by default_font_size(), and parse_options().

◆ gui_character_encoding

const char* const gui_character_encoding = "UTF-8"

Definition at line 94 of file gui_main.c.

◆ gui_use_transliteration

const bool gui_use_transliteration = FALSE

Definition at line 95 of file gui_main.c.

◆ info_user_event

SDL_Event* info_user_event = NULL
static

Definition at line 136 of file gui_main.c.

Referenced by gui_event_loop(), and ui_main().

◆ is_map_scrolling

bool is_map_scrolling = FALSE
static

◆ is_unit_move_blocked

bool is_unit_move_blocked

◆ LALT

bool LALT

Definition at line 108 of file gui_main.c.

Referenced by button_up_on_map(), and gui_event_loop().

◆ LCTRL

bool LCTRL

Definition at line 106 of file gui_main.c.

Referenced by button_up_on_map(), gui_event_loop(), and map_event_handler().

◆ LSHIFT

bool LSHIFT

◆ map_scroll_user_event

SDL_Event* map_scroll_user_event = NULL
static

Definition at line 138 of file gui_main.c.

Referenced by gui_event_loop(), and ui_main().

◆ MOVE_STEP_X

int MOVE_STEP_X = DEFAULT_MOVE_STEP

◆ MOVE_STEP_Y

int MOVE_STEP_Y = DEFAULT_MOVE_STEP

◆ net_socket

int net_socket = -1
static

Definition at line 120 of file gui_main.c.

Referenced by add_net_input(), gui_event_loop(), and remove_net_input().

◆ net_user_event

SDL_Event* net_user_event = NULL
static

Definition at line 134 of file gui_main.c.

Referenced by gui_event_loop(), and ui_main().

◆ RCTRL

bool RCTRL

Definition at line 107 of file gui_main.c.

Referenced by gui_event_loop(), and map_event_handler().

◆ RSHIFT

bool RSHIFT

Definition at line 105 of file gui_main.c.

Referenced by gui_event_loop(), main_key_down_handler(), and map_event_handler().

◆ scroll_dir

enum direction8 scroll_dir
static

Definition at line 123 of file gui_main.c.

Referenced by check_scroll_area(), and gui_event_loop().

◆ sdl2_client_flags

Uint32 sdl2_client_flags = 0

◆ user_event_type

int user_event_type

Definition at line 144 of file gui_main.c.

Referenced by force_exit_from_event_loop(), gui_event_loop(), and ui_main().

◆ widget_info_counter

Uint32 widget_info_counter = 0