Re: Forcing GtkScrolledWindow to sroll
- From: Carlos Pereira <jose carlos pereira ist utl pt>
- To: GTK App Developers List <gtk-app-devel-list gnome org>
- Subject: Re: Forcing GtkScrolledWindow to sroll
- Date: Mon, 11 Jan 2010 22:21:07 +0000
Then I want to implement a "drag" scrolling. The user will click and drag the image to make it scroll.
To write drag code in GTK you basically need to handle signals
"button_press_event" and "motion_notify_event", as exemplified below.
Essentially drag operations depend of the difference between current x,y
coordinates and old begin_x, begin_y coordinates (that you need to save
yourself).
my_bool my_callback_notify (GtkWidget *widget,
GdkEventMotion *event, void *data)
{
my_structure = (cast to my_structure) data;
...
if (event->is_hint) gdk_window_get_pointer (event->window, &x, &y, &state);
else
{
x = event->x;
y = event->y;
state = event->state;
}
if (state != 0)
{
dx = y - my_structure->begin_x;
dy = y - my_structure->begin_y;
/* drag code: do something with dx, dy */
...
}
my_structure->begin_x = x;
my_structure->begin_y = y;
return TRUE;
}
my_bool my_callback_press (GtkWidget *widget,
GdkEventButton *event, void *data)
{
my_structure = (cast to my_structure) data;
...
my_structure->begin_x = event->x;
my_structure->begin_y = event->y;
return TRUE;
}
Generally, you don't want to do this because it is inefficient if the
image is large. Do not allocate a larger drawing area than the visible
part, do not use a viewport and, instead, just draw the visible part of
the image according to the scrollbar positions in the expose event.
I agree. By the way, do you need scrollbars at all? they might be
usefull, to tell users how far are the image limits, but if they are
cumbersome to use, it might be reasonable to discard them at all. An
example of this is Google Maps, where you drag a drawing area with no
scrollbars (of course this is an ideal example, because there are no
image limits...). That would be easy to implement in GTK, you would use
(dx,dy) to know what part of the image you want to show. And if you
really need to tell users about the limits, perhaps you could use rulers
on the side. My point is, 1-D scrolling becomes redundant when you have
2-D dragging, more user-friendly...
Carlos
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]