Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4600) use put_unit in gui-gtk-2.0
Home

[Freeciv-Dev] (PR#4600) use put_unit in gui-gtk-2.0

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4600) use put_unit in gui-gtk-2.0
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Jul 2003 18:21:38 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch uses put_unit from within gui-gtk-2.0.  It is very similar to 
the GTK patch.

I can't compile this, though.  Vasco, will you test, fix, and commit it?

jason

Index: client/gui-gtk-2.0/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.h,v
retrieving revision 1.6
diff -u -r1.6 graphics.h
--- client/gui-gtk-2.0/graphics.h       2003/04/22 21:46:05     1.6
+++ client/gui-gtk-2.0/graphics.h       2003/07/18 01:19:58
@@ -28,11 +28,6 @@
   GdkPixbuf *pixbuf;
 };
 
-struct canvas_store
-{
-  GdkPixmap *pixmap;
-};
-
 typedef struct Sprite SPRITE;
 
 void   create_overlay_unit     (GtkWidget *pixcomm, int i);
Index: client/gui-gtk-2.0/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.h,v
retrieving revision 1.7
diff -u -r1.7 gui_main.h
--- client/gui-gtk-2.0/gui_main.h       2003/04/19 04:25:18     1.7
+++ client/gui-gtk-2.0/gui_main.h       2003/07/18 01:19:58
@@ -15,7 +15,14 @@
 
 #include <gtk/gtk.h>
 
+#include "gtkpixcomm.h"
 #include "gui_main_g.h"
+
+struct canvas_store
+{
+  GdkPixmap *pixmap;   /* if NULL, the pixcomm is drawn to instead. */
+  GtkPixcomm *pixcomm;
+};
 
 /* network string charset conversion */
 gchar *ntoh_str(const gchar *netstr);
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/18 01:19:59
@@ -57,14 +57,8 @@
 static void put_overlay_tile_gpixmap(GtkPixcomm *p,
                                     int canvas_x, int canvas_y,
                                     struct Sprite *ssprite);
-static void put_unit_pixmap(struct unit *punit, GdkPixmap *pm,
-                           int canvas_x, int canvas_y);
 static void put_line(GdkDrawable *pm, int x, int y, int dir);
 
-static void put_unit_pixmap_draw(struct unit *punit, GdkPixmap *pm,
-                                int canvas_x, int canvas_y,
-                                int offset_x, int offset_y_unit,
-                                int width, int height_unit);
 static void pixmap_put_overlay_tile_draw(GdkDrawable *pixmap,
                                         int canvas_x, int canvas_y,
                                         struct Sprite *ssprite,
@@ -147,7 +141,7 @@
 
       put_one_tile(&store, losing_unit->x, losing_unit->y,
                   0, 0, FALSE);
-      put_unit_pixmap(losing_unit, single_tile_pixmap, 0, 0);
+      put_unit_full(losing_unit, &store, 0, 0);
       pixmap_put_overlay_tile(single_tile_pixmap, 0, 0,
                              sprites.explode.unit[i]);
 
@@ -402,6 +396,8 @@
                               int old_canvas_x, int old_canvas_y,
                               int new_canvas_x, int new_canvas_y)
 {
+  struct canvas_store store = {single_tile_pixmap};
+
   /* Clear old sprite. */
   gdk_draw_drawable(map_canvas->window, civ_gc, map_canvas_store, old_canvas_x,
                    old_canvas_y, old_canvas_x, old_canvas_y, UNIT_TILE_WIDTH,
@@ -410,7 +406,7 @@
   /* Draw the new sprite. */
   gdk_draw_drawable(single_tile_pixmap, civ_gc, map_canvas_store, new_canvas_x,
                    new_canvas_y, 0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
-  put_unit_pixmap(punit, single_tile_pixmap, 0, 0);
+  put_unit_full(punit, &store, 0, 0);
 
   /* Write to screen. */
   gdk_draw_drawable(map_canvas->window, civ_gc, single_tile_pixmap, 0, 0,
@@ -607,6 +603,7 @@
       mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
     }
     mapview_canvas.store->pixmap = map_canvas_store;
+    mapview_canvas.store->pixcomm = NULL;
 
     gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
     gdk_draw_rectangle(map_canvas_store, fill_bg_gc, TRUE, 0, 0, -1, -1);
@@ -707,75 +704,8 @@
 }
 
 /**************************************************************************
-FIXME: Find a better way to put flags and such on top.
-**************************************************************************/
-static void put_unit_pixmap(struct unit *punit, GdkPixmap *pm,
-                           int canvas_x, int canvas_y)
-{
-  int 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]) {
-       pixmap_put_overlay_tile(pm, canvas_x, canvas_y, sprites[i]);
-      }
-    }
-  } else { /* is_isometric */
-    struct Sprite *sprites[40];
-    int count = fill_unit_sprite_array(sprites, punit, &solid_bg);
-
-    if (count) {
-      int i = 0;
-
-      if (solid_bg) {
-       gdk_gc_set_foreground(fill_bg_gc,
-                             colors_standard[player_color(unit_owner(punit))]);
-       gdk_draw_rectangle(pm, fill_bg_gc, TRUE,
-                          canvas_x, canvas_y,
-                          UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
-      } else {
-       pixmap_put_overlay_tile(pm, canvas_x, canvas_y, sprites[0]);
-       i++;
-      }
-
-      for (; i<count; i++) {
-       if (sprites[i])
-         pixmap_put_overlay_tile(pm, canvas_x, canvas_y, sprites[i]);
-      }
-    }
-  }
-}
-
-/**************************************************************************
 Only used for isometric view.
 **************************************************************************/
-static void put_unit_pixmap_draw(struct unit *punit, GdkPixmap *pm,
-                                int canvas_x, int canvas_y,
-                                int offset_x, int offset_y_unit,
-                                int width, int height_unit)
-{
-  struct Sprite *sprites[40];
-  int 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(pm, canvas_x, canvas_y, sprites[i],
-                                  offset_x, offset_y_unit,
-                                  width, height_unit, 0);
-    }
-  }
-}
-
-/**************************************************************************
-Only used for isometric view.
-**************************************************************************/
 void put_one_tile_full(GdkDrawable *pm, int x, int y,
                       int canvas_x, int canvas_y, int citymode)
 {
@@ -986,25 +916,12 @@
 **************************************************************************/
 void put_unit_gpixmap(struct unit *punit, GtkPixcomm *p)
 {
-  struct Sprite *sprites[40];
-  int solid_bg;
-  int count = fill_unit_sprite_array(sprites, punit, &solid_bg);
+  struct canvas_store canvas_store = {NULL, p};
 
   gtk_pixcomm_freeze(p);
   gtk_pixcomm_clear(p);
-
-  if (count) {
-    int i;
-
-    if (solid_bg) {
-      gtk_pixcomm_fill(p, colors_standard[player_color(unit_owner(punit))]);
-    }
 
-    for (i=0;i<count;i++) {
-      if (sprites[i])
-        put_overlay_tile_gpixmap(p, 0, 0, sprites[i]);
-    }
-  }
+  put_unit_full(punit, &canvas_store, 0, 0);
 
   gtk_pixcomm_thaw(p);
 }
@@ -1173,8 +1090,12 @@
                    struct Sprite *sprite,
                    int offset_x, int offset_y, int width, int height)
 {
-  pixmap_put_sprite(pcanvas_store->pixmap, canvas_x, canvas_y,
-                   sprite, offset_x, offset_y, width, height);
+  if (pcanvas_store->pixmap) {
+    pixmap_put_sprite(pcanvas_store->pixmap, canvas_x, canvas_y,
+                     sprite, offset_x, offset_y, width, height);
+  } else {
+    gtk_pixcomm_copyto(pcanvas_store->pixcomm, sprite, canvas_x, canvas_y);
+  }
 } 
 
 /**************************************************************************
@@ -1207,9 +1128,13 @@
                       enum color_std color,
                       int canvas_x, int canvas_y, int width, int height)
 {
-  gdk_gc_set_foreground(fill_bg_gc, colors_standard[color]);
-  gdk_draw_rectangle(pcanvas_store->pixmap, fill_bg_gc, TRUE,
-                    canvas_x, canvas_y, width, height);
+  if (pcanvas_store->pixmap) {
+    gdk_gc_set_foreground(fill_bg_gc, colors_standard[color]);
+    gdk_draw_rectangle(pcanvas_store->pixmap, fill_bg_gc, TRUE,
+                      canvas_x, canvas_y, width, height);
+  } else {
+    gtk_pixcomm_fill(pcanvas_store->pixcomm, colors_standard[color], FALSE);
+  }
 }
 
 /**************************************************************************
@@ -1627,6 +1552,7 @@
   int count, i = 0;
   int fog;
   int solid_bg;
+  struct canvas_store canvas_store = {pm};
 
   if (!width || !(height || height_unit))
     return;
@@ -1827,10 +1753,10 @@
 
   /*** Unit ***/
   if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    put_unit_pixmap_draw(punit, pm,
-                        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 - NORMAL_TILE_HEIGHT/2,
+            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(pm,
                                   canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,

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