[Freeciv-Dev] (PR#10385) cleanups to canvas<->map pos
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10385 >
This patch:
- Renames map_to_canvas_pos as tile_to_canvas_pos.
- Replaces canvas_to_map_pos.
- Adds a new function canvas_pos_to_tile (basically the same as
canvas_to_map_pos).
- Adds a new function canvas_pos_to_nearest_tile.
so instead of
if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y))
ptile = map_pos_to_tile(map_x, map_y);
we have
ptile = canvas_pos_to_tile(canvas_x, canvas_y);
and instead of
if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y))
ptile = map_pos_to_tile(map_x, map_y);
else
ptile = nearest_real_tile(map_x, map_y0;
we have
ptile = canvas_pos_to_nearest_tile(canvas_x, canvas_y);
Thanks to Mike for the suggestion of a second function here.
jason
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.142
diff -u -r1.142 control.c
--- client/control.c 29 Sep 2004 02:24:19 -0000 1.142
+++ client/control.c 29 Sep 2004 15:57:24 -0000
@@ -1373,7 +1373,7 @@
int height = get_citydlg_canvas_height();
int canvas_x, canvas_y;
- map_to_canvas_pos(&canvas_x, &canvas_y, ptile);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
width, height);
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.41
diff -u -r1.41 mapctrl_common.c
--- client/mapctrl_common.c 29 Sep 2004 02:24:19 -0000 1.41
+++ client/mapctrl_common.c 29 Sep 2004 15:57:24 -0000
@@ -42,7 +42,7 @@
/* Selection Rectangle */
static int rec_anchor_x, rec_anchor_y; /* canvas coordinates for anchor */
-static int rec_canvas_map_x0, rec_canvas_map_y0; /* mapview centering */
+static struct tile *rec_canvas_center_tile;
static int rec_corner_x, rec_corner_y; /* corner to iterate from */
static int rec_w, rec_h; /* width, heigth in pixels */
@@ -81,15 +81,13 @@
**************************************************************************/
void anchor_selection_rectangle(int canvas_x, int canvas_y)
{
- int tile_x, tile_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y);
- map_to_canvas_pos(&rec_anchor_x, &rec_anchor_y,
- nearest_real_tile(tile_x, tile_y));
+ tile_to_canvas_pos(&rec_anchor_x, &rec_anchor_y, ptile);
rec_anchor_x += NORMAL_TILE_WIDTH / 2;
rec_anchor_y += NORMAL_TILE_HEIGHT / 2;
/* FIXME: This may be off-by-one. */
- canvas_to_map_pos(&rec_canvas_map_x0, &rec_canvas_map_y0, 0, 0);
+ rec_canvas_center_tile = get_center_tile_mapcanvas();
rec_w = rec_h = 0;
}
@@ -115,15 +113,13 @@
const int inc_x = (rec_w > 0 ? half_W : -half_W);
const int inc_y = (rec_h > 0 ? half_H : -half_H);
- int x, y, x2, y2, xx, yy, tile_x, tile_y;
- bool is_real;
- struct tile *ptile;
- struct city *pcity;
+ int x, y, x2, y2, xx, yy;
y = rec_corner_y;
for (yy = 0; yy <= segments_y; yy++, y += inc_y) {
x = rec_corner_x;
for (xx = 0; xx <= segments_x; xx++, x += inc_x) {
+ struct tile *ptile;
/* For diamond shaped tiles, every other row is indented.
*/
@@ -131,14 +127,15 @@
continue;
}
- is_real = canvas_to_map_pos(&tile_x, &tile_y, x, y);
-
- if (!is_real) continue;
+ ptile = canvas_pos_to_tile(x, y);
+ if (!ptile) {
+ continue;
+ }
/* "Half-tile" indentation must match, or we'll process
* some tiles twice in the case of rectangular shape tiles.
*/
- map_to_canvas_pos(&x2, &y2, nearest_real_tile(tile_x, tile_y));
+ tile_to_canvas_pos(&x2, &y2, ptile);
if ((yy % 2) != 0 && ((rec_corner_x % W) ^ abs(x2 % W)) != 0) {
continue;
@@ -146,9 +143,7 @@
/* Tile passed all tests; process it.
*/
- ptile = map_pos_to_tile(tile_x, tile_y);
- pcity = ptile->city;
- if (pcity && pcity->owner == game.player_idx) {
+ if (ptile->city && ptile->city->owner == game.player_idx) {
ptile->client.hilite = HILITE_CITY;
tiles_hilited_cities = TRUE;
}
@@ -168,20 +163,20 @@
{
const int W = NORMAL_TILE_WIDTH, half_W = W / 2;
const int H = NORMAL_TILE_HEIGHT, half_H = H / 2;
- static int rec_tile_x = 9999, rec_tile_y = 9999;
- int tile_x, tile_y, diff_x, diff_y;
- int map_x0, map_y0;
+ static struct tile *rec_tile = NULL;
+ int diff_x, diff_y;
+ struct tile *center_tile;
+ struct tile *ptile;
- canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y);
+ ptile = canvas_pos_to_nearest_tile(canvas_x, canvas_y);
/* Did mouse pointer move beyond the current tile's
* boundaries? Avoid macros; tile may be unreal!
*/
- if (tile_x == rec_tile_x && tile_y == rec_tile_y) {
+ if (ptile == rec_tile) {
return;
}
- rec_tile_x = tile_x;
- rec_tile_y = tile_y;
+ rec_tile = ptile;
/* Clear previous rectangle. */
dirty_all();
@@ -189,7 +184,7 @@
/* Fix canvas coords to the center of the tile.
*/
- map_to_canvas_pos(&canvas_x, &canvas_y, nearest_real_tile(tile_x, tile_y));
+ tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
canvas_x += half_W;
canvas_y += half_H;
@@ -197,9 +192,8 @@
rec_h = rec_anchor_y - canvas_y; /* height */
/* FIXME: This may be off-by-one. */
- canvas_to_map_pos(&map_x0, &map_y0, 0, 0);
- diff_x = rec_canvas_map_x0 - map_x0;
- diff_y = rec_canvas_map_y0 - map_y0;
+ center_tile = get_center_tile_mapcanvas();
+ map_distance_vector(&diff_x, &diff_y, center_tile, rec_canvas_center_tile);
/* Adjust width, height if mapview has recentered.
*/
@@ -309,12 +303,10 @@
**************************************************************************/
void key_city_overlay(int canvas_x, int canvas_y)
{
- int map_x, map_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (can_client_change_view()
- && canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
+ if (can_client_change_view() && ptile) {
struct unit *punit;
- struct tile *ptile = map_pos_to_tile(map_x, map_y);
struct city *pcity = find_city_or_settler_near_tile(ptile, &punit);
if (pcity) {
@@ -428,13 +420,13 @@
**************************************************************************/
void release_goto_button(int canvas_x, int canvas_y)
{
- int tile_x, tile_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (keyboardless_goto_active && hover_state == HOVER_GOTO &&
- canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y)) {
+ if (keyboardless_goto_active && hover_state == HOVER_GOTO && ptile) {
struct unit *punit =
player_find_unit_by_id(game.player_ptr, hover_unit);
- do_unit_goto(map_pos_to_tile(tile_x, tile_y));
+
+ do_unit_goto(ptile);
set_hover_state(NULL, HOVER_NONE, ACTIVITY_LAST);
update_unit_info_label(punit);
}
@@ -449,12 +441,10 @@
**************************************************************************/
void maybe_activate_keyboardless_goto(int canvas_x, int canvas_y)
{
- int tile_x, tile_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (get_unit_in_focus()
- && canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y)
- && !same_pos(keyboardless_goto_start_tile,
- map_pos_to_tile(tile_x, tile_y))
+ if (ptile && get_unit_in_focus()
+ && !same_pos(keyboardless_goto_start_tile, ptile)
&& can_client_issue_orders()) {
keyboardless_goto_active = TRUE;
request_unit_goto();
@@ -497,16 +487,14 @@
write) a different xxx_button_pressed function.
**************************************************************************/
void action_button_pressed(int canvas_x, int canvas_y,
- enum quickselect_type qtype)
+ enum quickselect_type qtype)
{
- int map_x, map_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (can_client_change_view()) {
+ if (can_client_change_view() && ptile) {
/* FIXME: Some actions here will need to check can_client_issue_orders.
* But all we can check is the lowest common requirement. */
- if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
- do_map_click(map_pos_to_tile(map_x, map_y), qtype);
- }
+ do_map_click(ptile, qtype);
}
}
@@ -515,12 +503,10 @@
**************************************************************************/
void wakeup_button_pressed(int canvas_x, int canvas_y)
{
- int map_x, map_y;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (can_client_issue_orders()) {
- if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
- wakeup_sentried_units(map_pos_to_tile(map_x, map_y));
- }
+ if (can_client_issue_orders() && ptile) {
+ wakeup_sentried_units(ptile);
}
}
@@ -529,37 +515,35 @@
**************************************************************************/
void adjust_workers_button_pressed(int canvas_x, int canvas_y)
{
- int map_x, map_y, city_x, city_y;
+ int city_x, city_y;
enum city_tile_type worker;
+ struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
+
+ if (can_client_issue_orders() && ptile) {
+ struct city *pcity = find_city_near_tile(ptile);
- if (can_client_issue_orders()) {
- if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
- struct tile *ptile = map_pos_to_tile(map_x, map_y);
- struct city *pcity = find_city_near_tile(ptile);
-
- if (pcity && !cma_is_city_under_agent(pcity, NULL)) {
- if (!map_to_city_map(&city_x, &city_y, pcity, ptile)) {
- assert(0);
- }
-
- worker = get_worker_city(pcity, city_x, city_y);
- if (worker == C_TILE_WORKER) {
- dsend_packet_city_make_specialist(&aconnection, pcity->id, city_x,
- city_y);
- } else if (worker == C_TILE_EMPTY) {
- dsend_packet_city_make_worker(&aconnection, pcity->id, city_x,
- city_y);
- } else {
- /* If worker == C_TILE_UNAVAILABLE then we can't use this tile. No
- * packet is sent and city_workers_display is not updated. */
- return;
- }
-
- /* When the city info packet is received, update the workers on the
- * map. This is a bad hack used to selectively update the mapview
- * when we receive the corresponding city packet. */
- city_workers_display = pcity;
+ if (pcity && !cma_is_city_under_agent(pcity, NULL)) {
+ if (!map_to_city_map(&city_x, &city_y, pcity, ptile)) {
+ assert(0);
}
+
+ worker = get_worker_city(pcity, city_x, city_y);
+ if (worker == C_TILE_WORKER) {
+ dsend_packet_city_make_specialist(&aconnection, pcity->id,
+ city_x, city_y);
+ } else if (worker == C_TILE_EMPTY) {
+ dsend_packet_city_make_worker(&aconnection, pcity->id,
+ city_x, city_y);
+ } else {
+ /* If worker == C_TILE_UNAVAILABLE then we can't use this tile. No
+ * packet is sent and city_workers_display is not updated. */
+ return;
+ }
+
+ /* When the city info packet is received, update the workers on the
+ * map. This is a bad hack used to selectively update the mapview
+ * when we receive the corresponding city packet. */
+ city_workers_display = pcity;
}
}
}
@@ -570,15 +554,10 @@
**************************************************************************/
void recenter_button_pressed(int canvas_x, int canvas_y)
{
- int map_x, map_y;
- struct tile *ptile;
+ /* We use the "nearest" tile here so off-map clicks will still work. */
+ struct tile *ptile = canvas_pos_to_nearest_tile(canvas_x, canvas_y);
- if (can_client_change_view()) {
- if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
- ptile = map_pos_to_tile(map_x, map_y);
- } else {
- ptile = nearest_real_tile(map_x, map_y);
- }
+ if (can_client_change_view() && ptile) {
center_tile_mapcanvas(ptile);
}
}
@@ -631,12 +610,10 @@
|| hover_state == HOVER_CONNECT)
&& draw_goto_line) {
struct tile *ptile, *old_tile;
- int x, y;
- if (canvas_to_map_pos(&x, &y, canvas_x, canvas_y)) {
- ptile = map_pos_to_tile(x, y);
- } else {
- ptile = nearest_real_tile(x, y);
+ ptile = canvas_pos_to_tile(canvas_x, canvas_y);
+ if (!ptile) {
+ return;
}
old_tile = get_line_dest();
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.149
diff -u -r1.149 mapview_common.c
--- client/mapview_common.c 29 Sep 2004 02:24:19 -0000 1.149
+++ client/mapview_common.c 29 Sep 2004 15:57:25 -0000
@@ -64,7 +64,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
canvas_y += NORMAL_TILE_HEIGHT - UNIT_TILE_HEIGHT;
update_map_canvas(canvas_x, canvas_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
@@ -217,7 +217,7 @@
The center of a tile is defined as:
{
- map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
canvas_x += NORMAL_TILE_WIDTH / 2;
canvas_y += NORMAL_TILE_HEIGHT / 2;
}
@@ -227,7 +227,7 @@
parts of the code assume NORMAL_TILE_WIDTH and NORMAL_TILE_HEIGHT
to be even numbers.
**************************************************************************/
-bool map_to_canvas_pos(int *canvas_x, int *canvas_y, struct tile *ptile)
+bool tile_to_canvas_pos(int *canvas_x, int *canvas_y, struct tile *ptile)
{
int center_map_x, center_map_y, dx, dy;
@@ -269,24 +269,39 @@
resulting position is unwrapped and may be unreal.
****************************************************************************/
static void base_canvas_to_map_pos(int *map_x, int *map_y,
- int canvas_x, int canvas_y)
+ int canvas_x, int canvas_y)
{
gui_to_map_pos(map_x, map_y,
canvas_x + mapview_canvas.gui_x0,
canvas_y + mapview_canvas.gui_y0);
}
+/**************************************************************************
+ Finds the tile corresponding to pixel coordinates. Returns that tile,
+ or NULL if the position is off the map.
+**************************************************************************/
+struct tile *canvas_pos_to_tile(int canvas_x, int canvas_y)
+{
+ int map_x, map_y;
+
+ base_canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y);
+ if (normalize_map_pos(&map_x, &map_y)) {
+ return map_pos_to_tile(map_x, map_y);
+ } else {
+ return NULL;
+ }
+}
/**************************************************************************
- Finds the map coordinates corresponding to pixel coordinates. Returns
- TRUE if the position is real; in this case it will be normalized. Returns
- FALSE if the tile is unreal - caller may use nearest_real_pos() if
- required.
+ Finds the tile corresponding to pixel coordinates. Returns that tile,
+ or the one nearest is the position is off the map. Will never return NULL.
**************************************************************************/
-bool canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y)
+struct tile *canvas_pos_to_nearest_tile(int canvas_x, int canvas_y)
{
- base_canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y);
- return normalize_map_pos(map_x, map_y);
+ int map_x, map_y;
+
+ base_canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y);
+ return nearest_real_tile(map_x, map_y);
}
/****************************************************************************
@@ -616,16 +631,8 @@
**************************************************************************/
struct tile *get_center_tile_mapcanvas(void)
{
- int map_x, map_y;
-
- /* This sets the pointers map_x and map_y */
- if (canvas_to_map_pos(&map_x, &map_y,
- mapview_canvas.width / 2,
- mapview_canvas.height / 2)) {
- return map_pos_to_tile(map_x, map_y);
- } else {
- return nearest_real_tile(map_x, map_y);
- }
+ return canvas_pos_to_nearest_tile(mapview_canvas.width / 2,
+ mapview_canvas.height / 2);
}
/**************************************************************************
@@ -652,7 +659,7 @@
{
int dummy_x, dummy_y; /* well, it needs two pointers... */
- return map_to_canvas_pos(&dummy_x, &dummy_y, ptile);
+ return tile_to_canvas_pos(&dummy_x, &dummy_y, ptile);
}
/**************************************************************************
@@ -679,7 +686,7 @@
get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
get_mapview_scroll_pos(&scroll_x, &scroll_y);
- if (!map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (!tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
/* The tile isn't visible at all. */
return FALSE;
}
@@ -728,7 +735,7 @@
"Report this bug to bugs@xxxxxxxxxxxxxxxxxxx."));
}
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
if (sprites.path.turns[units]) {
canvas_put_sprite_full(mapview_canvas.store, canvas_x, canvas_y,
sprites.path.turns[units]);
@@ -956,7 +963,7 @@
pcity->client.color = (pcity->client.color + 1) % NUM_CITY_COLORS;
- map_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
width, height);
@@ -975,7 +982,7 @@
punit->client.color = (punit->client.color + 1) % NUM_CITY_COLORS;
- map_to_canvas_pos(&canvas_x, &canvas_y, punit->tile);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, punit->tile);
update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
width, height);
@@ -1168,9 +1175,9 @@
struct Sprite *mysprite = sprites.explode.nuke;
int width, height;
- /* We can't count on the return value of map_to_canvas_pos since the
+ /* We can't count on the return value of tile_to_canvas_pos since the
* sprite may span multiple tiles. */
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, ptile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
get_sprite_dimensions(mysprite, &width, &height);
canvas_x += (NORMAL_TILE_WIDTH - width) / 2;
@@ -1280,7 +1287,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
freelog(LOG_DEBUG, "putting (%d,%d) at (%d,%d)",
TILE_XY(ptile), canvas_x, canvas_y);
put_one_tile(mapview_canvas.store, ptile,
@@ -1423,7 +1430,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
freelog(LOG_DEBUG, "putting (%d,%d) at (%d,%d)",
TILE_XY(ptile), canvas_x, canvas_y);
@@ -1534,7 +1541,7 @@
if (pcity
&& city_colors[pcity->client.color] != COLOR_STD_LAST
&& map_to_city_map(&city_x, &city_y, pcity, ptile)
- && map_to_canvas_pos(&canvas_x2, &canvas_y2, ptile)) {
+ && tile_to_canvas_pos(&canvas_x2, &canvas_y2, ptile)) {
enum city_tile_type worker = get_worker_city(pcity, city_x, city_y);
put_city_worker(mapview_canvas.store,
@@ -1546,7 +1553,7 @@
}
} else if (punit
&& city_colors[punit->client.color] != COLOR_STD_LAST
- && map_to_canvas_pos(&canvas_x2, &canvas_y2, ptile)) {
+ && tile_to_canvas_pos(&canvas_x2, &canvas_y2, ptile)) {
/* Draw citymap overlay for settlers. */
put_city_worker(mapview_canvas.store,
city_colors[punit->client.color], C_TILE_EMPTY,
@@ -1603,7 +1610,7 @@
/* We update the entire map canvas area that this city description
* might be covering. This may, for instance, redraw other city
* descriptions that overlap with this one. */
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
update_map_canvas(canvas_x - (max_desc_width - NORMAL_TILE_WIDTH) / 2,
canvas_y + NORMAL_TILE_HEIGHT,
max_desc_width, max_desc_height);
@@ -1651,7 +1658,7 @@
if (pcity) {
int width = 0, height = 0;
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, ptile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
show_city_desc(mapview_canvas.store, canvas_x, canvas_y,
pcity, &width, &height);
@@ -1717,7 +1724,7 @@
int canvas_x, canvas_y, canvas_dx, canvas_dy;
/* Determine the source position of the segment. */
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, src_tile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, src_tile);
canvas_x += NORMAL_TILE_WIDTH / 2;
canvas_y += NORMAL_TILE_HEIGHT / 2;
@@ -1756,7 +1763,7 @@
* mapview wraps around) this will not give the correct behavior. This is
* consistent with the current design which fails when the size of the
* mapview approaches the size of the map. */
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, src_tile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, src_tile);
map_to_gui_vector(&canvas_dx, &canvas_dy, DIR_DX[dir], DIR_DY[dir]);
update_map_canvas(MIN(canvas_x, canvas_x + canvas_dx),
@@ -1798,7 +1805,7 @@
}
if (num_tiles_explode_unit > 0
- && map_to_canvas_pos(&canvas_x, &canvas_y,
+ && tile_to_canvas_pos(&canvas_x, &canvas_y,
losing_unit->tile)) {
refresh_tile_mapcanvas(losing_unit->tile, FALSE);
canvas_copy(mapview_canvas.tmp_store, mapview_canvas.store,
@@ -1876,7 +1883,7 @@
map_to_gui_vector(&canvas_dx, &canvas_dy, dx, dy);
- map_to_canvas_pos(&start_x, &start_y, src_tile);
+ tile_to_canvas_pos(&start_x, &start_y, src_tile);
if (is_isometric) {
start_y -= NORMAL_TILE_HEIGHT / 2;
}
@@ -2289,7 +2296,7 @@
{
int map_x0, map_y0;
- canvas_to_map_pos(&map_x0, &map_y0, 0, 0);
+ base_canvas_to_map_pos(&map_x0, &map_y0, 0, 0);
map_to_overview_pos(&x[0], &y[0], map_x0, map_y0);
/* Note: these calculations operate on overview coordinates as if they
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.77
diff -u -r1.77 mapview_common.h
--- client/mapview_common.h 29 Sep 2004 02:24:19 -0000 1.77
+++ client/mapview_common.h 29 Sep 2004 15:57:25 -0000
@@ -128,8 +128,9 @@
enum color_std get_grid_color(struct tile *ptile, enum direction8 dir);
void map_to_gui_vector(int *gui_dx, int *gui_dy, int map_dx, int map_dy);
-bool map_to_canvas_pos(int *canvas_x, int *canvas_y, struct tile *ptile);
-bool canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y);
+bool tile_to_canvas_pos(int *canvas_x, int *canvas_y, struct tile *ptile);
+struct tile *canvas_pos_to_tile(int canvas_x, int canvas_y);
+struct tile *canvas_pos_to_nearest_tile(int canvas_x, int canvas_y);
void get_mapview_scroll_window(int *xmin, int *ymin,
int *xmax, int *ymax,
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.407
diff -u -r1.407 packhand.c
--- client/packhand.c 29 Sep 2004 02:24:19 -0000 1.407
+++ client/packhand.c 29 Sep 2004 15:57:25 -0000
@@ -588,7 +588,7 @@
int width = get_citydlg_canvas_width();
int height = get_citydlg_canvas_height();
- (void) map_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
+ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
@@ -1209,7 +1209,7 @@
int height = get_citydlg_canvas_height();
int canvas_x, canvas_y;
- map_to_canvas_pos(&canvas_x, &canvas_y, punit->tile);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, punit->tile);
update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
width, height);
Index: client/gui-ftwl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/mapview.c,v
retrieving revision 1.5
diff -u -r1.5 mapview.c
--- client/gui-ftwl/mapview.c 29 Sep 2004 02:24:19 -0000 1.5
+++ client/gui-ftwl/mapview.c 29 Sep 2004 15:57:25 -0000
@@ -817,7 +817,7 @@
enum be_mouse_button button,
int state, void *data)
{
- int xtile, ytile;
+ struct tile *ptile;
if (!can_client_change_view()) {
return;
@@ -831,10 +831,13 @@
}
#endif
- canvas_to_map_pos(&xtile, &ytile, pos->x, pos->y);
+ ptile = canvas_pos_to_tile(pos->x, pos->y);
+ if (!ptile) {
+ return;
+ }
if (button == BE_MB_LEFT) {
- set_focus_tile(map_pos_to_tile(xtile, ytile));
+ set_focus_tile(ptile);
update_focus_tile_list();
} else if (button == BE_MB_MIDDLE) {
//popit(ev, xtile, ytile);
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.100
diff -u -r1.100 mapctrl.c
--- client/gui-gtk/mapctrl.c 29 Sep 2004 02:24:20 -0000 1.100
+++ client/gui-gtk/mapctrl.c 29 Sep 2004 15:57:25 -0000
@@ -208,7 +208,7 @@
gint butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev)
{
int xtile, ytile;
- struct tile *ptile;
+ struct tile *ptile = NULL;
struct city *pcity = NULL;
if (!can_client_change_view()) {
@@ -216,10 +216,8 @@
}
gtk_widget_grab_focus(turn_done_button);
- if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)) {
- ptile = map_pos_to_tile(xtile, ytile);
- pcity = map_get_city(ptile);
- }
+ ptile = canvas_pos_to_tile(ev->x, ev->y);
+ pcity = ptile ? ptile->city : NULL;
switch (ev->button) {
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.231
diff -u -r1.231 mapview.c
--- client/gui-gtk/mapview.c 29 Sep 2004 02:24:20 -0000 1.231
+++ client/gui-gtk/mapview.c 29 Sep 2004 15:57:26 -0000
@@ -790,7 +790,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
pixmap_put_overlay_tile(map_canvas->window,
canvas_x, canvas_y,
sprites.user.attention);
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.c,v
retrieving revision 1.42
diff -u -r1.42 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c 29 Sep 2004 02:24:21 -0000 1.42
+++ client/gui-gtk-2.0/mapctrl.c 29 Sep 2004 15:57:26 -0000
@@ -186,7 +186,6 @@
**************************************************************************/
gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data)
{
- int xtile, ytile;
struct city *pcity = NULL;
struct tile *ptile = NULL;
@@ -195,10 +194,8 @@
}
gtk_widget_grab_focus(map_canvas);
- if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)) {
- ptile = map_pos_to_tile(xtile, ytile);
- pcity = map_get_city(ptile);
- }
+ ptile = canvas_pos_to_tile(ev->x, ev->y);
+ pcity = ptile ? ptile->city : NULL;
switch (ev->button) {
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.141
diff -u -r1.141 mapview.c
--- client/gui-gtk-2.0/mapview.c 29 Sep 2004 02:24:21 -0000 1.141
+++ client/gui-gtk-2.0/mapview.c 29 Sep 2004 15:57:26 -0000
@@ -860,7 +860,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
pixmap_put_overlay_tile(map_canvas->window,
canvas_x, canvas_y,
sprites.user.attention);
Index: client/gui-mui/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.h,v
retrieving revision 1.7
diff -u -r1.7 mapview.h
--- client/gui-mui/mapview.h 3 Apr 2003 04:13:49 -0000 1.7
+++ client/gui-mui/mapview.h 29 Sep 2004 15:57:26 -0000
@@ -21,6 +21,6 @@
/* Use of these wrapper functions is deprecated. */
#define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
- map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
+ tile_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
#endif /* FC__MAPVIEW_H */
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.50
diff -u -r1.50 dialogs.c
--- client/gui-sdl/dialogs.c 23 Sep 2004 06:40:22 -0000 1.50
+++ client/gui-sdl/dialogs.c 29 Sep 2004 15:57:26 -0000
@@ -115,7 +115,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
if (canvas_x + NORMAL_TILE_WIDTH + window_width >= pWindow->dst->w)
{
if (canvas_x - window_width < 0) {
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.72
diff -u -r1.72 mapview.c
--- client/gui-sdl/mapview.c 25 Aug 2004 18:57:07 -0000 1.72
+++ client/gui-sdl/mapview.c 29 Sep 2004 15:57:27 -0000
@@ -2460,7 +2460,7 @@
static struct city *pCity;
if (draw_units && (pUnit = get_unit_in_focus())) {
- if(map_to_canvas_pos(&canvas_x, &canvas_y, pUnit->x, pUnit->y)) {
+ if(tile_to_canvas_pos(&canvas_x, &canvas_y, pUnit->x, pUnit->y)) {
area.x = canvas_x;
area.y = canvas_y - HALF_NORMAL_TILE_HEIGHT;
backup = area;
@@ -2614,7 +2614,7 @@
if (num_tiles_explode_unit &&
- map_to_canvas_pos(&canvas_x, &canvas_y, losing_unit->x, losing_unit->y))
{
+ tile_to_canvas_pos(&canvas_x, &canvas_y, losing_unit->x,
losing_unit->y)) {
/* copy screen area */
src.x = canvas_x;
src.y = canvas_y;
@@ -2693,7 +2693,7 @@
int canvas_x, canvas_y;
if (pAnim->num_tiles_explode_nuke &&
- map_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
+ tile_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
struct Sprite *pNuke;
SDL_Surface *pStore;
struct timer *anim_timer = NULL;
@@ -2767,8 +2767,8 @@
/* Find middle of tiles. y-1 to not undraw the the middle pixel of a
horizontal line when we refresh the tile below-between. */
- map_to_canvas_pos(&canvas_start_x, &canvas_start_y, src_x, src_y);
- map_to_canvas_pos(&canvas_end_x, &canvas_end_y, dest_x, dest_y);
+ tile_to_canvas_pos(&canvas_start_x, &canvas_start_y, src_x, src_y);
+ tile_to_canvas_pos(&canvas_end_x, &canvas_end_y, dest_x, dest_y);
canvas_start_x += HALF_NORMAL_TILE_WIDTH;
canvas_start_y += HALF_NORMAL_TILE_HEIGHT - 1;
canvas_end_x += HALF_NORMAL_TILE_WIDTH;
Index: client/gui-win32/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapctrl.c,v
retrieving revision 1.37
diff -u -r1.37 mapctrl.c
--- client/gui-win32/mapctrl.c 29 Sep 2004 06:26:11 -0000 1.37
+++ client/gui-win32/mapctrl.c 29 Sep 2004 15:57:27 -0000
@@ -169,8 +169,6 @@
{
HDC hdc;
PAINTSTRUCT ps;
- int xtile;
- int ytile;
struct tile *ptile;
switch(message) {
case WM_CREATE:
@@ -184,9 +182,8 @@
adjust_workers_button_pressed(LOWORD(lParam), HIWORD(lParam));
wakeup_button_pressed(LOWORD(lParam), HIWORD(lParam));
} else if (wParam & MK_CONTROL
- && canvas_to_map_pos(&xtile, &ytile,
- LOWORD(lParam), HIWORD(lParam))) {
- ptile = map_pos_to_tile(xtile, ytile);
+ && (ptile = canvas_pos_to_tile(LOWORLD(lParam),
+ HIWORD(lParam)))) {
popit(LOWORD(lParam),HIWORD(lParam),ptile);
} else {
action_button_pressed(LOWORD(lParam), HIWORD(lParam), SELECT_POPUP);
@@ -194,17 +191,15 @@
break;
case WM_MBUTTONDOWN:
if (can_client_change_view()
- && canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam))) {
- ptile = map_pos_to_tile(xtile, ytile);
+ && (ptile = canvas_pos_to_tile(LOWORLD(lParam),
+ HIWORD(lParam)))) {
popit(LOWORD(lParam), HIWORD(lParam), ptile);
}
break;
case WM_RBUTTONDOWN:
if (can_client_change_view()) {
if (wParam&MK_CONTROL) {
- if (canvas_to_map_pos(&xtile, &ytile,
- LOWORD(lParam), HIWORD(lParam))) {
- ptile = map_pos_to_tile(xtile, ytile);
+ if ((ptile = canvas_pos_to_tile(LOWORLD(lParam), HIWORD(lParam)))) {
popit(LOWORD(lParam), HIWORD(lParam), ptile);
}
} else {
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.134
diff -u -r1.134 mapview.c
--- client/gui-win32/mapview.c 29 Sep 2004 06:26:11 -0000 1.134
+++ client/gui-win32/mapview.c 29 Sep 2004 15:57:27 -0000
@@ -586,7 +586,7 @@
{
HDC hdc;
int canvas_x, canvas_y;
- map_to_canvas_pos(&canvas_x, &canvas_y, ptile);
+ tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
if (tile_visible_mapcanvas(ptile)) {
hdc=GetDC(map_window);
draw_sprite(sprites.user.attention,hdc,canvas_x,canvas_y);
Index: client/gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.16
diff -u -r1.16 mapview.h
--- client/gui-win32/mapview.h 22 Jul 2004 05:42:48 -0000 1.16
+++ client/gui-win32/mapview.h 29 Sep 2004 15:57:27 -0000
@@ -34,6 +34,6 @@
/* Use of these wrapper functions is deprecated. */
#define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
- map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
+ tile_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
#endif /* FC__MAPVIEW_H */
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.88
diff -u -r1.88 mapctrl.c
--- client/gui-xaw/mapctrl.c 29 Sep 2004 02:24:22 -0000 1.88
+++ client/gui-xaw/mapctrl.c 29 Sep 2004 15:57:28 -0000
@@ -200,7 +200,7 @@
**************************************************************************/
void mapctrl_btn_mapcanvas(XEvent *event)
{
- int x, y;
+ struct tile *ptile = canvas_pos_to_tile(ev->x, ev->y);
XButtonEvent *ev=&event->xbutton;
if (!can_client_change_view()) {
@@ -211,9 +211,8 @@
action_button_pressed(ev->x, ev->y, SELECT_SEA);
} else if (ev->button == Button1) {
action_button_pressed(ev->x, ev->y, SELECT_POPUP);
- } else if (ev->button == Button2 &&
- canvas_to_map_pos(&x, &y, ev->x, ev->y)) {
- popit(ev->x, ev->y, map_pos_to_tile(x, y));
+ } else if (ev->button == Button2 && ptile) {
+ popit(ev->x, ev->y, ptile);
} else if (ev->button == Button3 && (ev->state & ControlMask)) {
action_button_pressed(ev->x, ev->y, SELECT_LAND);
} else if (ev->button == Button3) {
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.181
diff -u -r1.181 mapview.c
--- client/gui-xaw/mapview.c 29 Sep 2004 02:24:22 -0000 1.181
+++ client/gui-xaw/mapview.c 29 Sep 2004 15:57:28 -0000
@@ -788,7 +788,7 @@
{
int canvas_x, canvas_y;
- if (map_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+ if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
pixmap_put_overlay_tile(XtWindow(map_canvas), canvas_x, canvas_y,
sprites.user.attention);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#10385) cleanups to canvas<->map pos,
Jason Short <=
|
|