Zooming by dragging the mouse
in
Programming Questions
•
5 months ago
Hello,
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):
Huge thanks to anyone willing to help me.
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
void setup(){
size(500,500);
x=100; y=100;
h=200; w=200;
xsc=1; xtr=0;
}
void draw(){
background(100);
if (mousePressed && mouseButton == LEFT){
xsc -= (mouseY-pmouseY)/30.0;
xtr += mouseX-pmouseX;
}
translate(mouseX,0);
scale(xsc,1);
translate(-mouseX,0);
translate(xtr,0);
rect(x,y,h,w);
}
Huge thanks to anyone willing to help me.
1