home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xpool-10.zip / Xpool / color.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  3KB  |  143 lines

  1.  
  2. /* I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400
  3.                 Golden,    CO,   USA. 80401
  4.  
  5.  
  6.   Copyright (C) 1992 Ismail ARIT
  7.  
  8.   This file  is distributed in the hope that it will be useful,
  9.   but without any warranty.  No author or distributor accepts
  10.   responsibility to anyone for the consequences of using it or for
  11.   whether it serves any particular purpose or works at all.
  12.  
  13.  
  14.   Everyone is granted permission to copy, modify and redistribute
  15.   this file under the following conditions:
  16.  
  17.      Permission is granted to anyone to make or distribute copies
  18.      of the source code, either as received or modified, in any
  19.      medium, provided that all copyright notices, permission and
  20.      nonwarranty notices are preserved, and that the distributor
  21.      grants the recipient permission for further redistribution as
  22.      permitted by this document.
  23.      No part of this program can be used in any commercial product.
  24.  
  25. */
  26.  
  27.  
  28. #include  <X11/Xlib.h>
  29. #include  <X11/Xutil.h>
  30.  
  31.  
  32. extern  Display * disp;
  33. extern  Colormap Cmap;
  34. extern  GC gc;
  35.  
  36.  
  37. unsigned long   Pixels[66];
  38.  
  39. char   *ColorNames[] =
  40. {
  41.     "Black", "Thistle", "SeaGreen", "PaleGreen",
  42.     "YellowGreen", "SkyBlue", "VioletRed",
  43.     "MediumVioletRed", "Red", "ForestGreen", "Blue", "Green",
  44.     "Khaki", "LightBlue", "Pink", "GreenYellow", "MediumSpringGreen",
  45.     "MediumTurquoise", "SkyBlue", "DarkTurquoise", "SlateBlue",
  46.     "VioletRed", "OrangeRed", "Red", "FireBrick", "Maroon", "Magenta",
  47.     "DarkSlateBlue", "LimeGreen", "Magenta", "Maroon", "MidnightBlue",
  48.     "Navy", "Orange", "Orchid", "Pink", "SkyBlue", "SpringGreen",
  49.     "SteelBlue", "Tan", "Thistle", "Turquoise", "Violet", "Wheat", "White",
  50.     "Yellow"
  51. };
  52.  
  53. setcolor_with_name (fg_name, bg_name)
  54. char    fg_name[];
  55. char    bg_name[];
  56. {
  57.     int     i = 0;
  58.  
  59.     /* 
  60.      while((strcmp(fg_name, ColorNames[i] ) != 0) && ( i < 66))
  61.      { i++ ;} 
  62.      if ( i < 66 ) 
  63.      {
  64.      XSetForeground( disp, gc,Pixels[i] );
  65.      }
  66.      i=0;
  67.      while((strcmp(bg_name,ColorNames[i] ) != 0) && (i < 66))
  68.      {i++;}
  69.      if( i < 66 )
  70.      {
  71.      XSetBackground(disp,gc,Pixels[i] );
  72.      }
  73.      */
  74.  
  75. }
  76.  
  77. int     get_color (name)
  78. char   *name;
  79. {
  80.     XColor exact, color;
  81.  
  82.     XAllocNamedColor (disp, Cmap, name, &color, &exact);
  83.     return (color.pixel);
  84. }
  85.  
  86.  
  87. setcolor (int color) {
  88.     XSetForeground (disp, gc, color);
  89. };
  90.  
  91. setbkcolor (int color) {
  92.     XSetBackground (disp, gc, color);
  93. };
  94.  
  95.  
  96. init_colors () {
  97.     XColor RGBColor, HardwareColor;
  98.  
  99.     int     Stat,
  100.             ii;
  101. /* I was using this for another project, don't need this for now */
  102.  
  103. /*
  104.    if ( DefaultDepth(disp) > 1)
  105.    {
  106.       for (ii = 0; ii < 66; ii++ )
  107.       { 
  108.          Stat = XLookupColor( disp,
  109.                      Cmap, ColorNames[ii],
  110.                      &RGBColor,&HardwareColor );
  111.          if( Stat  != 0)
  112.                         {  
  113.             Stat = XAllocColor( disp,
  114.                         Cmap,&HardwareColor);
  115.  
  116.             if (Stat != 0)
  117.                Pixels[ii] = HardwareColor.pixel;
  118.             else
  119.                Pixels[ii] = BlackPixel(disp,DefaultScreen(disp)); 
  120.                          }
  121.       }
  122.    }
  123.    else  
  124.    { 
  125.       for( ii =0; ii < 66; ii++)
  126.       { 
  127.          if( strcmp( "white", ColorNames[ii] ) == 0)
  128.            Pixels [ii] = WhitePixel(disp,DefaultScreen(disp)); 
  129.          else
  130.            Pixels [ ii ] = BlackPixel(disp,DefaultScreen(disp)); 
  131.       }
  132.    }
  133.  
  134.  */
  135.  
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.