I've recently (a few days ago) started using Processing and have decided to make a kind of music sequencer that allows the user to use a graphics tablet to draw in data that is later sent via OSC to another program that handles the sound engine (in my case puredata), but I have a problem with making the thing zoom in and out like I want it to.
The zooming is controlled in a manner similar to Ableton Live which works something like this:
The user clicks an area at the top of the screen and then drags the mouse left and right to move the screen left and right and drags the mouse up and down to zoom in and out (zooming is centered around the mouse).
My current code looks something like this (this is a simplified version where you only zoom a rectangle):
float x,y,h,w; // dimensions of the rectangle float xsc,xtr; // current zoom and translation values
I have tried a few different approaches and this is the one that got the closest to working properly, but it scrolls left and right when the mouse button is not pressed and the value of xsc != 1. I think I should multiply one of the translate(+/-mouseX, 0); parts with something, but I haven't been able to figure it out, so if anyone has a good idea to fix the problem or maybe another more elegant approach to doing this, please let me know.