Global Mouse Position in JSUI

Bogdan Yegolayev's icon

Hi guys, here I have a dial made in JSUI. But, my problem is that the mouse position cannot be tracked inside the JSUI object and used to for example set my mouse back to the dial after adjustments. Take a look at js file

Already big thanks!

Dial bogi zeno.js.zip
zip

TFL's icon

You forgot to actually save the mouse position when clicked. Just add

mouse_state(x,y);

at the end of your function onclick();

But mouseClickX and mouseClickY only save the initial position of the cursor relatively to the jsui itself. So in order to be able to set the cursor position in absolute screen coordinates, you need to add the position of the patch window in the screen, and the position of the jsui in the patch, .

So replace your

max.pupdate(mouseClickX, mouseClickY)

by

max.pupdate(mouseClickX + box.rect[0] + patcher.wind.location[0], mouseClickY + box.rect[1] + patcher.wind.location[1]);

But then you'll notice that the mouse is still a little bit offset when you release the click. This is because of the toolbars. Either disable it (untick Toolbar in the View menu) or add an X and Y offset of the size of the toolbar (around 30px I guess). I guess you can also programmatically check if the toolba is enabled or not and automatically add or not the offset.

Beside that, I saw various weird stuff in your code, I just ignored it.

Bogdan Yegolayev's icon

that fixed my problem

Great thanks! XOXO