static void gd_stack_draw_slide (GtkWidget *widget, cairo_t *cr) { GdStack *stack = GD_STACK (widget); GdStackPrivate *priv = stack->priv; GtkAllocation allocation; int x = 0; gtk_widget_get_allocation (widget, &allocation); x = get_bin_window_x (stack, &allocation); if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_LEFT) x -= allocation.width; if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_RIGHT) x += allocation.width; if (priv->last_visible_surface) { cairo_save (cr); cairo_set_source_surface (cr, priv->last_visible_surface, x, 0); cairo_paint (cr); cairo_restore (cr); } gtk_container_propagate_draw (GTK_CONTAINER (stack), priv->visible_child->widget, cr); }
static int eel_wrap_table_draw (GtkWidget *widget, cairo_t *cr) { EelWrapTable *wrap_table; GList *iterator; g_assert (EEL_IS_WRAP_TABLE (widget)); g_assert (gtk_widget_get_realized (widget)); wrap_table = EEL_WRAP_TABLE (widget); for (iterator = wrap_table->details->children; iterator; iterator = iterator->next) { g_assert (GTK_IS_WIDGET (iterator->data)); gtk_container_propagate_draw (GTK_CONTAINER (widget), GTK_WIDGET (iterator->data), cr); } /*Redraw the table once and only once to ensure it is displayed */ if (wrap_table->details->drawn == FALSE){ gtk_widget_queue_allocate (GTK_WIDGET(widget)); wrap_table->details->drawn = TRUE; } return FALSE; }
eel_wrap_table_expose_event (GtkWidget *widget, GdkEventExpose *event) #endif { EelWrapTable *wrap_table; GList *iterator; g_assert (EEL_IS_WRAP_TABLE (widget)); g_assert (gtk_widget_get_realized (widget)); #if !GTK_CHECK_VERSION (3, 0, 0) g_assert (event != NULL); #endif wrap_table = EEL_WRAP_TABLE (widget); for (iterator = wrap_table->details->children; iterator; iterator = iterator->next) { g_assert (GTK_IS_WIDGET (iterator->data)); #if GTK_CHECK_VERSION (3, 0, 0) gtk_container_propagate_draw (GTK_CONTAINER (widget), GTK_WIDGET (iterator->data), cr); #else gtk_container_propagate_expose (GTK_CONTAINER (widget), GTK_WIDGET (iterator->data), event); #endif } return FALSE; }
static void gd_stack_draw_crossfade (GtkWidget *widget, cairo_t *cr) { GdStack *stack = GD_STACK (widget); GdStackPrivate *priv = stack->priv; if (priv->last_visible_surface) { cairo_set_source_surface (cr, priv->last_visible_surface, priv->last_visible_surface_allocation.x, priv->last_visible_surface_allocation.y); cairo_set_operator (cr, CAIRO_OPERATOR_ADD); cairo_paint_with_alpha (cr, MAX (1.0 - priv->transition_pos, 0)); } cairo_push_group (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); gtk_container_propagate_draw (GTK_CONTAINER (stack), priv->visible_child->widget, cr); cairo_pop_group_to_source (cr); cairo_set_operator (cr, CAIRO_OPERATOR_ADD); cairo_paint_with_alpha (cr, priv->transition_pos); }
static gboolean panel_toggle_button_draw (GtkWidget *widget, cairo_t *cr) { GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget)); GtkStateType state_type; GtkShadowType shadow_type; GtkAllocation allocation; GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStateFlags flags = 0; state_type = gtk_widget_get_state (widget); /* FIXME: someone make this layout work nicely for all themes * Currently I'm trying to imitate the volume applet's widget */ if (gtk_toggle_button_get_inconsistent (GTK_TOGGLE_BUTTON (widget))) { if (state_type == GTK_STATE_ACTIVE) state_type = GTK_STATE_NORMAL; shadow_type = GTK_SHADOW_ETCHED_IN; } else { shadow_type = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) state_type = GTK_STATE_SELECTED; /* FIXME: better detail? */ gtk_widget_get_allocation (widget, &allocation); gtk_style_context_add_class (context, "togglebutton"); switch (state_type) { case GTK_STATE_PRELIGHT: flags |= GTK_STATE_FLAG_PRELIGHT; break; case GTK_STATE_SELECTED: flags |= GTK_STATE_FLAG_SELECTED; break; case GTK_STATE_INSENSITIVE: flags |= GTK_STATE_FLAG_INSENSITIVE; break; case GTK_STATE_ACTIVE: flags |= GTK_STATE_FLAG_ACTIVE; break; case GTK_STATE_FOCUSED: flags |= GTK_STATE_FLAG_FOCUSED; break; case GTK_STATE_NORMAL: case GTK_STATE_INCONSISTENT: default: break; } gtk_style_context_set_state (context, flags); gtk_render_background (context, cr, (gdouble) allocation.x, (gdouble) allocation.y, (gdouble) allocation.width, (gdouble) allocation.height); (void) shadow_type; if (child) gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr); return FALSE; }
static gboolean gtk_rotated_bin_draw (GtkWidget *widget, cairo_t *cr) { GtkRotatedBin *bin = GTK_ROTATED_BIN (widget); GdkWindow *window; gdouble s, c; gdouble w, h; window = gtk_widget_get_window (widget); if (gtk_cairo_should_draw_window (cr, window)) { cairo_surface_t *surface; GtkAllocation child_area; if (bin->child && gtk_widget_get_visible (bin->child)) { surface = gdk_offscreen_window_get_surface (bin->offscreen_window); gtk_widget_get_allocation (bin->child, &child_area); /* transform */ s = sin (bin->angle); c = cos (bin->angle); w = c * child_area.width + s * child_area.height; h = s * child_area.width + c * child_area.height; cairo_translate (cr, (w - child_area.width) / 2, (h - child_area.height) / 2); cairo_translate (cr, child_area.width / 2, child_area.height / 2); cairo_rotate (cr, bin->angle); cairo_translate (cr, -child_area.width / 2, -child_area.height / 2); /* clip */ cairo_rectangle (cr, 0, 0, gdk_window_get_width (bin->offscreen_window), gdk_window_get_height (bin->offscreen_window)); cairo_clip (cr); /* paint */ cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); } } if (gtk_cairo_should_draw_window (cr, bin->offscreen_window)) { gtk_render_background (gtk_widget_get_style_context (widget), cr, 0, 0, gdk_window_get_width (bin->offscreen_window), gdk_window_get_height (bin->offscreen_window)); if (bin->child) gtk_container_propagate_draw (GTK_CONTAINER (widget), bin->child, cr); } return FALSE; }
static gboolean gstyle_slidein_draw (GtkWidget *widget, cairo_t *cr) { GstyleSlidein *self = (GstyleSlidein *)widget; GtkStyleContext *context; GtkAllocation shade_box; GtkWidget *child; GdkRGBA rgba; g_assert (GSTYLE_IS_SLIDEIN (self)); g_assert (cr != NULL); /* To draw the shade effect in between the regular child and the slides, * we bypass gtk_event_box_draw (we use a windowless one so not a problem), * and provide your own container draw implementation. */ child = gtk_bin_get_child (GTK_BIN (self)); if (child == NULL) return GDK_EVENT_STOP; gtk_container_propagate_draw (GTK_CONTAINER (self), child, cr); if (self->offset > 0.0) { context = gtk_widget_get_style_context (widget); gtk_style_context_save (context); gtk_style_context_add_class (context, "shade"); gtk_style_context_get_color (context, gtk_style_context_get_state (context), &rgba); gtk_style_context_restore (context); rgba.alpha = rgba.alpha * self->offset; /* We shade the whole surface in case of slide tranparency */ gtk_widget_get_allocated_size (widget, &shade_box, NULL); cairo_rectangle (cr, shade_box.x, shade_box.y, shade_box.width, shade_box.height); gdk_cairo_set_source_rgba (cr, &rgba); cairo_fill (cr); } if (self->overlay_child != NULL) gtk_container_propagate_draw (GTK_CONTAINER (self), self->overlay_child, cr); return GDK_EVENT_STOP; }
static void draw_child (GtkWidget *child, gpointer client_data) { struct { GtkWidget *container; cairo_t *cr; } *data = client_data; gtk_container_propagate_draw (GTK_CONTAINER (data->container), child, data->cr); }
static gboolean gd_stack_draw (GtkWidget *widget, cairo_t *cr) { GdStack *stack = GD_STACK (widget); GdStackPrivate *priv = stack->priv; cairo_t *pattern_cr; if (priv->visible_child) { if (priv->transition_pos < 1.0) { if (priv->last_visible_surface == NULL && priv->last_visible_child != NULL) { gtk_widget_get_allocation (priv->last_visible_child->widget, &priv->last_visible_surface_allocation); priv->last_visible_surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), CAIRO_CONTENT_COLOR_ALPHA, priv->last_visible_surface_allocation.width, priv->last_visible_surface_allocation.height); pattern_cr = cairo_create (priv->last_visible_surface); /* We don't use propagate_draw here, because we don't want to apply the bin_window offset */ gtk_widget_draw (priv->last_visible_child->widget, pattern_cr); cairo_destroy (pattern_cr); } switch (priv->transition_type) { case GD_STACK_TRANSITION_TYPE_CROSSFADE: gd_stack_draw_crossfade (widget, cr); break; case GD_STACK_TRANSITION_TYPE_SLIDE_LEFT: case GD_STACK_TRANSITION_TYPE_SLIDE_RIGHT: gd_stack_draw_slide (widget, cr); break; default: g_assert_not_reached (); } } else if (gtk_cairo_should_draw_window (cr, priv->bin_window)) gtk_container_propagate_draw (GTK_CONTAINER (stack), priv->visible_child->widget, cr); } return TRUE; }
static gboolean budgie_panel_draw(GtkWidget *widget, cairo_t *cr, gpointer userdata) { GtkStyleContext *style; GtkAllocation alloc; gtk_widget_get_allocation(widget, &alloc); style = gtk_widget_get_style_context(widget); gtk_render_background(style, cr, 0, 0, alloc.width, alloc.height); gtk_render_frame(style, cr, 0, 0, alloc.width, alloc.height); if (GTK_IS_BIN(widget)) { gtk_container_propagate_draw(GTK_CONTAINER(widget), gtk_bin_get_child(GTK_BIN(widget)), cr); return TRUE; } return FALSE; }
static gboolean msd_osd_window_draw (GtkWidget *widget, cairo_t *cr) { MsdOsdWindow *window; GtkWidget *child; window = MSD_OSD_WINDOW (widget); if (window->priv->is_composited) draw_when_composited (widget, cr); else draw_when_not_composited (widget, cr); child = gtk_bin_get_child (GTK_BIN (window)); if (child) gtk_container_propagate_draw (GTK_CONTAINER (window), child, cr); return FALSE; }
/** * This draws the task title. Drawing is only effective if the window for this * task title is maximized */ static gboolean on_draw ( GtkWidget *widget, cairo_t *cr, gpointer userdata) { if (gtk_widget_get_state_flags (widget) == GTK_STATE_FLAG_ACTIVE) { //window is either maximized or we are on the desktop GtkStyleContext *context = gtk_widget_get_style_context (widget); gtk_render_frame ( context, cr, 0, 0, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget) ); } gtk_container_propagate_draw (GTK_CONTAINER (widget), gtk_bin_get_child (GTK_BIN (widget)), cr ); return FALSE; }
static gboolean budgie_popover_draw(GtkWidget *widget, cairo_t *cr, gboolean draw) { BudgiePopover *self = BUDGIE_POPOVER(widget); GtkStyleContext *style; GtkAllocation alloc; GtkPositionType gap_side; GdkRGBA color; gdouble x, y, tail_height, gap_width; gdouble margin, width, height, gap1, gap2; x = 0; y = 0; tail_height = 12; gap_width = 24; margin = 11; x += margin; y += margin; style = gtk_widget_get_style_context(widget); gtk_style_context_add_class(style, GTK_STYLE_CLASS_FRAME); gtk_widget_get_allocation(widget, &alloc); /* Have parent class do drawing, so we gain shadows */ ((GtkWidgetClass*)budgie_popover_parent_class)->draw(widget, cr); /* Remove height of tail, and margin, from our rendered size */ width = alloc.width; height = alloc.height - tail_height; height -= margin; width -= margin*2; cairo_set_operator(cr, CAIRO_OPERATOR_OVER); gap1 = (alloc.width/2)-(gap_width/2); gap1 = self->widg_x; gap2 = gap1 + gap_width; gap2 -= margin; gap_side = self->top == TRUE ? GTK_POS_TOP : GTK_POS_BOTTOM; /* Render a gap in the bottom center for our arrow */ gtk_render_frame_gap(style, cr, x, y, width, height, gap_side, gap1, gap2); /* Fill in the background (pre-clip) */ gtk_render_background(style, cr, x, y, width, height); /* Clip to the tail, fill in the arrow background */ cairo_save(cr); if (self->top) budgie_tail_path(cr, gap1, gap_width, y-margin, tail_height, self->top); else budgie_tail_path(cr, gap1, gap_width, height+margin, tail_height, self->top); cairo_clip(cr); if (self->top) gtk_render_background(style, cr, x, y-tail_height, alloc.width, alloc.height); else gtk_render_background(style, cr, x, y, alloc.width, alloc.height); cairo_restore(cr); /* Draw in the border */ gtk_style_context_get_border_color(style, gtk_widget_get_state_flags(widget), &color); gdk_cairo_set_source_rgba(cr, &color); cairo_set_line_width(cr, 1); if (self->top) budgie_tail_path(cr, gap1, gap_width, y-margin, tail_height, self->top); else budgie_tail_path(cr, gap1, gap_width, height+margin, tail_height, self->top); cairo_stroke(cr); /* Draw children */ gtk_container_propagate_draw(GTK_CONTAINER(widget), gtk_bin_get_child(GTK_BIN(widget)), cr); return TRUE; }
static gboolean widget_overlay_draw (GtkWidget *widget, cairo_t *cr) { WidgetOverlay *ovl = WIDGET_OVERLAY (widget); GdkWindow *window; GtkAllocation area; gtk_widget_get_allocation (widget, &area); window = gtk_widget_get_window (widget); if (gtk_cairo_should_draw_window (cr, window)) { GList *list; for (list = ovl->priv->children; list; list = list->next) { ChildData *cd = (ChildData*) list->data; if (gtk_widget_get_visible (cd->child)) { cairo_surface_t *surface; GtkAllocation child_area; double x, y; gtk_widget_get_allocation (cd->child, &child_area); child_area.width *= cd->scale; child_area.height *= cd->scale; switch (cd->halign) { case WIDGET_OVERLAY_ALIGN_FILL: case WIDGET_OVERLAY_ALIGN_START: x = 0; break; case WIDGET_OVERLAY_ALIGN_END: x = area.width - child_area.width; break; case WIDGET_OVERLAY_ALIGN_CENTER: x = (area.width - child_area.width) / 2.; break; } switch (cd->valign) { case WIDGET_OVERLAY_ALIGN_FILL: case WIDGET_OVERLAY_ALIGN_START: y = 0; break; case WIDGET_OVERLAY_ALIGN_END: y = area.height - child_area.height; break; case WIDGET_OVERLAY_ALIGN_CENTER: y = (area.height - child_area.height) / 2.; break; } surface = gdk_offscreen_window_get_surface (cd->offscreen_window); if (cd->scale == 1.) { cairo_set_source_surface (cr, surface, x, y); cairo_paint_with_alpha (cr, cd->alpha); } else { cairo_save (cr); cairo_scale (cr, cd->scale, cd->scale); cairo_set_source_surface (cr, surface, x/cd->scale, y/cd->scale); cairo_paint_with_alpha (cr, cd->alpha); cairo_restore (cr); } cd->x = x; cd->y = y; } if (list->next && ((ChildData*) list->next->data == ovl->priv->scale_child) && (ovl->priv->scale_child->alpha > 0.)) { cairo_set_source_rgba (cr, 0., 0., 0., .3); cairo_rectangle (cr, 0, 0, area.width, area.height); cairo_fill (cr); } } } else { GList *list; for (list = ovl->priv->children; list; list = list->next) { ChildData *cd = (ChildData*) list->data; if (gtk_cairo_should_draw_window (cr, cd->offscreen_window)) gtk_container_propagate_draw (GTK_CONTAINER (widget), cd->child, cr); } } return TRUE; }
static gboolean gtk_bubble_window_draw (GtkWidget *widget, cairo_t *cr) { GtkStyleContext *context; GtkAllocation allocation; GtkWidget *child; GtkBorder border; GdkRGBA border_color; gint rect_x1, rect_x2, rect_y1, rect_y2; gint initial_x, initial_y, final_x, final_y; gint gap_start, gap_end; GtkPositionType gap_side; GtkStateFlags state; context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_widget_get_allocation (widget, &allocation); if (gtk_widget_is_composited (widget)) { cairo_save (cr); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_paint (cr); cairo_restore (cr); } gtk_bubble_window_get_rect_coords (GTK_BUBBLE_WINDOW (widget), &rect_x1, &rect_y1, &rect_x2, &rect_y2); /* Render the rect background */ gtk_render_background (context, cr, rect_x1, rect_y1, rect_x2 - rect_x1, rect_y2 - rect_y1); gtk_bubble_window_get_gap_coords (GTK_BUBBLE_WINDOW (widget), &initial_x, &initial_y, NULL, NULL, &final_x, &final_y, &gap_side); if (POS_IS_VERTICAL (gap_side)) { gap_start = initial_x; gap_end = final_x; } else { gap_start = initial_y; gap_end = final_y; } /* Now render the frame, without the gap for the arrow tip */ gtk_render_frame_gap (context, cr, rect_x1, rect_y1, rect_x2 - rect_x1, rect_y2 - rect_y1, gap_side, gap_start, gap_end); /* Clip to the arrow shape */ cairo_save (cr); gtk_bubble_window_apply_tail_path (GTK_BUBBLE_WINDOW (widget), cr); cairo_clip (cr); /* Render the arrow background */ gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); /* Render the border of the arrow tip */ gtk_style_context_get_border (context, state, &border); if (border.bottom > 0) { gtk_style_context_get_border_color (context, state, &border_color); gtk_bubble_window_apply_tail_path (GTK_BUBBLE_WINDOW (widget), cr); gdk_cairo_set_source_rgba (cr, &border_color); cairo_set_line_width (cr, border.bottom); cairo_stroke (cr); } /* We're done */ cairo_restore (cr); child = gtk_bin_get_child (GTK_BIN (widget)); if (child) gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr); return TRUE; }
static gboolean gtk_offscreen_box_draw (GtkWidget *widget, cairo_t *cr) { GtkOffscreenBox *offscreen_box = GTK_OFFSCREEN_BOX (widget); GdkWindow *window; window = gtk_widget_get_window (widget); if (gtk_cairo_should_draw_window (cr, window)) { cairo_surface_t *surface; GtkAllocation child_area; if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1)) { surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); gtk_widget_get_allocation (offscreen_box->child1, &child_area); cairo_translate (cr, 0, child_area.height); } if (offscreen_box->child2 && gtk_widget_get_visible (offscreen_box->child2)) { surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2); gtk_widget_get_allocation (offscreen_box->child2, &child_area); /* transform */ cairo_translate (cr, child_area.width / 2, child_area.height / 2); cairo_rotate (cr, offscreen_box->angle); cairo_translate (cr, -child_area.width / 2, -child_area.height / 2); /* paint */ cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); } } else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window1)) { gtk_render_background (gtk_widget_get_style_context (widget), cr, 0, 0, gdk_window_get_width (offscreen_box->offscreen_window1), gdk_window_get_height (offscreen_box->offscreen_window1)); if (offscreen_box->child1) gtk_container_propagate_draw (GTK_CONTAINER (widget), offscreen_box->child1, cr); } else if (gtk_cairo_should_draw_window (cr, offscreen_box->offscreen_window2)) { gtk_render_background (gtk_widget_get_style_context (widget), cr, 0, 0, gdk_window_get_width (offscreen_box->offscreen_window2), gdk_window_get_height (offscreen_box->offscreen_window2)); if (offscreen_box->child2) gtk_container_propagate_draw (GTK_CONTAINER (widget), offscreen_box->child2, cr); } return FALSE; }