Example #1
0
/****************************************************************************
  Create a sprite with the given height, width and color.
****************************************************************************/
struct sprite *create_sprite(int width, int height, struct color *pcolor)
{
  struct sprite *plrcolor;

  fc_assert_ret_val(width > 0, NULL);
  fc_assert_ret_val(height > 0, NULL);
  fc_assert_ret_val(pcolor != NULL, NULL);

  {
    /* FIXME: I do not know why it works but the code below allows the creation
     *        of the needed player color sprites. */
    fc_assert_ret_val(tileset != NULL, NULL);
    struct sprite *psprite_dummy = get_basic_fog_sprite(tileset);
    Pixmap mypixmap, mymask;
    GC plane_gc;

    mypixmap = XCreatePixmap(display, root_window, width, height,
                             display_depth);
    mymask = XCreatePixmap(display, root_window, width, height, 1);
    plane_gc = XCreateGC(display, mymask, 0, NULL);
    XCopyArea(display, psprite_dummy->mask, mymask, plane_gc,
              0, 0, width, height, 0, 0);
    XFreeGC(display, plane_gc);
    plrcolor = ctor_sprite_mask(mypixmap, mymask, width, height);
  }

  XSetForeground(display, fill_bg_gc, pcolor->color.pixel);
  XFillRectangle(display, plrcolor->pixmap, fill_bg_gc, 0, 0, width, height);

  return plrcolor;
}
Example #2
0
/****************************************************************************
  Create a new sprite by cropping and taking only the given portion of
  the image.
****************************************************************************/
struct sprite *crop_sprite(struct sprite *source,
			   int x, int y, int width, int height,
			   struct sprite *mask,
			   int mask_offset_x, int mask_offset_y)
{
  Pixmap mypixmap, mymask;
  GC plane_gc;

  mypixmap = XCreatePixmap(display, root_window,
			   width, height, display_depth);
  XCopyArea(display, source->pixmap, mypixmap, civ_gc, 
	    x, y, width, height, 0, 0);

  if (source->has_mask) {
    mymask = XCreatePixmap(display, root_window, width, height, 1);

    plane_gc = XCreateGC(display, mymask, 0, NULL);
    XCopyArea(display, source->mask, mymask, plane_gc, 
	      x, y, width, height, 0, 0);
    XFreeGC(display, plane_gc);

    if (mask) {
      XGCValues values;

      values.function = GXand;

      plane_gc = XCreateGC(display, mymask, GCFunction, &values);
      XCopyArea(display, mask->mask, mymask, plane_gc,
		x - mask_offset_x, y - mask_offset_y, width, height, 0, 0);
      XFreeGC(display, plane_gc);
    }

    return ctor_sprite_mask(mypixmap, mymask, width, height);
  } else if (mask) {
    mymask = XCreatePixmap(display, root_window, width, height, 1);

    plane_gc = XCreateGC(display, mymask, 0, NULL);
    XCopyArea(display, source->mask, mymask, plane_gc, 
	      x, y, width, height, 0, 0);
    XFreeGC(display, plane_gc);
    return ctor_sprite_mask(mypixmap, mymask, width, height);
  } else {
    return ctor_sprite(mypixmap, width, height);
  }
}
Example #3
0
/***************************************************************************
...
***************************************************************************/
void load_tile_gfx(void)
{
  int i, x, y, ntiles, a;
  struct Sprite *big_sprite;
  big_sprite=load_xpmfile(datafilename("tiles.xpm"));
    
  ntiles=2*(big_sprite->width/30)*(big_sprite->height/30);

  if(!(tile_sprites=malloc(ntiles*sizeof(struct Sprite *)))) {
    log(LOG_FATAL, "couldn't malloc tile_sprites array");
    exit(1);
  }
  
  i=0;
  for(y=0, a=0; a<22 && y<big_sprite->height; a++, y+=30)
    for(x=0; x<big_sprite->width; x+=30) {
      GC plane_gc;
      Pixmap mypixmap, mask;
      
      mypixmap=XCreatePixmap(display, root_window, 30, 30, 
			     display_depth);
      XCopyArea(display, big_sprite->pixmap, mypixmap, civ_gc, 
		x, y, 30, 30, 0 ,0);

      mask=XCreatePixmap(display, root_window, 30, 30, 1);

      plane_gc = XCreateGC(display, mask, 0, NULL);

      XCopyArea(display, big_sprite->mask, mask, plane_gc, 
		x, y, 30, 30, 0 ,0);

      tile_sprites[i++]=ctor_sprite_mask(mypixmap, mask, 30, 30);

      XFreeGC(display, plane_gc);
    }

  for(x=0; x<big_sprite->width; x+=15) {
    Pixmap mypixmap;
    
    mypixmap=XCreatePixmap(display, root_window, 15, 20, 
			   display_depth);
    XCopyArea(display, big_sprite->pixmap, mypixmap, civ_gc, 
	      x, y, 15, 20, 0 ,0);
    
    tile_sprites[i++]=ctor_sprite(mypixmap, 15, 20);
 }
  

  tile_sprite_width=30;
  tile_sprite_height=30;

}