uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

button.tal (3998B)


      1 ( a simple button )
      2 
      3 |00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
      4 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
      5 |90 @Mouse &vector $2 &x $2 &y $2 &state $1 &chord $1 &pad $4 &scrolly &scrolly-hb $1 &scrolly-lb $1
      6 
      7 |100
      8 
      9 @on-reset ( -> )
     10 	;meta #06 DEO2
     11 	( | theme )
     12 	#5c0f DUP2 .System/r DEO2
     13 	DUP2 .System/g DEO2
     14 	.System/b DEO2
     15 	( | size )
     16 	#0058 DUP2 .Screen/width DEO2
     17 	.Screen/height DEO2
     18 	( >> )
     19 
     20 @on-mouse ( -> )
     21 	focus/<update>
     22 	BRK
     23 
     24 @meta $1
     25 	( name ) "Button 0a
     26 	( desc ) "A 20 "Simple 20 "Button 0a
     27 	( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a
     28 	( date ) "15 20 "Jan 20 "2025 $2
     29 
     30 (
     31 @|focus )
     32 
     33 @focus/<update> ( -- )
     34 	cursor/<redraw>
     35 	.Mouse/x DEI2 .Mouse/y DEI2
     36 	( test button ) button/is-within ?{ ;on-mouse !focus/<set> }
     37 	;button/on-mouse
     38 	( >> )
     39 
     40 @focus/<set> ( vector* -- )
     41 	DUP2 [ LIT2 &last $2 ] NEQ2 ?{ POP2 JMP2r }
     42 	DUP2 .Mouse/vector DEO2
     43 	,&last STR2 !button/<redraw>
     44 
     45 (
     46 @|button )
     47 
     48 @button/on-mouse ( -> )
     49 	focus/<update>
     50 	.Mouse/state DEI ?{ BRK }
     51 	/<press>
     52 	BRK
     53 
     54 @button/on-mouse-lock ( -> )
     55 	cursor/<redraw>
     56 	BRK
     57 
     58 @button/on-frame ( -> )
     59 	[ LIT &timer $1 ] INCk ,&timer STR
     60 	?{ /<release> }
     61 	BRK
     62 
     63 @button/<press> ( -- )
     64 	;&on-frame .Screen/vector DEO2
     65 	;&on-mouse-lock focus/<set>
     66 	[ LIT2 e8 _&timer ] STR
     67 	( emit ) [ LIT2 "! 18 ] DEO
     68 	JMP2r
     69 
     70 @button/<release> ( -- )
     71 	#0000 .Screen/vector DEO2
     72 	focus/<update>
     73 	[ LIT2 00 -Mouse/state ] DEO
     74 	JMP2r
     75 
     76 @button/<redraw> ( -- )
     77 	.Mouse/vector DEI2
     78 	( | handlers )
     79 	DUP2 ;&on-mouse-lock NEQ2 ?{ POP2 ;&down-chr !/<draw> }
     80 	DUP2 ;&on-mouse NEQ2 ?{ POP2 ;&hover-chr !/<draw> }
     81 	POP2 ;&up-chr
     82 	( >> )
     83 
     84 @button/<draw> ( addr* -- )
     85 	[ LIT2 26 -Screen/auto ] DEO
     86 	#0020 DUP2 .Screen/x DEO2
     87 	.Screen/y DEO2
     88 	.Screen/addr DEO2
     89 	[ LIT2 81 -Screen/sprite ] DEOk DEOk DEO
     90 	JMP2r
     91 
     92 @button/is-within ( x* y* -- f )
     93 	#0020 SUB2 #0018 LTH2 STH
     94 	#0020 SUB2 #0018 LTH2 STHr AND JMP2r
     95 
     96 (
     97 @|cursor )
     98 
     99 @cursor/<redraw> ( -- )
    100 	( | clear )
    101 	;fill-icn .Screen/addr DEO2
    102 	#40 /<draw>
    103 	( | paint )
    104 	#ca ;&sprite-chr .Mouse/state DEI ?{ #0040 ADD2 }
    105 	.Screen/addr DEO2
    106 	.Mouse/x DEI2 #0004 SUB2 ,&x STR2
    107 	.Mouse/y DEI2 #0005 SUB2 ,&y STR2
    108 	( >> )
    109 
    110 @cursor/<draw> ( color -- )
    111 	[ LIT2 16 -Screen/auto ] DEO
    112 	[ LIT2 &x $2 ] .Screen/x DEO2
    113 	[ LIT2 &y $2 ] .Screen/y DEO2
    114 	.Screen/sprite DEOk DEO
    115 	JMP2r
    116 
    117 (
    118 @|assets )
    119 
    120 @cursor/sprite-chr [
    121 	0000 0000 0000 0817 0000 0000 0000 0008
    122 	0000 0000 0000 00c0 0000 0000 0000 0000
    123 	1010 2010 1008 0700 0f0f 1f0f 0f07 0000
    124 	2010 1010 2020 c000 c0e0 e0e0 c0c0 0000
    125 	0000 0000 0814 1417 0000 0000 0008 0808
    126 	0000 0000 0000 00c0 0000 0000 0000 0000
    127 	1010 2010 1008 0700 0f0f 1f0f 0f07 0000
    128 	2010 1010 2020 c000 c0e0 e0e0 c0c0 0000 ]
    129 
    130 @button/up-chr [
    131 	0000 1f3f 3f3f 3f3f 001f 3f7f 7f7f 7f7f
    132 	0000 ffff ffff ffff 00ff ffff ffff ffff
    133 	0000 f8fc fcfc fcfc 00f8 fcfe fefe fefe
    134 	3f3f 3f3f 3f3f 3f3f 7f7f 7f7f 7f7f 7f7f
    135 	e7e7 e781 c3e7 ffff ffff ffff ffff ffff
    136 	fcfc fcfc fcfc fcfc fefe fefe fefe fefe
    137 	3f3f 3f3f 3f1f 0000 7f7f 7f5f 4020 1f00
    138 	ffff ffff ffff 0000 ffff ffff 0000 ff00
    139 	fcfc fcfc fcf8 0000 fefe fefa 0204 f800 ]
    140 
    141 @button/hover-chr [
    142 	0000 001f 3f3f 3f3f 0000 1f3f 7f7f 7f7f
    143 	0000 00ff ffff ffff 0000 ffff ffff ffff
    144 	0000 00f8 fcfc fcfc 0000 f8fc fefe fefe
    145 	3f3f 3f3f 3f3f 3f3f 7f7f 7f7f 7f7f 7f7f
    146 	ffe7 e7e7 81c3 e7ff ffff ffff ffff ffff
    147 	fcfc fcfc fcfc fcfc fefe fefe fefe fefe
    148 	3f3f 3f3f 3f1f 0000 7f7f 7f7f 5f20 1f00
    149 	ffff ffff ffff 0000 ffff ffff ff00 ff00
    150 	fcfc fcfc fcf8 0000 fefe fefe fa04 f800 ]
    151 
    152 @button/down-chr [
    153 	0000 001f 3f3f 3f3f 0000 1f20 5f7f 7f7f
    154 	0000 00ff ffff ffff 0000 ff00 ffff ffff
    155 	0000 00f8 fcfc fcfc 0000 f804 fafe fefe
    156 	3f3f 3f3f 3f3f 3f3f 7f7f 7f7f 7f7f 7f7f
    157 	ffff ffff ffff ffff ffff e7e7 e781 c3e7
    158 	fcfc fcfc fcfc fcfc fefe fefe fefe fefe
    159 	3f3f 3f3f 3f1f 0000 7f7f 7f7f 7f3f 1f00
    160 	ffff ffff ffff 0000 ffff ffff ffff ff00
    161 	fcfc fcfc fcf8 0000 fefe fefe fefc f800 ]
    162 
    163 @fill-icn [
    164 	ffff ffff ffff ffff ffff ffff ffff ffff
    165 	ffff ffff ffff ffff ffff ffff ffff ffff ]
    166