'Scroller' - begin to create custom controls!

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

'Scroller' - begin to create custom controls!

Post 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.
I may look like a mule, but I'm not a complete ass.
Fred
Administrator
Administrator
Posts: 18249
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Nice piece of work, as always ;)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Very nice! How I hate the Win32 API especially when dealing with scrolling! You have my respect!
--Kale

Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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?
I may look like a mule, but I'm not a complete ass.
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 115
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

:D
nice one

is there a plan for x64 version to?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Will this break if the Team breakes PB syntax again?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@Thomas : I see no reason why this code should not run on x64. When I have time I'll take a look.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Fixed.
Copyright infringement! Tweet!! Tweet!! Where's a bobby when you need one?
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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:
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Not me, the picture is yours to do as you wish. I mean, "Fixed." That belongs to Fred, you thieving limey!
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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!
I may look like a mule, but I'm not a complete ass.
Post Reply