Beispiel #1
0
static void draw_gradient(Pixmap pmap, int width, int height) {
  int xx, yy;
  double cosine;
  XColor bcolour, col2, diffcol;
  Colormap cmap = DefaultColormap(display, DefaultScreen(display));
  XParseColor(display, cmap, UserWhite, &bcolour);
  XParseColor(display, cmap, UserBlack, &diffcol);

  for (yy = 0; yy < height; yy += 1) {
    if (yy < 1.0) {
      col2.red = 65535;
      col2.green = 65355;
      col2.blue = 65355;
    } else {
      if (yy < (height / 2.0)) {
        cosine = 1.0;
      } else if ((height - yy) <= 1.0) {
        cosine = 0.1;
      } else {
        cosine = 0.93;
      }
      col2.red = bcolour.red * cosine;
      col2.green = bcolour.green * cosine;
      col2.blue = bcolour.blue * cosine;
    }

    XAllocColor(display, cmap, &col2);
    XSetForeground(display, gc, col2.pixel);

    for (xx = 1; xx < width - 1; xx += 1) {
      XDrawPoint(display, pmap, gc, xx, yy);
    }

    /*Now do xx=0 and xx=width-1*/
    xx = 0;
    col2.red = 65535;
    col2.green = 65355;
    col2.blue = 65355;
    XAllocColor(display, cmap, &col2);
    XSetForeground(display, gc, col2.pixel);
    XDrawPoint(display, pmap, gc, xx, yy);
    xx = width - 1;
    cosine = 0.1;
    col2.red = bcolour.red * cosine;
    col2.green = bcolour.green * cosine;
    col2.blue = bcolour.blue * cosine;

    XAllocColor(display, cmap, &col2);
    XSetForeground(display, gc, col2.pixel);
    XDrawPoint(display, pmap, gc, xx, yy);
  }
}
Beispiel #2
0
unsigned long mixColor(char *colorname1, int prop1, char *colorname2, int prop2){
	XColor color, color1, color2;
	XWindowAttributes winattr;
	XGetWindowAttributes(d_display, w_root, &winattr);
	XParseColor(d_display, winattr.colormap, colorname1, &color1);
	XParseColor(d_display, winattr.colormap, colorname2, &color2);
	color.pixel=0;
	color.red=(color1.red*prop1+color2.red*prop2)/(prop1+prop2);
	color.green=(color1.green*prop1+color2.green*prop2)/(prop1+prop2);
	color.blue=(color1.blue*prop1+color2.blue*prop2)/(prop1+prop2);
	color.flags=DoRed | DoGreen | DoBlue;
	XAllocColor(d_display, winattr.colormap, &color);
	return color.pixel;
}
Beispiel #3
0
void Initialize()
{

    disp = XOpenDisplay(NULL); // open $DISPLAY
    win = XCreateSimpleWindow(disp,						// ディスプレイ
				DefaultRootWindow(disp),			// 親ウィンドウ
				0, 0,						// (x, y)
				640, 480,					// 幅・高さ
				0,						// border width
				0,						// border color
				WhitePixel(disp, DefaultScreen(disp)));		// background color
    XMapWindow(disp, win);

    /* ウィンドウに関連付けられたグラフィックコンテキストを作る */
    gc = XCreateGC(disp, win, 0, NULL);
    XSetForeground(disp, gc,
		   BlackPixel(disp, DefaultScreen(disp)));

    // 暴露イベントとキー押下イベントを受け取る。
    XSelectInput(disp, win, ExposureMask | KeyPressMask);

    font = XLoadQueryFont(disp, FONT);
    XSetFont(disp, gc, (font)->fid);

    Colormap colormap;
    colormap = DefaultColormap(disp, 0);

    XParseColor(disp, colormap, "#00AA00", &Color.green);
    XAllocColor(disp, colormap, &Color.green);

    XParseColor(disp, colormap, "gray50", &Color.gray50);
    XAllocColor(disp, colormap, &Color.gray50);

    XParseColor(disp, colormap, "gray80", &Color.gray80);
    XAllocColor(disp, colormap, &Color.gray80);

    XParseColor(disp, colormap, "cyan3", &Color.skyblue);
    XAllocColor(disp, colormap, &Color.skyblue);

    control_gc = XCreateGC(disp, win, 0, NULL);
    XSetFont(disp, control_gc, (font)->fid);
    XSetForeground(disp, control_gc, Color.skyblue.pixel);

    margin_gc = XCreateGC(disp, win, 0, NULL);
    XSetForeground(disp, margin_gc, Color.gray80.pixel);

    cursor_gc = XCreateGC(disp, win, 0, NULL);
    XSetForeground(disp, cursor_gc, Color.green.pixel);
}
Beispiel #4
0
static int init_colors (void)
{
    if (visualInfo.VI_CLASS == TrueColor) {
	red_bits = bitsInMask (visualInfo.red_mask);
	green_bits = bitsInMask (visualInfo.green_mask);
	blue_bits = bitsInMask (visualInfo.blue_mask);
	red_shift = maskShift (visualInfo.red_mask);
	green_shift = maskShift (visualInfo.green_mask);
	blue_shift = maskShift (visualInfo.blue_mask);
    }

    if (need_dither) {
	if (bitdepth == 1)
	    setup_greydither (1, get_color);
	else
	    setup_dither (bitdepth, get_color);
    } else {
	if (bitdepth != 8 && bitdepth != 12 && bitdepth != 15
	    && bitdepth != 16 && bitdepth != 24) {
	    write_log ("Unsupported bit depth (%d)\n", bitdepth);
	    return 0;
	}

	switch (visualInfo.VI_CLASS) {
	 case TrueColor:
	    alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,
			     green_shift, blue_shift, 0, 0, 0,
			     inverse_byte_order);

	    XParseColor (display, cmap, "#000000", &black);
	    if (! XAllocColor (display, cmap, &black))
		write_log ("Whoops??\n");
	    XParseColor (display, cmap, "#ffffff", &white);
	    if (! XAllocColor (display, cmap, &white))
		write_log ("Whoops??\n");
	    break;

	 case GrayScale:
	 case PseudoColor:
	    alloc_colors256 (get_color);
	    break;

	 default:
	    write_log ("Unsupported visual class (%d)\n", visualInfo.VI_CLASS);
	    return 0;
	}
    }
    return 1;
}
Beispiel #5
0
static WMPropList*
getColor(WMPropList *texture)
{
    WMPropList *value, *type;
    char *str;

    type = WMGetFromPLArray(texture, 0);
    if (!type)
        return NULL;

    value = NULL;

    str = WMGetFromPLString(type);
    if (strcasecmp(str, "solid")==0) {
        value = WMGetFromPLArray(texture, 1);
    } else if (strcasecmp(str, "dgradient")==0
               || strcasecmp(str, "hgradient")==0
               || strcasecmp(str, "vgradient")==0) {
        WMPropList *c1, *c2;
        int r1, g1, b1, r2, g2, b2;
        char buffer[32];

        c1 = WMGetFromPLArray(texture, 1);
        c2 = WMGetFromPLArray(texture, 2);
        if (!dpy) {
            if (sscanf(WMGetFromPLString(c1), "#%2x%2x%2x", &r1, &g1, &b1)==3
                && sscanf(WMGetFromPLString(c2), "#%2x%2x%2x", &r2, &g2, &b2)==3) {
                sprintf(buffer, "#%02x%02x%02x", (r1+r2)/2, (g1+g2)/2,
                        (b1+b2)/2);
                value = WMCreatePLString(buffer);
            } else {
                value = c1;
            }
        } else {
            XColor color1;
            XColor color2;

            XParseColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),
                        WMGetFromPLString(c1), &color1);
            XParseColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),
                        WMGetFromPLString(c2), &color2);

            sprintf(buffer, "#%02x%02x%02x",
                    (color1.red+color2.red)>>9,
                    (color1.green+color2.green)>>9,
                    (color1.blue+color2.blue)>>9);
            value = WMCreatePLString(buffer);
        }
    } else if (strcasecmp(str, "mdgradient")==0
Beispiel #6
0
int XBAllocBW( XBWindow *XBWin, PixVal *white, PixVal *black ){
	XColor  bcolor, wcolor;
	XParseColor( XBWin->disp, XBWin->cmap, "black", &bcolor );
	XParseColor( XBWin->disp, XBWin->cmap, "white", &wcolor );
	if (BlackPixel(XBWin->disp,XBWin->screen) == 0) {
		XAllocColor( XBWin->disp, XBWin->cmap, &bcolor );
		XAllocColor( XBWin->disp, XBWin->cmap, &wcolor );
    	} else {
		XAllocColor( XBWin->disp, XBWin->cmap, &wcolor );
		XAllocColor( XBWin->disp, XBWin->cmap, &bcolor );
    	}
	*black = bcolor.pixel;
	*white = wcolor.pixel;
	return 0;
}
int main()
{
  char keyboard_input[100];
  XColor black_col,white_col,red_col,green_col,blue_col,yellow_col,magenta_col,cyan_col;
  Colormap colormap;
  char black_bits[] = "#000000";
  char white_bits[] = "#FFFFFF";    // Mix red, green and blue to get white
  char red_bits[] = "#FF0000";
  char green_bits[] = "#00FF00";
  char blue_bits[] = "#0000FF";
  char yellow_bits[] = "#FFFF00";   // Mix red and green to get yellow
  char magenta_bits[] = "#FF00FF";  // A sort of purple color
  char cyan_bits[] = "#00FFFF";     // A blue-green color

  //Display *dpy = XOpenDisplay(NIL); 
  dpy = XOpenDisplay(NIL); assert(dpy);   // Open the display
  // Define the colors we want to use
  colormap = DefaultColormap(dpy, 0);
  XParseColor(dpy, colormap, black_bits, &black_col); XAllocColor(dpy, colormap, &black_col);
  XParseColor(dpy, colormap, white_bits, &white_col); XAllocColor(dpy, colormap, &white_col);
  XParseColor(dpy, colormap, red_bits, &red_col); XAllocColor(dpy, colormap, &red_col);
  XParseColor(dpy, colormap, green_bits, &green_col);XAllocColor(dpy, colormap, &green_col);
  XParseColor(dpy, colormap, blue_bits, &blue_col);XAllocColor(dpy, colormap, &blue_col);
  XParseColor(dpy, colormap, yellow_bits, &yellow_col);XAllocColor(dpy, colormap, &yellow_col);
  XParseColor(dpy, colormap, magenta_bits, &magenta_col);XAllocColor(dpy, colormap, &magenta_col);
  XParseColor(dpy, colormap, cyan_bits, &cyan_col);XAllocColor(dpy, colormap, &cyan_col);
  // Create the window  The numbers are the x and y locations on the screen, the width and height, 
  // border width (which is usually zero)
  w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, window_width, window_height,
  0, black_col.pixel, black_col.pixel);
  XSelectInput(dpy, w, StructureNotifyMask);        // We want to get MapNotify events
  XMapWindow(dpy, w);         // "Map" the window (that is, make it appear on the screen)
  for(;;){XEvent e; XNextEvent(dpy,&e); if(e.type == MapNotify) break;} //Wait for the MapNotify event
  // which means that the window has appeared on the screen.
  gc = XCreateGC(dpy, w, 0, NIL);        // Create a "Graphics Context"
  get_pen(white_col);
  //  We are finally ready to do some drawing!  Whew!  

  // ................  Students: you put your beautiful code HERE: .......................
  srand(time(NULL)); //  Get ready to make random numbers.  The time "seeds" the generator.
  int i;
  double x=0,  y=0;
  home();      // Send the turtle to the middle of the window.  That's its "home"
  get_pen(green_col);  pen_down();
  for (i=0; i<36; i++) {
    x = x + rand_range(-30.0, 30.0);  //Generates random number between these two numbers.
    y = y + rand_range(-30.0, 30.0)+5.0;
    gotoxy(x, y);   // Move the turtle to the new location.  It will draw a line if the pen is down.
    XFlush(dpy); // Tell the graphics server that it should really show us the results now.
    printf("1 x=%g y=%g heading=%g\n",turtle_x,turtle_y,turtle_heading); //Optional: use for debugging
    usleep(100000); XFlush(dpy); // Optional: use this to see the lines being drawn, one-by-one
  }
  XFlush(dpy); // Tell the graphics server that it should really show us the results now.
  sleep(1);  // Wait for 1 second
  printf("Press enter when done.\n");
  fgets (keyboard_input,100,stdin); 
  return(0);
}
Beispiel #8
0
static void parse_colors(char *s)
{
    int n = ncolors + 1 + count_char(s, ',');

    g_colors = (Uint32*)realloc(g_colors, n * sizeof(Uint32));

    // we'll need an X display for this... yuck!
    Display *dpy = XOpenDisplay(NULL);
    if (!dpy) {
        fprintf(stderr, "can't open display\n");
        exit(EXIT_FAILURE);
    }
    Colormap cmap = DefaultColormap(dpy, 0);

    // tokenize the string and parse each color
    char *p = strsep(&s, ",");
    while (p) {
        Uint32 c;
        if (strlen(p) || !ncolors) {
            XColor color;
            if (!XParseColor(dpy, cmap, p, &color)) {
                fprintf(stderr, "can't parse color: %s\n", p);
                exit(EXIT_FAILURE);
            }

            c = (color.red / 256) << 16 | (color.green / 256) << 8 | (color.blue / 256);
        } else {
            c = g_colors[ncolors - 1];
        }
        g_colors[ncolors++] = c;

        p = strsep(&s, ",");
    }
}
Beispiel #9
0
Window mktitle(wm_t *wm, Window parent, int x, int y, int width, int height) {
  Window title;
  XSetWindowAttributes title_attr;
  XWindowAttributes parent_attr;
  unsigned long valuemask;
  XColor border_color;
  Visual *visual;

  XGetWindowAttributes(wm->dpy, parent, &parent_attr);
  visual = parent_attr.screen->root_visual;

  XParseColor(wm->dpy, parent_attr.screen->cmap, "#999933", &border_color);
  XAllocColor(wm->dpy, parent_attr.screen->cmap, &border_color);
  frame_attr.border_pixel = border_color.pixel;
  frame_attr.event_mask = (ButtonPressMask | ButtonReleaseMask \
                           | EnterWindowMask | LeaveWindowMask);

  valuemask = CWEventMask | CWBorderPixel;

  frame = XCreateWindow(wm->dpy, parent,
                        x, y, width, height,
                        BORDER, CopyFromParent, CopyFromParent,
                        visual, valuemask, &frame_attr);
  wm_log(wm, LOG_INFO, "%s; Created window %d", __func__, frame);

  XSelectInput(wm->dpy, frame, FRAME_EVENT_MASK);
  return frame;
}
Beispiel #10
0
/*----------------------------------------------------------------------------*/
inline void VKAllocColorName(char *name, ulong *color)
{
	XColor c;
	XParseColor(display, colormap, name, &c);
	XAllocColor(display, colormap, &c);
	*color = c.pixel;
}
Beispiel #11
0
bool de_alloc_colour(WRootWin *rootwin, DEColour *ret, const char *name)
{
#ifdef HAVE_X11_XFT
    if(name==NULL)
        return FALSE;
    return XftColorAllocName(
        ioncore_g.dpy,
        XftDEDefaultVisual(),
        rootwin->default_cmap,
        name,
        ret);
#else /* HAVE_X11_XFT */
    XColor c;
    bool ok=FALSE;

    if(name==NULL)
        return FALSE;

    if(XParseColor(ioncore_g.dpy, rootwin->default_cmap, name, &c)){
        ok=XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c);
        if(ok)
            *ret=c.pixel;
    }
    
    return ok;
#endif /* HAVE_X11_XFT */
}
Beispiel #12
0
unsigned int
get_pixel_resource (char *res_name, char *res_class,
		    Display *dpy, Colormap cmap, unsigned int default_value)
{
  XColor color;
  char *s = get_string_resource (res_name, res_class);
  char *s2;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s\n", progname, s);
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s);
      goto DEFAULT;
    }
  free (s);
  return color.pixel;
 DEFAULT:
  if (s) free (s);
  return default_value;
}
Beispiel #13
0
unsigned int
get_pixel_resource (char *res_name, char *res_class,
		    Display *dpy, Colormap cmap)
{
  XColor color;
  char *s = get_string_resource (res_name, res_class);
  char *s2;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s\n", progname, s);
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s);
      goto DEFAULT;
    }
  free (s);
  return color.pixel;
 DEFAULT:
  if (s) free (s);
  return ((strlen(res_class) >= 10 &&
	   !strcmp ("Background", res_class + strlen(res_class) - 10))
	  ? BlackPixel (dpy, DefaultScreen (dpy))
	  : WhitePixel (dpy, DefaultScreen (dpy)));
}
Beispiel #14
0
/* create a nice curved background gradient */
static Pixmap createGradPixmap(Display *dpy, int width, int height,
			char *basecolour){
	int x = 0, y;
	double cosine, l2rads;
	XColor bcolour, col2, diffcol;
	Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy));
	Pixmap pmap;
	GC gc = dc.gc;
	Window win = DefaultRootWindow(dpy);

	width = 1;
	l2rads = M_PIl/(height);

	XParseColor(dpy, cmap, basecolour, &bcolour);
	diffcol.red = min(bcolour.red, 0xffff-bcolour.red);
	diffcol.green = min(bcolour.green, 0xffff-bcolour.green);
	diffcol.blue = min(bcolour.blue, 0xffff-bcolour.blue);
	fprintf(stderr, "height %d, width %d, %s\n", height, width, basecolour);
	
	pmap = XCreatePixmap(dpy, win, width, height, 
		DefaultDepth(dpy, DefaultScreen(dpy)));
	for(y = 0; y < height; y += 1){
		cosine = cos(l2rads * y)/2.0; /* mute it */
		col2.red = bcolour.red + diffcol.red * cosine;
		col2.green = bcolour.green + diffcol.green * cosine;
		col2.blue = bcolour.blue + diffcol.blue * cosine;
		XAllocColor(dpy, cmap, &col2);
		XSetForeground(dpy, gc, col2.pixel);
		for (x = 0; x < width; x += 1){
			XDrawPoint(dpy, pmap, gc, x, y);
		}
	}
	return pmap;
}
Beispiel #15
0
static void
set_atom_color (ModeInfo *mi, const molecule_atom *a, 
                Bool font_p, GLfloat alpha)
{
  const atom_data *d;
  GLfloat gl_color[4];

  if (a)
    d = a->data;
  else
    d = get_atom_data ("bond");

  if (font_p)
    {
      gl_color[0] = d->gl_color[4];
      gl_color[1] = d->gl_color[5];
      gl_color[2] = d->gl_color[6];
      gl_color[3] = d->gl_color[7];
    }
  else
    {
      gl_color[0] = d->gl_color[0];
      gl_color[1] = d->gl_color[1];
      gl_color[2] = d->gl_color[2];
      gl_color[3] = d->gl_color[3];
    }

  if (gl_color[3] == 0)
    {
      const char *string = !font_p ? d->color : d->text_color;
      XColor xcolor;
      if (!XParseColor (mi->dpy, mi->xgwa.colormap, string, &xcolor))
        {
          fprintf (stderr, "%s: unparsable color in %s: %s\n", progname,
                   (a ? a->label : d->name), string);
          exit (1);
        }

      gl_color[0] = xcolor.red   / 65536.0;
      gl_color[1] = xcolor.green / 65536.0;
      gl_color[2] = xcolor.blue  / 65536.0;
    }
  
  gl_color[3] = alpha;

  /* If we're not drawing atoms, and the color is black, use white instead.
     This is a kludge so that H can have black text over its white ball,
     but the text still shows up if balls are off.
   */
  if (font_p && !do_atoms &&
      gl_color[0] == 0 && gl_color[1] == 0 && gl_color[2] == 0)
    {
      gl_color[0] = gl_color[1] = gl_color[2] = 1;
    }

  if (font_p)
    glColor4f (gl_color[0], gl_color[1], gl_color[2], gl_color[3]);
  else
    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gl_color);
}
Beispiel #16
0
void init_green() {

    green_gc = XCreateGC(dis, win, 0, 0);
    XParseColor(dis, colormap, green, &green_col);
    XAllocColor(dis, colormap, &green_col);
    XSetForeground(dis, green_gc, green_col.pixel);
}
Beispiel #17
0
int
drawText(Display *d, int screen, Window *w, GC *gc, const char *str) {
    XFontStruct *font;
    XColor textColor;
    char **list;
    int textWidth, textHeight, textX, textY, returnNo;

    list = XListFonts(d, "-*-*-bold-r-normal--*-*-100-100-c-*-*", 200, &returnNo);
    if (returnNo) {
        srand(time(NULL));
        static int fontIndex = rand() % returnNo;
        font = XLoadQueryFont(d, *(list + fontIndex));
        XFreeFontNames(list);
    }

    if (!font)
        return -1;

    XParseColor(d, DefaultColormap(d, screen), text, &textColor);
    XAllocColor(d, DefaultColormap(d, screen), &textColor);
    XSetForeground(d, *gc, textColor.pixel);
    XSetBackground(d, *gc, WhitePixel(d, screen));
    XSetFont(d, *gc, font->fid);

    textWidth = XTextWidth(font, str, strlen(str));
    textHeight = font->ascent + font->descent;
    textX = (windowWidth - textWidth) / 2;
    textY = ((windowHeight - rectHeight) / 2 - textHeight) / 2 + textHeight / 2;

    XDrawImageString(d, *w, *gc, textX, textY, str, strlen(str));
    return 0;
}
Beispiel #18
0
int
main(int argc, char **argv)
{
	Display *d;
	Window w;
	XEvent e;
	XColor x;
	Colormap c;
	int s;
	if(argc < 2)
		error("not enough arguments");
	if((d = XOpenDisplay(NULL)) == NULL)
		error("cannot open display");

	s = DefaultScreen(d);
	c = DefaultColormap(d, 0);
	XParseColor(d, c, argv[1], &x);
	XAllocColor(d, c, &x);
	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, BlackPixel(d, s), x.pixel);
	XSelectInput(d, w, ExposureMask | KeyPressMask);
	XMapWindow(d, w);

	for(;;)
	{
		XNextEvent(d, &e);
		if(e.type == KeyPress)
			break;
	}

	return 0;
}
Beispiel #19
0
static Pixel
GetColor( char *name )
{
  int status;
  bool res;
  XColor color;
  XWindowAttributes attributes;

  status = XGetWindowAttributes( dockapp.display, dockapp.root_win,
				 &attributes );
  if( status == XLIB_FAILURE ) {
    fprintf( stderr, "%s: XGetWindowAttributes() failed\n", PACKAGE );
    ErrorLocation( __FILE__, __LINE__ );
    exit( EXIT_FAILURE );
  }

  color.pixel = 0;
  res = (bool) XParseColor( dockapp.display, attributes.colormap, name,
			    &color );
  if( res == false ) {
    fprintf( stderr, "%s: Can't parse %s.\n", PACKAGE, name );
    ErrorLocation( __FILE__, __LINE__ );
    exit( EXIT_FAILURE );
  }

  res = (bool) XAllocColor( dockapp.display, attributes.colormap, &color );
  if( res == false ) {
    fprintf( stderr, "%s: Can't allocate %s.\n", PACKAGE, name );
    ErrorLocation( __FILE__, __LINE__ );
    exit( EXIT_FAILURE );
  }

  return color.pixel;
}
Beispiel #20
0
static void c300_color_to_rgb(char *c_color, XColor *rgb_space) {
  int rc;
  rc=XParseColor(PictureSaveDisplay, PictureCMap, c_color, rgb_space);
  if (rc==0) {
    fprintf(stderr,"color_to_rgb: can't parse color %s, rc %d\n", c_color, rc);
    return;
  }
}
Beispiel #21
0
static Status
XAllocDisplayColor(Display *display, Colormap map, char const *colorName,
		   XColor *color, XColor *junk)
{
  return (colorName!=0 &&
	  XParseColor(display, map, colorName, color) &&
	  XAllocColor(display, map, color));
}
Beispiel #22
0
void
Colors::Define(const char * colorname, const char * color) {
	XColor temp;

	XParseColor(mShared.display, mShared.ColorMap, color, &temp);
	XAllocColor(mShared.display, mShared.ColorMap, &temp);

	ColorContainer[colorname] = temp;
}
Beispiel #23
0
/* convert the XPMIcons to XImage */
void GetXPM(void)
{
  static char **alt_xpm;
  XColor col;
  XWindowAttributes attributes;
  int ret;
  char tempc1[12],tempc2[12],tempc3[12];
  float colr,colg,colb;

  alt_xpm =ONLYSHAPE ? mask_xpm : back_xpm;

  /* for the colormap */
  XGetWindowAttributes(dpy,Root,&attributes);

  /* get user-defined color or validate the default */
  if (!XParseColor (dpy, attributes.colormap, LedColor, &col))
    {
      nocolor("parse",LedColor);
    }
  else
    {
      /* scale down the Xcolor values */
      colr = col.red   / 257;
      colg = col.green / 257;
      colb = col.blue  / 257;
      /* the brightest color */
      sprintf(tempc1, "S c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[47] = tempc1;

      /* make medium color */
      colr = (colr /100) *89;
      colg = (colg /100) *89;
      colb = (colb /100) *89;
      sprintf(tempc2, "R c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[46] = tempc2;

      /* make darkest color */
      colr = (colr /100) *89;
      colg = (colg /100) *89;
      colb = (colb /100) *89;
      sprintf(tempc3, "Q c #%.2x%.2x%.2x", (int)colr, (int)colg, (int)colb);
      back_xpm[45] = tempc3;
    }

  wmload.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
  ret = XpmCreatePixmapFromData(dpy, Root, alt_xpm, &wmload.pixmap,
				&wmload.mask, &wmload.attributes);
  if(ret != XpmSuccess)
    {fprintf(stderr, "%s\n", ERR_colorcells);exit(1);}

  visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
  ret = XpmCreatePixmapFromData(dpy, Root, back_xpm, &visible.pixmap,
				&visible.mask, &visible.attributes);
  if(ret != XpmSuccess)
    {fprintf(stderr, "%s\n", ERR_colorcells);exit(1);}

}
Beispiel #24
0
void
createGC(Display *d, Window *w, int screen, int lineWidth, GC *gc, const char *str, XColor *color) {
    *gc = XCreateGC(d, *w, 0, 0);
    XParseColor(d, DefaultColormap(d, screen), str, color);
    XAllocColor(d, DefaultColormap(d, screen), color);
    XSetForeground(d, *gc, color->pixel);
    XSetLineAttributes(d, *gc, lineWidth, LineSolid, CapRound, JoinRound);
    XSetFillStyle(d, *gc, FillSolid);
    return;
}
Beispiel #25
0
static void
do_color (char *value, char *which)
{
  XColor color;
  if (XParseColor (display, cmap, value, &color))
    if (XAllocColor (display, cmap, &color))
      {
	stdarg (which, color.pixel);
      }
}
Beispiel #26
0
unsigned long ColorGetPixel(const char *name)
{
    assert(ColorIsInitialized());

    XColor color;
    XParseColor(disp, colormap, name, &color);
    XAllocColor(disp, colormap, &color);

    return color.pixel;
}
unsigned int
get_pixel_resource (Display *dpy, Colormap cmap,
                    char *res_name, char *res_class)
{
  XColor color;
  char *s = get_string_resource (dpy, res_name, res_class);
  char *s2;
  Bool ok = True;
  if (!s) goto DEFAULT;

  for (s2 = s + strlen(s) - 1; s2 > s; s2--)
    if (*s2 == ' ' || *s2 == '\t')
      *s2 = 0;
    else
      break;

  if (! XParseColor (dpy, cmap, s, &color))
    {
      fprintf (stderr, "%s: can't parse color %s", progname, s);
      ok = False;
      goto DEFAULT;
    }
  if (! XAllocColor (dpy, cmap, &color))
    {
      fprintf (stderr, "%s: couldn't allocate color %s", progname, s);
      ok = False;
      goto DEFAULT;
    }
  free (s);
  return (unsigned int) color.pixel;
 DEFAULT:
  if (s) free (s);

  {
    Bool black_p = (strlen(res_class) >= 10 &&
                    !strcasecmp ("Background",
                                 res_class + strlen(res_class) - 10));
    if (!ok)
      fprintf (stderr, ": using %s.\n", (black_p ? "black" : "white"));
    color.flags = DoRed|DoGreen|DoBlue;
    color.red = color.green = color.blue = (black_p ? 0 : 0xFFFF);
    if (XAllocColor (dpy, cmap, &color))
      return (unsigned int) color.pixel;
    else
      {
        fprintf (stderr, "%s: couldn't allocate %s either!\n", progname,
                 (black_p ? "black" : "white"));
        /* We can't use BlackPixel/WhitePixel here, because we don't know
           what screen we're allocating on (only an issue when running inside
           the xscreensaver daemon: for hacks, DefaultScreen is fine.)
         */
        return 0;
      }
  }
}
Beispiel #28
0
static unsigned long xf_floatbar_get_color(xfFloatbar* floatbar, char* rgb_value)
{
	Colormap cmap;
	XColor color;
	Display* display = floatbar->xfc->display;
	cmap = DefaultColormap(display, XDefaultScreen(display));
	XParseColor(display, cmap, rgb_value, &color);
	XAllocColor(display, cmap, &color);
	XFreeColormap(display, cmap);
	return color.pixel;
}
Beispiel #29
0
Bool container_create_gc(container_t *container) {
  unsigned long valuemask;
  XGCValues gcv;
  XColor bg_color, fg_color;

  XParseColor(container->wm->dpy, container->screen->cmap, "#000000", &bg_color);
  XAllocColor(container->wm->dpy, container->screen->cmap, &bg_color);

  XParseColor(container->wm->dpy, container->screen->cmap, "#FFFFFF", &fg_color);
  XAllocColor(container->wm->dpy, container->screen->cmap, &fg_color);
  gcv.line_style = LineSolid;
  gcv.line_width = 1;
  gcv.fill_style = FillSolid;
  gcv.background = bg_color.pixel;
  //gcv.foreground = fg_color.pixel;
  gcv.foreground = bg_color.pixel;
  valuemask = (GCLineStyle | GCLineWidth | GCFillStyle \
               | GCForeground | GCBackground);
  container->gc = XCreateGC(container->wm->dpy, container->frame, valuemask, &gcv);
  return True;
}
Beispiel #30
0
Pixel GetColor(char *name)
{
  XColor color;
  XWindowAttributes attributes;
  XGetWindowAttributes(dpy,Root,&attributes);
  color.pixel=0;
  if (!XParseColor(dpy,attributes.colormap,name,&color))
    nocolor("parse",name);
  else if(!XAllocColor (dpy,attributes.colormap,&color))
    nocolor("alloc",name);
  return color.pixel;
}