Freeciv-3.2
Loading...
Searching...
No Matches
mapctrl.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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <gtk/gtk.h>
19
20/* utility */
21#include "fcintl.h"
22#include "support.h"
23
24/* common */
25#include "combat.h"
26#include "game.h"
27#include "map.h"
28#include "player.h"
29#include "unit.h"
30
31#include "overview_common.h"
32
33/* client */
34#include "client_main.h"
35#include "climap.h"
36#include "climisc.h"
37#include "control.h"
38#include "editor.h"
39#include "tilespec.h"
40#include "text.h"
41#include "zoom.h"
42
43/* client/agents */
44#include "cma_core.h"
45
46/* client/gui-gtk-4.0 */
47#include "chatline.h"
48#include "citydlg.h"
49#include "colors.h"
50#include "dialogs.h"
51#include "editgui.h"
52#include "graphics.h"
53#include "gui_main.h"
54#include "infradlg.h"
55#include "inputdlg.h"
56#include "mapview.h"
57#include "menu.h"
58#include "rallypointdlg.h"
59
60#include "mapctrl.h"
61
63
64/**********************************************************************/
106
107/**********************************************************************/
117
118/**********************************************************************/
121static void name_new_city_popup_callback(gpointer data, gint response,
122 const char *input)
123{
124 int idx = GPOINTER_TO_INT(data);
125
126 switch (response) {
127 case GTK_RESPONSE_OK:
129 break;
133 break;
134 }
135}
136
137/**********************************************************************/
142void popup_newcity_dialog(struct unit *punit, const char *suggestname)
143{
144 input_dialog_create(GTK_WINDOW(toplevel), /*"shellnewcityname" */
145 _("Build New City"),
146 _("What should we call our new city?"), suggestname,
149}
150
151/**********************************************************************/
161
162/**********************************************************************/
167 double x, double y, gpointer data)
168{
169 if (editor_is_active()) {
171 x, y);
172 }
173
175
176 return TRUE;
177}
178
179/**********************************************************************/
184 double x, double y, gpointer data)
185{
186 if (editor_is_active()) {
188 x, y);
189 }
190
192
194 GdkModifierType state;
195
198 (state & GDK_SHIFT_MASK) != 0);
199 }
200
201 return TRUE;
202}
203
204/**********************************************************************/
209 double x, double y, gpointer data)
210{
211 struct tile *ptile = NULL;
212 GdkModifierType state;
213
214 if (editor_is_active()) {
216 x, y);
217 }
218
219 if (!can_client_change_view()) {
220 return TRUE;
221 }
222
224 ptile = canvas_pos_to_tile(x, y, mouse_zoom);
225
227
228 /* <SHIFT> + <CONTROL> + LMB : Adjust workers. */
229 if ((state & GDK_SHIFT_MASK) && (state & GDK_CONTROL_MASK)) {
231 } else if (state & GDK_CONTROL_MASK) {
232 /* <CONTROL> + LMB : Quickselect a sea unit. */
234 } else if (ptile && (state & GDK_SHIFT_MASK)) {
235 /* <SHIFT> + LMB: Append focus unit. */
237 } else if (ptile && (state & GDK_ALT_MASK)) {
238 /* <ALT> + LMB: popit (same as middle-click) */
239 /* FIXME: we need a general mechanism for letting freeciv work with
240 * 1- or 2-button mice. */
241 popit(ptile);
242 } else if (tiles_hilited_cities) {
243 /* LMB in Area Selection mode. */
244 if (ptile) {
245 toggle_tile_hilite(ptile);
246 }
247 } else if (rally_set_tile(ptile)) {
248 /* Nothing here, rally_set_tile() already did what we wanted */
249 } else if (infra_placement_mode()) {
251 } else {
252 /* Plain LMB click. */
254 }
255
256 return TRUE;
257}
258
259/**********************************************************************/
264 double x, double y, gpointer data)
265{
266 struct city *pcity = NULL;
267 struct tile *ptile = NULL;
268 GdkModifierType state;
269
270 if (editor_is_active()) {
272 x, y);
273 }
274
275 if (!can_client_change_view()) {
276 return TRUE;
277 }
278
280 ptile = canvas_pos_to_tile(x, y, mouse_zoom);
281 pcity = ptile ? tile_city(ptile) : NULL;
282
285
286 /* <CONTROL> + <ALT> + RMB : insert city or tile chat link. */
287 /* <CONTROL> + <ALT> + <SHIFT> + RMB : insert unit chat link. */
288 if (ptile && (state & GDK_ALT_MASK)
289 && (state & GDK_CONTROL_MASK)) {
290 inputline_make_chat_link(ptile, (state & GDK_SHIFT_MASK) != 0);
291 } else if ((state & GDK_SHIFT_MASK) && (state & GDK_ALT_MASK)) {
292 /* <SHIFT> + <ALT> + RMB : Show/hide workers. */
294 } else if ((state & GDK_SHIFT_MASK) && (state & GDK_CONTROL_MASK)
295 && pcity != NULL) {
296 /* <SHIFT + CONTROL> + RMB: Paste Production. */
299 } else if (state & GDK_SHIFT_MASK
300 && clipboard_copy_production(ptile)) {
301 /* <SHIFT> + RMB on city/unit: Copy Production. */
302 /* If nothing to copy, fall through to rectangle selection. */
303
304 /* Already done the copy */
305 } else if (state & GDK_CONTROL_MASK) {
306 /* <CONTROL> + RMB : Quickselect a land unit. */
308 } else {
309 /* Plain RMB click. Area selection. */
310 /* A foolproof user will depress button on canvas,
311 * release it on another widget, and return to canvas
312 * to find rectangle still active.
313 */
314 if (rectangle_active) {
316 (state & GDK_SHIFT_MASK) != 0);
317 return TRUE;
318 }
319 if (hover_state == HOVER_NONE) {
321 rbutton_down = TRUE; /* Causes rectangle updates */
322 }
323 }
324
325 return TRUE;
326}
327
328/**********************************************************************/
333 double x, double y, gpointer data)
334{
335 struct tile *ptile = NULL;
336 GdkModifierType state;
337
338 if (editor_is_active()) {
340 x, y);
341 }
342
343 if (!can_client_change_view()) {
344 return TRUE;
345 }
346
348 ptile = canvas_pos_to_tile(x, y, mouse_zoom);
349
351
352 /* <CONTROL> + MMB: Wake up sentries. */
353 if (state & GDK_CONTROL_MASK) {
355 } else if (ptile) {
356 /* Plain Middle click. */
357 popit(ptile);
358 }
359
360 return TRUE;
361}
362
363/**********************************************************************/
367{
368 double x, y;
371 GdkSurface *window;
372
373 if (!pointer) {
374 return;
375 }
376
378 if (window) {
380 update_line(x, y);
383 }
384 }
385}
386
387/**********************************************************************/
415
416/**********************************************************************/
449
450/**********************************************************************/
461
462/**********************************************************************/
472
473/**********************************************************************/
477 double x, double y, gpointer data)
478{
479 int xtile, ytile;
480
481 if (n_press != 1) {
482 return TRUE; /* Double-clicks? Triple-clicks? No thanks! */
483 }
484
486
488 GdkModifierType state;
489
493 }
494
495 return TRUE;
496}
497
498/**********************************************************************/
502 double x, double y, gpointer data)
503{
504 int xtile, ytile;
505
506 if (n_press != 1) {
507 return TRUE; /* Double-clicks? Triple-clicks? No thanks! */
508 }
509
511
514 }
515
516 return TRUE;
517}
518
519/**********************************************************************/
523{
525}
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
bool can_client_issue_orders(void)
bool can_client_change_view(void)
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
char * incite_cost
Definition comments.c:75
void do_map_click(struct tile *ptile, enum quickselect_type qtype)
Definition control.c:2921
struct unit_list * get_units_in_focus(void)
Definition control.c:177
void request_center_focus_unit(void)
Definition control.c:2762
enum cursor_hover_state hover_state
Definition control.c:89
void finish_city(struct tile *ptile, const char *name)
Definition control.c:4103
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:834
void control_mouse_cursor(struct tile *ptile)
Definition control.c:1227
void cancel_city(struct tile *ptile)
Definition control.c:4122
@ SELECT_LAND
Definition control.h:38
@ SELECT_APPEND
Definition control.h:38
@ SELECT_SEA
Definition control.h:38
@ SELECT_POPUP
Definition control.h:38
@ HOVER_NONE
Definition control.h:26
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
bool editor_is_active(void)
Definition editor.c:347
@ MOUSE_BUTTON_LEFT
Definition editor.h:126
@ MOUSE_BUTTON_RIGHT
Definition editor.h:128
@ MOUSE_BUTTON_MIDDLE
Definition editor.h:127
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:63
void inputline_make_chat_link(struct tile *ptile, bool unit)
Definition chatline.c:474
gboolean handle_edit_mouse_button_release(GdkEventButton *ev)
Definition editgui.c:956
gboolean handle_edit_mouse_button_press(GdkEventButton *ev)
Definition editgui.c:940
gboolean handle_edit_mouse_move(GdkEventMotion *ev)
Definition editgui.c:971
GtkWidget * turn_done_button
Definition gui_main.c:148
GtkWidget * overview_canvas
Definition gui_main.c:111
GtkWidget * toplevel
Definition gui_main.c:125
GtkWidget * map_canvas
Definition gui_main.c:107
void update_turn_done_tooltip(void)
Definition gui_main.c:1105
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:32
bool infra_placement_mode(void)
Definition infradlg.c:155
void infra_placement_set_tile(struct tile *ptile)
Definition infradlg.c:163
GtkWidget * input_dialog_create(GtkWindow *parent, const char *dialogname, const char *text, const char *postinputtest, input_dialog_callback_t response_callback, gpointer response_cli_data)
Definition inputdlg.c:66
gboolean move_overviewcanvas(GtkWidget *w, GdkEventMotion *ev, gpointer data)
Definition mapctrl.c:463
gint cur_y
Definition mapctrl.c:63
void popup_newcity_dialog(struct unit *punit, const char *suggestname)
Definition mapctrl.c:197
void center_on_unit(void)
Definition mapctrl.c:496
void create_line_at_mouse_pos(void)
Definition mapctrl.c:355
gboolean move_mapcanvas(GtkWidget *w, GdkEventMotion *ev, gpointer data)
Definition mapctrl.c:406
static void popit(GdkEventButton *ev, struct tile *ptile)
Definition mapctrl.c:121
gint cur_x
Definition gui_main.c:182
void set_turn_done_button_state(bool state)
Definition mapctrl.c:210
gboolean leave_mapcanvas(GtkWidget *widget, GdkEventCrossing *event)
Definition mapctrl.c:435
void popupinfo_popdown_callback(GtkWidget *w, gpointer data)
Definition mapctrl.c:167
static void name_new_city_popup_callback(gpointer data, gint response, const char *input)
Definition mapctrl.c:176
void update_rect_at_mouse_pos(void)
Definition mapctrl.c:380
void update_unit_info_label(struct unit_list *punits)
Definition mapview.c:275
void update_mouse_cursor(enum cursor_type new_cursor_type)
Definition mapview.c:257
bool rally_set_tile(struct tile *ptile)
gboolean right_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:501
gboolean left_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:166
gboolean right_butt_up_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:183
gboolean left_butt_down_overviewcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:476
gboolean left_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:208
gboolean right_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:263
gboolean middle_butt_down_mapcanvas(GtkGestureClick *gesture, int n_press, double x, double y, gpointer data)
Definition mapctrl.c:332
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:419
void update_line(int canvas_x, int canvas_y)
void maybe_activate_keyboardless_goto(int canvas_x, int canvas_y)
void adjust_workers_button_pressed(int canvas_x, int canvas_y)
bool rbutton_down
bool rectangle_active
void release_goto_button(int canvas_x, int canvas_y)
bool tiles_hilited_cities
void action_button_pressed(int canvas_x, int canvas_y, enum quickselect_type qtype)
void wakeup_button_pressed(int canvas_x, int canvas_y)
void release_right_button(int canvas_x, int canvas_y, bool shift)
bool keyboardless_goto_button_down
void key_city_overlay(int canvas_x, int canvas_y)
void update_selection_rectangle(float canvas_x, float canvas_y)
void overview_update_line(int overview_x, int overview_y)
void anchor_selection_rectangle(int canvas_x, int canvas_y)
void cancel_tile_hiliting(void)
void clipboard_paste_production(struct city *pcity)
bool clipboard_copy_production(struct tile *ptile)
void toggle_tile_hilite(struct tile *ptile)
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y, float zoom)
void mapdeco_set_gotoroute(const struct unit *punit)
void mapdeco_clear_gotoroutes(void)
void center_tile_mapcanvas(const struct tile *ptile)
void mapdeco_clear_crosshairs(void)
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, float zoom, const struct tile *ptile)
void overview_to_map_pos(int *map_x, int *map_y, int overview_x, int overview_y)
struct sprite int int int int struct sprite * mask
Definition sprite_g.h:32
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
Definition city.h:320
Definition tile.h:50
Definition unit.h:137
struct tile * goto_tile
Definition unit.h:154
struct civ_map map
#define TRUE
Definition support.h:46
const char * popup_info_text(struct tile *ptile)
Definition text.c:147
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
@ TILE_UNKNOWN
Definition tile.h:36
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:765
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
@ CURSOR_DEFAULT
Definition tilespec.h:301
#define unit_tile(_pu)
Definition unit.h:396
float mouse_zoom
Definition zoom.c:28
float map_zoom
Definition zoom.c:25