static void sample_expose(GtkWidget* darea, GdkEventExpose* expose) #endif { GtkAllocation allocation; GdkPixbuf* pixbuf = g_object_get_data(G_OBJECT(darea), "sample-pixbuf"); int width = gdk_pixbuf_get_width(pixbuf); int height = gdk_pixbuf_get_height(pixbuf); gtk_widget_get_allocation (darea, &allocation); int x = (allocation.width - width) / 2; int y = (allocation.height - height) / 2; GdkColor black, white; gdk_color_parse ("black", &black); gdk_color_parse ("white", &white); #if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr = gdk_cairo_create (expose->window); #endif cairo_set_line_width (cr, 1); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); gdk_cairo_set_source_color (cr, &white); cairo_rectangle (cr, 0, 0, allocation.width, allocation.height); cairo_fill_preserve (cr); gdk_cairo_set_source_color (cr, &black); cairo_stroke (cr); gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); cairo_paint(cr); #if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); #endif }
static GtkWidget *get_color_icon(int c, GtkStyle *style) { GtkWidget *icon; GdkPixbuf *pixbuf; cairo_surface_t *canvas; cairo_t *cr; canvas = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 16, 16); cr = cairo_create(canvas); gdk_cairo_set_source_color(cr, &style->dark[GTK_STATE_NORMAL]); cairo_rectangle(cr, 0, 0, 16, 16); cairo_fill(cr); gdk_cairo_set_source_color(cr, &colors[c]); cairo_rectangle(cr, 1, 1, 14, 14); cairo_fill(cr); cairo_destroy(cr); pixbuf = gdk_pixbuf_get_from_surface(canvas, 0, 0, 16, 16); icon = gtk_image_new_from_pixbuf(pixbuf); cairo_surface_destroy(canvas); g_object_unref(pixbuf); return icon; }
static gboolean app_resizer_paint_window (GtkWidget * widget, cairo_t * cr, AppShellData * app_data) { cairo_save(cr); GtkAllocation widget_allocation; gtk_widget_get_allocation (widget, &widget_allocation); gdk_cairo_set_source_color (cr, gtk_widget_get_style (widget)->base); cairo_set_line_width(cr, 1); cairo_rectangle(cr, widget_allocation.x, widget_allocation.y, widget_allocation.width, widget_allocation.height); cairo_stroke_preserve(cr); cairo_fill(cr); if (app_data->selected_group) { GtkWidget *selected_widget = GTK_WIDGET (app_data->selected_group); GtkAllocation selected_widget_allocation; gtk_widget_get_allocation (selected_widget, &selected_widget_allocation); gdk_cairo_set_source_color (cr, gtk_widget_get_style (selected_widget)->light); cairo_set_line_width(cr, 1); cairo_rectangle(cr, selected_widget_allocation.x, selected_widget_allocation.y, selected_widget_allocation.width, selected_widget_allocation.height); cairo_stroke_preserve(cr); cairo_fill(cr); } cairo_restore(cr); return FALSE; }
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring) { GdkPixbuf* glyph_pixbuf; cairo_surface_t *surface; PangoLayout* layout; PangoRectangle ink, logic; PangoContext* pango_context; gint w = gdk_pixbuf_get_width(base); gint h = gdk_pixbuf_get_height(base); cairo_t *cr; surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h); pango_context = gtk_widget_get_pango_context(widget); layout = pango_layout_new(pango_context); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, glyphstring, -1); cr = cairo_create (surface); gdk_cairo_set_source_color (cr, bg); cairo_paint (cr); gdk_cairo_set_source_color (cr, fg); pango_layout_get_pixel_extents(layout, &ink, &logic); cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); g_object_unref(layout); glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h); cairo_surface_destroy (surface); return glyph_pixbuf; }
void gtk_codegraph_paint( GtkCodeGraph* box){ box->priv->content = gdk_cairo_create(box->priv->backing_pixmap); cairo_set_source_rgb(box->priv->content, 0.5, 0.5, 0.5); GdkColor _color; gdk_color_parse("#bfbfbf", &_color); gdk_cairo_set_source_color (box->priv->content, &_color); cairo_paint(box->priv->content); int i; /*Нарисуем линию кодов*/ // printf("i: %d x:%d, y:%d\n", i ,box->priv->points[i].x, box->priv->points[i].y ); cairo_set_source_rgb(box->priv->content, 0., 0., 0.1); cairo_move_to(box->priv->content, box->priv->points[0].x, box->priv->points[0].y ); for (i=1; i < box->priv->numPoints; ++i){ cairo_line_to(box->priv->content, box->priv->points[i].x, box->priv->points[i].y ); } cairo_stroke(box->priv->content); /*Нарисуем текст длительностей*/ cairo_select_font_face (box->priv->content, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (box->priv->content, 11.0); gchar buff[10]; for ( i=0; i < box->priv->numPointsText; ++i ){ gdk_cairo_set_source_color (box->priv->content, &box->priv->color[i] ); cairo_move_to( box->priv->content, box->priv->pointsText[i].x, box->priv->pointsText[i].y ); snprintf(buff, sizeof(buff), "%1.3fc", box->priv->dta[i] ); cairo_show_text (box->priv->content , buff ); cairo_stroke(box->priv->content ); } cairo_destroy(box->priv->content); }
static void redraw_pixmap (Monitor *m) { int i; cairo_t *cr = cairo_create(m->pixmap); cairo_set_line_width (cr, 1.0); /* Erase pixmap */ gdk_cairo_set_source_color(cr, &m->da->style->black); cairo_paint(cr); gdk_cairo_set_source_color(cr, &m->foreground_color); for (i = 0; i < m->pixmap_width; i++) { unsigned int drawing_cursor = (m->ring_cursor + i) % m->pixmap_width; /* Draw one bar of the graph */ cairo_move_to(cr, i + 0.5, m->pixmap_height); cairo_line_to(cr, i + 0.5, (1.0 - m->stats[drawing_cursor]) * m->pixmap_height); cairo_stroke(cr); } check_cairo_status(cr); cairo_destroy(cr); /* Redraw pixmap */ gtk_widget_queue_draw(m->da); }
/* Deprecated? Depend strictly on refresh? This won't work for blinking * and friends * x and y are in pixel units */ static void vga_paint_charcell(GtkWidget *da, VGAText *vga, vga_charcell cell, int x, int y) { #ifdef USE_DEPRECATED_GDK vga_set_textattr(vga, cell.attr); gdk_gc_set_ts_origin(vga->pvt->gc, x, y-(16 * cell.c)); gdk_draw_rectangle(da->window, vga->pvt->gc, TRUE, x, y, vga->pvt->font->width, vga->pvt->font->height); #else printf("vga_paint_charcel() called -- why?\n"); #if 0 char text[2]; vga_set_textattr(vga, cell.attr); gdk_cairo_set_source_color(vga->pvt->cr, vga_palette_get_color(vga->pvt->pal, vga->pvt->bg)); cairo_move_to(vga->pvt->cr, x, y); cairo_rectangle(vga->pvt->cr, x, y, vga->pvt->font->width, vga->pvt->font->height); cairo_fill(vga->pvt->cr); gdk_cairo_set_source_color(vga->pvt->cr, vga_palette_get_color(vga->pvt->pal, vga->pvt->fg)); /* FIXME: Don't use toy text API. Use cairo_show_glyphs() instead */ text[0] = cell.c; text[1] = '\0'; cairo_show_text(vga->pvt->cr, text); #endif #endif }
void osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { gdk_cairo_set_source_color(cr, bg); cairo_fill_preserve (cr); gdk_cairo_set_source_color(cr, fg); cairo_set_line_width (cr, 1); cairo_stroke (cr); }
/* Handle exposure events for the color picker's drawing area */ static gint expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) { GtkColorButton *color_button = GTK_COLOR_BUTTON (data); GtkAllocation allocation; cairo_pattern_t *checkered; cairo_t *cr; cr = gdk_cairo_create (event->window); gtk_widget_get_allocation (widget, &allocation); gdk_cairo_rectangle (cr, &allocation); cairo_clip (cr); if (gtk_color_button_has_alpha (color_button)) { cairo_save (cr); cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK); cairo_paint (cr); cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT); cairo_scale (cr, CHECK_SIZE, CHECK_SIZE); checkered = gtk_color_button_get_checkered (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); cairo_restore (cr); cairo_set_source_rgba (cr, color_button->priv->color.red / 65535., color_button->priv->color.green / 65535., color_button->priv->color.blue / 65535., color_button->priv->alpha / 65535.); } else { gdk_cairo_set_source_color (cr, &color_button->priv->color); } cairo_paint (cr); if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button))) { gdk_cairo_set_source_color (cr, >K_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE]); checkered = gtk_color_button_get_checkered (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); } cairo_destroy (cr); return FALSE; }
app_resizer_paint_window (GtkWidget * widget, GdkEventExpose * event, AppShellData * app_data) #endif { /* printf("ENTER - app_resizer_paint_window\n"); printf("Area: %d, %d, %d, %d\n", event->area.x, event->area.y, event->area.width, event->area.height); printf("Allocation:%d, %d, %d, %d\n\n", widget->allocation.x, widget->allocation.y, widget->allocation.width, widget->allocation.height); */ #if GTK_CHECK_VERSION (3, 0, 0) cairo_save(cr); GtkAllocation widget_allocation; gtk_widget_get_allocation (widget, &widget_allocation); gdk_cairo_set_source_color (cr, gtk_widget_get_style (widget)->base); cairo_set_line_width(cr, 1); cairo_rectangle(cr, widget_allocation.x, widget_allocation.y, widget_allocation.width, widget_allocation.height); cairo_stroke_preserve(cr); cairo_fill(cr); #else gdk_draw_rectangle (GTK_LAYOUT (widget)->bin_window, widget->style->base_gc[GTK_STATE_NORMAL], TRUE, event->area.x, event->area.y, event->area.width, event->area.height); #endif if (app_data->selected_group) { GtkWidget *selected_widget = GTK_WIDGET (app_data->selected_group); #if GTK_CHECK_VERSION (3, 0, 0) GtkAllocation selected_widget_allocation; gtk_widget_get_allocation (selected_widget, &selected_widget_allocation); gdk_cairo_set_source_color (cr, gtk_widget_get_style (selected_widget)->light); cairo_set_line_width(cr, 1); cairo_rectangle(cr, selected_widget_allocation.x, selected_widget_allocation.y, selected_widget_allocation.width, selected_widget_allocation.height); cairo_stroke_preserve(cr); cairo_fill(cr); #else gdk_draw_rectangle (selected_widget->window, /* drawing on child window and child coordinates */ selected_widget->style->light_gc[GTK_STATE_SELECTED], TRUE, selected_widget->allocation.x, selected_widget->allocation.y, widget->allocation.width, /* drawing with our coordinates here to draw all the way to the edge. */ selected_widget->allocation.height); #endif } #if GTK_CHECK_VERSION (3, 0, 0) cairo_restore(cr); #endif return FALSE; }
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring) { GdkPixbuf* glyph_pixbuf; #if GTK_CHECK_VERSION (3, 0, 0) cairo_surface_t *surface; #else GdkPixbuf *alpha_pixbuf; GdkPixmap* pixmap; #endif PangoLayout* layout; PangoRectangle ink, logic; PangoContext* pango_context; gint w = gdk_pixbuf_get_width(base); gint h = gdk_pixbuf_get_height(base); cairo_t *cr; #if GTK_CHECK_VERSION (3, 0, 0) surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h); #else pixmap = gdk_pixmap_new(gdk_get_default_root_window (),w, h, -1); #endif pango_context = gtk_widget_get_pango_context(widget); layout = pango_layout_new(pango_context); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, glyphstring, -1); #if GTK_CHECK_VERSION (3, 0, 0) cr = cairo_create (surface); #else cr = gdk_cairo_create (pixmap); #endif gdk_cairo_set_source_color (cr, bg); cairo_paint (cr); gdk_cairo_set_source_color (cr, fg); pango_layout_get_pixel_extents(layout, &ink, &logic); cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); g_object_unref(layout); #if GTK_CHECK_VERSION (3, 0, 0) glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h); cairo_surface_destroy (surface); return glyph_pixbuf; #else glyph_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, w, h); g_object_unref(pixmap); alpha_pixbuf = gdk_pixbuf_add_alpha(glyph_pixbuf, TRUE, bg->red >> 8, bg->green >> 8, bg->blue >> 8); g_object_unref(G_OBJECT(glyph_pixbuf)); return alpha_pixbuf; #endif }
static void draw_icon() { gboolean tsin_pho_mode(); if (!tray_icon) return; GdkPixbuf *pix = ((! current_CS) || (current_CS->im_state != HIME_STATE_CHINESE)) ? pixbuf : pixbuf_ch; int w = 0, h = 0; iw = gtk_status_icon_get_size(tray_icon), ih = gtk_status_icon_get_size(tray_icon); cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, iw, ih); cr = cairo_create (cst); gdk_cairo_set_source_color (cr, &red_color_fg); if (pix) { gdk_cairo_set_source_pixbuf (cr, pix, 0, 0); cairo_paint (cr); } else { get_text_w_h(inmd[current_CS->in_method].cname, &w, &h); cairo_move_to (cr, 0, 0); pango_cairo_show_layout (cr, pango); } if (current_CS) { gdk_cairo_set_source_color (cr, &red_color_fg); if (current_shape_mode()) { get_text_w_h(full, &w, &h); cairo_move_to (cr, iw - w, ih - h); pango_cairo_show_layout (cr, pango); } if (current_CS->im_state == HIME_STATE_CHINESE && !tsin_pho_mode()) { gdk_cairo_set_source_color (cr, &blue_color_fg); get_text_w_h(engst, &w, &h); cairo_move_to (cr, 0, 0); pango_cairo_show_layout (cr, pango); } } if (gb_output) { gdk_cairo_set_source_color (cr, &red_color_fg); get_text_w_h(sim, &w, &h); cairo_move_to (cr, 0, ih - h); pango_cairo_show_layout (cr, pango); } cairo_destroy(cr); cr = NULL; GdkPixbuf *icon_pixbuf_output = gdk_pixbuf_get_from_surface(cst, 0, 0, iw, ih); cairo_surface_destroy(cst); cst = NULL; gtk_status_icon_set_from_pixbuf(tray_icon, icon_pixbuf_output); g_object_unref(icon_pixbuf_output); icon_pixbuf_output = NULL; pix = NULL; }
static void moblin_netbook_draw_option (GtkStyle *style, GdkWindow *window, GtkStateType state_type, GtkShadowType shadow_type, GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint x, gint y, gint width, gint height) { cairo_t *cr; gint cx, cy, radius; DEBUG; cr = moblin_netbook_cairo_create (window, area); cairo_set_line_width (cr, 1); cairo_translate (cr, 0.5, 0.5); width--; height--; if (shadow_type == GTK_SHADOW_IN && state_type != GTK_STATE_INSENSITIVE) { state_type = GTK_STATE_SELECTED; } /* define radius and centre coordinates */ if (width % 2) width--; radius = width / 2; cx = x + radius; cy = y + radius; /* fill the background */ gdk_cairo_set_source_color (cr, &style->base[state_type]); cairo_arc (cr, cx, cy, radius, 0, M_PI * 2); cairo_fill (cr); /* draw the border */ cairo_arc (cr, cx, cy, radius, 0, M_PI * 2); moblin_netbook_set_border_color (cr, style, state_type); cairo_stroke (cr); /*** draw check mark ***/ if (shadow_type == GTK_SHADOW_IN) { cairo_arc (cr, cx, cy, radius - 4, 0, M_PI * 2); gdk_cairo_set_source_color (cr, &style->text[state_type]); cairo_fill (cr); } cairo_destroy (cr); }
static gboolean gimp_palette_view_expose (GtkWidget *widget, GdkEventExpose *eevent) { GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (widget); GimpView *view = GIMP_VIEW (widget); if (! gtk_widget_is_drawable (widget)) return FALSE; GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent); if (view->renderer->viewable && pal_view->selected) { GimpViewRendererPalette *renderer; GtkStyle *style = gtk_widget_get_style (widget); GtkAllocation allocation; cairo_t *cr; gint row, col; renderer = GIMP_VIEW_RENDERER_PALETTE (view->renderer); gtk_widget_get_allocation (widget, &allocation); row = pal_view->selected->position / renderer->columns; col = pal_view->selected->position % renderer->columns; cr = gdk_cairo_create (gtk_widget_get_window (widget)); gdk_cairo_region (cr, eevent->region); cairo_clip (cr); cairo_translate (cr, allocation.x, allocation.y); cairo_rectangle (cr, col * renderer->cell_width + 0.5, row * renderer->cell_height + 0.5, renderer->cell_width, renderer->cell_height); cairo_set_line_width (cr, 1.0); gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_SELECTED]); cairo_stroke_preserve (cr); if (gimp_cairo_set_focus_line_pattern (cr, widget)) { gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]); cairo_stroke (cr); } cairo_destroy (cr); } return FALSE; }
gboolean gtk_madcirclebox_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data){ GtkAllocation * allocation; GtkBox *box; gint size; gint radius; gint width; gint height; gint x,y; gint nvis_children; GtkBoxChild *child; GList *children; cairo_t *cr; GtkStyle *style; box = GTK_BOX (widget); allocation = &widget->allocation; nvis_children = 0; children = box->children; while (children) { child = children->data; children = children->next; if (GTK_WIDGET_VISIBLE (child->widget)) { nvis_children += 1; } } width = (allocation->width - GTK_CONTAINER (box)->border_width * 2 ); height = (allocation->height - GTK_CONTAINER (box)->border_width * 2 ); size = MIN(width, height); x = allocation->x + (allocation->width-size)/2; y = allocation->y + (allocation->height-size)/2; radius = size/(1.0+sin(M_PI/(double)nvis_children))/2; style = gtk_widget_get_style(widget); cr = gdk_cairo_create(widget->window); gdk_cairo_set_source_color(cr, &style->fg[0]); cairo_set_line_width (cr, 0.5); cairo_arc(cr, x+size/2, y+size/2, radius, 0, M_PI*2.0); cairo_stroke(cr); gdk_cairo_set_source_color(cr, &style->fg[2]); cairo_arc(cr, x+size/2, y+size/2, radius+0.5, 0, M_PI*2.0); cairo_stroke(cr); cairo_destroy(cr); return FALSE; };
static gboolean avatar_image_expose_event (GtkWidget *widget, GdkEventExpose *event) { GiggleAvatarImagePriv *priv = GET_PRIV (widget); GtkAllocation allocation; GtkRequisition requisition; GtkStyle *style; float xalign, yalign; double x, y; int w, h; cairo_t *cr; gtk_widget_size_request (widget, &requisition); gtk_widget_get_allocation (widget, &allocation); style = gtk_widget_get_style (widget); cr = gdk_cairo_create (event->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); w = requisition.width; h = requisition.height; gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign); cairo_translate (cr, (int) ((allocation.width - w) * xalign), (int) ((allocation.height - h) * yalign)); rounded_rectangle (cr, 0.5, 0.5, w - 1, h - 1, MIN (w, h) * 0.2); gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]); cairo_fill_preserve (cr); if (priv->pixbuf) { x = (w - gdk_pixbuf_get_width (priv->pixbuf)) * 0.5; y = (h - gdk_pixbuf_get_height (priv->pixbuf)) * 0.5; gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x, y); cairo_fill_preserve (cr); } gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]); cairo_set_line_width (cr, 1); cairo_stroke (cr); cairo_destroy (cr); return TRUE; }
static gint mcus_led_expose_event (GtkWidget *widget, GdkEventExpose *event) { cairo_t *cr; MCUSLEDPrivate *priv; GdkColor fill, stroke; GtkAllocation allocation; GtkStyle *style; g_return_val_if_fail (event != NULL, FALSE); g_return_val_if_fail (MCUS_IS_LED (widget), FALSE); priv = MCUS_LED (widget)->priv; /* Prepare our custom colours */ fill.red = 29555; /* Tango's medium "chameleon" --- 73d216 */ fill.green = 53970; fill.blue = 5654; stroke.red = 34952; /* Tango's lightest "aluminium" --- 888a85 */ stroke.green = 35466; stroke.blue = 34181; /* Draw! */ cr = gdk_cairo_create (gtk_widget_get_window (widget)); /* Clip to the exposed area */ cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip (cr); style = gtk_widget_get_style (widget); cairo_set_line_width (cr, style->xthickness); /* Draw the LED */ gtk_widget_get_allocation (widget, &allocation); cairo_arc (cr, allocation.x + allocation.width / 2.0, allocation.y + allocation.height / 2.0, priv->render_size / 2.0, 0, 2 * M_PI); gdk_cairo_set_source_color (cr, priv->enabled ? &fill : &stroke); cairo_fill_preserve (cr); gdk_cairo_set_source_color (cr, &stroke); cairo_stroke (cr); cairo_destroy (cr); return TRUE; }
void VerticalToolHandler::paint(cairo_t * cr, GdkRectangle * rect, double zoom) { XOJ_CHECK_TYPE(VerticalToolHandler); GdkColor selectionColor = view->getSelectionColor(); cairo_set_line_width(cr, 1); gdk_cairo_set_source_color(cr, &selectionColor); double y; double height; if (this->startY < this->endY) { y = this->startY; height = this->endY - this->startY; } else { y = this->endY; height = this->startY - this->endY; } cairo_rectangle(cr, 0, y * zoom, this->page.getWidth() * zoom, height * zoom); cairo_stroke_preserve(cr); cairo_set_source_rgba(cr, selectionColor.red / 65536.0, selectionColor.green / 65536.0, selectionColor.blue / 65536.0, 0.3); cairo_fill(cr); cairo_set_source_surface(cr, this->crBuffer, 0, this->endY * zoom); cairo_paint(cr); }
static gboolean ghid_trackball_expose (GtkWidget * widget, GdkEventExpose * ev) { cairo_t *cr; cairo_pattern_t *pattern; GtkAllocation allocation; GdkColor color; double radius; cr = gdk_cairo_create (gtk_widget_get_window (widget)); /* set a clip region for the expose event */ cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); cairo_clip (cr); gtk_widget_get_allocation (widget, &allocation); radius = (MIN (allocation.width, allocation.height) - 5) / 2.; pattern = cairo_pattern_create_radial (2 * radius * 0.8, 2 * radius * 0.3, 0., 2 * radius * 0.50, 2 * radius * 0.50, 2 * radius * 0.71); color = widget->style->fg[GTK_WIDGET_STATE (widget)]; cairo_pattern_add_color_stop_rgb (pattern, 0.0, (color.red / 65535. * 0.5 + 4.5) / 5., (color.green / 65535. * 0.5 + 4.5) / 5., (color.blue / 65535. * 0.5 + 4.5) / 5.); cairo_pattern_add_color_stop_rgb (pattern, 0.2, (color.red / 65535. * 1.5 + 3.7) / 5., (color.green / 65535. * 1.5 + 3.7) / 5., (color.blue / 65535. * 1.5 + 3.7) / 5.); cairo_pattern_add_color_stop_rgb (pattern, 1.0, (color.red / 65535. * 5. + 0.) / 5., (color.green / 65535. * 5. + 0.) / 5., (color.blue / 65535. * 5. + 0.) / 5.); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_save (cr); cairo_translate (cr, allocation.width / 2., allocation.height / 2.); cairo_scale (cr, radius, radius); cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI); cairo_restore (cr); cairo_fill_preserve (cr); gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_WIDGET_STATE (widget)]); cairo_set_line_width (cr, 0.4); cairo_stroke (cr); cairo_destroy (cr); return FALSE; }
static GdkPixmap * tile_pixmap (GdkPixmap *pixmap, int width, int height) { GdkPixmap *copy; cairo_t *cr; copy = gdk_pixmap_new (pixmap, width, height, pixmap == NULL? 24 : -1); cr = gdk_cairo_create (copy); if (pixmap != NULL) { cairo_pattern_t *pattern; gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0); pattern = cairo_get_source (cr); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); } else { GtkStyle *style; style = gtk_widget_get_default_style (); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); } cairo_paint (cr); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { g_object_unref (copy); copy = NULL; } cairo_destroy (cr); return copy; }
static gboolean colorlabel_drawing_area_expose_event_cb (GtkWidget *widget, GdkEventExpose *expose, gpointer data) { cairo_t *cr; GdkWindow *drawable = gtk_widget_get_window(widget); GtkAllocation allocation; gulong c = (gulong) GPOINTER_TO_INT(data); GdkColor color; INTCOLOR_TO_GDKCOLOR(c, color) gdk_colormap_alloc_color(gtk_widget_get_colormap(widget), &color, FALSE, TRUE); cr = gdk_cairo_create(drawable); gtk_widget_get_allocation(widget, &allocation); cairo_set_source_rgb(cr, 0., 0., 0.); cairo_rectangle(cr, 0, 0, allocation.width - 1, allocation.height - 1); cairo_stroke(cr); gdk_cairo_set_source_color(cr, &color); cairo_rectangle(cr, 1, 1, allocation.width - 2, allocation.height - 2); cairo_fill(cr); cairo_destroy(cr); return FALSE; }
static gboolean paint_lines(GtkWidget *widget, cairo_t * cr, IBusHandwriteEngine * engine) { GtkStyleContext* stylectx; LineStroke cl; int i; puts(__func__); /* render frame border */ stylectx = gtk_widget_get_style_context(widget); gtk_render_frame(stylectx, cr, 0, 0, WIDTH, HEIGHT); /* set line attributes */ cairo_set_line_width(cr,3.0); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND); gdk_cairo_set_source_color (cr, engine->color); //已经录入的笔画 for (i = 0; i < engine->engine->strokes->len ; i++ ) { printf("drawing %d th line, total %d\n",i,engine->engine->strokes->len); cl = g_array_index(engine->engine->strokes,LineStroke,i); _draw_lines(cr, &cl); } //当下笔画 if ( engine->currentstroke.segments && engine->currentstroke.points ) _draw_lines(cr, &(engine->currentstroke)); return TRUE; }
static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard *wb, int x, int y, int color, int size) { PidginWhiteboard *gtkwb = wb->ui_data; GtkWidget *widget = gtkwb->drawing_area; GdkPixmap *pixmap = gtkwb->pixmap; cairo_t *gfx_con = g_object_get_data(G_OBJECT(pixmap), "cairo-context"); GdkColor col; /* Interpret and convert color */ pidgin_whiteboard_rgb24_to_rgb48(color, &col); gdk_cairo_set_source_color(gfx_con, &col); /* Draw a circle */ cairo_arc(gfx_con, x, y, size / 2.0, 0.0, 2.0 * M_PI); cairo_fill(gfx_con); gtk_widget_queue_draw_area(widget, x - size / 2, y - size / 2, size, size); }
static gboolean handle_draw_cb (GtkWidget * widget, cairo_t * cr, gpointer user_data) { GstVideoRectangle *r = &anim_state.rect; GtkStyle *style; int width, height; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); style = gtk_widget_get_style (widget); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); /* we should only redraw outside of the video rect! */ cairo_rectangle (cr, 0, 0, r->x, height); cairo_rectangle (cr, r->x + r->w, 0, width - (r->x + r->w), height); cairo_rectangle (cr, 0, 0, width, r->y); cairo_rectangle (cr, 0, r->y + r->h, width, height - (r->y + r->h)); cairo_fill (cr); if (verbose) { g_print ("draw(%p)\n", widget); } gst_video_overlay_expose (anim_state.overlay); return FALSE; }
static void set_foreground(GdkColor *color, int status) { int num_app_shells = get_num_shells(); int i, num; GdkPoint *p; num = numpoints[status]; p = polyptr[status]; for (i = 0; i < num_app_shells; i++) { tape_status_widget *ts = &app_shells[i].tape_status; if (ts) { cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(ts->control)); if (cr) { gdk_cairo_set_source_color(cr, color); cairo_translate(cr, 0, (gtk_widget_get_allocated_height(ts->control) - CTRL_HEIGHT) / 2); if (num) { draw_polygon(cr, p, num); } else { cairo_arc(cr, CTRL_WIDTH / 2, CTRL_HEIGHT / 2, (CTRL_HEIGHT / 2) - 1, 0, 360.0f * (M_PI / 180.0f)); } cairo_fill (cr); cairo_destroy(cr); } } } }
static gboolean pidgin_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) { PidginWhiteboard *gtkwb = (PidginWhiteboard*)data; GdkPixmap *pixmap = gtkwb->pixmap; cairo_t *cr; if (pixmap) { cr = g_object_get_data(G_OBJECT(pixmap), "cairo-context"); if (cr) cairo_destroy(cr); g_object_unref(pixmap); } pixmap = gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1); gtkwb->pixmap = pixmap; cr = gdk_cairo_create(GDK_DRAWABLE(pixmap)); g_object_set_data(G_OBJECT(pixmap), "cairo-context", cr); gdk_cairo_set_source_color(cr, &widget->style->white); cairo_rectangle(cr, 0, 0, widget->allocation.width, widget->allocation.height); cairo_fill(cr); return TRUE; }
static void draw_cursor_rectangle (HTMLEngine *e, gint x1, gint y1, gint x2, gint y2, GdkColor *on_color, GdkColor *off_color, gint offset) { cairo_t *cr; const double dashes[2] = { 1, 3 }; gint ndash = G_N_ELEMENTS (dashes); if (x1 > x2 || y1 > y2 || !e->window) return; /* FIXME: what is the off color for? */ cr = gdk_cairo_create (e->window); gdk_cairo_set_source_color (cr, on_color); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_set_dash (cr, dashes, ndash, offset); cairo_rectangle (cr, x1 - 0.5, y1 - 0.5, x2 - x1 + 1, y2 - y1 + 1); cairo_set_line_width (cr, 1.0); cairo_stroke (cr); cairo_destroy (cr); }
/* Handler for expose_event on drawing area. */ static gboolean desk_expose_event(GtkWidget * widget, GdkEventExpose * event, PagerDesk * d) { GtkStyle * style = gtk_widget_get_style(widget); if (d->pixmap != NULL) { cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget)); gdk_cairo_region(cr, event->region); cairo_clip(cr); /* Recompute the pixmap if needed. */ if (d->dirty) { d->dirty = FALSE; PagerPlugin * pg = d->pg; /* Erase the pixmap. */ if (d->pixmap != NULL) { //GtkWidget * widget = GTK_WIDGET(d->da); cairo_t *cr0 = cairo_create(d->pixmap); gdk_cairo_set_source_color(cr0, ((d->desktop_number == d->pg->current_desktop) ? &style->dark[GTK_STATE_SELECTED] : &style->dark[GTK_STATE_NORMAL])); cairo_paint(cr0); check_cairo_status(cr0); cairo_destroy(cr0); } /* Draw tasks onto the pixmap. */ int j; for (j = 0; j < pg->client_count; j++) task_update_pixmap(pg->tasks_in_stacking_order[j], d); } /* Draw the requested part of the pixmap onto the drawing area. */ GtkAllocation allocation; gtk_widget_get_allocation(GTK_WIDGET(widget), &allocation); gdk_cairo_set_source_color(cr, &style->fg[GTK_WIDGET_STATE(widget)]); cairo_set_source_surface(cr, d->pixmap, 0, 0); cairo_paint(cr); check_cairo_status(cr); cairo_destroy(cr); } return FALSE; }
/* Handle exposure events for the color picker's drawing area */ static gboolean draw (GtkWidget *widget, cairo_t *cr, gpointer data) { MateColorButton *color_button = MATE_COLOR_BUTTON (data); cairo_pattern_t *checkered; if (mate_color_button_has_alpha (color_button)) { cairo_save (cr); cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK); cairo_paint (cr); cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT); cairo_scale (cr, CHECK_SIZE, CHECK_SIZE); checkered = mate_color_button_get_checkered (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); cairo_restore (cr); cairo_set_source_rgba (cr, color_button->priv->color.red / 65535., color_button->priv->color.green / 65535., color_button->priv->color.blue / 65535., color_button->priv->alpha / 65535.); } else { gdk_cairo_set_source_color (cr, &color_button->priv->color); } cairo_paint (cr); if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button))) { gdk_cairo_set_source_color (cr, >k_widget_get_style (GTK_WIDGET(color_button))->bg[GTK_STATE_INSENSITIVE]); checkered = mate_color_button_get_checkered (); cairo_mask (cr, checkered); cairo_pattern_destroy (checkered); } return FALSE; }
void aff_element_draw (AffElement *elem, gboolean selected, gint width, gint height, cairo_t *cr, GdkColor *color, PangoLayout *layout) { PangoRectangle rect; gint i; pango_layout_set_text (layout, elem->name, -1); pango_layout_get_pixel_extents (layout, NULL, &rect); gdk_cairo_set_source_color (cr, color); cairo_move_to (cr, elem->v.x * width - rect.width / 2, elem->v.y * width + rect.height / 2); pango_cairo_show_layout (cr, layout); cairo_fill (cr); cairo_set_line_width (cr, 1.0); if (elem->click_boundary != elem->draw_boundary) { cairo_move_to (cr, elem->click_boundary->points[0].x, elem->click_boundary->points[0].y); for (i = 1; i < elem->click_boundary->npoints; i++) cairo_line_to (cr, elem->click_boundary->points[i].x, elem->click_boundary->points[i].y); cairo_close_path (cr); cairo_stroke (cr); } if (selected) cairo_set_line_width (cr, 3.0); cairo_move_to (cr, elem->draw_boundary->points[0].x, elem->draw_boundary->points[0].y); for (i = 1; i < elem->draw_boundary->npoints; i++) cairo_line_to (cr, elem->draw_boundary->points[i].x, elem->draw_boundary->points[i].y); cairo_close_path (cr); cairo_stroke (cr); }