Here's a handy superflexible spinnergadget!

BlitzMax Forums/MaxGUI Module/Here's a handy superflexible spinnergadget!

CS_TBL(Posted 2007) [#1]
Tadaa!

So, what's so special about it? There's lots of explanation in the tsmartspinner file, but in short:

<> can look like anything, by using your own hooked *external* functions, you never need to touch the smartspinner core

<> horizontal or vertical dragging with polarity choice

<> supports cursors, home, end, page up/dn, mousewheel

<> each spinner can record a value into one of the 10 slots, and one can easily recall such values with a single keypress

<> has one built-in simple displayer, showing the actual value, and with shadow & color options

<> right-mouse-button generates a gadgetaction event

So what can you do with it?

Obviously it's a spinner, so whenever you want a box with a number you can change: smartspinner is your solution.
It has tactful events, telling you when spinning starts, happens and stops. This is convenient when some renderer is constantly rendering according to values defined in these spinners. When changing these values the start and stop events could tell the renderer to temporarily stop rendering and continue when the new value is set.

The real power lies in the external drawing. Rather than bloating the original type with zillions of styles, it now sends out an update event while a canvas is opened for drawing. As long as you make a function that listens to that event, this function can be your new spinnerstyle. Two examples are given, one as a hooked function, and one as a hooked method in a type.

Examples of new drawing functions:
- display the (int) value as a float, by dividing it by 10000 orso
- have a strip of images in a type of a rotating knob, and draw this knob
- have a lookup table with strings in a type and draw these strings (0: "yes", 1: "no", 2: "cancel"), with the rightclick you can click this spinner and so this spinner more or less acts as a normal button of which the content can change.
- make a displayer using your own font


Using it requires barely any brains. If there are no spinners included then it still works, even if you've set a smartspinner to refer to one. Another advantage of using events, so to say..

I created wrapper functions to define things, whereas some would've preferred methods. I purely chose this way to make it look uniform with Blitz' own gadget functions. It isn't much work to make 'em methods nonetheless, allthough I don't think you really gain something with it. (and I don't feel like doing it :P)

So, have a go with it, if there're no obvious flaws, I'll dump it in the archives.

(oh, minor detail: I've tested it only on my 98 system in Bmax1.22 :P)

tsmartspinner_example.bmx


tsmartspinner_spinners.bmx


tsmartspinner.bmx



LAB[au](Posted 2007) [#2]
I got "attempt to access field or method of a null object" in tsmartspinner.bmx ...

Method ev(event:TEvent)

If event.source=canvas
... on this line.


CS_TBL(Posted 2007) [#3]
Odd, here everything works like a charm. I might be trying 1.24 then.

Do you get this when running the given stuff?


LAB[au](Posted 2007) [#4]
I just wrapped a If event <> Null ... EndIf on these ev methods and now everything works.


CS_TBL(Posted 2007) [#5]
But did you get that error with my example program?


LAB[au](Posted 2007) [#6]
Yes.