home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume15 / twm / part01 / gc.c < prev    next >
C/C++ Source or Header  |  1988-06-12  |  6KB  |  169 lines

  1. /*****************************************************************************/
  2. /**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  3. /**                          Salt Lake City, Utah                           **/
  4. /**                                                                         **/
  5. /**                           All Rights Reserved                           **/
  6. /**                                                                         **/
  7. /**    Permission to use, copy, modify, and distribute this software and    **/
  8. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  9. /**    granted, provided that the above copyright notice appear  in  all    **/
  10. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  11. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  12. /**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  13. /**    city pertaining to distribution  of the software without  specif-    **/
  14. /**    ic, written prior permission.                                        **/
  15. /**                                                                         **/
  16. /**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  17. /**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  18. /**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  19. /**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  20. /**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  21. /**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  22. /**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  23. /**    FORMANCE OF THIS SOFTWARE.                                           **/
  24. /*****************************************************************************/
  25.  
  26. /**********************************************************************
  27.  *
  28.  * $Header: gc.c,v 1.3 88/04/15 07:09:38 tlastran Exp $
  29.  *
  30.  * Open the fonts and create the GCs
  31.  *
  32.  * 31-Mar-88 Tom LaStrange        Initial Version.
  33.  *
  34.  **********************************************************************/
  35.  
  36. #ifndef lint
  37. static char RCSinfo[]=
  38. "$Header: gc.c,v 1.3 88/04/15 07:09:38 tlastran Exp $";
  39. #endif lint
  40.  
  41. #include <stdio.h>
  42. #include "twm.h"
  43.  
  44. /***********************************************************************
  45.  *
  46.  *  Procedure:
  47.  *    CreateGCs - open fonts and create all the needed GC's.  I only
  48.  *            want to do this once, hence the first_time flag.
  49.  *
  50.  ***********************************************************************
  51.  */
  52.  
  53. void
  54. CreateGCs()
  55. {
  56.     static int first_time = TRUE;
  57.     XGCValues        gcv;
  58.     unsigned long   gcm, mask;
  59.  
  60.     if (!first_time)
  61.     return;
  62.  
  63.     first_time = FALSE;
  64.  
  65.     /* open fonts */
  66.  
  67.     TitleBarFont = XLoadQueryFont(dpy, TitleBarFontName);
  68.     TitleBarFontHeight = TitleBarFont->ascent + TitleBarFont->descent;
  69.     if (TitleBarFontHeight < TITLE_BAR_FONT_HEIGHT)
  70.     {
  71.     TitleBarY = (TITLE_BAR_FONT_HEIGHT - TitleBarFontHeight)/2 +
  72.         TITLE_BAR_SPACE + TitleBarFont->ascent;
  73.     }
  74.     else
  75.     {
  76.     TitleBarY = TITLE_BAR_SPACE + TitleBarFont->ascent;
  77.     }
  78.  
  79.     MenuFont = XLoadQueryFont(dpy, MenuFontName);
  80.     MenuFontHeight = MenuFont->ascent + MenuFont->descent;
  81.     MenuY = MenuFont->ascent + 1;
  82.  
  83.     IconFont = XLoadQueryFont(dpy, IconFontName);
  84.     IconFontHeight = IconFont->ascent + IconFont->descent;
  85.  
  86.     VersionFont = XLoadQueryFont(dpy, VersionFontName);
  87.     VersionFontHeight = VersionFont->ascent + VersionFont->descent;
  88.  
  89.     SizeFont = XLoadQueryFont(dpy, SizeFontName);
  90.     SizeFontHeight = SizeFont->ascent + SizeFont->descent;
  91.  
  92.     /* create GC's */
  93.  
  94.     if (ReverseVideo)
  95.     {
  96.     Background = BlackPixel(dpy, DefaultScreen(dpy));
  97.     Foreground = WhitePixel(dpy, DefaultScreen(dpy));
  98.     }
  99.     else
  100.     {
  101.     Foreground = BlackPixel(dpy, DefaultScreen(dpy));
  102.     Background = WhitePixel(dpy, DefaultScreen(dpy));
  103.     }
  104.     mask = Foreground ^ Background;
  105.  
  106.     gcm = 0;
  107.     gcm |= GCFont;        gcv.font = TitleBarFont->fid;
  108.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  109.     gcm |= GCForeground;    gcv.foreground = Foreground;
  110.     gcm |= GCBackground;    gcv.background = Background;
  111.  
  112.     TitleNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  113.  
  114.     gcm = 0;
  115.     gcm |= GCFont;        gcv.font = MenuFont->fid;
  116.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  117.     gcm |= GCForeground;    gcv.foreground = Foreground;
  118.     gcm |= GCBackground;    gcv.background = Background;
  119.  
  120.     MenuNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  121.  
  122.     gcv.foreground = Background;
  123.     gcv.background = Foreground;
  124.  
  125.     MenuReverseGC = XCreateGC(dpy, Root, gcm, &gcv);
  126.  
  127.     gcm = 0;
  128.     gcm |= GCFunction;        gcv.function = GXxor;
  129.     gcm |= GCFont;        gcv.font = MenuFont->fid;
  130.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  131.     gcm |= GCForeground;    gcv.foreground = mask;
  132.     gcm |= GCBackground;    gcv.background = Background;
  133.  
  134.     MenuXorGC = XCreateGC(dpy, Root, gcm, &gcv);
  135.  
  136.     gcm = 0;
  137.     gcm |= GCFunction;        gcv.function = GXxor;
  138.     gcm |= GCLineWidth;        gcv.line_width = 0;
  139.     gcm |= GCForeground;    gcv.foreground = mask;
  140.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  141.     gcm |= GCSubwindowMode; gcv.subwindow_mode = IncludeInferiors;
  142.  
  143.     DrawGC = XCreateGC(dpy, Root, gcm, &gcv);
  144.  
  145.     gcm = 0;
  146.     gcm |= GCFont;        gcv.font = IconFont->fid;
  147.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  148.     gcm |= GCForeground;    gcv.foreground = Foreground;
  149.     gcm |= GCBackground;    gcv.background = Background;
  150.  
  151.     IconNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  152.  
  153.     gcm = 0;
  154.     gcm |= GCFont;        gcv.font = VersionFont->fid;
  155.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  156.     gcm |= GCForeground;    gcv.foreground = Foreground;
  157.     gcm |= GCBackground;    gcv.background = Background;
  158.  
  159.     VersionNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  160.  
  161.     gcm = 0;
  162.     gcm |= GCFont;        gcv.font = SizeFont->fid;
  163.     gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  164.     gcm |= GCForeground;    gcv.foreground = Foreground;
  165.     gcm |= GCBackground;    gcv.background = Background;
  166.  
  167.     SizeNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  168. }
  169.