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

Re: "Virtual" Scrolling?



On 11/07/98 SEGV uttered the following other thing:
> Is there an example somewhere I can look at of "virtual" scrolling? By
> that I mean, instead of just putting a bigger widget in a smaller
> scrolling container, actually drawing a scrolling container sized
> image myself based on the scroll position.
> 
> That is, I want to have a pixmap the size of a scrolled window, which
> is drawn to according to the scroll position, then copied into the
> scrolled window, giving the impression of a much larger image.
> 
> I have everything working, except I can't see how to get the scroll
> position. In fact, while I'm at it, I'd like to see how to
> programmatically set it also.
> 
> >From what I can figure out, my drawing area is in a viewport which is
> >in a
> scrolled window. The scrolled window and viewport have adjustments
> associated with them, which do things when changed. I assume the
> default setup is to scroll the drawing area when changed.
> 
> Is that correct? What should I be reading, the viewport's adjustments,
> or the scrolled windows? I changed the adjustments programmatically
> but that did nothing.

I'm going from memory, but essentially you don't need the viewport or
scrolled window (I believe those are used when you are actually
containing a larger widget in a smaller area, ie if you had the entire
image in the drawing area, but the viewport was of only a part of that).

/* Create an adjustment, see section 7.1 of the tutorial for what these
 * are */
GtkObject *adj;
GtkWidget *vscrollbar;

adj = gtk_adjustment_new (0, 0, 15, 1, 5, 5);

/* Create the scroll bar, using the adjustment you just created */
vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT(adj));

/* add it to your window however you want */

/* show it */
gtk_widget_show (vscrollbar);

/* Connect to the changed signal */
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
    GTK_SIGNAL_FUNC (vscroll_callback), NULL);

In the callback, you can just grab the value out of the adjustment:
void vscroll_callback (GtkAdjustment *adj, gpointer data)
{
  vertical_position = adj->value;
}

To change the values in the adjustment (say, when loading a new image of
different size into the drawing area), you can change the values in the
adjustment struct directly, and then emit the changed signal:

void load_image ()
{
  /* load image */
  /* new values for scrollbars */
  adj->lower = 0;
  adj->upper = 100;
  adj->value = 0;
  adj->step_increment = 1;
  adj->page_increment = 5;
  adj->page_size = 10;
  gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed");
}

There are some convenience functions for setting these values, see the
source in gtkadjustment.c for more information on what they do.

Brandon
-- 
 Brandon Long          "Quantum Mechanics: The dreams stuff is made of"
 Fiction Networks                              -- Steven Wright
 blong@fiction.net		  http://www.fiction.net/blong/



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