Re: GnomeCanvasPixbuf



On Fri, Dec 20, 2002 at 02:08:40PM +0000, Chris Garrett wrote:
> 
> Having taken a look at the GnomeCanvas API, it looks like it might be a 
> little more convenient for things like scaling.  However, I cannot find any 
> good examples of displaying a GdkPixbuf on a GnomeCanvas using 
> GnomeCanvasPixbuf.  I cannot see any tutorials either.
> 
> Is there a project you know of out there that does this (using GTK2).  Once 
> I look at some code I should understand how it all hangs together, but the 
> API on its own is confusing.
> 

Try this.


#include <gnome.h>

void
on_zoom_changed(GtkAdjustment* adjs, GnomeCanvas* canvas)
{
        gnome_canvas_set_pixels_per_unit(canvas, adjs->value);
}

int
main(int argc, char** argv)
{
        GtkWidget *window;
        GtkWidget *canvas;
        GtkWidget *scroll_window;
        GtkWidget *vbox;
        GtkWidget *scrool_zoom;
        GnomeCanvasGroup *root;
        GdkPixbuf* pixbuf;
	GtkAdjustment *adjustment;

        gnome_init("zoom_an_image", "0.1", argc, argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(G_OBJECT(window), "destroy", gtk_main_quit, 0);

        vbox = gtk_vbox_new(FALSE, 1);
        gtk_container_add(GTK_CONTAINER(window), vbox);

        adjustment = GTK_ADJUSTMENT(
			gtk_adjustment_new(1.0, 0.25, 4.0, 0.1, 0.5, 1.0));
        scrool_zoom = gtk_hscale_new(adjustment);
        gtk_scale_set_draw_value(GTK_SCALE(scrool_zoom), TRUE);
        gtk_box_pack_start(GTK_BOX(vbox), scrool_zoom, FALSE, TRUE, 1);

        scroll_window = gtk_scrolled_window_new(NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), scroll_window, TRUE, TRUE, 1);

        canvas = gnome_canvas_new_aa();
        gtk_container_add(GTK_CONTAINER(scroll_window), canvas);
        gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, 1000, 1000);

        root = gnome_canvas_root(GNOME_CANVAS(canvas));

	pixbuf = gdk_pixbuf_new_from_file("some.png", NULL);
        gnome_canvas_item_new(root,
			gnome_canvas_pixbuf_get_type(),
                        "pixbuf", pixbuf,
                        NULL);
	gdk_pixbuf_unref(pixbuf);

        g_signal_connect(G_OBJECT(adjustment), "value_changed",
			G_CALLBACK(on_zoom_changed), canvas);

        gtk_widget_show_all(window);
        gtk_main();

        return 0;
}



-- 
Ayose Cazorla León
Debian GNU/Linux - setepo



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