uxn/projects/examples/dev.mouse.usm

141 lines
2.8 KiB
Plaintext
Raw Normal View History

2021-04-21 12:48:04 -04:00
( dev/mouse )
%RTN { JMP2r }
2021-04-22 18:19:09 -04:00
%8+ { #0008 ADD2 }
%++ { #0001 ADD2 }
%-- { #0001 SUB2 }
2021-04-22 14:08:06 -04:00
%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 }
2021-04-21 12:48:04 -04:00
2021-04-22 18:57:40 -04:00
(
%%^ { .% PEK } %%= { .% POK }
%%? { .% DEI } %%! { .% DEO }
)
2021-04-22 18:19:09 -04:00
%%^ { .% PEK2 } %%= { .% POK2 }
%%? { .% DEI2 } %%! { .% DEO2 }
2021-04-22 17:29:48 -04:00
2021-04-21 12:48:04 -04:00
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|40 @Controller [ &vector $2 &button $1 &key $1 ]
|60 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|0000
2021-04-22 14:08:06 -04:00
@line [ &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 ]
@pointer [ &x $2 &y $2 &lastx $2 &lasty $2 &state $1 ]
@color $1
2021-04-21 12:48:04 -04:00
( program )
|0100 ( -> )
( theme )
2021-04-22 18:57:40 -04:00
#f0f0 System/r!
#f00f System/g!
#f000 System/b!
2021-04-21 12:48:04 -04:00
2021-04-22 18:57:40 -04:00
( vectors )
;on-mouse Mouse/vector!
2021-04-21 12:48:04 -04:00
BRK
@on-mouse ( -> )
;draw-cursor JSR2
2021-04-22 14:08:06 -04:00
( on down )
2021-04-22 18:57:40 -04:00
.Mouse/state DEI #00 NEQ .pointer/state PEK #00 EQU #0101 EQU2 ,on-mouse-down JNZ
2021-04-22 14:08:06 -04:00
( on drag )
2021-04-22 18:57:40 -04:00
.Mouse/state DEI #00 NEQ ,on-mouse-drag JNZ
2021-04-22 14:08:06 -04:00
.Mouse/state DEI .pointer/state POK
2021-04-21 12:48:04 -04:00
BRK
2021-04-22 14:08:06 -04:00
@on-mouse-down ( -> )
2021-04-22 17:29:48 -04:00
( record start position )
2021-04-22 18:19:09 -04:00
Mouse/x? DUP2 pointer/x= pointer/lastx=
Mouse/y? DUP2 pointer/y= pointer/lasty=
2021-04-22 18:57:40 -04:00
2021-04-22 14:08:06 -04:00
.Mouse/state DEI .pointer/state POK
BRK
@on-mouse-drag ( -> )
2021-04-22 17:29:48 -04:00
( draw line )
2021-04-22 18:19:09 -04:00
pointer/lastx^
pointer/lasty^
pointer/x^
pointer/y^
2021-04-22 17:29:48 -04:00
#01 ( add mouse state ) [ .Mouse/state DEI #10 EQU #02 MUL ADD ]
2021-04-22 18:57:40 -04:00
;draw-line JSR2
2021-04-22 14:08:06 -04:00
( record last position )
2021-04-22 18:19:09 -04:00
Mouse/x? pointer/lastx=
Mouse/y? pointer/lasty=
2021-04-22 18:57:40 -04:00
2021-04-22 14:08:06 -04:00
.Mouse/state DEI .pointer/state POK
BRK
2021-04-21 12:48:04 -04:00
@draw-cursor ( -- )
( clear last cursor )
2021-04-22 18:19:09 -04:00
;clear Screen/addr!
pointer/x^ Screen/x!
pointer/y^ Screen/y!
#30 .Screen/color DEO
2021-04-21 12:48:04 -04:00
( record pointer positions )
2021-04-22 18:19:09 -04:00
Mouse/x? pointer/x=
Mouse/y? pointer/y=
2021-04-21 12:48:04 -04:00
( draw new cursor )
2021-04-22 18:19:09 -04:00
;cursor Screen/addr!
pointer/x^ Screen/x!
pointer/y^ Screen/y!
2021-04-21 12:48:04 -04:00
( colorize on state )
.Mouse/state DEI #00 NEQ
#31 ADD .Screen/color DEO
2021-04-21 12:48:04 -04:00
RTN
2021-04-22 18:57:40 -04:00
@draw-line ( x1 y1 x2 y2 color -- )
2021-04-22 14:08:06 -04:00
2021-04-22 18:19:09 -04:00
( load ) .color POK line/y0= line/x0= line/y= line/x=
line/x0^ line/x^ SUB2 ABS2 line/dx=
line/y0^ line/y^ SUB2 ABS2 #0000 SWP2 SUB2 line/dy=
#ffff #00 line/x^ line/x0^ LTS2 #0002 MUL2 ADD2 line/sx=
#ffff #00 line/y^ line/y0^ LTS2 #0002 MUL2 ADD2 line/sy=
line/dx^ line/dy^ ADD2 line/e1=
2021-04-22 14:08:06 -04:00
&loop
2021-04-22 18:57:40 -04:00
( draw )
line/x^ Screen/x!
line/y^ Screen/y!
.color PEK
.Screen/color DEO
2021-04-22 18:19:09 -04:00
line/x^ line/x0^ EQU2 line/y^ line/y0^ EQU2 #0101 EQU2 ,&end JNZ
line/e1^ #0002 MUL2 line/e2=
line/e2^ line/dy^ LTS2 ,&skipy JNZ
line/e1^ line/dy^ ADD2 line/e1=
line/x^ line/sx^ ADD2 line/x=
2021-04-22 14:08:06 -04:00
&skipy
2021-04-22 18:19:09 -04:00
line/e2^ line/dx^ GTS2 ,&skipx JNZ
line/e1^ line/dx^ ADD2 line/e1=
line/y^ line/sy^ ADD2 line/y=
2021-04-22 14:08:06 -04:00
&skipx
,&loop JMP
&end
RTN
2021-04-22 18:19:09 -04:00
@clear [ 0000 0000 0000 0000 ]
@cursor [ 80c0 e0f0 f8e0 1000 ]