/************************************************************************** Button pressed at overview **************************************************************************/ gboolean butt_down_overviewcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data) { int xtile, ytile; if (ev->type != GDK_BUTTON_PRESS) return TRUE; /* Double-clicks? Triple-clicks? No thanks! */ overview_to_map_pos(&xtile, &ytile, ev->x, ev->y); if (can_client_change_view() && (ev->button == 3)) { center_tile_mapcanvas(map_pos_to_tile(xtile, ytile)); } else if (can_client_issue_orders() && (ev->button == 1)) { do_map_click(map_pos_to_tile(xtile, ytile), (ev->state & GDK_SHIFT_MASK) ? SELECT_APPEND : SELECT_POPUP); } return TRUE; }
/************************************************************************** ... **************************************************************************/ static void overview_mouse_press_callback(struct sw_widget *widget, const struct ct_point *pos, enum be_mouse_button button, int state, void *data) { int xtile, ytile; freelog(LOG_DEBUG, "press (%d,%d)", pos->x, pos->y); overview_to_map_pos(&xtile,&ytile,pos->x,pos->y); freelog(LOG_DEBUG, " --> (%d,%d)", xtile, ytile); if (can_client_change_view() && button == 3) { center_tile_mapcanvas(map_pos_to_tile(xtile, ytile)); } /* FIXME else if (can_client_issue_orders() && ev->button == 1) { do_unit_goto(xtile, ytile); } */ }
/************************************************************************** ... **************************************************************************/ void mapctrl_btn_overviewcanvas(XEvent *event) { int map_x, map_y; struct tile *ptile; XButtonEvent *ev = &event->xbutton; if (!can_client_change_view()) { return; } overview_to_map_pos(&map_x, &map_y, event->xbutton.x, event->xbutton.y); ptile = map_pos_to_tile(map_x, map_y); if (!ptile) { return; } if(ev->button==Button1) do_map_click(ptile, SELECT_POPUP); else if(ev->button==Button3) center_tile_mapcanvas(ptile); }
/*************************************************************************** Client variant of city_tile(). This include the case of this could a ghost city (see client/packhand.c). In a such case, the returned tile is an approximative position of the city on the map. ***************************************************************************/ struct tile *client_city_tile(const struct city *pcity) { int dx, dy; double x = 0, y = 0; size_t num = 0; if (NULL == pcity) { return NULL; } if (NULL != city_tile(pcity)) { /* Normal city case. */ return city_tile(pcity); } whole_map_iterate(ptile) { int tile_x, tile_y; index_to_map_pos(&tile_x, &tile_y, tile_index(ptile)); if (pcity == tile_worked(ptile)) { if (0 == num) { x = tile_x; y = tile_y; num = 1; } else { num++; base_map_distance_vector(&dx, &dy, (int)x, (int)y, tile_x, tile_y); x += (double) dx / num; y += (double) dy / num; } } } whole_map_iterate_end; if (0 < num) { return map_pos_to_tile((int) x, (int) y); } else { return NULL; } }