//. Moon Video Controls
//We want to specify the top, bottom, width and height of the video view.
//This will never change as zoom and pan change
// 'name' [defval minval maxval centval step]
//
@param 1:opacity 'Opacity' 1 0 1 0.5 0.01;
//@param 2:zoom 'Zoom' 1 1 5 2.25 0.05
//@param 3:x_pan 'Horiz Pan' 0 -1 1 0 0.01
//@param 4:y_pan 'Vert Pan ' 0 -1 1 0 0.01
//@param 6:coarse_y 'Bottom/Top' .5 0 1 .5 0.01
//@param 7:coarse_x 'Left/right' .5 0 1 .5 0.01
//@param 8:coarse_h 'Height' .5 0 1 .5 0.01
//@param 9:coarse_w 'Width' .5 0 1 .5 0.01
//@param 11:fine_y 'Top-fine' 0 -1 1 0 0.01
//@param 12:fine_x 'Left-fine' 0 -1 1 0 0.01
//@param 13:fine_h 'Height-fine' 0 -1 1 0 0.01
//@param 14:fine_w 'Width-fine' 0 -1 1 0 0.01
//@param 16:asp 'Keep Aspect' 1 0 1 0 1;
img1=0;
img2=input_track(0); //this is the actual image
gfx_blit(img2);
input_info(img1, sourceW, sourceH);
fine = .01;
//HEIGHT AND WIDTH
percentH = (coarse_h + (fine * fine_h));
percentW = (coarse_w + (fine * fine_w));
percentX = (coarse_x + (fine * fine_x));
percentY = 1 - (coarse_y + (fine * fine_y)); //for more natural knob motion
//dont allow frame to go off the edges
rangeX = percentX * (1 - percentW);
rangeY = percentY * (1 - percentH);
//convert percents to pixels
frameH = percentH * project_h;
frameW = percentW * project_w;
frameX = rangeX * project_w;
frameY = rangeY * project_h;
//don't let us zoom out too far,
//the minimum zoom should be larger for smaller frames
smaller = min(percentH, percentW);
zoomAdj = zoom / smaller;
viewW = sourceW / zoomAdj;
viewH = sourceH / zoomAdj;
//this code works pefectly for the minimum dimension
//in the denominator of zoomAdj, but allows way too much in the max dim.
xPanAdj = x_pan;
yPanAdj = y_pan;
//The following gets closer, but still allows too much pan in one direction
xPanAdj = x_pan * (smaller / percentW);
yPanAdj = y_pan * (smaller / percentH);
viewX = ((sourceW - viewW) / 2) * (1 - xPanAdj);
viewY = ((sourceH - viewH) / 2) * (1 - yPanAdj);
//Ideally we would never see this painful color...
gfx_set(1,0,0,opacity);
gfx_mode = 256;
//gfx_blit(input,aspect,x,y,w,h,srcx,srcy,srcw,srch);
gfx_blit(img1,asp,
frameX, frameY, frameW|0, frameH|0, //pipe-zero truncates any decimal
viewX, viewY, viewW|0, viewH|0
);