From a7ae511906f7fbfe0c41a4ac2750d1a92ad7ff1d Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 7 Nov 2022 17:07:01 -0500 Subject: Move to using regions and outlining instead of axis-aligned rectangles and highlighting --- virtual-programs/archive/highlight.folk | 10 ++++++++++ virtual-programs/highlight.folk | 10 ---------- virtual-programs/label.folk | 9 +++++++-- virtual-programs/outline.folk | 14 ++++++++++++++ virtual-programs/tags-and-calibration.folk | 13 ++++++++----- 5 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 virtual-programs/archive/highlight.folk delete mode 100644 virtual-programs/highlight.folk create mode 100644 virtual-programs/outline.folk (limited to 'virtual-programs') diff --git a/virtual-programs/archive/highlight.folk b/virtual-programs/archive/highlight.folk new file mode 100644 index 00000000..d4206622 --- /dev/null +++ b/virtual-programs/archive/highlight.folk @@ -0,0 +1,10 @@ +Wish $this has filename "highlight.folk" + +When /someone/ wishes /thing/ is highlighted /color/ { + When $thing has region /region/ { + # it's not really correct to just stick a side-effect in the + # When handler like this. but we did it in Realtalk, and it + # was ok, so whatever for now + Display::fillRect device $x $y [expr {$x+$width}] [expr {$y+$height}] $color + } +} diff --git a/virtual-programs/highlight.folk b/virtual-programs/highlight.folk deleted file mode 100644 index ad19b86c..00000000 --- a/virtual-programs/highlight.folk +++ /dev/null @@ -1,10 +0,0 @@ -Wish $this has filename "highlight.folk" - -When /someone/ wishes /rect/ is highlighted /color/ { - When $rect is a rectangle with x /x/ y /y/ width /width/ height /height/ { - # it's not really correct to just stick a side-effect in the - # When handler like this. but we did it in Realtalk, and it - # was ok, so whatever for now - Display::fillRect device $x $y [expr {$x+$width}] [expr {$y+$height}] $color - } -} diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 26b3f7ef..2c2ef0f0 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -1,7 +1,12 @@ Wish $this has filename "label.folk" -When /someone/ wishes /rect/ is labelled /text/ { - When $rect is a rectangle with x /x/ y /y/ width /width/ height /height/ { +When /someone/ wishes /thing/ is labelled /text/ { + When $thing has region /region/ { + set bbox [regionToBbox $region] + lassign [boxCentroid $bbox] x y + set width [boxWidth $bbox] + set height [boxHeight $bbox] + set lines [split $text "\n"] set longestLineLength [tcl::mathfunc::max {*}[lmap line $lines {string length $line}]] set fontSize [expr {$width / $longestLineLength}] diff --git a/virtual-programs/outline.folk b/virtual-programs/outline.folk new file mode 100644 index 00000000..a4ca20a5 --- /dev/null +++ b/virtual-programs/outline.folk @@ -0,0 +1,14 @@ +Wish $this has filename "outline.folk" + +When /someone/ wishes /thing/ is outlined /color/ { + When $thing has region /region/ { + # FIXME: assumes path + lassign $region vertices edges + foreach edge $edges { + set from [lindex $vertices [lindex $edge 0]] + set to [lindex $vertices [lindex $edge 1]] + Display::stroke [list $from $to] 2 $color + } + } +} + diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index b1975bc5..03f3eeaa 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -62,16 +62,19 @@ When tag /tag/ is a tag { set code [read $fp] close $fp - Wish $tag is highlighted green + Wish $tag is outlined green Claim $tag has program code $code } When tag /tag/ has corners /corners/ { set corners [lmap p $corners {cameraToProjector $p}] - # Display::stroke [list {*}$corners [lindex $corners 0]] 2 green - foreach corner $corners { - lassign $corner x y - # Display::fillRect fb $x $y [expr $x+10] [expr $y+10] white + set edges [list] + for {set i 0} {$i < [llength $corners]} {incr i} { + lassign [lindex $corners $i] x y Display::text fb $x $y 10 $tag + if {$i > 0} { lappend edges [list [expr {$i - 1}] $i] } } + lappend edges [list [expr {[llength $corners] - 1}] 0] + set region [list $corners $edges] + Claim $tag has region $region } -- cgit v1.2.3