~ubuntu-branches/ubuntu/trusty/netrek-client-cow/trusty

« back to all changes in this revision

Viewing changes to x11sprite.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2009-06-16 15:27:20 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616152720-whngeaf1w8l23u14
Tags: 3.3.0-1
[ Barry deFreese ]
* New upstream release.
* Install upstream desktop file. (Closes: #522587).
* Add quilt patch system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "config.h"
2
2
 
3
 
#ifdef HAVE_XPM
4
3
#include <stdio.h>
 
4
#include <unistd.h>
5
5
#include <stdlib.h>
 
6
#include <strings.h>
6
7
#include <sys/param.h>
7
8
 
8
9
#include <sys/stat.h>
 
10
#include <fts.h>
9
11
#include <unistd.h>
10
12
 
11
13
#include <X11/Xlib.h>
12
 
#include INC_XPM
 
14
#include <Imlib2.h>
13
15
 
14
16
#include "Wlib.h"
15
17
#include "defs.h"
21
23
 
22
24
#include "x11sprite.h"
23
25
 
24
 
#define W_Void2Window(win) ((win) ? ((struct window *) (win)) : (mylocal))
 
26
#define W_Void2Window(win) (((struct window *) (win)))
25
27
#define NoPixmapError 0
26
28
 
27
29
struct S_Object
28
30
  {
29
 
    W_Window *parent;
 
31
    Drawable drawable;
30
32
    GC      gc;
31
33
    int     view, nviews, width, height, cloak;
32
34
    Pixmap  image;
73
75
extern int takeNearest;
74
76
 
75
77
extern Display *W_Display;
76
 
struct window *mylocal;
77
 
static GC pixmap_gc;
78
78
 
79
79
const char teamnames[NUMTEAM + 1][4] =
80
80
{"Ind", "Fed", "Rom", "Kli", "Ori"};
81
81
 
82
82
const char mplanetfiles[NUM_PL_IMGS][12] =
83
 
{"UNKN.xpm",
84
 
 "ROCK.xpm",
85
 
 "AGRI.xpm",
86
 
 "army.xpm",
87
 
 "repair.xpm",
88
 
 "fuel.xpm",
89
 
 "Ind.xpm",
90
 
 "Fed.xpm",
91
 
 "Rom.xpm",
92
 
 "Kli.xpm",
93
 
 "Ori.xpm"
 
83
{"UNKN.png",
 
84
 "ROCK.png",
 
85
 "AGRI.png",
 
86
 "army.png",
 
87
 "repair.png",
 
88
 "fuel.png",
 
89
 "Ind.png",
 
90
 "Fed.png",
 
91
 "Rom.png",
 
92
 "Kli.png",
 
93
 "Ori.png"
94
94
};
95
95
const char shipfiles[NUM_TYPES][8] =
96
 
{"SC.xpm",
97
 
 "DD.xpm",
98
 
 "CA.xpm",
99
 
 "BB.xpm",
100
 
 "AS.xpm",
101
 
 "SB.xpm",
102
 
 "GA.xpm",
103
 
 "AT.xpm"
 
96
{"SC.png",
 
97
 "DD.png",
 
98
 "CA.png",
 
99
 "BB.png",
 
100
 "AS.png",
 
101
 "SB.png",
 
102
 "GA.png",
 
103
 "AT.png"
104
104
};
105
105
const char torpfiles[2][14] =
106
 
{"torp.xpm", "torp_det.xpm"};
 
106
{"torp.png", "torp_det.png"};
107
107
const char plasmafiles[2][16] =
108
 
{"plasma.xpm", "plasma_det.xpm"};
109
 
const char cloakfile[10] = "cloak.xpm";
 
108
{"plasma.png", "plasma_det.png"};
 
109
const char cloakfile[10] = "cloak.png";
110
110
const char explosionfiles[2][18] =
111
 
{"explosion.xpm", "sbexplosion.xpm"};
 
111
{"explosion.png", "sbexplosion.png"};
112
112
const char bgfiles[NUM_BG_IMGS][16] =
113
 
{"map_back.xpm",
114
 
 "local_back.xpm",
115
 
 "ghostbust.xpm",
116
 
 "genocide.xpm",
117
 
 "greet.xpm",
118
 
 "hockey.xpm"
 
113
{"map_back.png",
 
114
 "local_back.png",
 
115
 "ghostbust.png",
 
116
 "genocide.png",
 
117
 "greet.png",
 
118
 "hockey.png"
119
119
};
120
120
 
121
 
int     ReadFileToSprite(char *filename, struct S_Object *sprite, W_Window * w)
 
121
 
 
122
static int ReadFileToSprite(char *filename, struct S_Object *sprite, Drawable drawable)
122
123
{
123
 
  register int k;
124
 
  XpmAttributes attr;
125
 
  int     nviews = 0;
126
 
  struct window *win = W_Void2Window(mylocal);
127
 
 
128
 
 
129
 
  attr.visual = W_Visual;
130
 
  attr.colormap = W_Colormap;
131
 
  attr.exactColors = takeNearest;
132
 
  attr.closeness = 40000;
133
 
  attr.valuemask = XpmVisual | XpmColormap | XpmExactColors |
134
 
      XpmReturnExtensions | XpmCloseness;
135
 
 
136
 
  if (XpmReadFileToPixmap(W_Display, win->window, filename, &sprite->image,
137
 
                          &sprite->shape, &attr) != XpmSuccess)
138
 
    {
139
 
      if (!(pixMissing & NO_PIXMAPS))
140
 
        fprintf(stderr, "Unable to read file %s.\n", filename);
141
 
      sprite->image = NoPixmapError;
142
 
      sprite->nviews = 1;
143
 
      return (1);
144
 
    }
145
 
 
146
 
  for (k = 0; k < attr.nextensions; k++)
147
 
    {
148
 
      if (strcmpi(attr.extensions[0].name, "num_views") == 0)
149
 
        nviews = atoi(attr.extensions[0].lines[0]);
150
 
    }
151
 
 
152
 
  if (nviews == 0)
153
 
    {
154
 
      int     guess;
155
 
 
156
 
      guess = (int) ((attr.height) / (attr.width));
157
 
      if (guess == (attr.height) / (attr.width))
158
 
        {
159
 
          nviews = guess;
160
 
        }
161
 
      else
162
 
        {
163
 
          if (!(pixMissing & NO_PIXMAPS))
164
 
            fprintf(stderr, "NUM_VIEWS not suppied in %s.  Unable to estimate ...\n",
165
 
                    filename);
166
 
          sprite->image = NoPixmapError;
167
 
          sprite->nviews = 1;
168
 
          return (1);
169
 
        }
170
 
    }
171
 
 
172
 
  sprite->parent = w;
 
124
  Imlib_Image im;
 
125
  int width, height, nviews;
 
126
 
 
127
  if (access(filename, R_OK) != 0) {
 
128
    fprintf(stderr, "image %s is not readable\n", filename);
 
129
    goto fail;
 
130
  }
 
131
 
 
132
  im = imlib_load_image(filename);
 
133
  if (!im) {
 
134
    fprintf(stderr, "image %s failed to load\n", filename);
 
135
    goto fail;
 
136
  }
 
137
 
 
138
  imlib_context_set_display(W_Display);
 
139
  imlib_context_set_visual(W_Visual);
 
140
  imlib_context_set_colormap(W_Colormap);
 
141
  imlib_context_set_image(im);
 
142
  imlib_context_set_drawable(drawable);
 
143
  imlib_render_pixmaps_for_whole_image(&sprite->image, &sprite->shape);
 
144
 
 
145
  width = imlib_image_get_width();
 
146
  height = imlib_image_get_height();
 
147
  nviews = height / width;
 
148
  if (nviews * width != height) {
 
149
    nviews = 1;
 
150
  }
 
151
 
 
152
  sprite->drawable = drawable;
173
153
  sprite->gc = XCreateGC(W_Display, sprite->image, 0, NULL);
 
154
  sprite->view = 0;
174
155
  sprite->nviews = nviews;
175
 
  sprite->width = attr.width;
176
 
  sprite->height = (attr.height) / nviews;
177
 
 
178
 
  return (0);
179
 
}
180
 
 
181
 
int     ReadFileToTile(char *filename, Pixmap * pix)
182
 
{
183
 
  XpmAttributes attr;
184
 
  struct window *win = W_Void2Window(mylocal);
185
 
 
186
 
  attr.visual = W_Visual;
187
 
  attr.colormap = W_Colormap;
188
 
  attr.exactColors = takeNearest;
189
 
  attr.closeness = 40000;
190
 
  attr.valuemask = XpmVisual | XpmColormap | XpmExactColors |
191
 
      XpmReturnExtensions | XpmCloseness;
192
 
 
193
 
  if (XpmReadFileToPixmap(W_Display, win->window, filename, pix, NULL, &attr)
194
 
      != XpmSuccess)
195
 
    {
196
 
      if (!(pixMissing & NO_PIXMAPS))
197
 
        fprintf(stderr, "Unable to read file %s.\n", filename);
198
 
      *pix = NoPixmapError;
199
 
      return (1);
200
 
    }
201
 
 
202
 
  return (0);
203
 
}
204
 
 
205
 
void    GetPixmaps(Display * d, struct window *win)
206
 
{
207
 
  register int i, j;
208
 
  char    buf[1024], pixmapDir[1024];
 
156
  sprite->width = width;
 
157
  sprite->height = height / nviews;
 
158
  sprite->cloak = 0;
 
159
#ifdef DEBUG
 
160
  fprintf(stderr, "image %s loaded, nv=%d w=%d h=%d (%d)\n", filename,
 
161
          nviews, width, height, sprite->height);
 
162
#endif
 
163
  imlib_free_image_and_decache();
 
164
  return 0;
 
165
 
 
166
 fail:
 
167
  sprite->image = NoPixmapError;
 
168
  sprite->nviews = 1;
 
169
  return 1;
 
170
}
 
171
 
 
172
int     ReadFileToTile(char *filename, Pixmap *pix, Drawable drawable)
 
173
{
 
174
  Imlib_Image im;
 
175
 
 
176
  if (access(filename, R_OK) != 0) {
 
177
    fprintf(stderr, "image %s is not readable\n", filename);
 
178
    goto fail;
 
179
  }
 
180
 
 
181
  im = imlib_load_image(filename);
 
182
  if (!im) {
 
183
    fprintf(stderr, "image %s failed to load\n", filename);
 
184
    goto fail;
 
185
  }
 
186
 
 
187
  imlib_context_set_display(W_Display);
 
188
  imlib_context_set_visual(W_Visual);
 
189
  imlib_context_set_colormap(W_Colormap);
 
190
  imlib_context_set_image(im);
 
191
  imlib_context_set_drawable(drawable);
 
192
  imlib_render_pixmaps_for_whole_image(pix, NULL);
 
193
#ifdef DEBUG
 
194
  fprintf(stderr, "tile %s loaded, w=%d h=%d\n", filename,
 
195
          imlib_image_get_width(), imlib_image_get_height());
 
196
#endif
 
197
  imlib_free_image_and_decache();
 
198
  return 0;
 
199
 
 
200
 fail:
 
201
  *pix = NoPixmapError;
 
202
  return 1;
 
203
}
 
204
 
 
205
static char pixmapDir[1024] = { '\0' };
 
206
 
 
207
static void GetPixmapDir()
 
208
{
209
209
  char   *pd;
210
 
  int     missing;
211
210
 
212
 
  mylocal = win;
213
 
  W_Display = d;
 
211
  if (pixmapDir[0] != '\0') return;
214
212
 
215
213
  pd = getdefault("pixmapDir");
216
214
  if (pd != (char *) NULL)
217
 
    strcpy(pixmapDir, pd);
 
215
    strncpy(pixmapDir, pd, 1024);
218
216
  else
219
217
    strcpy(pixmapDir, "/usr/share/pixmaps/netrek-client-cow");
220
218
 
221
 
  if ((strcmpi(pixmapDir, "None") == 0) || (pixMissing & NO_PIXMAPS))
222
 
    {
223
 
      pixMissing = NO_IND_PIX | NO_FED_PIX | NO_ROM_PIX |
 
219
  if ((strcmpi(pixmapDir, "None") == 0) || (pixMissing & NO_PIXMAPS)) {
 
220
    pixMissing = NO_IND_PIX | NO_FED_PIX | NO_ROM_PIX |
 
221
      NO_KLI_PIX | NO_ORI_PIX | NO_WEP_PIX | NO_EXP_PIX |
 
222
      NO_CLK_PIX | NO_MAP_PIX | NO_BG_PIX | NO_PIXMAPS;
 
223
    fprintf(stderr, "pixmaps turned off\n");
 
224
  } else {
 
225
    struct stat buf;
 
226
 
 
227
    if ((stat(pixmapDir, &buf)) || (!(S_ISDIR(buf.st_mode)))) {
 
228
      /* if .xtrekrc is wrong, and package default wrong, try default dir */
 
229
      if ((stat("pixmaps", &buf)) || (!(S_ISDIR(buf.st_mode)))) {
 
230
        pixMissing = NO_IND_PIX | NO_FED_PIX | NO_ROM_PIX |
224
231
          NO_KLI_PIX | NO_ORI_PIX | NO_WEP_PIX | NO_EXP_PIX |
225
232
          NO_CLK_PIX | NO_MAP_PIX | NO_BG_PIX | NO_PIXMAPS;
226
 
      fprintf(stderr, "pixmaps turned off\n");
227
 
    }
228
 
  else
229
 
    {
230
 
      struct stat buf;
231
 
 
232
 
      if ((stat(pixmapDir, &buf)) || (!(S_ISDIR(buf.st_mode))))
233
 
        {
234
 
          pixMissing = NO_IND_PIX | NO_FED_PIX | NO_ROM_PIX |
235
 
              NO_KLI_PIX | NO_ORI_PIX | NO_WEP_PIX | NO_EXP_PIX |
236
 
              NO_CLK_PIX | NO_MAP_PIX | NO_BG_PIX | NO_PIXMAPS;
237
 
          fprintf(stderr, "pixmaps not here\n");
238
 
        }
239
 
    }
240
 
 
241
 
  pixmap_gc = XCreateGC(W_Display, win->window, 0, NULL);
 
233
        fprintf(stderr, "pixmaps not here\n");
 
234
      } else {
 
235
        strcpy(pixmapDir, "pixmaps");
 
236
      }
 
237
    }
 
238
  }
 
239
}
 
240
 
 
241
void    GetPixmaps(Display * d, struct window *win, W_Window t, W_Window g)
 
242
{
 
243
  register int i, j;
 
244
  char    buf[1024];
 
245
  int     missing;
 
246
 
 
247
  Drawable tactical = W_Void2Window(t)->window;
 
248
  Drawable galactic = W_Void2Window(g)->window;
 
249
  W_Display = d;
 
250
 
 
251
  GetPixmapDir();
242
252
 
243
253
  for (i = 0; i < NUMTEAM + 1; i++)
244
254
    {
246
256
      for (j = 0; j < NUM_TYPES; j++)
247
257
        {
248
258
          sprintf(buf, "%s/%s/%s", pixmapDir, teamnames[i], shipfiles[j]);
249
 
          missing += ReadFileToSprite(buf, &shipImg[i][j], &w);
 
259
          missing += ReadFileToSprite(buf, &shipImg[i][j], tactical);
250
260
        }
251
261
      if (missing == NUM_TYPES)
252
262
        {
262
272
      for (j = 0; j < 2; j++)
263
273
        {
264
274
          sprintf(buf, "%s/%s/%s", pixmapDir, teamnames[i], torpfiles[j]);
265
 
          missing += ReadFileToSprite(buf, &torpImg[i][j], &w);
 
275
          missing += ReadFileToSprite(buf, &torpImg[i][j], tactical);
266
276
 
267
277
          sprintf(buf, "%s/%s/%s", pixmapDir, teamnames[i], plasmafiles[j]);
268
 
          missing += ReadFileToSprite(buf, &plasmaImg[i][j], &w);
 
278
          missing += ReadFileToSprite(buf, &plasmaImg[i][j], tactical);
269
279
        }
270
280
    }
271
281
  if (missing == (NUMTEAM + 1) * 4)
279
289
  for (i = 0; i < 2; i++)
280
290
    {
281
291
      sprintf(buf, "%s/Misc/%s", pixmapDir, explosionfiles[i]);
282
 
      missing += ReadFileToSprite(buf, &explosionImg[i], &w);
 
292
      missing += ReadFileToSprite(buf, &explosionImg[i], tactical);
283
293
    }
284
294
  if (missing == 2)
285
295
    {
295
305
      if (i == PL_PIX_AGRI && missing == 0)
296
306
        {
297
307
          /* If the AGRI pixmap is missing, use the ROCK pixmap */
298
 
          if (ReadFileToSprite(buf, &mplanetImg[i], &mapw) != 0)
 
308
          if (ReadFileToSprite(buf, &mplanetImg[i], galactic) != 0)
299
309
            {
300
310
              sprintf(buf, "%s/Planets/%s", pixmapDir, mplanetfiles[i - 1]);
301
 
              ReadFileToSprite(buf, &mplanetImg[i], &mapw);
 
311
              ReadFileToSprite(buf, &mplanetImg[i], galactic);
302
312
            }
303
313
        }
304
314
      else
305
 
        missing += ReadFileToSprite(buf, &mplanetImg[i], &mapw);
 
315
        missing += ReadFileToSprite(buf, &mplanetImg[i], galactic);
306
316
    }
307
317
  if (missing)
308
318
    {
312
322
    }
313
323
 
314
324
  sprintf(buf, "%s/Misc/%s", pixmapDir, cloakfile);
315
 
  if (ReadFileToSprite(buf, &cloakImg, &w))
 
325
  if (ReadFileToSprite(buf, &cloakImg, tactical))
316
326
    {
317
327
      pixMissing |= NO_CLK_PIX;
318
328
      if (!(pixMissing & NO_PIXMAPS))
323
333
  for (i = 0; i < NUM_BG_IMGS; i++)
324
334
    {
325
335
      sprintf(buf, "%s/Misc/%s", pixmapDir, bgfiles[i]);
326
 
      missing += ReadFileToTile(buf, &backPix[i]);
 
336
      missing += ReadFileToTile(buf, &backPix[i], galactic);
327
337
    }
328
338
  if (missing == NUM_BG_IMGS)
329
339
    {
342
352
int     W_DrawSprite(void *in, int x, int y, int winside)
343
353
{
344
354
  const int view = SCALE * winside / 2;
345
 
  struct window *win;
346
355
  struct S_Object *sprite = (struct S_Object *) in;
347
356
  int     dx, dy;
348
357
 
352
361
  if (x > view || x < -view || y > view || y < -view)
353
362
    return 0;
354
363
 
355
 
  win = W_Void2Window(*(sprite->parent));
356
 
 
357
364
  dx = x - (sprite->width) / 2;
358
365
  dy = y - (sprite->height) / 2;
359
366
 
370
377
                     dx, dy - sprite->view * (sprite->height));
371
378
    }
372
379
 
373
 
  XCopyArea(W_Display, sprite->image, win->window, sprite->gc,
 
380
  XCopyArea(W_Display, sprite->image, sprite->drawable, sprite->gc,
374
381
            0, (sprite->view) * (sprite->height),
375
382
            sprite->width, sprite->height,
376
383
            dx, dy);
378
385
  return (sprite->width);
379
386
}
380
387
 
 
388
void W_DrawSpriteAbsolute(void *in, int x, int y)
 
389
{
 
390
  struct S_Object *sprite = (struct S_Object *) in;
 
391
 
 
392
  if (sprite == NULL)
 
393
    return;
 
394
 
 
395
  XSetClipMask(W_Display, sprite->gc, sprite->shape);
 
396
  XSetClipOrigin(W_Display, sprite->gc, x, y);
 
397
  XCopyArea(W_Display, sprite->image, sprite->drawable, sprite->gc,
 
398
            0, 0, sprite->width, sprite->height, x, y);
 
399
}
 
400
 
 
401
void W_ClearSpriteAbsolute(void *in, int x, int y)
 
402
{
 
403
  struct S_Object *sprite = (struct S_Object *) in;
 
404
 
 
405
  if (sprite == NULL)
 
406
    return;
 
407
 
 
408
  XSetClipMask(W_Display, sprite->gc, sprite->shape);
 
409
  XSetClipOrigin(W_Display, sprite->gc, x, y);
 
410
  XClearArea(W_Display, sprite->drawable,
 
411
             x, y, sprite->width, sprite->height, False);
 
412
}
 
413
 
381
414
void   *S_Ship(int playerno)
382
415
{
383
416
  struct S_Object *sprite;
390
423
  sprite = &(shipImg[remap[this->p_team]][this->p_ship.s_type]);
391
424
  sprite->cloak = 0;
392
425
 
393
 
  /* The following generalizes "rosette(x)" for an arbitrary number of views
394
 
   * * in the xpm    */
 
426
  /* The following generalizes "rosette(x)" for an arbitrary number of
 
427
     views in the image */
395
428
 
396
429
  sprite->view = ((((this->p_dir) + 128 / (sprite->nviews))
397
430
                   / (256 / (sprite->nviews))) % (sprite->nviews));
410
443
    }
411
444
  else if (this->p_status == PEXPLODE)
412
445
    {
413
 
      int     i = this->p_explode;
 
446
      int     i = this->p_explode * 5 / server_ups;
414
447
 
415
448
      if (pixFlags & NO_EXP_PIX)
416
449
        return ((void *) NULL);
588
621
    {
589
622
      sprite = &torpImg[remap[players[this->t_owner].p_team]][1];
590
623
      this->t_fuse--;
591
 
      numdetframes = NUMDETFRAMES * server_ups / 10;
592
 
      frame = this->t_fuse * 10 / server_ups;
 
624
      numdetframes = NUMDETFRAMES * server_ups / 5;
 
625
      frame = this->t_fuse * 5 / server_ups;
593
626
      if (this->t_fuse <= 0)
594
627
        {
595
628
          this->t_status = PTFREE;
608
641
    {
609
642
      sprite = &torpImg[remap[players[this->t_owner].p_team]][0];
610
643
      sprite->view = ++sprite->view % sprite->nviews;
 
644
      // FIXME: torps rotate faster with higher client update rates
611
645
    }
612
646
 
613
647
  if ((sprite->image == NoPixmapError) || (pixFlags & NO_WEP_PIX))
677
711
 
678
712
  W_ClearWindow(w);
679
713
}
680
 
#endif /* HAVE_XPM */
 
714
 
 
715
void    W_SetBackground(W_Window w, int which)
 
716
{
 
717
  struct window *win = W_Void2Window(w);
 
718
 
 
719
  if ((backPix[which] == NoPixmapError) || (pixFlags & NO_BG_PIX))
 
720
    W_UnTileWindow(w);
 
721
  else
 
722
    XSetWindowBackgroundPixmap(W_Display, win->window, backPix[which]);
 
723
 
 
724
  W_ClearWindow(w);
 
725
}
 
726
 
 
727
void *W_SetBackgroundImage(W_Window w, char *name)
 
728
{
 
729
  Drawable drawable = W_Void2Window(w)->window;
 
730
  struct S_Object *sprite = calloc(1, sizeof(struct S_Object));
 
731
  char *path;
 
732
 
 
733
  if (sprite == NULL) return NULL;
 
734
 
 
735
  GetPixmapDir();
 
736
  path = malloc(strlen(pixmapDir) + strlen(name) + 2);
 
737
  if (path == NULL) return NULL;
 
738
 
 
739
  sprintf(path, "%s/%s", pixmapDir, name);
 
740
 
 
741
  if (ReadFileToSprite(path, sprite, drawable)) {
 
742
    free(path);
 
743
    return NULL;
 
744
  }
 
745
  free(path);
 
746
 
 
747
  XSetWindowBackgroundPixmap(W_Display, drawable, sprite->image);
 
748
  W_ClearWindow(w);
 
749
  return (void *) sprite;
 
750
}
 
751
 
 
752
static struct S_Object *ss = NULL;
 
753
static int ss_size = 0;
 
754
static int ss_next = 0;
 
755
static int ss_show = 0;
 
756
 
 
757
static void ss_init(W_Window w)
 
758
{
 
759
  char *path, *argv[2];
 
760
  FTS *fts;
 
761
  FTSENT *ent;
 
762
  Drawable drawable = W_Void2Window(w)->window;
 
763
 
 
764
  if (ss != NULL) return;
 
765
 
 
766
  GetPixmapDir();
 
767
 
 
768
  path = malloc(strlen(pixmapDir) + 4);
 
769
  sprintf(path, "%s/ss", pixmapDir);
 
770
  argv[0] = path;
 
771
  argv[1] = NULL;
 
772
 
 
773
  ss_size = 50;
 
774
  ss = (struct S_Object *) malloc(ss_size * sizeof(struct S_Object));
 
775
  ss_next = 0;
 
776
 
 
777
  fts = fts_open(argv, FTS_LOGICAL, NULL);
 
778
  while ((ent = fts_read(fts))) {
 
779
    if (ent->fts_info != FTS_F) continue;
 
780
    memset(&ss[ss_next], 0, sizeof(struct S_Object));
 
781
    if (ReadFileToSprite(ent->fts_path, &ss[ss_next], drawable)) continue;
 
782
    ss_next++;
 
783
    if (ss_next >= ss_size) {
 
784
      ss_size += 10;
 
785
      ss = realloc(ss, ss_size * sizeof(struct S_Object));
 
786
    }
 
787
  }
 
788
  fts_close(fts);
 
789
  free(path);
 
790
}
 
791
 
 
792
void    W_NextScreenShot(W_Window w, int x, int y)
 
793
{
 
794
  ss_init(w);
 
795
  if (ss_next == 0) return;
 
796
  W_ClearSpriteAbsolute(&ss[ss_show], x, y);
 
797
  ss_show++;
 
798
  if (ss_show >= ss_next) ss_show=0;
 
799
  W_DrawSpriteAbsolute(&ss[ss_show], x, y);
 
800
}
 
801
 
 
802
void    W_DrawScreenShot(W_Window w, int x, int y)
 
803
{
 
804
  ss_init(w);
 
805
  if (ss_next == 0) return;
 
806
  W_DrawSpriteAbsolute(&ss[ss_show], x, y);
 
807
}
 
808
 
 
809
void    *W_ReadImage(W_Window w, char *name)
 
810
{
 
811
  Drawable drawable = W_Void2Window(w)->window;
 
812
  struct S_Object *sprite = calloc(1, sizeof(struct S_Object));
 
813
  char *path;
 
814
 
 
815
  if (sprite == NULL) return NULL;
 
816
 
 
817
  GetPixmapDir();
 
818
  path = malloc(strlen(pixmapDir) + strlen(name) + 2);
 
819
  if (path == NULL) return NULL;
 
820
 
 
821
  sprintf(path, "%s/%s", pixmapDir, name);
 
822
 
 
823
  if (ReadFileToSprite(path, sprite, drawable)) {
 
824
    free(path);
 
825
    return NULL;
 
826
  }
 
827
  free(path);
 
828
  return (void *) sprite;
 
829
}
 
830
 
 
831
void    W_DrawImage(int x, int y, void *sprite_v)
 
832
{
 
833
  struct S_Object *sprite = (struct S_Object *) sprite_v;
 
834
 
 
835
  if (sprite == NULL) return;
 
836
 
 
837
  W_DrawSpriteAbsolute(sprite, x, y);
 
838
}
 
839
 
 
840
void    W_DropImage(void *sprite_v)
 
841
{
 
842
  struct S_Object *sprite = (struct S_Object *) sprite_v;
 
843
 
 
844
  if (sprite == NULL) return;
 
845
 
 
846
  XFreeGC(W_Display, sprite->gc);
 
847
  XFreePixmap(W_Display, sprite->image);
 
848
  XFreePixmap(W_Display, sprite->shape);
 
849
  free(sprite);
 
850
}