Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2001:
[Freeciv-Dev] scaling of flags working now
Home

[Freeciv-Dev] scaling of flags working now

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: <freeciv-dev@xxxxxxxxxxx>
Cc: <pbarker@xxxxxxxxxxxxxxxxxxxxx>
Subject: [Freeciv-Dev] scaling of flags working now
From: Karl-Ingo Friese <kif@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 16 Jun 2001 16:53:36 +0200 (CEST)

Hello there,

The second solution suggested by Thue worked out fine. Have a look at

  http://www-c.informatik.uni-hannover.de/~kif/civ/screenies2.html

I think it looks quite good now.

Still, b4 I submit anything, I would like to have some gdk/gtk expert
have a glance at the code, for I am sure it could be done better. Since
I am considering myself more a novice gtk user, I used mainly the
infos I found client/gui-gtk/gui_stuff.h and gdk.h. Speed is not realy
critical since each flag is of course calculated only once per nation,
but still ... well here is what I do:


/* builds the flag pixmap */
void build_flag(int playerindex) {
  int oldh, oldw, flagh, flagw, border;
  guint32 pixel;
  GdkImage *flag_image;
  GdkPixmap *flag_pixmap;

  flag_pixmap=get_nation_by_idx(playerindex)->flag_sprite->pixmap;
  oldw=get_nation_by_idx(playerindex)->flag_sprite->width;
  oldh=get_nation_by_idx(playerindex)->flag_sprite->height;

  /* since the flag pixmap contains more data then necessary, we have to */
  /* look into the pixels for the "real" flag dimensions. If this fails, */
  /* we have to keep the given values ... */

  flag_image=gdk_image_get(flag_pixmap, 0, 0, oldw, oldh);

  /* i dont know how to find out transparent pixels else ... */
  /* are they always ==0 ? */
  pixel=gdk_image_get_pixel(flag_image, oldw-1, oldh-1);
  while (pixel==gdk_image_get_pixel(flag_image, oldw-1, 2)) oldw--;
  if (oldw<5) oldw=get_nation_by_idx(playerindex)->flag_sprite->width;

  while (pixel==gdk_image_get_pixel(flag_image, 2, oldh-1)) oldh--;
  if (oldh<5) oldh=get_nation_by_idx(playerindex)->flag_sprite->height;
  gdk_image_destroy(flag_image);

  /* now scaling the original pixmap */
  flagh=GTK_CLIST(players_list)->row_height;
  flagw=((double)flagh/oldh)*oldw;

  flag_pixmap=gtk_scale_pixmap(flag_pixmap, oldw, oldh, flagw, flagh);

  /* drawing a black border ... can this be done more easily ? Do I realy */
  /* have to turn the pixmap into an image each time before doing pixel */
  /* operations or can I work with the gdk_pixmap itself ? */
  flag_image=gdk_image_get(flag_pixmap, 0, 0, flagw, flagh);
  for (border=0; border<flagw; border++) {
      gdk_image_put_pixel(flag_image, border, 0, 0);
      gdk_image_put_pixel(flag_image, border, flagh-1, 0);
  }
  for (border=0; border<flagh; border++) {
      gdk_image_put_pixel(flag_image, 0, border, 0);
      gdk_image_put_pixel(flag_image, flagw-1, border, 0);
  }

  /* and finaly ... storing the pixmap  in the static flags array */
  flags[playerindex]=gdk_pixmap_new(root_window, flagw, flagh, -1);
  gdk_draw_image(flags[playerindex], civ_gc, flag_image,
                 0, 0, 0, 0, flagw, flagh);

  gdk_image_destroy(flag_image);
}


See the comments for my questions ... did I miss anything else ?

ChaosE

PS: Again, reply directly to me please ...


-- 

Karl-Ingo Friese
kif@xxxxxxxxxxxxxxxxxxxxxxxxxx



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] scaling of flags working now, Karl-Ingo Friese <=