/* * File : canvastest.c * * Description : Simple application to demonstrate the use of the GnomeCanvas * with libglade, and hopefully gdk-pixbuf's. * * Dependencies : canvastest.glade * * Author : Andrae Muys <andrae@humbug.org.au> * * Date : 22nd November 2000 * * License : GPL. * */ #include <glade/glade.h> #include <glade/glade-build.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <gnome.h> #define FILENAME "canvastest.glade" GladeXML *xml; GtkWidget? *NewGnomeCanvas?(GladeXML *xml, GladeWidgetInfo? *info) { double x1, x2, y1, y2; double ppu = 1.0; int aa = 1; GList *attrlist = info->attributes; GnomeCanvas *canvas; gdk_rgb_init(); while(attrlist) { GladeAttribute? *attr = (GladeAttribute? *)attrlist->data; if (strcmp(attr->name, "scroll_x1")) { x1 = atof(attr->value); } else if (!strcmp(attr->name, "scroll_x2")) { x2 = atof(attr->value); } else if (!strcmp(attr->name, "scroll_y1")) { y1 = atof(attr->value); } else if (!strcmp(attr->name, "scroll_y2")) { y2 = atof(attr->value); } else if (!strcmp(attr->name, "anti-aliased")) { if (!strcmp(attr->value, "False")) { aa = 0; } else { aa = 1; } } else if (!strcmp(attr->name, "pixels_per_unit")) { ppu = atof(attr->value); } attrlist = g_list_next(attrlist); } if (aa) { /* gtk_widget_push_visual(gdk_rgb_get_visual()); gtk_widget_push_colormap(gdk_rgb_get_cmap()); */ canvas = (GnomeCanvas*)gnome_canvas_new_aa(); /* gtk_widget_pop_visual(); gtk_widget_pop_colormap(); */ } else { g_warning("Gdk mode for gnomeCanvas Depreciated."); gtk_widget_push_visual(gdk_imlib_get_visual()); gtk_widget_push_colormap(gdk_imlib_get_colormap()); canvas = (GnomeCanvas*)gnome_canvas_new(); gtk_widget_pop_visual(); gtk_widget_pop_colormap(); } gnome_canvas_set_scroll_region(canvas, x1, y1, x2, y2); gnome_canvas_set_pixels_per_unit(canvas, ppu); return GTK_WIDGET(canvas); } GladeWidgetBuildData? customWidgets[] = { { "GnomeCanvas", NewGnomeCanvas?, NULL }, { NULL, NULL, NULL }, }; int main(int argc, char *argv[]) { GtkWidget? *canvas; GnomeCanvasItem? *item; GnomeCanvasItem? *pixitem; GdkPixbuf? *pixbuf; gnome_init("canvastest", "0.01", argc, argv); glade_init(); glade_register_widgets(customWidgets); xml = glade_xml_new(FILENAME, "mainWindow"); if(!xml) { g_warning("Could not load interface."); return 1; } canvas = glade_xml_get_widget(xml, "canvas"); /* item = gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(canvas)), gnome_canvas_rect_get_type(), "x1", 100.0, "y1", 100.0, "x2", 300.0, "y2", 300.0, "fill_color_rgba", 0x3cb37180, "outline_color", "black", "width_units", 4.0, NULL); */ pixbuf = gdk_pixbuf_new_from_file("/export/home/andrae/src/outlandish/water.jpg"); if (pixbuf == NULL) { g_warning("couldn't load pixmap"); } else { pixitem = gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(canvas)), gnome_canvas_pixbuf_get_type(), "pixbuf", pixbuf, NULL); gdk_pixbuf_unref(pixbuf); } glade_xml_signal_autoconnect(xml); gtk_object_unref(GTK_OBJECT(xml)); gtk_main(); return 0; }