From 1a652efefde2ff68866dc787c7e87188bb6270d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Fri, 22 Sep 2023 13:09:47 -0400 Subject: Add absolute cursor, prep for refactor --- virtual-programs/editor.folk | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk index aa39795a..6387c363 100644 --- a/virtual-programs/editor.folk +++ b/virtual-programs/editor.folk @@ -128,16 +128,18 @@ proc drawText {text cursor count region} { } } +# TODO: refactor this to not reply on absolute region position but instead to compose as 0, 0 +# and then translate and rotate according to the virtual region as the final step proc drawCursor {cursorPosition region} { - # calculate relative to topLeft of region set corner [region topleft $region] - - set cpX [* 1 [lindex $corner 0]] - set cpY [* 1 [lindex $corner 1]] - set cp [list $cpX $cpY] - set cursorTop [list $cpX [expr {$cpY - 50}]] - - Display::stroke [list $cp $cursorTop] 2 gray + lassign $corner cornerX cornerY + lassign $cursorPosition cursorX cursorY + set cursorX [int [- $cornerX [* $cursorX 20]]] + set cursorY [int [- [- $cornerY [* $cursorY 65]] 20]] + set cursorX2 $cursorX + set cursorY2 [- $cursorY 50] + puts " $cursorPosition => $cursorX $cursorY" + Display::stroke [list [list $cursorX $cursorY] [list $cursorX2 $cursorY2]] 3 white } When $id has program code /code/ & the clock time is /t/ & the cursor is /cursor/ & $id has region /r/ { @@ -147,7 +149,7 @@ When $id has program code /code/ & the clock time is /t/ & the cursor is /cursor set intTime [expr {int($t * 10)}] drawText [insertCursor $code $cursor $intTime] $cursor $intTime $r # Hide cursor, TODO: fix to calculate accurate position based on cursor position - # drawCursor $cursor $r + drawCursor $cursor $r # DEBUG INFO When the cursor is /cursor/ { -- cgit v1.2.3