home *** CD-ROM | disk | FTP | other *** search
- /* This program was written by Helmut Hoenig */
- /* in May of 1988 at the Unitversity of */
- /* Kaiserslautern, Germany. It may be copied freely. */
-
- #include <X11/Xlib.h>
- #include <stdio.h>
-
- #include "header.h"
-
- /*****************************
- * externe globale Variablen *
- *****************************/
-
- extern Display *display;
- extern Screen *screen;
-
- extern XEvent event;
- Window aw; /* Eingabe-/Ausgabefenster */
-
- GC gc_copy,gc_copyInverted; /* Graphik-Kontexte */
- GC gc_or,gc_orInverted,gc_xor;
- GC gc_clear,gc_set;
- GC gc_filler;
- GC gc_root;
-
- #define MAXID 2
-
- XFontStruct *finfo[MAXID]; /* Zeiger auf FontInfo-Strukturen der geladenen Fonts */
- int floaded[MAXID];
-
- /**************
- * Prozeduren *
- **************/
-
- openfont(name,fid) /*f font <name> eroeffnen mit Nummer <fid> */
- char *name;
- int fid;
-
- { if ((fid >= 0) && (fid < MAXID))
- { closefont(fid);
- if ((finfo[fid]=XLoadQueryFont(display,name)) == NULL)
- { fprintf(stderr,"** Unable to load font %s\n",name);
- exit(-1);
- };
- floaded[fid]=1;
- };
- }
-
- closefont(fid) /*f font mit Nummer <fid> schliessen */
- int fid;
-
- { if ((fid >=0) && (fid < MAXID))
- if (floaded[fid]==1)
- { XFreeFont(display,finfo[fid]);
- floaded[fid]=0;
- }
- }
-
- init_texter()
- {
- int reverse;
- int mw=XRootWindowOfScreen(screen);
-
- openfont(FONT_NAME,0);
- reverse = (XBlackPixelOfScreen(screen)==0)?1:0;
-
- /* Standard-GC setzen */
- gc_copy = DefaultGCOfScreen(screen);
- XSetState(display,gc_copy,1,0,(reverse)?GXcopyInverted:GXcopy,AllPlanes);
- XSetLineAttributes(display,gc_copy,0,LineSolid,CapButt,JoinBevel);
- XSetGraphicsExposures(display,gc_copy,0);
-
- /* Invers-GC setzen */
- gc_copyInverted=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_copyInverted);
- XSetFunction(display,gc_copyInverted,(reverse)?GXcopy:GXcopyInverted);
-
- /* GC_clear setzen */
- gc_clear=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_clear);
- XSetFunction(display,gc_clear,(reverse)?GXset:GXclear);
-
- /* GC_set setzen */
- gc_set=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_set);
- XSetFunction(display,gc_set,(reverse)?GXclear:GXset);
-
- /* OR-GC setzen */
- gc_or=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_or);
- XSetFunction(display,gc_or,(reverse)?GXandInverted:GXor);
- XSetFont(display,gc_or,finfo[0]->fid);
-
- /* ORInverted-GC setzen */
- gc_orInverted=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_or,(long)-1,gc_orInverted);
- XSetFunction(display,gc_orInverted,(reverse)?GXor:GXandInverted);
-
- /* XOR-GC setzen */
- gc_xor=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_xor);
- XSetFunction(display,gc_xor,GXxor);
-
- /* root-GC setzen */
- gc_root=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_xor,(long)-1,gc_root);
- XSetSubwindowMode(display,gc_root,IncludeInferiors);
-
- /* filler-GC setzen */
- gc_filler=XCreateGC(display,mw,(unsigned long)0,NULL);
- XCopyGC(display,gc_copy,(long)-1,gc_filler);
- XSetFunction(display,gc_filler,(reverse)?GXcopyInverted:GXcopy);
- XSetFillStyle(display,gc_filler,FillTiled);
- XSetTSOrigin(display,gc_filler,0,0);
- }
-
- printcleared(x,y,string,fid) /*f Text an Zeichenposition x,y ausgeben (Hintergrund wird geloescht) */
- int x,y,fid;
- char *string;
- {
- XFillRectangle(display,aw,gc_clear,x * CharWidth(fid),y * CharHeight(fid),StringWidth(string,fid),CharHeight(fid));
- printat(x,y,string,fid);
- }
-
- printat(x,y,string,fid) /*f Text an Zeichenposition x,y ausgeben */
- int x,y,fid;
- char *string;
- {
- XSetFont(display,gc_or,finfo[fid]->fid);
- XDrawString(display,aw,gc_or,
- x * CharWidth(fid),y * CharHeight(fid) + finfo[fid]->ascent,string,strlen(string));
- }
-
- print(x,y,string,fid) /*f Text an Position x,y ausgeben */
- int x,y,fid;
- char *string;
- {
- XSetFont(display,gc_or,finfo[fid]->fid);
- XDrawString(display,aw,gc_or,
- x,y+finfo[fid]->ascent,string,strlen(string));
- }
-
- text(x,y,string,fid) /*f Text zentriert ausgeben (Hintergrund loeschen) */
- int x,y,fid;
- char *string;
-
- { int xs,ys;
-
- XSetFont(display,gc_or,finfo[fid]->fid);
- XDrawString(display,aw,gc_or,x-(StringWidth(string,fid)>>1),y+(finfo[fid]->ascent>>1),string,strlen(string));
- }
-