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 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_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; }