Esempio n. 1
0
static Bool
canvas_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
 GtkAllocation allocation;
 cairo_text_extents_t te;
 //printf("canvas_configure_event\n");

 gtk_widget_get_allocation(widget,&allocation);
 vdevice.sizeX = 1;
 vdevice.sizeY = 1;
 vdevice.minVx = vdevice.minVy = 0;
 vdevice.maxVx = vdevice.sizeSx = allocation.width;
 vdevice.maxVy = vdevice.sizeSy = allocation.height;
 vdevice.depth = 3;
 if (VGUI.cr!=NULL) {
  cairo_destroy (VGUI.cr);
  cairo_surface_destroy (VGUI.surface);
 }
 VGUI.surface= gdk_window_create_similar_surface (gtk_widget_get_window (VGUI.canvas),
  CAIRO_CONTENT_COLOR, vdevice.sizeSx, vdevice.sizeSy);
 VGUI.cr = cairo_create(VGUI.surface);
 cairo_set_antialias(VGUI.cr,VGUI.antialias);
 my_set_font(VGUI.cr);
 cairo_text_extents (VGUI.cr, "A", &te);
 vdevice.hheight = te.height;
 vdevice.hwidth = te.x_advance;
 VGUI.line_width=1;
 //printf("vdevice address=%ld, vdevice.sizeSx=%d, vdevice.sizeSy=%d\n", (long)&vdevice,  vdevice.sizeSx, vdevice.sizeSy);
 Keyboard_Buffer_push('');	// queue a redraw command
 notify_input();
 return TRUE;
}
Esempio n. 2
0
/* Create a new surface of the appropriate size to store our scribbles */
static gboolean
scribble_configure_event (GtkWidget         *widget,
                          GdkEventConfigure *event,
                          gpointer           data)
{
  GtkAllocation allocation;
  cairo_t *cr;

  if (surface)
    cairo_surface_destroy (surface);

  gtk_widget_get_allocation (widget, &allocation);
  surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
                                               CAIRO_CONTENT_COLOR,
                                               allocation.width,
                                               allocation.height);

  /* Initialize the surface to white */
  cr = cairo_create (surface);

  cairo_set_source_rgb (cr, 1, 1, 1);
  cairo_paint (cr);

  cairo_destroy (cr);

  /* We've handled the configure event, no need for further processing. */
  return TRUE;
}
Esempio n. 3
0
static void
maybe_update_shape (GtkTooltip *tooltip)
{
  cairo_t *cr;
  cairo_surface_t *surface;
  cairo_region_t *region;

  /* fallback to XShape only for non-composited clients */
  if (gtk_widget_is_composited (tooltip->window))
    {
      gtk_widget_shape_combine_region (tooltip->window, NULL);
      return;
    }

  surface = gdk_window_create_similar_surface (gtk_widget_get_window (tooltip->window),
                                               CAIRO_CONTENT_COLOR_ALPHA,
                                               gtk_widget_get_allocated_width (tooltip->window),
                                               gtk_widget_get_allocated_height (tooltip->window));

  cr = cairo_create (surface);
  paint_background_and_frame (tooltip, cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  gtk_widget_shape_combine_region (tooltip->window, region);

  cairo_surface_destroy (surface);
  cairo_region_destroy (region);
}
Esempio n. 4
0
static gint
load_graph_configure (GtkWidget *widget, GdkEventConfigure *event,
		      gpointer data_ptr)
{
    GtkAllocation allocation;
    LoadGraph *c = (LoadGraph *) data_ptr;
    
    load_graph_unalloc (c);

    gtk_widget_get_allocation (c->disp, &allocation);

    c->draw_width = allocation.width;
    c->draw_height = allocation.height;
    c->draw_width = MAX (c->draw_width, 1);
    c->draw_height = MAX (c->draw_height, 1);
    
    load_graph_alloc (c);
 
    if (!c->surface)
	c->surface = gdk_window_create_similar_surface (gtk_widget_get_window (c->disp),
                                                        CAIRO_CONTENT_COLOR,
				                        c->draw_width, c->draw_height);

    gtk_widget_queue_draw (widget);

    return TRUE;
}
Esempio n. 5
0
static gboolean configure_cb (GtkWidget *widget,
        GdkEventConfigure *evt, gpointer user_data) {
    canvasbacken_data_t *data = user_data;
    assert (data);

    int w = gtk_widget_get_allocated_width (widget);
    int h = gtk_widget_get_allocated_height (widget);

    if (data->track) 
        cairo_surface_destroy (data->track);
    data->track = gdk_window_create_similar_surface (
            gtk_widget_get_window (widget),
            CAIRO_CONTENT_COLOR_ALPHA,
            w, h);
    clear_surface (data->track);

    if (data->surf)
        cairo_surface_destroy (data->surf);

    data->surf = cairo_surface_create_similar (
            data->track,
            CAIRO_CONTENT_COLOR_ALPHA,
            w, h);

    clear_surface (data->surf);

    canvas_draw (data);
    gtk_widget_queue_draw (widget);

    return TRUE;
}
static void
maybe_update_shape (GtkWidget *widget)
{
	cairo_t *cr;
	cairo_surface_t *surface;
	cairo_region_t *region;

	/* fallback to XShape only for non-composited clients */
	if (gtk_widget_is_composited (widget)) {
		gtk_widget_shape_combine_region (widget, NULL);
		return;
	}

	surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
						     CAIRO_CONTENT_COLOR_ALPHA,
						     gtk_widget_get_allocated_width (widget),
						     gtk_widget_get_allocated_height (widget));

	cr = cairo_create (surface);
	label_draw_background_and_frame (widget, cr, TRUE);
	cairo_destroy (cr);

	region = gdk_cairo_region_create_from_surface (surface);
	gtk_widget_shape_combine_region (widget, region);

	cairo_surface_destroy (surface);
	cairo_region_destroy (region);
}
Esempio n. 7
0
static void
gtk_bubble_window_update_shape (GtkBubbleWindow *window)
{
  cairo_surface_t *surface;
  cairo_region_t *region;
  GdkWindow *win;
  cairo_t *cr;

  win = gtk_widget_get_window (GTK_WIDGET (window));
  surface =
    gdk_window_create_similar_surface (win,
                                       CAIRO_CONTENT_COLOR_ALPHA,
                                       gdk_window_get_width (win),
                                       gdk_window_get_height (win));

  cr = cairo_create (surface);
  gtk_bubble_window_apply_border_path (window, cr);
  cairo_fill (cr);
  cairo_destroy (cr);

  region = gdk_cairo_region_create_from_surface (surface);
  cairo_surface_destroy (surface);

  if (!gtk_widget_is_composited (GTK_WIDGET (window)))
    gtk_widget_shape_combine_region (GTK_WIDGET (window), region);

  gtk_widget_input_shape_combine_region (GTK_WIDGET (window), region);
  cairo_region_destroy (region);
}
Esempio n. 8
0
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;
}
static void
selection_render_mask (Selection *selection)
{
  GdkWindow       *window;
  cairo_surface_t *surface;
  cairo_t         *cr;

  window = gtk_widget_get_window (selection->shell->canvas);
  surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_ALPHA,
                                               gdk_window_get_width  (window),
                                               gdk_window_get_height (window));
  cr = cairo_create (surface);

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

  if (selection->shell->rotate_transform)
    cairo_transform (cr, selection->shell->rotate_transform);

  gimp_cairo_add_segments (cr,
                           selection->segs_in,
                           selection->n_segs_in);
  cairo_stroke (cr);

  selection->segs_in_mask = cairo_pattern_create_for_surface (surface);

  cairo_destroy (cr);
  cairo_surface_destroy (surface);
}
Esempio n. 10
0
File: vfo.c Progetto: frohro/pihpsdr
static gboolean vfo_configure_event_cb (GtkWidget         *widget,
            GdkEventConfigure *event,
            gpointer           data)
{
fprintf(stderr,"vfo_configure_event_cb: width=%d height=%d\n",
                                       gtk_widget_get_allocated_width (widget),
                                       gtk_widget_get_allocated_height (widget));
  if (vfo_surface)
    cairo_surface_destroy (vfo_surface);

  vfo_surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
                                       CAIRO_CONTENT_COLOR,
                                       gtk_widget_get_allocated_width (widget),
                                       gtk_widget_get_allocated_height (widget));

  /* Initialize the surface to black */
  cairo_t *cr;
  cr = cairo_create (vfo_surface);
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_paint (cr);

  g_idle_add(vfo_update,NULL);

  /* We've handled the configure event, no need for further processing. */
  return TRUE;
}
Esempio n. 11
0
/**
 * ppg_ruler_size_allocate:
 * @ruler: (in): A #PpgRuler.
 *
 * Handle the "size-allocate" for the #GtkWidget. The pixmap for the
 * background is created and drawn if necessary.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_ruler_size_allocate (GtkWidget     *widget,
                         GtkAllocation *alloc)
{
	PpgRuler *ruler = (PpgRuler *)widget;
	PpgRulerPrivate *priv;
	GdkWindow *window;

	g_return_if_fail(PPG_IS_RULER(ruler));

	priv = ruler->priv;

	GTK_WIDGET_CLASS(ppg_ruler_parent_class)->size_allocate(widget, alloc);

	if (priv->ruler) {
		cairo_surface_destroy(priv->ruler);
	}

	if (gtk_widget_is_drawable(widget)) {
		window = gtk_widget_get_window(widget);
		priv->ruler = gdk_window_create_similar_surface(window,
														CAIRO_CONTENT_COLOR_ALPHA,
														alloc->width,
														alloc->height);
		ppg_ruler_draw_ruler(ruler);
	}
}
std::unique_ptr<BackingStoreBackendCairo> BackingStore::createBackend()
{
#if PLATFORM(GTK) && PLATFORM(X11)
    const auto& sharedDisplay = PlatformDisplay::sharedDisplay();
    if (is<PlatformDisplayX11>(sharedDisplay)) {
        GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget());
        GdkScreen* screen = gdk_visual_get_screen(visual);
        ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen));
        return std::make_unique<BackingStoreBackendCairoX11>(downcast<PlatformDisplayX11>(sharedDisplay).native(), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
            GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor);
    }
#endif

    IntSize scaledSize = m_size;
    scaledSize.scale(m_deviceScaleFactor);

#if PLATFORM(GTK)
    RefPtr<cairo_surface_t> surface = adoptRef(gdk_window_create_similar_surface(gtk_widget_get_window(m_webPageProxy.viewWidget()),
        CAIRO_CONTENT_COLOR_ALPHA, scaledSize.width(), scaledSize.height()));
#else
    RefPtr<cairo_surface_t> surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scaledSize.width(), scaledSize.height()));
#endif

    cairoSurfaceSetDeviceScale(surface.get(), m_deviceScaleFactor, m_deviceScaleFactor);
    return std::make_unique<BackingStoreBackendCairoImpl>(surface.get(), m_size);
}
void ChunkedUpdateDrawingAreaProxy::ensureBackingStore()
{
    if (m_backingStoreImage)
        return;

    m_backingStoreImage = gdk_window_create_similar_surface(gtk_widget_get_window(m_webView->window()),
                          CAIRO_CONTENT_COLOR_ALPHA, size().width(), size().height());
}
Esempio n. 14
0
static gboolean on_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) {
    if (surface != NULL) {
        cairo_surface_destroy(surface);
    }
    surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR,
            gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
    clear_surface();
    return TRUE;
}
Esempio n. 15
0
static cairo_region_t*
curved_rect_mask(GtkWidget *widget)
{
    GdkWindow *window;
    cairo_region_t *shape;
    cairo_surface_t *surface;
    cairo_t *cr;
    double w, h;
    int radius;

    if (!gtk_widget_get_realized(widget))
        return NULL;

    window = gtk_widget_get_window(widget);
    w = gdk_window_get_width(window);
    h = gdk_window_get_height(window);
    if (w <= 50 || h <= 50)
        return NULL;
    radius = h / 4;
    surface = gdk_window_create_similar_surface(window,
                                                CAIRO_CONTENT_COLOR_ALPHA,
                                                w, h);
    cr = cairo_create (surface);

    if (radius > w / 2)
        radius = w / 2;
    if (radius > h / 2)
        radius = h / 2;

    // fill shape with black
    cairo_save(cr);
    cairo_rectangle (cr, 0, 0, w, h);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_fill (cr);
    cairo_restore (cr);

    cairo_move_to  (cr, 0, radius);
    cairo_curve_to (cr, 0 , 0, 0 , 0, radius, 0);
    cairo_line_to (cr, w - radius, 0);
    cairo_curve_to (cr, w, 0, w, 0, w, radius);
    cairo_line_to (cr, w , h - radius);
    cairo_curve_to (cr, w, h, w, h, w - radius, h);
    cairo_line_to (cr, 0 + radius, h);
    cairo_curve_to (cr, 0, h, 0, h, 0, h - radius);

    cairo_close_path(cr);

    cairo_set_source_rgb(cr, 1, 1, 1);
    cairo_fill(cr);

    cairo_destroy(cr);
    shape = gdk_cairo_region_create_from_surface(surface);
    cairo_surface_destroy(surface);

    return shape;
}
Esempio n. 16
0
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 cairo_surface_t *
tile_surface (cairo_surface_t *surface,
              int              width,
              int              height)
{
	cairo_surface_t *copy;
	cairo_t *cr;

	if (surface == NULL)
	{
		copy = gdk_window_create_similar_surface (gdk_get_default_root_window (),
		                                          CAIRO_CONTENT_COLOR,
		                                          width, height);
	}
	else
	{
		copy = cairo_surface_create_similar (surface,
		                                     cairo_surface_get_content (surface),
		                                     width, height);
	}

	cr = cairo_create (copy);

	if (surface != NULL)
	{
		cairo_pattern_t *pattern;
		cairo_set_source_surface (cr, surface, 0.0, 0.0);
		pattern = cairo_get_source (cr);
		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
	}
	else
	{
		GtkStyleContext *context;
		GdkRGBA bg;
		context = gtk_style_context_new ();
		gtk_style_context_add_provider (context,
										GTK_STYLE_PROVIDER (gtk_css_provider_get_default ()),
										GTK_STYLE_PROVIDER_PRIORITY_THEME);
		gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
		gdk_cairo_set_source_rgba(cr, &bg);
		g_object_unref (G_OBJECT (context));
	}

	cairo_paint (cr);

	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
	{
		cairo_surface_destroy (copy);
		copy = NULL;
	}

	cairo_destroy(cr);

	return copy;
}
Esempio n. 18
0
static cairo_surface_t *
tile_surface (cairo_surface_t *surface,
              int              width,
              int              height)
{
	cairo_surface_t *copy;
	cairo_t *cr;

#if GTK_CHECK_VERSION (3, 0, 0)
	if (surface == NULL)
	{
		copy = gdk_window_create_similar_surface (gdk_get_default_root_window (),
		                                          CAIRO_CONTENT_COLOR,
		                                          width, height);
	}
	else
	{
		copy = cairo_surface_create_similar (surface,
		                                     cairo_surface_get_content (surface),
		                                     width, height);
	}
#else
	copy = gdk_pixmap_new(surface, width, height, surface == NULL? 24 : -1);
#endif

	cr = cairo_create (copy);

	if (surface != NULL)
	{
		cairo_pattern_t *pattern;
		cairo_set_source_surface (cr, surface, 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)
	{
		cairo_surface_destroy (copy);
		copy = NULL;
	}

	cairo_destroy(cr);

	return copy;
}
Esempio n. 19
0
/* Redraws the backing pixmap for the load graph and updates the window */
static void
load_graph_draw (LoadGraph *g)
{
    GtkStyle *style;
    guint i, j;
    cairo_t *cr;

    /* we might get called before the configure event so that
     * g->disp->allocation may not have the correct size
     * (after the user resized the applet in the prop dialog). */

    if (!g->surface)
		g->surface = gdk_window_create_similar_surface (gtk_widget_get_window (g->disp),
					                        CAIRO_CONTENT_COLOR,
                                                                g->draw_width, g->draw_height);
	
    style = gtk_widget_get_style (g->disp);

    cr = cairo_create (g->surface);
    cairo_set_line_width (cr, 1.0);
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);

    for (i = 0; i < g->draw_width; i++)
		g->pos [i] = g->draw_height - 1;

    for (j = 0; j < g->n; j++)
    {
		gdk_cairo_set_source_color (cr, &(g->colors [j]));

		for (i = 0; i < g->draw_width; i++) {
			if (g->data [i][j] != 0) {
                                cairo_move_to (cr,
                                               g->draw_width - i - 0.5,
                                               g->pos[i] + 0.5);
                                cairo_line_to (cr,
                                               g->draw_width - i - 0.5,
					       g->pos[i] - (g->data [i][j] - 0.5));

				g->pos [i] -= g->data [i][j];
			}
		}

                cairo_stroke (cr);
    }
	
    cairo_destroy (cr);

    cr = gdk_cairo_create (gtk_widget_get_window (g->disp));
    cairo_set_source_surface (cr, g->surface, 0, 0);
    cairo_paint (cr);
    cairo_destroy (cr);
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
/**
 * ar_card_surface_cache_get_card_surface_by_id:
 * @cache:
 * @card_id:
 *
 * Returns: a cached #cairo_surface_t for @card_id.
 */
cairo_surface_t *
ar_card_surface_cache_get_card_surface_by_id (ArCardSurfaceCache *cache,
                                              guint card_id)
{
  ArCardSurfaceCachePrivate *priv = cache->priv;
  cairo_surface_t *surface;

  g_return_val_if_fail (card_id < AR_CARDS_TOTAL , NULL);

  LOG_CALL (cache);

  surface = priv->cards[card_id];
  if (IS_FAILED_SURFACE (surface)) {
    LOG_CACHE_HIT (cache);
    return NULL;
  }

  if (surface == NULL) {
    CardSize card_size;
    cairo_t *cr;

    LOG_CACHE_MISS (cache);

    ar_card_theme_get_size (priv->theme, &card_size);

    if (priv->drawable != NULL) {
      surface = gdk_window_create_similar_surface (priv->drawable, CAIRO_CONTENT_COLOR_ALPHA,
                                                   card_size.width, card_size.height);
    } else {
      surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                            card_size.width, card_size.height);
    }

    cr = cairo_create (surface);
    ar_card_theme_paint_card (priv->theme, cr, card_id);
    cairo_destroy (cr);

    if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
      cairo_surface_destroy (surface);
      priv->cards[card_id] = FAILED_SURFACE;
      return NULL;
    }

    priv->cards[card_id] = surface; /* adopts */
  } else {
    LOG_CACHE_HIT (cache);
  }

  return surface;
}
Esempio n. 22
0
static gboolean splash_configure_event_cb (GtkWidget         *widget,
            GdkEventConfigure *event,
            gpointer           data)
{
  if (splash_surface)
    cairo_surface_destroy (splash_surface);

  splash_surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
                                       CAIRO_CONTENT_COLOR,
                                       gtk_widget_get_allocated_width (widget),
                                       gtk_widget_get_allocated_height (widget));

  return TRUE;
}
Esempio n. 23
0
static gboolean configure_event_cb (GtkWidget *widget,
                                    GdkEventConfigure *event,
                                    gpointer data)
{
    if (surface)
        cairo_surface_destroy(surface);
    surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget),
                                                CAIRO_CONTENT_COLOR,
                                                CanvasWidth,
                                                CanvasWidth);
    DrawBoard();
    gtk_widget_queue_draw_area(widget, 0, 0, CanvasWidth, CanvasWidth);
    return TRUE;
}
Esempio n. 24
0
static cairo_pattern_t *
composite_image_onto_desktop (PanelBackground *background)
{
	int              width, height;
	cairo_t         *cr;
	cairo_surface_t *surface;
	cairo_pattern_t *pattern;

	if (!background->desktop)
		background->desktop = get_desktop_pixbuf (background);

	if (!background->desktop)
		return NULL;

	width  = gdk_pixbuf_get_width  (background->desktop);
	height = gdk_pixbuf_get_height (background->desktop);

	surface = gdk_window_create_similar_surface (background->window,
						     CAIRO_CONTENT_COLOR_ALPHA,
						     width, height);
	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
		cairo_surface_destroy (surface);
		return NULL;
	}

	cr = cairo_create (surface);
	if(!gdk_window_check_composited_wm(background->window)){
		cairo_set_source_rgb (cr, 1, 1, 1);
		cairo_paint (cr);

		gdk_cairo_set_source_pixbuf (cr, background->desktop, 0, 0);
		cairo_rectangle (cr, 0, 0, width, height);
		cairo_fill (cr);
	}

	gdk_cairo_set_source_pixbuf (cr, background->transformed_image, 0, 0);
	pattern = cairo_get_source (cr);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

	cairo_rectangle (cr, 0, 0, width, height);
	cairo_fill (cr);

	cairo_destroy (cr);

	pattern = cairo_pattern_create_for_surface (surface);
	cairo_surface_destroy (surface);
	return pattern;
}
Esempio n. 25
0
File: gdk.c Progetto: hedmo/compiz
cairo_surface_t *
create_surface (int        w,
                int        h,
                GtkWidget *parent_style_window)
{
    GdkWindow       *window;
    cairo_surface_t *surface;

    if (w == 0 || h == 0)
	abort ();

    window = gtk_widget_get_window (parent_style_window);
    surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR_ALPHA, w, h);

    return surface;
}
Esempio n. 26
0
/**
 * ppg_visualizer_resize_timeout:
 * @visualizer: (in): A #PpgVisualizer.
 *
 * A GSourceFunc to handle a resize request. The surface of the visualizer
 * is resized and a draw request is queued.
 *
 * Returns: %FALSE always
 * Side effects: None.
 */
static gboolean
ppg_visualizer_resize_timeout (gpointer data)
{
	PpgVisualizer *visualizer = (PpgVisualizer *)data;
	PpgVisualizerPrivate *priv;
	cairo_pattern_t *pattern;
	GdkWindow *window;
	GooCanvas *canvas;
	gdouble width;
	gdouble height;

	g_return_val_if_fail(PPG_IS_VISUALIZER(visualizer), FALSE);

	priv = visualizer->priv;

	/*
	 * Remove existing surface.
	 */
	if (priv->surface) {
		g_object_set(visualizer, "pattern", NULL, NULL);
		cairo_surface_destroy(priv->surface);
		priv->surface = NULL;
	}

	/*
	 * Create new surface matching new size allocation.
	 */
	g_object_get(visualizer, "height", &height, "width", &width, NULL);
	canvas = goo_canvas_item_get_canvas(GOO_CANVAS_ITEM(visualizer));
	window = gtk_widget_get_window(GTK_WIDGET(canvas));
	priv->surface = gdk_window_create_similar_surface(window,
	                                                  CAIRO_CONTENT_COLOR_ALPHA,
	                                                  width, height);

	/*
	 * Create a new pattern for drawing the item.
	 */
	pattern = cairo_pattern_create_for_surface(priv->surface);
	g_object_set(visualizer, "pattern", pattern, NULL);
	cairo_pattern_destroy(pattern);
	ppg_visualizer_queue_draw(visualizer);

	priv->resize_handler = 0;
	return FALSE;
}
Esempio n. 27
0
/*
 * Aquí creamos una superficie de dibujo en la cual vamos a almacenar todo.
 */
gboolean on_drawingareaPrincipal_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data){
  /* Verificamos que la superficie no esté en uso */
  if(superficie)
    cairo_surface_destroy(superficie);

  /* Creamos una nueva instancia de la superficie */
  superficie = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
					   CAIRO_CONTENT_COLOR,
					   gtk_widget_get_allocated_width (widget),
					   gtk_widget_get_allocated_height (widget));

  /* Iniciamos con una superficie limpia */
  limpia_superficie();

  
  /* En este punto hemos manejado satisfactoriamente el evento. */
  return TRUE;
}
Esempio n. 28
0
static void
gimp_ruler_make_pixmap (GimpRuler *ruler)
{
  GtkWidget        *widget = GTK_WIDGET (ruler);
  GimpRulerPrivate *priv   = GIMP_RULER_GET_PRIVATE (ruler);
  GtkAllocation     allocation;

  gtk_widget_get_allocation (widget, &allocation);

  if (priv->backing_store)
    cairo_surface_destroy (priv->backing_store);

  priv->backing_store =
    gdk_window_create_similar_surface (gtk_widget_get_window (widget),
                                       CAIRO_CONTENT_COLOR,
                                       allocation.width,
                                       allocation.height);
}
Esempio n. 29
0
static int gtkDialogSetOpacityImageAttrib(Ihandle *ih, const char *value)
{
  GdkPixbuf* pixbuf = iupImageGetImage(value, ih, 0);
  if (pixbuf)
  {
#if GTK_CHECK_VERSION(3, 0, 0)
    GdkWindow* window = iupgtkGetWindow(ih->handle);
    if (window)
    {
      cairo_region_t *shape;

#if GTK_CHECK_VERSION(3, 10, 0)
      cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, window);
#else
      int width = gdk_pixbuf_get_width(pixbuf);
      int height = gdk_pixbuf_get_height(pixbuf);
      cairo_surface_t* surface = gdk_window_create_similar_surface(window, CAIRO_CONTENT_COLOR_ALPHA, width, height);
      cairo_t* cr = cairo_create(surface);
      gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
      cairo_paint(cr);
      cairo_destroy(cr);
#endif

      shape = gdk_cairo_region_create_from_surface(surface);
      cairo_surface_destroy(surface);

      gtk_widget_shape_combine_region(ih->handle, shape);
      cairo_region_destroy(shape);
    }
#else
    GdkBitmap* mask = NULL;
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, NULL, &mask, 255);
    if (mask) 
    {
      gtk_widget_shape_combine_mask(ih->handle, mask, 0, 0);
      g_object_unref(mask);
    }
#endif
    return 1;
  }
  return 0;
}
Esempio n. 30
0
/* Create a new surface of the appropriate size to store our scribbles */
static gboolean
configure_event_cb (GtkWidget         *widget,
                    GdkEventConfigure *event,
                    gpointer           data)
{
    if (surface)
        cairo_surface_destroy (surface);

    surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
                                                 CAIRO_CONTENT_COLOR,
                                                 gtk_widget_get_allocated_width (widget),
                                                 gtk_widget_get_allocated_height (widget));

    /* Initialize the surface to white */
    clear_surface ();

    /* We've handled the configure event, no need for further processing. */
    return TRUE;
}