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

[Freeciv-Dev] (PR#2874) unification of put_one_tile_iso

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2874) unification of put_one_tile_iso
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 21 Jan 2003 17:35:37 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch moves the code of the function put_one_tile_iso into 
mapview_common.  It removes this as a GUI function and adds two new GUI 
functions in its place.

Although this doesn't decrease the quantity of code all that much, it is 
an important step in moving the drawing logic into the client-common code.

It is tested under all GUIs other than gui-mui.

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 01:29:03
@@ -403,9 +403,51 @@
   int canvas_x, canvas_y;
 
   if (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)) {
+    int height, width, height_unit;
+    int offset_x, offset_y, offset_y_unit;
+
     freelog(LOG_DEBUG, "putting (%d,%d) at (%d,%d), draw %x",
            map_x, map_y, canvas_x, canvas_y, draw);
-    put_one_tile_iso(map_x, map_y, canvas_x, canvas_y, draw);
+
+    width = (draw & D_TMB_L) && (draw & D_TMB_R)
+           ? NORMAL_TILE_WIDTH : NORMAL_TILE_WIDTH / 2;
+    if (!(draw & D_TMB_L)) {
+      offset_x = NORMAL_TILE_WIDTH / 2;
+    } else {
+      offset_x = 0;
+    }
+
+    height = 0;
+    if (draw & D_M_LR) {
+      height += NORMAL_TILE_HEIGHT / 2;
+    }
+    if (draw & D_B_LR) {
+      height += NORMAL_TILE_HEIGHT / 2;
+    }
+    if (draw & D_T_LR) {
+      height_unit = height + NORMAL_TILE_HEIGHT / 2;
+    } else {
+      height_unit = height;
+    }
+
+    offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT / 2;
+    if (!(draw & D_T_LR)) {
+      offset_y_unit = (draw & D_M_LR)
+             ? NORMAL_TILE_HEIGHT / 2 : NORMAL_TILE_HEIGHT;
+    } else {
+      offset_y_unit = 0;
+    }
+
+    if (normalize_map_pos(&map_x, &map_y)) {
+      mapview_put_tile_iso(map_x, map_y, canvas_x, canvas_y,
+                          offset_x, offset_y, offset_y_unit,
+                          width, height, height_unit,
+                          draw);
+    } else {
+      mapview_put_black_tile_iso(canvas_x, canvas_y,
+                                offset_x, offset_y,
+                                width, height);
+    }
   }
 }
 
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 01:29:04
@@ -892,45 +892,31 @@
 }
 
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view.
+  Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int x, int y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
 {
-  int height, width, height_unit;
-  int offset_x, offset_y, offset_y_unit;
+  pixmap_put_tile_iso(map_canvas_store,
+                     map_x, map_y, canvas_x, canvas_y,
+                     FALSE,
+                     offset_x, offset_y, offset_y_unit,
+                     width, height, height_unit, draw);
+}
 
-  width = (draw & D_TMB_L) && (draw & D_TMB_R) ? NORMAL_TILE_WIDTH : 
NORMAL_TILE_WIDTH/2;
-  if (!(draw & D_TMB_L))
-    offset_x = NORMAL_TILE_WIDTH/2;
-  else
-    offset_x = 0;
-
-  height = 0;
-  if (draw & D_M_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_B_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_T_LR)
-    height_unit = height + NORMAL_TILE_HEIGHT/2;
-  else
-    height_unit = height;
-
-  offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT/2;
-  if (!(draw & D_T_LR))
-    offset_y_unit = (draw & D_M_LR) ? NORMAL_TILE_HEIGHT/2 : 
NORMAL_TILE_HEIGHT;
-  else
-    offset_y_unit = 0;
-
-  if (normalize_map_pos(&x, &y)) {
-    pixmap_put_tile_iso(map_canvas_store, x, y, canvas_x, canvas_y, 0,
-                       offset_x, offset_y, offset_y_unit,
-                       width, height, height_unit,
-                       draw);
-  } else {
-    pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
-                             offset_x, offset_y,
-                             width, height);
-  }
+/**************************************************************************
+  Draw some or all of a black tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
+{
+  pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
+                           offset_x, offset_y,
+                           width, height);     
 }
 
 /**************************************************************************
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 01:29:05
@@ -921,45 +921,31 @@
 }
 
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view.
+  Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int x, int y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
 {
-  int height, width, height_unit;
-  int offset_x, offset_y, offset_y_unit;
+  pixmap_put_tile_iso(map_canvas_store,
+                     map_x, map_y, canvas_x, canvas_y,
+                     FALSE,
+                     offset_x, offset_y, offset_y_unit,
+                     width, height, height_unit, draw);
+}
 
-  width = (draw & D_TMB_L) && (draw & D_TMB_R) ? NORMAL_TILE_WIDTH : 
NORMAL_TILE_WIDTH/2;
-  if (!(draw & D_TMB_L))
-    offset_x = NORMAL_TILE_WIDTH/2;
-  else
-    offset_x = 0;
-
-  height = 0;
-  if (draw & D_M_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_B_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_T_LR)
-    height_unit = height + NORMAL_TILE_HEIGHT/2;
-  else
-    height_unit = height;
-
-  offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT/2;
-  if (!(draw & D_T_LR))
-    offset_y_unit = (draw & D_M_LR) ? NORMAL_TILE_HEIGHT/2 : 
NORMAL_TILE_HEIGHT;
-  else
-    offset_y_unit = 0;
-
-  if (normalize_map_pos(&x, &y)) {
-    pixmap_put_tile_iso(map_canvas_store, x, y, canvas_x, canvas_y, 0,
-                       offset_x, offset_y, offset_y_unit,
-                       width, height, height_unit,
-                       draw);
-  } else {
-    pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
-                             offset_x, offset_y,
-                             width, height);
-  }
+/**************************************************************************
+  Draw some or all of a black tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
+{
+  pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
+                           offset_x, offset_y,
+                           width, height);     
 }
 
 /**************************************************************************
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 01:29:06
@@ -170,70 +170,43 @@
 }
 
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view use with unification of update_mapcanvas(...).
+  Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int x, int y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
 {
-  SDL_Rect dest;       
-  int height, width;
-  int offset_x, offset_y;
+  if (draw == D_MB_LR || draw == D_FULL) {
+    draw_map_cell(Main.screen, canvas_x, canvas_y,
+                 (Uint16)map_x, (Uint16)map_y, 0);
+  } else {
+    SDL_Rect dest;
 
-/*
-  if (!tile_visible_mapcanvas(x, y)) {
-    freelog(LOG_DEBUG, "dropping %d,%d", x, y);
-    return;
-  }
-*/
-       
-  if (!normalize_map_pos(&x, &y)) {
-    blit_entire_src( (SDL_Surface *)sprites.black_tile ,
-                       Main.screen , canvas_x , canvas_y );
-    return;  
-  }
+    dest.x = canvas_x + offset_x;
+    dest.y = canvas_y + offset_y;
+    dest.w = width;
+    dest.h = height;
+    SDL_SetClipRect(Main.screen, &dest);
   
-  freelog(LOG_DEBUG, "putting %d,%d draw %x", x, y, draw);
-
-  if ( draw == D_MB_LR || draw == D_FULL )
-  {
     draw_map_cell(Main.screen, canvas_x, canvas_y,
-                         (Uint16)x, (Uint16)y, 0);
-    
-    return;
-  }
-  
-  width = (draw & D_TMB_L) && (draw & D_TMB_R)
-        ? NORMAL_TILE_WIDTH : NORMAL_TILE_WIDTH>>1;
+                 (Uint16)map_x, (Uint16)map_y, 0);
   
-  if (!(draw & D_TMB_L))
-    offset_x = NORMAL_TILE_WIDTH>>1;
-  else
-    offset_x = 0;
+    /* clear ClipRect */
+    SDL_SetClipRect(Main.screen, NULL);
+  }
+}
 
-  height = 0;
-  if (draw & D_M_LR) height += (NORMAL_TILE_HEIGHT>>1);
-  if (draw & D_B_LR) height += (NORMAL_TILE_HEIGHT>>1);
-  if (draw & D_T_LR) height += (NORMAL_TILE_HEIGHT>>1);
-         
-  if ((draw & D_T_LR))
-    offset_y = - (NORMAL_TILE_HEIGHT>>1);
-  else
-    offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT>>1;
-  
-  dest.x = canvas_x + offset_x;
-  dest.y = canvas_y + offset_y;
-  dest.w = width;
-  dest.h = height;
-  SDL_SetClipRect(Main.screen, &dest);
-  
-  draw_map_cell(Main.screen, canvas_x, canvas_y,
-                         (Uint16)x, (Uint16)y, 0 );
-  
-  /* clear ClipRect */
-  SDL_SetClipRect(Main.screen, NULL);
- 
-  return;
+/**************************************************************************
+  Draw some or all of a black tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
+{
+  blit_entire_src((SDL_Surface *)sprites.black_tile,
+                 Main.screen, canvas_x, canvas_y);
 }
 
 void flush_mapcanvas( int canvas_x , int canvas_y ,
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 01:29:06
@@ -193,11 +193,23 @@
 }
 
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view.
+  Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int map_x, int map_y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
+{
+  /* PORTME */
+}
+
+/**************************************************************************
+  Draw some or all of a black tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
 {
   /* PORTME */
 }
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 01:29:07
@@ -1325,54 +1325,48 @@
                       D_FULL);
 }
 
+/**************************************************************************
+  Draw some or all of a tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
+{
+  HDC hdc;
+  HBITMAP old;
 
+  /* FIXME: we don't want to have to recreate the hdc each time! */
+  hdc = CreateCompatibleDC(NULL);
+  old = SelectObject(hdc, mapstorebitmap);
+
+  pixmap_put_tile_iso(hdc, map_x, map_y, canvas_x, canvas_y, 0,
+                     offset_x, offset_y, offset_y_unit,
+                     width, height, height_unit,
+                     draw);
 
+  SelectObject(hdc, old);
+  DeleteDC(hdc);
+}
+
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view.
+  Draw some or all of a black tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int x, int y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
 {
   HDC hdc;
   HBITMAP old;
-  int height, width, height_unit;
-  int offset_x, offset_y, offset_y_unit;
 
   /* FIXME: we don't want to have to recreate the hdc each time! */
   hdc = CreateCompatibleDC(NULL);
   old = SelectObject(hdc, mapstorebitmap);
-  
-  width = (draw & D_TMB_L) && (draw & D_TMB_R) ? NORMAL_TILE_WIDTH : 
NORMAL_TILE_WIDTH/2;
-  if (!(draw & D_TMB_L))
-    offset_x = NORMAL_TILE_WIDTH/2;
-  else
-    offset_x = 0;
-  
-  height = 0;
-  if (draw & D_M_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_B_LR) height += NORMAL_TILE_HEIGHT/2;
-  if (draw & D_T_LR)
-    height_unit = height + NORMAL_TILE_HEIGHT/2;
-  else
-    height_unit = height;
-
-  offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT/2;
-  if (!(draw & D_T_LR))
-    offset_y_unit = (draw & D_M_LR) ? NORMAL_TILE_HEIGHT/2 : 
NORMAL_TILE_HEIGHT;
-  else
-    offset_y_unit = 0;
-
-  if (normalize_map_pos(&x, &y)) {
-    pixmap_put_tile_iso(hdc, x, y, canvas_x, canvas_y, 0,
-                       offset_x, offset_y, offset_y_unit,
-                       width, height, height_unit,
-                       draw);
-  } else {
-    pixmap_put_black_tile_iso(hdc, canvas_x, canvas_y,
-                             offset_x, offset_y,
-                             width, height);
-  }
+
+  pixmap_put_black_tile_iso(hdc, canvas_x, canvas_y,
+                           offset_x, offset_y,
+                           width, height);
 
   SelectObject(hdc, old);
   DeleteDC(hdc);
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 01:29:07
@@ -608,11 +608,24 @@
 }
 
 /**************************************************************************
-  Draw the given map tile at the given canvas position in isometric
-  view.
+  Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
-void put_one_tile_iso(int map_x, int map_y, int canvas_x, int canvas_y,
-                     enum draw_type draw)
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw)
+{
+  /* PORTME */
+  assert(0);
+}
+
+/**************************************************************************
+  Draw some or all of a black tile onto the mapview canvas.
+**************************************************************************/
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height)
 {
   /* PORTME */
   assert(0);
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 01:29:07
@@ -39,8 +39,14 @@
 void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
 
 void put_one_tile(int map_x, int map_y, int canvas_x, int canvas_y);
-void put_one_tile_iso(int map_x, int map_y, int canvas_x, int canvas_y,
-                     enum draw_type draw);
+void mapview_put_tile_iso(int map_x, int map_y,
+                         int canvas_x, int canvas_y,
+                         int offset_x, int offset_y, int offset_y_unit,
+                         int width, int height, int height_unit,
+                         enum draw_type draw);
+void mapview_put_black_tile_iso(int canvas_x, int canvas_y,
+                               int offset_x, int offset_y,
+                               int width, int height);
 void flush_mapcanvas(int canvas_x, int canvas_y,
                     int pixel_width, int pixel_height);
 

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