How do I get the pixel data under the mouse cursor?
-
Say I have a panel, and inside it there are two sub panels, each one containing a PNG image. The PNG images have transparency. I want to sweep the mouse across the top level panel, and have each sub panel process the pixel under the mouse, and return a true if the pixel is transparent (taking a threshold into account) or a false if it isn't.
How would I do this?
-
@Orvillain said in How do I get the pixel data under the mouse cursor?:
How would I do this?
I don't think this is possible
-
@d-healey Because there's nothing like a getPixelData(x=a, y=b) method for panels I guess?
-
@Orvillain Correct
-
@d-healey ahhhhhhhh suckage. Hmmmm. I can definitely provide X/Y data in a JSON file, and parse the current position in relation to that, to be able to detect which image I am hovered over. But these images might overlap... which meannnnnssss.... hmmm, I need to think about it some more.
Basically the goal here is... load a bunch of film strips that can potentially overlap with some transparent areas.... click on one of them, and trigger the filmstrip animation. But I can foresee that if the images are overlapping, I'll end up triggering the wrong animation if I click in a particular area where they overlap unintuitively.
The ideal solution would be to parse the current pixel (or pixels in a grid around the mouse cursor) and detect if that particular sub panel is transparent or not. If it is, don't trigger the filmstrip animation. If it isn't, then trigger it.
-
@Orvillain you need to rethink that entire approach, even in JUCE it's almost impossible to query the actual pixel at a given position because the image data is passed to the GPU so the CPU will not now the blended state.
-
@Christoph-Hart said in How do I get the pixel data under the mouse cursor?:
@Orvillain you need to rethink that entire approach, even in JUCE it's almost impossible to query the actual pixel at a given position because the image data is passed to the GPU so the CPU will not now the blended state.
Thanks. The only other thing that springs to mind right now is:
Assemble the filmstrip panels as I want them.
Provide a JSON file that gives click zone co-ordinates.
On a click, check the current position, and check if it falls within a specific coordinate region.
If it does, tell the film strip to animate.
If it doesn't, do nothing. -
@Orvillain I could add a wrapper to Path.contains(), then you can at least create shapes with hit zones using paths and test the hover state with the mouse positions, this relieves you from the burden of weird geometry and a JSON file.