Problems with scrolling canvas, items not where they should be !



Hi,

In the code included I have managed to get a scrolling canvas view, with
one canvas item at (0,0) position. Yet there are some problems with
this,

1.) Notice how it seems to offset so it actually appears to be at
(-3,-3) or something. When the app starts the green band is thinner on
the top & left edges. I can't actually see the (0,0) position of the
canvas ! Why ?

2.) This offset appears to be the same as the distance of the red
segment, that just shows on start, from the scrollbars. I don't like
this gap. I want the canvas to go right up flush against the scrollbars.
How can I solve this ?

3.) Why when I make the window really big, bigger than the canvas scroll
region, does the canvas appear to move as if it was stuck to the right
and bottom edges of the scroll window. I would like it to remain at the
top and left edge, and just have some sort of black background show
through that suggests the edge of the canvas has been reached. How can I
do this ?

Thanks for the help,
/Lukas
#include <gtk/gtk.h>
#include <libgnomeui/gnome-canvas.h>

void destroy(GtkWidget *widget, gpointer data)
{
    gtk_main_quit();
}

int main (int argc, char *argv[])
{
    static GtkWidget *window;
    GtkWidget *scrolled_window;
    GtkWidget* canvas;
    GnomeCanvasGroup *root;
    GtkWidget* button;
    
    gtk_init (&argc, &argv);
    
    /* Create a new dialog window for the scrolled window to be
     * packed into. A dialog is just like a normal window except it has a 
     * vbox and a horizontal separator packed into it. It's just a shortcut
     * for creating dialogs */
    window = gtk_dialog_new ();
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
			(GtkSignalFunc) destroy, NULL);
    gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
    gtk_widget_set_usize(window, 300, 300);
    
    /* create a new scrolled window. */
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    
    /* the policy is one of GTK_POLICY AUTOMATIC, or GTK_POLICY_ALWAYS.
     * GTK_POLICY_AUTOMATIC will automatically decide whether you need
     * scrollbars, whereas GTK_POLICY_ALWAYS will always leave the scrollbars
     * there.  The first one is the horizontal scrollbar, the second, 
     * the vertical. */
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
    /* The dialog window is created with a vbox packed into it. */								
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window, 
			TRUE, TRUE, 0);
    
    /*create canvas */
    canvas = gnome_canvas_new();
    
    root = gnome_canvas_root (GNOME_CANVAS (canvas));
    gnome_canvas_item_new (root,
                           gnome_canvas_rect_get_type (),
                           "x1", 200.0,
                           "y1", 230.0,
                           "x2", 300.0,
                           "y2", 260.0,
                           "outline_color", "red",
                           "fill_color", "yellow",
                           "width_pixels", 8,
                           NULL);
    gnome_canvas_item_new (root,
                           gnome_canvas_rect_get_type (),
                           "x1", 0.0,
                           "y1", 0.0,
                           "x2", 100.0,
                           "y2", 80.0,
                           "outline_color", "green",
                           "fill_color", "white",
                           "width_pixels", 12,
                           NULL);
    gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0, 0, 600, 450);
    gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET (canvas));
    gtk_widget_show (canvas);
    gtk_widget_show (scrolled_window);
    
    /* Add a "close" button to the bottom of the dialog */
    button = gtk_button_new_with_label ("close");
    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			       (GtkSignalFunc) gtk_widget_destroy,
			       GTK_OBJECT (window));
    
    /* this makes it so the button is the default. */
    GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);
    
    /* This grabs this button to be the default button. Simply hitting
     * the "Enter" key will cause this button to activate. */
    gtk_widget_grab_default (button);
    gtk_widget_show (button);
    
    gtk_widget_show (window);
    
    gtk_main();
    
    return(0);
}

CC = gcc
LIBS=`gnome-config --libs gnomeui`

scrolledwin: scrolledwin.c 
	$(CC) `gnome-config --cflags gnomeui`  scrolledwin.c -o scrolledwin $(LIBS)

clean: 
	rm -f *.o scrolledwin


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