您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ DefaultColormap函数代码示例

51自学网 2021-06-01 20:26:01
  C++
这篇教程C++ DefaultColormap函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中DefaultColormap函数的典型用法代码示例。如果您正苦于以下问题:C++ DefaultColormap函数的具体用法?C++ DefaultColormap怎么用?C++ DefaultColormap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了DefaultColormap函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

intmain(int argc, char *argv[]){	XEvent e;	Atom type;	XClassHint *h;	XSetWindowAttributes wa;	unsigned int desktop;	struct pollfd pfd[1];	int nfds;	char *fontstr = FONT;	int running = 1;	d = XOpenDisplay(NULL);	if (d == NULL) {		fprintf(stderr, "Cannot open display/n");		exit(1);	}	s = DefaultScreen(d);	wa.override_redirect = 1;	wa.background_pixmap = ParentRelative;	wa.event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;	w = XCreateWindow(d, RootWindow(d, s), 0, BARPOS, BARWIDTH, BARHEIGHT, 0,	    DefaultDepth(d, s), CopyFromParent, DefaultVisual(d, s),	    CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);	h = XAllocClassHint();	h->res_name  = "status";	h->res_class = "status";	XSetClassHint(d, w, h);	XFree(h);	XStoreName(d, w, "status");	type = XInternAtom(d, "_NET_WM_WINDOW_TYPE_DOCK", False);	XChangeProperty(d, w, XInternAtom(d, "_NET_WM_WINDOW_TYPE", False),	    XInternAtom(d, "ATOM", False), 32, PropModeReplace, (unsigned char *)&type, 1);	type = XInternAtom(d, "_NET_WM_STATE_ABOVE", False);	XChangeProperty(d, w, XInternAtom(d, "_NET_WM_STATE", False),	    XInternAtom(d, "ATOM", False), 32, PropModeReplace, (unsigned char *)&type, 1);	type = XInternAtom(d, "_NET_WM_STATE_STICKY", False);	XChangeProperty(d, w, XInternAtom(d, "_NET_WM_STATE", False),	    XInternAtom(d, "ATOM", False), 32, PropModeAppend, (unsigned char *)&type, 1); 	desktop = 0xffffffff;	XChangeProperty(d, w, XInternAtom(d, "_NET_WM_DESKTOP", False),	    XInternAtom(d, "CARDINAL", False), 32, PropModeReplace, (unsigned char *)&desktop, 1);	xftd = XftDrawCreate(d, w, DefaultVisual(d, s), DefaultColormap(d, s));	XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s),  "white",  &white);	XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s),  "black",  &black);	XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s),  "red",  &red);	XftColorAllocName(d, DefaultVisual(d, s), DefaultColormap(d, s),  "green",  &green);	xftfont = XftFontOpenXlfd(d, s, fontstr);	if (!xftfont)		xftfont = XftFontOpenName(d, s, fontstr);	if (!xftfont)		exit(1);	XSelectInput(d, w, ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask);	XSelectInput(d, RootWindow(d, s), PropertyChangeMask);	XMapWindow(d, w);	XFlush(d);	pfd[0].fd = ConnectionNumber(d);	pfd[0].events = POLLIN;	while (running) {		nfds = poll(pfd, 1, 1000);		if (nfds == -1 || (pfd[0].revents & (POLLERR|POLLHUP|POLLNVAL)))			break;		if (nfds == 0) {			redraw();			XFlush(d);			continue;		}		while (XPending(d)) {			XNextEvent(d, &e);			if (e.type == PropertyNotify &&			    e.xproperty.window == RootWindow(d, s) &&			    e.xproperty.atom == XInternAtom(d, "_NET_CURRENT_DESKTOP", True)) {				redraw();			}			if (e.type == Expose) {				XftDrawRect(xftd, &black, 0, 0, BARWIDTH, BARHEIGHT);				redraw();			}			if (e.type == ButtonPress) {				/*running = 0;				break;*/				redraw();//.........这里部分代码省略.........
开发者ID:awaw,项目名称:status,代码行数:101,


示例2: XMenuCreate

//.........这里部分代码省略.........  /*   * Get default values from X.   */  def_val = x_get_resource_string ("menuFreeze", "MenuFreeze");  if (def_val != NULL) {    if (strcmp(def_val, "on") == 0) freeze = 1;    else if (strcmp(def_val, "off") == 0) freeze = 0;  }  def_val = x_get_resource_string ("menuReverseVideo", "MenuReverseVideo");  if (def_val != NULL) {    if (strcmp(def_val, "on") == 0) reverse = 1;    else if (strcmp(def_val, "off") == 0) reverse = 0;  }  def_val = x_get_resource_string ("menuStyle", "MenuStyle");  if (def_val != NULL) {    if (strcmp(def_val, "right_hand") == 0) menu_style = RIGHT;    else if (strcmp(def_val, "left_hand") == 0) menu_style = LEFT;    else if (strcmp(def_val, "center") == 0) menu_style = CENTER;  }  def_val = x_get_resource_string ("menuMode", "MenuMode");  if (def_val != NULL) {    if (strcmp(def_val, "box") == 0) menu_mode = BOX;    else if (strcmp(def_val, "invert") == 0) menu_mode = INVERT;  }  def_val = x_get_resource_string ("menuMouse", "MenuMouse");  if (      def_val != NULL &&      DisplayCells(display, DefaultScreen(display)) > 2 &&      XAllocDisplayColor(display,			 DefaultColormap(display, DefaultScreen(display)),			 def_val,			 &mouse_color, &color_def)      );  else if (reverse &&	   XAllocDisplayColor(display,			      DefaultColormap(display, DefaultScreen(display)),			      "white",			      &mouse_color, &color_def)	   );  else if (XAllocDisplayColor(display,			      DefaultColormap(display, DefaultScreen(display)),			      "black",			      &mouse_color, &color_def)	   );  else {}  def_val = x_get_resource_string ("menuBackground", "MenuBackground");  if (      def_val != NULL &&      DisplayCells(display, DefaultScreen(display)) > 2 &&      XAllocDisplayColor(display,			 DefaultColormap(display, DefaultScreen(display)),			 def_val,			 &bkgnd_color, &color_def)      );  else if (reverse &&	   XAllocDisplayColor(display,			      DefaultColormap(display, DefaultScreen(display)),			      "black",			      &bkgnd_color, &color_def)
开发者ID:7696122,项目名称:emacs,代码行数:67,


示例3: _find_color

static void _find_color(Widget w, XColor *target, char *dontuse){Colormap		cm;XColor			cell_def[256];double 			cur_dist;int 			cur_red_dist_index=0;int 			cur_green_dist_index=0;int 			cur_blue_dist_index=0;double 			cur_red_dist;double 			cur_green_dist;double 			cur_blue_dist;double 			dist;double 			red_dist;double 			green_dist;double 			blue_dist;int    			i;XColor 			tmp = {0,0,0,0,0,0};int    			screen;int    			ncells;Display 		*d = XtDisplay(w);XWindowAttributes 	win_att;int			depth;Pixel			pix;unsigned long		red_mask=0;unsigned long		green_mask=0;unsigned long		blue_mask=0;unsigned long		red_mult=0;unsigned long		green_mult=0;unsigned long		blue_mult=0;    screen = XScreenNumberOfScreen(XtScreen(w));    XtVaGetValues(w, XmNdepth, &depth, NULL);    if(depth == 8) 	    ncells = 255;    else if(depth == 12) 	    ncells = 16;     else	    ncells = 256;    if(XtIsRealized(w))    {	    XGetWindowAttributes(d, XtWindow(w), &win_att);	    if(win_att.colormap != 	        DefaultColormap(XtDisplay(w), screen))	    {	        cm = win_att.colormap;	        red_mask = win_att.visual->red_mask;	        green_mask = win_att.visual->green_mask;	        blue_mask = win_att.visual->blue_mask;	        red_mult = red_mask & (~red_mask+1);	        green_mult = green_mask & (~green_mask+1);	        blue_mult = blue_mask & (~blue_mask+1);	    }	    else	    {	        cm = DefaultColormap(XtDisplay(w), screen);	    }    }    else    {	    cm = DefaultColormap(XtDisplay(w), screen);    }    for (i = 0; i < ncells; i++)	{	    switch(depth)	        {	        case 8:		    cell_def[i].pixel = i;		    break;	        case 12:		    pix = i;		    cell_def[i].pixel = 		        (pix * red_mult) + 		        (pix * green_mult) + 		        (pix * blue_mult);		    break;	        default:		    pix = i;		    cell_def[i].pixel = 		        (pix * red_mult) | 		        (pix * green_mult) | 		        (pix * blue_mult);		    break;	        }	    cell_def[i].flags = DoRed | DoGreen | DoBlue;	}    XQueryColors(d, cm, cell_def, ncells);    cur_dist = sqrt((double)((double)65535*(double)65535*(double)65535));    cur_red_dist = cur_green_dist = cur_blue_dist = 65535.0*65535.0;    for (i = 0; i < ncells; i++)	{	red_dist = (double)(target->red - cell_def[i].red) * 	      	   (double)(target->red - cell_def[i].red);	green_dist = (double)(target->green - cell_def[i].green) * 	      	     (double)(target->green - cell_def[i].green);	blue_dist = (double)(target->blue - cell_def[i].blue) * 	      	    (double)(target->blue - cell_def[i].blue);//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:opendx2,代码行数:101,


示例4: lookup

//.........这里部分代码省略.........    if (property != XA_RGB_DEFAULT_MAP) {	if (replace) {	    XmuDeleteStandardColormap(dpy, screen, property);	    if (cnew)		XSetRGBColormaps(dpy, win, cnew, 1, property);	}	XFree((char *)stdcmaps);	return 1;    }    /* The property exists and is RGB_DEFAULT_MAP */    for (i=0, s=stdcmaps; (i < count) && (s->visualid != visualid); i++, s++)	;    /* No RGB_DEFAULT_MAP property matches the given visualid */    if (i == count) {	if (cnew) {	    XStandardColormap	*m, *maps;	    s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof					      (XStandardColormap)));	    for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) {		m->colormap   = maps->colormap;		m->red_max    = maps->red_max;		m->red_mult   = maps->red_mult;		m->green_max  = maps->green_max;		m->green_mult = maps->green_mult;		m->blue_max   = maps->blue_max;		m->blue_mult  = maps->blue_mult;		m->base_pixel = maps->base_pixel;		m->visualid   = maps->visualid;		m->killid     = maps->killid;	    }	    m->colormap   = cnew->colormap;	    m->red_max    = cnew->red_max;	    m->red_mult   = cnew->red_mult;	    m->green_max  = cnew->green_max;	    m->green_mult = cnew->green_mult;	    m->blue_max   = cnew->blue_max;	    m->blue_mult  = cnew->blue_mult;	    m->base_pixel = cnew->base_pixel;	    m->visualid   = cnew->visualid;	    m->killid     = cnew->killid;	    XSetRGBColormaps(dpy, win, s, ++count, property);	    free((char *) s);	}	XFree((char *) stdcmaps);	return 0;    }    /* Found an RGB_DEFAULT_MAP property with a matching visualid */    if (replace) {	/* Free old resources first - we may need them, particularly in	 * the default colormap of the screen.  However, because of this,	 * it is possible that we will destroy the old resource and fail	 * to create a new one if XmuStandardColormap() fails.	 */	if (count == 1) {	    XmuDeleteStandardColormap(dpy, screen, property);	    if (cnew)		XSetRGBColormaps(dpy, win, cnew, 1, property);	}	else {	    XStandardColormap	*map;	    /* s still points to the matching standard colormap */	    if (s->killid == ReleaseByFreeingColormap) {		if ((s->colormap != None) &&		    (s->colormap != DefaultColormap(dpy, screen)))		    XFreeColormap(dpy, s->colormap);	    }	    else if (s->killid != None)		XKillClient(dpy, s->killid);	    map = (cnew) ? cnew : stdcmaps + --count;	    s->colormap   = map->colormap;	    s->red_max    = map->red_max;	    s->red_mult   = map->red_mult;	    s->green_max  = map->green_max;	    s->green_mult = map->green_mult;	    s->blue_max   = map->blue_max;	    s->blue_mult  = map->blue_mult;	    s->visualid   = map->visualid;	    s->killid     = map->killid;	    XSetRGBColormaps(dpy, win, stdcmaps, count, property);	}    }    XFree((char *) stdcmaps);    return 1;}
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:101,


示例5: DefaultScreen

int XAbstractGui::SetColors(Display *dpy){    int screen;    XcmsColor xcolor;    XcmsColor exact;    int i, scale;    int rw_color;   /* is it a read/write color ?*/    int visualClass;    unsigned long pixels[1 << COLOR_PLANES];    screen = DefaultScreen(dpy);    visual = GetBestVisual(dpy, &visualClass, &depth);    if (!visual)    {        fprintf(stderr, "Unable to find an appropriate visual/n");        return 0;    }    rw_color = (visualClass == DirectColor || visualClass == PseudoColor ||                visualClass == GrayScale);    cmap = DefaultColormap(dpy, screen);    if (rw_color)    {        /* on visuals with read/write color cells           first allocate them */        if (!XAllocColorCells(dpy, cmap, False, nullptr, 0, pixels,                              1 << COLOR_PLANES))        {            /* try again with a own colormap */            cmap = XCreateColormap(dpy,                                   RootWindow(dpy, screen),                                   visual, AllocNone);            own_cmap = 1;            if (!XAllocColorCells(dpy, cmap, False, nullptr, 0,                                  pixels, 1 << COLOR_PLANES))            {                fprintf(stderr, "Unable to allocate %d colors/n",                        1 << COLOR_PLANES);                return 0; /* failed even with own colormap */            }        }    }    if (!XcmsLookupColor(dpy, cmap, color.c_str(), &xcolor, &exact,                         XcmsRGBiFormat))    {        exact.spec.RGBi.blue  = 1.0;        exact.spec.RGBi.red   = 1.0;        exact.spec.RGBi.green = 1.0;    }    xcolor.format = XcmsRGBiFormat;    for (i = 0; i < (1 << COLOR_PLANES); i++)    {        if (withColorScale)        {            // DEPENDANCIES:            // the color plane masks used here depend on            // the same masks used in CopyToZPixmap            scale  = i & 0x20 ? 2 : 0;            scale |= i & 0x04 ? 1 : 0;            xcolor.spec.RGBi.green = 1.0 * scale / 3;            scale  = i & 0x10 ? 2 : 0;            scale |= i & 0x02 ? 1 : 0;            xcolor.spec.RGBi.red   = 1.0 * scale / 3;            scale  = i & 0x08 ? 2 : 0;            scale |= i & 0x01 ? 1 : 0;            xcolor.spec.RGBi.blue  = 1.0 * scale / 3;        }        else        {            xcolor.spec.RGBi.blue  =                exact.spec.RGBi.blue  * i / (1 << COLOR_PLANES);            xcolor.spec.RGBi.red   =                exact.spec.RGBi.red   * i / (1 << COLOR_PLANES);            xcolor.spec.RGBi.green =                exact.spec.RGBi.green * i / (1 << COLOR_PLANES);        }        if (rw_color)        {            xcolor.pixel = pixels[i];            if (XcmsStoreColor(dpy, cmap,                               &xcolor) == XcmsFailure)            {                fprintf(stderr, "Error storing a color/n");                return 0;            }        }        else        {            if (XcmsAllocColor(dpy, cmap,                               &xcolor, XcmsRGBiFormat) == XcmsFailure)            {                fprintf(stderr, "Error allocating a color/n");//.........这里部分代码省略.........
开发者ID:aladur,项目名称:flexemu,代码行数:101,


示例6: initializeWindowSystem

voidinitializeWindowSystem(void){    char *display_name = NULL;    XColor fg, bg;#if 0    XColor rgbdef;#endif    Colormap cmap;    Pixmap  mousebits, mousemask;/*    fprintf(stderr,"initx:initializeWindowSystem:entered/n");*/    /* Try to open the display *//*    fprintf(stderr,"initx:initializeWindowSystem:XOpenDisplay/n");*/    if ((gXDisplay = XOpenDisplay(display_name)) == NULL) {        fprintf(stderr, "(HyperDoc) Cannot connect to the X11 server!/n");        exit(-1);    }    /* Get the screen *//*    fprintf(stderr,"initx:initializeWindowSystem:DefaultScreen/n");*/    gXScreenNumber = scrn = DefaultScreen(gXDisplay);/*    fprintf(stderr,"initx:initializeWindowSystem:XGContextFromGC/n");*/    server_font =XGContextFromGC(DefaultGC(gXDisplay, gXScreenNumber));    /* Get the cursors we need. *//*    fprintf(stderr,"initx:initializeWindowSystem:DefaultColormap/n");*/    cmap = DefaultColormap(gXDisplay, gXScreenNumber);/*    fprintf(stderr,"initx:initializeWindowSystem:WhitePixel/n");*/    fg.pixel = WhitePixel(gXDisplay,gXScreenNumber);/*    fprintf(stderr,"initx:initializeWindowSystem:XQueryColor/n");*/    XQueryColor(gXDisplay, cmap, &fg );/*    fprintf(stderr,"initx:initializeWindowSystem:BlackPixel/n");*/    bg.pixel = BlackPixel(gXDisplay,gXScreenNumber);/*    fprintf(stderr,"initx:initializeWindowSystem:XQueryColor2/n");*/    XQueryColor(gXDisplay, cmap, &bg );#if 0    XAllocNamedColor(gXDisplay, cmap, "Black", &fg, &rgbdef);    XAllocNamedColor(gXDisplay, cmap, "White", &bg, &rgbdef);#endif#ifdef USE_BORING_OLD_CURSORS    gActiveCursor = XCreateFontCursor(gXDisplay, XC_circle);    gNormalCursor = XCreateFontCursor(gXDisplay, XC_dot);#else/*  fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 1/n");*/    mousebits = XCreateBitmapFromData(gXDisplay,        RootWindow(gXDisplay, gXScreenNumber),        mouseBitmap_bits, mouseBitmap_width,mouseBitmap_height);/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2/n");*/    mousemask = XCreateBitmapFromData(gXDisplay,        RootWindow(gXDisplay, gXScreenNumber),        mouseMask_bits, mouseMask_width,mouseMask_height);/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2/n");*/    gActiveCursor = XCreatePixmapCursor(gXDisplay,        mousebits, mousemask, &fg, &bg,        mouseBitmap_x_hot,mouseBitmap_y_hot);/*    fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor/n");*/    gNormalCursor = XCreateFontCursor(gXDisplay, XC_left_ptr);#endif/*    fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor 2/n");*/    gBusyCursor = XCreateFontCursor(gXDisplay, XC_watch);    /* Now initialize all the colors and fonts *//*    fprintf(stderr,"initx:initializeWindowSystem:ingItColors_and_fonts/n");*/    ingItColors_and_fonts();/*    fprintf(stderr,"initx:initializeWindowSystem:init_text/n");*/    init_text();/*    fprintf(stderr,"initx:initializeWindowSystem:exited/n");*/}
开发者ID:bfauser,项目名称:fricas,代码行数:74,


示例7: main

int main(){#ifdef TEST_FOR_X	Display		*display;	Window		window;	GC		gc;	XGCValues	gcValues;	Colormap	colormap;	Pixmap		src_pixmap;	unsigned long	fgColor, bgColor;	int		screenNum;	XPoint		points[NUM_POINTS];#else	GR_WINDOW_ID 	window;	GR_WINDOW_ID	src_pixmap;	unsigned char*	src_pixmap_buf[320*240*2];	GR_GC_ID        gc;	GR_POINT	points[NUM_POINTS];#endif		int		c, c1,  count=4500;	int		x, y, x1, y1, x2, y2;#ifdef TEST_FOR_X	if(!(display=XOpenDisplay(""))) {		printf("Cannot connect to X./n");	}	screenNum = DefaultScreen(display);	colormap = DefaultColormap(display, screenNum);	bgColor = BlackPixel(display, screenNum);	fgColor = WhitePixel(display, screenNum);	window = XCreateSimpleWindow(display, RootWindow(display, screenNum),		0, 0 , 639, 479, 0,		fgColor, bgColor);	src_pixmap = XCreatePixmap(display, window, 320, 240, 16);	XMapRaised(display, window);	gcValues.background = bgColor;	gcValues.foreground = fgColor;	gcValues.line_width = 1;	gcValues.line_style = LineSolid;	gcValues.fill_style = FillSolid;	gcValues.fill_rule = WindingRule;	gcValues.arc_mode = ArcPieSlice;	gc = XCreateGC(display, window,		GCForeground  | GCBackground | GCLineWidth | GCLineStyle |		GCFillStyle,		&gcValues);#else		GrOpen();	window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 639, 479, 0, BLACK, BLUE);	src_pixmap = GrNewPixmap(640, 480, src_pixmap_buf);	GrMapWindow(window);	gc = GrNewGC();        GrSetGCForeground(gc, WHITE);	GrSetGCBackground(gc, BLACK);	GrSetGCMode(gc, GR_MODE_COPY);#endif		// Horizontal Line	////////////////////////////////////////////////	printf("Horizontal Line(XDrawLine)/n");	start_timer();	for(c=0; c<count*20; c++)	{		y1=random()%480;#ifdef TEST_FOR_X		XDrawLine(display, window, gc, 0, y1, 639, y1);		XFlush(display);#else		GrLine(window, gc, 0, y1, 639, y1);		GrFlush();#endif	}	end_timer();#ifdef TEST_FOR_X	XClearWindow(display, window);#else	GrClearWindow(window, GR_TRUE);#endif		// Vertical Line	/////////////////////////////////////////////////	printf("Vertical Line(XDrawLine)/n");	start_timer();	for(c=0; c<count*19; c++)	{		x1=random()%640;#ifdef TEST_FOR_X		XDrawLine(display, window, gc, x1, 0, x1, 479);		XFlush(display);#else		GrLine(window, gc, x1, 0, x1, 479);		GrFlush();#endif//.........这里部分代码省略.........
开发者ID:LucidOne,项目名称:Rovio,代码行数:101,


示例8: calibrator

GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)  : calibrator(calibrator0), time_elapsed(0){    display = XOpenDisplay(NULL);    if (display == NULL) {        throw std::runtime_error("Unable to connect to X server");    }    screen_num = DefaultScreen(display);    // Load font and get font information structure    font_info = XLoadQueryFont(display, "9x15");    if (font_info == NULL) {        // fall back to native font        font_info = XLoadQueryFont(display, "fixed");        if (font_info == NULL) {            XCloseDisplay(display);            throw std::runtime_error("Unable to open neither '9x15' nor 'fixed' font");        }    }#ifdef HAVE_X11_XRANDR    // get screensize from xrandr    int nsizes;    XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes);    if (nsizes != 0) {        set_display_size(randrsize->width, randrsize->height);    } else {        set_display_size(DisplayWidth(display, screen_num),                         DisplayHeight(display, screen_num));    }# else    set_display_size(DisplayWidth(display, screen_num),                     DisplayHeight(display, screen_num));#endif    // Register events on the window    XSetWindowAttributes attributes;    attributes.override_redirect = True;    attributes.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;    win = XCreateWindow(display, RootWindow(display, screen_num),                0, 0, display_width, display_height, 0,                CopyFromParent, InputOutput, CopyFromParent,                CWOverrideRedirect | CWEventMask,                &attributes);    XMapWindow(display, win);    // Listen to events    XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync,                CurrentTime);    calib_input = calibrator->register_events();    if (!calib_input) {            XGrabPointer(display, win, False, ButtonPressMask, GrabModeAsync,                GrabModeAsync, None, None, CurrentTime);    }    Colormap colormap = DefaultColormap(display, screen_num);    XColor color;    for (int i = 0; i != nr_colors; i++) {        XParseColor(display, colormap, colors[i], &color);        XAllocColor(display, colormap, &color);        pixel[i] = color.pixel;    }    XSetWindowBackground(display, win, pixel[GRAY]);    XClearWindow(display, win);    gc = XCreateGC(display, win, 0, NULL);    XSetFont(display, gc, font_info->fid);    // Setup timer for animation    signal(SIGALRM, sigalarm_handler);    struct itimerval timer;    timer.it_value.tv_sec = time_step/1000;    timer.it_value.tv_usec = (time_step % 1000) * 1000;    timer.it_interval = timer.it_value;    setitimer(ITIMER_REAL, &timer, NULL);}
开发者ID:axet,项目名称:xinput_calibrator,代码行数:76,


示例9: main

int main (int argc, char **argv) {	Cursor cursor;	Display *display;	Window root, blub, *blubs = NULL;	unsigned clients;	unsigned long pixel;	char *cname;	XColor color;	int cnt;	Atom prop;	Pixmap save_pixmap = (Pixmap)None;	display = XOpenDisplay(NULL);	if(!display) return 1;	cname = argc == 2 ? argv[1] : "black";	screen = DefaultScreen(display);	root = RootWindow(display, screen);	pixel = BlackPixel(display, screen);	if(XParseColor(display, DefaultColormap(display, screen), cname, &color)) {	if(XAllocColor(display, DefaultColormap(display, screen), &color)) {		pixel = color.pixel;	}	}	XSetWindowBackground(display, root, pixel);	XClearWindow(display, root);	cursor = CreateCursorFromName(display,"watch");	if (cursor) {		XDefineCursor (display, root, cursor);		XFreeCursor (display, cursor);	}		if (fork() == 0) {		Window win;		XEvent xev;		close(0); close(1); close(2);		chdir("/");		display = XOpenDisplay(NULL);		// open a client...		if (display) {			win = XCreateSimpleWindow (				display, root, 0, 0, 1, 1, 0, 0, pixel			);			XSync(display, False);		}		// wait within event loop...		for(;;) XNextEvent(display, &xev);	}	// wait until the child has opened a client	cnt = 100;	do {	if (!XQueryTree (display, root, &blub, &blub, &blubs, &clients)) {		XCloseDisplay(display);		return 0;	}	usleep(50000);	} while(clients < 1 && cnt--);	save_pixmap = XCreatePixmap (display, root, 1, 1, 1);	prop = XInternAtom (display, "_XSETROOT_ID", False);	XChangeProperty (		display, root, prop, XA_PIXMAP, 32, 		PropModeReplace, (unsigned char *) &save_pixmap, 1	);	XSetCloseDownMode (display, RetainPermanent);	// enable accessX	// XAccess (display,NULL);	XCloseDisplay(display);	RunWindowManager();	return 0;}
开发者ID:BackupTheBerlios,项目名称:sax-svn,代码行数:80,


示例10: Init_X

int Init_X (int swidth, int sheight){    XGCValues vals;    Colormap TheColormap;    XColor TheColor;    int i;    TheWidth = swidth ;    TheHeight = sheight ;    TheDisplay = XOpenDisplay("/0");    TheRootWindow = DefaultRootWindow(TheDisplay);    TheScreenNumber = DefaultScreen(TheDisplay);     TheDepth = DefaultDepth(TheDisplay, TheScreenNumber);    if (TheDepth != 24) {      printf("24 bit color not supported./n") ;      printf("Color function not likely to work./n") ;    }    TheWindow = XCreateSimpleWindow(TheDisplay, TheRootWindow,                        0, 0, TheWidth, TheHeight, 0, 0, 0);    if (!TheWindow) return 0 ;    ThePixmap = XCreatePixmap(TheDisplay, TheRootWindow, TheWidth, TheHeight, 				TheDepth);    if (!ThePixmap) return 0 ;    TheDrawable = ThePixmap;        XMapWindow(TheDisplay, TheWindow);    XSelectInput(TheDisplay, TheWindow, ExposureMask |					StructureNotifyMask |					PointerMotionMask | 					ButtonPressMask |					KeyPressMask );    /*    TheWindowContext = XCreateGC(TheDisplay, TheWindow, 0, 0);    // this is a bad idea ... see test t02.c for an example    // of what can happen to the behavior of the event handler,    //       int Handle_Events_X(int *px, int *py)    // if you do this, you'll get runaway calls to Handle_Events    // with the default condition being met and this produces    // a great deal of tearing in the animation of t02.c    */    /* also a bad idea...same behavior as above    vals.graphics_exposures = 1; // True    */    // so this is what you want :    vals.graphics_exposures = 0; // False    TheWindowContext = XCreateGC(TheDisplay, TheWindow,                                 GCGraphicsExposures, &vals);    if (!TheWindowContext) return 0;    ThePixmapContext = XCreateGC(TheDisplay, ThePixmap, 0, 0);    if (!ThePixmapContext) return 0;    TheColormap = DefaultColormap(TheDisplay, TheScreenNumber);    for(i = 0; i < 256; i++) {	TheColor.green = TheColor.blue = TheColor.red = (i << 8) | i;	TheColor.flags = DoRed | DoGreen | DoBlue;	XAllocColor(TheDisplay, TheColormap, &TheColor);	Grays[i] = TheColor.pixel;    }     TheFontInfo = XLoadQueryFont(TheDisplay, TheFont) ;    XSetFont(TheDisplay, TheWindowContext, TheFontInfo->fid) ;    //   XClearWindow(TheDisplay, TheWindow);    //   XClearArea(TheDisplay, TheWindow, 0,0,0,0,False); // same as above    XClearArea(TheDisplay, TheWindow, 0,0,0,0,True);                   // Does the boolean matter here?    // most people expect a white piece of paper    // with a black pencil    Set_Color_Rgb_X (255,255,255) ; // white    Clear_Buffer_X() ; // otherwise you can inherit garbage    // from the parent window    //    Set_Color_Rgb_X (255,0,255) ; // purple    //    Fill_Rectangle_X(10,10,50,80) ;    // above was just a test//.........这里部分代码省略.........
开发者ID:javins,项目名称:fpt,代码行数:101,


示例11: read_ppm_file

XImage *read_ppm_file(Display *disp, Colormap cmap, int depth, IOSTREAM *fd){ XImage *img;  long here = Stell(fd);  int c;  int fmt, encoding;  int width, height, bytes_per_line, scale=0;  char *data;  int allocdepth;  int pad = XBitmapPad(disp);  Visual *v = DefaultVisual(disp, DefaultScreen(disp));  ncolours = nmapped = nfailed = 0;	/* statistics */  assert(pad%8 == 0);  if ( (c=Sgetc(fd)) != 'P' )  { Sungetc(c, fd);    return NULL;  }  if ( !cmap )    cmap = DefaultColormap(disp, DefaultScreen(disp));  c = Sgetc(fd);  if ( c < '1' || c > '9' )    goto errout;  c -= '0';  fmt      = ((c - 1) % 3) + 1;  encoding = c - fmt;  width = getNum(fd);  height = getNum(fd);  if ( fmt == PNM_PBM )  { depth = 1;  } else  { scale = getNum(fd);    if ( !depth )      depth = DefaultDepth(disp, DefaultScreen(disp));  }  if ( width < 0 || height < 0 || scale < 0 )    goto errout;  allocdepth = (depth >= 24 ? 32 : depth);  bytes_per_line = roundup((width*allocdepth+7)/8, pad/8);  data = (char *)pceMalloc(height * bytes_per_line);  img = XCreateImage(disp,		     v,		     depth,		     fmt == PNM_PBM ? XYBitmap : ZPixmap,		     0,		     data,		     width, height,		     pad, bytes_per_line);  if ( !img )  { perror("XCreateImage");    pceFree(data);    goto errout;  }  img->bits_per_pixel = depth;  switch(encoding)  { int x, y;    case PNM_ASCII:    { switch(fmt)      { case PNM_PBM:	  for(y=0; y<height; y++)	  { for(x=0; x<width; x++)	    { int value = getNum(fd);	      if ( value < 0 || value > 1 )		goto errout;	      XPutPixel(img, x, y, value);	    }	  }	  break;	case PNM_PGM:	{ Table t = newTable(64);	  for(y=0; y<height; y++)	  { for(x=0; x<width; x++)	    { int g = getNum(fd);	      unsigned long pixel;	      if ( g < 0 || g > scale )		goto errout;	      if ( scale != 255 )		g = rescale(g, scale, 255);	      pixel = colourPixel(disp, depth, cmap, t, g, g, g);	      XPutPixel(img, x, y, pixel);	    }	  }	  freeTable(t);	  break;//.........这里部分代码省略.........
开发者ID:brayc0,项目名称:nlfetdb,代码行数:101,


示例12: malloc

stk_widget *stk_progress_bar_new(stk_widget *parent_win, int x, int y, uint w, uint h, char *label){    stk_widget *new_pb  = (stk_widget*) malloc(sizeof(stk_widget));    stk_progress_bar *pb  = (stk_progress_bar*) malloc(sizeof(stk_progress_bar));    int screen;    XGCValues gcval;    long fg, bg;        memset(new_pb, 0, sizeof(stk_widget));        new_pb->dsp = display;    new_pb->fontname = "7x13";    screen = DefaultScreen(new_pb->dsp);    fg = BlackPixel(new_pb->dsp, screen);    bg = WhitePixel(new_pb->dsp, screen);        gcval.foreground = fg;    gcval.background = bg;    new_pb->gc2 = XCreateGC(new_pb->dsp, parent_win->win, GCForeground |                                                  GCBackground, &gcval);    if(new_pb->dsp)    {        new_pb->win = XCreateSimpleWindow(new_pb->dsp, parent_win->win, x, y, w,                                                                  h, 1, fg, bg);        new_pb->gc = XCreateGC(new_pb->dsp, new_pb->win, 0, 0);        new_pb->font_info = XLoadQueryFont(new_pb->dsp, new_pb->fontname);        if(new_pb->fontname != NULL)            XSetFont(display, new_pb->gc2, new_pb->font_info->fid);        else            perror("XLoadQueryFont");        new_pb->mask =  ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask;        XSelectInput(new_pb->dsp, new_pb->win, new_pb->mask);                if(DisplayPlanes(new_pb->dsp, screen) != 1)        {            pb->cmap = DefaultColormap(new_pb->dsp, screen);            if(XAllocNamedColor(new_pb->dsp, pb->cmap, "red", &pb->color, &pb->colorrgb))                    XSetForeground(new_pb->dsp, new_pb->gc, pb->color.pixel);        }        XMapWindow(new_pb->dsp, new_pb->win);        memset(pb, 0, sizeof(stk_progress_bar));        new_pb->x = x;        new_pb->y = y;        new_pb->w = w;        new_pb->h = h;        new_pb->handler = &stk_progress_bar_handle;        pb->pct = 0;        new_pb->ext_struct = (void*)pb;        if(label)            strcpy(pb->label, label);        else            new_pb->label = NULL;        stk_widget_insert((void*)new_pb);         return new_pb;    }    else        return NULL;}
开发者ID:gabrield,项目名称:stk,代码行数:75,


示例13: main

//.........这里部分代码省略.........            my_current_person_id <= our_number_of_people - 1;            my_current_person_id++)    {        our_num_days_infected[my_current_person_id] = 0;    }    /* ALG XIII: Rank 0 initializes the graphics display */#ifdef X_DISPLAY    if(our_rank == 0)    {        /* Initialize the X Windows Environment         * This all comes from          *   http://en.wikibooks.org/wiki/X_Window_Programming/XLib         *   http://tronche.com/gui/x/xlib-tutorial         *   http://user.xmission.com/~georgeps/documentation/tutorials/         *      Xlib_Beginner.html         */        /* Open a connection to the X server */        display = XOpenDisplay(NULL);        if(display == NULL)        {            fprintf(stderr, "Error: could not open X display/n");        }        screen = DefaultScreen(display);        window = XCreateSimpleWindow(display, RootWindow(display, screen),                0, 0, environment_width * PIXEL_WIDTH_PER_PERSON,                 environment_height * PIXEL_HEIGHT_PER_PERSON, 1,                BlackPixel(display, screen), WhitePixel(display, screen));        delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0);        XSetWMProtocols(display, window, &delete_window, 1);        XSelectInput(display, window, ExposureMask | KeyPressMask);        XMapWindow(display, window);        colormap = DefaultColormap(display, 0);        gc = XCreateGC(display, window, 0, 0);        XParseColor(display, colormap, red, &infected_color);        XParseColor(display, colormap, green, &immune_color);        XParseColor(display, colormap, white, &dead_color);        XParseColor(display, colormap, black, &susceptible_color);        XAllocColor(display, colormap, &infected_color);        XAllocColor(display, colormap, &immune_color);        XAllocColor(display, colormap, &susceptible_color);        XAllocColor(display, colormap, &dead_color);    }#endif    /* ALG XIV: Each process starts a loop to run the simulation for the     *  specified number of days */    for(our_current_day = 0; our_current_day <= total_number_of_days - 1;             our_current_day++)    {        /* ALG XIV.A: Each process determines its infected x locations and          *  infected y locations */        our_current_infected_person = 0;        for(our_person1 = 0; our_person1 <= our_number_of_people - 1;                our_person1++)        {            if(our_states[our_person1] == INFECTED)            {                our_infected_x_locations[our_current_infected_person] =                    our_x_locations[our_person1];                our_infected_y_locations[our_current_infected_person] =                    our_y_locations[our_person1];                our_current_infected_person++;            }        }
开发者ID:Jgarcia08,项目名称:PetascaleInstitute,代码行数:67,


示例14: MakeColors

/* *********************************************************************** * Allocates colors and fill a pixel value array. Color values are * truncated with RED_MASK, GREEN_MASK and BLUE_MASK * * from,to are the primary colors to use * maxcols is the number of colors * colors is the array of pixel values * light,dark are the colors for the relief * dr,dg,db are the increment values for the colors * alloc_relief if colors for relief should be allocated * incr - 0 if gradient is light to dark, 1 if dark to light *********************************************************************** */int MakeColors(Display *dpy, Drawable d, int from[3], int to[3], int maxcols,	       unsigned long *colors, unsigned long *dark,	       unsigned long *light, int dr, int dg, int db,	       int alloc_relief, int incr){    float rv, gv, bv;    float sr,sg,sb;    int red, green, blue;    XColor color;    int i;    sr = (float)dr / (float)maxcols;    sg = (float)dg / (float)maxcols;    sb = (float)db / (float)maxcols;    rv = (float)from[0];    gv = (float)from[1];    bv = (float)from[2];    /* kludge to frce color allocation in the first iteration on any case */    color.red = (from[0] == 0) ? 0xffff : 0;    color.green = 0;    color.blue = 0;    for(i = 0; i < maxcols; i++) {	/* color allocation saver */	red = ((short)rv) & RED_MASK;	green = ((short)gv) & GREEN_MASK;	blue = ((short)bv) & BLUE_MASK;	if (color.red != red || color.green != green || color.blue != blue) {	    color.red = red;	    color.green = green;	    color.blue = blue;	    if (XAllocColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),			&color)==0) {	        return 0;	    }	}	colors[i] = color.pixel;	rv += sr;	gv += sg;	bv += sb;	if ((rv > 65535.0) || (rv < 0.0)) rv -= sr;	if ((gv > 65535.0) || (gv < 0.0)) gv -= sg;	if ((bv > 65535.0) || (bv < 0.0)) bv -= sb;    }    /* allocate 2 colors for the bevel */    if (alloc_relief) {	if (incr) {	    rv = (float)from[0] * 0.8;	    gv = (float)from[1] * 0.8;	    bv = (float)from[2] * 0.8;	} else {	    rv = (float)to[0] * 0.8;	    gv = (float)to[1] * 0.8;	    bv = (float)to[2] * 0.8;	}	color.red = (unsigned short)(rv<0?0:rv);    color.green = (unsigned short)(gv<0?0:gv);	color.blue = (unsigned short)(bv<0?0:bv);	if (XAllocColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),&color))	  *dark = color.pixel;	else	  *dark = colors[incr ? 0 : maxcols-1];	if (incr) {	    float avg;	    avg = (float)(to[0]+to[1]+to[2])/3;	    rv = avg + (float)(to[0]/2);	    gv = avg + (float)(to[1]/2);	    bv = avg + (float)(to[2]/2);	} else {            float avg;	    avg = (float)(from[0]+from[1]+from[2])/3;	    rv = avg + (float)(from[0]/2);	    gv = avg + (float)(from[1]/2);	    bv = avg + (float)(from[2]/2);	}	color.red = (unsigned short)(rv>65535.0 ? 65535.0:rv);    color.green = (unsigned short)(gv>65535.0 ? 65535.0:gv);	color.blue = (unsigned short)(bv>65535.0 ? 65535.0:bv);	if (XAllocColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),			&color))	  *light = color.pixel;	else	  *light = colors[incr ? maxcols-1 : 0];    } else {	*light = colors[incr ? maxcols-1 : 0];	*dark = colors[incr ? 0 : maxcols-1];//.........这里部分代码省略.........
开发者ID:att,项目名称:uwin,代码行数:101,


示例15: Tk_GetPixmap

PixmapTk_GetPixmap(    Display *display,    Drawable d,    int width,    int height,    int depth){    TkWinDrawable *newTwdPtr, *twdPtr;    int planes;    Screen *screen;    display->request++;    newTwdPtr = ckalloc(sizeof(TkWinDrawable));    newTwdPtr->type = TWD_BITMAP;    newTwdPtr->bitmap.depth = depth;    twdPtr = (TkWinDrawable *) d;    if (twdPtr->type != TWD_BITMAP) {	if (twdPtr->window.winPtr == NULL) {	    newTwdPtr->bitmap.colormap = DefaultColormap(display,		    DefaultScreen(display));	} else {	    newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap;	}    } else {	newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap;    }    screen = &display->screens[0];    planes = 1;    if (depth == screen->root_depth) {	planes = PTR2INT(screen->ext_data);	depth /= planes;    }    newTwdPtr->bitmap.handle =	    CreateBitmap(width, height, (DWORD) planes, (DWORD) depth, NULL);    /*     * CreateBitmap tries to use memory on the graphics card. If it fails,     * call CreateDIBSection which uses real memory; slower, but at least     * still works. [Bug 2080533]     */    if (newTwdPtr->bitmap.handle == NULL) {	static int repeatError = 0;	void *bits = NULL;	BITMAPINFO bitmapInfo;	HDC dc;	memset(&bitmapInfo, 0, sizeof(bitmapInfo));	bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo.bmiHeader);	bitmapInfo.bmiHeader.biWidth = width;	bitmapInfo.bmiHeader.biHeight = height;	bitmapInfo.bmiHeader.biPlanes = planes;	bitmapInfo.bmiHeader.biBitCount = depth;	bitmapInfo.bmiHeader.biCompression = BI_RGB;	bitmapInfo.bmiHeader.biSizeImage = 0;	dc = GetDC(NULL);	newTwdPtr->bitmap.handle = CreateDIBSection(dc, &bitmapInfo,		DIB_RGB_COLORS, &bits, 0, 0);	ReleaseDC(NULL, dc);	/*	 * Oh no! Things are still going wrong. Pop up a warning message here	 * (because things will probably crash soon) which will encourage	 * people to report this as a bug...	 */	if (newTwdPtr->bitmap.handle == NULL && !repeatError) {	    LPVOID lpMsgBuf;	    repeatError = 1;	    if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |		    FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,		    NULL, GetLastError(),		    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),		    (LPSTR) &lpMsgBuf, 0, NULL)) {		MessageBoxA(NULL, (LPCSTR) lpMsgBuf,			"Tk_GetPixmap: Error from CreateDIBSection",			MB_OK | MB_ICONINFORMATION);		LocalFree(lpMsgBuf);	    }	}    }    if (newTwdPtr->bitmap.handle == NULL) {	ckfree(newTwdPtr);	return None;    }    return (Pixmap) newTwdPtr;}
开发者ID:AlexShiLucky,项目名称:bitkeeper,代码行数:92,


示例16: InitX

int InitX() {  XColor    xColor;  Colormap  colormap;  dpy = XOpenDisplay(NULL);  if(dpy == NULL) {    fprintf(stderr, "ERROR: Unable to open X display/n");    return 1;  }  clrBlack = BlackPixel(dpy, DefaultScreen(dpy));  clrWhite = WhitePixel(dpy, DefaultScreen(dpy));  colormap = DefaultColormap(dpy, DefaultScreen(dpy));  XParseColor(dpy, colormap, "red", &xColor);  XAllocColor(dpy, colormap, &xColor);  clrRed = xColor.pixel;  XParseColor(dpy, colormap, "blue", &xColor);  XAllocColor(dpy, colormap, &xColor);  clrBlue = xColor.pixel;  XParseColor(dpy, colormap, "orange", &xColor);  XAllocColor(dpy, colormap, &xColor);  clrOrange = xColor.pixel;  wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", False);  // Create the window  win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 			    400, 300, 8, clrBlack, clrWhite);  XSetWMProtocols(dpy, win, &wmDeleteMessage, 1);  XSelectInput(dpy, win, StructureNotifyMask | ExposureMask | KeyPressMask);  XGCValues    values;  XFontStruct *font;  font = XLoadQueryFont(dpy, "fixed");  if(!font) {    fprintf(stderr, "No fixed font?/n");    return 2;  }    values.line_width = 1;  values.line_style = LineSolid;  values.font = font->fid;  gc = XCreateGC(dpy, win, GCLineWidth|GCLineStyle|GCFont,		 &values);  XStoreName(dpy, win, "xtemp");    // Map the window (that is, make it appear on the screen)  XMapWindow(dpy, win);  // Tell the GC we draw using black on white  XSetForeground(dpy, gc, clrBlack);  XSetBackground(dpy, gc, clrWhite);  // Wait for the MapNotify event  for(;;) {    XEvent e;    XNextEvent(dpy, &e);    if (e.type == MapNotify)      break;  }  return 0;}
开发者ID:Bedoustani,项目名称:parallella-utils,代码行数:69,


示例17: InitColorTableFixed

Colormap InitColorTableFixed(Colormap cmap){    int n_colors = xwa.visual->map_entries;    int r, g, b, y, i;    switch (xwa.visual->class) {    case StaticGray:    case GrayScale:	/* determine how many levels of gray we can actually get */	y = try_get_grays(cmap, n_colors);	if (y > 2 && y < n_colors)	    y = try_get_grays(cmap, y);	if (y < 2)	    G_fatal_error(_("Unable to get sufficient gray shades."));	NCOLORS = y;	for (i = 0; i < 256; i++)	    Gray[i] = i * y / 256;	break;    case StaticColor:    case PseudoColor:	/* determine how many levels of r, g, and b are possible */	get_max_levels(n_colors, &r, &g, &b);	/* now see how many we can actually get */	while (!try_get_colors(cmap, r, g, b))	    if (!get_fewer_levels(&r, &g, &b))		G_fatal_error(_("Unable to get sufficient colors."));	NCOLORS = r * g * b;	for (i = 0; i < 256; i++) {	    Red[i] = (i * r / 256) * g * b;	    Grn[i] = (i * g / 256) * b;	    Blu[i] = (i * b / 256);	}	break;    case DirectColor:	G_warning(_("Using private colormap for DirectColor visual."));	/* free any previously-allocated Colormap */	if (cmap != DefaultColormap(dpy, scrn))	    XFreeColormap(dpy, cmap);	/* get shift factors for R,G,B masks */	NCOLORS = get_rgb_shifts();	/* create colormap (emulates TrueColor visual) */	cmap = ramp_colormap();	break;    case TrueColor:	/* get shift factors for R,G,B masks */	NCOLORS = get_rgb_shifts();	break;    default:	G_fatal_error(_("Unknown visual class [%d]."), xwa.visual->class);	break;    }    return cmap;}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:68,


示例18: setup_gui_colors

void setup_gui_colors() {  XColor kolor,unused;  int *depths, num_depths;  display = XtDisplay(shell);  window = XtWindow(shell);  if((depths = XListDepths(display, XScreenNumberOfScreen(XtScreen(shell)),                &num_depths))==NULL) {      printf("XListDepths() failed./n");      exit(0);  }  cmap = DefaultColormap(display, 0);   XAllocNamedColor(display,cmap,"black",&kolor,&unused);  black_color = kolor.pixel;  XAllocNamedColor(display,cmap,"white",&kolor,&unused);  white_color = kolor.pixel;  XAllocNamedColor(display,cmap,"lawngreen",&kolor,&unused);  green_color = kolor.pixel;  XAllocNamedColor(display,cmap,"red",&kolor,&unused);  red_color = kolor.pixel;  XAllocNamedColor(display,cmap,"blue",&kolor,&unused);  blue_color = kolor.pixel;  XAllocNamedColor(display,cmap,"grey",&kolor,&unused);  grey_color = kolor.pixel;  XAllocNamedColor(display,cmap,"yellow",&kolor,&unused);  yellow_color = kolor.pixel;    XAllocNamedColor(display,cmap,"orange",&kolor,&unused);  orange_color = kolor.pixel;    XAllocNamedColor(display,cmap,"magenta",&kolor,&unused);  magenta_color = kolor.pixel;      XAllocNamedColor(display,cmap,"cyan",&kolor,&unused);  cyan_color = kolor.pixel;    XAllocNamedColor(display,cmap,"brown",&kolor,&unused);  brown_color = kolor.pixel;    XAllocNamedColor(display,cmap,"light grey",&kolor,&unused);  light_grey_color = kolor.pixel;    XAllocNamedColor(display,cmap,"snow",&kolor,&unused);  snow_color = kolor.pixel;    XAllocNamedColor(display,cmap,"indian red",&kolor,&unused);  indian_red_color = kolor.pixel;    XAllocNamedColor(display,cmap,"ghost white",&kolor,&unused);  ghost_white_color = kolor.pixel;    gcv.foreground = white_color;  gcv.background = black_color;  gcv.graphics_exposures = FALSE;  gc = XCreateGC(display, window, GCBackground|GCForeground|GCGraphicsExposures, &gcv);  }
开发者ID:likev,项目名称:CodeOrpgPub,代码行数:67,


示例19: SilChessMachine

XSilChessWindow::XSilChessWindow(XtAppContext app, Widget toplevel,                                 Visual * vsl, int vsldepth, Colormap cmap){	char tmp[512];	Arg al[10];	int i;	XmString xms;	// Initialize member variables	App=app;	TopLevel=toplevel;	Disp=XtDisplay(TopLevel);	Vsl=vsl;	VslDepth=vsldepth;	CMap=cmap;	DlgVsl=DefaultVisual(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));	DlgVslDepth=DefaultDepth(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));	DlgCMap=DefaultColormap(Disp,XScreenNumberOfScreen(XtScreen(TopLevel)));	PixelSize=(VslDepth<=8 ? 1 : (VslDepth<=16 ? 2 : 4));	RedMask=Vsl->red_mask;	GreenMask=Vsl->green_mask;	BlueMask=Vsl->blue_mask;	SelX=SelY-1;	IsSearching=false;	AbortSearching=false;	NeedPainting=false;	IsPainting=false;	HintWanted=false;	HintValid=false;	// Create main window	MainWin=XtVaCreateManagedWidget(		"mainWin",xmMainWindowWidgetClass,TopLevel,		(char*)NULL	);	// Create main menu bar	MainMenu=XmCreateMenuBar(MainWin,(char*)"mainMenu",NULL,0);	XtManageChild(MainMenu);	// Create menu item: file	XtSetArg(al[0],XmNvisual,Vsl);	XtSetArg(al[1],XmNdepth,VslDepth);	XtSetArg(al[2],XmNcolormap,CMap);	FileMenu=XmCreatePulldownMenu(MainMenu,(char*)"fileMenu",al,3);	BFile=XtVaCreateManagedWidget(		"file",xmCascadeButtonWidgetClass,MainMenu,		XmNsubMenuId,FileMenu,		(char*)NULL	);	// Create menu item: file/load	BFileLoad=XtVaCreateManagedWidget(		"load",xmPushButtonWidgetClass,FileMenu,		(char*)NULL	);	XtAddCallback(BFileLoad,XmNactivateCallback,HandleCallback,this);	// Create menu item: file/save	BFileSave=XtVaCreateManagedWidget(		"save",xmPushButtonWidgetClass,FileMenu,		(char*)NULL	);	XtAddCallback(BFileSave,XmNactivateCallback,HandleCallback,this);	// Create menu item: file/exit	XtVaCreateManagedWidget(		"separator",xmSeparatorWidgetClass,FileMenu,		(char*)NULL	);	BFileExit=XtVaCreateManagedWidget(		"exit",xmPushButtonWidgetClass,FileMenu,		(char*)NULL	);	XtAddCallback(BFileExit,XmNactivateCallback,HandleCallback,this);	// Create menu item: game	XtSetArg(al[0],XmNvisual,Vsl);	XtSetArg(al[1],XmNdepth,VslDepth);	XtSetArg(al[2],XmNcolormap,CMap);	GameMenu=XmCreatePulldownMenu(MainMenu,(char*)"gameMenu",al,3);	BGame=XtVaCreateManagedWidget(		"game",xmCascadeButtonWidgetClass,MainMenu,		XmNsubMenuId,GameMenu,		(char*)NULL	);	// Create menu item: game/new	BGameNew=XtVaCreateManagedWidget(		"new",xmPushButtonWidgetClass,GameMenu,		(char*)NULL	);	XtAddCallback(BGameNew,XmNactivateCallback,HandleCallback,this);	// Create menu item: game/flip	BGameFlip=XtVaCreateManagedWidget(		"flip",xmPushButtonWidgetClass,GameMenu,		(char*)NULL	);	XtAddCallback(BGameFlip,XmNactivateCallback,HandleCallback,this);//.........这里部分代码省略.........
开发者ID:ackalker,项目名称:eaglemode,代码行数:101,


示例20: ingItColors_and_fonts

static voidingItColors_and_fonts(void){    char property[256];    char *prop = &property[0];    char *str_type[50];    XrmValue value;    Colormap cmap;    int ts;    /** get the color map for the display **//*    fprintf(stderr,"initx:ingItColors_and_fonts:entered/n");*//*    fprintf(stderr,"initx:ingItColors_and_fonts:DefaultColorMap/n");*/    cmap = DefaultColormap(gXDisplay, gXScreenNumber);/*    fprintf(stderr,"initx:ingItColors_and_fonts:init_group_stack/n");*/    init_group_stack();    /** then start getting the fonts **//*    fprintf(stderr,"initx:ingItColors_and_fonts:mergeDatabases/n");*/    mergeDatabases();/*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.RmFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)        (void) strncpy(prop, value.addr, (int) value.size);    else        (void) strcpy(prop, RmFontDefault);/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 1/n");*/    load_font(&gRmFont, prop);/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 2/n");*/    load_font(&gInputFont, prop);/*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 2/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.TtFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)        (void) strncpy(prop, value.addr, (int) value.size);    else        (void) strcpy(prop, TtFontDefault);/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 3/n");*/    load_font(&gTtFont, prop);/*    fprintf(stderr,"initx:ingItColors_and_fonts:is_it_850/n");*/    gTtFontIs850=is_it_850(gTtFont);/*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 5/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.ActiveFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)        (void) strncpy(prop, value.addr, (int) value.size);    else        (void) strcpy(prop, ActiveFontDefault);/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 4/n");*/    load_font(&gActiveFont, prop);    /* maintain backwards compatibility *//*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 6/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.AxiomFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)        (void) strncpy(prop, value.addr, (int) value.size);    else {        if (XrmGetResource(rDB, "Axiom.hyperdoc.SpadFont",                           "Axiom.hyperdoc.Font", str_type, &value) == True)        {            (void) strncpy(prop, value.addr, (int) value.size);        }        else {            (void) strcpy(prop, fricas_font_default);        }    }/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 5/n");*/    load_font(&fricas_font, prop);/*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 7/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.EmphasizeFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)    {        (void) strncpy(prop, value.addr, (int) value.size);    }    else {        (void) strcpy(prop, EmphasizeFontDefault);    }/*    fprintf(stderr,"initx:ingItColors_and_fonts:load_font 6/n");*/    load_font(&gEmFont, prop);/*    fprintf(stderr,"initx:ingItColors_and_fonts:XrmGetResource 8/n");*/    if (XrmGetResource(rDB, "Axiom.hyperdoc.BoldFont",                            "Axiom.hyperdoc.Font", str_type, &value) == True)    {        (void) strncpy(prop, value.addr, (int) value.size);    }    else {        (void) strcpy(prop, BoldFontDefault);//.........这里部分代码省略.........
开发者ID:bfauser,项目名称:fricas,代码行数:101,


示例21: lockscreen

static Lock *lockscreen(Display *dpy, int screen) {	char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};	unsigned int len;	Lock *lock;	XColor color;	XSetWindowAttributes wa;	Cursor invisible;	int hue1, hue2;	if(dpy == NULL || screen < 0)		return NULL;	lock = malloc(sizeof(Lock));	if(lock == NULL)		return NULL;	lock->screen = screen;	lock->root = RootWindow(dpy, lock->screen);	/* init */	wa.override_redirect = 1;	lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen),			0, DefaultDepth(dpy, lock->screen), CopyFromParent,			DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa);		/* locked color */	hue1 = rand() % 360;	gen_random_pastel(&color, hue1);	XAllocColor(dpy, DefaultColormap(dpy, lock->screen), &color);	lock->colors[0] = color.pixel;	XSetWindowBackground(dpy, lock->win, lock->colors[0]);		/* trying to unlock color */	hue2 = hue1 + 180;	if (hue2 >= 360) {		hue2 -= 360;	}	gen_random_pastel(&color, hue2);	XAllocColor(dpy, DefaultColormap(dpy, lock->screen), &color);	lock->colors[1] = color.pixel;		lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);	invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &color, &color, 0, 0);	XDefineCursor(dpy, lock->win, invisible);	XMapRaised(dpy, lock->win);	for(len = 1000; len; len--) {		if(XGrabPointer(dpy, lock->root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,			GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)			break;		usleep(1000);	}	if(running && (len > 0)) {		for(len = 1000; len; len--) {			if(XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime)				== GrabSuccess)				break;			usleep(1000);		}	}	running &= (len > 0);	if(!running) {		unlockscreen(dpy, lock);		lock = NULL;	}	else 		XSelectInput(dpy, lock->root, SubstructureNotifyMask);	return lock;}
开发者ID:eepp,项目名称:slock,代码行数:71,


示例22: XmuLookupStandardColormap

StatusXmuLookupStandardColormap(Display *dpy, int screen, VisualID visualid,			  unsigned int depth, Atom property,			  Bool replace, Bool retain)     /*      * dpy		- specifies X server connection      * screen 		- specifies screen of display      * visualid	- specifies the visual type      * depth		- specifies  the visual type      * property	- a standard colormap property      * replace		- specifies whether to replace      * retain		- specifies whether to retain      */{    Display		*odpy;		/* original display connection */    XStandardColormap	*colormap;    XVisualInfo		vinfo_template, *vinfo;	/* visual */    long		vinfo_mask;    unsigned long	r_max, g_max, b_max;	/* allocation */    int			count;    Colormap		cmap;			/* colormap ID */    Status		status = 0;    /* Match the requested visual */    vinfo_template.visualid = visualid;    vinfo_template.screen = screen;    vinfo_template.depth = depth;    vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask;    if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &count)) ==	NULL)	return 0;    /* Monochrome visuals have no standard maps */    if (vinfo->colormap_size <= 2) {	XFree((char *) vinfo);	return 0;    }    /* If the requested property already exists on this screen, and,     * if the replace flag has not been set to true, return success.     * lookup() will remove a pre-existing map if replace is true.     */    if (lookup(dpy, screen, visualid, property, (XStandardColormap *) NULL,	       replace) && !replace) {	XFree((char *) vinfo);	return 1;    }    /* Determine the best allocation for this property under the requested     * visualid and depth, and determine whether or not to use the default     * colormap of the screen.     */    if (!XmuGetColormapAllocation(vinfo, property, &r_max, &g_max, &b_max)) {	XFree((char *) vinfo);	return 0;    }    cmap = (property == XA_RGB_DEFAULT_MAP &&	    visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen)))	? DefaultColormap(dpy, screen) : None;    /* If retaining resources, open a new connection to the same server */    if (retain) {	odpy = dpy;	if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {	    XFree((char *) vinfo);	    return 0;	}    }    /* Create the standard colormap */    colormap = XmuStandardColormap(dpy, screen, visualid, depth, property,				   cmap, r_max, g_max, b_max);    /* Set the standard colormap property */    if (colormap) {	XGrabServer(dpy);	if (lookup(dpy, screen, visualid, property, colormap, replace) &&	    !replace) {	    /* Someone has defined the property since we last looked.	     * Since we will not replace it, release our own resources.	     * If this is the default map, our allocations will be freed	     * when this connection closes.	     */	    if (colormap->killid == ReleaseByFreeingColormap)		XFreeColormap(dpy, colormap->colormap);	}	else if (retain) {		XSetCloseDownMode(dpy, RetainPermanent);	}	XUngrabServer(dpy);//.........这里部分代码省略.........
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:101,


示例23: glutSetCursor

/* * Set the cursor image to be used for the current window */void FGAPIENTRY glutSetCursor( int cursorID ){    freeglut_assert_ready;  /* XXX WHY do we need the timer active for this? */    freeglut_assert_window;#if TARGET_HOST_UNIX_X11    /*     * Open issues:     * (a) Partial error checking.  Is that a problem?     *     Is fgGetCursorError() correct?  Should we abort on errors?     *     Should there be a freeglut-wide X error handler?  Should     *     we use the X error-handler mechanism?     * (b) FULL_CROSSHAIR demotes to plain CROSSHAIR.  Old GLUT allows     *     for this, but if there is a system that easily supports a full-     *     window (or full-screen) crosshair, we might consider it.     * (c) Out-of-range cursor-types generate warnings.  Should we abort?     */    {        Cursor cursor = None;        Pixmap no_cursor = None ;  /* Used for GLUT_CURSOR_NONE */        int error = 0;#define MAP_CURSOR(a,b)                                     /    case a:                                                 /        cursor = XCreateFontCursor( fgDisplay.Display, b ); /        break;        if( GLUT_CURSOR_FULL_CROSSHAIR == cursorID )            cursorID = GLUT_CURSOR_CROSSHAIR;        switch( cursorID )        {            MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, XC_right_ptr);            MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW,  XC_left_ptr);            MAP_CURSOR( GLUT_CURSOR_INFO,        XC_hand1);            MAP_CURSOR( GLUT_CURSOR_DESTROY,     XC_pirate);            MAP_CURSOR( GLUT_CURSOR_HELP,        XC_question_arrow);            MAP_CURSOR( GLUT_CURSOR_CYCLE,       XC_exchange);            MAP_CURSOR( GLUT_CURSOR_SPRAY,       XC_spraycan);            MAP_CURSOR( GLUT_CURSOR_WAIT,        XC_watch);            MAP_CURSOR( GLUT_CURSOR_TEXT,        XC_xterm);            MAP_CURSOR( GLUT_CURSOR_CROSSHAIR,   XC_crosshair);            MAP_CURSOR( GLUT_CURSOR_UP_DOWN,     XC_sb_v_double_arrow);            MAP_CURSOR( GLUT_CURSOR_LEFT_RIGHT,  XC_sb_h_double_arrow);            MAP_CURSOR( GLUT_CURSOR_TOP_SIDE,    XC_top_side);            MAP_CURSOR( GLUT_CURSOR_BOTTOM_SIDE, XC_bottom_side);            MAP_CURSOR( GLUT_CURSOR_LEFT_SIDE,   XC_left_side);            MAP_CURSOR( GLUT_CURSOR_RIGHT_SIDE,  XC_right_side);            MAP_CURSOR( GLUT_CURSOR_TOP_LEFT_CORNER,     XC_top_left_corner);            MAP_CURSOR( GLUT_CURSOR_TOP_RIGHT_CORNER,    XC_top_right_corner);            MAP_CURSOR( GLUT_CURSOR_BOTTOM_RIGHT_CORNER,                        XC_bottom_right_corner);            MAP_CURSOR( GLUT_CURSOR_BOTTOM_LEFT_CORNER, XC_bottom_left_corner);            /* MAP_CURSOR( GLUT_CURSOR_NONE,        XC_bogosity); */        case GLUT_CURSOR_NONE:        {            /*             * Note that we *never* change {no_cursor_bits} from anything             * but all-zeros.  It is our image and mask.  We also apparently             * need to pick a color for foreground/background---but what             * one we pick doesn't matter for GLUT_CURSOR_NONE.             */            static char no_cursor_bits[ 32 ];            XColor black;            no_cursor = XCreatePixmapFromBitmapData( fgDisplay.Display,                                                     fgDisplay.RootWindow,                                                     no_cursor_bits,                                                     16, 16,                                                     1, 0, 1 );            XParseColor( fgDisplay.Display,                         DefaultColormap( fgDisplay.Display,                                          DefaultScreen( fgDisplay.Display ) ),                         "black",                         &black );            cursor = XCreatePixmapCursor( fgDisplay.Display,                                          no_cursor, no_cursor,                                          &black, &black,                                          0, 0 );            break;        }        case GLUT_CURSOR_INHERIT:            break;        default:            fgWarning( "Unknown cursor type: %d/n", cursorID );            return;        }        error = fgGetCursorError( cursor );        if( GLUT_CURSOR_INHERIT == cursorID )            XUndefineCursor( fgDisplay.Display,                             fgStructure.Window->Window.Handle );        else        {//.........这里部分代码省略.........
开发者ID:ramanshu,项目名称:btp,代码行数:101,


示例24: main

int main(int argc, char *argv[]) {	int rank, nprocs, x, y;	Window win; // initialization for a window	GC gc; // graphics context	Display *display = NULL;	Colormap screenColourmap;	XColor colours[15];	unsigned int width = X_RESN, height = Y_RESN; /* window size */	clock_t start, end, elapsed;	int pixelToDraw[3];	MPI_Init(&argc, &argv); 	MPI_Comm_size(MPI_COMM_WORLD, &nprocs); 	MPI_Comm_rank(MPI_COMM_WORLD, &rank);	ComplexNumber c;	ComplexNumber z;	int depth = 1000;	int cSize = 4;	double cX = -2;	double cY = -2;	double cMinR = cX;	double cMinI = cY;	double cMaxR = cMinR + cSize;	double cMaxI = cMinI + cSize;	double increaseX = (cMaxR - cMinR) / X_RESN;	double increaseY = (cMaxI - cMinI) / Y_RESN;	int drawable[X_RESN][Y_RESN];        	if(rank==0)	{		display = x11setup(&win, &gc, width, height);		screenColourmap = DefaultColormap(display, DefaultScreen(display));		setupColours(display, colours, screenColourmap);		int probeFlag = 0;		MPI_Status status;		int count = 0;		int start = 1;		for (int i = 1; i < nprocs; i++) {			MPI_Send(&start, 1, MPI_INT, i, 98, MPI_COMM_WORLD);		}		for (int y = 0; y < Y_RESN; y++) {			for (int x = 0; x < X_RESN; x++) {				while (!probeFlag) {					MPI_Iprobe(MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, &probeFlag, &status);					if (probeFlag) {						int coords[2] = {x, y};						int slave = status.MPI_SOURCE;						MPI_Recv(&pixelToDraw, 3, MPI_INT, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE);						MPI_Send(&coords, 2, MPI_INT, slave, 99, MPI_COMM_WORLD); 						drawable[pixelToDraw[0]][pixelToDraw[1]] = pixelToDraw[2];						count++;					} else {						MPI_Iprobe(MPI_ANY_SOURCE, 98, MPI_COMM_WORLD, &probeFlag, &status);						if (probeFlag) {							int slave = status.MPI_SOURCE;							int coords[2] = {x, y};							MPI_Recv(&start, 1, MPI_INT, MPI_ANY_SOURCE, 98, MPI_COMM_WORLD, MPI_STATUS_IGNORE);							MPI_Send(&coords, 2, MPI_INT, slave, 99, MPI_COMM_WORLD); 						}					}				}				probeFlag = 0;			}		}		MPI_Recv(&pixelToDraw, 3, MPI_INT, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE);		drawable[pixelToDraw[0]][pixelToDraw[1]] = pixelToDraw[2];		for (int y = 0; y < Y_RESN; y++) {			for (int x = 0; x < X_RESN; x++) {				drawPoint(display, win, gc, colours, x, y, depth, drawable[x][y]);			}		}	} else {		int flag = 1;		int coords[2];		MPI_Recv(&start, 1, MPI_INT, 0, 98, MPI_COMM_WORLD, MPI_STATUS_IGNORE);		MPI_Send(&start, 1, MPI_INT, 0, 98, MPI_COMM_WORLD);		while (flag) {			MPI_Recv(&coords, 2, MPI_INT, 0, 99, MPI_COMM_WORLD, MPI_STATUS_IGNORE);			c.r = coords[0] * increaseX - 2;			c.i = coords[1] * increaseY - 2;			resetComplexNumber(&z);			int limit = seriesDiverges(depth, &z, &c);			pixelToDraw[0] = coords[0];			pixelToDraw[1] = coords[1];			pixelToDraw[2] = limit;			MPI_Send(&pixelToDraw, 3, MPI_INT, 0, 99, MPI_COMM_WORLD);		}	}		// main loop	int running = 1; // loop variable	start = clock();	while(running) {			// checks to see if there have been any events,		// will exit the main loop if any key is pressed		if(rank==0) {			if(XPending(display)) {				XEvent ev;				XNextEvent(display, &ev);//.........这里部分代码省略.........
开发者ID:esainty,项目名称:parallel-mandelbrot,代码行数:101,


示例25: GETSTRORGOTO

static BackgroundTexture *parseTexture(RContext * rc, char *text){	BackgroundTexture *texture = NULL;	WMPropList *texarray;	WMPropList *val;	int count;	char *tmp;	char *type;#define GETSTRORGOTO(val, str, i, label) /    val = WMGetFromPLArray(texarray, i);/    if (!WMIsPLString(val)) {/    wwarning("could not parse texture %s", text);/    goto label;/    }/    str = WMGetFromPLString(val)	texarray = WMCreatePropListFromDescription(text);	if (!texarray || !WMIsPLArray(texarray)	    || (count = WMGetPropListItemCount(texarray)) < 2) {		wwarning("could not parse texture %s", text);		if (texarray)			WMReleasePropList(texarray);		return NULL;	}	texture = wmalloc(sizeof(BackgroundTexture));	GETSTRORGOTO(val, type, 0, error);	if (strcasecmp(type, "solid") == 0) {		XColor color;		Pixmap pixmap;		texture->solid = 1;		GETSTRORGOTO(val, tmp, 1, error);		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {			wwarning("could not parse color %s in texture %s", tmp, text);			goto error;		}		XAllocColor(dpy, DefaultColormap(dpy, scr), &color);		pixmap = XCreatePixmap(dpy, root, 8, 8, DefaultDepth(dpy, scr));		XSetForeground(dpy, DefaultGC(dpy, scr), color.pixel);		XFillRectangle(dpy, pixmap, DefaultGC(dpy, scr), 0, 0, 8, 8);		texture->pixmap = pixmap;		texture->color = color;		texture->width = 8;		texture->height = 8;	} else if (strcasecmp(type, "vgradient") == 0		   || strcasecmp(type, "dgradient") == 0 || strcasecmp(type, "hgradient") == 0) {		XColor color;		RColor color1, color2;		RImage *image;		Pixmap pixmap;		RGradientStyle gtype;		int iwidth, iheight;		GETSTRORGOTO(val, tmp, 1, error);		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {			wwarning("could not parse color %s in texture %s", tmp, text);			goto error;		}		color1.red = color.red >> 8;		color1.green = color.green >> 8;		color1.blue = color.blue >> 8;		GETSTRORGOTO(val, tmp, 2, error);		if (!XParseColor(dpy, DefaultColormap(dpy, scr), tmp, &color)) {			wwarning("could not parse color %s in texture %s", tmp, text);			goto error;		}		color2.red = color.red >> 8;		color2.green = color.green >> 8;		color2.blue = color.blue >> 8;		switch (type[0]) {		case 'h':		case 'H':			gtype = RHorizontalGradient;			iwidth = scrWidth;			iheight = 32;			break;		case 'V':		case 'v':			gtype = RVerticalGradient;			iwidth = 32;			iheight = scrHeight;			break;		default:			gtype = RDiagonalGradient;			iwidth = scrWidth;//.........这里部分代码省略.........
开发者ID:cneira,项目名称:wmaker-crm,代码行数:101,


示例26: main

// #includ ur #lifeint main(int argc, char *argv[]) {  bool q = false;  if(argv[1] != NULL && strcmp(argv[1], "-q") == 0) q=true;  Display *disp;  Window win;  XEvent e;  int screen;  int winy = 0;  int winx = 0;  int winheight = 300;  int winwidth = 500;  int borderwidth = 10;  int stdcposx = 20;  int stdcposy = 20;  int cposx = stdcposx;  int cposy = stdcposy;  int lastdeltime = 0;  int lastrowlength = 0;  int lastkeysym = 0;  char *msg = "Clear";  int bwidth=strlen(msg)*6;  int bheight=15;  int btop=20;  int bmargin = 2;  int bleft=winwidth - bwidth - 20;  GC white;  XColor white_color;  Colormap colormap;  char whiteidk[] = "#FFFFFF";  GC red;  XColor red_color;  Colormap rcolormap;  char redidk[] = "#FF0000";  disp = XOpenDisplay(NULL);  if (disp == NULL) {    fprintf(stderr, "Cannot open display/n");    exit(1);  }  screen = DefaultScreen(disp);  win = XCreateSimpleWindow(disp, RootWindow(disp, screen), winx, winy, winwidth, winheight, borderwidth,  BlackPixel(disp, screen), WhitePixel(disp, screen));  XSelectInput(disp, win, ExposureMask | KeyPressMask | ButtonPressMask);  // Window XCreateWindow(display, parent, x, y, width, height, border_width, depth,  //                    class, visual, valuemask, attributes)  XMapWindow(disp, win);  colormap = DefaultColormap(disp, 0);  white = XCreateGC(disp, win, 0, 0);  XParseColor(disp, colormap, whiteidk, &white_color);  XAllocColor(disp, colormap, &white_color);  XSetForeground(disp, white, white_color.pixel);  rcolormap = DefaultColormap(disp, 0);  red = XCreateGC(disp, win, 0, 0);  XParseColor(disp, colormap, redidk, &red_color);  XAllocColor(disp, colormap, &red_color);  XSetForeground(disp, red, red_color.pixel);  while (1) {    XNextEvent(disp, &e);    if (e.type == Expose)      {        XFillRectangle(disp, win, red, bleft, btop, bwidth, bheight);        XDrawString(disp, win, white, bleft+bmargin, btop+bmargin+9, msg, strlen(msg));        //http://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawString.html      }      if(e.type == 4) // button press        {          int x=e.xbutton.x;          int y=e.xbutton.y;          int button = e.xbutton.button;          if(!q) printf("Button pressed. X: %d, Y: %d Button: %d/n",x,y,button);          if(button == 1)            {              if(y < bheight+btop && x < bwidth+bleft)                {                  if(y > btop && x > bleft)                    {                      if(!q) printf("You've hitten the button!!/nClearing.../n");                      XFillRectangle(disp, win, white, 0, 0, winwidth, winheight);                      cposx = stdcposx;                      cposy = stdcposy;                      if(!q) printf("Repainting clearbutton.../n");                      XFillRectangle(disp, win, red, bleft, btop, bwidth, bheight);                      XDrawString(disp, win, white, bleft+bmargin, btop+bmargin+9, msg, strlen(msg));                    }                  }                }              }              if (e.type == KeyPress)                {                  if(!q) printf("Keycode: %d/n", e.xkey.keycode);                  unsigned long keysym = XLookupKeysym(&e.xkey, 0);                  if(!q) printf("Keysym: %lu/n",keysym);                  char *ascii = XKeysymToString(keysym);                  if(!q) printf("ASCII: %s/n",ascii);                  if(keysym == 65307 && lastkeysym == 65406) // alt+ESC                    {                      printf("Exiting.../n");                      return 0;//.........这里部分代码省略.........
开发者ID:danieltroger,项目名称:X,代码行数:101,


示例27: XDefaultColormap

Colormap XDefaultColormap(Display *dpy, int scr){    return (DefaultColormap(dpy, scr));}
开发者ID:mirror,项目名称:libX11,代码行数:4,


示例28: main

  int main (void)  {    int i;      int allocateOK;      ximg = NULL;    	    d = XOpenDisplay (NULL);      if (!d)      fputs ("Couldn't open display/n", stderr), exit (1);      screen = DefaultScreen (d);    gc = DefaultGC (d, screen);      /* Find a visual */      vis.screen = screen;    vlist = XGetVisualInfo (d, VisualScreenMask, &vis, &match);      if (!vlist)      fputs ("No matched visuals/n", stderr), exit (1);      vis = vlist[0];    XFree (vlist);		  	// That's not a fair comparison colormap_size is depth in bits!    // if (vis.colormap_size < COLORS)      // printf("Colormap is too small: %i./n",vis.colormap_size); // , exit (1);		// printf("Colour depth: %i/n",vis.colormap_size);		// No way this number means nothing!  It is 64 for 16-bit truecolour and 256 for 8-bit!      win = XCreateSimpleWindow (d, DefaultRootWindow (d),			       0, 0, WIN_W, WIN_H, 0,			       WhitePixel (d, screen), BlackPixel (d, screen));  	  int xclass=get_xvisinfo_class(vis);		// printf("class = %i/n",xclass);	  stylee = ( vis.depth > 8 ? styleeTrueColor : styleePrivate );	  // printf("stylee=%i/n",stylee);      if ( get_xvisinfo_class(vis) % 2 == 1) {	/* The odd numbers can redefine colors */  			  // printf("%i/n",get_xvisinfo_class(vis));	  	      colormap = DefaultColormap (d, screen);		  Visual *defaultVisual=DefaultVisual(d,screen);	  	      /* Allocate cells */      allocateOK = (XAllocColorCells (d, colormap, 1,							      NULL, 0, color, COLORS) != 0);			printf("Allocated OK? %i/n",allocateOK);			      if (allocateOK) {  			  // printf("Allocated OK/n");        // This doesn't work for installed colormap!          /* Modify the colorcells */        for (i = 0; i < COLORS; i++)				  xrgb[i].pixel = color[i];          XStoreColors (d, colormap, xrgb, COLORS);  		  } else {			  colormap = XCreateColormap(d,win,defaultVisual,AllocNone);		  	    	  // redocolors();					  	      }  		  // black = XBlackPixel(d,screen);		  // white = XWhitePixel(d,screen);  			XAllocColorCells(d,colormap,1,0,0,color,colors);			XSetWindowColormap(d,win,colormap);    } else if ( get_xvisinfo_class(vis) == TrueColor) {      colormap = DefaultColormap (d, screen);					  // printf("TrueColor %i = %i/n",xclass,TrueColor);      /* This will lookup the color and sets the xrgb[i].pixel value */      // for (i = 0; i < COLORS; i++)        // XAllocColor (d, colormap, &xrgb[i]);    } else      fprintf (stderr, "Not content with visual class %d./n",	       get_xvisinfo_class(vis) ), exit (1);      /* Find out if MITSHM is supported and useable */    printf ("MITSHM: ");      if (XShmQueryVersion (d, &mitshm_major_code,			  &mitshm_minor_code, &shared_pixmaps)) {      int (*handler) (Display *, XErrorEvent *);      ximg = XShmCreateImage (d, vis.visual,			     vis.depth, XShmPixmapFormat (d),			     NULL, &shminfo, WIN_W, WIN_H);//.........这里部分代码省略.........
开发者ID:10crimes,项目名称:code,代码行数:101,


示例29: main

int main () {	printf ("X11 demo/n");	Display* display = NULL;	GC graphics_context;	Window window;	int black_colour, white_colour;	{ // create window and display combo		printf ("init window.../n");		display = XOpenDisplay (NULL);		if (!display) {			fprintf (stderr, "ERROR: opening display/n");			return 1;		}		black_colour = BlackPixel (display, DefaultScreen (display));		white_colour = WhitePixel (display, DefaultScreen (display));		// colour map		Colormap colour_map;		char green[] = "#00FF00";		char charcoal[] ="RGBi:0.01/0.02/0.01";		char lcharcoal[] = "RGBi:0.02/0.03/0.02";//"#445544";		char textc[] = "#DDEEDD";		char linenoc[] = "#667766";		char rulerc[] = "#556655";		colour_map = DefaultColormap (display, 0);		// add colours		XParseColor (display, colour_map, green, &green_col);		XAllocColor (display, colour_map, &green_col);		XParseColor (display, colour_map, charcoal, &charcoal_col);		XAllocColor (display, colour_map, &charcoal_col);		XParseColor (display, colour_map, lcharcoal, &lcharcoal_col);		XAllocColor (display, colour_map, &lcharcoal_col);		XParseColor (display, colour_map, textc, &text_col);		XAllocColor (display, colour_map, &text_col);		XParseColor (display, colour_map, rulerc, &ruler_col);		XAllocColor (display, colour_map, &ruler_col);		XParseColor (display, colour_map, linenoc, &lineno_col);		XAllocColor (display, colour_map, &lineno_col);		// note: can use CopyFromParent instead of colour index		// note: there is also XCreateWindow with more params		// simplewindow also clears the window to background colour		// 0,0 is request position, other 0 is border (not used)		window = XCreateSimpleWindow (display, DefaultRootWindow (display), 0, 0,			1024, 768, 0, charcoal_col.pixel, charcoal_col.pixel);		XStoreName (display, window, "Anton's X11 demo");		// get MapNotify events etc.		XSelectInput (display, window, ExposureMask); // was StructureNotifyMask		// put window on screen command		XMapWindow (display, window);		// create graphics context		graphics_context = XCreateGC (display, window, 0, 0);	} // endinitwindow	{ // draw		// note: can also unload a font		const char* font_name = "-*-Monospace-*-10-*";		XFontStruct* font = XLoadQueryFont (display, font_name);		if (!font) {			fprintf (stderr, "ERROR: could not load font %s/n", font_name);			font = XLoadQueryFont (display, "fixed");			if (!font) {				fprintf (stderr, "ERROR: default font fixed did not load/n");				return 1;			}		}		XSetFont (display, graphics_context, font->fid);		event_loop (display, window, graphics_context);	} // enddraw	return 0;}
开发者ID:capnramses,项目名称:opengl_expmts,代码行数:73,



注:本文中的DefaultColormap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ DefaultDepth函数代码示例
C++ Default函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。