Re: "ghost" image on canvas



Diego Zuccato wrote:

That's strictly related to the previous. I could reproduce a really
strange behaviour using the attached code.
The only difference lies in the pointer type. And I can't understand why
in the hell should that matter...

The code should display a thumbnail (the file 001_01.jpg in the current
directory, must be 256x256) when first clicked and clear the window when
clicked again (like a toggle button). canvas_ok.c works as expected,
while canvas_bad not :-(

Please, HELP! I's driving me crazy :-(

BYtE,
 Diego.
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gnome-canvas-pixbuf.h>

gboolean
canvas_event(GtkWidget *w, GdkEvent *e, gpointer d)
{
    gpointer bg;
    if(e->type!=GDK_BUTTON_PRESS)
	return FALSE;

    bg=gtk_object_get_data(GTK_OBJECT(d), "thumb");

    if(bg) {
	printf("Destroying!\n");
	gtk_object_destroy(GTK_OBJECT(bg));
	bg=NULL;
    } else {
        GdkPixbuf *pb=gdk_pixbuf_new_from_file("001_01.jpg");
        bg=gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(d)),
			gnome_canvas_pixbuf_get_type(), "pixbuf", pb, NULL);
    }
    gtk_object_set_data(GTK_OBJECT(d), "thumb", bg);
    return TRUE;
}

int main( int argc, char *argv[] )
{
    GtkWidget *window;
    GnomeCanvas *gc=NULL;


    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_widget_push_visual (gdk_imlib_get_visual ());
    gtk_widget_push_colormap (gdk_imlib_get_colormap ());
    gc = gnome_canvas_new ();
    gtk_widget_pop_colormap ();
    gtk_widget_pop_visual ();

    gtk_container_add (GTK_CONTAINER (window), gc);
    gtk_widget_set_usize (gc, 256, 256);
    gnome_canvas_set_scroll_region (gc, 0, 0, 256, 256);
    gtk_signal_connect(GTK_OBJECT(gc), "event", canvas_event, gc);

    gtk_widget_show_all(window);

    gtk_main ();

    return(0);
}

//#include <gnome/gnome.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gnome-canvas-pixbuf.h>

gboolean
canvas_event(GtkWidget *w, GdkEvent *e, gpointer d)
{
    GtkObject *bg;
    if(e->type!=GDK_BUTTON_PRESS)
	return FALSE;

    bg=GTK_OBJECT(gtk_object_get_data(GTK_OBJECT(d), "thumb"));

    if(bg) {
	printf("Destroying!\n");
	gtk_object_destroy(bg);
	bg=NULL;
    } else {
        GdkPixbuf *pb=gdk_pixbuf_new_from_file("001_01.jpg");
        bg=GTK_OBJECT(gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(d)),
				gnome_canvas_pixbuf_get_type(),
    		    		"pixbuf", pb, NULL));
    }
    gtk_object_set_data(GTK_OBJECT(d), "thumb", bg);
    return TRUE;
}

int main( int argc, char *argv[] )
{
    GtkWidget *window;
    GnomeCanvas *gc=NULL;


    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_widget_push_visual (gdk_imlib_get_visual ());
    gtk_widget_push_colormap (gdk_imlib_get_colormap ());
    gc = gnome_canvas_new ();
    gtk_widget_pop_colormap ();
    gtk_widget_pop_visual ();

    gtk_container_add (GTK_CONTAINER (window), gc);
    gtk_widget_set_usize (gc, 256, 256);
    gnome_canvas_set_scroll_region (gc, 0, 0, 256, 256);
    gtk_signal_connect(GTK_OBJECT(gc), "event", canvas_event, gc);

    gtk_widget_show_all(window);

    gtk_main ();

    return(0);
}



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