1. Use of Scrollbars in IDE

Happy New Year everyone.

I'm trying to put together an embroidery design program with version 3.1 and the IDE, but I'm struggling to work out how to use the scrollbars. I've read the win32lib documentation and demo files, but I'm still none the wiser as how you get the contents of the window to move as the scrollbars are moved. Presumably I have to put in some code for the on_Scroll event for both scrollbars, but I can't work out from the examples I've seen exactly what's going on.

Please could somebody explain to me what the process involves to get me started.

I thought I was doing very well up to that point, I'd managed to draw a grid on the window and draw lines with mouse clicks, save and open files, erase lines by repainting the window and all sorts of things, but the scrollbars have got me stumped!

Many thanks.

Carolyn

new topic     » topic index » view message » categorize

2. Re: Use of Scrollbars in IDE

carolyn said...

I'm struggling to work out how to use the scrollbars ... how you get the contents of the window to move as the scrollbars are moved.

Hi, just to clarify, which part is giving you concern? Is it the values you get when you receive an w32HScroll event, or how to move the image?

In simple terms, the w32HScroll event tells you which scrollbar was moved and what is it's current position. You then have to calculate how much to move the image based on the change in the scrollbar's position.

By the way, I assume you are drawing the image into a child window and not the main window. In fact, I also assume you are actually doing the detail drawing onto a pixmap and then bliting it to the window during an w32HPaint event - as that is the easiest and most efficient method.

Anyhow, for example ... you have a pixmap for 1000 by 1000 pixels and a child window that shows a view into that pixmap of 400 x 400 pixels. This means that initially the child window only shows the top left 400x400 area of the full image. To see the rest you need to scroll it. So you create two bars (vertical and horizontal) in which each SMALL change represents one pixel and a LARGE change represents 100 pixels. The scale on each bars is 0 to 599, such that the thumb is at the top (vertical bar) when the scroll position is 0 and at the bottom of the bar when the position is 599. Why 599? Because that is the bottom pixel less the size of the viewport window 999 - 400. That makes it so the when the scroll thumb is at the bottom, the topmost pixel you see is 599 and the bottom pixel you see is 999 - the bottom of the image.

Now when the user moves the vertical scroll thumb to 250, for example, it means that the viewport window must show pixel number 250 as the top pixel. So, in your paint handler, you calculate the blit offset accordingly to copy the requested section of the pixmap image to the viewport window.

procedure onPaintViewPort(integer id, integer event, sequence parms) 
  vpos = getScrollPos( vertbar ) 
  hpos = getScrollPos( horzbar ) 
  bitBlt( TheViewPort,   -- copy to child window (viewport) 
             0, 0,       -- start output at (0,0) on the view port. 
             myImage,    -- copy from the pixmap containing the whole image 
             vpos, hpos, -- the upper left corner from where to start copying. 
             400, 400,   -- copy a 400x400 pixel portion 
             SRCCOPY )   -- do an exact pixel copy 
end procedure 

All the scroll event has to do is trigger a repaint of the view port.

procedure onScrolling(integer id, integer event, sequence parms) 
    repaintWindow(TheViewPort) 
end procedure 

Have a look at the 'scroller.exw' and 'scrollbg.exw' demos again.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Use of Scrollbars in IDE

That's helpful, thank you. I'd decided that I probably needed to use a graphic control rather than drawing straight onto the window, but it hadn't occurred to me to use a child window. I haven't needed more than one window for anything yet!

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu