⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcolor.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   (C) 2001 by Argonne National Laboratory.       See COPYRIGHT in top-level directory.*/#include "mpe_graphics_conf.h"#include "mpetools.h"#include "basex11.h"#include "baseclr.h"/* This is used to correct system header files without prototypes */#if defined(NEEDS_STDLIB_PROTOTYPES)#include "protofix.h"#endif/*    This file contains routines to provide color support where available.    This is made difficult by the wide variety of color implementations    that X11 supports, and the failure of the X consortium to recognize    until very recently that window managers must have a minimum,    standardized interface that includes color (and window mapping,    mouse control, ...  ) *//* for some reason, this isn't included by the X11 includes */#include <X11/Xatom.h>int XBHlsHelper ( int, int, int );/* cmap is ignored for now? */void XBInitColors( XBWin, cmap, nc )XBWindow *XBWin;Colormap cmap;int      nc;{    PixVal   white_pixel, black_pixel;/* reset the number of colors from info on the display *//* This is wrong; it needs to take the value from the visual *//* Also, I'd like to be able to set this so as to force B&W behaviour   on color displays */    if (nc > 0) 	XBWin->numcolors = nc;    else	XBWin->numcolors = 1 << DefaultDepth( XBWin->disp, XBWin->screen );/* we will use the default colormap of the visual */    if (!XBWin->cmap)	XBWin->cmap = XBCreateColormap( XBWin->disp, XBWin->screen, XBWin->vis );/* get the initial colormap */    if (XBWin->numcolors > 2)	XBInitCmap( XBWin );    else {	/* note that the 1-bit colormap is the DEFAULT map */	white_pixel     = WhitePixel(XBWin->disp,XBWin->screen);	black_pixel     = BlackPixel(XBWin->disp,XBWin->screen);	/* the default "colormap"; the mapping from color indices to 	   X pixel values */	XBWin->cmapping[BLACK]   = black_pixel;	XBWin->cmapping[WHITE]   = white_pixel;	XBWin->foreground        = black_pixel;	XBWin->background        = white_pixel;    }}/*    Set the initial color map */int XBInitCmap( XBWin )XBWindow *XBWin;{    XColor  colordef;    int     i;/* Also, allocate black and white first, in the same order that   there "pixel" values are, incase the pixel values assigned   start from 0 */    XBAllocBW( XBWin, &XBWin->cmapping[WHITE], &XBWin->cmapping[BLACK] );    XBWin->background = XBWin->cmapping[WHITE];    XBWin->foreground = XBWin->cmapping[BLACK];/* Look up the colors so that they can be use server standards   (and be corrected for the monitor) */    for (i=2; i<16; i++) {	XParseColor( XBWin->disp, XBWin->cmap, colornames[i], &colordef );	XAllocColor( XBWin->disp, XBWin->cmap, &colordef );	XBWin->cmapping[i]   = colordef.pixel;    }    XBWin->maxcolors = 15;    return 0;}/* * The input to this routine is RGB, not HLS. * X colors are 16 bits, not 8, so we have to shift the input by 8. */int XBCmap( red, green, blue, mapsize, XBWin )int           mapsize;unsigned char red[], green[], blue[];XBWindow      *XBWin;{    int         i, err;    XColor      colordef;    PixVal      white_pixel, black_pixel, pix, white_pix, black_pix;    white_pixel     = WhitePixel(XBWin->disp,XBWin->screen);    black_pixel     = BlackPixel(XBWin->disp,XBWin->screen);/*    Free the old colors if we have the colormap. */    if (XBWin->cmap != DefaultColormap( XBWin->disp, XBWin->screen ) ) {	if (XBGetVisualClass( XBWin ) == PseudoColor ||	    XBGetVisualClass( XBWin ) == DirectColor )	    XFreeColors( XBWin->disp, XBWin->cmap, XBWin->cmapping,			 XBWin->maxcolors + 1, (unsigned long)0 );    }/*   The sun convention is that 0 is the background and 2**depth-1 is   foreground.  We make these the Xtools conventions (ignoring foreground)  */    if (mapsize > XBWin->numcolors) mapsize = XBWin->numcolors;    XBWin->maxcolors = mapsize - 1;/*  Now, set the color values    Since it is hard (impossible?) to insure that black and white are    allocated to the SAME pixel values in the default/window manager    colormap, we ALWAYS allocate black and white FIRST    Note that we may have allocated more than mapsize colors if the    map did not include black or white.  We need to handle this later. */    XBAllocBW( XBWin, &white_pix, &black_pix );    err = 0;    for (i=0; i<mapsize; i++) {	if (red[i] == 0 && green[i] == 0 && blue[i] == 0)	    XBWin->cmapping[i]   = black_pix;	else if (red[i] == 255 && green[i] == 255 && blue[i] == 255)	    XBWin->cmapping[i]   = white_pix;	else {	    colordef.red    = ((int)red[i]   * 65535) / 255;	    colordef.green  = ((int)green[i] * 65535) / 255;	    colordef.blue   = ((int)blue[i]  * 65535) / 255;	    colordef.flags  = DoRed | DoGreen | DoBlue;	    if (!XAllocColor( XBWin->disp, XBWin->cmap, &colordef ))		err = 1;	    XBWin->cmapping[i]   = colordef.pixel;	}	/* printf( "pixel value for %d is %d\n\r", i, XBWin->cmap[i] ); */    }/* make sure that there are 2 different colors */    pix             = XBWin->cmapping[0];    for (i=1; i<mapsize; i++)	if (pix != XBWin->cmapping[i]) break;    if (i >= mapsize) {	/* no different colors */	if (XBWin->cmapping[0] != black_pixel)	    XBWin->cmapping[0]   = black_pixel;	else	    XBWin->cmapping[0]   = white_pixel;    }/*    The window needs to be told the new background pixel so that things    like XClearArea will work    Note that this should not be called until the window is actually    created. */    if (XBWin->win)	XSetWindowBackground( XBWin->disp, XBWin->win, XBWin->cmapping[0] );/*   Note that since we haven't allocated a range of pixel-values to this   window, the changes will only take effect with future writes.   Further, several colors may have been mapped to the same display color.   We could detect this only by seeing if there are any duplications   among the XBWin->cmap values. *//*    Remaining bug: foreground and background not set. */    return err;}/*    Color in X is many-layered.  The first layer is the "visual", a    immutable attribute of a window set when the window is    created.    The next layer is the colormap.  The installation of colormaps is    the buisness of the window manager (in some distant later release).    Rather than fight with that, we will use the default colormap.    This usually does not have many (any?) sharable color entries,    so we just try to match with the existing entries. *//*    This routine gets the visual class (PseudoColor, etc) and returns    it.  It finds the default visual.  Possible returns are	PseudoColor	StaticColor	DirectColor	TrueColor	GrayScale	StaticGray */int XBSetVisualClass( XBWin )XBWindow *XBWin;{    XVisualInfo vinfo;    if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 			  24, DirectColor, &vinfo)) {	XBWin->vis    = vinfo.visual;	return 0;    }    if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 			  8, PseudoColor, &vinfo)) {	XBWin->vis    = vinfo.visual;	return 0;    }    if (XMatchVisualInfo( XBWin->disp, XBWin->screen,			  DefaultDepth(XBWin->disp,XBWin->screen), 			  PseudoColor, &vinfo)) {	XBWin->vis    = vinfo.visual;	return 0;    }    XBWin->vis    = DefaultVisual( XBWin->disp, XBWin->screen );    return 0;}int XBGetVisualClass( XBWin )XBWindow *XBWin;{    return XBWin->vis->class;}/* Should pass this an XBWin */Colormap XBCreateColormap( display, screen, visual )Display *display;int      screen;Visual  *visual;{    Colormap Cmap;    if (DefaultDepth( display, screen ) <= 1)	Cmap    = DefaultColormap( display, screen );    else	Cmap    = XCreateColormap( display, RootWindow(display,screen),				   visual, AllocNone );    return Cmap;}int XBSetColormap( XBWin )XBWindow *XBWin;{    XSetWindowColormap( XBWin->disp, XBWin->win, XBWin->cmap );    return 0;}int XBAllocBW( XBWin, white, black )XBWindow *XBWin;PixVal   *white, *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 XBGetBaseColor( XBWin, white_pix, black_pix )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -