GC create_gc(Display* display, Window win, int reverse_video) { GC gc; unsigned long valuemask = 0; XGCValues values; unsigned int line_width = 2; int line_style = LineSolid; int cap_style = CapButt; int join_style = JoinBevel; int screen_num = DefaultScreen(display); gc = XCreateGC(display, win, valuemask, &values); if (gc < 0) { fprintf(stderr, "XCreateGC: \n"); } if (reverse_video) { XSetForeground(display, gc, WhitePixel(display, screen_num)); XSetBackground(display, gc, BlackPixel(display, screen_num)); } else { XSetForeground(display, gc, BlackPixel(display, screen_num)); XSetBackground(display, gc, WhitePixel(display, screen_num)); } XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style); XSetFillStyle(display, gc, FillSolid); return gc; }
void Painter::SetColors(const Color* f, const Color* b) { if (rep->iv_xor) { End_xor(); } /* * Make sure to reference both new colors before unreferencing the old * in case the call is swapping colors. */ if (foreground != f) { Resource::ref(f); } if (background != b) { Resource::ref(b); } XDisplay* dpy = rep->display->rep()->display_; if (f != nil && foreground != f) { Resource::unref(foreground); foreground = f; unsigned long pixel = foreground->PixelValue(); XSetForeground(dpy, rep->fillgc, pixel); XSetForeground(dpy, rep->dashgc, pixel); } if (b != nil && background != b) { Resource::unref(background); background = b; unsigned long pixel = background->PixelValue(); XSetBackground(dpy, rep->fillgc, pixel); XSetBackground(dpy, rep->dashgc, pixel); } }
static BOOL xf_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) { xfContext* xfc = (xfContext*) context; XRectangle rect; XColor xbgcolor, xfgcolor; if (!xf_decode_color(xfc, bgcolor, &xbgcolor)) return FALSE; if (!xf_decode_color(xfc, fgcolor, &xfgcolor)) return FALSE; rect.x = x; rect.y = y; rect.width = width; rect.height = height; xf_lock_x11(xfc, FALSE); if (!fOpRedundant) { XSetForeground(xfc->display, xfc->gc, xfgcolor.pixel); XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel); XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled); XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, width, height); } XSetForeground(xfc->display, xfc->gc, xbgcolor.pixel); XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel); xf_unlock_x11(xfc, FALSE); return TRUE; }
GC create_gc(Display* display, Window win, int reverse_video){ GC gc; /* handle of newly created GC. */ unsigned long valuemask = 0; /* which values in 'values' to */ /* check when creating the GC. */ XGCValues values; /* initial values for the GC. */ unsigned int line_width = 2; /* line width for the GC. */ int line_style = LineSolid; /* style for lines drawing and */ int cap_style = CapButt; /* style of the line's edje and */ int join_style = JoinBevel; /* joined lines. */ int screen_num = DefaultScreen(display); gc = XCreateGC(display, win, valuemask, &values); if (gc < 0) { fprintf(stderr, "XCreateGC: \n"); } /* allocate foreground and background colors for this GC. */ if (reverse_video) { XSetForeground(display, gc, WhitePixel(display, screen_num)); XSetBackground(display, gc, BlackPixel(display, screen_num)); } else { XSetForeground(display, gc, BlackPixel(display, screen_num)); XSetBackground(display, gc, WhitePixel(display, screen_num)); } /* define the style of lines that will be drawn using this GC. */ XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style); /* define the fill style for the GC. to be 'solid filling'. */ XSetFillStyle(display, gc, FillSolid); return gc; }
void setbkcolor(int color) { XColor background; XColor unused; char *bg; int screen_number; int rc; #ifdef ALLOCATE_COLOR_CELLS XStoreNamedColor(dpy, cmap, Colors[color], background_pixel, (DoRed|DoGreen|DoBlue)); #else if (-1 == color) { // returned by COLOR() XSetBackground(dpy, gc, current_rgb_colour); if (visual_page == active_page) XSetWindowBackground(dpy, window, current_rgb_colour); bg_rgb_colour = current_rgb_colour; } else { rc = XSetBackground(dpy, gc, vga_palette[color].pixel_value); if (visual_page == active_page) { XSetWindowBackground(dpy, window, vga_palette[color].pixel_value); } bg_colour = color; } #endif }
void init_contexts() { static int i; /* * create default, writable, graphics contexts for the canvas. */ Data_GC[0] = XCreateGC(dpy, DefaultRootWindow(dpy), (unsigned long) NULL, (XGCValues *) NULL); /* set the background to black */ XSetBackground(dpy,Data_GC[0],BlackPixel(dpy, screen)); /* set the foreground of the 0th context to black */ XSetForeground(dpy, Data_GC[0], BlackPixel(dpy, screen)); Data_GC[1] = XCreateGC(dpy, DefaultRootWindow(dpy), (unsigned long) NULL, (XGCValues *) NULL); /* set the background to black */ XSetBackground(dpy,Data_GC[1],BlackPixel(dpy, screen)); /* set the foreground of the 1st context to white */ XSetForeground(dpy, Data_GC[1], WhitePixel(dpy, screen)); for (i=2; i<maxcolor; i++) { Data_GC[i] = XCreateGC(dpy, DefaultRootWindow(dpy), (unsigned long) NULL, (XGCValues *) NULL); /* set the background to black */ XSetBackground(dpy,Data_GC[i],BlackPixel(dpy, screen)); /* set the foreground of the ith context to i */ XSetForeground(dpy, Data_GC[i], i); } }
void MyFrame::init_graphics() { /* global variables */ Widget canvas; Display *theDisplay; XImage *pic_array[MAXIMAGES]; GC invertGC, drawGC; int scrn; Display *dpy; Window grwin; Colormap fixedcmap; unsigned long blackPix, whitePix; unsigned int depth; Visual *use_visual; dpy = XtDisplay(canvas); grwin = XtWindow(canvas); scrn = DefaultScreen(dpy); use_visual = DefaultVisual(dpy, scrn); #if 1 fixedcmap = XCreateColormap(dpy, grwin, use_visual, AllocNone); #else fixedcmap = DefaultColormap(dpy, scrn); #endif fixedcmap = InitColorTableFixed(fixedcmap); XtVaGetValues(canvas, XmNdepth, &depth, NULL); XtVaSetValues(toplevel, XmNcolormap, fixedcmap, NULL); XtSetWMColormapWindows(toplevel, &canvas, 1); /**************************************************************/ blackPix = _get_lookup_for_color(0, 0, 0); whitePix = _get_lookup_for_color(255, 255, 255); drawGC = XCreateGC(XtDisplay(canvas), XtWindow(canvas), (unsigned long)0, NULL); theDisplay = XtDisplay(toplevel); XSetFunction(theDisplay, drawGC, GXcopy); XSetForeground(theDisplay, drawGC, blackPix); XSetBackground(theDisplay, drawGC, whitePix); invertGC = XCreateGC(XtDisplay(canvas), XtWindow(canvas), (unsigned long)0, NULL); XSetFunction(theDisplay, invertGC, GXcopy); XSetForeground(theDisplay, invertGC, whitePix); XSetBackground(theDisplay, invertGC, blackPix); }
GC SpadFillGC(Display *dsply,int hue, int theshade,char * fill_routine) { int dither; int color; if (!SpadFillInit) { fprintf(stderr, "Tried to use SpadFillGC before calling XInitSpadFill\n"); exit(0); } if (theshade >= totalShades) { fprintf(stderr, "Shade %d out of range\n",theshade); exit(-1); } if (hue >= totalHues) { fprintf(stderr, "Error Hue %d is out of range\n",hue); exit(-1); } dither = ((theshade) % (totalDithered - 1)); if (dither != 0) { XChangeDither(dsply, stippleGC, dither); if (theshade < totalDithered) { /* Dither to black */ color = totalSolid * hue; XSetForeground(dsply, stippleGC, black); XSetBackground(dsply, stippleGC, spadColors[color]); } else if (theshade > (totalShades - totalDithered)) { /* Dither to white */ color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; XSetForeground(dsply, stippleGC, spadColors[color]); XSetBackground(dsply, stippleGC, white); } else { color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; XSetForeground(dsply, stippleGC, spadColors[color]); XSetBackground(dsply, stippleGC, spadColors[color + 1]); } return (stippleGC); } else { if (theshade == 0) XSetForeground(dsply, solidGC, black); else if (theshade == (totalShades - 1)) XSetForeground(dsply, solidGC, white); else { color = ((theshade) / (totalDithered - 1)) + totalSolid * hue - 1; XSetForeground(dsply, solidGC, spadColors[color]); } return (solidGC); } }
static void x_create_gcs(void) { /* normal GC */ dzen.gc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), 0, 0); XSetForeground(dzen.dpy, dzen.gc, dzen.norm[ColFG]); XSetBackground(dzen.dpy, dzen.gc, dzen.norm[ColBG]); /* reverse color GC */ dzen.rgc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), 0, 0); XSetForeground(dzen.dpy, dzen.rgc, dzen.norm[ColBG]); XSetBackground(dzen.dpy, dzen.rgc, dzen.norm[ColFG]); /* temporary GC */ dzen.tgc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), 0, 0); }
static void ui_sel_showSelectedItem (struct Ui_DisplayType *displayPtr, FlagType scope, int unitNo, struct PosType gridPos) { struct PosType pos1, pos2; struct Ui_DisplayType *dPtr; if (scope == UI_GLOBAL) { for (dPtr = ui_displ_listPtr; dPtr != NULL; dPtr = dPtr ->nextPtr) ui_sel_showSelectedItem(dPtr, UI_LOCAL, unitNo, gridPos); } else { if ((NOT displayPtr->frozen) AND ui_isUnitVisibleInDisplay(displayPtr, unitNo)) { if (ui_col_colorDisplay) { XSetFunction(ui_display, ui_gc, GXcopy); XSetBackground(ui_display, ui_gc, ui_backgroundColor); XSetForeground(ui_display, ui_gc, ui_selectionColor); } else { XSetFunction(ui_display, ui_gc, GXcopyInverted); XSetBackground(ui_display, ui_gc, ui_backgroundColor); XSetForeground(ui_display, ui_gc, ui_textColor); } pos1 = ui_utilGridToPix(displayPtr, gridPos); pos1.x -= (ui_selectionSize / 2); pos1.y -= (ui_selectionSize / 2); pos2.x = pos1.x + ui_selectionSize - 1; pos2.y = pos1.y + ui_selectionSize - 1; /* ui_xDeleteRect(ui_display, displayPtr->drawable, ui_gc, pos1, pos2); */ if (ui_col_colorDisplay) ui_xDeleteRect(ui_display, displayPtr->drawable, ui_gc, pos1, pos2); else { ui_xDeleteRect(ui_display, displayPtr->drawable, ui_gc, pos1, pos2); XSetFunction(ui_display, ui_gc, GXcopy); ui_xDrawCrossBox(ui_display, displayPtr->drawable, ui_gc, pos1, pos2); } } } }
//F gfx_init gfx 0 0 void gfx_init(){ //Initialize our environment disp = XOpenDisplay(NULL); screen = DefaultScreen(disp); fg = WhitePixel(disp, screen); bg = BlackPixel(disp, screen); cm = DefaultColormap(disp, DefaultScreen(disp)); colors = (XColor*) malloc(sizeof(XColor) * 8); int err = 0; err = XAllocNamedColor(disp, cm, "white", &colors[0], &colors[0]); err += XAllocNamedColor(disp, cm, "black", &colors[1], &colors[1]); err += XAllocNamedColor(disp, cm, "red", &colors[2], &colors[2]); err += XAllocNamedColor(disp, cm, "blue", &colors[3], &colors[3]); err += XAllocNamedColor(disp, cm, "green", &colors[4], &colors[4]); if(err == 0){ puts("Failed to allocate color!!!"); exit(-1); } //Register our window with default properties win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), \ 200, 200, 640, 480, 5, fg, bg); XSetStandardProperties(disp, win, title, "Placeholder", None, NULL, 0, NULL); //Initialize the graphics and input context = XCreateGC(disp, win, 0, 0); XSetBackground(disp, context, bg); XSetForeground(disp, context, fg); XClearWindow(disp, win); XMapWindow(disp, win); }
void init_x() { unsigned long black,white; dis=XOpenDisplay((char *)0); if(dis == NULL) { fprintf(stderr,"error: cannot open window\n"); exit(1); } screen = DefaultScreen(dis); black = BlackPixel(dis,screen), /* get color black */ white = WhitePixel(dis, screen); /* get color white */ win = XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0, 200, 300, 5, black, white); XSetStandardProperties(dis,win,"My Window","HI!",None,NULL,0,NULL); XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask); gc=XCreateGC(dis, win, 0,0); XSetBackground(dis,gc,white); XSetForeground(dis,gc,black); XClearWindow(dis, win); XMapRaised(dis, win); }
void handleButtonPress (XEvent *myevent, struct drawing *canvas, struct window *win) /* Zoom in on the mouse pointer */ { double range = 0.0; range = fractal_options.range; /* center clicked area */ fractal_options.origin.real += (double) (range * myevent->xbutton.x) / (double) (canvas->width * 2.0); fractal_options.origin.imag -= (double) (range * myevent->xbutton.y) / (double) (canvas->height * 2.0); /* and magnify */ fractal_options.range /= 2.0; /* increase the depth so there's a picture worth looking at */ fractal_options.depth *= 2.0; print_fractal_info (); XSetForeground (win->display, win->gc, 0x00); XSetBackground (win->display, win->gc, 0x00); XFillRectangle (win->display, canvas->pixmap, win->gc, 0, 0, canvas->width, canvas->height); XClearWindow (win->display, win->win); if (fractal_options.type == MANDELBROT) mandelbrot (canvas, win); else julia (canvas, win); }
void draw_score_board(PANE_TYPE which_pane) { int i, y; const char *string; PANE pane = all_panes[which_pane]; XSetForeground(disp, gc, cm_pixels[bkgr_colour]); XFillRectangle(disp, pane, gc, ScoreX-5, ScoreY-5, ScoreWidth+10, ScoreHeight+10); XSetForeground(disp, gc, cm_pixels[score_colour]); XDrawRectangle(disp, pane, gc, ScoreX-5, ScoreY-5, ScoreWidth+10, ScoreHeight+10); XDrawRectangle(disp, pane, gc, ScoreX-3, ScoreY-3, ScoreWidth+6, ScoreHeight+6); if (ConsFont == 0) { XSetBackground(disp, gc, cm_pixels[bkgr_colour]); XSetFont(disp, gc, FontId[FT_FIXED]); } for (i=0; i< ScoreLines; i++) { string = ScoreLineText[i]; y = ScoreLineY[i]; if (ConsFont == 0) XDrawImageString (disp, pane, gc, ScoreLineX, y, string, strlen(string)); else show_shadow_text(which_pane, FT_FIXED, string, ScoreLineX, y-FixedFontAscent, 1, 1, 0, 0, score_colour, bkgr_colour, ST_NO_STIPPLE); } flush_pane(which_pane, ScoreX-5, ScoreY-5, ScoreWidth+10, ScoreHeight+10); }
void paintLabel(AppInfo *app, Drawable draw, LabelInfo label) { TextObject *t; Position x; Position y; if (!(label.fullText)) { return; } XSetForeground(app->dpy, app->textGC, label.w.foreground); XSetBackground(app->dpy, app->textGC, label.w.background); XSetFont(app->dpy, app->textGC, label.font->fid); t = label.multiText; x = label.w.x; y = label.w.y + t->ascent; while (NULL != t) { if (t->text) { XDrawString(app->dpy, draw, app->textGC, x, y, t->text, t->textLength); } y += t->descent; t = t->next; if (t) { y += t->ascent; } } }
void CreateDock(int argc, char *argv[]) /* this part comes from http://www.linuxmag-france.org/ */ { Window root; XWMHints wmHints; XSizeHints sizeHints; XClassHint classHint; Pixmap pixmask; unsigned long p_blanc; unsigned long p_noir; unsigned int borderWidth = 2; char *wname = argv[0] ; dpy = XOpenDisplay(NULL) ; if(dpy == NULL) { fprintf(stderr, "Can't open display\n") ; exit(1) ; } root = RootWindow(dpy,screen); p_blanc = WhitePixel(dpy,screen) ; p_noir = BlackPixel(dpy,screen) ; gc = XDefaultGC(dpy,screen) ; XSetForeground(dpy, gc, p_noir); XSetBackground(dpy, gc,p_noir); sizeHints.x = 0 ; sizeHints.y = 0 ; sizeHints.width = 64 ; sizeHints.height = 64 ; win = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y , sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir) ; iconWin = XCreateSimpleWindow(dpy,root,sizeHints.x,sizeHints.y,sizeHints.width, sizeHints.height, borderWidth, p_noir,p_noir ) ; sizeHints.flags = USSize | USPosition ; XSetWMNormalHints(dpy,win,&sizeHints) ; wmHints.initial_state = WithdrawnState ; wmHints.icon_window = iconWin ; wmHints.icon_x = sizeHints.x ; wmHints.icon_y = sizeHints.y ; wmHints.window_group = win ; wmHints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint ; XSetWMHints(dpy, win, &wmHints) ; classHint.res_name = wname ; classHint.res_class = wname ; XSetClassHint(dpy, win, &classHint) ; XSetCommand(dpy,win, argv, argc) ; pixmask = XCreateBitmapFromData(dpy,win,fond_bits, fond_width, fond_height) ; XShapeCombineMask(dpy,win,ShapeBounding,0,0,pixmask,ShapeSet) ; XShapeCombineMask(dpy,iconWin,ShapeBounding, 0, 0, pixmask, ShapeSet) ; XpmCreatePixmapFromData(dpy,root,wmAppKill_xpm, &XPM, NULL,NULL) ; XSelectInput(dpy,win, ExposureMask | ButtonPressMask) ; XSelectInput(dpy,iconWin, ExposureMask | ButtonPressMask) ; XMapWindow(dpy,win) ; }
void debrush_do_draw_string_default_bmf( DEBrush *brush, int x, int y, const char *str, int len, bool needfill, DEColourGroup *colours) { GC gc=brush->d->normal_gc; if(brush->d->font==NULL) return; XSetForeground(ioncore_g.dpy, gc, PIXEL(colours->fg)); if(!needfill){ if(brush->d->font->fontset!=NULL){ #ifdef CF_DE_USE_XUTF8 if(ioncore_g.enc_utf8) Xutf8DrawString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); else #endif XmbDrawString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); }else if(brush->d->font->fontstruct!=NULL){ if(ioncore_g.enc_utf8){ XChar2b *str16; int len16=0; toucs(str, len, &str16, &len16); XDrawString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16); free(str16); }else{ XDrawString(ioncore_g.dpy, brush->win, gc, x, y, str, len); } } }else{ XSetBackground(ioncore_g.dpy, gc, PIXEL(colours->bg)); if(brush->d->font->fontset!=NULL){ #ifdef CF_DE_USE_XUTF8 if(ioncore_g.enc_utf8) Xutf8DrawImageString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); else #endif XmbDrawImageString(ioncore_g.dpy, brush->win, brush->d->font->fontset, gc, x, y, str, len); }else if(brush->d->font->fontstruct!=NULL){ if(ioncore_g.enc_utf8){ XChar2b *str16; int len16=0; toucs(str, len, &str16, &len16); XDrawImageString16(ioncore_g.dpy, brush->win, gc, x, y, str16, len16); free(str16); }else{ XDrawImageString(ioncore_g.dpy, brush->win, gc, x, y, str, len); } } } }
static void RefreshAppearance () { static char *operation_text = NULL; XmString label; Window window; window = XtWindow (Progress_widget); XSetForeground (display, Progress_gc, hci_get_read_color (WHITE)); XSetBackground (display, Progress_gc, hci_get_read_color (WHITE)); XFillRectangle (display, window, Progress_gc, 0, 0, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT); XSetForeground (display, Progress_gc, hci_get_read_color (BLACK)); XFillRectangle (display, window, Progress_gc, 0, 0, Bar_width, PROGRESS_BAR_HEIGHT); operation_text = STR_copy (operation_text, "Operation:\t"); operation_text = STR_cat (operation_text, Operation); label = XmStringCreateLocalized (operation_text); XtVaSetValues (Operation_label, XmNlabelString, label, NULL); XmStringFree (label); label = XmStringCreateLocalized (Transfer_op_label_str); XtVaSetValues (Transfer_op_label, XmNlabelString, label, NULL); XmStringFree (label); label = XmStringCreateLocalized (Transfer_rate_label_str); XtVaSetValues (Transfer_rate_label, XmNlabelString, label, NULL); XmStringFree (label); if( Visible ){ XmUpdateDisplay( Main_widget ); } }
static void set_up_gc () { text_box.screen = DefaultScreen (text_box.display); text_box.gc = XCreateGC (text_box.display, text_box.window, 0, 0); XSetBackground (text_box.display, text_box.gc, text_box.white_pixel); XSetForeground (text_box.display, text_box.gc, text_box.black_pixel); }
/* note: unused Drawable d */ GC XCreateGC(Display *dpy, Drawable d, unsigned long valuemask, XGCValues *values) { GC gc; XGCValues *vp; if ((gc = (GC) Xmalloc(sizeof(struct _XGC))) == NULL) return NULL; if ((vp = (XGCValues *)Xmalloc(sizeof(XGCValues))) == NULL) { Xfree(gc); return NULL; } gc->ext_data = (XExtData *)vp; memcpy(vp, &initial_GC, sizeof(initial_GC)); gc->gid = GrNewGC(); /* X11 doesn't draw background, must set on all GrNewGC's*/ GrSetGCUseBackground(gc->gid, GR_FALSE); /* X11 defaults to fg=black, bg=white, NX is opposite...*/ if (!(valuemask & GCForeground)) XSetForeground(dpy, gc, 0L); /* black*/ if (!(valuemask & GCBackground)) XSetBackground(dpy, gc, ~0L); /* white*/ setupGC(dpy, gc, valuemask, values); return gc; }
void xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) { xfContext* xfc = (xfContext*) context; bgcolor = freerdp_convert_gdi_order_color(bgcolor, context->settings->ColorDepth, xfc->format, xfc->palette); fgcolor = freerdp_convert_gdi_order_color(fgcolor, context->settings->ColorDepth, xfc->format, xfc->palette); xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); if (width && height) { XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, fgcolor); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, width, height); } XSetForeground(xfc->display, xfc->gc, bgcolor); XSetBackground(xfc->display, xfc->gc, fgcolor); XSetFillStyle(xfc->display, xfc->gc, fOpRedundant ? FillOpaqueStippled : FillStippled); xf_unlock_x11(xfc, FALSE); }
int drawText(Display *d, int screen, Window *w, GC *gc, const char *str) { XFontStruct *font; XColor textColor; char **list; int textWidth, textHeight, textX, textY, returnNo; list = XListFonts(d, "-*-*-bold-r-normal--*-*-100-100-c-*-*", 200, &returnNo); if (returnNo) { srand(time(NULL)); static int fontIndex = rand() % returnNo; font = XLoadQueryFont(d, *(list + fontIndex)); XFreeFontNames(list); } if (!font) return -1; XParseColor(d, DefaultColormap(d, screen), text, &textColor); XAllocColor(d, DefaultColormap(d, screen), &textColor); XSetForeground(d, *gc, textColor.pixel); XSetBackground(d, *gc, WhitePixel(d, screen)); XSetFont(d, *gc, font->fid); textWidth = XTextWidth(font, str, strlen(str)); textHeight = font->ascent + font->descent; textX = (windowWidth - textWidth) / 2; textY = ((windowHeight - rectHeight) / 2 - textHeight) / 2 + textHeight / 2; XDrawImageString(d, *w, *gc, textX, textY, str, strlen(str)); return 0; }
void DisplayX11::ASetBackground( char * color ) { XColor def, closest; XAllocNamedColor( disp, DefaultColormap( disp, 0 ), color, &def, &closest ); XSetBackground( disp, gc, closest.pixel ); }
static x11_window_t*create_window(Display*disp, Window root, int wid) { x11_window_t*win = NULL; opp_str2_alloc2((char**)&win,sizeof(x11_window_t)); win->black_pixel = WhitePixel (gcore.disp, gcore.scrn); win->white_pixel = BlackPixel (gcore.disp, gcore.scrn); win->title = "great"; /* Suggest where to position the window: */ XSizeHints myhint; myhint.x = 200,myhint.y = 200; myhint.width = win->width = 200; myhint.height = win->height = 200; myhint.flags = PPosition | PSize; win->w = XCreateSimpleWindow( disp , root , 200, 200 , win->width, win->height , 5 /* border width */ , win->black_pixel/*foreground*/, win->white_pixel /*background*/ ); aroop_indexed_list_set(&gcore.pwins, wid, win); XSetStandardProperties (disp, win->w, win->title, win->title, None, argv, argc, &myhint); win->gc = XCreateGC(disp, win->w, 0, 0); XSetBackground (disp, win->gc, win->white_pixel); XSetForeground (disp, win->gc, win->black_pixel); /* Select input devices to listen to: */ XSelectInput (disp, win->w, StructureNotifyMask | ButtonPressMask | KeyPressMask | ExposureMask); // display window XMapRaised (disp, win->w); //XMapWindow(disp, win->w); gcore.wid = wid; watchdog_log_string("Created new X11 window\n"); return win; }
/** * @brief The default constructor. You need to call this to initialize the engine. * @param[in] width The width of the desired screen. * @param[in] height The height of the desired screen. * @param[in] title You can supply a title for a window here. * @param[in] argc The number of arguments passed to your application (optional) * @param[in] argv The arguments passed to your application (optional) */ Simple3D::Simple3D(int width, int height,std::string title,int argc, char **argv) { for(int i=0;i<argc;i++) { if(argv[i][1] == 'A') options |= S3DOptionDrawAxis; } //This is temporary...hopefully :D options |= S3DOptionDrawAxis; disp = XOpenDisplay((char *)0); screen = DefaultScreen(disp); backColor = BlackPixel(disp,screen); foreColor = WhitePixel(disp,screen); this->width = (unsigned int)width; this->height = (unsigned int)height; window = XCreateSimpleWindow(disp,DefaultRootWindow(disp),0,0,width,height,0,backColor,0); XSetStandardProperties(disp,window,title.c_str(),title.c_str(),None,NULL,0,NULL); XMapWindow(disp,window); XSelectInput(disp, window, StructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask); gc = XCreateGC(disp,window,0,0); XSetForeground(disp,gc,foreColor); XSetBackground(disp,gc,backColor); backbuffer = XCreatePixmap(disp,window,width,height,24); zbuffer = new S3DZBuffer(width,height); }
BOOL xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant) { xfContext* xfc = (xfContext*) context; bgcolor = xf_convert_rdp_order_color(xfc, bgcolor); fgcolor = xf_convert_rdp_order_color(xfc, fgcolor); xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); if (width && height) { XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, fgcolor); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, width, height); } XSetForeground(xfc->display, xfc->gc, bgcolor); XSetBackground(xfc->display, xfc->gc, fgcolor); XSetFillStyle(xfc->display, xfc->gc, fOpRedundant ? FillOpaqueStippled : FillStippled); xf_unlock_x11(xfc, FALSE); return TRUE; }
void paintBackground( XInfo& xinfo, PixmapArray& pixmapArray ) { XClearWindow( xinfo.display, xinfo.window ); // Paint rainbow paintRainbowArc( xinfo, 0, XInfoColor::ORANGE ); paintRainbowArc( xinfo, 1, XInfoColor::YELLOW ); paintRainbowArc( xinfo, 2, XInfoColor::GREEN ); paintRainbowArc( xinfo, 3, XInfoColor::BLUE ); paintRainbowArc( xinfo, 4, XInfoColor::INDIGO ); paintRainbowArc( xinfo, 5, XInfoColor::PURPLE ); paintRainbowArc( xinfo, 6, XInfoColor::RED ); // Paint title int titleX = xinfo.windowAttr.width/2 - (290/2); int titleY = 50; XSetForeground( xinfo.display, xinfo.gc, xinfo.color[ (int) XInfoColor::BLACK ].pixel ); XSetBackground( xinfo.display, xinfo.gc, xinfo.color[ (int) XInfoColor::RED ].pixel ); XCopyPlane( xinfo.display, pixmapArray[ PixmapArray::TITLE ], xinfo.window, xinfo.gc, 0, 0, 290, 184, titleX, titleY, 1 ); // Paint Stalin and instructions int stalinX = xinfo.windowAttr.width - 469; int stalinY = xinfo.windowAttr.height - 307; XCopyPlane( xinfo.display, pixmapArray[ PixmapArray::STALIN ], xinfo.window, xinfo.gc, 0, 0, 469, 307, stalinX, stalinY, 1 ); }
//Display functions. void display_init (void) { _D=XOpenDisplay(NULL); if (_D==NULL) { fprintf(stderr, "Could not open display.\n"); exit(EXIT_FAILURE); } _S=DefaultScreen(_D); white_pixel=WhitePixel(_D, _S); black_pixel=BlackPixel(_D, _S); _W=XCreateSimpleWindow(_D, RootWindow(_D, _S), 100, 100, W_Width, W_Height, 1, black_pixel, white_pixel); XSelectInput(_D, _W, ExposureMask|KeyPressMask); XMapWindow(_D, _W); if ((font_info=XLoadQueryFont(_D, "9x15"))==NULL) { fprintf(stderr, "Could not open 9x15 font.\n"); exit(EXIT_FAILURE); } _gc=XCreateGC(_D, _W, 0, &_V); XSetFont(_D, _gc, font_info->fid); XSetBackground(_D, _gc, white_pixel); _CM = DefaultColormap(_D, _S); if (!XAllocNamedColor(_D, _CM, "red", &red, &red) || !XAllocNamedColor(_D, _CM, "blue", &blue, &blue)) { fprintf(stderr, "Failed to allocated color.\n"); exit(EXIT_FAILURE); //Maybe add support for grayscale displays. } }
static void x_create_gcs(void) { XGCValues gcv; gcv.graphics_exposures = 0; /* normal GC */ dzen.gc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), GCGraphicsExposures, &gcv); XSetForeground(dzen.dpy, dzen.gc, dzen.norm[ColFG]); XSetBackground(dzen.dpy, dzen.gc, dzen.norm[ColBG]); /* reverse color GC */ dzen.rgc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), GCGraphicsExposures, &gcv); XSetForeground(dzen.dpy, dzen.rgc, dzen.norm[ColBG]); XSetBackground(dzen.dpy, dzen.rgc, dzen.norm[ColFG]); /* temporary GC */ dzen.tgc = XCreateGC(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), GCGraphicsExposures, &gcv); }
void xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor) { xfContext* context_ = (xfContext*) context; xfContext* xfc = (xfContext*) context; bgcolor = (xfc->clrconv->invert)? freerdp_color_convert_var_bgr(bgcolor, context_->settings->ColorDepth, xfc->bpp, xfc->clrconv): freerdp_color_convert_var_rgb(bgcolor, context_->settings->ColorDepth, xfc->bpp, xfc->clrconv); fgcolor = (xfc->clrconv->invert)? freerdp_color_convert_var_bgr(fgcolor, context_->settings->ColorDepth, xfc->bpp, xfc->clrconv): freerdp_color_convert_var_rgb(fgcolor, context_->settings->ColorDepth, xfc->bpp, xfc->clrconv); xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, fgcolor); XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, width, height); XSetForeground(xfc->display, xfc->gc, bgcolor); XSetBackground(xfc->display, xfc->gc, fgcolor); XSetFillStyle(xfc->display, xfc->gc, FillStippled); xf_unlock_x11(xfc, FALSE); }