v08i092: Yet Another Bitmap Viewer, Part01/01
Robert Thompson
thompson_r at hpmtlrt.hp.com
Wed Aug 22 11:58:20 AEST 1990
Submitted-by: Robert Thompson <thompson_r at hpmtlrt.hp.com>
Posting-number: Volume 8, Issue 92
Archive-name: yabv/part01
[ Need I say more? :-) --dan ]
#---------------------------------- cut here ----------------------------------
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by <thompson_r at hpmtlrt> on Mon Aug 20 14:28:20 1990
#
# This archive contains:
# Imakefile Makefile bmv.c patchlevel.h
#
LANG=""; export LANG
PATH=/bin:/usr/bin:$PATH; export PATH
echo x - Imakefile
cat >Imakefile <<'@EOF'
LOCAL_LIBRARIES = $(XLIB)
SRCS = bmv.c
OBJS = bmv.o
ComplexProgramTarget(bmv)
@EOF
chmod 666 Imakefile
echo x - Makefile
cat >Makefile <<'@EOF'
SRCS= bmv.c
OBJS= bmv.o
CC= cc
CFLAGS= -O
LIBS= -lX11
all: bmv
bmv:
cc $(CFLAGS) $@.c -o $@ $(LIBS)
@EOF
chmod 666 Makefile
echo x - bmv.c
cat >bmv.c <<'@EOF'
#include <X11/XHPlib.h>
#include <X11/X.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include "patchlevel.h"
typedef struct {
Pixmap pmap;
char name[64];
int x;
int y;
int width;
int height;
} Image;
Image image[256];
int numbms;
main(argc,argv)
int argc;
char **argv;
{
register int counter,status;
int xh,yh;
int maxheight = 0;
int nextx = 0;
int nexty = 30;
int lasty = 0;
GC gc;
Window w;
Display *disp;
XGCValues values;
Font font;
if (argc < 2)
{
printf ("usage: %s file1 [file 2] ... [file 256]\n",argv[0]);
exit(0);
}
else
numbms = argc;
disp = XOpenDisplay("");
font = XLoadFont(disp,"vtbold");
w = XCreateSimpleWindow(disp,
RootWindow(disp,DefaultScreen(disp)),
0,0,900,800,
10,
0x000000,
0x2a5a7b);
XStoreName(disp,w,"Bitmap Viewer v1.0");
XSetIconName(disp,w,"BMV V1.0");
values.foreground = 0x000000;
values.background = 0xffffff;
values.function = GXcopy;
values.font = font;
gc = XCreateGC(disp,w,
GCFunction|GCForeground|GCBackground|GCFont,&values);
for (counter=1;counter < argc;counter++) {
status = XReadBitmapFile(disp,w,argv[counter],
&image[counter].width,
&image[counter].height,
&image[counter].pmap,&xh,&yh);
if (status != BitmapSuccess)
fprintf (stderr,"Could not load %s\n",argv[counter]);
else
{
if (nextx > 900 - image[counter].width)
{
nexty = lasty + maxheight + 2;
lasty = nexty;
nextx = 0;
maxheight = 0;
}
strcpy(image[counter].name,argv[counter]);
XCopyPlane(disp, image[counter].pmap,w, gc, 0,0,
image[counter].width,
image[counter].height,
nextx,nexty,
1);
image[counter].x = nextx;
image[counter].y = nexty;
maxheight = (image[counter].height > maxheight ?
image[counter].height:maxheight);
nextx += image[counter].width + 2;
}
}
XMapWindow(disp,w);
XSelectInput(disp,w, ButtonPressMask|ExposureMask|
VisibilityChangeMask|KeyPressMask);
for (;;)
{
XEvent ev;
XNextEvent(disp,&ev);
switch (ev.type) {
case ButtonPress:
if (!FindBitmap(disp,w,ev,gc))
break;
case KeyPress:
{
for (counter = 1;counter < argc;counter ++)
XFreePixmap(disp,image[counter].pmap);
exit(0);
}
case MapNotify:
case Expose:
for (counter = 1;counter < argc;counter ++)
{
XCopyPlane(disp,
image[counter].pmap,w,
gc,
0,0,
image[counter].width,
image[counter].height,
image[counter].x,
image[counter].y,
1);
}
break;
}
}
}
int FindBitmap(disp,win,event,gc)
Display *disp;
Window win;
XEvent event;
GC gc;
{
int x = event.xbutton.x;
int y = event.xbutton.y;
register int i;
char buf[128];
for (i = 1;i < numbms;i++)
if ( x >= image[i].x &&
y >= image[i].y &&
x <= image[i].x+image[i].width &&
y <= image[i].y+image[i].height) break;
switch (event.xbutton.button)
{
case 1:
XClearArea(disp,win,0,0,900,29);
sprintf(buf,"That bitmap is called: %s",image[i].name);
XDrawString(disp,win,gc,20,20,buf,strlen(buf));
break;
case 2:
sprintf (buf,"bitmap -nodashed %s",image[i].name);
system(buf);
break;
case 3:
return (-1);
}
return(0);
}
@EOF
chmod 666 bmv.c
echo x - patchlevel.h
cat >patchlevel.h <<'@EOF'
#define PATCHLEVEL 0
@EOF
chmod 666 patchlevel.h
exit 0
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list