~rabbits/public-inbox

oekaki: Clear menu only when it was shown v1 PROPOSED

Jules Maselbas: 4
 Clear menu only when it was shown
 Hide menu when dragging with any tools
 Remove clear-menu function
 Rework redraw request using a single rectangle region

 4 files changed, 46 insertions(+), 42 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rabbits/public-inbox/patches/55110/mbox | git am -3
Learn more about email & git

[PATCH oekaki 1/4] Clear menu only when it was shown Export this patch

---
 src/oekaki.tal | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/oekaki.tal b/src/oekaki.tal
index cb39fc4..ddc8385 100644
--- a/src/oekaki.tal
+++ b/src/oekaki.tal
@@ -198,7 +198,8 @@
	#03 DIVk MUL SUB .brush/natural STZ !<draw-menu>

@<hide-menu> ( -- )
	[ LIT2 01 -menu/hide ] STZ !<clear-menu>
	.menu/hide LDZ ?{ [ LIT2 01 -menu/hide ] STZ !<clear-menu> }
	JMP2r

@<set-tool> ( tool -- )
	DUP #05 LTH ?{ POP JMP2r }
-- 
2.45.2
That's an excellent patch,
thank you so much!

It is now part of Oekaki :)

Dll

[PATCH oekaki 2/4] Hide menu when dragging with any tools Export this patch

---
 src/oekaki.tal | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/oekaki.tal b/src/oekaki.tal
index ddc8385..546cf77 100644
--- a/src/oekaki.tal
+++ b/src/oekaki.tal
@@ -329,7 +329,8 @@
	JMP2r

	&drag ( -- )
	[ LIT2 &last-x $2 ] [ LIT2 &last-y $2 ] OVR2 #0010 GTH2 ?{ <hide-menu> }
	( ) .Mouse/x DEI2 #0010 GTH2 ?{ <hide-menu> }
	[ LIT2 &last-x $2 ] [ LIT2 &last-y $2 ]
	( natural ) [ LIT2 00 -brush/natural ] LDZ EQU ?{ natural }
	( ) get-touch-x #0003 SUB2 DUP2 ,&last-x STR2
	( ) get-touch-y #0003 SUB2 DUP2 ,&last-y STR2
@@ -354,6 +355,7 @@
	( ) get-touch-y ;<paint-dot> !<do-line>

	&drag ( -- )
	( ) .Mouse/x DEI2 #0010 GTH2 ?{ <hide-menu> }
	<clear-guide>
	( ) [ LIT2 &x $2 ] [ LIT2 &y $2 ]
	( ) .Mouse/x DEI2 #0003 ADD2 .Mouse/y DEI2 #0003 ADD2 ;<guide-dot>
@@ -377,6 +379,7 @@
	( ) get-touch-x INC2 get-touch-y INC2 !<paint-rect>

	&drag ( -- )
	( ) .Mouse/x DEI2 #0010 GTH2 ?{ <hide-menu> }
	<clear-guide>
	( ) [ LIT2 &x $2 ] [ LIT2 &y $2 ]
	( ) .Mouse/x DEI2 #0003 ADD2 .Mouse/y DEI2 #0003 ADD2 <guide-rect>
@@ -396,6 +399,7 @@
	( draw cursor ) #43 ;hand-icn <update-cursor> !<redraw-all>

	&drag ( -- )
	( ) .Mouse/x DEI2 #0010 GTH2 ?{ <hide-menu> }
	( draw cursor ) #42 ;hand-icn/down <update-cursor>
	.Mouse/x DEI2
	( ) DUP2 [ LIT2 &x $2 ] SUB2 .canvas/x LDZ2 ADD2 .canvas/x STZ2
@@ -423,6 +427,7 @@
	( ) get-touch-x #33 SFT2 get-touch-y #33 SFT2 !<snarf-rect>

	&drag ( -- )
	( ) .Mouse/x DEI2 #0010 GTH2 ?{ <hide-menu> }
	,&paste LDR ?{ JMP2r }
	<clear-guide>
	( ) [ LIT2 &x $2 ] [ LIT2 &y $2 ]
-- 
2.45.2

[PATCH oekaki 3/4] Remove clear-menu function Export this patch

---
 src/oekaki.tal | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/oekaki.tal b/src/oekaki.tal
index 546cf77..93ab909 100644
--- a/src/oekaki.tal
+++ b/src/oekaki.tal
@@ -198,7 +198,7 @@
	#03 DIVk MUL SUB .brush/natural STZ !<draw-menu>

@<hide-menu> ( -- )
	.menu/hide LDZ ?{ [ LIT2 01 -menu/hide ] STZ !<clear-menu> }
	.menu/hide LDZ ?{ [ LIT2 01 -menu/hide ] STZ !<redraw-all> }
	JMP2r

@<set-tool> ( tool -- )
@@ -737,7 +737,7 @@
	POP2

@<draw-menu> ( -- )
	.menu/hide LDZ ?<clear-menu>
	.menu/hide LDZ #00 EQU ?{ JMP2r }
	( | background )
	#000f .Screen/x DEO2
	#0000 .Screen/y DEO2
@@ -850,17 +850,6 @@
	[ LIT2 c0 -Screen/pixel ] DEO
	JMP2r

@<clear-menu> ( -- )
	#000c .Screen/x DEO2
	#0000 .Screen/y DEO2
	[ LIT2 93 -Screen/pixel ] DEO
	.canvas/height LDZ2 #0000
	&>y ( -- )
		( ) #0000 OVR2 <push-request>
		( ) #0008 OVR2 <push-request>
		#0008 ADD2 GTH2k ?&>y
	POP2 POP2 JMP2r

@<draw-pointer> ( -- )
	[ LIT2 00 -brush/color ] LDZ EQU ?&eraser
	.brush/erase LDZ ?&eraser
-- 
2.45.2

[PATCH oekaki 4/4] Rework redraw request using a single rectangle region Export this patch

Using only a rectangle to keep track of tiles that needs to be redrawn
makes rectangle operation faster by removing the iteration on the list
of requests (which was done for each pixel).

---
 src/oekaki.tal | 63 ++++++++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/oekaki.tal b/src/oekaki.tal
index 93ab909..8288e91 100644
--- a/src/oekaki.tal
+++ b/src/oekaki.tal
@@ -147,20 +147,36 @@
		BRK }
	POP BRK

@draw-pict-rect ( xmin xmax ymin ymax -- )
	INC ,&yn STR ,&yi STR
	INC ,&xn STR ,&xi STR
	[ LIT2 05 -Screen/auto ] DEO
	[ LIT2 &yn $1 &yi $1 ]
	&>v ( -- )
		[ LIT2 &xn $1 &xi $1 ]
		( xi yi ) ROTk ROT POP
		( *x *y ) SWP #00 SWP #30 SFT2 ROT #00 SWP #30 SFT2
		get-tile-addr .Screen/addr DEO2
		.canvas/y LDZ2 ADD2 .Screen/y DEO2
		.canvas/x LDZ2 ADD2 .Screen/x DEO2
		&>h ( -- )
			[ LIT2 81 -Screen/sprite ] DEO
			INC GTHk ?&>h
		POP2
		INC GTHk ?&>v
	POP2
	JMP2r

@on-frame ( -> )
	[ LIT2 00 &reqdraw $1 ] EQU ?{
		( | draw request stack )
		;<push-request>/ptr LDA2 ;requests
		&>l ( -- )
			LDA2k #00 SWP #30 SFT2 ROT #00 SWP #30 SFT2
			( ) get-tile-addr .Screen/addr DEO2
			.canvas/y LDZ2 ADD2 .Screen/y DEO2
			.canvas/x LDZ2 ADD2 .Screen/x DEO2
			[ LIT2 81 -Screen/sprite ] DEO
			INC2 INC2 GTH2k ?&>l
		POP2 POP2 ;requests ;<push-request>/ptr STA2
		<draw-state>
		[ LIT2 00 _&reqdraw ] STR }
		[ LIT2 &rect/xmin ff &rect/xmax 00 ]
		[ LIT2 &rect/ymin ff &rect/ymax 00 ]
		&draw-rect
		draw-pict-rect
		#00 ;on-frame/reqdraw STA
		#ffff ,&rect/xmin STR ,&rect/ymin STR
		#0000 ,&rect/xmax STR ,&rect/ymax STR
	}
	BRK

(
@@ -467,7 +483,7 @@
	&force ( x* y* color -- )
	STH
	[ LITr 01 ]
	( x y ) OVR2 OVR2 <push-request>
	( x y ) OVR2 OVR2 <push-reqdraw>
	( get tile addr ) get-tile-addr STH2
	( get glyph vertical offset ) DUP2 #0007 AND2 STH2
	ADD2r
@@ -886,20 +902,15 @@
(
@|requests )

@<push-request> ( x* y* -- )
	( x ) #03 SFT2 ,&x STR
@<push-reqdraw> ( x* y* -- )
	( y >> 3 ) #03 SFT2 NIP DUPk
	( y < y1 ) ;on-frame/rect/ymin LDA GTH ?{ DUP ;on-frame/rect/ymin STA }
	( y > y2 ) ;on-frame/rect/ymax LDA LTH ?{ DUP ;on-frame/rect/ymax STA }
	POP
	( y ) #03 SFT2 ,&y STR
	( x >> 3 ) #03 SFT2 NIP DUPk
	( x < x1 ) ;on-frame/rect/xmin LDA GTH ?{ DUP ;on-frame/rect/xmin STA }
	( x > x2 ) ;on-frame/rect/xmax LDA LTH ?{ DUP ;on-frame/rect/xmax STA }
	POP
	( | find duplicate )
	[ LIT2 &ptr =requests ] ;requests EQU2k ?{
		&>l ( -- )
			LDA2k [ LIT2 &t &x $1 &y $1 ] NEQ2 ?{ POP2 POP2 JMP2r }
			INC2 INC2 GTH2k ?&>l }
	POP2 POP2
	( | push )
	,&t LDR2 ,&ptr LDR2 INC2k INC2 ,&ptr STR2
	STA2
	#01 ;on-frame/reqdraw STA
	JMP2r

@@ -1062,5 +1073,3 @@

@pict $a400

@requests

-- 
2.45.2