Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] (PR#4831) drawn sprite support for gui-win32
Home

[Freeciv-Dev] (PR#4831) drawn sprite support for gui-win32

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4831) drawn sprite support for gui-win32
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Aug 2003 12:09:17 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch aims to make gui-win32 work with the new drawn_sprite 
structures.  I have no way to test it.  It includes PR#4601.

jason

Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.61
diff -u -r1.61 citydlg.c
--- client/gui-win32/citydlg.c  2003/08/06 07:22:44     1.61
+++ client/gui-win32/citydlg.c  2003/08/12 19:06:57
@@ -294,6 +294,8 @@
   struct unit_list *plist;
   struct genlist_iterator myiter;
   struct unit *punit;
+  struct canvas_store store = {hdc, NULL};
+
   if(unitid) {
     for(i=0; i<NUM_UNITS_SHOWN; i++)
       if(pdialog->present_unit_ids[i]==unitid)
@@ -322,9 +324,9 @@
       rc.right=rc.left+NORMAL_TILE_WIDTH;
       rc.bottom=rc.top+SMALL_TILE_HEIGHT+NORMAL_TILE_HEIGHT;
       
FillRect(hdc,&rc,(HBRUSH)GetClassLong(pdialog->mainwindow,GCL_HBRBACKGROUND));
-      put_unit_pixmap(punit,hdc,
-                     pdialog->pop_x+i*(SMALL_TILE_WIDTH+NORMAL_TILE_WIDTH),
-                     pdialog->present_y); 
+      put_unit(punit, &store,
+              pdialog->pop_x + i * (SMALL_TILE_WIDTH + NORMAL_TILE_WIDTH),
+              pdialog->present_y);
       pdialog->present_unit_ids[i]=punit->id;       
       
     }
@@ -350,6 +352,8 @@
   struct unit_list *plist;
   struct genlist_iterator myiter;
   struct unit *punit;    
+  struct canvas_store store = {hdc, NULL};
+
   if(unitid) {
     for(i=0; i<NUM_UNITS_SHOWN; i++)
       if(pdialog->support_unit_ids[i]==unitid)
@@ -375,9 +379,9 @@
       rc.right=rc.left+NORMAL_TILE_WIDTH;
       rc.bottom=rc.top+SMALL_TILE_HEIGHT+NORMAL_TILE_HEIGHT;
       
FillRect(hdc,&rc,(HBRUSH)GetClassLong(pdialog->mainwindow,GCL_HBRBACKGROUND));
-      put_unit_pixmap(punit,hdc,
-                     pdialog->pop_x+i*(SMALL_TILE_WIDTH+NORMAL_TILE_WIDTH),
-                     pdialog->supported_y);
+      put_unit(punit, &store,
+              pdialog->pop_x + i * (SMALL_TILE_WIDTH + NORMAL_TILE_WIDTH),
+              pdialog->supported_y);
       put_unit_city_overlays(punit,hdc,
                      pdialog->pop_x+i*(SMALL_TILE_WIDTH+NORMAL_TILE_WIDTH),
                      pdialog->supported_y);
Index: client/gui-win32/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v
retrieving revision 1.36
diff -u -r1.36 dialogs.c
--- client/gui-win32/dialogs.c  2003/08/04 15:42:47     1.36
+++ client/gui-win32/dialogs.c  2003/08/12 19:06:57
@@ -775,6 +775,8 @@
       struct unit *punit=unit_list_get(&ptile->units, i);
       struct unit_type *punittemp=unit_type(punit);
       struct city *pcity;
+      struct canvas_store store = {unitsel_dc, NULL};
+
       pcity=player_find_city_by_id(game.player_ptr, punit->homecity);
       my_snprintf(buffer, sizeof(buffer), "%s(%s)\n%s",
                  punittemp->name,
@@ -793,7 +795,7 @@
       SelectObject(unitsel_dc,unit_select_bitmaps[i]);
       BitBlt(unitsel_dc,0,0,UNIT_TILE_WIDTH,UNIT_TILE_HEIGHT,NULL,
             0,0,WHITENESS);
-      put_unit_pixmap(punit,unitsel_dc,0,0);
+      put_unit(punit, &store, 0, 0);
       SelectObject(unitsel_dc,old);
       unit_select_but[i]=CreateWindow("BUTTON",NULL,
                                      WS_CHILD | WS_VISIBLE | BS_BITMAP,
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.78
diff -u -r1.78 mapview.c
--- client/gui-win32/mapview.c  2003/08/06 16:10:08     1.78
+++ client/gui-win32/mapview.c  2003/08/12 19:06:57
@@ -173,50 +173,6 @@
 /**************************************************************************
 
 **************************************************************************/
-void put_unit_pixmap(struct unit *punit, HDC hdc,int canvas_x,int canvas_y)
-{
-  bool solid_bg;
-
-  if (is_isometric) {
-    struct Sprite *sprites[40];        
-    int count = fill_unit_sprite_array(sprites, punit,&solid_bg);        
-    int i;
-  
-    assert(!solid_bg);
-    for (i=0; i<count; i++) {
-      if (sprites[i]) {
-       draw_sprite(sprites[i],hdc,canvas_x,canvas_y);
-      }
-    }
-    
-  } else {
-    struct Sprite *sprites[40];
-    int count = fill_unit_sprite_array(sprites, punit, &solid_bg);
-    if (count) {
-      int i=0;
-      if (solid_bg) {
-       RECT rc;
-       rc.left=canvas_x;
-       rc.top=canvas_y;
-       rc.right=rc.left+UNIT_TILE_WIDTH;
-       rc.bottom=rc.top+UNIT_TILE_HEIGHT;
-       FillRect(hdc,&rc,brush_std[player_color(unit_owner(punit))]);
-      } else {
-       
-       draw_sprite(sprites[0],hdc,canvas_x,canvas_y);
-       
-       i++;
-      }
-      for(;i<count;i++) {
-       if (sprites[i])
-         draw_sprite(sprites[i],hdc,canvas_x,canvas_y);
-      }
-    }
-  }
-}
-/**************************************************************************
-
-**************************************************************************/
 void put_unit_city_overlays(struct unit *punit, HDC hdc, int x, int y)
 {
   int upkeep_food = CLIP(0, punit->upkeep_food, 2);
@@ -724,15 +680,14 @@
                               int old_canvas_x, int old_canvas_y,
                               int new_canvas_x, int new_canvas_y)
 {
-  static HDC mapstoredc, hdc, hdcwin;
-  static HBITMAP old, oldbmp;
+  static HDC mapstoredc, hdcwin;
+  static HBITMAP old;
+  struct canvas_store store = {MULL, single_tile_pixmap}
 
   /* Create extra backing store.  This should be done statically. */
   if (first_frame) {
     mapstoredc = CreateCompatibleDC(NULL);
     old = SelectObject(mapstoredc, mapstorebitmap);
-    hdc = CreateCompatibleDC(NULL);
-    oldbmp = SelectObject(hdc, single_tile_pixmap);
     hdcwin = GetDC(map_window);
   }
 
@@ -743,7 +698,7 @@
   /* Draw the new sprite. */
   BitBlt(hdc, 0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT, mapstoredc,
         new_canvas_x, new_canvas_y, SRCCOPY);
-  put_unit_pixmap(punit, hdc, 0, 0);
+  put_unit_full(punit, &store, 0, 0);
 
   /* Write to screen. */
   BitBlt(hdcwin, new_canvas_x, new_canvas_y, UNIT_TILE_WIDTH,
@@ -753,8 +708,6 @@
   GdiFlush();
 
   if (last_frame) {
-    SelectObject(hdc, oldbmp);
-    DeleteDC(hdc);
     ReleaseDC(map_window, hdcwin);
     SelectObject(mapstoredc, old);
     DeleteDC(mapstoredc);
@@ -819,7 +772,7 @@
       struct canvas_store store = {NULL, single_tile_pixmap};
 
       put_one_tile(&store, losing_unit->x, losing_unit->y, 0, 0, FALSE);
-      put_unit_pixmap(losing_unit, hdc, 0, 0);
+      put_unit(losing_unit, &store, 0, 0);
       draw_sprite(sprites.explode.unit[i],hdc,NORMAL_TILE_WIDTH/4,0);
       BitBlt(hdcwin,canvas_x,canvas_y,
             NORMAL_TILE_WIDTH,NORMAL_TILE_HEIGHT,
@@ -1308,28 +1261,21 @@
 }
 
 /**************************************************************************
-Only used for isometric view.
+  Put part of a "drawn sprite" onto the canvas.
 **************************************************************************/
-static void put_unit_pixmap_draw(struct unit *punit, HDC hdc,
-                                 int canvas_x, int canvas_y,
-                                 int offset_x, int offset_y_unit,
-                                 int width, int height_unit)
-{
-  struct Sprite *sprites[40];
-  bool dummy;
-  int count = fill_unit_sprite_array(sprites, punit, &dummy);
-  int i;
-
-  for (i=0; i<count; i++) {
-    if (sprites[i]) {
-      pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y, sprites[i],
-                                   offset_x, offset_y_unit,
-                                   width, height_unit, 0);
-    }
-  }
+static void pixmap_put_drawn_sprite(HDC hdc, int canvas_x, int canvas_y,
+                                   struct drawn_sprite *pdsprite,
+                                   int offset_x, int offset_y,
+                                   int width, int height, fog)
+{
+  int ox = pdsprite->offset_x, oy = pdsprite->offset_y;
+
+  pixmap_put_overlay_tile_draw(hdc, canvas_x + ox, canvas_y + oy,
+                              pdsprite->sprite,
+                              offset_x - ox, offset_y - oy,
+                              width - ox, height - oy, fog);
 }
 
-
 /**************************************************************************
 Only used for isometric view.
 **************************************************************************/
@@ -1339,16 +1285,15 @@
                                  int width, int height_unit,
                                 bool fog)
 {
-  struct Sprite *sprites[80];
+  struct drawn_sprite sprites[80];
   int count = fill_city_sprite_array_iso(sprites, pcity);
   int i;
 
   for (i=0; i<count; i++) {
-    if (sprites[i]) {
-      pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y, sprites[i],
-                                   offset_x, offset_y_unit,
-                                   width, height_unit,
-                                   fog);
+    if (sprites[i].sprite) {
+      pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, sprites[i],
+                             offset_x, offset_y_unit, width, height_unit,
+                             fog);
     }
   }
 }
@@ -1364,7 +1309,7 @@
                                 int width, int height, int height_unit,
                                 enum draw_type draw)
 {
-  struct Sprite *tile_sprs[80];
+  struct drawn_sprite tile_sprs[80];
   struct Sprite *coasts[4];
   struct Sprite *dither[4];
   struct city *pcity;
@@ -1453,8 +1398,8 @@
                                    fog);
 
     } else {
-      pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y, tile_sprs[0],
-                                   offset_x, offset_y, width, height, fog);
+      pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, tile_sprs[0],
+                             offset_x, offset_y, width, height, fog);
       i++;
     }
     if (draw_terrain) {
@@ -1468,11 +1413,12 @@
   
   /*** Rest of terrain and specials ***/
   for (; i<count; i++) {
-    if (tile_sprs[i])
-      pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y, tile_sprs[i],
-                                   offset_x, offset_y, width, height, fog);
-    else
+    if (tile_sprs[i].sprite) {
+      pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, tile_sprs[i],
+                             offset_x, offset_y, width, height, fog);
+    } else {
       freelog(LOG_ERROR, "sprite is NULL");
+    }
   }
   /*** Map grid ***/
   if (draw_map_grid) {
@@ -1564,10 +1510,8 @@
 
     /*** Unit ***/
   if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    put_unit_pixmap_draw(punit, hdc,
-                         canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-                         offset_x, offset_y_unit,
-                         width, height_unit);
+    put_unit(punit, &canvas_store, canvas_x, canvas_y,
+            offset_x, offset_y_unit, width, height_unit);
     if (!pcity && unit_list_size(&map_get_tile(x, y)->units) > 1)
       pixmap_put_overlay_tile_draw(hdc,
                                    canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
Index: client/gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.10
diff -u -r1.10 mapview.h
--- client/gui-win32/mapview.h  2003/04/03 04:13:49     1.10
+++ client/gui-win32/mapview.h  2003/08/12 19:06:57
@@ -17,7 +17,6 @@
 
 void put_city_tile_output(HDC hdc, int x, int y,
                           int food, int shield, int trade);    
-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 put_one_tile_full(HDC hdc, int x, int y,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4831) drawn sprite support for gui-win32, Jason Short <=