// left mouse = move ball
// right mouse = reset to center
// ctrl + left mouse = X-axis only
// alt + left mouse = Y-axis only

// New: (with disabled 'slider_automate' in the code...)
// Use the XY sliders for Parameter Modulation Slider Linking.
// Draw envelopes for the 'linked' FX parameters
// instead for the XY sliders... (Reaper 'touch recording' bug ???)

// Old: (with enabled 'slider_automate' in the code)
// Use only 'write' mode when drawing automation envelopes for the XY sliders !!!
// Reaper 'touch/latch' mode has bugs with slider_automate ???
// Workaround for 'touch/latch' mode:
// Don't create envelopes for the parameters of this plugin !!!
// Instead create envelopes for the VST parameters you have 'linked to' from this plugin,
// then write these envelopes in 'touch/latch' mode with the XY sliders !!!

slider1:50<0,100,1>-X Position (Link Me!!!)
slider2:50<0,100,1>-Y Position (Link Me!!!)

in_pin:none
out_pin:none

@init
gfx_clear = 0x202020;

@slider
//slider1 = tmpA;
//slider2 = tmpB;

@gfx 652 652
gfx_getchar();

gCenterX = gfx_w * 0.5;
gCenterY = gfx_h * 0.5;

(mouse_cap == 1) ? (
v1 = (mouse_x - gCenterX) / gCenterX;
v2 = -(mouse_y - gCenterY) / gCenterY;
);
(mouse_cap == 2) ? (
v1 = 0;
v2 = 0;
);
(mouse_cap == 5) ? (
v1 = (mouse_x - gCenterX) / gCenterX;
);
(mouse_cap == 17) ? (
v2 = -(mouse_y - gCenterY) / gCenterY;
);

v1 = min(max(v1,-1),1);
v2 = min(max(v2,-1),1);
tmpA = floor((v1+1)*50);
tmpB = floor((v2+1)*50);
slider1 = tmpA;
slider2 = tmpB;
sliderchange(slider1);
sliderchange(slider2);
//slider_automate(slider1); // disabled
//slider_automate(slider2); // disabled

small_mode = gfx_w<110 || gfx_h<110;

// Draw readout
small_mode ? font_size = 15 : font_size = 50;
gfx_setfont(1, "Lucida Sans Unicode", font_size);
gfx_r=1; gfx_g=0.8; gfx_b=0.2; gfx_a=0.5;
gfx_x = gCenterX-floor(font_size/2);
gfx_y = gCenterY-floor(font_size/2)+25;
gfx_drawnumber(tmpA,0);
gfx_x = gCenterX-floor(font_size/2);
gfx_y = gCenterY-floor(font_size/2)-25;
gfx_drawnumber(tmpB,0);

// Draw grid
gfx_r=gfx_g=gfx_b=0.25;
gfx_line(0, gfx_h/2, gfx_w, gfx_h/2);
gfx_line(gfx_w/2, 0, gfx_w/2, gfx_h);

// Draw circle
gfx_r=0.8; gfx_g=0.2; gfx_b=0.2; gfx_a=1;
small_mode ? gfx_circle((v1+1)*gCenterX,(-v2+1)*gCenterY,8,1,1) : gfx_circle((v1+1)*gCenterX,(-v2+1)*gCenterY,20,1,1);
