Get size/visibility of toolbar in Max?
I'm trying to determine the global (screen) location of the top-left of a patcher but it seems that you need to know the height/size of the toolbar otherwise the reported location from patcher.win.location is incorrect (can be confirmed by turning off the toolbars).
Does anyone know the proper way to compensate for this? I've tried searching for information regarding the toolbarvisible property but there seems to be no way of reading this or if there is there's no information regarding the size of the toolbar.
The thispatcher Max object can give this information

But I don't see a way to do it in js. this.patcher.window("getwindowrect") doesn't work.
This is a way to get the toolbarvisible attribute: this.patcher.getattr("toolbarvisible")
the toolbar size could change over runtime versions, so it makes sense that an external can do it but not js.
i had a similar issue with the menubars of the 4 different macos i use and "solved" it by always hiding it, then 0 0 is always 0 0.
Fortunately, we can script-create any object, send it a message and get the result before you can even say cheating.
function bang()
{
var myObject = this.patcher.newdefault(0,0,"thispatcher");
this.patcher.connect(myObject,0,this.box,0);
myObject.message("window", "getwindowrect");
this.patcher.remove(myObject);
}
function window()
{
if (arguments[0] == "windowrect")
post("windowrect:", arguments[1],arguments[2],arguments[3],arguments[4]);
}
Yeah, there's a few way to fake it. Something I'm doing at the moment is constantly sending the output from `mousestate` (global screen position) into my JSUI object (using polling mode). Inside the JSUI I'm using the difference between two points. Point A is the X/Y origin of where the pointer was when the user clicks inside the JSUI subtracted from the X/Y position of the JSUI window inside the Max window (`this.box.rect` information of the JSUI). Point B is the global position of the mouse (`mousestate`) when the user clicks the mouse button. The X/Y difference between these two gives you the correct offset to calculate the position of the click inside your JSUI, *inside* the Max window, *inside* your screen. It works but having to pipe the `mousestate` constantly into the JSUI is a bit icky.
That wasn't aimed at you @11olsen
This is confusing. What type of coordinates you want to get for the click?
What I'm trying to do is hide the mouse pointer when you click and drag an element inside a JSUI so when you release the mouse button it's position is restored to where you clicked via `pupdate(x,y)`. The difficulty arises because pupdate() uses screen-based coordinates and the window/rectangle parameters inside Max don't take into account the toolbar.

Here's a video of it in action using the `mousestate` method I described. You'll see the mouse pointer reappears over the node after I've stopped dragging it, even though in the real world the mouse pointer has likely gone way outside of the frame of the JSUI.
Ok, I get it now. If you use the patcher rect attr instead of the wind.location, your calculation should work without [mousestate].
function onclick(x,y,but,cmd,shift,capslock,option,ctrl)
{
//box2screen
post(this.patcher.getattr('rect')[0] + x + this.box.rect[0]);
post(this.patcher.getattr('rect')[1] + y + this.box.rect[1]);
post();
}
Thanks! I'll give that a try.
That's working perfectly! Thank you so much 🙏
You also need to have in mind that patcher scrolling is changing the position. And zooming may also affect the result.
Good point. It's a great start though!