Using RectanglePlacement properly

Hello everyone. First time post, so I hope I'm abidding by the rules.

I have a six position sprite 'film strip' of a knob that I'd like to implement as the visual element for a Slider object. But before I do that, I need to figure out how to 'subdivide' the source image for use.

From what I've seen in the forums and the API docs, my best approach would be to define a frame representing the dimensions to view a portion of the image, and then use RectanglePlacement to move the underlying image within the frame. However, I'm a bit confused of how to properly use RectanglePlacement. Currently I have the asset stored as a BinaryImage object in the project, and it's source dimensions are 96x762


Let's say my DrawableImage is defined in my editor constructor as:

bass_cut_1 = (DrawableImage*)DrawableImage::createFromImageData(BinaryData::Bass_Cut_png, BinaryData::Bass_Cut_pngSize);

And my paint() method my frame size is defined as:

juce::Rectangle<float> frameDim (96, 127);

Generic RetanglePlacement Object:

juce::RectanglePlacement framePosition(pileOFlags);

(The 'pileOFlags' is a stand-in for my lack of understanding of how to properly implement the flags for RectanglePlacement.)


And I attempt to draw the portion of the image I want using this:

bass_cut_1->drawWithin(g, frameDim, framePosition, 1);


My questions are three-fold:

- Does this seem like a reasonable approach?

- If so, what would be the proper flags to set to show only a portion of the source image, while preserving aspect ratio?

- Is there perhaps a better class/method to do this with?


Edit: I see now that the enum flags in the constructor are simply bitwise operators to be combined into a single argument. However, I still have a lack of understanding of the flags themselves, and whether or not I am considering this problem properly.

To be honest, I wouldn't use a DrawableImage for this, it's overkill when you could just use Image::getClippedImage() to create an array of sub-area Images that represent each part, and draw them into your control.

I have two other tips for you:

1. Never use C-style casts on polymorphic classes (or anything more complex than primitive numeric types)

2. Don't use filmstrips for knobs - it's sooo 1990s!

Thank you very much for your swift response!

I had seen Image::getClippedImage in the documentation (as well as a few other things from other classes), but since the assets are stored as BinaryData I was under the impression that I was locked into using the DrawableImage class.

1. Thanks for the C tip.

2. Filmstrips are what the client handed me! I'd prefer to use the visual aspects of Slider class though. Do you have a suggestion for a different/better approach as far as starting with a different asset?

Hrmmm, I wish Jules would have answered #2 as I am stuck in the 1990's!

Can anyone else chime in on the evils of FilmStrip knobs?


Main drawback AFAIC is that filmstrips are rendered to a set size. This reduces your flexibility and also means compromises if you want to support both regular resolutions and high DPI (or retina) resolutions.

If you really need to use film strips, then don't use Drawables at all, just roll your own slider class and work directly with Images.

But they really are a dreadful way to do it. You should at least ask your client to give you some vector SVG images to work with, and deal with them as an array of separate frames, not as a large image.

Ahh...Got it! Thanks Andrew and Jules (and OP for creating this thread)!