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

[Freeciv-Dev] Re: (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] Re: (PR#2884) unification of center_tile_mapcanvas
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Wed, 22 Jan 2003 15:48:20 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short via RT wrote:
> This patch moves center_tile_mapcanvas into mapview_common.  In the 
> process some of the code is cleaned up a little, and I added a check to 
> avoid recentering when the center doesn't change.
> 
> It will break gui-sdl unless PR#2868 is used or a "proper" fix for the 
> buffering problem is addressed.

Patch attached.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.24
diff -u -r1.24 mapview_common.c
--- client/mapview_common.c     2003/01/17 20:20:56     1.24
+++ client/mapview_common.c     2003/01/22 22:25:36
@@ -22,6 +22,7 @@
 #include "support.h"
 #include "timing.h"
 
+#include "mapctrl_g.h"
 #include "mapview_g.h"
 
 #include "control.h"
@@ -278,43 +279,48 @@
 }
 
 /**************************************************************************
-  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)
 {
+  int old_mapview_x0, old_mapview_y0;
+  int mapview_canvas_width, mapview_canvas_height;
+  int mapview_tile_width, mapview_tile_height;
+
+  /* First, determine the mapview origin from the center tile. */
+  get_mapview_dimensions(&old_mapview_x0, &old_mapview_y0,
+                        &mapview_canvas_width, &mapview_canvas_height);
+  mapview_tile_width = (mapview_canvas_width - 1) / NORMAL_TILE_WIDTH + 1;
+  mapview_tile_height = (mapview_canvas_height - 1) / NORMAL_TILE_HEIGHT + 1;
+
   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_tile_width / 2;
+    map_y += mapview_tile_width / 2;
+    map_x -= mapview_tile_height / 2;
+    map_y -= mapview_tile_height / 2;
+
   } else {
-    int new_map_view_x0, new_map_view_y0;
+    map_x -= mapview_tile_width / 2;
+    map_y -= mapview_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 and clip the mapview (this will only work under the standard
+   * topology). */
+  nearest_real_pos(&map_x, &map_y);
+  map_y = MIN(map_y, map.ysize + EXTRA_BOTTOM_ROW - mapview_tile_height);
+
+  if (map_x == old_mapview_x0 && map_y == old_mapview_y0) {
+    /* The origin hasn't changed; no need to do more. */
+    return;
+  }
+
+  set_mapview_origin(map_x, map_y);
 
-    *map_view_topleft_map_x = new_map_view_x0;
-    *map_view_topleft_map_y = new_map_view_y0;
+  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/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.149
diff -u -r1.149 mapview.c
--- client/gui-gtk/mapview.c    2003/01/17 20:20:56     1.149
+++ client/gui-gtk/mapview.c    2003/01/22 22:25:37
@@ -109,6 +109,17 @@
                      map_view_pixel_height);
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -504,24 +515,6 @@
 
   /* Flush. */
   gdk_flush();
-}
-
-/**************************************************************************
-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();
 }
 
 /**************************************************************************
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.37
diff -u -r1.37 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/01/17 20:20:56     1.37
+++ client/gui-gtk-2.0/mapview.c        2003/01/22 22:25:38
@@ -108,6 +108,17 @@
                      map_view_pixel_width, map_view_pixel_height);
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -510,24 +521,6 @@
 
   /* Flush. */
   gdk_flush();
-}
-
-/**************************************************************************
-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();
 }
 
 /**************************************************************************
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.57
diff -u -r1.57 mapview.c
--- client/gui-mui/mapview.c    2003/01/18 18:58:26     1.57
+++ client/gui-mui/mapview.c    2003/01/22 22:25:38
@@ -94,6 +94,16 @@
   *map_view_pixel_height = _mheight(main_map_area);    /* !! */
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  set_map_xy_start(map_view_topleft_map_x, map_view_topleft_map_y);
+}
+
 /**************************************************************************
  This function is called to decrease a unit's HP smoothly in battle
  when combat_animation is turned on.
@@ -388,26 +398,6 @@
           MUIA_Map_HorizFirst, new_map_view_x0,
           MUIA_Map_VertFirst, new_map_view_y0,
           TAG_DONE);
-}
-
-/**************************************************************************
-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();
 }
 
 /**************************************************************************
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.9
diff -u -r1.9 mapview.c
--- client/gui-sdl/mapview.c    2003/01/19 11:39:47     1.9
+++ client/gui-sdl/mapview.c    2003/01/22 22:25:39
@@ -160,6 +160,17 @@
   *map_view_pixel_height = Main.screen->h;
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 
 /**************************************************************************
   Draw the given map tile at the given canvas position in no-isometric
@@ -300,52 +311,6 @@
   return (*pX > -NORMAL_TILE_WIDTH && *pX < pDest->w + NORMAL_TILE_WIDTH
          && *pY > -NORMAL_TILE_HEIGHT
          && *pY < pDest->h + NORMAL_TILE_HEIGHT);
-}
-
-/**************************************************************************
-  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)
-{
-  
-    int ww = ( Main.screen->w - 1 ) / NORMAL_TILE_WIDTH + 1;
-    int hh = ( Main.screen->h - 1 ) / NORMAL_TILE_HEIGHT + 1;
-  
-#ifdef DRAW_TIMING
-  struct timer *ttt=new_timer_start(TIMER_USER,TIMER_ACTIVE);
-#endif   
-       
-    refresh_rects();   
-       
-    base_center_tile_mapcanvas( col , row, &map_view_x0 , &map_view_y0 ,
-                                       ww , hh );
-
-  
-    SDL_FillRect( Main.screen, NULL , 0x0 );
-  
-    update_map_canvas_visible();
-  
-    redraw_map_widgets();
-  
-#ifdef DRAW_TIMING
-  freelog(LOG_NORMAL, "redraw_map = %fms\n",
-         1000.0 * read_timer_seconds_free(ttt));
-#endif
-  
-    refresh_fullscreen();
-
-  /*update_map_canvas_scrollbars(); */
-  /*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.24
diff -u -r1.24 mapview.c
--- client/gui-stub/mapview.c   2003/01/17 20:20:56     1.24
+++ client/gui-stub/mapview.c   2003/01/22 22:25:39
@@ -48,6 +48,18 @@
   *map_view_pixel_height = canvas_height;
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  /* PORTME */
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 /**************************************************************************
   Typically an info box is provided to tell the player about the state
   of their civilization.  This function is called when the label is
@@ -153,25 +165,6 @@
 void overview_update_tile(int map_x, int map_y)
 {
   /* PORTME */
-}
-
-/**************************************************************************
-  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();
-  }
 }
 
 /**************************************************************************
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.51
diff -u -r1.51 mapview.c
--- client/gui-win32/mapview.c  2003/01/17 20:20:56     1.51
+++ client/gui-win32/mapview.c  2003/01/22 22:25:40
@@ -101,6 +101,17 @@
   *map_view_pixel_height = map_win_height;
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 /**************************************************************************
 
 **************************************************************************/
@@ -616,22 +627,6 @@
   rc.bottom=rc.top+2;
   FillRect(hdc,&rc,brush_std[overview_tile_color(x,y)]);
   ReleaseDC(root_window,hdc);
-}
-
-/**************************************************************************
-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);
 }
 
 /**************************************************************************
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.118
diff -u -r1.118 mapview.c
--- client/gui-xaw/mapview.c    2003/01/17 20:20:57     1.118
+++ client/gui-xaw/mapview.c    2003/01/22 22:25:40
@@ -83,6 +83,17 @@
   *map_view_pixel_height = (Dimension)height;
 }
 
+/***********************************************************************
+  This function can be used by mapview_common code to set the location
+  of the map canvas.
+***********************************************************************/
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y)
+{
+  map_view_x0 = map_view_topleft_map_x;
+  map_view_y0 = map_view_topleft_map_y;
+}
+
 /**************************************************************************
  This function is called to decrease a unit's HP smoothly in battle
  when combat_animation is turned on.
@@ -372,23 +383,6 @@
 
   /* Flush. */
   XSync(display, 0);
-}
-
-/**************************************************************************
-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();
 }
 
 /**************************************************************************
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.29
diff -u -r1.29 mapview_g.h
--- client/include/mapview_g.h  2003/01/17 20:20:57     1.29
+++ client/include/mapview_g.h  2003/01/22 22:25:40
@@ -23,6 +23,8 @@
                            int *map_view_topleft_map_y,
                            int *map_view_pixel_width,
                            int *map_view_pixel_height);
+void set_mapview_origin(int map_view_topleft_map_x,
+                       int map_view_topleft_map_y);
 
 void update_info_label(void);
 void update_unit_info_label(struct unit *punit);

[Prev in Thread] Current Thread [Next in Thread]