/*Sets up the cursors data for a dnd. * display - X display * rw - the root window */ void xdndCursorInit(Display *display, Window rw) { Pixmap ip,mp; XdndCursor *cursorPtr; XColor black, white; /* gets color info */ black.pixel = BlackPixel(display, DefaultScreen (display)); XQueryColor(display, DefaultColormap (display, DefaultScreen(display)), &black); white.pixel = WhitePixel(display, DefaultScreen (display)); XQueryColor(display, DefaultColormap (display, DefaultScreen(display)), &white); /* now initialize the cursors */ for (cursorPtr = &xdndCursors[0];cursorPtr->w != 0;cursorPtr++) { ip = XCreateBitmapFromData(display, rw, (char *) cursorPtr->imageData, cursorPtr->w, cursorPtr->h); mp = XCreateBitmapFromData(display, rw, (char *) cursorPtr->maskData, cursorPtr->w, cursorPtr->h); cursorPtr->cursor = XCreatePixmapCursor (display, ip, mp, &black, &white, cursorPtr->x, cursorPtr->y); XFreePixmap (display, ip); XFreePixmap (display, mp); cursorPtr->action = XInternAtom (display, cursorPtr->actionStr, False); } }
/* set up needed bitmaps in the server */ static void initCursors(void) { Pixmap p, m; XColor mc, bc; mc.pixel = app_resources.mouseground; bc.pixel = app_resources.bg_pixel; mc.flags = DoRed | DoGreen | DoBlue; bc.flags = DoRed | DoGreen | DoBlue; XQueryColor(dpy, DefaultColormap(dpy, screen), &mc); XQueryColor(dpy, DefaultColormap(dpy, screen), &bc); m = XCreateBitmapFromData(dpy, mwWindow, (char *)ratMask_bits, ratMask_width, ratMask_height); p = XCreateBitmapFromData(dpy, mwWindow, (char *)rat_bits, rat_width, rat_height); ratCursor = XCreatePixmapCursor(dpy, p, m, &mc, &bc, rat_x_hot, rat_y_hot); m = XCreateBitmapFromData(dpy, mwWindow, (char *)dRatMask_bits, dRatMask_width, dRatMask_height); p = XCreateBitmapFromData(dpy, mwWindow, (char *)dRat_bits, dRat_width, dRat_height); deadRatCursor = XCreatePixmapCursor(dpy, p, m, &mc, &bc, 0, 0); p = XCreateBitmapFromData(dpy, mwWindow, (char *)cup_bits, cup_width, cup_height); hourGlassCursor = XCreatePixmapCursor(dpy, p, p, &mc, &bc, 0, 0); }
/**************************************************************************** * * This routine computes the hilight color from the background color * ****************************************************************************/ Pixel GetHilite(Pixel background) { XColor bg_color, white_p; XWindowAttributes attributes; XGetWindowAttributes(dpy,Root,&attributes); bg_color.pixel = background; XQueryColor(dpy,attributes.colormap,&bg_color); white_p.pixel = GetColor("white"); XQueryColor(dpy,attributes.colormap,&white_p); #ifndef min #define min(a,b) (((a)<(b)) ? (a) : (b)) #define max(a,b) (((a)>(b)) ? (a) : (b)) #endif bg_color.red = max((white_p.red/5), bg_color.red); bg_color.green = max((white_p.green/5), bg_color.green); bg_color.blue = max((white_p.blue/5), bg_color.blue); bg_color.red = min(white_p.red, (bg_color.red*140)/100); bg_color.green = min(white_p.green, (bg_color.green*140)/100); bg_color.blue = min(white_p.blue, (bg_color.blue*140)/100); if(!XAllocColor(dpy,attributes.colormap,&bg_color)) nocolor("alloc hilight",""); return bg_color.pixel; }
void reserveColors(ModeInfo * mi, Colormap cmap, unsigned long *black) { Display *display = MI_DISPLAY(mi); XColor blackcolor, whitecolor; blackcolor.flags = DoRed | DoGreen | DoBlue; blackcolor.pixel = MI_BLACK_PIXEL(mi); blackcolor.red = 0; blackcolor.green = 0; blackcolor.blue = 0; whitecolor.flags = DoRed | DoGreen | DoBlue; whitecolor.pixel = MI_WHITE_PIXEL(mi); whitecolor.red = 0xFFFF; whitecolor.green = 0xFFFF; whitecolor.blue = 0xFFFF; /* If they fail what should I do? */ (void) XAllocColor(display, cmap, &blackcolor); (void) XAllocColor(display, cmap, &whitecolor); *black = blackcolor.pixel; #if 0 { XColor bgcolor, fgcolor; bgcolor.pixel = MI_BG_PIXEL(mi); fgcolor.pixel = MI_FG_PIXEL(mi); XQueryColor(display, cmap, &bgcolor); XQueryColor(display, cmap, &fgcolor); (void) XAllocColor(display, cmap, &bgcolor); (void) XAllocColor(display, cmap, &fgcolor); } #endif }
int NewBitmapCursor(Cursor *cp, char *source, char *mask) { XColor fore, back; int hotx, hoty; int sx, sy, mx, my; unsigned int sw, sh, mw, mh; Pixmap spm, mpm; Colormap cmap = Scr->RootColormaps.cwins[0]->colormap->c; fore.pixel = Scr->Black; XQueryColor(dpy, cmap, &fore); back.pixel = Scr->White; XQueryColor(dpy, cmap, &back); spm = GetBitmap(source); if ((hotx = HotX) < 0) hotx = 0; if ((hoty = HotY) < 0) hoty = 0; mpm = GetBitmap(mask); /* make sure they are the same size */ XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth); XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth); if (sw != mw || sh != mh) { fprintf (stderr, "%s: cursor bitmaps \"%s\" and \"%s\" not the same size\n", ProgramName, source, mask); return (1); } *cp = XCreatePixmapCursor(dpy, spm, mpm, &fore, &back, hotx,hoty); return (0); }
/*============================================================ DndInitialize * Must be called anywhere before the top level widget creation and the * main loop. Initialize global variables and bind the DndDispatch function * to the top level widget. Creates the cursors to be used in drag actions. *=========================================================================*/ void MwDndInitialize(Widget shell) { int screen,i; Colormap colormap; Window root; dpy = XtDisplayOfObject(shell); screen = DefaultScreen(dpy); colormap= DefaultColormap(dpy,screen); root = DefaultRootWindow(dpy); Black.pixel=BlackPixel(dpy,screen); White.pixel=WhitePixel(dpy,screen); XQueryColor(dpy,colormap,&Black); XQueryColor(dpy,colormap,&White); for(i=1;i!=MW_DndEND;i++) { DndCursor[i].ImagePixmap= XCreateBitmapFromData(dpy,root, DndCursor[i].ImageData, DndCursor[i].Width, DndCursor[i].Height); DndCursor[i].MaskPixmap= XCreateBitmapFromData(dpy,root, DndCursor[i].MaskData, DndCursor[i].Width, DndCursor[i].Height); DndCursor[i].CursorID= XCreatePixmapCursor(dpy,DndCursor[i].ImagePixmap, DndCursor[i].MaskPixmap, &Black,&White, DndCursor[i].HotSpotX, DndCursor[i].HotSpotY); } DndCursor[0].CursorID=XCreateFontCursor(dpy,XC_question_arrow); /* These two are for older versions */ OldDndProtocol=XInternAtom(dpy,"DndProtocol",FALSE); OldDndSelection=XInternAtom(dpy,"DndSelection",FALSE); /* Now the correct stuff */ MwDndProtocol=XInternAtom(dpy,"_DND_PROTOCOL",FALSE); MwDndSelection=XInternAtom(dpy,"_DND_SELECTION",FALSE); WM_STATE=XInternAtom(dpy,"WM_STATE",True); Dragging=0; DragPrecision=10; XtAddEventHandler(shell,NoEventMask,True,MwDndDispatchEvent,NULL); OtherDrop=RootDrop=IconDrop=NULL; RootFlag=0; MainWidget=shell; }
void XbrGfxBWPixels(Display *display, Screen *screen, Colormap colourmap, XColor *black, XColor *white) { if(black != NULL) { black->pixel = BlackPixelOfScreen(screen); XQueryColor(display, colourmap, black); } if(white != NULL) { white->pixel = WhitePixelOfScreen(screen); XQueryColor(display, colourmap, white); } }
/* This function converts the colour stored in a colorcell (pixel) into the * string representation of a colour. The output is printed at the * address 'output'. It is either in rgb format ("rgb:rrrr/gggg/bbbb") if * use_hash is False or in hash notation ("#rrrrggggbbbb") if use_hash is true. * The return value is the number of characters used by the string. The * rgb values of the output are undefined if the colorcell is invalid. The * memory area pointed at by 'output' must be at least 64 bytes (in case of * future extensions and multibyte characters).*/ int pixel_to_color_string( Display *dpy, Colormap cmap, Pixel pixel, char *output, Bool use_hash) { XColor color; int n; color.pixel = pixel; color.red = 0; color.green = 0; color.blue = 0; XQueryColor(dpy, cmap, &color); if (!use_hash) { sprintf( output, "rgb:%04x/%04x/%04x%n", (int)color.red, (int)color.green, (int)color.blue, &n); } else { sprintf( output, "#%04x%04x%04x%n", (int)color.red, (int)color.green, (int)color.blue, &n); } return n; }
gboolean cb_hide_pointer(GtkWidget *widget, GdkEvent *event, gpointer data) { static Cursor cursor = 0; XColor colour; Pixmap cursorPixmap; colour.pixel = WhitePixel(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), DefaultScreen(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window))); XQueryColor(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), DefaultColormap(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), DefaultScreen(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window))), &colour); if(cursor) { XFreeCursor(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), cursor); } cursorPixmap = XCreatePixmap(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), GDK_WINDOW_XWINDOW(GTK_WIDGET(widget)->window), 1, 1, 1); cursor = XCreatePixmapCursor(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), cursorPixmap, cursorPixmap, &colour, &colour, 0, 0); if(cursorPixmap) { XFreePixmap(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), cursorPixmap); } XDefineCursor(GDK_WINDOW_XDISPLAY(GTK_WIDGET(widget)->window), GDK_WINDOW_XWINDOW(GTK_WIDGET(widget)->window), cursor); return TRUE; }
/*! For internal use only. */ void QNPWidget::setWindow(bool delold) { saveWId = winId(); // ### Don't need this anymore create((WId)pi->window, FALSE, delold); if ( delold ) { // Make sure they get a show() clearWState( WState_Visible ); } #ifdef _WS_X11_ Widget w = XtWindowToWidget (qt_xdisplay(), pi->window); XtAddEventHandler(w, EnterWindowMask, FALSE, enter_event_handler, pi); XtAddEventHandler(w, LeaveWindowMask, FALSE, leave_event_handler, pi); Pixmap bgpm=0; XColor col; XtVaGetValues(w, XtNbackground, &col.pixel, XtNbackgroundPixmap, &bgpm, 0, 0); XQueryColor(qt_xdisplay(), x11Colormap(), &col); setBackgroundColor(QColor(col.red >> 8, col.green >> 8, col.blue >> 8)); if (bgpm) { // ### Need an under-the-hood function here, or we have to // ### rewrite lots of code from QPixmap::convertToImage(). // ### Doesn't matter yet, because Netscape doesn't ever set // ### the background image of the window it gives us. } #endif createNewWindowsForAllChildren(this); setGeometry( pi->x, pi->y, pi->width, pi->height ); }
/*ARGSUSED*/ static Boolean _XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args, XrmValue *fromVal, XrmValue *toVal, XtPointer *converter_data) { static char buffer[19]; Cardinal size; Colormap colormap; XColor color; if (*num_args != 1) { XtAppWarningMsg(XtDisplayToApplicationContext(dpy), XtNwrongParameters, "cvtPixelToString", XtCToolkitError, "Pixel to String conversion needs colormap argument", NULL, NULL); return (False); } colormap = *(Colormap *)args[0].addr; color.pixel = *(Pixel *)fromVal->addr; /* Note: * If we know the visual type, we can calculate the xcolor * without asking Xlib. */ XQueryColor(dpy, colormap, &color); XmuSnprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx", color.red, color.green, color.blue); size = strlen(buffer) + 1; string_done(buffer); }
static void initialize_transparency_colormap (Display *dpy, Colormap cmap, int nplanes, unsigned long base_pixel, unsigned long *plane_masks, XColor *colors, Bool additive_p , ModeInfo* mi ) { int i; int total_colors = i_exp (2, nplanes); XColor *all_colors = (XColor *) calloc (total_colors, sizeof (XColor)); for (i = 0; i < nplanes; i++) colors[i].pixel = base_pixel | plane_masks [i]; permute_colors (colors, all_colors, nplanes, plane_masks, additive_p); /* clone the default background of the window into our "base" pixel */ all_colors [total_colors - 1].pixel = MI_BLACK_PIXEL( mi ); XQueryColor (dpy, cmap, &all_colors [total_colors - 1]); all_colors [total_colors - 1].pixel = base_pixel; for (i = 0; i < total_colors; i++) all_colors[i].flags = DoRed|DoGreen|DoBlue; XStoreColors (dpy, cmap, all_colors, total_colors); XFree ((XPointer) all_colors); }
static char* get_bgcolor(Ihandle *n) { Widget w[6]; XColor xcor; Colormap cmap; char *cor = getBuffer(); if (iupmotGetWidgetHandles(n, w) == 0) return NULL; if (type(n) == DIALOG_ || type(n) == MULTILINE_ || type(n) == CANVAS_ || (type(n) == LIST_ && w[1]) ) { XtVaGetValues(w[1], XmNcolormap, &cmap, XmNbackground, &xcor.pixel, NULL); } else { XtVaGetValues(w[0], XmNcolormap, &cmap, XmNbackground, &xcor.pixel, NULL); } XQueryColor(iupmot_display, cmap, &xcor ); sprintf(cor, "%d %d %d", xcor.red/257, xcor.green/257, xcor.blue/257); return cor; }
/* This routine takes a named color and returns a color that is either lighter or darker */ PixVal XBSimColor( XBWindow *XBWin, PixVal pixel, int intensity, int is_fore ){ XColor colordef, colorsdef; char RGBcolor[20]; PixVal red, green, blue; /* int st; */ colordef.pixel = pixel; XQueryColor( XBWin->disp, XBWin->cmap, &colordef ); /* Adjust the color value up or down. Get the RGB values for the color */ red = colordef.red; green = colordef.green; blue = colordef.blue; #define min(a,b) ((a)<(b) ? a : b) #define max(a,b) ((a)>(b) ? a : b) #define WHITE_AMOUNT 5000 if (intensity > 0) { /* Add white to the color */ red = min(65535,red + WHITE_AMOUNT); green = min(65535,green + WHITE_AMOUNT); blue = min(65535,blue + WHITE_AMOUNT); } else { /* Subtract white from the color */ red = (red < WHITE_AMOUNT) ? 0 : red - WHITE_AMOUNT; green = (green < WHITE_AMOUNT) ? 0 : green - WHITE_AMOUNT; blue = (blue < WHITE_AMOUNT) ? 0 : blue - WHITE_AMOUNT; } sprintf( RGBcolor, "rgb:%4.4x/%4.4x/%4.4x", (unsigned int)red, (unsigned int) green, (unsigned int) blue ); XLookupColor( XBWin->disp, XBWin->cmap, RGBcolor, &colordef, &colorsdef ); /* st = XLookupColor( XBWin->disp, XBWin->cmap, RGBcolor, &colordef, &colorsdef ); */ return colorsdef.pixel; }
/////////////////////////////////////////////////////////////////////// /// Function: QueryRGB8 /// /// Author: $author$ /// Date: 4/25/2012 /////////////////////////////////////////////////////////////////////// virtual XosError QueryRGB8 (Display* xDisplay, Colormap xColormap, uint8_t r, uint8_t g, uint8_t b, bool onlyFreed=false) { XosError error = XOS_ERROR_FAILED; XosError error2; XColor xColor; Pixel detached; int err; if ((error2 = Freed(onlyFreed))) return error2; RGB8ToXColor(xColor, r,g,b); if ((xDisplay) && (None != (xColormap))) { XQueryColor(xDisplay, xColormap, &xColor); if ((xColor.pixel)) { m_xDisplay = xDisplay; m_xColormap = xColormap; Attach(detached = xColor.pixel); error = XOS_ERROR_NONE; } } return error; }
QColor QGLContext::overlayTransparentColor() const { //### make more efficient using the transpColor member if ( isValid() ) { if ( !trans_colors_init ) find_trans_colors(); VisualID myVisualId = ((XVisualInfo*)vi)->visualid; int myScreen = ((XVisualInfo*)vi)->screen; for ( int i = 0; i < (int)trans_colors.size(); i++ ) { if ( trans_colors[i].vis == myVisualId && trans_colors[i].screen == myScreen ) { XColor col; col.pixel = trans_colors[i].color; col.red = col.green = col.blue = 0; col.flags = 0; Display *dpy = d->paintDevice->x11Display(); if (col.pixel > (uint) ((XVisualInfo *)vi)->colormap_size - 1) col.pixel = ((XVisualInfo *)vi)->colormap_size - 1; XQueryColor(dpy, choose_cmap(dpy, (XVisualInfo *) vi), &col); uchar r = (uchar)((col.red / 65535.0) * 255.0 + 0.5); uchar g = (uchar)((col.green / 65535.0) * 255.0 + 0.5); uchar b = (uchar)((col.blue / 65535.0) * 255.0 + 0.5); return QColor(qRgb(r,g,b), trans_colors[i].color); } } } return QColor(); // Invalid color }
static void default_colors() { Arg args[5]; Pixel background, foreground, top_shadow, bottom_shadow, arm_color; Pixel r_foreground, r_top_shadow, r_bottom_shadow, r_arm_color; Widget widget; int n = 0; XColor color; widget = XtNameToWidget(fetched,"color_change_BB.color_change"); XtSetArg(args[n], XmNbackground, &background); n++; XtGetValues(widget, args, n); XmGetColors(XtScreen(widget), cmap, background, &r_foreground, &r_top_shadow, &r_bottom_shadow, &r_arm_color); XtSetArg(args[n], XmNforeground, &foreground); n++; XtSetArg(args[n], XmNtopShadowColor, &top_shadow); n++; XtSetArg(args[n], XmNbottomShadowColor, &bottom_shadow); n++; XtSetArg(args[n], XmNarmColor, &arm_color); n++; XtGetValues(widget, args, n); color.pixel = r_foreground; XQueryColor(dpy,cmap,&color); color.pixel = foreground; XStoreColor(dpy, cmap, &color); color.pixel = background; XQueryColor(dpy,cmap,&color); color.pixel = background; XStoreColor(dpy, cmap, &color); color.pixel = r_top_shadow; XQueryColor(dpy,cmap,&color); color.pixel = top_shadow; XStoreColor(dpy, cmap, &color); color.pixel = r_bottom_shadow; XQueryColor(dpy,cmap,&color); color.pixel = bottom_shadow; XStoreColor(dpy, cmap, &color); color.pixel = r_arm_color; XQueryColor(dpy,cmap,&color); color.pixel = arm_color; XStoreColor(dpy, cmap, &color); }
static void InstallColours(void) { int pixVal=0; int c, f, ggap, steps[GSTP] = {8, 4, 2, 1}; XColor greyDef, whiteDef, blackDef, colourDef; short RGBval, step; /* initialise the grey levels/colours depending on the number of planes */ for (c = 0; c < MAX_COLOURS; c++){ /* get colour from the X11 database */ if (!XParseColor(theDisp, theCmap, XColArray[c], &colourDef)) HError(6870,"InstallColours: Colour name %s not in X11 database", XColArray[c]); if (!XAllocColor(theDisp, theCmap, &colourDef)) HError(-6870,"InstallColours: Cannot allocate colour %s", XColArray[c]); else pixVal = colourDef.pixel; colours[c] = pixVal; } if (dispDEEP == 1){ /* map all grey levels onto b/w */ for (c = 0; c < MAX_GREYS/2; c++) greys[c] = white; for (c = MAX_GREYS/2; c < MAX_GREYS; c++) greys[c] = black; } else { /* then the grey levels */ whiteDef.pixel = white; XQueryColor(theDisp, theCmap, &whiteDef); blackDef.pixel = black; XQueryColor(theDisp, theCmap, &blackDef); ggap = ((int)(whiteDef.red - blackDef.red))/MAX_GREYS; for (f = 0; f < GSTP; f++){ step = steps[f]*ggap; for (c = 0; c < (MAX_GREYS/steps[f]); c++){ RGBval = whiteDef.red - c*step; greyDef.red = RGBval; greyDef.green = RGBval; greyDef.blue = RGBval; if (!XAllocColor(theDisp, theCmap, &greyDef)) HError(-6870, "InstallColours: Cannot allocate grey level %d", c*steps[f]); else pixVal = greyDef.pixel; greys[c] = pixVal; } } } }
// Get pixel color at coordinates x,y void pixel_color (Display *display, int x, int y, XColor *color) { XImage *image; image = XGetImage (display, DefaultRootWindow (display), x, y, 1, 1, AllPlanes, XYPixmap); color->pixel = XGetPixel (image, 0, 0); XFree (image); XQueryColor (display, DefaultColormap(display, DefaultScreen (display)), color); }
void JColor::setPixel(int _pixel) { if (hnd == _pixel) return; XColor color; color.pixel = _pixel; XQueryColor(JUNIX::theDisplay, JUNIX::theColormap, &color); value = JColor(color.red >> 8, color.green >> 8, color.blue >> 8).getRGB(); Release(); }
/* %F Funcao usando tabela de conversao. \ Usada quando nao estamos em TrueColor. */ static void not_truecolor_get_rgb(unsigned long pixel, unsigned char* red, unsigned char* green, unsigned char* blue) { XColor xc; xc.pixel = pixel; XQueryColor(iupmot_display, iupmot_color.colormap, &xc); *red = (unsigned char)xc.red; *green = (unsigned char)xc.green; *blue = (unsigned char)xc.blue; }
unsigned char GetBValue(Display *display, unsigned long pixel) { Colormap cm; XColor xc; cm = DefaultColormap(display, DefaultScreen(display)); XQueryColor(display, cm, &xc); return xc.blue / 256; }
LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { xPriv * priv = (xPriv *)g->priv; XColor color; XImage *img; img = XGetImage (dis, priv->pix, g->p.x, g->p.y, 1, 1, AllPlanes, XYPixmap); color.pixel = XGetPixel (img, 0, 0); XFree(img); XQueryColor(dis, cmap, &color); return RGB2COLOR(color.red>>8, color.green>>8, color.blue>>8); }
/* ColorPixelToRGB {{{ */ static void ColorPixelToRGB(XColor *xcolor) { XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), xcolor); /* Scale 65535 to 255 */ xcolor->red = SCALE(xcolor->red, 65535, 255); xcolor->green = SCALE(xcolor->green, 65535, 255); xcolor->blue = SCALE(xcolor->blue, 65535, 255); } /* }}} */
void OGLwin_GetColorVal(int ind, short *r, short *g, short *b) { XColor color; color.pixel = ind; XQueryColor(Dsp, Cmap, &color); *r = color.red; *g = color.green; *b = color.blue; }
bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out) { XColor c; c.pixel=in; XQueryColor(ioncore_g.dpy, rootwin->default_cmap, &c); if(XAllocColor(ioncore_g.dpy, rootwin->default_cmap, &c)){ *out=c.pixel; return TRUE; } return FALSE; }
XColor *GetTintedColor(Pixel in, Pixel tint, int percent) { XColor tint_color; memset(&color, 0, sizeof(color)); memset(&tint_color, 0, sizeof(tint_color)); color.pixel = in; XQueryColor(Pdpy, Pcmap, &color); tint_color.pixel = tint; XQueryColor(Pdpy, Pcmap, &tint_color); color.red = (unsigned short) (((100-percent)*color.red + tint_color.red * percent) / 100); color.green = (unsigned short) (((100-percent)*color.green + tint_color.green * percent) / 100); color.blue = (unsigned short) (((100-percent)*color.blue + tint_color.blue * percent) / 100); return &color; }
ColorRep::ColorRep ( long p, ColorIntensity& r, ColorIntensity& g, ColorIntensity& b ) { XColor* c = new XColor; c->pixel = p; XQueryColor(_world->display(), _world->cmap(), c); r = c->red; g = c->green; b = c->blue; info = (void*)c; }
XColor *GetForeShadowColor(Pixel foreground, Pixel background) { XColor bg_color; float fg[3], bg[3]; int result[3]; int i; memset(&color, 0, sizeof(color)); memset(&bg_color, 0, sizeof(bg_color)); color.pixel = foreground; bg_color.pixel = background; XQueryColor(Pdpy, Pcmap, &color); XQueryColor(Pdpy, Pcmap, &bg_color); fg[0] = color.red; fg[1] = color.green; fg[2] = color.blue; bg[0] = bg_color.red; bg[1]= bg_color.green; bg[2] = bg_color.blue; for (i=0; i<3; i++) { if (fg[i] - bg[i] < 8192 && fg[i] - bg[i] > -8192) { result[i] = 0; } else { result[i] = (int)((5 * bg[i] - fg[i]) / 4); if (fg[i] < bg[i] || result[i] < 0) { result[i] = (int)((3 * bg[i] + fg[i]) / 4); } } } color.red = result[0]; color.green = result[1]; color.blue = result[2]; return &color; }
Cursor MakeStringCursor(char *string) { Cursor cursor; XColor black, white; Pixmap bitmap; unsigned int width, height, middle; GC gc; Colormap cmap = Scr->RootColormaps.cwins[0]->colormap->c; MyFont myfont = Scr->TitleBarFont; XRectangle inc_rect; XRectangle logical_rect; black.pixel = Scr->Black; XQueryColor(dpy, cmap, &black); white.pixel = Scr->White; XQueryColor(dpy, cmap, &white); XmbTextExtents(myfont.font_set, string, strlen(string), &inc_rect, &logical_rect); width = logical_rect.width + 4; height = logical_rect.height + 2; middle = myfont.ascent; /*XQueryBestCursor (dpy, Scr->Root, width, height, &rwidth, &rheight);*/ bitmap = XCreatePixmap(dpy, Scr->Root, width, height, 1); gc = XCreateGC(dpy, bitmap, 0L, NULL); XSetForeground(dpy, gc, 0L); XFillRectangle(dpy, bitmap, gc, 0, 0, width, height); XSetForeground(dpy, gc, 1L); XDrawRectangle(dpy, bitmap, gc, 0, 0, width - 1, height - 1); XmbDrawString(dpy, bitmap, myfont.font_set, gc, 2, middle, string, strlen(string)); cursor = XCreatePixmapCursor(dpy, bitmap, None, &black, &white, 0, 0); XFreePixmap(dpy, bitmap); XFreeGC(dpy, gc); return (cursor); }