uxn/projects/examples/gui/hover.tal

122 lines
3.2 KiB
Tal
Raw Normal View History

2021-04-02 00:53:41 -04:00
( GUI Hover )
2021-02-28 22:49:53 -05:00
2021-03-16 00:29:44 -04:00
%RTN { JMP2r }
2021-05-16 00:35:01 -04:00
%DEBUG { .Console/byte DEO #0a .Console/char DEO }
%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
2021-03-16 00:29:44 -04:00
( devices )
2021-02-28 22:49:53 -05:00
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
2021-05-16 00:35:01 -04:00
|10 @Console [ &vector $2 &pad $6 &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 ]
2021-05-31 18:08:34 -04:00
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
( variables )
|0000
@color [ &byte $1 ]
@pointer [ &x $2 &y $2 &sprite $2 ]
@rect [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@r1 [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@r2 [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@r3 [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
2021-03-21 17:16:19 -04:00
2021-04-05 16:00:55 -04:00
( program )
|0100
2021-03-21 17:16:19 -04:00
( theme ) #0f0f .System/r DEO2 #0fff .System/g DEO2 #0ff0 .System/b DEO2
( vectors ) ;on-mouse .Mouse/vector DEO2
2021-02-28 22:49:53 -05:00
2021-05-11 14:14:52 -04:00
#0020 #0030 #0060 #0060 .r1/y2 STZ2 .r1/x2 STZ2 .r1/y1 STZ2 .r1/x1 STZ2
#0058 #0050 #0090 #0080 .r2/y2 STZ2 .r2/x2 STZ2 .r2/y1 STZ2 .r2/x1 STZ2
#0048 #0048 #0080 #0098 .r3/y2 STZ2 .r3/x2 STZ2 .r3/y1 STZ2 .r3/x1 STZ2
2021-02-28 22:49:53 -05:00
( no BRK, run through to on-mouse )
2021-02-28 22:49:53 -05:00
@on-mouse
2021-05-16 00:35:01 -04:00
( defaults )
2021-05-11 14:14:52 -04:00
;pointer_icn .pointer/sprite STZ2
2021-02-28 22:49:53 -05:00
2021-05-11 14:14:52 -04:00
#01 .color STZ
2021-05-16 00:35:01 -04:00
.Mouse/x DEI2 .Mouse/y DEI2 .r1 ;within-rect JSR2 #00 EQU ,&draw1 JCN
#02 .color STZ
;hand_icn .pointer/sprite STZ2
&draw1
.r1/x1 LDZ2 .r1/y1 LDZ2 .r1/x2 LDZ2 .r1/y2 LDZ2 .color LDZ ;line-rect JSR2
2021-02-28 22:49:53 -05:00
2021-05-11 14:14:52 -04:00
#01 .color STZ
2021-05-16 00:35:01 -04:00
.Mouse/x DEI2 .Mouse/y DEI2 .r2 ;within-rect JSR2 #00 EQU ,&draw2 JCN
#03 .color STZ
;hand_icn .pointer/sprite STZ2
&draw2
.r2/x1 LDZ2 .r2/y1 LDZ2 .r2/x2 LDZ2 .r2/y2 LDZ2 .color LDZ ;line-rect JSR2
2021-02-28 22:49:53 -05:00
2021-05-11 14:14:52 -04:00
#01 .color STZ
2021-05-16 00:35:01 -04:00
.Mouse/x DEI2 .Mouse/y DEI2 .r3 ;within-rect JSR2 #00 EQU ,&draw3 JCN
#02 .color STZ
;hand_icn .pointer/sprite STZ2
&draw3
.r3/x1 LDZ2 .r3/y1 LDZ2 .r3/x2 LDZ2 .r3/y2 LDZ2 .color LDZ ;line-rect JSR2
2021-02-28 22:49:53 -05:00
;draw-cursor JSR2
2021-02-28 22:49:53 -05:00
BRK
2021-02-28 22:49:53 -05:00
2021-05-16 00:35:01 -04:00
@draw-cursor ( -- )
2021-02-28 22:49:53 -05:00
2021-03-13 20:34:08 -05:00
( clear last cursor )
2021-05-11 14:14:52 -04:00
.pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2
#30 .Screen/color DEO
2021-02-28 22:49:53 -05:00
2021-03-13 20:34:08 -05:00
( record pointer positions )
2021-05-11 14:14:52 -04:00
.Mouse/x DEI2 .pointer/x STZ2 .Mouse/y DEI2 .pointer/y STZ2
2021-02-28 22:49:53 -05:00
2021-03-13 20:34:08 -05:00
( draw new cursor )
2021-05-11 14:14:52 -04:00
.pointer/sprite LDZ2 .Screen/addr DEO2
.pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2
#31 .Screen/color DEO
2021-02-28 22:49:53 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-02-28 22:49:53 -05:00
2021-05-16 00:35:01 -04:00
@within-rect ( x* y* rect -- flag )
STH
( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 LTH2 ,&skip JCN
( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN
SWP2
( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN
( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN
POP2 POP2 POPr
#01
RTN
&skip
POP2 POP2 POPr
#00
RTN
2021-04-29 00:00:39 -04:00
@line-rect ( x1* y1* x2* y2* color -- )
2021-02-28 22:49:53 -05:00
2021-05-11 14:14:52 -04:00
( load ) .color STZ .rect/y2 STZ2 .rect/x2 STZ2 DUP2 .Screen/y DEO2 .rect/y1 STZ2 DUP2 .Screen/x DEO2 .rect/x1 STZ2
&hor
( incr ) .Screen/x DEI2 #0001 ADD2 .Screen/x DEO2
2021-05-11 14:14:52 -04:00
( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ .Screen/color DEO
( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .color LDZ .Screen/color DEO
.Screen/x DEI2 .rect/x2 LDZ2 LTH2 ,&hor JCN
.rect/y1 LDZ2 .Screen/y DEO2
&ver
2021-05-11 14:14:52 -04:00
( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ .Screen/color DEO
( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .color LDZ .Screen/color DEO
( incr ) .Screen/y DEI2 #0001 ADD2 .Screen/y DEO2
2021-05-11 14:14:52 -04:00
.Screen/y DEI2 .rect/y2 LDZ2 #0001 ADD2 LTH2 ,&ver JCN
2021-02-28 22:49:53 -05:00
2021-03-14 17:26:17 -04:00
RTN
2021-02-28 22:49:53 -05:00
2021-03-01 12:16:40 -05:00
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
2021-02-28 22:49:53 -05:00
@hand_icn [ 4040 4070 f8f8 f870 ]