Hi,
Is it possible in AE scripting/ScriptUI to get the absolute window position of a floating dockable palette, or one of its child elements?
I'm trying to open a new dialog directly underneath a button when it is clicked, so I need screen coordinates of either the button itself or the palette (from which I can then calculate the relative position).
Obviously if I report the bounds or location of a button it returns it to me relative to its container. If I attempt to access frameBounds on the palette I get an "undefined" error, whereas the bounds of the palette always have 0,0 coordinates for the top-left.
If neither is possible, can you get the mouse pointer coordinates instead?
Many thanks,
Christian
Thanks Dan, but I can't get it to work. Here's my code:
{
// Object UI Constructor
function UI() {
this.myUI = null;
}
UI.prototype.buildUI = function(thisObj) {
var me = thisObj; // Because in onButtonClick(), "this" isn't this "this", so make "me" this "this"!
function addButton(container, buttonBounds, txt, id) {
var btn = container.add("button", buttonBounds, txt);
btn.id= id;
btn.onClick = onButtonClick;
return btn;
}
function onButtonClick() {
alert(me.frameBounds.left + ", " + me.frameBounds.top); // It's here where it fails - obviously I'm accessing the wrong thing, so how do I get the frameBounds of the palette from within here?
// Create the dialog, which I want underneath the button just clicked
var res = "dialog { alignChildren: 'left', margins: 5, spacing: 5}";
var dlg = new Window(res);
dlg.bounds = [0, 0, 100, 200];
dlg.location = [500, 500]; // Will eventually be underneath the button that invoked the dialog
dlg.show();
}
if(thisObj instanceof Panel) {
this.myUI = thisObj;
} else {
this.myUI = new Window("palette", "UI Test");
}
this.myUI.margins = 0;
this.myUI.grp = this.myUI.add("group", [0,0,200,30]);
this.myUI.grp.spacing = 0;
this.myUI.grp.alignChildren = "[right, top]";
// Add a couple of buttons
addButton(this.myUI.grp, [0, 0, 50, 25], "Foo", 0);
addButton(this.myUI.grp, [0, 0, 50, 25], "Bar", 1);
// Show the palette
this.myUI.layout.layout(true);
// Resize code
this.myUI.grp.minimumSize = this.myUI.grp.size;
this.myUI.layout.resize();
this.myUI.onResizing = this.myUI.onResize = function () {this.layout.resize(); }
}
// Main
var ui = new UI();
ui.buildUI(this);
}
I'm probably doing something stupid, so any help would be appreciated!
Thanks,
Christian
Actually I'm trying to work this out at the moment, trying to find the position of a docked panel.
//=======================================================
var w = Window.find("","TheWindowName");
alert(w.frameBounds.left + ", " + w.frameBounds.top);
//=======================================================
I think it's excluded from the Script UI (window, palette, dialog). Alternatively the Scripting guide(UI) says you can put in a
resourceName which I presume is a variable?
Any pointers appreciated...?
So here I am using a global to reference a docked panel...
//=======================================================
var pnl = (thisObj instanceof Panel) ? thisObj : new Window("palette", "", [200, 200, 1265,242]);
gReference = pnl;
//So from another script...
//instead of :
var w = Window.find("","TheWindowName");
//using this
var w = Window.find(gReference);
alert(gReference.windowBounds); // incorrect because it's a panel not a window.
alert(gReference.location); // [0,0] relative.
//finds the docked panel... all good but the frameBounds/windowBounds property doesn't exist for "Panel".
//so I can't find the screen position of an element only it's relative position in the panel.
//dead end?
Just found out that it's possible to retrieve the cursor's absolute location using an eventlistener. From the ScriptUI for Dummies guide by Peter Kahrel:
var w = new Window ("dialog");
var b = w.add ("button", undefined, "Qwerty");
b.addEventListener ("click", function (k) {whatsup (k)});
function whatsup (p)
{
if (p.button == 2) {$.writeln ("Right-button clicked.")}
if (p.altKey) {$.writeln ("Alt key pressed.")}
$.writeln ("X: " + p.clientX);
$.writeln ("Y: " + p.clientY);
}
w.show ();
But this still gives a relative value. The CS6 Tools Guide (p.153) says you can also use screenX and screenY. So slightly modified:
var w = new Window ("dialog");
var b = w.add ("button", undefined, "Qwerty");
w.addEventListener ("click", function (k) {whatsup (k)});
function whatsup (p)
{
$.writeln ("X: " + p.screenX);
$.writeln ("Y: " + p.screenY);
w.close();
}
w.show ();
This returns the absolute location when the button is clicked. Which in turn, you can pass to the bounds of the new window.
Alternatively you might be able to show() a group or UI element when the button is clicked.
North America
Europe, Middle East and Africa
Asia Pacific