home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / tron / part02 / texter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-21  |  4.1 KB  |  152 lines

  1. /*     This program was written by Helmut Hoenig    */
  2. /*        in May of 1988 at the Unitversity of        */
  3. /*   Kaiserslautern, Germany. It may be copied freely.    */
  4.  
  5. #include <X11/Xlib.h>
  6. #include <stdio.h>
  7.  
  8. #include "header.h"
  9.  
  10. /*****************************
  11.  * externe globale Variablen *
  12.  *****************************/
  13.  
  14. extern    Display    *display;
  15. extern    Screen    *screen;
  16.  
  17. extern    XEvent    event;
  18. Window    aw;                /* Eingabe-/Ausgabefenster */
  19.  
  20. GC    gc_copy,gc_copyInverted;    /* Graphik-Kontexte */
  21. GC    gc_or,gc_orInverted,gc_xor;
  22. GC    gc_clear,gc_set;
  23. GC    gc_filler;
  24. GC    gc_root;
  25.  
  26. #define    MAXID    2
  27.  
  28. XFontStruct    *finfo[MAXID];        /* Zeiger auf FontInfo-Strukturen der geladenen Fonts */
  29. int        floaded[MAXID];
  30.  
  31. /**************
  32.  * Prozeduren *
  33.  **************/
  34.  
  35. openfont(name,fid)        /*f font <name> eroeffnen mit Nummer <fid> */
  36.     char    *name;
  37.     int    fid;
  38.     
  39. {    if ((fid >= 0) && (fid < MAXID))
  40.     {    closefont(fid);
  41.         if ((finfo[fid]=XLoadQueryFont(display,name)) == NULL)
  42.         {    fprintf(stderr,"** Unable to load font %s\n",name);
  43.             exit(-1);
  44.         };
  45.         floaded[fid]=1;
  46.     };
  47. }
  48.  
  49. closefont(fid)        /*f font mit Nummer <fid> schliessen */
  50.     int    fid;
  51.     
  52. {    if ((fid >=0) && (fid < MAXID))
  53.         if (floaded[fid]==1)    
  54.         {    XFreeFont(display,finfo[fid]);
  55.             floaded[fid]=0;
  56.         }
  57. }
  58.  
  59. init_texter()
  60. {
  61. int    reverse;
  62. int    mw=XRootWindowOfScreen(screen);
  63.  
  64.     openfont(FONT_NAME,0);
  65.     reverse = (XBlackPixelOfScreen(screen)==0)?1:0;
  66.  
  67. /* Standard-GC setzen */
  68.     gc_copy = DefaultGCOfScreen(screen);
  69.     XSetState(display,gc_copy,1,0,(reverse)?GXcopyInverted:GXcopy,AllPlanes);
  70.     XSetLineAttributes(display,gc_copy,0,LineSolid,CapButt,JoinBevel);
  71.     XSetGraphicsExposures(display,gc_copy,0);
  72.  
  73. /* Invers-GC setzen */
  74.     gc_copyInverted=XCreateGC(display,mw,(unsigned long)0,NULL);
  75.     XCopyGC(display,gc_copy,(long)-1,gc_copyInverted);
  76.     XSetFunction(display,gc_copyInverted,(reverse)?GXcopy:GXcopyInverted);
  77.  
  78. /* GC_clear setzen */
  79.     gc_clear=XCreateGC(display,mw,(unsigned long)0,NULL);
  80.     XCopyGC(display,gc_copy,(long)-1,gc_clear);
  81.     XSetFunction(display,gc_clear,(reverse)?GXset:GXclear);
  82.  
  83. /* GC_set setzen */
  84.     gc_set=XCreateGC(display,mw,(unsigned long)0,NULL);
  85.     XCopyGC(display,gc_copy,(long)-1,gc_set);
  86.     XSetFunction(display,gc_set,(reverse)?GXclear:GXset);
  87.  
  88. /* OR-GC setzen */
  89.     gc_or=XCreateGC(display,mw,(unsigned long)0,NULL);
  90.     XCopyGC(display,gc_copy,(long)-1,gc_or);
  91.     XSetFunction(display,gc_or,(reverse)?GXandInverted:GXor);
  92.     XSetFont(display,gc_or,finfo[0]->fid);
  93.  
  94. /* ORInverted-GC setzen */
  95.     gc_orInverted=XCreateGC(display,mw,(unsigned long)0,NULL);
  96.     XCopyGC(display,gc_or,(long)-1,gc_orInverted);
  97.     XSetFunction(display,gc_orInverted,(reverse)?GXor:GXandInverted);
  98.  
  99. /* XOR-GC setzen */
  100.     gc_xor=XCreateGC(display,mw,(unsigned long)0,NULL);
  101.     XCopyGC(display,gc_copy,(long)-1,gc_xor);
  102.     XSetFunction(display,gc_xor,GXxor);
  103.  
  104. /* root-GC setzen */
  105.     gc_root=XCreateGC(display,mw,(unsigned long)0,NULL);
  106.     XCopyGC(display,gc_xor,(long)-1,gc_root);
  107.     XSetSubwindowMode(display,gc_root,IncludeInferiors);
  108.  
  109. /* filler-GC setzen */
  110.     gc_filler=XCreateGC(display,mw,(unsigned long)0,NULL);
  111.     XCopyGC(display,gc_copy,(long)-1,gc_filler);
  112.     XSetFunction(display,gc_filler,(reverse)?GXcopyInverted:GXcopy);
  113.     XSetFillStyle(display,gc_filler,FillTiled);
  114.     XSetTSOrigin(display,gc_filler,0,0);
  115. }
  116.  
  117. printcleared(x,y,string,fid)    /*f Text an Zeichenposition x,y ausgeben (Hintergrund wird geloescht) */
  118.     int    x,y,fid;
  119.     char    *string;
  120. {
  121.     XFillRectangle(display,aw,gc_clear,x * CharWidth(fid),y * CharHeight(fid),StringWidth(string,fid),CharHeight(fid));
  122.     printat(x,y,string,fid);
  123. }
  124.  
  125. printat(x,y,string,fid)        /*f Text an Zeichenposition x,y ausgeben */
  126.     int    x,y,fid;
  127.     char    *string;
  128. {
  129.     XSetFont(display,gc_or,finfo[fid]->fid);
  130.     XDrawString(display,aw,gc_or,
  131.             x * CharWidth(fid),y * CharHeight(fid) + finfo[fid]->ascent,string,strlen(string));
  132. }
  133.  
  134. print(x,y,string,fid)        /*f Text an Position x,y ausgeben */
  135.     int    x,y,fid;
  136.     char    *string;
  137. {
  138.     XSetFont(display,gc_or,finfo[fid]->fid);
  139.     XDrawString(display,aw,gc_or,
  140.             x,y+finfo[fid]->ascent,string,strlen(string));
  141. }
  142.  
  143. text(x,y,string,fid)        /*f Text zentriert ausgeben (Hintergrund loeschen) */
  144.     int    x,y,fid;
  145.     char    *string;
  146.  
  147. {    int    xs,ys;
  148.     
  149.     XSetFont(display,gc_or,finfo[fid]->fid);
  150.     XDrawString(display,aw,gc_or,x-(StringWidth(string,fid)>>1),y+(finfo[fid]->ascent>>1),string,strlen(string));
  151. }
  152.