Mouse position: Difference between revisions
Content deleted Content added
Lingo added |
|||
Line 704: | Line 704: | ||
say .getX, 'x', .getY; |
say .getX, 'x', .getY; |
||
}</lang> |
}</lang> |
||
=={{header|Phix}}== |
|||
The following example shows three labels being updated with the mouse position.<br> |
|||
The globalmotion label is updated whenever the mouse moves anywhere within the window, but not outside it.<br> |
|||
The canvasmotion label is updated whenever the mouse moves within the canvas, but not elsewhere in the window.<br> |
|||
The timer label is updated every three seconds and gets mouse positions anywhere on the whole screen, whether it moves or not.<br> |
|||
Note that cursormotion coordinates are relative to the top left of the canvas, whereas the other two are absolute. |
|||
<lang Phix>-- |
|||
-- demo\rosetta\Mouse_position.exw |
|||
-- |
|||
include pGUI.e |
|||
Ihandle global_lbl, canvas_lbl, timer_lbl |
|||
function globalmotion_cb(integer x, integer y, atom /*pStatus*/) |
|||
IupSetStrAttribute(global_lbl,"TITLE","globalmotion_cb %d, %d",{x,y}) |
|||
return IUP_DEFAULT |
|||
end function |
|||
function canvas_motion_cb(Ihandle /*canvas*/, integer x, integer y, atom pStatus) |
|||
IupSetStrAttribute(canvas_lbl,"TITLE","canvasmotion_cb %d, %d",{x,y}) |
|||
return IUP_DEFAULT; |
|||
end function |
|||
function OnTimer(Ihandle /*ih*/) |
|||
integer {x,y} = IupGetIntInt(NULL,"CURSORPOS") |
|||
IupSetStrAttribute(timer_lbl,"TITLE","timer %d, %d",{x,y}) |
|||
return IUP_IGNORE |
|||
end function |
|||
function esc_close(Ihandle /*ih*/, atom c) |
|||
return iff(c=K_ESC?IUP_CLOSE:IUP_CONTINUE) |
|||
end function |
|||
procedure main() |
|||
Ihandle separator1, separator2, |
|||
canvas, frame_1, frame_2, |
|||
dialog |
|||
IupOpen() |
|||
global_lbl = IupLabel("Move the mouse anywhere on the window","EXPAND=HORIZONTAL") |
|||
separator1 = IupLabel(NULL,"SEPARATOR=HORIZONTAL") |
|||
canvas_lbl = IupLabel("Move the mouse anywhere on the canvas","EXPAND=HORIZONTAL") |
|||
separator2 = IupLabel(NULL,"SEPARATOR=HORIZONTAL") |
|||
timer_lbl = IupLabel("This one runs on a three second timer","EXPAND=HORIZONTAL") |
|||
frame_1 = IupFrame(IupVbox({global_lbl, |
|||
separator1, |
|||
canvas_lbl, |
|||
separator2, |
|||
timer_lbl}), |
|||
"TITLE=IupLabel, SIZE=200x") |
|||
canvas = IupCanvas("MOTION_CB", Icallback("canvas_motion_cb"), |
|||
"EXPAND=HORIZONTAL, RASTERSIZE=200x200") |
|||
frame_2 = IupFrame(canvas, "TITLE=IupCanvas") |
|||
dialog = IupDialog(IupHbox({frame_1,frame_2}, "MARGIN=5x5, GAP=5")) |
|||
IupSetAttribute(dialog,"TITLE","Mouse motion"); |
|||
IupSetCallback(dialog, "K_ANY", Icallback("esc_close")); |
|||
IupSetGlobal("INPUTCALLBACKS", "Yes"); |
|||
IupSetGlobalFunction("GLOBALMOTION_CB", Icallback("globalmotion_cb")); |
|||
Ihandle hTimer = IupTimer(Icallback("OnTimer"), 3000) |
|||
IupShow(dialog) |
|||
IupMainLoop() |
|||
IupClose() |
|||
end procedure |
|||
main()</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |