Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4597) overview cleanup: new function get_mapview_corne
Home

[Freeciv-Dev] (PR#4597) overview cleanup: new function get_mapview_corne

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4597) overview cleanup: new function get_mapview_corners
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Jul 2003 13:51:15 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch introduces a new function get_mapview_corners() into 
mapview_common.  This function returns the overview positions of the 4 
corners of the mapview window.

It can be used by the GUI code to simplify drawing the mapview rectangle 
onto the overview minimap.  This cuts down the amount of GUI code needed 
by about 70% and makes future changes easier.

GTK and XAW clients are tested; Win32 and GTK-2.0 are supported but 
untested.  SDL and MUI don't use the overview coordinate system yet and 
are unsupported (they still use their own code for this).

jason

? rc
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.48
diff -u -r1.48 mapview_common.c
--- client/mapview_common.c     2003/07/17 16:36:56     1.48
+++ client/mapview_common.c     2003/07/17 20:45:59
@@ -1139,3 +1139,46 @@
   *map_x = map_adjust_x(overview_x / OVERVIEW_TILE_WIDTH + map_overview_x0);
   *map_y = overview_y / OVERVIEW_TILE_HEIGHT;
 }
+
+/**************************************************************************
+  Find the corners of the mapview, in overview coordinates.  Used to draw
+  the "mapview window" rectangle onto the overview.
+**************************************************************************/
+void get_mapview_corners(int x[4], int y[4])
+{
+  map_to_overview_pos(&x[0], &y[0],
+                     mapview_canvas.map_x0, mapview_canvas.map_y0);
+
+  if (is_isometric) {
+    /* We start with the west corner. */
+
+    /* North */
+    x[1] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_width;
+    y[1] = y[0] - OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_width;
+
+    /* East */
+    x[2] = x[1] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_height;
+    y[2] = y[1] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height;
+
+    /* South */
+    x[3] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_height;
+    y[3] = y[0] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height;
+  } else {
+    /* We start with the northwest corner. */
+
+    /* Northeast */
+    x[1] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_width - 1;
+    y[1] = y[0];
+
+    /* Southeast */
+    x[2] = x[1];
+    y[2] = y[0] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height - 1;
+
+    /* Southwest */
+    x[3] = x[0];
+    y[3] = y[2];
+  }
+
+  freelog(LOG_DEBUG, "(%d,%d)->(%d,%x)->(%d,%d)->(%d,%d)",
+         x[0], y[0], x[1], y[1], x[2], y[2], x[3], y[3]);
+}
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.31
diff -u -r1.31 mapview_common.h
--- client/mapview_common.h     2003/07/17 01:37:06     1.31
+++ client/mapview_common.h     2003/07/17 20:45:59
@@ -179,6 +179,8 @@
 void overview_to_map_pos(int *map_x, int *map_y,
                         int overview_x, int overview_y);
 
+void get_mapview_corners(int overview_x_array[4], int overview_y_array[4]);
+
 extern int map_overview_x0;
 
 #endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.172
diff -u -r1.172 mapview.c
--- client/gui-gtk/mapview.c    2003/07/17 01:37:06     1.172
+++ client/gui-gtk/mapview.c    2003/07/17 20:45:59
@@ -470,7 +470,7 @@
   int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
   int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
   int dy = OVERVIEW_TILE_HEIGHT * map.ysize;
-  int gui_x, gui_y;
+  int gui_x[4], gui_y[4], i;
 
   /* Copy the part of the overview to the right of map_overview_x0. */
   gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
@@ -480,46 +480,17 @@
   gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
                  0, 0, x1, 0, x0, dy);
 
-  /* Find the origin of the mapview, in overview (gui) coordinates. */
-  map_to_overview_pos(&gui_x, &gui_y,
-                     mapview_canvas.map_x0, mapview_canvas.map_y0);
+  /* Now draw the mapview window rectangle onto the overview. */
+  gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_WHITE]);
+  get_mapview_corners(gui_x, gui_y);
+  for (i = 0; i < 4; i++) {
+    int src_x = gui_x[i];
+    int src_y = gui_y[i];
+    int dest_x = gui_x[(i + 1) % 4];
+    int dest_y = gui_y[(i + 1) % 4];
 
-  gdk_gc_set_foreground( civ_gc, colors_standard[COLOR_STD_WHITE] );
-  
-  if (is_isometric) {
-    /* The x's and y's are in overview coordinates. */
-    int Wx = gui_x;
-    int Wy = gui_y;
-    int Nx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_twidth;
-    int Ny = Wy - OVERVIEW_TILE_HEIGHT * map_canvas_store_twidth;
-    int Sx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Sy = Wy + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    int Ex = Nx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Ey = Ny + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    
-    freelog(LOG_DEBUG, "wx,wy: %d,%d nx,ny:%d,%x ex,ey:%d,%d, sx,sy:%d,%d",
-           Wx, Wy, Nx, Ny, Ex, Ey, Sx, Sy);
-
-    /* W to N */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Wx, Wy, Nx, Ny);
-
-    /* N to E */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Nx, Ny, Ex, Ey);
-
-    /* E to S */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Ex, Ey, Sx, Sy);
-
-    /* S to W */
     gdk_draw_line(overview_canvas->window, civ_gc,
-                 Sx, Sy, Wx, Wy);
-  } else {
-    gdk_draw_rectangle(overview_canvas->window, civ_gc, FALSE,
-                      gui_x, gui_y,
-                      OVERVIEW_TILE_WIDTH * map_canvas_store_twidth,
-                      OVERVIEW_TILE_HEIGHT * map_canvas_store_theight - 1);
+                 src_x, src_y, dest_x, dest_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.65
diff -u -r1.65 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/07/17 01:37:07     1.65
+++ client/gui-gtk-2.0/mapview.c        2003/07/17 20:45:59
@@ -518,7 +518,7 @@
   int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
   int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
   int dy = OVERVIEW_TILE_HEIGHT * map.ysize;
-  int gui_x, gui_y;
+  int gui_x[4], gui_y[4];
 
   /* Copy the part of the overview to the right of map_overview_x0. */
   gdk_draw_drawable(overview_canvas->window, civ_gc, overview_canvas_store,
@@ -528,46 +528,17 @@
   gdk_draw_drawable(overview_canvas->window, civ_gc, overview_canvas_store,
                    0, 0, x1, 0, x0, dy);
 
-  /* Find the origin of the mapview, in overview (gui) coordinates. */
-  map_to_overview_pos(&gui_x, &gui_y,
-                     mapview_canvas.map_x0, mapview_canvas.map_y0);
+  /* Now draw the mapview window rectangle onto the overview. */
+  gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_WHITE]);
+  get_mapview_corners(gui_x, gui_y);
+  for (i = 0; i < 4; i++) {
+    int src_x = gui_x[i];
+    int src_y = gui_y[i];
+    int dest_x = gui_x[(i + 1) % 4];
+    int dest_y = gui_y[(i + 1) % 4];
 
-  gdk_gc_set_foreground( civ_gc, colors_standard[COLOR_STD_WHITE] );
-  
-  if (is_isometric) {
-    /* The x's and y's are in overview coordinates. */
-    int Wx = gui_x;
-    int Wy = gui_y;
-    int Nx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_twidth;
-    int Ny = Wy - OVERVIEW_TILE_HEIGHT * map_canvas_store_twidth;
-    int Sx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Sy = Wy + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    int Ex = Nx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Ey = Ny + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    
-    freelog(LOG_DEBUG, "wx,wy: %d,%d nx,ny:%d,%x ex,ey:%d,%d, sx,sy:%d,%d",
-           Wx, Wy, Nx, Ny, Ex, Ey, Sx, Sy);
-
-    /* W to N */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Wx, Wy, Nx, Ny);
-
-    /* N to E */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Nx, Ny, Ex, Ey);
-
-    /* E to S */
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 Ex, Ey, Sx, Sy);
-
-    /* S to W */
     gdk_draw_line(overview_canvas->window, civ_gc,
-                 Sx, Sy, Wx, Wy);
-  } else {
-    gdk_draw_rectangle(overview_canvas->window, civ_gc, FALSE,
-                      gui_x, gui_y,
-                      OVERVIEW_TILE_WIDTH * map_canvas_store_twidth,
-                      OVERVIEW_TILE_HEIGHT * map_canvas_store_theight - 1);
+                 src_x, src_y, dest_x, dest_y);
   }
 }
 
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.72
diff -u -r1.72 mapview.c
--- client/gui-win32/mapview.c  2003/07/17 01:37:07     1.72
+++ client/gui-win32/mapview.c  2003/07/17 20:45:59
@@ -910,7 +910,7 @@
   int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
   int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
   int dy = OVERVIEW_TILE_HEIGHT * map.ysize;
-  int gui_x, gui_y;
+  int gui_x[4], gui_y[4];
   HDC hdc = hdcp;
   HPEN oldpen;
 
@@ -924,33 +924,17 @@
   /* Copy the part of the overview to the left of map_overview_x0. */
   BitBlt(hdc, overview_win_x + x1, overview_win_y, x0, dy, 0, 0);
 
-  /* Find the origin of the mapview, in overview (gui) coordinates. */
-  map_to_overview_pos(&gui_x, &gui_y,
-                     mapview_canvas.map_x0, mapview_canvas.map_y0);
-
+  /* Now draw the mapview window rectangle onto the overview. */
   oldpen = SelectObject(hdc, pen_std[COLOR_STD_WHITE]);
-  if (is_isometric) {
-    int Wx = gui_x;
-    int Wy = gui_y;
-    int Nx = Wx + OVERVIEW_TILE_WIDTH * map_view_width;
-    int Ny = Wy - OVERVIEW_TILE_HEIGHT * map_view_width;
-    int Sx = Wx + OVERVIEW_TILE_WIDTH * map_view_height;
-    int Sy = Wy + OVERVIEW_TILE_HEIGHT * map_view_height;
-    int Ex = Nx + OVERVIEW_TILE_WIDTH * map_view_height;
-    int Ey = Ny + OVERVIEW_TILE_HEIGHT * map_view_height;
-    
-    freelog(LOG_DEBUG, "wx,wy: %d,%d nx,ny:%d,%x ex,ey:%d,%d, sx,sy:%d,%d",
-            Wx, Wy, Nx, Ny, Ex, Ey, Sx, Sy);
-    MoveToEx(hdc,Wx+overview_win_x,Wy+overview_win_y,NULL);
-    LineTo(hdc,Nx+overview_win_x,Ny+overview_win_y);
-    LineTo(hdc,Ex+overview_win_x,Ey+overview_win_y);
-    LineTo(hdc,Sx+overview_win_x,Sy+overview_win_y);
-    LineTo(hdc,Wx+overview_win_x,Wy+overview_win_y);
-  } else {
-    mydrawrect(hdc, overview_win_x + gui_x, overview_win_y + gui_y,
-              OVERVIEW_TILE_WIDTH * map_view_width,
-              OVERVIEW_TILE_HEIGHT * map_view_height);
+  get_mapview_corners(gui_x, gui_y);
+  MoveToEx(hdc, gui_x[0] + overview_win_x, gui_y[0] + overview_win_y, NULL);
+  for (i = 0; i < 4; i++) {
+    int dest_x = gui_x[(i + 1) % 4];
+    int dest_y = gui_y[(i + 1) % 4];
+
+    LineTo(hdc, dest_x + overview_win_x, dest_y + overview_win_y);
   }
+
   SelectObject(hdc,oldpen);
   if (!hdcp)
     ReleaseDC(root_window,hdc);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.138
diff -u -r1.138 mapview.c
--- client/gui-xaw/mapview.c    2003/07/17 01:37:07     1.138
+++ client/gui-xaw/mapview.c    2003/07/17 20:45:59
@@ -436,7 +436,7 @@
   int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
   int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
   int dy = OVERVIEW_TILE_HEIGHT * map.ysize;
-  int gui_x, gui_y;
+  int gui_x[4], gui_y[4];
 
   /* Copy the part of the overview to the right of map_overview_x0. */
   XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
@@ -446,46 +446,17 @@
   XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
            civ_gc, 0, 0, x0, dy, x1, 0);
 
-  /* Find the origin of the mapview, in overview (gui) coordinates. */
-  map_to_overview_pos(&gui_x, &gui_y,
-                     mapview_canvas.map_x0, mapview_canvas.map_y0);
-
+  /* Now draw the mapview window rectangle onto the overview. */
   XSetForeground(display, civ_gc, colors_standard[COLOR_STD_WHITE]);
-  
-  if (is_isometric) {
-    /* The x's and y's are in overview coordinates. */
-    int Wx = gui_x;
-    int Wy = gui_y;
-    int Nx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_twidth;
-    int Ny = Wy - OVERVIEW_TILE_HEIGHT * map_canvas_store_twidth;
-    int Sx = Wx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Sy = Wy + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    int Ex = Nx + OVERVIEW_TILE_WIDTH * map_canvas_store_theight;
-    int Ey = Ny + OVERVIEW_TILE_HEIGHT * map_canvas_store_theight;
-    
-    freelog(LOG_DEBUG, "wx,wy: %d,%d nx,ny:%d,%x ex,ey:%d,%d, sx,sy:%d,%d",
-           Wx, Wy, Nx, Ny, Ex, Ey, Sx, Sy);
-
-    /* W to N */
-    XDrawLine(display, XtWindow(overview_canvas), civ_gc,
-                 Wx, Wy, Nx, Ny);
-
-    /* N to E */
-    XDrawLine(display, XtWindow(overview_canvas), civ_gc,
-                 Nx, Ny, Ex, Ey);
-
-    /* E to S */
-    XDrawLine(display, XtWindow(overview_canvas), civ_gc,
-                 Ex, Ey, Sx, Sy);
+  get_mapview_corners(gui_x, gui_y);
+  for (i = 0; i < 4; i++) {
+    int src_x = gui_x[i];
+    int src_y = gui_y[i];
+    int dest_x = gui_x[(i + 1) % 4];
+    int dest_y = gui_y[(i + 1) % 4];
 
-    /* S to W */
     XDrawLine(display, XtWindow(overview_canvas), civ_gc,
-                 Sx, Sy, Wx, Wy);
-  } else {
-    XDrawRectangle(display, XtWindow(overview_canvas), civ_gc, 
-                  gui_x, gui_y,
-                  OVERVIEW_TILE_WIDTH * map_canvas_store_twidth,
-                  OVERVIEW_TILE_HEIGHT * map_canvas_store_theight - 1);
+             src_x, src_y, dest_x, dest_y);
   }
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4597) overview cleanup: new function get_mapview_corners, Jason Short <=