Lost with LookAndFeel for custom component


#1

So... I want my Sliders to have a default value, an assignable Image resource, an assignable "number of frames" to deal with filmstrips, and a few connected functions (set/get/reset) each. I've created my custom class rchSlider : public Slider etc. to do this, and all the various values and functions appear to be working fine so far.

Now I want to swap the vector drawing against a filmstrip, which already works well when I manipulate the original JUCE module.

But I would prefer a lot to deal with filmstrips in a "clean" way, with something like the void drawRotarySlider(xxx) function of LookAndFeel, and not compromising the integrity of the JUCE framework by hacking around in its sources.

Been screwing around with this for hours now, searching the Web for ages and trying out all sorts of approaches.
struct rchLookAndFeel : public LookAndFeel, class rchLookAndFeel : public LookAndFeel, yada yada.
But whatever I try, it just won't work.

The big issue seems to be that the void drawRotarySlider(xxx) in LookAndFeel expects a Slider& slider, which works fine for drawing some vector arcs and paths that calculate themselves from position and size of the component. But to access the Image resource and the "number of frames" value that I need to make the filmstrip work, I would have to pass a rchSlider& slider into the void drawRotarySlider(xxx) ... and of course the standard void drawRotarySlider(xxx) doesn't like that.

Can anyone point me in the right direction? Can I somehow override the void drawRotarySlider(xxx) inside my class rchSlider? I attempted that already and failed, but I only had half a clue of what I was doing, so... or is it somehow possible to create (for example) something like a void drawRchSlider(xxx) that extends LookAndFeel, accepts an rchSlider& slider and is somehow automagically connected to my custom rchSlider class?

Thankful for any hints!

Cheers,

Rob


#2

Derive your own LnF class and add the drawRotarySlider method with the expected signature which accepts Slider& slider. Then dynamic_cast slider to rchSlider as follows:

rchSlider* myRchSlider = dynamic_cast<rchSlider*> (&slider);

This is fine if your LnF is only used for rchSlider objects.

If you want to use it generically then you’ll need to test the slider type. If (myRchSlider != nullptr) then you’re good to go with your bitmap strip, otherwise call the base version of drawRotarySlider.


#3

Have started using the void paint() of the rchSlider component to stop it from going into LookAndFeel at all.
Seems to be going somewhere, but some of the parameters I need to pass into there are still a puzzle...

But thank you for that hint, I'll try it in a minute!


#4

After a lot of pointer frustration (I hate those brutes...) I finally got it working.

Thank you for that final nudge, much appreciated! :)


#5

Or make a derived L&F class, and store the filmstrip image and number of frames there instead of in a customized slider class.  That way the information about how a slider looks and is drawn is contained completely in the L&F, and you can switch back and forth between different filmstrips or procedural renderings and even back to the default L&F just by what you pass to setLookAndFeel().

 


#6

Yeah - I should have said that too :)