#86 GtkExtra3 fails to draw

closed-fixed
Fredy Paquet
None
5
2013-03-10
2011-02-15
Pedro Santos
No

Hello. The GtkExtra3 version fails to draw graphics. No error messages are seen, even when compiled in debug mode. I attached a comparison between gtkextracairo (draw) and gtkextra 3 (incomplete draw). I built both against Gtk+-2.22.1. Any help will be appreciated.

Gratefully,

Pedro Santos

Discussion

1 2 > >> (Page 1 of 2)
  • Pedro Santos
    Pedro Santos
    2011-02-15

     
    Attachments
  • Pedro Santos
    Pedro Santos
    2011-02-27

    Hello. I used the configure script (along with the generated makefiles) to built gtkextra3 and the same behaviour persists. I'm building under win7 64bit. All help will be apreciatted.

    Gratefully,

    Pedro Santos

     
  • Fredy Paquet
    Fredy Paquet
    2011-10-28

    Date: Fri, 28 Oct 2011 18:53:15 +0200
    From: Fredy Paquet <fredy@opag.ch>
    To: "Luis A. Montes" <luis@qdusa.com>, scigraphica-gtkextra@lists.sourceforge.net
    Subject: Re: [gtkextra] GtkPlot with multiple datasets

    Hello Luis

    The plot widgets of gtkextra-3 are working properly on Solaris here.

    I did a few tests on MinGW today and can confirm the drawing problem.

    From gtkextra-2 to gtkextra-3, the drawing base was rewritten to use Cairo.
    The sheet code in gtkextra-3 is still based on GDK and has not yet been rewritten.

    fp

    --On Thursday, October 27, 2011 1:24:03 PM -0700 "Luis A. Montes" <luis@qdusa.com> wrote:

    > I've been trying to use GtkExtra, specifically gtk plot to produce some
    > simple graphs. I have a single plot on a canvas, and then I add one
    > dataset. That seems to work. But when I add a second one using:
    >
    > pImpl->m_dataset[n] = GTK_PLOT_DATA(gtk_plot_data_new());
    > gtk_plot_add_data(GTK_PLOT(pImpl->m_plot), pImpl->m_dataset[n]);
    >
    > and then I try to set a different symbol for the second one using:
    >
    > gtk_plot_data_set_symbol(
    > pImpl->m_dataset[n], symbol, GTK_PLOT_SYMBOL_OPAQUE,
    > 5, 1,
    > &pImpl->m_color[color_ndx],&pImpl->m_color[color_ndx]
    > );
    >
    > It ends up using the same symbol for both. The odd part is that the
    > legend does show different symbols for each data set. It actually seems
    > as if the two datasets get spliced into one.
    > Since I was using a sort of an old version, I downloaded the latest
    > (3.0.1) and compiled it using mingw, but I found out that the tests
    > (testgtkplot*) don't work any more. I do remember them working before.
    > The changelog seems to imply that the GtkSheet part is working but the
    > GtkPlot is not? Is there anybody working on fixing GtkPlot? I could
    > help, but it'll be a steep learning curve for me.
    >
    > Thanks
    >
    >

     
  • Fredy Paquet
    Fredy Paquet
    2011-10-31

    While debugging the MinGW problem last saturday, i found out that
    the cairo drawing functions get called, with arguments looking good to me.

    Does the plot really show up when you hide and expose it ?
    (it doesn't with my installation here on WinXP/Gtk 2.24.4, testgtkplot.exe shows only 3 lines, 1 black and 2 grey.)

    I can select each of the two plots and drag it around, the drag rectangle appears.

    To get over the SEGV, you could try to switch the plot invisible an back visible again,
    which causes a complete redraw... but this wouldn't solve the underlying problem.

    The strange thing is, that it all works fine on Linux and Solaris, so where's the difference?

    fp

    --On Monday, October 31, 2011 10:29:32 AM -0700 "Luis A. Montes" <luis@qdusa.com> wrote:

    > Hi,
    >
    > I've solved my problem with multiple sets, it was actually on my code,
    > not gtkextra. I'm not using 3.0.1 yet, though. But I want to get it
    > working with my current version and then I can try to see if I can
    > figure out why 3.0.1 is not drawing on the canvas under MS windows.
    > The only thing left before I do that is to repaint the plot after a
    > window resize. The plot seems to repaint itself on an expose event (that
    > is, if I cover the window and then uncover it, it repaints) but several
    > combinations of gtk_plot_paint and/or send_expose on_size_allocate,
    > on_idle, on_realize either don't do anything or produce a SIGV. Anybody
    > has some trick that can share?
    >
    > The last thing I tried involved sending a delayed expose event (I'm
    > using gtkmm):
    >
    > void GtkPlotWrapper::on_size_allocate( Gtk::Allocation &allocation )
    > {
    > set_allocation( allocation );
    > gtk_plot_canvas_set_size(
    > GTK_PLOT_CANVAS(pImpl->m_canvas),
    > allocation.get_width(),
    > allocation.get_height() );
    > gtk_widget_set_uposition(
    > GTK_WIDGET(pImpl->m_canvas),
    > allocation.get_x(),
    > allocation.get_y() );
    > pImpl->m_resized = true;
    > pImpl->m_resized_time_stamp = clock();
    > }
    >
    > bool GtkPlotWrapper::on_idle()
    > {
    > if (pImpl){
    > if ((pImpl->m_resized)&&(clock()-pImpl->m_resized_time_stamp>500))
    > send_expose((GdkEvent *)&pImpl->m_event);
    > pImpl->m_resized = false;
    > }
    > return true;
    > }
    >
    > If I change the send_expose with a gtk_plot_paint it segfaults.
    >
    > Thanks again,
    >
    > Luis
    >

     
  • Pedro Santos
    Pedro Santos
    2011-12-10

    Hello,
    10 months passed since I experienced this bug. Are there any developments about this issue? Thank you.

    Pedro Santos

     
  • Fredy Paquet
    Fredy Paquet
    2012-04-22

    Hello Pedro

    I'm still stuck with this, but today i found a hint in the Gtk2 FAQ which might help to solve it.
    It seams that the public Gtk-2 doc has been removed, so i copy the hint

    Using cairo with GTK+

    6.1. How do I use cairo to draw in GTK+ applications ?

    Use gdk_cairo_create() to obtain a cairo context for drawing on a GDK window or pixmap. See Cairo Interaction for some more useful functions.

    6.2. I have created a cairo context with gdk_cairo_create(), but when I later use it, my drawing does not show up. Why is that ?

    All drawing in GTK+ is normally done in an expose handler, and GTK+ creates a temporary pixmap for double-buffering the drawing. If you create a cairo context outside the expose handler, it is backed by the GDK window itself, not the double-buffering pixmap. Consequently, any drawing you do with that cairo context gets overwritten at the end of the expose handler, when the double-buffering pixmap is copied back.

    Possible solutions to this problem are:

    1. Turn off double-buffering, with gtk_widget_set_double_buffered(). This is not ideal, since it can cause some flickering.

    2. Create the cairo context inside the expose handler. If you do this, gdk_create_cairo() arranges for it to be backed by the double-buffering pixmap. This is the preferred solution, and is used throughout GTK+ itself.

     
  • Now GtkPlot of GtkExtra3 works fine on win32!

    It had a couple of problems.
    The first problem was happened at getting font at "drawstring()" in gtkplotcairo.c.
    "gdk_screen_get_resolution()" any time return -1, so that it failed DPI calculation and getting font.

    The second, it did not check being a cairo object at "gtk_plot_cairo_draw_pixmap()" in gtkplotcairo.c.

    And testgtkplot.c also has a small problem, it prints a very small image like a stamp.

    I attach a patch.
    Please check this on your environment.

    Daisuke Shimamura

    -- cut here ---- cut here ---- cut here ---- cut here ---- cut here ---- cut here ---- cut here --
    diff -u gtk+extra-3.0.1/gtkextra/gtkplotcairo.c gtk+extra-3.0.1.new/gtkextra/gtkplotcairo.c
    --- gtk+extra-3.0.1/gtkextra/gtkplotcairo.c 2010-07-09 16:50:35 +0900
    +++ gtk+extra-3.0.1.new/gtkextra/gtkplotcairo.c 2013-03-01 22:07:20 +0900
    @@ -619,8 +619,8 @@
    map = pango_cairo_font_map_get_default();
    dpi_cairo = pango_cairo_font_map_get_resolution(PANGO_CAIRO_FONT_MAP(map));
    dpi_screen = gdk_screen_get_resolution(screen);
    -
    - height *= (double)dpi_screen/(double)dpi_cairo;
    + if (dpi_screen != -1)
    + height *= (double)dpi_screen/(double)dpi_cairo;
    font = gtk_psfont_get_font_description(psfont, height);
    pango_layout_set_font_description(GTK_PLOT_CAIRO(pc)->layout, font);
    pango_layout_set_text(GTK_PLOT_CAIRO(pc)->layout, text, strlen(text));
    @@ -1111,6 +1111,9 @@
    gdouble scale_x,
    gdouble scale_y)
    {
    + if (!GTK_PLOT_CAIRO(pc)->cairo)
    + return;
    +
    cairo_surface_t *image_surface = NULL;
    cairo_surface_t *mask_surface = NULL;
    cairo_t *cr;
    diff -u gtk+extra-3.0.1/gtkextra/testgtkplot.c gtk+extra-3.0.1.new/gtkextra/testgtkplot.c
    --- gtk+extra-3.0.1/gtkextra/testgtkplot.c 2010-07-09 16:50:36 +0900
    +++ gtk+extra-3.0.1.new/gtkextra/testgtkplot.c 2013-03-01 15:17:00 +0900
    @@ -38,6 +38,10 @@
    GtkPlotCanvas *canvas = GTK_PLOT_CANVAS(user_data);

    cr = gtk_print_context_get_cairo_context (context);
    +
    + double width = gtk_print_context_get_width (context);
    + double height = gtk_print_context_get_height (context);
    + cairo_scale (cr, width/canvas->pixmap_width, height/canvas->pixmap_height);
    gtk_plot_canvas_export_cairo(canvas, cr);
    }

    -- cut here ---- cut here ---- cut here ---- cut here ---- cut here ---- cut here ---- cut here --

     
  • Fredy Paquet
    Fredy Paquet
    2013-03-05

    Hello Daisuke

    This is great!

    I will try to review and apply your patches as soon as possible.

    ---
    by the way: i released 3.0.2 last weekend, with lots of sheet-fixes.

    Many Thanks
    F. Paquet

    --
    OPAG Informatik AG Tel. ++41 61 716 92 22
    F. Paquet Fax. ++41 61 716 92 29
    Fabrikmattenweg 11 http://www.opag.ch
    CH-4144 Arlesheim

    On Wed, 2013-03-06 at 01:30 +0900, Daisuke Shimamura wrote:
    Hi all,
    >
    > This is a patch to solve the problem miss drawing on MS-Windows.
    > I have tested this code on Win7 using the GTK-2.24 and MinGW.
    > This patch repair three problems.
    >
    > The first problem is the reason of the problem miss drawing.
    > Because gdk_screen_get_resolution() of gtkplotcairo.c have always
    > returns -1, Failed to get the font, it eventually breaks the Cairo
    > context.
    >
    > The second problem, because the gtk_plot_cairo_draw_pixmap() of
    > gtkplotcairo.c did not check a cairo object, it produces SEGV.
    >
    > The third problem, testgtkplot.c prints out a too small image like a stamp.
    >
    > I hope you like it.
    >
    > --
    > Daisuke Shimamura
    >

     
  • Fredy Paquet
    Fredy Paquet
    2013-03-10

    Patch from Daisuke Shimamura

     
    Attachments
  • Fredy Paquet
    Fredy Paquet
    2013-03-10

    Patch applied to GtkExtra-3.0.3

     
1 2 > >> (Page 1 of 2)