errante
February 15, 2025, 9:54pm
1
Currently you can get mouse coordinates when reacting to an event in a script dialog via the Msg
object, but these are relative to the screen rather than the dialog itself. Although you can do some math to convert these coordinates to be relative to the dialog, it would only be an approximation because there are unknowns (like the titlebar height, etc.).
Is there any way to achieve that? I want to show a control exactly where the mouse pointer is (Assuming that its coordinates are within the space of the dialog window in question).
Leo
February 19, 2025, 6:14pm
2
We'll add methods for this in the next beta.
Example of how it can be used:
Script Code:
function OnClick(clickData)
{
var dlg = DOpus.Dlg();
dlg.window = clickData.func.sourcetab;
dlg.template = "mousePosDialog";
dlg.detach = true;
dlg.Create();
dlg.SetTimer(100, "mouseTimer");
dlg.Show();
var ctrlSX = dlg.Control("staticSX");
var ctrlSY = dlg.Control("staticSY");
var ctrlCX = dlg.Control("staticCX");
var ctrlCY = dlg.Control("staticCY");
while(true)
{
var msg = dlg.GetMsg();
if (!msg.result)
break;
if (msg.control == "mouseTimer")
{
var t = dlg.ScreenToClient(msg.mousex, msg.mousey);
ctrlSX.label = String(msg.mousex);
ctrlSY.label = String(msg.mousey);
ctrlCX.label = String(t.left);
ctrlCY.label = String(t.top);
}
}
}
Resources:
<resources>
<resource name="mousePosDialog" type="dialog">
<dialog height="48" lang="english" title="Mouse Pos Example" width="114">
<control halign="left" height="8" name="static1" title="Screen:" type="static" valign="top" width="30" x="12" y="12" />
<control halign="center" height="8" name="staticSX" title="SX" type="static" valign="top" width="20" x="48" y="12" />
<control halign="left" height="8" name="static4" title="x" type="static" valign="top" width="6" x="72" y="12" />
<control halign="center" height="8" name="staticSY" title="SY" type="static" valign="top" width="20" x="84" y="12" />
<control halign="left" height="8" name="static2" title="Client:" type="static" valign="top" width="30" x="12" y="30" />
<control halign="center" height="8" name="staticCX" title="CX" type="static" valign="top" width="20" x="48" y="30" />
<control halign="left" height="8" name="static5" title="x" type="static" valign="top" width="6" x="72" y="30" />
<control halign="center" height="8" name="staticCY" title="CY" type="static" valign="top" width="20" x="84" y="30" />
</dialog>
</resource>
</resources>
1 Like