; on mouse enter event in @window
;
; - triggers when the mouse is within a specified square in a custom window
; - Multiple on mouse_event are allowed by cannot overlap.
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
;
on *:signal:$($mouse_enter(50, 50, 100, 100)):{
echo -s Mouse is in window %%window within the square area (50, 50) and (150, 150)! $&
At ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
on *:signal:$($mouse_enter(200, 200, 100, 100)):{
echo -s Mouse is in window %%window within the square area (200, 200) and (300, 300)! $&
At ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
; on mouse move event in @window
;
; - triggers when the mouse moves in a custom window
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
;
on *:signal:mouse,move:{
echo -s Mouse moved in window %%window at ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
; on mouse leave event in @window
;
; - triggers when the mouse leaves a custom window
;
; Params:
; - %%window -> @window that triggered the event
;
on *:signal:mouse,leave:{
echo -s Mouse left window %%window $+ .
}
; on mouse drag event in @window
;
; - triggers when the mouse is dragging in a custom window
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
;
on *:signal:mouse,drag:{
echo -s Mouse is dragging in window %%window at ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
; on mouse drop event in @window
;
; - triggers when a mouse has dropped/done dragging in a custom window
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
; - %%mouse.origin.x -> mouse drag origin x coordinate
; - %%mouse.origin.x -> mouse drag origin y coordinate
;
on *:signal:mouse,drop:{
echo -s Mouse is dropped in window %%window at ( $+ %%mouse.x $+ , %%mouse.y $+ ). $&
Mouse was dragged from: ( $+ %%mouse.origin.x $+ , %%mouse.origin.y $+ ).
}
; on mouse click event in @window
;
; - triggers when a mouse click occures in a custom window
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
;
on *:signal:mouse,click:{
echo -s Mouse clicked in window %%window at ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
; on mouse double-click event in @window
;
; - triggers when a double click occures in a custom window
;
; Params:
; - %%window -> @window that triggered the event
; - %%mouse.x -> mouse current x coordinate
; - %%mouse.x -> mouse current y coordinate
;
on *:signal:mouse,dclick:{
echo -s Mouse double-clicked in window %%window at ( $+ %%mouse.x $+ , %%mouse.y $+ ).
}
/* event dispatcher
*/
menu @* {
mouse:setcoords | if ($isdragged) .signal -n mouse,drag | else .signal -n mouse,move | .signal -n __enter_event
sclick:setcoords | .signal -n mouse,click
dclick:setcoords | .signal -n mouse,dclick
rclick:setcoords | .signal -n mouse,rclick
leave:setcoords | .signal -n mouse,leave
}
/*
** set some cross-alias local variables
** This is needed because $mouse.x/y from signal can differ (or not
** exists at all) from the actual window (taken from global pos).
*/
alias setcoords {
; mouse x/y
set -u0 %%mouse.x $mouse.x
set -u0 %%mouse.y $mouse.y
; event/window
set -u0 %%event $active
set -u0 %%window $active
}
/*
** check if the mouse is being dragged
*/
alias isdragged {
if ($mouse.key & 1) {
.timer $+ %%window -m 0 0 checkdrop $ltimer
set -u1 %%_x_ $+ %%window $mouse.x
set -u1 %%_y_ $+ %%window $mouse.y
return 1
}
return 0
}
/*
** check if the mouse is dropped
*/
alias checkdrop {
if (!$mouse.key) {
timer $+ $1 off
set -u0 %%mouse.x $($+(%, %, _x_, $1), 2)
set -u0 %%mouse.y $($+(%, %, _y_, $1), 2)
set -u0 %%mouse.origin.x $click($1, $click($1, 0)).x
set -u0 %%mouse.origin.y $click($1, $click($1, 0)).y
.signal -n mouse,drop
}
}
/*
** check if we are within a certain area
*/
alias mouse_enter {
if ($0 != 4) { echo -sc info * on mouse_enter: syntax error! | halt }
if ($inrect(%%mouse.x, %%mouse.y, $1, $2, $3, $4)) {
return __enter_event
}
return __enter_nop
}