Il 04/11/2013 15:24, Jasper St. Pierre ha scritto: > Hm. This shouldn't be happening. What version of GTK+3 are you using, > and can you produce a small reproducible example[0] ? > > [0] http://sscce.org/ > Please, find the attached example. I can get what I think is the right behaviour by commenting the call to the drawing function in on_daCairo_draw() callback, but when I have any cairo_ action, the result is an infinite firing. Release I'm currently using is 3.8.4 (Debian testing current version). > > On Mon, Nov 4, 2013 at 9:18 AM, onetmt <onetmt@xxxxxxxxx > <mailto:onetmt@xxxxxxxxx>> wrote: > > Il 04/11/2013 15:06, Jasper St. Pierre ha scritto: > > Connect to the "draw" signal on the widget to do your drawing, and > call > > gtk_widget_queue_redraw(); on the widget if you want to request a > redraw. > > > This is what I'm currently doing (I've connected to "draw" signal of a > GtkDrawingArea), but the problem is that I have the "draw" event fired > continuosly. > > > > > > On Mon, Nov 4, 2013 at 9:02 AM, onetmt <onetmt@xxxxxxxxx > <mailto:onetmt@xxxxxxxxx> > > <mailto:onetmt@xxxxxxxxx <mailto:onetmt@xxxxxxxxx>>> wrote: > > > > I'm currently in the process of porting to gtk+-3 an old finite > > difference calculation application; this application had a > custom graph > > drawing routine based on gdk_ subsystem that cannot be > compiled anymore > > against new gtk3 api :( . I succesfully converted every gdk_ > invocation > > in their cairo_ counterparts, but now I have to substitute the > no longer > > available "expose-event" with the new "draw" event. The > problem is that > > it runs continuosly in an infinite loop. > > > > What is the expected mechanism of this new event? How can I > refresh the > > graph in a clean way as in old expose-event? > > > > TIA > > > > -- > > Hofstadter's Law: > > "It always takes longer than you expect, even when you take > into account > > Hofstadter's Law." > > _______________________________________________ > > gtk-list mailing list > > gtk-list@xxxxxxxxx <mailto:gtk-list@xxxxxxxxx> > <mailto:gtk-list@xxxxxxxxx <mailto:gtk-list@xxxxxxxxx>> > > https://mail.gnome.org/mailman/listinfo/gtk-list > > > > > > > > > > -- > > Jasper > > > -- > Hofstadter's Law: > "It always takes longer than you expect, even when you take into account > Hofstadter's Law." > _______________________________________________ > gtk-list mailing list > gtk-list@xxxxxxxxx <mailto:gtk-list@xxxxxxxxx> > https://mail.gnome.org/mailman/listinfo/gtk-list > > > > > -- > Jasper -- Hofstadter's Law: "It always takes longer than you expect, even when you take into account Hofstadter's Law."
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * cairo_test.c */ #include <gtk/gtk.h> #include <glib.h> #include <cairo.h> #include <pango/pango.h> #include <stdio.h> #include <locale.h> #define UI_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \ <interface> \ <!-- interface-requires gtk+ 3.0 --> \ <object class=\"GtkWindow\" id=\"window\"> \ <property name=\"can_focus\">False</property> \ <property name=\"window_position\">center</property> \ <property name=\"default_width\">450</property> \ <property name=\"default_height\">450</property> \ <signal name=\"destroy\" handler=\"on_window_destroy\" swapped=\"no\"/> \ <child> \ <object class=\"GtkBox\" id=\"box1\"> \ <property name=\"visible\">True</property> \ <property name=\"can_focus\">False</property> \ <property name=\"orientation\">vertical</property> \ <property name=\"spacing\">5</property> \ <child> \ <placeholder/> \ </child> \ <child> \ <object class=\"GtkDrawingArea\" id=\"daCairo\"> \ <property name=\"visible\">True</property> \ <property name=\"app_paintable\">True</property> \ <property name=\"can_focus\">False</property> \ <signal name=\"draw\" handler=\"on_daCairo_draw\" swapped=\"no\"/> \ </object> \ <packing> \ <property name=\"expand\">True</property> \ <property name=\"fill\">True</property> \ <property name=\"position\">1</property> \ </packing> \ </child> \ <child> \ <object class=\"GtkButtonBox\" id=\"buttonbox1\"> \ <property name=\"visible\">True</property> \ <property name=\"can_focus\">False</property> \ <property name=\"spacing\">5</property> \ <property name=\"layout_style\">start</property> \ <child> \ <object class=\"GtkButton\" id=\"btnDraw\"> \ <property name=\"label\" translatable=\"yes\">Draw</property> \ <property name=\"visible\">True</property> \ <property name=\"can_focus\">True</property> \ <property name=\"receives_default\">True</property> \ <signal name=\"clicked\" handler=\"on_btnDraw_clicked\" swapped=\"no\"/> \ </object> \ <packing> \ <property name=\"expand\">False</property> \ <property name=\"fill\">True</property> \ <property name=\"position\">0</property> \ </packing> \ </child> \ <child> \ <placeholder/> \ </child> \ <child> \ <placeholder/> \ </child> \ </object> \ <packing> \ <property name=\"expand\">False</property> \ <property name=\"fill\">True</property> \ <property name=\"position\">2</property> \ </packing> \ </child> \ </object> \ </child> \ </object> \ </interface>" /* * Da builder - variabile globale */ GtkBuilder *builder; float thick = 1.0; /* Called when the window is closed */ G_MODULE_EXPORT void on_window_destroy(GtkWidget *self, gpointer data) { gtk_main_quit(); } void draw_me(GtkWidget *self, cairo_t *cr) { GdkRGBA rosa, bianco, nero, rosso; gint width, height; gdouble dash[] = {10.0, 10.0}; rosa.red = 1; rosa.green = 0.2; rosa.blue = 0.2; rosa.alpha = 0.6; rosso.red = 1; rosso.green = 0; rosso.blue = 0; rosso.alpha = 0.6; bianco.red = 1; bianco.green = 1; bianco.blue = 1; bianco.alpha = 1; nero.red = 0; nero.green = 0; nero.blue = 0; nero.alpha = 1; //cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6); gdk_cairo_set_source_rgba(cr, &rosa); cairo_set_line_width(cr, thick); cairo_set_dash(cr, dash, 2, 0); gdk_window_set_background_rgba(gtk_widget_get_window(self), &bianco); cairo_move_to(cr, 128.0, 25.6); cairo_line_to(cr, 230.4, 230.4); cairo_stroke(cr); gdk_cairo_set_source_rgba(cr, &rosso); cairo_set_dash(cr, dash, 0, 0); cairo_move_to(cr, 230.4, 230.4); cairo_rel_line_to(cr, -102.4, 0.0); cairo_rel_line_to(cr, 100, 100); cairo_stroke(cr); gdk_cairo_set_source_rgba(cr, &nero); cairo_move_to(cr, 250, 250); cairo_set_font_size(cr, 16.0); cairo_show_text(cr, "A ciccio"); gdk_window_get_geometry(gtk_widget_get_window(self), NULL, NULL, &width, &height); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); } /** @fn on_btnQuit_clicked(GtkButton *, gpointer) * Callback collegata al pulsante "Quit". */ G_MODULE_EXPORT void on_btnDraw_clicked(GtkButton *self, gpointer data) { GtkWidget *da; cairo_rectangle_int_t rec; g_print("drawing...\n"); if (thick < 10.0) { thick *= 1.5; } else { thick = 1.0; } da = GTK_WIDGET(gtk_builder_get_object(builder, "window")); rec.x = 0; rec.y = 0; gdk_window_get_geometry(gtk_widget_get_window(da), NULL, NULL, &(rec.width), &(rec.height)); gdk_window_invalidate_rect(gtk_widget_get_window(da), &rec, TRUE); } G_MODULE_EXPORT gboolean on_daCairo_draw(GtkWidget *self, cairo_t *cr, gpointer data) { g_print("draw+"); /* all drawing actions are performed by this function */ draw_me(self, cr); return FALSE; } static GtkWidget *create_window(void) { GtkWidget *window; GError *error = NULL; /* * Load UI from file */ builder = gtk_builder_new(); //if (!gtk_builder_add_from_file(builder, "./cairo_test.ui", &error)) if (!gtk_builder_add_from_string(builder, UI_STRING, -1, &error)) { g_critical("Couldn't load builder file: %s", error->message); g_error_free(error); } /* * Get the window object from the ui file */ window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); if (!window) { g_critical("Widget \"%s\" is missing in file %s.", "window", "./cairo_test.ui"); } /* * Auto-connect signal handlers */ gtk_builder_connect_signals(builder, window); return window; } int main(int argc, char *argv[]) { GtkWidget *window; /* * Prima di invocare il main loop, imposto il locale * di default ("C", per leggere i float con il punto) */ setlocale(/*LC_NUMERIC*/1, "C"); gtk_disable_setlocale(); gtk_init(&argc, &argv); window = create_window(); gtk_widget_show(window); gtk_main(); g_object_unref(builder); return 0; }
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx https://mail.gnome.org/mailman/listinfo/gtk-list