Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2338) moving get_map_xy/get_canvas_xy into mapview_com
Home

[Freeciv-Dev] (PR#2338) moving get_map_xy/get_canvas_xy into mapview_com

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2338) moving get_map_xy/get_canvas_xy into mapview_common
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 14 Nov 2002 13:35:25 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch moves the functions get_map_xy and get_canvas_xy into 
mapview_common.[ch].

There's not much to say about this.  The logic of the functions had 
already been moved via canvas_to_map_pos and map_to_canvas_pos 
functions.  This patch doesn't interfere with any of the naming, it 
simply moves the wrappers into mapview_common as well.  At some point in 
the future the wrappers should be removed and the clients should just 
call map_to_canvas_pos and canvas_to_map_pos.

jason

? client/gui-gtk/diff
? client/gui-stub/stub-update.diff
? client/gui-xaw/diff
Index: client//mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.12
diff -u -r1.12 mapview_common.c
--- client//mapview_common.c    2002/03/19 15:48:38     1.12
+++ client//mapview_common.c    2002/11/14 21:32:49
@@ -89,12 +89,12 @@
   in canvas_x,canvas_y it returns whether the tile is inside the
   visible map.
 **************************************************************************/
-bool map_pos_to_canvas_pos(int map_x, int map_y,
-                         int *canvas_x, int *canvas_y,
-                         int map_view_topleft_map_x,
-                         int map_view_topleft_map_y,
-                         int map_view_pixel_width,
-                         int map_view_pixel_height)
+static bool map_pos_to_canvas_pos(int map_x, int map_y,
+                                 int *canvas_x, int *canvas_y,
+                                 int map_view_topleft_map_x,
+                                 int map_view_topleft_map_y,
+                                 int map_view_pixel_width,
+                                 int map_view_pixel_height)
 {
   if (is_isometric) {
     /* For a simpler example of this math, see
@@ -181,10 +181,10 @@
 /**************************************************************************
   Finds the map coordinates corresponding to pixel coordinates.
 **************************************************************************/
-void canvas_pos_to_map_pos(int canvas_x, int canvas_y,
-                          int *map_x, int *map_y,
-                          int map_view_topleft_map_x,
-                          int map_view_topleft_map_y)
+static void canvas_pos_to_map_pos(int canvas_x, int canvas_y,
+                                 int *map_x, int *map_y,
+                                 int map_view_topleft_map_x,
+                                 int map_view_topleft_map_y)
 {
   if (is_isometric) {
     *map_x = map_view_topleft_map_x;
@@ -222,6 +222,35 @@
    */
   nearest_real_pos(map_x, map_y);
 }
+
+/**************************************************************************
+  Finds the pixel coordinates of a tile.  Beside setting the results in
+  canvas_x, canvas_y it returns whether the tile is inside the visible
+  map.
+**************************************************************************/
+int get_canvas_xy(int map_x, int map_y, int *canvas_x, int *canvas_y)
+{
+  int map_view_x0, map_view_y0, map_win_width, map_win_height;
+  get_mapview_dimensions(&map_view_x0, &map_view_y0,
+                        &map_win_width, &map_win_height);
+  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
+                              map_view_x0, map_view_y0,
+                              map_win_width, map_win_height);
+}
+
+/**************************************************************************
+  Finds the map coordinates corresponding to pixel coordinates.
+**************************************************************************/
+void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
+{
+  int map_view_x0, map_view_y0, map_win_width, map_win_height;
+  get_mapview_dimensions(&map_view_x0, &map_view_y0,
+                        &map_win_width, &map_win_height);
+  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y,
+                       map_view_x0, map_view_y0);
+}
+
+
 
 /**************************************************************************
   Centers the mapview around (map_x, map_y).  (map_view_x0,
Index: client//mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.7
diff -u -r1.7 mapview_common.h
--- client//mapview_common.h    2002/04/12 13:50:55     1.7
+++ client//mapview_common.h    2002/11/14 21:32:49
@@ -44,16 +44,8 @@
 void refresh_tile_mapcanvas(int x, int y, bool write_to_screen);
 enum color_std get_grid_color(int x1, int y1, int x2, int y2);
 
-bool map_pos_to_canvas_pos(int map_x, int map_y,
-                         int *canvas_x, int *canvas_y,
-                         int map_view_topleft_map_x,
-                         int map_view_topleft_map_y,
-                         int map_view_pixel_width,
-                         int map_view_pixel_height);
-void canvas_pos_to_map_pos(int canvas_x, int canvas_y,
-                          int *map_x, int *map_y,
-                          int map_view_topleft_map_x,
-                          int map_view_topleft_map_y);
+int get_canvas_xy(int map_x, int map_y, int *canvas_x, int *canvas_y);
+void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
 
 void base_center_tile_mapcanvas(int map_x, int map_y,
                                int *map_view_topleft_map_x,
Index: client//gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.129
diff -u -r1.129 mapview.c
--- client//gui-gtk/mapview.c   2002/11/14 09:45:17     1.129
+++ client//gui-gtk/mapview.c   2002/11/14 21:32:50
@@ -244,34 +244,6 @@
 }
 
 /**************************************************************************
-Finds the pixel coordinates of a tile.  Beside setting the results in
-canvas_x,canvas_y it returns whether the tile is inside the visible
-map.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-static int get_canvas_xy(int map_x, int map_y, int *canvas_x,
-                        int *canvas_y)
-{
-  int width, height;
-
-  gdk_window_get_size(map_canvas->window, &width, &height);
-  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
-                              map_view_x0, map_view_y0, width, height);
-}
-
-/**************************************************************************
-Finds the map coordinates corresponding to pixel coordinates.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
-{
-  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y, map_view_x0,
-                       map_view_y0);
-}
-
-/**************************************************************************
  This function is called to decrease a unit's HP smoothly in battle
  when combat_animation is turned on.
 **************************************************************************/
Index: client//gui-gtk/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.h,v
retrieving revision 1.12
diff -u -r1.12 mapview.h
--- client//gui-gtk/mapview.h   2001/10/30 12:11:44     1.12
+++ client//gui-gtk/mapview.h   2002/11/14 21:32:50
@@ -49,8 +49,6 @@
 void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar);
 void update_map_canvas_scrollbars_size(void);
 
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
-
 /* contains the x0, y0 coordinates of the upper left corner block */
 extern int map_view_x0, map_view_y0;
 
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.16
diff -u -r1.16 mapview.c
--- client//gui-gtk-2.0/mapview.c       2002/11/14 09:45:17     1.16
+++ client//gui-gtk-2.0/mapview.c       2002/11/14 21:32:51
@@ -243,34 +243,6 @@
 }
 
 /**************************************************************************
-Finds the pixel coordinates of a tile.  Beside setting the results in
-canvas_x,canvas_y it returns whether the tile is inside the visible
-map.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-static int get_canvas_xy(int map_x, int map_y, int *canvas_x,
-                        int *canvas_y)
-{
-  int width, height;
-
-  gdk_window_get_size(map_canvas->window, &width, &height);
-  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
-                              map_view_x0, map_view_y0, width, height);
-}
-
-/**************************************************************************
-Finds the map coordinates corresponding to pixel coordinates.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
-{
-  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y, map_view_x0,
-                       map_view_y0);
-}
-
-/**************************************************************************
  This function is called to decrease a unit's HP smoothly in battle
  when combat_animation is turned on.
 **************************************************************************/
Index: client//gui-gtk-2.0/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.h,v
retrieving revision 1.3
diff -u -r1.3 mapview.h
--- client//gui-gtk-2.0/mapview.h       2002/06/25 02:36:52     1.3
+++ client//gui-gtk-2.0/mapview.h       2002/11/14 21:32:52
@@ -51,8 +51,6 @@
 void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar);
 void update_map_canvas_scrollbars_size(void);
 
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
-
 /* contains the x0, y0 coordinates of the upper left corner block */
 extern int map_view_x0, map_view_y0;
 
Index: client//gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.43
diff -u -r1.43 mapview.c
--- client//gui-mui/mapview.c   2002/11/14 09:45:17     1.43
+++ client//gui-mui/mapview.c   2002/11/14 21:32:52
@@ -363,38 +363,6 @@
 }
 
 /**************************************************************************
-Finds the pixel coordinates of a tile.  Beside setting the results in
-canvas_x,canvas_y it returns whether the tile is inside the visible
-map.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-int get_canvas_xy(int map_x, int map_y, int *canvas_x, int *canvas_y)
-{
-  int map_view_x0 = xget(main_map_area, MUIA_Map_HorizFirst);
-  int map_view_y0 = xget(main_map_area, MUIA_Map_VertFirst);
-  int width = _mwidth(main_map_area);  /* !! */
-  int height = _mheight(main_map_area);        /* !! */
-
-  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
-                              map_view_x0, map_view_y0, width, height);
-}
-
-/**************************************************************************
-Finds the map coordinates corresponding to pixel coordinates.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
-{
-  int map_view_x0 = xget(main_map_area, MUIA_Map_HorizFirst);
-  int map_view_y0 = xget(main_map_area, MUIA_Map_VertFirst);
-
-  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y, map_view_x0,
-                       map_view_y0);
-}
-
-/**************************************************************************
  GUI Independ (with new access functions)
 **************************************************************************/
 bool tile_visible_mapcanvas(int x, int y)
Index: client//gui-mui/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.h,v
retrieving revision 1.4
diff -u -r1.4 mapview.h
--- client//gui-mui/mapview.h   2001/02/22 19:51:21     1.4
+++ client//gui-mui/mapview.h   2002/11/14 21:32:52
@@ -19,7 +19,4 @@
 
 void create_line_at_mouse_pos(void);
 
-int get_canvas_xy(int map_x, int map_y, int *canvas_x, int *canvas_y);
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
-
 #endif  /* FC__MAPVIEW_H */
Index: client//gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.31
diff -u -r1.31 mapview.c
--- client//gui-win32/mapview.c 2002/11/14 09:45:18     1.31
+++ client//gui-win32/mapview.c 2002/11/14 21:32:53
@@ -91,7 +91,6 @@
 static void show_city_descriptions(HDC hdc);     
 void refresh_overview_viewrect_real(HDC hdcp);
 void set_overview_win_dim(int w,int h);
-static int get_canvas_xy(int map_x, int map_y, int *canvas_x, int *canvas_y);
 static void put_one_tile(HDC mapstoredc,int x, int y, enum draw_type draw);
 void put_one_tile_full(HDC hdc, int x, int y,
                              int canvas_x, int canvas_y, int citymode);
@@ -1474,33 +1473,6 @@
         map_view_y;
   update_map_canvas_visible();
   refresh_overview_viewrect();
-}
-
-/**************************************************************************
-Finds the pixel coordinates of a tile.  Beside setting the results in
-canvas_x,canvas_y it returns whether the tile is inside the visible
-map.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-static int get_canvas_xy(int map_x, int map_y, int *canvas_x,
-                        int *canvas_y)
-{
-  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
-                              map_view_x, map_view_y, map_win_width,
-                              map_win_height);
-}
-
-
-/**************************************************************************
-Finds the map coordinates corresponding to pixel coordinates.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
-{
-  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y, map_view_x,
-                       map_view_y);
 }
 
 /**************************************************************************
Index: client//gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.3
diff -u -r1.3 mapview.h
--- client//gui-win32/mapview.h 2002/04/02 19:29:12     1.3
+++ client//gui-win32/mapview.h 2002/11/14 21:32:53
@@ -22,7 +22,6 @@
 void put_unit_pixmap(struct unit *punit, HDC hdc,int x,int y);
 void pixmap_frame_tile_red(HDC hdc, int x, int y);
 void put_unit_city_overlays(struct unit *punit, HDC hdc, int x, int y);
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
 void put_one_tile_full(HDC hdc, int x, int y,
                       int canvas_x, int canvas_y, int citymode);
 void check_mapstore();
Index: client//gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.101
diff -u -r1.101 mapview.c
--- client//gui-xaw/mapview.c   2002/11/14 09:45:18     1.101
+++ client//gui-xaw/mapview.c   2002/11/14 21:32:53
@@ -82,34 +82,6 @@
 }
 
 /**************************************************************************
-Finds the pixel coordinates of a tile.  Beside setting the results in
-canvas_x,canvas_y it returns whether the tile is inside the visible map.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-static int get_canvas_xy(int map_x, int map_y, int *canvas_x,
-                        int *canvas_y)
-{
-  Dimension width, height;
-
-  XtVaGetValues(map_canvas, XtNwidth, &width, XtNheight, &height, NULL);
-
-  return map_pos_to_canvas_pos(map_x, map_y, canvas_x, canvas_y,
-                              map_view_x0, map_view_y0, width, height);
-}
-
-/**************************************************************************
-Finds the map coordinates corresponding to pixel coordinates.
-
-This function is almost identical between all GUI's.
-**************************************************************************/
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y)
-{
-  canvas_pos_to_map_pos(canvas_x, canvas_y, map_x, map_y, map_view_x0,
-                       map_view_y0);
-}
-
-/**************************************************************************
  This function is called to decrease a unit's HP smoothly in battle
  when combat_animation is turned on.
 **************************************************************************/
Index: client//gui-xaw/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.h,v
retrieving revision 1.10
diff -u -r1.10 mapview.h
--- client//gui-xaw/mapview.h   2001/01/30 23:38:54     1.10
+++ client//gui-xaw/mapview.h   2002/11/14 21:32:53
@@ -25,7 +25,6 @@
 Pixmap get_thumb_pixmap(int onoff);
 Pixmap get_citizen_pixmap(int frame);
 
-void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y);
 void put_unit_pixmap(struct unit *punit, Pixmap pm,
                     int canvas_x, int canvas_y);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2338) moving get_map_xy/get_canvas_xy into mapview_common, Jason Short via RT <=