73
75
extern int takeNearest;
75
77
extern Display *W_Display;
76
struct window *mylocal;
79
79
const char teamnames[NUMTEAM + 1][4] =
80
80
{"Ind", "Fed", "Rom", "Kli", "Ori"};
82
82
const char mplanetfiles[NUM_PL_IMGS][12] =
95
95
const char shipfiles[NUM_TYPES][8] =
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] =
121
int ReadFileToSprite(char *filename, struct S_Object *sprite, W_Window * w)
122
static int ReadFileToSprite(char *filename, struct S_Object *sprite, Drawable drawable)
126
struct window *win = W_Void2Window(mylocal);
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;
136
if (XpmReadFileToPixmap(W_Display, win->window, filename, &sprite->image,
137
&sprite->shape, &attr) != XpmSuccess)
139
if (!(pixMissing & NO_PIXMAPS))
140
fprintf(stderr, "Unable to read file %s.\n", filename);
141
sprite->image = NoPixmapError;
146
for (k = 0; k < attr.nextensions; k++)
148
if (strcmpi(attr.extensions[0].name, "num_views") == 0)
149
nviews = atoi(attr.extensions[0].lines[0]);
156
guess = (int) ((attr.height) / (attr.width));
157
if (guess == (attr.height) / (attr.width))
163
if (!(pixMissing & NO_PIXMAPS))
164
fprintf(stderr, "NUM_VIEWS not suppied in %s. Unable to estimate ...\n",
166
sprite->image = NoPixmapError;
125
int width, height, nviews;
127
if (access(filename, R_OK) != 0) {
128
fprintf(stderr, "image %s is not readable\n", filename);
132
im = imlib_load_image(filename);
134
fprintf(stderr, "image %s failed to load\n", filename);
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);
145
width = imlib_image_get_width();
146
height = imlib_image_get_height();
147
nviews = height / width;
148
if (nviews * width != height) {
152
sprite->drawable = drawable;
173
153
sprite->gc = XCreateGC(W_Display, sprite->image, 0, NULL);
174
155
sprite->nviews = nviews;
175
sprite->width = attr.width;
176
sprite->height = (attr.height) / nviews;
181
int ReadFileToTile(char *filename, Pixmap * pix)
184
struct window *win = W_Void2Window(mylocal);
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;
193
if (XpmReadFileToPixmap(W_Display, win->window, filename, pix, NULL, &attr)
196
if (!(pixMissing & NO_PIXMAPS))
197
fprintf(stderr, "Unable to read file %s.\n", filename);
198
*pix = NoPixmapError;
205
void GetPixmaps(Display * d, struct window *win)
208
char buf[1024], pixmapDir[1024];
156
sprite->width = width;
157
sprite->height = height / nviews;
160
fprintf(stderr, "image %s loaded, nv=%d w=%d h=%d (%d)\n", filename,
161
nviews, width, height, sprite->height);
163
imlib_free_image_and_decache();
167
sprite->image = NoPixmapError;
172
int ReadFileToTile(char *filename, Pixmap *pix, Drawable drawable)
176
if (access(filename, R_OK) != 0) {
177
fprintf(stderr, "image %s is not readable\n", filename);
181
im = imlib_load_image(filename);
183
fprintf(stderr, "image %s failed to load\n", filename);
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);
194
fprintf(stderr, "tile %s loaded, w=%d h=%d\n", filename,
195
imlib_image_get_width(), imlib_image_get_height());
197
imlib_free_image_and_decache();
201
*pix = NoPixmapError;
205
static char pixmapDir[1024] = { '\0' };
207
static void GetPixmapDir()
211
if (pixmapDir[0] != '\0') return;
215
213
pd = getdefault("pixmapDir");
216
214
if (pd != (char *) NULL)
217
strcpy(pixmapDir, pd);
215
strncpy(pixmapDir, pd, 1024);
219
217
strcpy(pixmapDir, "/usr/share/pixmaps/netrek-client-cow");
221
if ((strcmpi(pixmapDir, "None") == 0) || (pixMissing & NO_PIXMAPS))
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");
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");
232
if ((stat(pixmapDir, &buf)) || (!(S_ISDIR(buf.st_mode))))
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");
241
pixmap_gc = XCreateGC(W_Display, win->window, 0, NULL);
233
fprintf(stderr, "pixmaps not here\n");
235
strcpy(pixmapDir, "pixmaps");
241
void GetPixmaps(Display * d, struct window *win, W_Window t, W_Window g)
247
Drawable tactical = W_Void2Window(t)->window;
248
Drawable galactic = W_Void2Window(g)->window;
243
253
for (i = 0; i < NUMTEAM + 1; i++)
678
712
W_ClearWindow(w);
680
#endif /* HAVE_XPM */
715
void W_SetBackground(W_Window w, int which)
717
struct window *win = W_Void2Window(w);
719
if ((backPix[which] == NoPixmapError) || (pixFlags & NO_BG_PIX))
722
XSetWindowBackgroundPixmap(W_Display, win->window, backPix[which]);
727
void *W_SetBackgroundImage(W_Window w, char *name)
729
Drawable drawable = W_Void2Window(w)->window;
730
struct S_Object *sprite = calloc(1, sizeof(struct S_Object));
733
if (sprite == NULL) return NULL;
736
path = malloc(strlen(pixmapDir) + strlen(name) + 2);
737
if (path == NULL) return NULL;
739
sprintf(path, "%s/%s", pixmapDir, name);
741
if (ReadFileToSprite(path, sprite, drawable)) {
747
XSetWindowBackgroundPixmap(W_Display, drawable, sprite->image);
749
return (void *) sprite;
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;
757
static void ss_init(W_Window w)
759
char *path, *argv[2];
762
Drawable drawable = W_Void2Window(w)->window;
764
if (ss != NULL) return;
768
path = malloc(strlen(pixmapDir) + 4);
769
sprintf(path, "%s/ss", pixmapDir);
774
ss = (struct S_Object *) malloc(ss_size * sizeof(struct S_Object));
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;
783
if (ss_next >= ss_size) {
785
ss = realloc(ss, ss_size * sizeof(struct S_Object));
792
void W_NextScreenShot(W_Window w, int x, int y)
795
if (ss_next == 0) return;
796
W_ClearSpriteAbsolute(&ss[ss_show], x, y);
798
if (ss_show >= ss_next) ss_show=0;
799
W_DrawSpriteAbsolute(&ss[ss_show], x, y);
802
void W_DrawScreenShot(W_Window w, int x, int y)
805
if (ss_next == 0) return;
806
W_DrawSpriteAbsolute(&ss[ss_show], x, y);
809
void *W_ReadImage(W_Window w, char *name)
811
Drawable drawable = W_Void2Window(w)->window;
812
struct S_Object *sprite = calloc(1, sizeof(struct S_Object));
815
if (sprite == NULL) return NULL;
818
path = malloc(strlen(pixmapDir) + strlen(name) + 2);
819
if (path == NULL) return NULL;
821
sprintf(path, "%s/%s", pixmapDir, name);
823
if (ReadFileToSprite(path, sprite, drawable)) {
828
return (void *) sprite;
831
void W_DrawImage(int x, int y, void *sprite_v)
833
struct S_Object *sprite = (struct S_Object *) sprite_v;
835
if (sprite == NULL) return;
837
W_DrawSpriteAbsolute(sprite, x, y);
840
void W_DropImage(void *sprite_v)
842
struct S_Object *sprite = (struct S_Object *) sprite_v;
844
if (sprite == NULL) return;
846
XFreeGC(W_Display, sprite->gc);
847
XFreePixmap(W_Display, sprite->image);
848
XFreePixmap(W_Display, sprite->shape);