-
-
Notifications
You must be signed in to change notification settings - Fork 22
Revive drawing capabilities (new and improved!) #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
99f085d
2282866
5365688
5bcac76
88fb8b8
8cb109e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ debug: folk | |
| if [ "$$(uname)" = "Darwin" ]; then \ | ||
| lldb -o "process handle -p true -s false SIGUSR1" -- ./folk; \ | ||
| else \ | ||
| DEBUGINFOD_URLS="" gdb -ex "handle SIGUSR1 nostop" -ex "handle SIGPIPE nostop" ./folk; \ | ||
| gdb -ex "handle SIGUSR1 nostop" -ex "handle SIGPIPE nostop" ./folk; \ | ||
| fi | ||
|
|
||
| clean: | ||
|
|
@@ -115,19 +115,20 @@ kill-folk: | |
| fi | ||
|
|
||
| FOLK_REMOTE_NODE ?= folk-live | ||
| FOLK_SYNC_IGNORES ?= $(shell git rev-parse --git-path ignores.tmp 2>/dev/null || printf '%s\n' .git/ignores.tmp) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this fix? |
||
|
|
||
| sync: | ||
| ssh $(FOLK_REMOTE_NODE) -t \ | ||
| 'cd ~/folk && git init > /dev/null && git ls-files --exclude-standard -oi --directory' \ | ||
| > .git/ignores.tmp || true | ||
| git ls-files --exclude-standard -oi --directory >> .git/ignores.tmp | ||
| > '$(FOLK_SYNC_IGNORES)' || true | ||
| git ls-files --exclude-standard -oi --directory >> '$(FOLK_SYNC_IGNORES)' | ||
| rsync --timeout=15 -e "ssh -o StrictHostKeyChecking=no" \ | ||
| --archive --delete --itemize-changes \ | ||
| --exclude='/.git' \ | ||
| --exclude-from='$(FOLK_SYNC_IGNORES)' \ | ||
| --exclude='vendor/tracy/public/TracyClient.o' \ | ||
| --include='vendor/tracy/public/***' \ | ||
| --exclude='vendor/tracy/*' \ | ||
| --exclude-from='.git/ignores.tmp' \ | ||
| ./ $(FOLK_REMOTE_NODE):~/folk/ | ||
|
|
||
| remote-setup: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,50 @@ | ||
| fn drawLabelMaxLineLength {text} { | ||
| set maxLength 0 | ||
| foreach line [split $text "\n"] { | ||
| set lineLength [string length $line] | ||
| if {$lineLength > $maxLength} { | ||
| set maxLength $lineLength | ||
| } | ||
| } | ||
| return $maxLength | ||
| } | ||
|
|
||
| fn drawLabelDefaultScale {text} { | ||
| set maxLength [drawLabelMaxLineLength $text] | ||
| if {$maxLength == 0} { return 0.02 } | ||
| ::math::min 0.02 [/ 0.45 $maxLength] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be better style to use explicit |
||
| } | ||
|
|
||
| fn drawLabelDefaultOptions {text width height} { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, I don't really like all these utility functions, but I could be convinced otherwise. @ppkn @smj-edison what do you think? Lots of repetition since you need to restate and pass in all the parameters, and it doesn't fit the style we use in existing drawing programs. I think a straight-line When body is easier to read than having like 4 functions in each file.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not opposed to utility functions, as long as they're used multiple times and don't cause indirection fatigue. I think in this case it might be clearer inline, since they're not used that often. |
||
| set scale [drawLabelDefaultScale $text] | ||
| set position [list [expr {$width / 2.0}] [expr {$height / 2.0}]] | ||
| dict create \ | ||
| position $position \ | ||
| scale $scale \ | ||
| anchor center \ | ||
| font "PTSans-Regular" | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ { | ||
| When the collected results for [list /someone/ wishes $thing is labelled /text/ with /...options/] are /results/ { | ||
| set text [join [lmap result $results {dict get $result text}] "\n"] | ||
| if {$text eq ""} { return } | ||
|
|
||
| # Split text into lines and find the longest line. | ||
| set lines [split $text "\n"] | ||
| set maxLength 0 | ||
| foreach line $lines { | ||
| set lineLength [string length $line] | ||
| if {$lineLength > $maxLength} { | ||
| set maxLength $lineLength | ||
| } | ||
| set width [dict get $geom width] | ||
| set height [dict get $geom height] | ||
| set options [drawLabelDefaultOptions $text $width $height] | ||
| if {[dict exists $geom top] && | ||
| [dict exists $geom tagSize] && | ||
| [dict exists $geom bottom]} { | ||
| dict set options position \ | ||
| [list [expr {$width / 2.0}] \ | ||
| [expr {[dict get $geom top] + [dict get $geom tagSize] + [dict get $geom bottom] / 2.0}]] | ||
| } | ||
|
|
||
| # Set default scale based on longest line length. | ||
| # Scale inversely with length to keep text readable. | ||
| set defaultScale [::math::min 0.02 [/ 0.45 $maxLength]] | ||
|
|
||
| set x [/ $geom(width) 2.0] | ||
| try { | ||
| set y $($geom(top) + $geom(tagSize) + $geom(bottom)/2.0) | ||
| } on error e { | ||
| set y [/ $geom(height) 2.0] | ||
| foreach result $results { | ||
| set options [dict merge $options [dict get $result options]] | ||
| } | ||
| set options [dict create x $x y $y scale $defaultScale] | ||
| # FIXME: support per-label options; right now, this just | ||
| # applies an arbitrary label's options to all of them | ||
| # together. | ||
| set options [dict merge $options [dict get $result options]] | ||
| dict set options text $text | ||
|
|
||
| Wish to draw text onto $thing with {*}$options | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,65 @@ | ||
| When /someone/ wishes /thing/ is outlined /color/ &\ | ||
| /thing/ has resolved geometry /geom/ { | ||
| dict with geom { | ||
| set points [list [list 0 0] \ | ||
| [list $width 0] \ | ||
| [list $width $height] \ | ||
| [list 0 $height] \ | ||
| [list 0 0]] | ||
| } | ||
| fn drawOutlinePoints {width height} { | ||
| return [list [list 0 0] \ | ||
| [list $width 0] \ | ||
| [list $width $height] \ | ||
| [list 0 $height] \ | ||
| [list 0 0]] | ||
| } | ||
|
|
||
| fn drawOutlineOptions {color options} { | ||
| if {![info exists options]} { set options [dict create] } | ||
| dict set options color $color | ||
| return $options | ||
| } | ||
|
|
||
| fn drawOutlineOptionTail {key value rest} { | ||
| if {![info exists rest]} { set rest [list] } | ||
| return [list $key $value {*}$rest] | ||
| } | ||
|
|
||
| fn drawOutlineOnto {thing geom options} { | ||
| if {![info exists options]} { set options [dict create] } | ||
| set color [dict getdef $options color white] | ||
| set outlineWidth [drawPhysicalLength \ | ||
| [dict getdef $options width [dict getdef $options thickness 1cm]]] | ||
| set layer [dict getdef $options layer 2] | ||
|
|
||
| Wish to draw a line onto $thing with \ | ||
| points $points width 0.01 color $color | ||
| points [drawOutlinePoints [dict get $geom width] [dict get $geom height]] \ | ||
| width $outlineWidth color $color layer $layer | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ &\ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stuff is really ugly:
I would rather standardize on one variant (even if we have to break compatibility) and/or add some syntax sugar (maybe so one handler can deal with both |
||
| /someone/ wishes /thing/ is outlined /color/ { | ||
| drawOutlineOnto $thing $geom [drawOutlineOptions $color [dict create]] | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ &\ | ||
| /someone/ wishes /thing/ is outlined /color/ with /optionKey/ /optionValue/ /...optionRest/ { | ||
| if {![info exists optionKey] || ![info exists optionValue]} { return } | ||
| if {![info exists optionRest]} { set optionRest [list] } | ||
| set options [drawOutlineOptionTail $optionKey $optionValue $optionRest] | ||
| drawOutlineOnto $thing $geom [drawOutlineOptions $color $options] | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ &\ | ||
| /someone/ wishes /thing/ is outlined /color/ with /optionKey/ /optionValue/ { | ||
| if {![info exists optionKey] || ![info exists optionValue]} { return } | ||
| set options [list $optionKey $optionValue] | ||
| drawOutlineOnto $thing $geom [drawOutlineOptions $color $options] | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ &\ | ||
| /someone/ wishes /thing/ is outlined with /optionKey/ /optionValue/ /...optionRest/ { | ||
| if {![info exists optionKey] || ![info exists optionValue]} { return } | ||
| if {![info exists optionRest]} { set optionRest [list] } | ||
| set options [drawOutlineOptionTail $optionKey $optionValue $optionRest] | ||
| drawOutlineOnto $thing $geom $options | ||
| } | ||
|
|
||
| When /thing/ has resolved geometry /geom/ &\ | ||
| /someone/ wishes /thing/ is outlined with /optionKey/ /optionValue/ { | ||
| if {![info exists optionKey] || ![info exists optionValue]} { return } | ||
| set options [list $optionKey $optionValue] | ||
| drawOutlineOnto $thing $geom $options | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ Claim 45004 has demo code { | |
| } | ||
| Claim 45005 has demo code { | ||
| When the clock time is /t/ { | ||
| Wish $this draws a circle offset [list expr {sin($t) * 50} 0] | ||
| Wish $this draws a circle with offset [list [expr {sin($t) * 5.0}cm] 0cm] radius 1.2cm | ||
| } | ||
| } | ||
| Claim 45006 has demo code { | ||
|
|
@@ -43,3 +43,19 @@ Claim 45008 has demo code { | |
| Wish $this displays camera slice $slice | ||
| } | ||
| } | ||
|
|
||
| When /someone/ wishes /program/ runs demo code from /filename/ { | ||
| Hold! -key "active-demo-$program" Claim $program running demo code from $filename | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't need to use |
||
| On unmatch { | ||
| if {[llength [Query! /someone/ wishes $program runs demo code from /any/]] == 0} { | ||
| Hold! -key "active-demo-$program" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| When /program/ running demo code from /filename/ { | ||
| When $filename has demo code /code/ { | ||
| set this $program | ||
| eval $code | ||
| } | ||
| } | ||
This file was deleted.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed? The debuginfod suppression is there because it would hang in gdb on accessing it for me (can add a comment about that)