Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] (PR#2884) unification of center_tile_mapcanvas
Home

[Freeciv-Dev] (PR#2884) unification of center_tile_mapcanvas

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2884) unification of center_tile_mapcanvas
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Feb 2003 17:34:49 -0800
Reply-to: rt@xxxxxxxxxxxxxx

With the other changes that have happened in the meantime
(mapview_canvas struct and SDL buffer code), this patch is now much
simpler and more correct.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.33
diff -u -r1.33 mapview_common.c
--- client/mapview_common.c     2003/02/27 00:31:09     1.33
+++ client/mapview_common.c     2003/02/27 01:32:16
@@ -22,6 +22,7 @@
 #include "support.h"
 #include "timing.h"
 
+#include "mapctrl_g.h"
 #include "mapview_g.h"
 
 #include "climap.h"
@@ -335,43 +336,37 @@
 }
 
 /**************************************************************************
-  Centers the mapview around (map_x, map_y).  (map_view_x0,
-  map_view_y0) is the upper-left coordinates of the mapview; these
-  should be (but aren't) stored globally - each GUI has separate
-  storate structs for them.
+  Centers the mapview around (map_x, map_y).
 **************************************************************************/
-void base_center_tile_mapcanvas(int map_x, int map_y,
-                               int *map_view_topleft_map_x,
-                               int *map_view_topleft_map_y,
-                               int map_view_map_width,
-                               int map_view_map_height)
+void center_tile_mapcanvas(int map_x, int map_y)
 {
+  /* Find top-left corner. */
   if (is_isometric) {
-    map_x -= map_view_map_width / 2;
-    map_y += map_view_map_width / 2;
-    map_x -= map_view_map_height / 2;
-    map_y -= map_view_map_height / 2;
-
-    *map_view_topleft_map_x = map_adjust_x(map_x);
-    *map_view_topleft_map_y = map_adjust_y(map_y);
-
-    *map_view_topleft_map_y =
-       (*map_view_topleft_map_y >
-        map.ysize + EXTRA_BOTTOM_ROW - map_view_map_height) ? map.ysize +
-       EXTRA_BOTTOM_ROW - map_view_map_height : *map_view_topleft_map_y;
+    map_x -= mapview_canvas.tile_width / 2;
+    map_y += mapview_canvas.tile_width / 2;
+    map_x -= mapview_canvas.tile_height / 2;
+    map_y -= mapview_canvas.tile_height / 2;
   } else {
-    int new_map_view_x0, new_map_view_y0;
+    map_x -= mapview_canvas.tile_width / 2;
+    map_y -= mapview_canvas.tile_height / 2;
+  }
 
-    new_map_view_x0 = map_adjust_x(map_x - map_view_map_width / 2);
-    new_map_view_y0 = map_adjust_y(map_y - map_view_map_height / 2);
-    if (new_map_view_y0 >
-       map.ysize + EXTRA_BOTTOM_ROW - map_view_map_height) {
-      new_map_view_y0 =
-         map_adjust_y(map.ysize + EXTRA_BOTTOM_ROW - map_view_map_height);
-    }
+  /* Wrap. */
+  map_x = map_adjust_x(map_x);
 
-    *map_view_topleft_map_x = new_map_view_x0;
-    *map_view_topleft_map_y = new_map_view_y0;
+  /* Clip. */
+  map_y = map_adjust_y(map_y);
+  map_y = MIN(map_y,
+             map.ysize + EXTRA_BOTTOM_ROW - mapview_canvas.tile_height);
+
+  /* Now that we've determined the new origin, update everything. */
+  mapview_canvas.map_x0 = map_x;
+  mapview_canvas.map_y0 = map_y;
+  update_map_canvas_visible();
+  update_map_canvas_scrollbars();
+  refresh_overview_viewrect();
+  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL) {
+    create_line_at_mouse_pos();
   }
 }
 
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.25
diff -u -r1.25 mapview_common.h
--- client/mapview_common.h     2003/02/27 00:31:09     1.25
+++ client/mapview_common.h     2003/02/27 01:32:16
@@ -141,11 +141,7 @@
 void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
 
 void get_center_tile_mapcanvas(int *map_x, int *map_y);
-void base_center_tile_mapcanvas(int map_x, int map_y,
-                               int *map_view_topleft_map_x,
-                               int *map_view_topleft_map_y,
-                               int map_view_map_width,
-                               int map_view_map_height);
+void center_tile_mapcanvas(int map_x, int map_y);
 
 bool tile_visible_mapcanvas(int map_x, int map_y);
 bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.161
diff -u -r1.161 mapview.c
--- client/gui-gtk/mapview.c    2003/02/27 00:31:10     1.161
+++ client/gui-gtk/mapview.c    2003/02/27 01:32:18
@@ -393,24 +393,6 @@
 }
 
 /**************************************************************************
-Centers the mapview around (x, y).
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void center_tile_mapcanvas(int x, int y)
-{
-  base_center_tile_mapcanvas(x, y, &map_view_x0, &map_view_y0,
-                            map_canvas_store_twidth,
-                            map_canvas_store_theight);
-
-  update_map_canvas_visible();
-  update_map_canvas_scrollbars();
-  refresh_overview_viewrect();
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
-    create_line_at_mouse_pos();
-}
-
-/**************************************************************************
 ...
 **************************************************************************/
 void set_overview_dimensions(int x, int y)
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.49
diff -u -r1.49 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/02/27 00:31:10     1.49
+++ client/gui-gtk-2.0/mapview.c        2003/02/27 01:32:19
@@ -400,24 +400,6 @@
 }
 
 /**************************************************************************
-Centers the mapview around (x, y).
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void center_tile_mapcanvas(int x, int y)
-{
-  base_center_tile_mapcanvas(x, y, &map_view_x0, &map_view_y0,
-                            map_canvas_store_twidth,
-                            map_canvas_store_theight);
-
-  update_map_canvas_visible();
-  update_map_canvas_scrollbars();
-  refresh_overview_viewrect();
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
-    create_line_at_mouse_pos();
-}
-
-/**************************************************************************
 ...
 **************************************************************************/
 void set_overview_dimensions(int x, int y)
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.58
diff -u -r1.58 mapview.c
--- client/gui-mui/mapview.c    2003/02/04 23:12:31     1.58
+++ client/gui-mui/mapview.c    2003/02/27 01:32:20
@@ -391,26 +391,6 @@
 }
 
 /**************************************************************************
-Centers the mapview around (x, y).
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void center_tile_mapcanvas(int x, int y)
-{
-  int map_view_x0;
-  int map_view_y0;
-
-  base_center_tile_mapcanvas(x, y, &map_view_x0, &map_view_y0,
-                            get_map_x_visible(), get_map_y_visible());
-       set_map_xy_start(map_view_x0, map_view_y0);
-
-  update_map_canvas_visible();
-  refresh_overview_viewrect();
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
-    create_line_at_mouse_pos();
-}
-
-/**************************************************************************
 ...
 **************************************************************************/
 void refresh_overview_canvas(void)
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.30
diff -u -r1.30 mapview.c
--- client/gui-sdl/mapview.c    2003/02/27 00:31:10     1.30
+++ client/gui-sdl/mapview.c    2003/02/27 01:32:21
@@ -331,30 +331,6 @@
   return iRet;
 }
 
-
-/**************************************************************************
-  Centers the mapview around (col, row).
-  col,row are tile cordinate !
-
-  This function callculate:    map_view_x0 , map_view_y0,
-                               map_view_col0, map_view_row0.
-
-  then redraw all.
-**************************************************************************/
-void center_tile_mapcanvas(int col, int row)
-{
-  base_center_tile_mapcanvas(col, row, &map_view_x0, &map_view_y0,
-                            mapview_canvas.tile_width,
-                            mapview_canvas.tile_height);
-  
-  update_map_canvas_visible();
-  refresh_overview_viewrect();
-
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL) {
-    create_line_at_mouse_pos();
-  }
-}
-
 /* ===================================================================== */
 
 /**************************************************************************
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.29
diff -u -r1.29 mapview.c
--- client/gui-stub/mapview.c   2003/02/27 00:31:10     1.29
+++ client/gui-stub/mapview.c   2003/02/27 01:32:21
@@ -156,25 +156,6 @@
 }
 
 /**************************************************************************
-  Center the mapview around (map_x, map_y).
-
-  This function is almost identical between all GUIs.
-**************************************************************************/
-void center_tile_mapcanvas(int map_x, int map_y)
-{
-  base_center_tile_mapcanvas(map_x, map_y, &map_view_x0, &map_view_y0,
-                            mapview_tile_width, mapview_tile_height);
-
-  update_map_canvas_visible();
-  update_map_canvas_scrollbars();
-  refresh_overview_viewrect();
-
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL) {
-    create_line_at_mouse_pos();
-  }
-}
-
-/**************************************************************************
   Draw a description for the given city.  (canvas_x, canvas_y) is the
   canvas position of the city itself.
 **************************************************************************/
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.61
diff -u -r1.61 mapview.c
--- client/gui-win32/mapview.c  2003/02/27 00:31:10     1.61
+++ client/gui-win32/mapview.c  2003/02/27 01:32:23
@@ -502,22 +502,6 @@
 }
 
 /**************************************************************************
-Centers the mapview around (x, y).
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void center_tile_mapcanvas(int x, int y)
-{
-  base_center_tile_mapcanvas(x, y, &map_view_x, &map_view_y,
-                            map_view_width, map_view_height);
-
-  update_map_canvas_visible();
-  update_map_canvas_scrollbars();
-
-  refresh_overview_viewrect_real(NULL);
-}
-
-/**************************************************************************
   Flush the given part of the canvas buffer (if there is one) to the
   screen.
 **************************************************************************/
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.128
diff -u -r1.128 mapview.c
--- client/gui-xaw/mapview.c    2003/02/27 00:31:11     1.128
+++ client/gui-xaw/mapview.c    2003/02/27 01:32:24
@@ -374,23 +374,6 @@
 }
 
 /**************************************************************************
-Centers the mapview around (x, y).
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void center_tile_mapcanvas(int x, int y)
-{
-  base_center_tile_mapcanvas(x, y, &map_view_x0, &map_view_y0, 
map_canvas_store_twidth, map_canvas_store_theight);
-
-  update_map_canvas_visible();
-  update_map_canvas_scrollbars();
-  
-  refresh_overview_viewrect();
-  if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
-    create_line_at_mouse_pos();
-}
-
-/**************************************************************************
 ...
 **************************************************************************/
 void overview_canvas_expose(Widget w, XEvent *event, Region exposed, 
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.34
diff -u -r1.34 mapview_g.h
--- client/include/mapview_g.h  2003/02/27 00:31:11     1.34
+++ client/include/mapview_g.h  2003/02/27 01:32:26
@@ -34,8 +34,6 @@
 void set_overview_dimensions(int x, int y);
 void overview_update_tile(int x, int y);
 
-void center_tile_mapcanvas(int x, int y);
-
 void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
 void prepare_show_city_descriptions(void);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2884) unification of center_tile_mapcanvas, Jason Short <=