(mouse.tal) Drawing button states

This commit is contained in:
Devine Lu Linvega 2023-04-03 21:15:52 -07:00
parent 3b10969f9e
commit a55d2c80ca
1 changed files with 96 additions and 36 deletions

View File

@ -7,14 +7,11 @@
|0000 |0000
@line @line &x2 $2 &y2 $2
&x $2 &y $2 &dx $2 &dy $2 &e1 $2 @length $2
@length $2 @frame $2
@frame $2 @pen &x $2 &y $2 &x2 $2 &y2 $2
@pen @pointer &x $2 &y $2 &lastx $2 &lasty $2 &state $1
&x $2 &y $2 &x2 $2 &y2 $2
@pointer
&x $2 &y $2 &lastx $2 &lasty $2 &state $1
|0100 ( -> ) |0100 ( -> )
@ -27,8 +24,13 @@
;on-mouse .Mouse/vector DEO2 ;on-mouse .Mouse/vector DEO2
;on-frame .Screen/vector DEO2 ;on-frame .Screen/vector DEO2
draw-mouse
BRK BRK
(
@|vectors )
@on-frame ( -> ) @on-frame ( -> )
.Mouse/state DEI ?&skip .Mouse/state DEI ?&skip
@ -39,15 +41,17 @@ BRK
@on-mouse ( -> ) @on-mouse ( -> )
;pointer-icn .Screen/addr DEO2
( clear last cursor ) ( clear last cursor )
.pointer/x LDZ2 .Screen/x DEO2 .pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2 .pointer/y LDZ2 .Screen/y DEO2
[ LIT2 40 -Screen/sprite ] DEO [ LIT2 40 -Screen/sprite ] DEO
draw-mouse
( draw new cursor ) ( draw new cursor )
;pointer-icn .Screen/addr DEO2
#00 .Screen/auto DEO
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
#42 .Mouse/state DEI #00 NEQ ADD .Screen/sprite DEO #45 .Mouse/state DEI #00 NEQ #05 MUL ADD .Screen/sprite DEO
( on down ) ( on down )
.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?on-mouse-down .Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?on-mouse-down
( on drag ) ( on drag )
@ -74,7 +78,7 @@ BRK
.pointer/x LDZ2 .pointer/lastx LDZ2 SUB2 STH2kr STA2 .pointer/x LDZ2 .pointer/lastx LDZ2 SUB2 STH2kr STA2
.pointer/y LDZ2 .pointer/lasty LDZ2 SUB2 STH2r INC2 INC2 STA2 .pointer/y LDZ2 .pointer/lasty LDZ2 SUB2 STH2r INC2 INC2 STA2
( move ptr ) ( move ptr )
.length LDZ2 INC2 .length STZ2 .length LDZ2 INC2 .length STZ2
( draw line ) ( draw line )
.pointer/lastx LDZ2 .pointer/lastx LDZ2
.pointer/lasty LDZ2 .pointer/lasty LDZ2
@ -82,18 +86,23 @@ BRK
.pointer/y LDZ2 .pointer/y LDZ2
#01 draw-line #01 draw-line
( record last position ) ( record last position )
.Mouse/x DEI2 .Mouse/x DEI2
DUP2 .pointer/lastx STZ2 DUP2 .pointer/lastx STZ2
DUP2 .pen/x STZ2 DUP2 .pen/x STZ2
.pen/x2 STZ2 .pen/x2 STZ2
.Mouse/y DEI2 .Mouse/y DEI2
DUP2 .pointer/lasty STZ2 DUP2 .pointer/lasty STZ2
DUP2 .pen/y STZ2 DUP2 .pen/y STZ2
.pen/y2 STZ2 .pen/y2 STZ2
.Mouse/state DEI .pointer/state STZ .Mouse/state DEI
DUP #01 NEQ INC ;run/color STA
.pointer/state STZ
BRK BRK
(
@|main )
@run ( -- ) @run ( -- )
( read ) ( read )
@ -103,7 +112,7 @@ BRK
( line ) ( line )
.pen/x LDZ2 .pen/y LDZ2 .pen/x LDZ2 .pen/y LDZ2
.pen/x2 LDZ2 .pen/y2 LDZ2 .pen/x2 LDZ2 .pen/y2 LDZ2
.frame LDZ2 #01 SFT2 NIP #01 AND INC draw-line .frame LDZ2 #01 SFT2 NIP #01 AND [ LIT &color $1 ] ADD INC draw-line
( history ) ( history )
.pen/x LDZ2 .pen/x2 STZ2 .pen/x LDZ2 .pen/x2 STZ2
.pen/y LDZ2 .pen/y2 STZ2 .pen/y LDZ2 .pen/y2 STZ2
@ -112,31 +121,65 @@ BRK
JMP2r JMP2r
@draw-mouse ( -- )
( clear )
#0010
DUP2 .Screen/x DEO2
.Screen/y DEO2
#16 .Screen/auto DEO
#40 .Screen/sprite DEOk DEO
( buttons )
#0300
&l
#01 OVR #40 SFT SFT .Mouse/state DEI AND #00 EQU ?&no-draw
#0010 .Screen/y DEO2
#00 OVR #40 SFT2 ;button-icn ADD2 .Screen/addr DEO2
#45 .Screen/sprite DEO
&no-draw
INC GTHk ?&l
POP2
( outline )
#0010 .Screen/y DEO2
;mouse-icn .Screen/addr DEO2
#16 .Screen/auto DEO
#4a .Screen/sprite DEOk DEO
JMP2r
@draw-line ( x1* y1* x2* y2* color -- ) @draw-line ( x1* y1* x2* y2* color -- )
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2 ( load )
,&x LDR2 .line/x LDZ2 SUB2 abs2 .line/dx STZ2 ,&color STR
#0000 ,&y LDR2 .line/y LDZ2 SUB2 abs2 SUB2 .line/dy STZ2 ,&y STR2
#ffff #00 .line/x LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2 ,&x STR2
#ffff #00 .line/y LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2 .line/y2 STZ2
.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2 .line/x2 STZ2
,&x LDR2 .line/x2 LDZ2 SUB2 abs2 ,&dx STR2
#0000 ,&y LDR2 .line/y2 LDZ2 SUB2 abs2 SUB2 ,&dy STR2
#ffff #00 .line/x2 LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
#ffff #00 .line/y2 LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
[ LIT2 &dx $2 ] [ LIT2 &dy $2 ] ADD2 ,&e1 STR2
&loop &loop
.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2 .line/x2 LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2 .line/y2 LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
STHkr .Screen/pixel DEO [ LIT2 &color $1 -Screen/pixel ] DEO
AND ?&end AND ?&end
.line/e1 LDZ2 DUP2 ADD2 DUP2 [ LIT2 &e1 $2 ] DUP2 ADD2 DUP2
.line/dy LDZ2 lts2 ?&skipy ,&dy LDR2 lts2 ?&skipy
.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2 ,&e1 LDR2 ,&dy LDR2 ADD2 ,&e1 STR2
.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2 .line/x2 LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x2 STZ2
&skipy &skipy
.line/dx LDZ2 gts2 ?&skipx ,&dx LDR2 gts2 ?&skipx
.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2 ,&e1 LDR2 ,&dx LDR2 ADD2 ,&e1 STR2
.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2 .line/y2 LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y2 STZ2
&skipx &skipx
!&loop !&loop
&end &end
POPr
JMP2r JMP2r
@ -146,6 +189,8 @@ JMP2r
@clear-screen ( -- ) @clear-screen ( -- )
#00 .Screen/auto DEO
.Screen/height DEI2 #03 SFT2 NIP #00 .Screen/height DEI2 #03 SFT2 NIP #00
&y &y
#00 OVR #30 SFT2 .Screen/y DEO2 #00 OVR #30 SFT2 .Screen/y DEO2
@ -160,8 +205,23 @@ JMP2r
JMP2r JMP2r
@pointer-icn @pointer-icn [
80c0 e0f0 f8e0 1000 80c0 e0f0 f8e0 1000 ]
@mouse-icn [
000d 1212 1212 121d
00b0 4848 4848 48b8
1010 1010 1008 0700
0808 0808 0810 e000 ]
@button-icn [
000c 1e1e 1e1e 1e0c
0000 0000 0000 0000
0001 0303 0303 0301
0080 c0c0 c0c0 c080
0000 0000 0000 0000
0030 7878 7878 7830 ]
(
@|memory )
@stroke @stroke