Page 1 of 2

'Scroller' - begin to create custom controls!

Posted: Fri Jul 17, 2009 2:17 pm
by srod
Hi,

'Scroller' is a bare-bones custom control suitable for use as the basis for a whole host of custom controls which need to offer scrolling facilities. (e.g. one of the demos creates a scrollable image control which can be used straight out of the box!)

Creating any custom control is a technical and demanding process. Creating one which offers full scrolling capabilities can be very demanding indeed! :) Scroller can alleviate much of that complexity.

The first thing to say is that Scroller takes a completely different approach to scrolling than PB's ScrollArea gadget. A ScrollArea gadget uses an 'inner-container' which is moved around to simulate scrolling. A very useful control, but limited to a scrolling range of 32767 pixels due to certain Windows limitations. Custom controls based upon this gadget, therefore, will be subject to the same limitations (as I have discovered. Doh!)

Scroller has no such limitations as it does not use an inner-container. Instead it utilises the appropriate Windows messages and functions to offer it's scrolling facilities. A somewhat complex process in all and for those not in the know, slapping a set of scrollbars on a window/control does not mean that the window/control will be able to scroll it's contents etc. This is a common misconception. Windows offers nothing in the way of automating the scrolling operations etc.

Any custom control based upon Scroller can call upon the latter for all (or some) of it's scrolling needs. Scroller can handle all of the scroll-box positioning, the page sizes and physically scrolls the client area where possible.

The custom control will have to take charge of the painting in order to give some content to the control etc. but Scroller can take charge of the scrolling aspects.

See the various demo programs for some examples of putting Scroller to use.

Of course, more complex custom controls will need to override some (or even all!) of Scroller's default behaviour and take personal charge of the scrolling itself. For example, I myself shall be using Scroller as the basis of a new grid control. This control will need to override Scroller's scrolling routines in order to scroll just parts of the client area (as opposed to the entire client area!)

The relevant page on the nxSoftware site gives a lot more details about Windows scrolling than I can give here.

The Scroller download includes the following :
  • Full source code
  • A simple bare-bones demo
  • A custom demo showing a customised painting process in order to give the control some content
  • A full demo of creating a scrollable control based upon Scroller. In this case we have an ImageScroller control - a scrollable image gadget. (The equivalent using Purebasic requires 3 controls; a ScrollArea + a ScrollArea's inner container + an ImageGadget, all of which are subject to the aforementioned 32767 pixel limitation!).
There is no license. Do as you wish with any of the code. There are no warranties either other than I guarantee not to feel responsible for any mishaps caused by this code! :wink:

In cases where Scroller is perhaps not appropriate because of the need to customise the scrolling to such an extent that a new control is perhaps more suitable, Scroller could nevertheless prove useful as a learning aid for those new to the business of creating custom controls and new to the work involved in scrolling a window or control's client area. :) Indeed, whilst Scroller has been created as part of my own work, I am nevertheless making this available to others as I reckon that it could prove useful.

Please see the nxSoftware site for the download and for a more detailed description etc.

Regards.

Stephen.

Posted: Fri Jul 17, 2009 2:39 pm
by Fred
Nice piece of work, as always ;)

Posted: Fri Jul 17, 2009 2:48 pm
by srod
Fred wrote:Nice piece of work, as always ;)
Thanks Fred. 8)


Bug fixed with the ImageScroller control. Please download again. Scroller version 1.1.

Posted: Fri Jul 17, 2009 3:10 pm
by Kale
Very nice! How I hate the Win32 API especially when dealing with scrolling! You have my respect!

Posted: Fri Jul 17, 2009 3:17 pm
by srod
Kale wrote:Very nice! How I hate the Win32 API especially when dealing with scrolling! You have my respect!
Thanks Kale.

Whilst I can see why Windows does things the way it does as regarding Scrolling I can't help but agree that it does seem overly complex in places. I wonder how GTK, for example, handles it? Anyone know, for curiosity's sake?

Posted: Sun Jul 19, 2009 5:53 pm
by Erlend
Gtk handles thing pretty much the same way. i.e. you'll have to add a Gtkfixed to a GtkScrolledWindow to get widgets scrolling inside.

Posted: Sun Jul 19, 2009 6:21 pm
by ts-soft
:D
nice one

is there a plan for x64 version to?

Posted: Sun Jul 19, 2009 7:38 pm
by utopiomania
Will this break if the Team breakes PB syntax again?

Posted: Tue Jul 21, 2009 8:10 pm
by srod
@Thomas : I see no reason why this code should not run on x64. When I have time I'll take a look.

Posted: Tue Jul 21, 2009 8:19 pm
by ts-soft
> I see no reason why this code should not run on x64
"Custom demo.pb" and "Demo of image scroller.pb" creates a empty scroller on x64

Posted: Tue Jul 21, 2009 8:29 pm
by srod
ts-soft wrote:> I see no reason why this code should not run on x64
"Custom demo.pb" and "Demo of image scroller.pb" creates a empty scroller on x64
Fixed. :)

It now works with PB 64.

Posted: Tue Jul 21, 2009 8:36 pm
by netmaestro
Fixed.
Copyright infringement! Tweet!! Tweet!! Where's a bobby when you need one?

Posted: Tue Jul 21, 2009 8:39 pm
by srod
netmaestro wrote:
Fixed.
Copyright infringement! Tweet!! Tweet!! Where's a bobby when you need one?
Ah, but the relevant demo does credit you with having provided the image.
Nude picture of woman courtesy of Netmaestro and his camera spying through his neighbour's window......
Copyright satisfied methinks! :wink:

Posted: Tue Jul 21, 2009 8:43 pm
by netmaestro
Not me, the picture is yours to do as you wish. I mean, "Fixed." That belongs to Fred, you thieving limey!

Posted: Tue Jul 21, 2009 8:47 pm
by srod
netmaestro wrote:Not me, the picture is yours to do as you wish. I mean, "Fixed." That belongs to Fred, you thieving limey!
Nah, Fred stole it from fangbeast's surgeon after that incident with the hamster hiding in his boxer shorts bent on revenge after all the years of abuse!