Re: deprecated gtk_cairo_create



Generally, what you need is something like:

cairo_surface_t *surface;

static gboolean
da_configure_cb (GtkWidget *widget,
                 GdkEvent  *event,
                 gpointer   user_data)
{
  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));
}

static gboolean
da_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
{
  cairo_set_source_surface (cr, surface, 0.0, 0.0);

  // cairo drawing stuff
}

whatever()
{
  da = gtk_drawing_area_new ();
  g_signal_connect (da, "configure-event",
                    G_CALLBACK (da_configure_cb), whatever);
  g_signal_connect (da, "draw",
                    G_CALLBACK (da_draw_cb), whatever);
}



On 12/30/16 06:15, Sergei Kolomeeyets wrote:
Hi, everyone
I'm struggling with migration from gtk2. Well gtk_cairo_create is deprecated in gtk3. And it looks  the changes are very serious (or I'm sach silly that even do not understand what should I do instead of it ). Is there anybody who use Drawing Area in GTK3 and can explain the right way of its cairo context creation and drawing on it to me. It would be so appreciated.

Documentation says the following:
***gtk_cairo_create
gdk_cairo_create
has been deprecated since version 3.22 and should not be used in newly-written code. Use gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context() instead.

***gdk_window_begin_draw_frame
[bla-bla-bla...] When using GTK+, the widget system automatically places calls to gdk_window_begin_draw_frame() and gdk_window_end_draw_frame() around emissions of the GtkWidget::draw signal. That is, if you’re drawing the contents of the widget yourself, you can assume that the widget has a cleared background, is already set as the clip region, and already has a backing store. Therefore in most cases, application code in GTK does not need to call gdk_window_begin_draw_frame() explicitly.

I use GTK+, so I can forget about gdk_window_begin_draw_frame for some time. Right?
And there is only gdk_drawing_context_get_cairo_context in the rest of options. So I write the following:

{main}
...
/*Drawing area and text_entry at the bottom of it */
area = gtk_drawing_area_new();
text_entry = gtk_entry_new();
vbox = gtk_vbox_new (FALSE, 0); 

gtk_box_pack_start(vbox, area, TRUE, TRUE, 0);
gtk_box_pack_start(vbox, text_entry,  FALSE, FALSE, 0);

gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(window);
gtk_main();  
...

{draw_callback}

gboolean draw_callback(GtkWidget *area, GdkEventExpose *event, GArray *ptLinePoints) {
...
cairo_t *cr = gdk_drawing_context_get_cairo_context (area);
...
}

But linker (gcc package) writes  "undefined reference to `gdk_drawing_context_get_cairo_context"... :-(
Everything indicated that I missed several lines of code before gdk_drawing_context_get_cairo_context. But what lines exactly? Googling gives nothing...

Is there anybody who use Drawing Area in GTK3 and can explain the right way of its cairo context creation and drawing on it to me. It would be so appreciated.

Thanks in advance!

Best Regards, (and Happy New Year for everyone here!!!)
Sergey.





_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]