void paintLabel(AppInfo *app, Drawable draw, LabelInfo label) { TextObject *t; Position x; Position y; int first = 1; 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 (!first) XSetFont(app->dpy, app->textGC, label.fixedFont->fid); else first = 0; 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; } } }
int main(int argc, char *argv[]) { Display *display; int screen; GC gc; Window window; XWMHints hints; Atom protocols; XEvent event; unsigned long mask; Font xfont1, xfont2; display = XOpenDisplay(""); screen = DefaultScreen(display); gc = DefaultGC(display, screen); /* * Font names are hard-coded. */ xfont1 = XLoadFont(display, "a14"); xfont2 = XLoadFont(display, "k14"); window = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, W_WIDTH, W_HEIGHT, 2, BlackPixel(display, screen), WhitePixel(display, screen)); XStoreName(display, window, "XFontStruct demo"); hints.flags = InputHint; hints.input = True; XSetWMHints(display, window, &hints); protocols = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &protocols, 1); mask = ExposureMask; XSelectInput(display, window, mask); XMapWindow(display, window); for (;;) { XNextEvent(display, &event); if (XFilterEvent(&event, window) == True) continue; switch (event.type) { case Expose: { XSetFont(display, gc, xfont1); XDrawString(display, window, gc, 10, 50, "abcdef", 6); XSetFont(display, gc, xfont2); /* JIS */ XDrawString16(display, window, gc, 10, 80, (XChar2b *) "\x24\x22\x24\x24", 4); break; } default: { break; } } } }
static void caml_gr_get_font(char *fontname) { XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname); if (font == NULL) caml_gr_fail("cannot find font %s", fontname); if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font); caml_gr_font = font; XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid); XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid); }
/* ------------------------------------------------------------------ */ int drawWinFlag(int c) { char msg[40]; theFont = XLoadFont(theDisplay, FONT18 ); XSetFont(theDisplay, theGC, theFont); sprintf(msg, "YOU WON. With only %d moves !!!", c); XDrawImageString(theDisplay, theWindow, theGC, (wW-10*strlen(msg))/2, wH/2, msg, strlen(msg) ); XFlush(theDisplay); theFont = XLoadFont(theDisplay, FONT10 ); XSetFont(theDisplay, theGC, theFont); return c; }
void SpecialTextInRect(t_x11 *x11, XFontStruct *font, Drawable win, const char *s, int x, int y, int width, int height, eXPos eX, eYPos eY) { int fw, fh, x0, y0; XFontStruct *f; if (font) { XSetFont(x11->disp, x11->gc, font->fid); f = font; } else { f = x11->font; } fw = XTextWidth(f, s, strlen(s)); fh = XTextHeight(f); switch (eX) { case eXLeft: x0 = x; break; case eXRight: x0 = x+width-fw; break; case eXCenter: default: x0 = x+(width-fw)/2; break; } switch (eY) { case eYTop: y0 = y+f->ascent; break; case eYBottom: y0 = y+height-f->descent; break; case eYCenter: default: y0 = y+(height-fh)/2+f->ascent; break; } XDrawString(x11->disp, win, x11->gc, x0, y0, s, strlen(s)); if (font) { XSetFont(x11->disp, x11->gc, x11->font->fid); } }
void Initialize() { disp = XOpenDisplay(NULL); // open $DISPLAY win = XCreateSimpleWindow(disp, // ディスプレイ DefaultRootWindow(disp), // 親ウィンドウ 0, 0, // (x, y) 640, 480, // 幅・高さ 0, // border width 0, // border color WhitePixel(disp, DefaultScreen(disp))); // background color XMapWindow(disp, win); /* ウィンドウに関連付けられたグラフィックコンテキストを作る */ gc = XCreateGC(disp, win, 0, NULL); XSetForeground(disp, gc, BlackPixel(disp, DefaultScreen(disp))); // 暴露イベントとキー押下イベントを受け取る。 XSelectInput(disp, win, ExposureMask | KeyPressMask); font = XLoadQueryFont(disp, FONT); XSetFont(disp, gc, (font)->fid); Colormap colormap; colormap = DefaultColormap(disp, 0); XParseColor(disp, colormap, "#00AA00", &Color.green); XAllocColor(disp, colormap, &Color.green); XParseColor(disp, colormap, "gray50", &Color.gray50); XAllocColor(disp, colormap, &Color.gray50); XParseColor(disp, colormap, "gray80", &Color.gray80); XAllocColor(disp, colormap, &Color.gray80); XParseColor(disp, colormap, "cyan3", &Color.skyblue); XAllocColor(disp, colormap, &Color.skyblue); control_gc = XCreateGC(disp, win, 0, NULL); XSetFont(disp, control_gc, (font)->fid); XSetForeground(disp, control_gc, Color.skyblue.pixel); margin_gc = XCreateGC(disp, win, 0, NULL); XSetForeground(disp, margin_gc, Color.gray80.pixel); cursor_gc = XCreateGC(disp, win, 0, NULL); XSetForeground(disp, cursor_gc, Color.green.pixel); }
//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. } }
void WPsfnt(int fntnum) /* Set active font. * * In: fntnum = Font number. * * (C)2007-11-10 J.Kjellander * * ******************************************************!*/ { /* ***If not already active, look up the font in ***fnttab and activate it. */ if ( fntnum != actfnt ) { actfnt = fntnum; XSetFont(xdisp,xgc,fnttab[fntnum].xfs->fid); actxfs = fnttab[fntnum].xfs; } /* ***The end. */ return; }
void drawTitle(Display *display, Drawable window, GC gc, const char *title, XWindowAttributes attr){ int titleWillFit = !!title; int twidth; if (titleWillFit) { // Set up text if (!font) { font = XLoadQueryFont(display, TITLEBAR_FONTNAME); if (!font) { fprintf(stderr, "unable to load preferred font: " TITLEBAR_FONTNAME " using fixed"); font = XLoadQueryFont(display, "fixed"); } } XSetFont(display, gc, font->fid); twidth = XTextWidth(font, title, (int)strlen(title)); if (attr.width < (twidth + 42 + (2 * TITLEBAR_TEXT_MARGIN))) { return; } // White out under Title XSetForeground(display, gc, white); XFillRectangle(display, window, gc, ((attr.width - twidth)/ 2) - TITLEBAR_TEXT_MARGIN, 4, twidth + (2 * TITLEBAR_TEXT_MARGIN), TITLEBAR_CONTROL_SIZE); // Draw title XSetForeground(display, gc, black); XSetBackground(display, gc, white); XDrawString(display, window, gc, ((attr.width - twidth)/ 2), TITLEBAR_TEXT_OFFSET, title, (int)strlen(title)); } }
// Reset all values void PlotArea::plot_reset(const char *) { if (!XtIsRealized(area)) { win = 0; return; } win = XtWindow(area); // Set scaling factor between internal driver & window geometry Dimension area_width, area_height; XtVaGetValues(area, XmNwidth, &area_width, XmNheight, &area_height, XtPointer(0)); xscale = (double)area_width / 4096.0; yscale = (double)area_height / 4096.0; // Reset center cx = 0; cy = 0; // Reset line type type = LineSolid; // Create new GC if (gc != 0) XFreeGC(dpy, gc); gc = XCreateGC(dpy, win, 0, (XGCValues *)0); XSetFont(dpy, gc, font->fid); }
void GraphicWindow::open(Display* d, Window w) { display = d; win = w; screen_num = DefaultScreen(display); XGCValues xgc_values; // ignored xgc = XCreateGC(display, win, 0, &xgc_values); // specify black foreground since default window background is // white and default foreground is undefined. XSetForeground(display, xgc, BlackPixel(display, screen_num)); // set line attributes. This class only uses rounded styles. XSetLineAttributes(display, xgc, 2 /* pen thickness */, LineSolid, CapRound, JoinRound); // set up the font - uses only 14pt bold Courier _fontinfo_ptr = XLoadQueryFont(display, SYS_FONT_NAME); if (_fontinfo_ptr == NULL) { cerr << "Unable to initialize font: " << SYS_FONT_NAME << endl; exit(1); } XSetFont(display, xgc, _fontinfo_ptr->fid); // sets the rop mode, using Copy for the user prompts XSetFunction(display, xgc, GXcopy /*0x3 COPY*/); _ppm = XCreatePixmap(display, win, DEF_WIDTH, DEF_HEIGHT, DefaultDepth(display, screen_num)); clear(); }
void do_draw_technical(EX_Drawable dr, GC gc, int a, int b, int c, int d, int bl, int br, int bt, int bb) { if (!font) font = XLoadFont(disp, "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*"); XSetFont(disp, gc, font); if (c < 3) c = 3; if (d < 3) d = 3; draw_h_arrow(dr, gc, a + bl, a + bl + c - 1, b + bt + d - 16); draw_h_arrow(dr, gc, 0, a - 1, b + bt + (d / 2)); draw_h_arrow(dr, gc, a + c + bl + br, WinGetW(VROOT) - 1, b + bt + (d / 2)); draw_v_arrow(dr, gc, b + bt, b + bt + d - 1, a + bl + 16); draw_v_arrow(dr, gc, 0, b - 1, a + bl + (c / 2)); draw_v_arrow(dr, gc, b + d + bt + bb, WinGetH(VROOT) - 1, a + bl + (c / 2)); XDrawLine(disp, dr, gc, a, 0, a, WinGetH(VROOT)); XDrawLine(disp, dr, gc, a + c + bl + br - 1, 0, a + c + bl + br - 1, WinGetH(VROOT)); XDrawLine(disp, dr, gc, 0, b, WinGetW(VROOT), b); XDrawLine(disp, dr, gc, 0, b + d + bt + bb - 1, WinGetW(VROOT), b + d + bt + bb - 1); XDrawRectangle(disp, dr, gc, a + bl + 1, b + bt + 1, c - 3, d - 3); }
Window CreateButtonWindow(char *label, int x, int y, int gravity, int *width) { static GC textgc = NULL, cleargc = NULL; int w = XTextWidth(font, label, strlen(label)) + 4; int h = font->ascent + font->descent + 4; if (width) *width = w; Pixmap pixmap = XCreatePixmap(dpy, toplevel, w, h, DefaultDepth(dpy, screen)); if (textgc == NULL) { textgc = XCreateGC(dpy, toplevel, 0, NULL); XSetForeground(dpy, textgc, GetColor("black", BlackPixel(dpy, screen))); XSetFont(dpy, textgc, font->fid); cleargc = XCreateGC(dpy, toplevel, 0, NULL); XSetForeground(dpy, cleargc, backpixel); } XFillRectangle(dpy, pixmap, cleargc, 0, 0, w, h); XDrawString(dpy, pixmap, textgc, 2, 2 + font->ascent, label, strlen(label)); XSetWindowAttributes attributes; long valuemask = CWEventMask | CWBackPixmap | CWWinGravity; attributes.event_mask = ButtonPressMask; attributes.background_pixmap = pixmap; attributes.win_gravity = gravity; Window window = XCreateWindow(dpy, toplevel, x, y, w, h, 1, (int) CopyFromParent, InputOutput, (Visual *) CopyFromParent, valuemask, &attributes); XMapWindow(dpy, window); return window; }
void draw_score_line(PANE_TYPE which_pane, int line, int value) { char text[7]; int y, y1; if (value < 0) sprintf(text, "%6s", " "); else sprintf(text, "%6d", value); y = ScoreLineY[line]; y1 = y - FixedFontAscent; if (ConsFont == 0) { PANE pane = all_panes[which_pane]; XSetFont(disp, gc, FontId[FT_FIXED]); XSetForeground(disp, gc, cm_pixels[border_colour]); XDrawImageString (disp, pane, gc, ScoreValueX, y, text, 6); } else { fill_parallelogramm(which_pane, ScoreValueX, y1, FixedFontWidth*6, 0, 0, FontHeight[FT_FIXED], bkgr_colour, bkgr_colour, ST_NO_STIPPLE); show_shadow_text(which_pane, FT_FIXED, text, ScoreValueX, y1, 1, 1, 0, 0, border_colour, bkgr_colour, ST_NO_STIPPLE); } flush_pane(which_pane, ScoreValueX, y1, FixedFontWidth*6, FixedFontAscent+FixedFontDescent); }
void DrawCharacters(Page *page) { size_t start = page->start; size_t i; for (i = start; i < page->end; i++) { short x = character_positions[i].x; short y = character_positions[i].y; if (IsPrint(text[i])) { draw: ; XChar2b font_code; XFontStruct *font = SelectFont(text[i], &font_code); GC gc = XCreateGC(disp, back_buffer, 0, NULL); XCopyGC(disp, default_gc, GCForeground | GCBackground, gc); XSetFont(disp, gc, font->fid); XDrawString16(disp, back_buffer, gc, x, y + (font->ascent - default_font->ascent), &font_code, 1); XFreeGC(disp, gc); } else { if (EqAscii2b(text[i], '\n')) { // DOWNWARDS ARROW WITH TIP LEFTWARDS XChar2b symbol = { .byte1 = 0x21, .byte2 = 0xb2 }; XDrawString16(disp, back_buffer, control_gc, x, y, &symbol, 1); } else if (EqAscii2b(text[i], '\t')) { ; } else { goto draw; } } }
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; }
int main(int argc, char * argv[]) { GC gc; XFontStruct* font; XGCValues values; Display* dpy = InitDisplay(); if(!dpy) return EXIT_FAILURE; Window win = InitWindow(dpy, argc, argv); if(!win) return EXIT_FAILURE; // ListFontNames(dpy); if(!(font = XLoadQueryFont(dpy, "-misc-fixed-bold-r-normal--18-120-100-100-c-90-iso10646-1"))) { fprintf(stderr, "%s: cannot open 9x15 font.\n", argv[0]); return EXIT_FAILURE; } gc = XCreateGC(dpy, win, 0, &values); XSetFont(dpy, gc, font->fid); XSetForeground(dpy, gc, BlackPixel(dpy, DefaultScreen(dpy))); XMapWindow(dpy, win); //XFlush(dpy);//force message sending MsgLoop(dpy, win, gc, font); XFreeFont(dpy, font); XFreeGC(dpy, gc); XCloseDisplay(dpy); return EXIT_SUCCESS; }
/* -------------------------------------------------------------------- */ void CanvasMotion(Widget w, XtPointer client, XmDrawingAreaCallbackStruct *evt) { XMotionEvent *xm = (XMotionEvent *)evt; dpy = mainPlot[0].dpy; win = XtWindow(mainPlot[0].canvas); gc = mainPlot[0].gc; /* The color that works ok on Solaris doesn't work so good under Linux. * This should eventually be put in some defaults file along with colors. * Similar code is in zoom.c. */ #ifdef SVR4 XSetForeground(dpy, gc, GetColor(2)); #else XSetForeground(dpy, gc, GetColor(3)); #endif XSetFont(dpy, gc, mainPlot[0].fontInfo[4]->fid); XSetFunction(dpy, gc, GXxor); switch (PlotType) { case TIME_SERIES: TrackTimeSeries(xm->x, xm->y); break; case XY_PLOT: TrackXY(xm->x, xm->y); break; } XSetFunction(dpy, gc, GXcopy); } /* END CANVASMOTION */
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 MpLabel::SetFont (const XFontStruct* newfont) { // defaults to fixed font (an uniformly spaced font) font = (newfont == NULL) ? Mp.theFont : newfont; XSetFont(Mp.theDisplay, TextGC, font->fid); Redraw(); }
void pullclick(DSPOBJ *dspobj, XButtonEvent *ev) { PULLDOWN *pulldown = dspobj->extend; if (!pulldown->sub) { DSPOBJ *sub; int ww; pulldown->gtitems(dspobj, &pulldown->items, &pulldown->nitems); pulldown->w = 0; for (ww = 0; ww != pulldown->nitems; ww++) { int w = XTextWidth(bfs, pulldown->items[ww], strlen(pulldown->items[ww])) + bwidth; if (w > pulldown->w) pulldown->w = w; } sub = dspopen(dspobj->in, dspobj->x, dspobj->y + pulldown->h + 2, pulldown->w, pulldown->h * pulldown->nitems + 1); pulldown->sub = sub; XSetWindowBackground(dsp, sub->win, hred.pixel); sub->extend = pulldown; sub->show = subshow; sub->leave = subremove; pulldown->which = -1; XSetFont(dsp, sub->gc, bigfont); subshow(sub); } }
static void force_setfontsize (int pointsize) { /* Valid point sizes are between 1 and MAX_FONT_SIZE */ if (pointsize < 1) pointsize = 1; else if (pointsize > MAX_FONT_SIZE) pointsize = MAX_FONT_SIZE; currentfontsize = pointsize; if (disp_type == SCREEN) { if (!font_is_loaded[pointsize]) { load_font (pointsize); font_is_loaded[pointsize] = 1; } XSetFont(display, gc, font_info[pointsize]->fid); } else { /* PostScript: set up font and centering function */ fprintf(ps,"%d setfontsize\n",pointsize); } }
DSPOBJ *mkpulldown( DSPOBJ *in, int x, int y, char *name, void (*gtitems)(DSPOBJ *dspobj, char ***items, int *nitems), void (*select)(DSPOBJ *dspobj, int n) ) { int width = XTextWidth(bfs, name, strlen(name)) + bwidth; int ww; DSPOBJ *dspobj = dspopen(in, x, y, width, bheight + 1); PULLDOWN *pulldown = calloc(1, sizeof(PULLDOWN)); XSetFont(dsp, dspobj->gc, bigfont); XSetWindowBackground(dsp, dspobj->win, hred.pixel); dspobj->extend = pulldown; dspobj->show = pullshow; dspobj->press = pullclick; dspobj->release = pullunclick; dspobj->move = pullmove; dspobj->close = rmpulldown; pulldown->name = name; pulldown->y = bascent; pulldown->x = bwidth / 2; pulldown->h = bheight; pulldown->w = 0; pulldown->sub = 0; pulldown->select = select; pulldown->gtitems = gtitems; return dspobj; }
void initGraphics( int argc, char *argv[] ) { XSetWindowAttributes myWindowAttributes; int myDepth; XGCValues myGCValues; unsigned long myWindowMask; myDisplay = XOpenDisplay( "" ); if (myDisplay == NULL) { exit (0); } myScreen = DefaultScreen (myDisplay); myDepth = DefaultDepth (myDisplay, myScreen); if ( parseArgs( argc, argv ) ) assignDefault(); myWindowAttributes.border_pixel = BlackPixel (myDisplay, myScreen); myWindowAttributes.background_pixel = getColor( myDisplay, 252, 234, 212 ); myWindowAttributes.override_redirect = 0; myWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect; myWindow = XCreateWindow (myDisplay, RootWindow (myDisplay, myScreen), window_x, window_y, window_width, window_height, BORDER_WIDTH, myDepth, InputOutput, CopyFromParent, myWindowMask, &myWindowAttributes); myGC = XCreateGC (myDisplay, myWindow, (unsigned long) 0, &myGCValues); if (myGC == 0) { XDestroyWindow(myDisplay, myScreen); exit (0); } myFont = XLoadQueryFont (myDisplay, "9x15"); if (myFont == (XFontStruct *)NULL) { fprintf(stderr,"Cannot get font:9x15.\n"); myFont = NULL; } else XSetFont (myDisplay, myGC, myFont->fid); XSetForeground (myDisplay, myGC, BlackPixel( myDisplay, myScreen ) ); XMapWindow (myDisplay, myWindow); XLowerWindow( myDisplay, myWindow ); paint(); XFlush( myDisplay ); }
/*----------------------------------------------------------------------------*/ void VKCreateFontDialog() { static char *max_fnt_string = "Alt Control Shift ISO_Left_Tab"; int i, j, fh, fa, fw; #ifdef USE_XFT XGlyphInfo fi; fw = 2 * vk_font->max_advance_width; XftTextExtentsUtf8(display, vk_font, max_fnt_string, strlen(max_fnt_string), &fi); #else XRectangle fi; fw = 2 * vk_font->perchar['W'].width; XmbTextExtents(vk_fontset, max_fnt_string, strlen(max_fnt_string), 0, &fi); #endif fnt.width = (fi.width<300 ? 300 : fi.width+fw); fa = vk_text_ascent; fh = vk_text_height; fnt.ty = (fa + 5) + fh + 4; VKFontControlInit(20, 2 * (fh + 4) + 6, fnt.width - 20, fh+4); fnt.ly = 0;//fnt.name.y + fnt.name.h + fh/2; for( i=0; i<2; i++ ) { VKButtonControl *b = fb_actions[i]; #ifdef USE_XFT XftTextExtentsUtf8(display, vk_font, "Cancel", 6, &fi); #else XmbTextExtents(vk_fontset, "Cancel", 6, 0, &fi); #endif fw = fi.width; b[0].w = b[1].w = fw + 24; b[0].x = (fnt.width - 2 * b[0].w - 24) / 2; b[1].x = fnt.width - b[0].x - b[0].w; for( j=0; j<2; j++ ) { b[j].y = fnt.ly + fh/2; b[j].h = fh + 4; } } fnt.height = fb_actions[0][0].y + fh + 4 + fh/2; fnt.window = XCreateWindow(display, root, 0, 0, fnt.width, fnt.height, 0, DefaultDepth(display, screen), InputOutput, visual, vk_attribmask, &vk_attrib); XSelectInput(display, fnt.window, MAIN_EVENT_MASKS); XDefineCursor(display, fnt.window, vk_cursor); fnt.gc = XCreateGC(display, fnt.window, 0, 0); #ifndef USE_XFT XSetFont(display, fnt.gc, vk_font->fid); #endif VKRegisterEvent(fnt.window, VKFontProcess); DUMP("create done\n"); }
void GameOverLayer::drawGameOverScreen() { GC gc = xInfo->gc[0]; XFontStruct *font = XLoadQueryFont(xInfo->display, "12x24"); XSetFont(xInfo->display, gc, font->fid); XDrawImageString(xInfo->display, xInfo->pixmap, gc, crashMsgX, crashMsgY, crashMsg.c_str(), (int)crashMsg.length()); XDrawImageString(xInfo->display, xInfo->pixmap, gc, restartMsgX, restartMsgY, restartMsg.c_str(), (int)restartMsg.length()); }
void sg_outText(int x, int y, int color, char* s) { if (!xw_graphic){XSetFont(display,gc,bgi_font->fid);xw_graphic=1;} x-=bgi_font->min_bounds.lbearing; y-=bgi_font->descent; XSetForeground(display,gc,bgi_colors[color]); XDrawString(display,win,gc,x,y,s,strlen(s)); }
void Fl_Device::rtl_draw(const char *str, int n, float x, float y) { if (font_gc != fl_gc) { font_gc = fl_gc; XSetFont(fl_display, fl_gc, ((XFontStruct*)fl_xfont())->fid); } /// /// }
/* * Standard Text */ static errr Infofnt_text_std(int x, int y, cptr str, int len) { int i; /*** Do a brief info analysis ***/ /* Do nothing if the string is null */ if (!str || !*str) return (-1); /* Get the length of the string */ if (len < 0) len = strlen(str); /*** Decide where to place the string, vertically ***/ /* Ignore Vertical Justifications */ y = (y * Infofnt->hgt) + Infofnt->asc + Infowin->oy; /*** Decide where to place the string, horizontally ***/ /* Line up with x at left edge of column 'x' */ x = (x * Infofnt->wid) + Infowin->ox; /*** Actually draw 'str' onto the infowin ***/ /* Be sure the correct font is ready */ XSetFont(Metadpy->dpy, Infoclr->gc, Infofnt->info->fid); /*** Handle the fake mono we can enforce on fonts ***/ /* Monotize the font */ if (Infofnt->mono) { /* Do each character */ for (i = 0; i < len; ++i) { /* Note that the Infoclr is set up to contain the Infofnt */ XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc, x + i * Infofnt->wid + Infofnt->off, y, str + i, 1); } } /* Assume monoospaced font */ else { /* Note that the Infoclr is set up to contain the Infofnt */ XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc, x, y, str, len); } /* Success */ return (0); }
void Fl_Device::transformed_draw(const char *str, int n, float x, float y) { if (font_gc != fl_gc) { font_gc = fl_gc; XSetFont(fl_display, fl_gc, current_font->fid); } int X = int(floor(x+.5f)); int Y = int(floor(y+.5f)); #if HAVE_XUTF8 char glyph[2]; // byte1 and byte2 value of the UTF-8 char XChar2b buf[128]; // drawing buffer int pos = 0; // position in buffer int ulen; // byte length of the UTF-8 char unsigned int ucs; // Unicode value of the UTF-8 char unsigned int no_spc; // Spacing char equivalent of a non-spacing char while(n > 0) { if(pos>120) { XDrawString16(fl_display, fl_window, fl_gc, X, Y, buf, pos); X += XTextWidth16(current_font, buf, pos); pos = 0; } ulen = fl_fast_utf2ucs((unsigned char*)str, n, &ucs); if (ulen < 1) ulen = 1; no_spc = fl_nonspacing(ucs); if(no_spc) ucs = no_spc; if(fl_ucs2fontmap(glyph, ucs, fl_fontsize->encoding_num) < 0) { // the char is not valid in this encoding fl_ucs2fontmap(glyph, '?', fl_fontsize->encoding_num); } if(no_spc) { XDrawString16(fl_display, fl_window, fl_gc, X, Y, buf, pos); X += XTextWidth16(current_font, buf, pos); pos = 0; (*buf).byte1 = glyph[1]; (*buf).byte2 = glyph[0]; X -= XTextWidth16(current_font, buf, 1); } else { (*(buf + pos)).byte1 = glyph[1]; (*(buf + pos)).byte2 = glyph[0]; } pos++; str += ulen; n-=ulen; } if(pos>0) XDrawString16(fl_display, fl_window, fl_gc, X, Y, buf, pos); #else XDrawString(fl_display, fl_window, fl_gc, X, Y, str, n); #endif }