Styles in GnomeCanvas?




I figured out the solution to my last question (changing the background
color in GnomeCanvas), but now I'm having another problem that may not be
as easy for me to solve. When I set the bg_pixmap[GTK_STATE_NORMAL] of a
GnomeCanvas, it displays my image once and then removes it. I'm not sure
if GnomeCanvas supports having a background pixmap normally. Here's the
entire main() of my code (it's just a slightly modified version of the
GnomeCanvas example code). I'm not sure why the GnomeCanvas seems to
repaint the window to its normal color (so that bg_pixmap isn't shown
anymore) apparently after gtk_main() is called.

int main(int argc, char **argv)
{
   GtkWidget *window;
   GtkWidget *vbox;
   GtkWidget *hbox;
   GtkWidget *button;
   GtkWidget *frame;
   GtkWidget *canvas;
   GtkStyle *style;
   GdkImlibImage *im;
   GdkPixmap *pic;

   gnome_init("canvas-test", NULL, argc, arv);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   vbox = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(window), vbox);
   gtk_widget_show(vbox);
   frame = gtk_frame_new(NULL);
   gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
   gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
   gtk_widget_show(frame);

/* Create the canvas */
   canvas = gnome_canvas_new();
   gnome_canvas_set_size(GNOME_CANVAS(canvas), CANVAS_SIZE, CANVAS_SIZE);
   gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0.0, 0.0,
                                  CANVAS_SIZE, CANVAS_SIZE);
   gtk_container_add(GTK_CONTAINER(frame), canvas);

/* Set the background pixmap to "space.png" */
   im = gdk_imlib_load_image("space.png");
   gdk_imlib_render(im, im->rgb_width, im->rgb_height);
   pic = gdk_imlib_move_image(im);
   style = gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(canvas)));
   style->bg_pixmap[GTK_STATE_NORMAL] = pic;
   gtk_widget_set_style(GTK_WIDGET(canvas), style);

   gtk_widget_show(canvas);

   hbox = gtk_hbox_new(TRUE, 0);
   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
   gtk_widget_show(hbox);

   button = gtk_button_new_with_label("Add an object");
   gtk_signal_connect(GTK_OBJECT(button), "clicked",
                      (GtkSignalFunc) add_object_clicked,
                      canvas);
   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
   gtk_widget_show(button);
   button = gtk_button_new_with_label("Exit");
   gtk_signal_connect(GTK_OBJECT(button), "clicked",
                      (GtkSignalFunc) exit_clicked, window);
   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
   gtk_widget_show(button);

   gtk_signal_connect(GTK_OBJECT(window), "delete_event",
                      (GtkSignalFunc) delete_event, NULL);
   gtk_widget_show(window);

   gtk_main();
   return 0;
}




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