示例#1
0
void
xwindow_draw_string_xft(XWindow *xw, char *text, int x, int y) {
  int n;
  XftDraw *draw;
  XftColor color;
  XRenderColor rc;
  XftFont *font;
  XGlyphInfo extents;
  float shift[] = { 0.0, 0.0, -0.5, -1.0 };
  
  n = strlen(text);

  font = xw->font->font_xft;
  if(!font) {
    return;
  }
  draw = XftDrawCreate(DISPLAY(xw),
                       xw->buffer,
                       VISUAL(xw),
                       DefaultColormap(DISPLAY(xw), SCREEN(xw)));

  /* Set Text from current Color */
  rc.red   = xw->color->red;
  rc.green = xw->color->green;
  rc.blue  = xw->color->blue;
  rc.alpha = 0xFFFF; /* 65535 */
  XftColorAllocValue(DISPLAY(xw),
                     VISUAL(xw),
                     DefaultColormap(DISPLAY(xw), SCREEN(xw)),
                     &rc,
                     &color);
  
  XftTextExtents8(DISPLAY(xw), font, (FcChar8*)text, n, &extents);

  if(cmgdm.tangle != 0.0) {
    XftMatrix m;
    m.xx =  0.0;
    m.xy = -1.0;
    m.yx =  1.0;
    m.yy =  0.0;

    y = y - shift[cmgdm.ihjust] * extents.xOff;
    x = x - shift[cmgdm.ivjust] * (font->ascent + font->descent);
    
    font = XftFontOpen(DISPLAY(xw),
                       SCREEN(xw),
                       XFT_FAMILY,    XftTypeString,  xw->font->family,
                       XFT_SIZE,      XftTypeDouble,  xw->font->size,
                       XFT_STYLE,     XftTypeString,  xfont_style(xw->font),
                       XFT_ANTIALIAS, XftTypeBool,    xw->font->antialias,
                       XFT_MATRIX, XftTypeMatrix, &m,
                       NULL);

    
  } else {
    x = x + shift[cmgdm.ihjust] * extents.xOff;
    y = y - shift[cmgdm.ivjust] * (font->ascent + font->descent);
  }
  XftDrawString8(draw, &color, font, x, y, (FcChar8 *)text, n);
}
示例#2
0
void sSetColor2D(sInt colid,sU32 color)
{
  sVERIFY(colid>=0 && colid<MAX_COLORS);
  
  if(Color[colid][1] != color)
  {
    XColor col;
    col.red   = ((color>>16) & 0xff)*0x101;
    col.green = ((color>> 8) & 0xff)*0x101;
    col.blue  = ((color>> 0) & 0xff)*0x101;
    col.flags = DoRed|DoGreen|DoBlue;
    if(!XAllocColor(sXDisplay(),sXColMap,&col))
      sFatal(L"XAllocColor failed");
    
    Color[colid][0] = col.pixel;
    Color[colid][1] = color;
    
    XRenderColor rc;
    rc.red = col.red;
    rc.green = col.green;
    rc.blue = col.blue;
    rc.alpha = 0xffff;
    
    if(!XftColorAllocValue(sXDisplay(),sXVisual,sXColMap,&rc,&ColorXFT[colid]))
      sFatal(L"XftColorAllocValue failed");
  }
void
JXGC::DrawString
	(
	Drawable			drawable,
	XftDraw*			fdrawable,
	const JCoordinate	origX,
	const JCoordinate	y,
	const JCharacter*	str
	)
	const
{
	JXFontManager::XFont xfont = (itsDisplay->GetXFontManager())->GetXFontInfo(itsLastFont);

	XftColor color;
	if (xfont.type == JXFontManager::kTrueType)
		{
		JSize red, green, blue;
		itsColormap->GetRGB(itsLastColor, &red, &green, &blue);

		XRenderColor renderColor;
		renderColor.red   = red;
		renderColor.green = green;
		renderColor.blue  = blue;
		renderColor.alpha = 65535;

		XftColorAllocValue(*itsDisplay, itsDisplay->GetDefaultVisual(),
						   itsColormap->GetXColormap(), &renderColor, &color);
		}

	const JFontManager* fontMgr = itsDisplay->GetFontManager();

	const JSize length          = strlen(str);
	const JSize maxStringLength = itsDisplay->GetMaxStringLength();

	JCoordinate x = origX;
	JSize offset  = 0;
	while (offset < length)
		{
		const JSize count = JMin(length - offset, maxStringLength);

		if (xfont.type == JXFontManager::kStdType)
			{
			XDrawString(*itsDisplay, drawable, itsXGC, x,y, str + offset, count);
			}
		else
			{
			assert( xfont.type == JXFontManager::kTrueType );
			XftDrawString8(fdrawable, &color, xfont.xftrue, x,y, (FcChar8*) (str + offset), count);
			}

		if (offset + count < length)
			{
			x += fontMgr->GetStringWidth(itsLastFont, 0, JFontStyle(),
										 str + offset, count);
			}
		offset += count;
		}
}
示例#4
0
文件: x11.c 项目: NattyNarwhal/edit
static void
xftcolor(XftColor *xc, GColor c)
{
	xc->color.red = c.red << 8;
	xc->color.green = c.green << 8;
	xc->color.blue = c.blue << 8;
	xc->color.alpha = 65535;
	XftColorAllocValue(d, visual, cmap, &xc->color, xc);
}
示例#5
0
文件: text_xft.c 项目: burzumishi/e16
void
_xft_FdcSetColor(TextState * ts, unsigned int color)
{
   FontCtxXft         *fdc = (FontCtxXft *) ts->fdc;
   XRenderColor        xrc;

   COLOR32_TO_ARGB16(color, xrc.alpha, xrc.red, xrc.green, xrc.blue);

   XftColorAllocValue(disp, WinGetVisual(fdc->win), WinGetCmap(fdc->win),
		      &xrc, &(fdc->xftc));
}
示例#6
0
文件: Logo.c 项目: aosm/X11
static Boolean
XmuCvtStringToXftColor(Display *dpy,
		       XrmValue *args, Cardinal *num_args,
		       XrmValue *fromVal, XrmValue *toVal,
		       XtPointer *converter_data)
{
    char	    *spec;
    XRenderColor    renderColor;
    XftColor	    xftColor;
    Screen	    *screen;
    Colormap	    colormap;
    
    if (*num_args != 2)
    {
	XtAppErrorMsg (XtDisplayToApplicationContext (dpy),
		       "cvtStringToXftColor", "wrongParameters",
		       "XtToolkitError",
		       "String to render color conversion needs screen and colormap arguments",
		       (String *) NULL, (Cardinal *)NULL);
	return False;
    }

    screen = *((Screen **) args[0].addr);
    colormap = *((Colormap *) args[1].addr);

    spec = (char *) fromVal->addr;
    if (strcasecmp (spec, XtDefaultForeground) == 0)
    {
	renderColor.red = 0;
	renderColor.green = 0;
	renderColor.blue = 0;
	renderColor.alpha = 0xffff;
    }
    else if (strcasecmp (spec, XtDefaultBackground) == 0)
    {
	renderColor.red = 0xffff;
	renderColor.green = 0xffff;
	renderColor.blue = 0xffff;
	renderColor.alpha = 0xffff;
    }
    else if (!XRenderParseColor (dpy, spec, &renderColor))
	return False;
    if (!XftColorAllocValue (dpy, 
			     DefaultVisual (dpy,
					    XScreenNumberOfScreen (screen)),
			     colormap,
			     &renderColor,
			     &xftColor))
	return False;
    
    donestr (XftColor, xftColor, XtRXftColor);
}
示例#7
0
文件: Ctrl.c 项目: xtforever/xtcw
static void alloc_xft_color( Widget w, Pixel fg, XftColor *col )
{
  Display *dpy = XtDisplay(w);
  XRenderColor xre_color;
  TRACE(2,"%X",fg);
  xre_color.red = (fg >> 8) & 0xff00;
  xre_color.green = (fg) & 0xff00;
  xre_color.blue = (fg <<8) & 0xff00;
  xre_color.alpha = 0xffff;
  
  XftColorAllocValue(dpy, DefaultVisual(dpy, DefaultScreen(dpy)),
		     None, &xre_color, col );
}
示例#8
0
文件: decor.c 项目: damaru/zwm
void zwm_decor_init(void)
{
	int i;
	XGlyphInfo info;

	cmap = DefaultColormap(dpy, scr);
	gc = XCreateGC(dpy, root, 0, NULL);

	memset(icons,0,64);

	xfont = XftFontOpenName (dpy, scr, "DejaVu Sans-9:bold");
	if(!xfont)xfont = XftFontOpenXlfd(dpy, scr, config.font);

	ifont = XftFontOpenName (dpy, scr, "DejaVu Sans-16:bold");
	if(!ifont)ifont = XftFontOpenXlfd(dpy, scr, config.icons);

	XftColorAllocValue(dpy, DefaultVisual(dpy, scr), cmap, &xcolor.color, &xcolor);

	config.xcolor_nborder = alloc_color(config.normal_border_color);
	config.xcolor_fborder = alloc_color(config.focus_border_color);
	config.xcolor_nbg = alloc_color(config.normal_bg_color);
	config.xcolor_fbg = alloc_color(config.focus_bg_color);
	config.xcolor_flbg = alloc_color(config.float_bg_color);
	config.xcolor_nshadow = alloc_color(config.normal_shadow_color);
	config.xcolor_fshadow = alloc_color(config.focus_shadow_color);
	config.xcolor_ntitle = alloc_color(config.normal_title_color);
	config.xcolor_ftitle = alloc_color(config.focus_title_color);
	config.xcolor_root = alloc_color(config.root_bg_color);

	get_status(icons, 64);
	XftTextExtentsUtf8(dpy, xfont, (FcChar8*)" [000] ", 7, &info);
	char_width = info.width;
	XftTextExtentsUtf8(dpy, xfont, (FcChar8*)icons, strlen(icons), &info);
	date_width = info.width;
	icons[0] = 0;

	for(i=0; i<32 && config.buttons[i].func; i++){
		strcat(icons, config.buttons[i].c);
		config.button_count = i+1;
	}

	if(config.button_count){
		XftTextExtentsUtf8(dpy, ifont, (FcChar8*)icons, strlen(icons), &info);
		config.button_width = info.width / config.button_count;
		config.icon_y = info.height + (config.title_height - info.height)/2 + 1;
	}

	config.title_y = config.title_height - xfont->descent - 2;
}
示例#9
0
bool de_duplicate_colour(WRootWin *rootwin, DEColour in, DEColour *out)
{
#ifdef HAVE_X11_XFT
    return XftColorAllocValue(
        ioncore_g.dpy,
        XftDEDefaultVisual(),
        rootwin->default_cmap,
        &(in.color),
        out);
#else /* HAVE_X11_XFT */
    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;
#endif /* HAVE_X11_XFT */
}
void XftTextRenderer::drawRect(int x, int y, int w, int h, const GdkColor* color)
{
    
#if defined(USE_XFT_DRAWRECT)
    g_warning("(%d,%d,%d,%d)", x,y,w,h);
    XftColor xft_c;
    XRenderColor xrender_c;
    
    getXRenderColorFromGdkColor(color, &xrender_c);    

    XftColorAllocValue(xdisplay,
		       xvisual,
		       xcmap,
		       &xrender_c,
		       &xft_c);

    x -= gdkxoff;
    y -= gdkyoff;

    XftDrawRect(xftdraw, &xft_c, x, y, w, h);
    
    XftColorFree(xdisplay,
		 xvisual,
		 xcmap,
		 &xft_c);
#else
    gdk_gc_set_rgb_fg_color(gdkgc, const_cast<GdkColor*>(color));

    x -= gdkxoff;
    y -= gdkyoff;

    gdk_gc_set_fill (gdkgc, GDK_SOLID);
    gdk_draw_rectangle(gdkdrawable, gdkgc, TRUE, x, y, w, h);

#endif
}
示例#11
0
文件: xview.c 项目: sonald/semacs
static void se_draw_buffer_point( se_text_xviewer* viewer )
{
    se_env *env = viewer->env;
    se_world *world = viewer->env->world;
    g_assert( world );

    se_buffer *cur_buf = world->current;
    g_assert( cur_buf );

    se_cursor point_cur = {
        .row = cur_buf->getLine( cur_buf ),
        .column = cur_buf->getCurrentColumn( cur_buf )
    };
    se_position point_pos = se_text_cursor_to_physical( viewer, point_cur );
    point_pos.y -= (env->glyphMaxHeight - env->glyphAscent)/2;
    

    XRenderColor renderClr = {
        .red = 0x00,
        .green = 0xffff,
        .blue = 0x00,
        .alpha = 0x00
    };
        
    XftColor clr;
    XftColorAllocValue( env->display, env->visual, env->colormap, &renderClr, &clr );
    
    XftDrawRect( viewer->xftDraw, &clr, point_pos.x, point_pos.y, 2, env->glyphMaxHeight );

    XftColorFree( env->display, env->visual, env->colormap, &clr );
}

// send draw event and do real update in redisplay routine
static void se_text_xviewer_repaint( se_text_xviewer* viewer )
{
    XWindowAttributes attrs;
    XGetWindowAttributes( viewer->env->display, viewer->view, &attrs);
    viewer->updateSize( viewer, attrs.width, attrs.height );

    //refill text viewer
    se_world *world = viewer->env->world;
    g_assert( world );

    se_buffer *cur_buf = world->current;
    g_assert( cur_buf );

    //FIXME: this is slow algo just as a demo, change it later
    se_line* lp = cur_buf->lines;
    int nr_lines = cur_buf->getLineCount( cur_buf );
    se_debug( "paint rect: rows: %d", nr_lines );
    
    for (int r = 0; r < MIN(viewer->rows, nr_lines); ++r) {
        const char* buf = se_line_getData( lp );
        int cols = se_line_getLineLength( lp );
        if ( buf[cols-1] == '\n' ) cols--;
        memcpy( (viewer->content + r*SE_MAX_ROWS), buf, cols );
        *(viewer->content + r*SE_MAX_ROWS+cols) = '\0';
        /* se_debug( "draw No.%d: [%s]", r, buf ); */
        lp = lp->next;
    }
}
示例#12
0
文件: xview.c 项目: sonald/semacs
static void se_text_xviewer_redisplay(se_text_xviewer* viewer )
{
    se_debug( "redisplay" );
    
    se_env *env = viewer->env;
    XRenderColor renderClr = {
        .red = 0x0,
        .green = 0x0,
        .blue = 0x0,
        .alpha = 0xffff
    };
        
    XftColor clr;
    XftColorAllocValue( env->display, env->visual, env->colormap, &renderClr, &clr );

    se_world *world = viewer->env->world;
    g_assert( world );
    se_buffer *cur_buf = world->current;
    g_assert( cur_buf );
    int nr_lines = cur_buf->getLineCount( cur_buf );
    se_debug( "update buf %s [%d, %d]", cur_buf->getBufferName(cur_buf),
              viewer->columns, MIN(viewer->rows, nr_lines) );    

    // this clear the whole window ( slow )
    XClearArea( env->display, viewer->view, 0, 0, 0, 0, False );
    
    viewer->cursor = (se_cursor){ 0, 0 };
    for (int r = 0; r < MIN(viewer->rows, nr_lines); ++r) {
        char *data = viewer->content + r*SE_MAX_ROWS;
        int data_len = strlen( data );
        se_draw_text_utf8( viewer, &clr, viewer->cursor,
                           data, MIN(data_len, viewer->columns) );
        viewer->cursor = (se_cursor){0, viewer->cursor.row + 1};
    }

    se_draw_buffer_point( viewer );
    XftColorFree( env->display, env->visual, env->colormap, &clr );
}

void se_text_xviewer_configure_change_handler(se_text_xviewer* viewer, XEvent* ev )
{
    se_debug( "enter configure_change_handler" );
    gboolean need_update = FALSE;
    
    if ( ev->type == ConfigureRequest ) {
        XConfigureEvent configEv = ev->xconfigure;
        if ( viewer->physicalWidth != configEv.width
             || viewer->physicalHeight != configEv.height ) {
            need_update = TRUE;
        }
        
    } else if ( ev->type == ResizeRequest ) {
        XResizeRequestEvent resizeEv = ev->xresizerequest;
        if ( viewer->physicalWidth != resizeEv.width
             || viewer->physicalHeight != resizeEv.height ) {
            need_update = TRUE;
        }
    }

    if ( need_update ) {
        XWindowAttributes attrs;
        XGetWindowAttributes( viewer->env->display, viewer->view, &attrs);
        viewer->updateSize( viewer, attrs.width, attrs.height );
    }
}
示例#13
0
static void InitXLib()
{
  for(sInt i=0;i<MAX_CLIPS;i++)
    ClipStack[i] = XCreateRegion();
  
  EmptyRegion = XCreateRegion();
  UpdateRegion = XCreateRegion();
  
  static const int shapeInd[] =
  {
    0,
    XC_left_ptr,
    XC_watch,
    XC_crosshair,
    XC_hand2,
    XC_xterm,
    XC_X_cursor,
    XC_fleur,
    XC_sb_v_double_arrow,
    XC_sb_h_double_arrow,
    XC_bottom_right_corner, // poor match!
    XC_bottom_left_corner, // poor match!
  };
  Cursors[0] = 0;
  for(sInt i=1;i<sMP_MAX;i++)
    Cursors[i] = XCreateFontCursor(sXDisplay(),shapeInd[i]);
  
  if(sGetSystemFlags() & sISF_2D)
  {
    XRenderColor rc;
    XftColor blackColor;
    sClear(rc);
    rc.alpha = 0xffff;
    XftColorAllocValue(sXDisplay(),sXVisual,sXColMap,&rc,&blackColor);
    
    for(sInt i=0;i<MAX_COLORS;i++)
    {
      Color[i][0] = Color[i][1] = 0;
      ColorXFT[i] = blackColor;
    }

    XDraw = XftDrawCreate(sXDisplay(),sXWnd,DefaultVisual(sXDisplay(),sXScreen),sXColMap);
    if(!XDraw)
      sFatal(L"XftDrawCreate failed!");
    
    // initialize x render extension
    int major,minor;
    XRenderQueryVersion(sXDisplay(),&major,&minor);
    sLogF(L"xlib",L"XRender %d.%d found\n",major,minor);
    
    XRenderPictFormat *fmt = XRenderFindVisualFormat(sXDisplay(),sXVisual);
    if(!fmt)
      sFatal(L"XRenderFindVisualFormat failed on default visual!");
    
    XRenderPictureAttributes attr;
    attr.graphics_exposures = False;
    XPict = XRenderCreatePicture(sXDisplay(),sXWnd,fmt,CPGraphicsExposure,&attr);
    if(!XPict)
      sFatal(L"XRenderCreatePicture for main picture failed!");
    
    XFmtARGB = XRenderFindStandardFormat(sXDisplay(),PictStandardARGB32);
    if(!XFmtARGB)
      sFatal(L"XRenderFindStandardFormat failed on display!");
  }
  
  ForegroundCol = -1;
}
void XftTextRenderer::drawRun(const WebCoreTextRun *run, const WebCoreTextStyle *style, int x, int y)
{
    assert(run);
    assert(style);
    assert(style->families);
    
    if (run->length == 0) 
	return;

    XRenderColor xrc;
    XftColor c;
  

    getXRenderColorFromGdkColor(&style->textColor, &xrc);

    XftColorAllocValue(xdisplay,
		       xvisual,
		       xcmap,
		       &xrc,
		       &c);

    x -=  gdkxoff;
    y -=  gdkyoff;

    const int wordBufSz = 10;	// size of scan buffer
    WordRange words[wordBufSz]; // scan buffer
    int nWords;			// number of words in scan buffer
    int totWords = 0;		// total word count



    // needs always totWords because wordSpacing is applied only to spaces in the middle, not
    // for the last word. Is this correct practice?
    scanRunForWords(run, run->from, words, wordBufSz, &nWords, &totWords);

    if (totWords == 0) 
	return;

    float wordPadding =  style->padding / totWords;

    float wordWidth = 0.0f;
    int wordsDrawn = 0;
    int wordIndex;

    while (1) {

	// iterate over scan buffer
	for (wordIndex = 0; wordIndex < nWords; wordIndex++) {

	    wordWidth = drawRange(run, style, words[wordIndex].start, words[wordIndex].stop, x, y, &c, true);

	    // not last word
	    wordWidth += wordPadding;
	    wordWidth += font->spaceWidth + style->wordSpacing;

	    x += (int)wordWidth;

	    ++wordsDrawn;
	} 

	if (nWords > 0 && words[nWords-1].stop+1 < run->to) {
            // update scan buffer (will happen if number of spaces > wordBufSz)
	    scanRunForWords(run, words[nWords-1].stop+1, words, wordBufSz, &nWords, NULL); 	
	} else 
	    break;
    }


    XftColorFree(xdisplay,
		 xvisual,
		 xcmap,
		 &c);

    
    if (style->rtl){
	g_warning("RTL painting not implemented"); 	// FIXME:: Handle right-to-left text
    }
}
示例#15
0
bool ui_init()
{
	movelist_init();

	/* window, drawable stuff */
	ui_display = XOpenDisplay(getenv("DISPLAY"));
	if (NULL == ui_display) {
		ui_close();
		return false;
	}

	ui_rootwindow = DefaultRootWindow(ui_display);
	if (0 == ui_rootwindow) {
		ui_close();
		return false;
	}

	ui_screenwidth = DisplayWidth(ui_display, DefaultScreen(ui_display));
	ui_screenheight = DisplayHeight(ui_display, DefaultScreen(ui_display));
	int depth = DisplayPlanes(ui_display, DefaultScreen(ui_display));

	LOG( INFO, "Screen size: %dx%d, Depth: %d", ui_screenwidth, ui_screenheight, depth );

	ui_backbuf = XCreatePixmap( ui_display, ui_rootwindow,
			ui_screenwidth, ui_screenheight, depth );

	if ( ui_backbuf == 0 ) {
		ui_close();
		return false;
	}

	ui_gcontext = XCreateGC(ui_display, ui_backbuf, 0, NULL);
	if (0 == ui_gcontext) {
		ui_close();
		return false;
	}

	ui_xftdraw = XftDrawCreate(ui_display, ui_backbuf, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0));
	if (NULL == ui_xftdraw) {
		ui_close();
		return false;
	}

	/* load fonts */
	ui_piecefont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_PIECES,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_PIECES,
		NULL);

	if (NULL == ui_piecefont) {
		ui_close();
		return false;
	}

	ui_infofont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_INFO,
		NULL);

	if (NULL == ui_infofont) {
		ui_close();
		return false;
	}

	ui_namefont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_NAME,
		NULL);

	if (NULL == ui_namefont) {
		ui_close();
		return false;
	}

	ui_coordfont = XftFontOpen(ui_display, DefaultScreen(ui_display),
		XFT_FAMILY, XftTypeString, UI_FONT_FAMILY_TEXT,
		XFT_SIZE, XftTypeDouble, UI_FONT_SIZE_COORD,
		XFT_WEIGHT, XftTypeInteger, XFT_WEIGHT_BOLD,
		NULL);

	if (NULL == ui_coordfont) {
		ui_close();
		return false;
	}

	ui_infofontchwidth = ui_info_font_normal_char_width();

	/* create colors */
	XRenderColor whiteSquareColor;
	whiteSquareColor.red = (0xffff * ((UI_COL_WHITE_SQUARE >> 16) & 0xff)) / 0xff;
	whiteSquareColor.green = (0xffff * ((UI_COL_WHITE_SQUARE >> 8) & 0xff)) / 0xff;
	whiteSquareColor.blue = (0xffff * (UI_COL_WHITE_SQUARE & 0xff)) / 0xff;
	whiteSquareColor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0),
			&whiteSquareColor, &ui_squarecolorwhite)) {
		ui_squarecolorwhiteinit = false;
		ui_close();
		return false;
	}
	ui_squarecolorwhiteinit = true;

	XRenderColor blackSquareColor;
	blackSquareColor.red = (0xffff * ((UI_COL_BLACK_SQUARE >> 16) & 0xff)) / 0xff;
	blackSquareColor.green = (0xffff * ((UI_COL_BLACK_SQUARE >> 8) & 0xff)) / 0xff;
	blackSquareColor.blue = (0xffff * (UI_COL_BLACK_SQUARE & 0xff)) / 0xff;
	blackSquareColor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0),
			&blackSquareColor, &ui_squarecolorblack)) {
		ui_squarecolorblackinit = false;
		ui_close();
		return false;
	}
	ui_squarecolorblackinit = true;

	XRenderColor white;
	white.red = 0xffff;
	white.green = 0xffff;
	white.blue = 0xffff;
	white.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &white, &ui_piececolorwhite)) {
		ui_piececolorwhiteinit = false;
		ui_close();
		return false;
	}
	ui_piececolorwhiteinit = true;

	XRenderColor black;
	black.red = 0;
	black.green = 0;
	black.blue = 0;
	black.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &black, &ui_piececolorblack)) {
		ui_piececolorblackinit = false;
		ui_close();
		return false;
	}
	ui_piececolorblackinit = true;

	XRenderColor infocolor;
	infocolor.red = 0x6666;
	infocolor.green = 0x6666;
	infocolor.blue = 0x6666;
	infocolor.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0), DefaultColormap(ui_display, 0), &infocolor, &ui_infocolor)) {
		ui_infocolorinit = false;
		ui_close();
		return false;
	}
	ui_infocolorinit = true;

	XRenderColor infocolortag;
	infocolortag.red = 0x4444;
	infocolortag.green = 0x4444;
	infocolortag.blue = 0x4444;
	infocolortag.alpha = 0xffff;

	if (!XftColorAllocValue(ui_display, DefaultVisual(ui_display, 0),
			DefaultColormap(ui_display, 0), &infocolortag, &ui_infocolortag)) {
		ui_infocolortaginit = false;
		ui_close();
		return false;
	}
	ui_infocolortaginit = true;

	/* start with board on the left */
	ui_board_pos_x = UI_POS_BOARD_X_LEFT;

	return true;
}
示例#16
0
文件: do_traps.c 项目: aosm/X11
int
InitFixedTrapezoids(XParms xp, Parms p, int reps)
{
    int     i, numTraps;
    int     rows;
    int     x, y;
    int     size, skew;
    XTrapezoid	*curTrap;
    XRenderColor	color;

    pgc = xp->fggc;

    size = p->special;
    numTraps = p->objects;
    traps = (XTrapezoid *)malloc(numTraps * sizeof(XTrapezoid));
    curTrap = traps;
    x = size;
    y = 0;
    rows = 0;
    skew = size;
    aadraw = XftDrawCreate (xp->d, xp->w, 
			    xp->vinfo.visual, 
			    xp->cmap);
    if (p->font && !strcmp (p->font, "add"))
    {
	XRenderPictFormat   templ;
	templ.type = PictTypeDirect;
	templ.depth = 8;
	templ.direct.alpha = 0;
	templ.direct.alphaMask = 0xff;
	maskFormat = XRenderFindFormat (xp->d, 
					PictFormatType |
					PictFormatDepth |
					PictFormatAlpha |
					PictFormatAlphaMask,
					&templ,
					0);
    }
    else
	maskFormat = 0;
    color.red = 0;
    color.green = 0;
    color.blue = 0;
    color.alpha = 0xffff;
    if (!XftColorAllocValue (xp->d,
			     xp->vinfo.visual, 
			     xp->cmap,
			     &color, &aablack))
    {
	XftDrawDestroy (aadraw);
	aadraw = 0;
	return 0;
    }
    color.red = 0xffff;
    color.green = 0xffff;
    color.blue = 0xffff;
    color.alpha = 0xffff;
    if (!XftColorAllocValue (xp->d,
			     xp->vinfo.visual, 
			     xp->cmap,
			     &color, &aawhite))
    {
	XftDrawDestroy (aadraw);
	aadraw = 0;
	return 0;
    }

    for (i = 0; i != p->objects; i++, curTrap ++) {
	curTrap->top = XDoubleToFixed (y);
	curTrap->bottom = XDoubleToFixed (y + size);
	curTrap->left.p1.x = XDoubleToFixed (x - skew);
	curTrap->left.p1.y = XDoubleToFixed (y);
	curTrap->left.p2.x = XDoubleToFixed (x + skew - size);
	curTrap->left.p2.y = XDoubleToFixed (y + size);
	
	curTrap->right.p1.x = XDoubleToFixed (x - skew + size);
	curTrap->right.p1.y = XDoubleToFixed (y);
	curTrap->right.p2.x = XDoubleToFixed (x + skew);
	curTrap->right.p2.y = XDoubleToFixed (y + size);
	
	skew--;
	if (skew < 0) skew = size;

	y += size;
	rows++;
	if (y + size > HEIGHT || rows == MAXROWS) {
	    rows = 0;
	    y = 0;
	    x += 2 * size;
	    if (x + size > WIDTH) {
		x = size;
	    }
	}
    }

    
    SetFillStyle(xp, p);
    return reps;
}
static void setup_font_sample(GtkWidget* darea, Antialiasing antialiasing, Hinting hinting)
{
	const char* string1 = "abcfgop AO ";
	const char* string2 = "abcfgop";

	XftColor black, white;
	XRenderColor rendcolor;

	Display* xdisplay = gdk_x11_get_default_xdisplay();

#if GTK_CHECK_VERSION (3, 0, 0)
	Colormap xcolormap = DefaultColormap(xdisplay, 0);
#else
	GdkColormap* colormap = gdk_rgb_get_colormap();
	Colormap xcolormap = GDK_COLORMAP_XCOLORMAP(colormap);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	GdkVisual* visual = gdk_visual_get_system ();
#else
	GdkVisual* visual = gdk_colormap_get_visual(colormap);
#endif
	Visual* xvisual = GDK_VISUAL_XVISUAL(visual);

	FcPattern* pattern;
	XftFont* font1;
	XftFont* font2;
	XGlyphInfo extents1 = { 0 };
	XGlyphInfo extents2 = { 0 };
#if !GTK_CHECK_VERSION (3, 0, 0)
	GdkPixmap* pixmap;
#endif
	XftDraw* draw;
	GdkPixbuf* tmp_pixbuf;
	GdkPixbuf* pixbuf;

	int width, height;
	int ascent, descent;

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN,
		FC_SIZE, FcTypeDouble, 18.,
		NULL);
	font1 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC,
		FC_SIZE, FcTypeDouble, 20.,
		NULL);
	font2 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	ascent = 0;
	descent = 0;
	
	if (font1)
	{
		XftTextExtentsUtf8 (xdisplay, font1, (unsigned char*) string1,
		strlen (string1), &extents1);
		ascent = MAX (ascent, font1->ascent);
		descent = MAX (descent, font1->descent);
	}

	if (font2)
	{
		XftTextExtentsUtf8 (xdisplay, font2, (unsigned char*) string2, strlen (string2), &extents2);
		ascent = MAX (ascent, font2->ascent);
		descent = MAX (descent, font2->descent);
	}

	width = extents1.xOff + extents2.xOff + 4;
	height = ascent + descent + 2;

#if !GTK_CHECK_VERSION (3, 0, 0)
	pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	draw = XftDrawCreate (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (gdk_screen_get_default ())), xvisual, xcolormap);
#else
	draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap);
#endif

	rendcolor.red = 0;
	rendcolor.green = 0;
	rendcolor.blue = 0;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &black);

	rendcolor.red = 0xffff;
	rendcolor.green = 0xffff;
	rendcolor.blue = 0xffff;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &white);
	XftDrawRect(draw, &white, 0, 0, width, height);
	
	if (font1)
	{
		XftDrawStringUtf8(draw, &black, font1, 2, 2 + ascent, (unsigned char*) string1, strlen(string1));
	}
	
	if (font2)
	{
		XftDrawStringUtf8(draw, &black, font2, 2 + extents1.xOff, 2 + ascent, (unsigned char*) string2, strlen(string2));
	}

	XftDrawDestroy(draw);

	if (font1)
	{
		XftFontClose(xdisplay, font1);
	}
	
	if (font2)
	{
		XftFontClose(xdisplay, font2);
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,8, width, height);
#else
	tmp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, colormap, 0, 0, 0, 0, width, height);
#endif
	pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES);

#if !GTK_CHECK_VERSION (3, 0, 0)
	g_object_unref(pixmap);
#endif
	g_object_unref(tmp_pixbuf);

	g_object_set_data_full(G_OBJECT(darea), "sample-pixbuf", pixbuf, (GDestroyNotify) g_object_unref);

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_set_size_request  (GTK_WIDGET(darea), width + 2, height + 2);
	g_signal_connect(darea, "draw", G_CALLBACK(sample_draw), NULL);
#else
	g_signal_connect(darea, "size_request", G_CALLBACK(sample_size_request), NULL);
	g_signal_connect(darea, "expose_event", G_CALLBACK(sample_expose), NULL);
#endif
}
示例#18
0
文件: main.c 项目: howrujh/tp
void* thread_pattern_gen(void *data){

	Display *dp;
	Bool is_ntsc = (Bool)data;
	Window mw; /* One TopLevel Window & Two Child Windows */
	GC gc, gc_rect1, gc_rect2, gc_string;
	XftFont *xft;
	XftDraw *xftdraw;
	XRenderColor xrcolor;
	XftColor xftcolor;

	XGCValues gv;
	XSetWindowAttributes xswa;

	struct timeval tv;

	/* 서버와 접속하기 그리고 변수들을 초기화 */
	dp = XOpenDisplay ( NULL );

	mw = XCreateSimpleWindow ( dp, DefaultRootWindow( dp ),
			0, 0, 720, is_ntsc?480:576, 0,
			WhitePixel(dp,0), BlackPixel(dp,0) );

	xswa.override_redirect = True;
	XChangeWindowAttributes ( dp, mw, CWOverrideRedirect, &xswa );
	XMapWindow( dp, mw );

	gv.foreground = UsrColorPixel( dp, "red" );
	gv.background = UsrColorPixel( dp, "yello" );
	gc = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "red" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_rect1 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "blue" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_rect2 = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	gv.foreground = UsrColorPixel( dp, "white" );
	gv.background = UsrColorPixel( dp, "black" );
	gc_string = XCreateGC( dp, mw, GCForeground | GCBackground, &gv );
	
	//xft  = XftFontOpenName( dp, 0, "Bitstream Vera Sans Mono-50:bold" ); 
	xft  = XftFontOpenName( dp, 0, "Courier New-48:bold" ); 
	if(!xft){
		printf("font null\n");
		return 0;
	}
	xftdraw = XftDrawCreate(dp, mw, DefaultVisual(dp, 0), DefaultColormap(dp, 0));

	xrcolor.red = 65535;
	xrcolor.green = 65535;
	xrcolor.blue =65535;
	xrcolor.alpha = 65535;

	XftColorAllocValue(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xrcolor, &xftcolor);



	int frame_rate = is_ntsc? 30:25;
	unsigned int div = is_ntsc? 33333: 40000;

	char line1[40];
	char line2[40];

	int line1_y = is_ntsc? (480/2)-30 : (576/2)-30;
	int line2_y = is_ntsc? (480/2)+30 : (576/2)+30;

	int rect1_y = is_ntsc? 480/4 : 576/4;
	int rect2_y = is_ntsc? (480/4)*3 : (576/4)*3;


	while(1){
		if(kill_thread) break;

		int move;
		for( move = 0; move < frame_rate; move ++){
			gettimeofday(&tv, NULL);
			struct tm *ptm = localtime(&(tv.tv_sec));


			XFlush(dp);
			XClearWindow( dp, mw );

			XFillRectangle ( dp, mw, gc_rect1, (move==0)? 0:(720/30)*move, rect1_y, 50, 10);

			XFillRectangle ( dp, mw, gc_rect2, (move==0)? 0:720-(720/30)*move, rect2_y, 50, 10);


			sprintf(line1," %04d/%02d/%02d ", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);

			sprintf(line2,"%02d:%02d:%02d %02ld\'",ptm->tm_hour, ptm->tm_min, ptm->tm_sec, tv.tv_usec/div);
			XftDrawString8(xftdraw, &xftcolor, xft, 100, line1_y, (XftChar8 *)line1, 12);
			XftDrawString8(xftdraw, &xftcolor, xft, 100, line2_y, (XftChar8 *)line2, 12);
			usleep(div);
		}
	}


	printf("thread kill\n");

	/* GC, 창 파괴 & 서버와의 접속 해제 */
	XFreeGC( dp, gc );
	XUnmapWindow( dp, mw );

	XftDrawDestroy(xftdraw);
	XftColorFree(dp, DefaultVisual(dp, 0), DefaultColormap(dp, 0), &xftcolor);

	XDestroyWindow( dp, mw );


	XCloseDisplay( dp );

	return 0;


}