drawing area in a scrolled window
- From: "Christopher Garrett" <ctg24 admin cam ac uk>
- To: <gtk-app-devel-list gnome org>
- Subject: drawing area in a scrolled window
- Date: Sun, 10 Jun 2007 13:44:38 +0100
Hi,
I have coded a drawing area (which has a gdkpixbuf rendered to it), which sits
inside an alignment (0.5, 0.5, 0, 0) which itself is inside a viewport
associated with a GtkScrolledWindow. Scrolling works as expected, and if the
window is resized to be bigger than the drawing area you see a grey border
filling the area between the drawing area and the scrollbars / edge of the
viewport.
However, I have only been able to get mouse coordinates from the drawing area.
I would like to get coordinates from the origin in the top left of the scrolled
window. What do I need to do? I tried getting coords from the alignment, but
that seems to cover exactly the same area as the drawing area itself...
I provide a code snippet below. If anyone wants the full listing (its not long
- its purely to test this implementation problem) I can send it to them.
Best regards,
Chris.
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
canvas->darea=gtk_drawing_area_new();
canvas->scrollarea = gtk_scrolled_window_new(NULL, NULL);
alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
gtk_widget_set_size_request(canvas->darea, canvas->width, canvas->height);
gtk_box_pack_start(GTK_BOX(vbox), canvas->scrollarea, TRUE, TRUE, 0);
horizontal =
gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(canvas->scrollarea));
vertical =
gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(canvas->scrollarea));
viewport = gtk_viewport_new(horizontal, vertical);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(canvas->scrollarea),
alignment);
gtk_container_add(GTK_CONTAINER(alignment), canvas->darea);
g_signal_connect(GTK_OBJECT(canvas->darea), "expose-event",
GTK_SIGNAL_FUNC(imcanvas_on_expose), (gpointer) canvas);
g_signal_connect(GTK_OBJECT(canvas->darea), "motion_notify_event",
GTK_SIGNAL_FUNC(imcanvas_motion_notify_event), (gpointer) canvas);
g_signal_connect(GTK_OBJECT(canvas->darea), "button_press_event",
GTK_SIGNAL_FUNC(imcanvas_button_press_event), (gpointer) canvas);
g_signal_connect(GTK_OBJECT(canvas->darea), "button_release_event",
GTK_SIGNAL_FUNC(imcanvas_button_release_event), (gpointer) canvas);
gtk_widget_set_events(canvas->darea, GDK_EXPOSURE_MASK
| GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK
| GDK_BUTTON_RELEASE_MASK
);
GTK_WIDGET_SET_FLAGS(canvas->darea, GTK_CAN_FOCUS);
gtk_window_set_focus (GTK_WINDOW(window), canvas->darea);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]