当前位置: 首页>>代码示例>>C++>>正文


C++ cairo_clip函数代码示例

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


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

示例1: vga_paint

/* Draw part of the widget by blitting surface buffer to window */
static void
vga_paint(GtkWidget *widget, GdkRectangle *area)
{
	VGAText * vga;

	/* Sanity checks */
	g_return_if_fail(widget != NULL);
	g_return_if_fail(VGA_IS_TEXT(widget));
	g_return_if_fail(area != NULL);
	vga = VGA_TEXT(widget);
	if (!GTK_WIDGET_DRAWABLE(widget))
	{
		fprintf(stderr, "vga_paint(): widget not drawable!\n");
		return;
	}

printf("vga_paint(): area x,y = %d,%d, width=%d, height=%d\n", area->x, area->y, area->width, area->height);
#if 0
	vga_render_area(widget, vga, area);
#else
	cairo_t *cr;
	cr = gdk_cairo_create(widget->window);
	/* Set clip region for speed */
	cairo_rectangle(cr, area->x, area->y, area->width, area->height);
	cairo_clip(cr);
	cairo_set_source_surface(cr, vga->pvt->surface_buf, 0, 0);
	cairo_paint(cr);
	cairo_destroy(cr);
#endif
	
	/* 
	 * FIXME: The algorithm seems to work great.  I watch the debug output
	 * as it runs trying various things and it always calculates the
	 * right starting/stopping row/col.  However, still sometimes things
	 * are not drawn, but I'm lead to believe right now that the problem
	 * lies elsewhere.
	 * UPDATE: Correct.  We now use vga_render_area() which is a
	 * pixel-level based refresh rather than character level.  It
	 * works fine.  Commenting out approach below.
	 *
	 */
#if 0
	row_start = area->y / vga->pvt->font->height; /* verified */
	
	num_rows = area->height / vga->pvt->font->height + 1;
	row_stop = MIN(row_start + num_rows, vga->pvt->rows);
	
	num_cols = area->width / vga->pvt->font->width + 1;
	col_start = area->x / vga->pvt->font->width;
	col_stop = MIN(col_start + num_cols, vga->pvt->cols);
#ifdef VGA_DEBUG
	fprintf(stderr, "area->y = %d, area->height = %d\n", area->y, area->height);
	fprintf(stderr, "area->x = %d, area->width = %d\n", area->x, area->width);
	fprintf(stderr, "row_start = %d, row_stop = %d\n", row_start, row_stop);
	fprintf(stderr, "col_start = %d, col_stop = %d\n", col_start, col_stop);
	fprintf(stderr, "\tnum_cols = %d\n", num_cols);

#endif

	for (y = row_start; y < row_stop; y++)
		for (x = col_start; x < col_stop; x++)
		{
			vga_paint_charcell(widget, vga,
					vga->pvt->video_buf[y*80+x],
					x*vga->pvt->font->width,
					y*vga->pvt->font->height);
		}
#endif
	
}
开发者ID:nacase,项目名称:libvgaterm-staging,代码行数:71,代码来源:vgatext.c

示例2: draw_column_data

void draw_column_data (DdbListview *listview, cairo_t *cr, DdbListviewIter it, DdbListviewIter group_it, int column, int group_y, int x, int y, int width, int height) {
    const char *ctitle;
    int cwidth;
    int calign_right;
    col_info_t *cinf;
    int minheight;
    int res = ddb_listview_column_get_info (listview, column, &ctitle, &cwidth, &calign_right, &minheight, (void **)&cinf);
    if (res == -1) {
        return;
    }
    DB_playItem_t *playing_track = deadbeef->streamer_get_playing_track ();
	int theming = !gtkui_override_listview_colors ();

    if (cinf->id == DB_COLUMN_ALBUM_ART) {
        if (theming) {
#if GTK_CHECK_VERSION(3,0,0)
            cairo_rectangle (cr, x, y, width, height);
            cairo_clip (cr);
            gtk_paint_flat_box (gtk_widget_get_style (theme_treeview), cr, GTK_STATE_NORMAL, GTK_SHADOW_NONE, theme_treeview, "cell_even_ruled", x-1, y, width+2, height);
            cairo_reset_clip (cr);
#else
            GdkRectangle clip = {
                .x = x,
                .y = y,
                .width = width,
                .height = height,
            };
            gtk_paint_flat_box (gtk_widget_get_style (theme_treeview), gtk_widget_get_window (listview->list), GTK_STATE_NORMAL, GTK_SHADOW_NONE, &clip, theme_treeview, "cell_even_ruled", x-1, y, width+2, height);
#endif
        }
        else {
            GdkColor clr;
            gtkui_get_listview_even_row_color (&clr);
            cairo_set_source_rgb (cr, clr.red/65535.f, clr.green/65535.f, clr.blue/65535.f);
            cairo_rectangle (cr, x, y, width, height);
            cairo_fill (cr);
        }
        int art_width = width - ART_PADDING_HORZ * 2;
        int art_y = y; // dest y
        int art_h = height;
        int sy; // source y
        if (group_y < ART_PADDING_VERT) {
            art_y = y - group_y + ART_PADDING_VERT;
            art_h = height - (art_y - y);
            sy = group_y;
        }
        else {
            sy = group_y - ART_PADDING_VERT;
        }
        if (art_width > 0) {
            if (group_it) {
                int h = cwidth - group_y;
                h = min (height, art_h);
                const char *album = deadbeef->pl_find_meta (group_it, "album");
                const char *artist = deadbeef->pl_find_meta (group_it, "artist");
                if (!album || !*album) {
                    album = deadbeef->pl_find_meta (group_it, "title");
                }
                GdkPixbuf *pixbuf = get_cover_art (deadbeef->pl_find_meta (((DB_playItem_t *)group_it), ":URI"), artist, album, art_width);
                if (pixbuf) {
                    int pw = gdk_pixbuf_get_width (pixbuf);
                    int ph = gdk_pixbuf_get_height (pixbuf);
                    if (sy < ph)
                    {
                        pw = min (art_width, pw);
                        ph -= sy;
                        ph = min (ph, h);
                        gdk_cairo_set_source_pixbuf (cr, pixbuf, (x + ART_PADDING_HORZ)-0, (art_y)-sy);
                        cairo_rectangle (cr, x + ART_PADDING_HORZ, art_y, pw, ph);
                        cairo_fill (cr);
                    }
                    g_object_unref (pixbuf);
                }
            }
        }
    }
开发者ID:Tydus,项目名称:deadbeef,代码行数:76,代码来源:plcommon.c

示例3: vga_render_area

/*
 * vga_render_area:
 * @vga: VGAText structure pointer
 * @area: Area to refresh
 *
 * For the given rectangular area, render the contents of the VGA buffer
 * onto the surface buffer (NOT on-screen).
 */
static void
vga_render_area(VGAText *vga, GdkRectangle * area)
{
	int x, y, x2, y2;
	int char_x, char_y, x_drawn, y_drawn, row, col;
	x2 = area->x + area->width;	/* Last column in area + 1 */
	y2 = area->y + area->height;	/* Last row in area + 1 */
	x2 = MIN(x2, vga->pvt->font->width * vga->pvt->cols);
	y2 = MIN(y2, vga->pvt->font->height * vga->pvt->rows);
	y = area->y;
	vga_charcell * cell;
	char text[2];
	cairo_t *cr;
	guchar attr;
	int cols_sameattr;
	int col_topaint;
	int num_cols;
	int last_col;
	vga_charcell *video_buf;

//printf("vga_render_area(): x,y = (%d,%d), width=%d, height=%d\n", area->x, area->y, area->width, area->height);
	/* We must create/destroy the context in each expose event */
	//cr = gdk_cairo_create(da->window);
	cr = cairo_create(vga->pvt->surface_buf);
#if 1
	/* Set clip region for speed */
	cairo_rectangle(cr, area->x, area->y, area->width, area->height);
	cairo_clip(cr);
#endif

	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
	//cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
#if 1
	cairo_set_font_face(cr, vga->pvt->font->face);
	cairo_set_font_size(cr, 1.0);
#endif

	if (vga->pvt->render_sec_buf)
		video_buf = vga->pvt->sec_buf;
	else
		video_buf = vga->pvt->video_buf;

#define NEW_WAY
#ifdef NEW_WAY
	while (y < y2) {
	//printf("while loop: y (%d) < y2 (%d)\n", y, y2);
		row = PIXEL_TO_ROW(y, vga->pvt->font);
		char_y = row * vga->pvt->font->height;
		y_drawn = (char_y + vga->pvt->font->height) - y;

		col = PIXEL_TO_COL(area->x, vga->pvt->font);
		num_cols = PIXEL_TO_COL(x2-1, vga->pvt->font) - col + 1;
		cols_sameattr = 0;
		x = col * vga->pvt->font->width;
		col_topaint = col;
		cell = &(video_buf[row * 80 + col]);
		attr = cell->attr;
		last_col = col + num_cols - 1;
		//printf("col_topaint = %d, last_col = %d, num_cols=%d\n", col_topaint, last_col, num_cols);
		while (col <= last_col) {
			cell = &(video_buf[row * 80 + col]);
			//printf("CHAR: '%c', cell attr = 0x%02x, old attr was 0x%02x\n", cell->c, cell->attr, attr);
			if (cell->attr == attr) {
				cols_sameattr++;
			} else {
				vga_set_textattr(vga, attr);
				//printf("vga_block_paint() - mid line, cols_sameattr=%d\n", cols_sameattr);
				vga_block_paint(vga, cr, col_topaint,
						row, cols_sameattr);
				attr = cell->attr;
				col_topaint += cols_sameattr;
				cols_sameattr = 1;
			}
			col++;
		}
		/* Paint last chunk of row */
		vga_set_textattr(vga, cell->attr);
		//printf("vga_block_paint() - last chunk, col_to_paint=%d, cols=%d\n", col_topaint, last_col-col_topaint);
		vga_block_paint(vga, cr, col_topaint, row,
				last_col - col_topaint + 1);
		y += vga->pvt->font->height;
	}
#else	/* !NEW_WAY */
	while (y < y2)
	{
		row = PIXEL_TO_ROW(y, vga->pvt->font);
		char_y = row * vga->pvt->font->height;
		y_drawn = (char_y + vga->pvt->font->height) - y;

		x = area->x;
		while (x < x2)
		{
//.........这里部分代码省略.........
开发者ID:nacase,项目名称:libvgaterm-staging,代码行数:101,代码来源:vgatext.c

示例4: cr_clip

static int
cr_clip (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    cairo_clip(*obj);
    return 0;
}
开发者ID:awesomeWM,项目名称:oocairo,代码行数:6,代码来源:obj_context.c

示例5: wxCHECK_MSG

bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dstHeight, wxDC* source, int xsrc, int ysrc, int srcWidth, int srcHeight, wxRasterOperationMode rop, bool useMask, int xsrcMask, int ysrcMask)
{
    wxCHECK_MSG(IsOk(), false, "invalid DC");
    wxCHECK_MSG(source && source->IsOk(), false, "invalid source DC");

    cairo_t* cr = NULL;
    if (m_graphicContext)
        cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
    cairo_t* cr_src = NULL;
    wxGraphicsContext* gc_src = source->GetGraphicsContext();
    if (gc_src)
        cr_src = static_cast<cairo_t*>(gc_src->GetNativeContext());

    if (cr == NULL || cr_src == NULL)
        return false;

    const int xsrc_dev = source->LogicalToDeviceX(xsrc);
    const int ysrc_dev = source->LogicalToDeviceY(ysrc);

    cairo_surface_t* surface = cairo_get_target(cr_src);
    cairo_surface_flush(surface);
    cairo_save(cr);
    cairo_translate(cr, xdest, ydest);
    cairo_rectangle(cr, 0, 0, dstWidth, dstHeight);
    double sx, sy;
    source->GetUserScale(&sx, &sy);
    cairo_scale(cr, dstWidth / (sx * srcWidth), dstHeight / (sy * srcHeight));
    cairo_set_source_surface(cr, surface, -xsrc_dev, -ysrc_dev);
    const wxRasterOperationMode rop_save = m_logicalFunction;
    SetLogicalFunction(rop);
    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
    cairo_surface_t* maskSurf = NULL;
    if (useMask)
    {
        const wxBitmap& bitmap = source->GetImpl()->GetSelectedBitmap();
        if (bitmap.IsOk())
        {
            wxMask* mask = bitmap.GetMask();
            if (mask)
                maskSurf = *mask;
        }
    }
    if (maskSurf)
    {
        int xsrcMask_dev = xsrc_dev;
        int ysrcMask_dev = ysrc_dev;
        if (xsrcMask != -1)
            xsrcMask_dev = source->LogicalToDeviceX(xsrcMask);
        if (ysrcMask != -1)
            ysrcMask_dev = source->LogicalToDeviceY(ysrcMask);
        cairo_clip(cr);
        cairo_mask_surface(cr, maskSurf, -xsrcMask_dev, -ysrcMask_dev);
    }
    else
    {
        cairo_fill(cr);
    }
    cairo_restore(cr);
    m_logicalFunction = rop_save;
    return true;
}
开发者ID:3v1n0,项目名称:wxWidgets,代码行数:61,代码来源:dc.cpp

示例6: g_debug

void
HippoCanvas::onPaint(WPARAM wParam, LPARAM lParam)
{
    RECT region;
    if (GetUpdateRect(window_, &region, true)) {

        int regionWidth = region.right - region.left;
        int regionHeight = region.bottom - region.top;

#if 0
        g_debug("SIZING: %p paint region %d,%d %dx%d",
                window_, region.left, region.top,
                regionWidth, regionHeight);
#endif

        // go ahead and request/resize if necessary, so we paint the right thing
        ensureRequestAndAllocation();

        PAINTSTRUCT paint;
        HDC hdc = BeginPaint(window_, &paint);

        //g_debug("paint.fErase=%d", paint.fErase);

        cairo_surface_t *surface = cairo_win32_surface_create(hdc);
        cairo_surface_t *buffer = cairo_surface_create_similar(surface,
            CAIRO_CONTENT_COLOR, regionWidth, regionHeight);
        cairo_t *cr = cairo_create(buffer);
        hippo_canvas_context_win_update_pango(context_, cr);

        // make the buffer's coordinates look like the real coordinates
        cairo_translate(cr, - region.left, - region.top);

        // Paint a background rectangle to the buffer
        cairo_rectangle(cr, region.left, region.top, regionWidth, regionHeight);
        cairo_clip(cr);
        
        // FIXME not the right background color (on linux it's the default gtk background)
        // should use system color, maybe GetThemeSysColorBrush is right. Note that 
        // this rectangle draws the little corner between the scrollbars in 
        // addition to the viewport background.
        hippo_cairo_set_source_rgba32(cr, 0xffffffff);
        cairo_paint(cr);

        // Draw canvas item to the buffer
        if (root_ != (HippoCanvasItem*) NULL) {
            RECT viewport;
            HippoRectangle viewport_hippo;
            HippoRectangle region_hippo;

            getViewport(&viewport);
            
            hippo_rectangle_from_rect(&viewport_hippo, &viewport);
            hippo_rectangle_from_rect(&region_hippo, &region);

            if (hippo_rectangle_intersect(&viewport_hippo, &region_hippo, &region_hippo)) {
                // we have to clip so we don't draw outside the viewport - the canvas
                // doesn't have its own window
                cairo_save(cr);
                cairo_rectangle(cr, region_hippo.x, region_hippo.y, region_hippo.width, region_hippo.height);
                cairo_clip(cr);

                int x, y;
                getCanvasOrigin(&x, &y);
                hippo_canvas_item_process_paint(root_, cr, &region_hippo, x, y);

                cairo_restore(cr);
            }
        }
        
        // pop the update region clip and the translation off the buffer
        cairo_destroy(cr);

        // Copy the buffer to the window
        cairo_t *window_cr = cairo_create(surface);
        cairo_rectangle(window_cr, region.left, region.top, regionWidth, regionHeight);
        cairo_clip(window_cr);
        cairo_set_source_surface(window_cr, buffer, region.left, region.top);
        cairo_paint(window_cr);
        cairo_destroy(window_cr);

        cairo_surface_destroy(buffer);
        cairo_surface_destroy(surface);

        EndPaint(window_, &paint);
    }
}
开发者ID:manoj-makkuboy,项目名称:magnetism,代码行数:86,代码来源:HippoCanvas.cpp

示例7: gimp_tag_popup_list_expose

static gboolean
gimp_tag_popup_list_expose (GtkWidget      *widget,
                            GdkEventExpose *event,
                            GimpTagPopup   *popup)
{
    GdkWindow      *window = gtk_widget_get_window (widget);
    GtkStyle       *style  = gtk_widget_get_style (widget);
    cairo_t        *cr;
    PangoAttribute *attribute;
    PangoAttrList  *attributes;
    gint            i;

    cr = gdk_cairo_create (event->window);

    gdk_cairo_region (cr, event->region);
    cairo_clip (cr);

    cairo_set_line_width (cr, 1.0);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);

    for (i = 0; i < popup->tag_count; i++)
    {
        PopupTagData *tag_data = &popup->tag_data[i];

        pango_layout_set_text (popup->layout,
                               gimp_tag_get_name (tag_data->tag), -1);

        switch (tag_data->state)
        {
        case GTK_STATE_SELECTED:
            attributes = pango_attr_list_copy (popup->combo_entry->selected_item_attr);
            break;

        case GTK_STATE_INSENSITIVE:
            attributes = pango_attr_list_copy (popup->combo_entry->insensitive_item_attr);
            break;

        default:
            attributes = pango_attr_list_copy (popup->combo_entry->normal_item_attr);
            break;
        }

        if (tag_data == popup->prelight &&
                tag_data->state != GTK_STATE_INSENSITIVE)
        {
            attribute = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
            pango_attr_list_insert (attributes, attribute);
        }

        pango_layout_set_attributes (popup->layout, attributes);
        pango_attr_list_unref (attributes);

        if (tag_data->state == GTK_STATE_SELECTED)
        {
            gdk_cairo_set_source_color (cr,
                                        &popup->combo_entry->selected_item_color);

            cairo_rectangle (cr,
                             tag_data->bounds.x - 1,
                             tag_data->bounds.y - popup->scroll_y,
                             tag_data->bounds.width + 2,
                             tag_data->bounds.height);
            cairo_fill (cr);

            cairo_translate (cr, 0.5, 0.5);

            cairo_move_to (cr,
                           tag_data->bounds.x,
                           tag_data->bounds.y - popup->scroll_y - 1);
            cairo_line_to (cr,
                           tag_data->bounds.x + tag_data->bounds.width - 1,
                           tag_data->bounds.y - popup->scroll_y - 1);

            cairo_move_to (cr,
                           tag_data->bounds.x,
                           tag_data->bounds.y - popup->scroll_y + tag_data->bounds.height);
            cairo_line_to (cr,
                           tag_data->bounds.x + tag_data->bounds.width - 1,
                           tag_data->bounds.y - popup->scroll_y + tag_data->bounds.height);

            cairo_stroke (cr);

            cairo_translate (cr, -0.5, -0.5);
        }

        cairo_move_to (cr,
                       (tag_data->bounds.x +
                        GIMP_TAG_POPUP_PADDING),
                       (tag_data->bounds.y -
                        popup->scroll_y +
                        GIMP_TAG_POPUP_PADDING));

        pango_cairo_show_layout (cr, popup->layout);

        if (tag_data == popup->prelight              &&
                tag_data->state != GTK_STATE_INSENSITIVE &&
                ! popup->single_select_disabled)
        {
            gtk_paint_focus (style, window,
                             tag_data->state,
//.........这里部分代码省略.........
开发者ID:davidyang5405,项目名称:gimp,代码行数:101,代码来源:gimptagpopup.c

示例8: draw_column_data

void draw_column_data (DdbListview *listview, cairo_t *cr, DdbListviewIter it, DdbListviewIter group_it, int column, int group_y, int group_height, int group_pinned, int grp_next_y, int x, int y, int width, int height) {
    const char *ctitle;
    int cwidth;
    int calign_right;
    col_info_t *cinf;
    int minheight;
    int res = ddb_listview_column_get_info (listview, column, &ctitle, &cwidth, &calign_right, &minheight, (void **)&cinf);
    if (res == -1) {
        return;
    }

    DB_playItem_t *playing_track = deadbeef->streamer_get_playing_track ();
    int theming = !gtkui_override_listview_colors ();

    if (cinf->id == DB_COLUMN_ALBUM_ART) {
        if (theming) {
#if GTK_CHECK_VERSION(3,0,0)
            cairo_rectangle (cr, x, y, width, height);
            cairo_clip (cr);
            gtk_paint_flat_box (gtk_widget_get_style (theme_treeview), cr, GTK_STATE_NORMAL, GTK_SHADOW_NONE, theme_treeview, "cell_even_ruled", x-1, y, width+2, height);
            cairo_reset_clip (cr);
#else
            GdkRectangle clip = {
                .x = x,
                .y = y,
                .width = width,
                .height = height,
            };
            gtk_paint_flat_box (gtk_widget_get_style (theme_treeview), gtk_widget_get_window (listview->list), GTK_STATE_NORMAL, GTK_SHADOW_NONE, &clip, theme_treeview, "cell_even_ruled", x-1, y, width+2, height);
#endif
        }
        else {
            GdkColor clr;
            gtkui_get_listview_even_row_color (&clr);
            cairo_set_source_rgb (cr, clr.red/65535.f, clr.green/65535.f, clr.blue/65535.f);
            cairo_rectangle (cr, x, y, width, height);
            cairo_fill (cr);
        }
        int real_art_width = width - ART_PADDING_HORZ * 2;
        if (real_art_width > 0 && group_it) {
            const char *album = deadbeef->pl_find_meta (group_it, "album");
            const char *artist = deadbeef->pl_find_meta (group_it, "artist");
            if (!album || !*album) {
                album = deadbeef->pl_find_meta (group_it, "title");
            }
            if (listview->new_cover_size != real_art_width) {
                listview->new_cover_size = real_art_width;
                if (listview->cover_refresh_timeout_id) {
                    g_source_remove (listview->cover_refresh_timeout_id);
                    listview->cover_refresh_timeout_id = 0;
                }
                if (listview->cover_size == -1) {
                    listview->cover_size = real_art_width;
                }
                else {
                    if (!listview->cover_refresh_timeout_id) {
                        listview->cover_refresh_timeout_id = g_timeout_add (1000, deferred_cover_load_cb, listview);
                    }
                }
            }
            int art_width = listview->cover_size;
            int art_y = y; // dest y
            int art_h = height;
            int sy; // source y
            if (group_y < ART_PADDING_VERT) {
                art_y = y - group_y + ART_PADDING_VERT;
                art_h = height - (art_y - y);
                sy = group_y;
            }
            else {
                sy = group_y - ART_PADDING_VERT;
            }
            int h = cwidth - group_y;
            h = min (height, art_h);

            int hq = 0;
            GdkPixbuf *pixbuf = get_cover_art_callb (deadbeef->pl_find_meta (((DB_playItem_t *)group_it), ":URI"), artist, album, real_art_width == art_width ? art_width : -1, redraw_playlist_single, listview);
            if (!pixbuf) {
                pixbuf = cover_get_default_pixbuf ();
            }
            if (pixbuf) {
                art_width = gdk_pixbuf_get_width (pixbuf);
                float art_scale = (float)real_art_width / art_width;
                int pw = real_art_width;
                int ph;
                if (gdk_pixbuf_get_width (pixbuf) < gdk_pixbuf_get_height (pixbuf)) {
                    art_scale *= (float)gdk_pixbuf_get_width (pixbuf) / gdk_pixbuf_get_height (pixbuf);
                }

                if (group_pinned == 1 && gtkui_groups_pinned) {
                    ph = group_height;
                }
                else {
                    ph = pw;
                }

                if (sy < ph)
                {
                    cairo_save (cr);
                    if (group_pinned == 1 && gtkui_groups_pinned) {
//.........这里部分代码省略.........
开发者ID:kij,项目名称:deadbeef,代码行数:101,代码来源:plcommon.c

示例9: hc_draw_shadow


//.........这里部分代码省略.........
	gint line_width;
	gint clip_x = x, clip_y = y, clip_width = width, clip_height = height;

	/***********************************************/
	/* GTK Sanity Checks                           */
	/***********************************************/
	CHECK_ARGS


	/***********************************************/
	/* GTK Special Cases - adjust Size/Offset      */
	/***********************************************/
	line_width = HC_STYLE(style)->edge_thickness;

	if (CHECK_DETAIL (detail, "menubar") && ge_is_panel_widget_item(widget))
	{
		return;
	}

	/* Spin Button */
	if ((CHECK_DETAIL(detail, "spinbutton_up")) || (CHECK_DETAIL(detail, "spinbutton_down")))
	{
		/* Overdraw Height By Half The Line Width -
			Prevents Double line Between buttons */
		height += floor(line_width / 2);


		/* If Down Button Offset By Half Line Width */
		if (CHECK_DETAIL(detail, "spinbutton_down"))
		{
			y -= floor(line_width / 2);
		}


		/* Overdraw Width By Line Width -
			Prevents Double line Between Entry And Buttons */
		width += line_width;


		/* If LTR Offset X By Line Width */
		if (ge_widget_is_ltr (widget))
		{
			x -= line_width;
		}

		/* Force Border To Use Foreground Widget State */
		if (widget)
		{
			foreground = HC_STYLE(style)->color_cube.fg[gtk_widget_get_state(widget)];
		}
	}


	/* Entry - Force Border To Use Foreground Matching Widget State */
	if (CHECK_DETAIL(detail, "entry") && !ge_is_combo(widget))
	{
		foreground = HC_STYLE(style)->color_cube.fg[widget ? gtk_widget_get_state(widget) : GTK_STATE_NORMAL];
	}


	/* Combo Box Button's */
	if (CHECK_DETAIL(detail, "button") && ge_is_in_combo_box(widget))
	{
		/* Overdraw Width By Line Width -
			Prevents Double Line Between Entry and Button. */
		width += line_width;


		/* If LTR Offset X By Line Width */
		if (ge_widget_is_ltr (widget))
		{
			x -= line_width;
		}


		/* Force Border To Use Foreground Matching Parent State */
		if ((widget) && (gtk_widget_get_parent(widget)))
		{
			gtk_widget_ensure_style(gtk_widget_get_parent(widget));
			ge_gdk_color_to_cairo(&gtk_widget_get_style(gtk_widget_get_parent(widget))->fg[gtk_widget_get_state (widget)], &foreground);
		}
	}


	/***********************************************/
	/* Draw Border                                 */
	/***********************************************/
	/* Clip Border Too Passed Size */
	cairo_rectangle(cr, clip_x, clip_y, clip_width, clip_height);
	cairo_clip(cr);

	/* Set Line Style */
	ge_cairo_set_color(cr, &foreground);
	cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);

	cairo_set_line_width (cr, line_width);
	ge_cairo_inner_rectangle (cr, x, y, width, height);
	
	cairo_stroke(cr);
}
开发者ID:Distrotech,项目名称:gtk-engines,代码行数:101,代码来源:hc-style.c

示例10: hc_draw_extension


//.........这里部分代码省略.........
	/***********************************************/
	line_width = HC_STYLE(style)->edge_thickness;

	/* What all this is for -

		GTK doesn't overlap Extensions and Notebooks,
		but rather a tab is drawn with a "gap" side.

		Instead of long draw cases per gap side,
		perform a standard draw, but clipped to size,
		and overdraw edge thickness + one on gap side.
 
		To fake the apearance of overlap on edge aligned tabs
		increase clip by edge thickness on gap side. 
	 */
	if (widget && (GE_IS_NOTEBOOK (widget)))
	{
		GtkAllocation allocation;
		gtk_widget_get_allocation (widget, &allocation);
		widget_x = (allocation.x + gtk_container_get_border_width (GTK_CONTAINER (widget)));
		widget_y = (allocation.y + gtk_container_get_border_width (GTK_CONTAINER (widget)));
		widget_width = (allocation.width - 2*gtk_container_get_border_width (GTK_CONTAINER (widget)));
		widget_height = (allocation.height - 2*gtk_container_get_border_width (GTK_CONTAINER (widget)));
	}

	switch (gap_side)
	{
		case GTK_POS_TOP:
			if (GTK_CHECK_VERSION(2,10,0) || 
				((widget && GE_IS_NOTEBOOK (widget)) && 
				((x==widget_x) || 
				((x + width) == (widget_x + widget_width)))))
			{
				clip_height += line_width;

				if (!GTK_CHECK_VERSION(2,10,0))
				{
					height -= floor(line_width/2.0);
				}
			}
			
			y -= (line_width + 1);
			height += (line_width + 1);
		break;

		case GTK_POS_LEFT:
			if (GTK_CHECK_VERSION(2,10,0) || 
				((widget && GE_IS_NOTEBOOK (widget)) && 
				((y==widget_y) || 
				((y + height) == (widget_y + widget_height)))))
			{
				clip_width += line_width;

				if (!GTK_CHECK_VERSION(2,10,0))
				{
					x -= floor(line_width/2.0);
				}
			}

			x -= (line_width + 1);
			width += (line_width + 1);
		break;

		default:
		case GTK_POS_BOTTOM:
			height += (line_width + 1);
		break;

		case GTK_POS_RIGHT:
			width += (line_width + 1);
		break;
	}


	/***********************************************/
	/* Draw Border                                 */
	/***********************************************/

	/* Clip Too Size */
	cairo_rectangle(cr, clip_x, clip_y, clip_width, clip_height);
	cairo_clip(cr);


	/* Set Fill Style */
	ge_cairo_set_color(cr, background);

	/* Fill Rectangle */
	cairo_rectangle (cr, x, y, width, height);
	cairo_fill(cr);


	/* Set Line Style */
	ge_cairo_set_color(cr, foreground);
	cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);

	cairo_set_line_width (cr, line_width);
	ge_cairo_inner_rectangle (cr, x, y, width, height);
	
	cairo_stroke(cr);
}
开发者ID:Distrotech,项目名称:gtk-engines,代码行数:101,代码来源:hc-style.c

示例11: um_crop_area_expose

static gboolean
um_crop_area_expose (GtkWidget      *widget,
                     GdkEventExpose *event)
{
        cairo_t *cr;
        GdkRectangle area;
        GdkRectangle crop;
        gint width, height;
        UmCropArea *uarea = UM_CROP_AREA (widget);

        if (uarea->priv->browse_pixbuf == NULL)
                return FALSE;

        update_pixbufs (uarea);

        width = gdk_pixbuf_get_width (uarea->priv->pixbuf);
        height = gdk_pixbuf_get_height (uarea->priv->pixbuf);
        crop_to_widget (uarea, &crop);

        area.x = 0;
        area.y = 0;
        area.width = width;
        area.height = crop.y;
        gdk_rectangle_intersect (&area, &event->area, &area);
        gdk_draw_pixbuf (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         uarea->priv->color_shifted,
                         area.x, area.y,
                         area.x, area.y,
                         area.width, area.height,
                         GDK_RGB_DITHER_NONE, 0, 0);

        area.x = 0;
        area.y = crop.y;
        area.width = crop.x;
        area.height = crop.height;
        gdk_rectangle_intersect (&area, &event->area, &area);
        gdk_draw_pixbuf (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         uarea->priv->color_shifted,
                         area.x, area.y,
                         area.x, area.y,
                         area.width, area.height,
                         GDK_RGB_DITHER_NONE, 0, 0);

        area.x = crop.x;
        area.y = crop.y;
        area.width = crop.width;
        area.height = crop.height;
        gdk_rectangle_intersect (&area, &event->area, &area);
        gdk_draw_pixbuf (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         uarea->priv->pixbuf,
                         area.x, area.y,
                         area.x, area.y,
                         area.width, area.height,
                         GDK_RGB_DITHER_NONE, 0, 0);

        area.x = crop.x + crop.width;
        area.y = crop.y;
        area.width = width - area.x;
        area.height = crop.height;
        gdk_rectangle_intersect (&area, &event->area, &area);
        gdk_draw_pixbuf (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         uarea->priv->color_shifted,
                         area.x, area.y,
                         area.x, area.y,
                         area.width, area.height,
                         GDK_RGB_DITHER_NONE, 0, 0);

        area.x = 0;
        area.y = crop.y + crop.height;
        area.width = width;
        area.height = height - area.y;
        gdk_rectangle_intersect (&area, &event->area, &area);
        gdk_draw_pixbuf (widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                         uarea->priv->color_shifted,
                         area.x, area.y,
                         area.x, area.y,
                         area.width, area.height,
                         GDK_RGB_DITHER_NONE, 0, 0);

        cr = gdk_cairo_create (widget->window);
        gdk_cairo_rectangle (cr, &event->area);
        cairo_clip (cr);

        if (uarea->priv->active_region != OUTSIDE) {
                gint x1, x2, y1, y2;
                gdk_cairo_set_source_color (cr, &widget->style->white);
                cairo_set_line_width (cr, 1.0);
                x1 = crop.x + crop.width / 3.0;
                x2 = crop.x + 2 * crop.width / 3.0;
                y1 = crop.y + crop.height / 3.0;
                y2 = crop.y + 2 * crop.height / 3.0;

                cairo_move_to (cr, x1 + 0.5, crop.y);
                cairo_line_to (cr, x1 + 0.5, crop.y + crop.height);

//.........这里部分代码省略.........
开发者ID:raveit65,项目名称:mate-accountsdialog,代码行数:101,代码来源:um-crop-area.c

示例12: cairo_clip

void cairo_context::clip()
{
    cairo_clip(cairo_.get());
    check_object_status_and_throw_exception(*this);
}
开发者ID:MMyhub,项目名称:mapnik,代码行数:5,代码来源:cairo_context.cpp

示例13: gimp_ruler_draw_pos

static void
gimp_ruler_draw_pos (GimpRuler *ruler,
                     cairo_t   *cr)
{
  GtkWidget        *widget = GTK_WIDGET (ruler);
  GtkStyle         *style  = gtk_widget_get_style (widget);
  GimpRulerPrivate *priv   = GIMP_RULER_GET_PRIVATE (ruler);
  GtkStateType      state  = gtk_widget_get_state (widget);
  GtkAllocation     allocation;
  gint              x, y;
  gint              width, height;
  gint              bs_width, bs_height;
  gint              xthickness;
  gint              ythickness;

  if (! gtk_widget_is_drawable (widget))
    return;

  gtk_widget_get_allocation (widget, &allocation);

  xthickness = style->xthickness;
  ythickness = style->ythickness;

  if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      width  = allocation.width;
      height = allocation.height - ythickness * 2;

      bs_width = height / 2 + 2;
      bs_width |= 1;  /* make sure it's odd */
      bs_height = bs_width / 2 + 1;
    }
  else
    {
      width  = allocation.width - xthickness * 2;
      height = allocation.height;

      bs_height = width / 2 + 2;
      bs_height |= 1;  /* make sure it's odd */
      bs_width = bs_height / 2 + 1;
    }

  if ((bs_width > 0) && (bs_height > 0))
    {
      gdouble  lower;
      gdouble  upper;
      gdouble  position;
      gdouble  increment;

      if (! cr)
        {
          cr = gdk_cairo_create (gtk_widget_get_window (widget));

          cairo_rectangle (cr,
                           allocation.x, allocation.y,
                           allocation.width, allocation.height);
          cairo_clip (cr);

          cairo_translate (cr, allocation.x, allocation.y);

          /*  If a backing store exists, restore the ruler  */
          if (priv->backing_store)
            {
              cairo_set_source_surface (cr, priv->backing_store, 0, 0);
              cairo_rectangle (cr, priv->xsrc, priv->ysrc, bs_width, bs_height);
              cairo_fill (cr);
            }
        }
      else
        {
          cairo_reference (cr);
        }

      position = gimp_ruler_get_position (ruler);

      gimp_ruler_get_range (ruler, &lower, &upper, NULL);

      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          increment = (gdouble) width / (upper - lower);

          x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
          y = (height + bs_height) / 2 + ythickness;
        }
      else
        {
          increment = (gdouble) height / (upper - lower);

          x = (width + bs_width) / 2 + xthickness;
          y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
        }

      gdk_cairo_set_source_color (cr, &style->fg[state]);

      cairo_move_to (cr, x, y);

      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
        {
          cairo_line_to (cr, x + bs_width / 2.0, y + bs_height);
          cairo_line_to (cr, x + bs_width,       y);
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:gimp,代码行数:101,代码来源:gimpruler.c

示例14: gimp_color_bar_expose

static gboolean
gimp_color_bar_expose (GtkWidget      *widget,
                       GdkEventExpose *event)
{
  GimpColorBar    *bar = GIMP_COLOR_BAR (widget);
  cairo_t         *cr;
  GtkAllocation    allocation;
  cairo_surface_t *surface;
  cairo_pattern_t *pattern;
  guchar          *src;
  guchar          *dest;
  gint             x, y;
  gint             width, height;
  gint             i;

  cr = gdk_cairo_create (event->window);

  gdk_cairo_region (cr, event->region);
  cairo_clip (cr);

  gtk_widget_get_allocation (widget, &allocation);

  x = y = gtk_container_get_border_width (GTK_CONTAINER (bar));

  width  = allocation.width  - 2 * x;
  height = allocation.height - 2 * y;

  if (width < 1 || height < 1)
    return TRUE;

  cairo_translate (cr, allocation.x + x, allocation.y + y);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_clip (cr);

  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1);

  for (i = 0, src = bar->buf, dest = cairo_image_surface_get_data (surface);
       i < 256;
       i++, src += 3, dest += 4)
    {
      GIMP_CAIRO_RGB24_SET_PIXEL(dest, src[0], src[1], src[2]);
    }

  cairo_surface_mark_dirty (surface);

  pattern = cairo_pattern_create_for_surface (surface);
  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
  cairo_surface_destroy (surface);

  if (bar->orientation == GTK_ORIENTATION_HORIZONTAL)
    {
      cairo_scale (cr, (gdouble) width / 256.0, 1.0);
    }
  else
    {
      cairo_translate (cr, 0, height);
      cairo_scale (cr, 1.0, (gdouble) height / 256.0);
      cairo_rotate (cr, - G_PI / 2);
    }

  cairo_set_source (cr, pattern);
  cairo_pattern_destroy (pattern);

  cairo_paint (cr);

  cairo_destroy (cr);

  return TRUE;
}
开发者ID:AdamGrzonkowski,项目名称:gimp-1,代码行数:69,代码来源:gimpcolorbar.c

示例15: ag_chart_renderer_render

static void
ag_chart_renderer_render(GtkCellRenderer      *renderer,
                         cairo_t              *cr,
                         GtkWidget            *widget,
                         const GdkRectangle   *background_area,
                         const GdkRectangle   *cell_area,
                         GtkCellRendererState flags)
{
    AgChartRendererPrivate *priv = ag_chart_renderer_get_instance_private(
            AG_CHART_RENDERER(renderer)
        );
    int             margin;
    GtkStyleContext *context = gtk_widget_get_style_context(widget);
    GdkPixbuf       *pixbuf;

    gtk_style_context_save(context);
    gtk_style_context_add_class(context, "ag-chart-renderer");

    if (priv->css_class) {
        gtk_style_context_add_class(context, priv->css_class);
    }

    cairo_save(cr);
    gdk_cairo_rectangle(cr, cell_area);
    cairo_clip(cr);

    cairo_translate(cr, cell_area->x, cell_area->y);

    margin = MAX(
            AG_CHART_RENDERER_TILE_MARGIN,
            (int)((cell_area->width - AG_CHART_RENDERER_TILE_SIZE) / 2)
        );

    g_object_get(renderer, "pixbuf", &pixbuf, NULL);

    if (pixbuf != NULL) {
        GdkRectangle area = {
                margin,
                margin,
                AG_CHART_RENDERER_TILE_SIZE,
                AG_CHART_RENDERER_TILE_SIZE
            };

        GTK_CELL_RENDERER_CLASS(ag_chart_renderer_parent_class)->render(
                renderer,
                cr,
                widget,
                &area,
                &area,
                flags
            );
    } else {
        gtk_render_frame(
                context,
                cr,
                margin,
                margin,
                AG_CHART_RENDERER_TILE_SIZE,
                AG_CHART_RENDERER_TILE_SIZE
            );
        gtk_render_background(
                context,
                cr,
                margin,
                margin,
                AG_CHART_RENDERER_TILE_SIZE,
                AG_CHART_RENDERER_TILE_SIZE
            );
    }

    gtk_style_context_restore(context);

    if (priv->toggle_visible) {
        gint xpad,
             ypad,
             x_offset,
             check_x,
             check_y;

        gtk_cell_renderer_get_padding(
                GTK_CELL_RENDERER(renderer),
                &xpad, &ypad
            );

        if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) {
            x_offset = xpad;
        } else {
            x_offset = cell_area->width
                - AG_CHART_RENDERER_CHECK_ICON_SIZE
                - xpad;
        }

        check_x = x_offset;
        check_y = cell_area->height - AG_CHART_RENDERER_CHECK_ICON_SIZE - ypad;

        gtk_style_context_save(context);
        gtk_style_context_add_class(context, GTK_STYLE_CLASS_CHECK);

        if (priv->checked) {
            gtk_style_context_set_state(context, GTK_STATE_FLAG_CHECKED);
//.........这里部分代码省略.........
开发者ID:gergelypolonkai,项目名称:astrognome,代码行数:101,代码来源:ag-chart-renderer.c


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