From 0ece21c189df93d85f5d59fa42ed497a3f012a5e Mon Sep 17 00:00:00 2001 From: Cristobal Sciutto Date: Fri, 27 Oct 2023 17:54:01 -0400 Subject: no collection for outline --- virtual-programs/outline.folk | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/outline.folk b/virtual-programs/outline.folk index 1d6411cb..13f060b1 100644 --- a/virtual-programs/outline.folk +++ b/virtual-programs/outline.folk @@ -9,21 +9,9 @@ proc loopRegion {edges vertices width color} { Wish the GPU draws pipeline "line" with instances $instances } -When the collected matches for [list /someone/ wishes /thing/ is outlined /color/] are /matches/ { - set thingColors [dict create] - foreach match $matches { - dict lappend thingColors [dict get $match thing] [dict get $match color] - } - foreach thing [dict keys $thingColors] { - When $thing has region /region/ { - set thickness 0 - foreach color [dict get $thingColors $thing] { - # FIXME: assumes path - lassign $region vertices edges - loopRegion $edges $vertices [incr thickness 3] $color - } - } - } +When /someone/ wishes /thing/ is outlined /color/ & /thing/ has region /region/ { + lassign $region vertices edges + loopRegion $edges $vertices 3 $color } When /someone/ wishes /thing/ is outlined thick /color/ & /thing/ has region /region/ { -- cgit v1.2.3 From e92b0920b8f9523d89779edbab563ac076b60387 Mon Sep 17 00:00:00 2001 From: Cristobal Sciutto Date: Fri, 27 Oct 2023 17:54:10 -0400 Subject: neighbor callback --- virtual-programs/intersect.folk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/intersect.folk b/virtual-programs/intersect.folk index 7755acbd..1aea9695 100644 --- a/virtual-programs/intersect.folk +++ b/virtual-programs/intersect.folk @@ -25,4 +25,8 @@ When /someone/ wishes /p/ has neighbors & /p/ has region /r/ & /p2/ has region / #Display::stroke [list [list $b2MaxX $b2MaxY] {500 500}] 3 white #Display::stroke [list [list $b2MinX $b2MinY] [list $b2MaxX $b2MaxY]] 10 blue } -} \ No newline at end of file +} + +When when /p/ has neighbor /n/ /lambda/ with environment /e/ { + Wish $p has neighbors +} -- cgit v1.2.3 From 4ab1d8922b54fe2945dcdb6b3272c52c71f28957 Mon Sep 17 00:00:00 2001 From: Cristobal Sciutto Date: Fri, 27 Oct 2023 18:00:12 -0400 Subject: scale as param --- virtual-programs/display/image.folk | 8 ++++---- virtual-programs/images.folk | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk index 23246d45..55a283e0 100644 --- a/virtual-programs/display/image.folk +++ b/virtual-programs/display/image.folk @@ -5,10 +5,10 @@ On process "display" { dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize vec2 pos float radians float scale fn rotate} { - vec2 a = pos + rotate(-imageSize/2, -radians); - vec2 b = pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians); - vec2 c = pos + rotate(imageSize/2, -radians); - vec2 d = pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians); + vec2 a = scale * (pos + rotate(-imageSize/2, -radians)); + vec2 b = scale * (pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); + vec2 c = scale * (pos + rotate(imageSize/2, -radians)); + vec2 d = scale * (pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); vec2 vertices[4] = vec2[4](a, b, d, c); return vertices[gl_VertexIndex]; } {fn invBilinear fn rotate} { diff --git a/virtual-programs/images.folk b/virtual-programs/images.folk index d8bcaf55..1be51424 100644 --- a/virtual-programs/images.folk +++ b/virtual-programs/images.folk @@ -343,7 +343,7 @@ When /someone/ wishes /p/ displays camera slice /slice/ & /p/ has region /r/ { Wish to draw an image with center $center image $slice radians 0 scale 1 } -When /someone/ wishes /p/ displays image /im/ { +When /someone/ wishes /p/ displays image /im/ with scale /s/ { set im [image load $im] When $p has region /r/ { # Compute a scale for im that will fit in the region width/height @@ -354,10 +354,14 @@ When /someone/ wishes /p/ displays image /im/ { # set scale [expr {min($width / [image width $im], # $height / [image height $im])}] # Wish $p is labelled $im - Wish to draw an image with center $center image $im radians [region angle $r] + Wish to draw an image with center $center image $im radians [region angle $r] scale $s } # On unmatch { # # HACK: Leaves time for the display to finish trying to display this. # after 5000 [list image freeJpeg $im] # } } + +When /someone/ wishes /p/ displays image /im/ { + Wish $p displays image $im with scale 1 +} -- cgit v1.2.3 From 37ccfee6ea7e27607b4a08fd44048d6ae8a189e2 Mon Sep 17 00:00:00 2001 From: Cristobal Sciutto Date: Fri, 27 Oct 2023 18:18:31 -0400 Subject: scale sampling --- virtual-programs/display/image.folk | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk index 55a283e0..7415b260 100644 --- a/virtual-programs/display/image.folk +++ b/virtual-programs/display/image.folk @@ -5,17 +5,17 @@ On process "display" { dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize vec2 pos float radians float scale fn rotate} { - vec2 a = scale * (pos + rotate(-imageSize/2, -radians)); - vec2 b = scale * (pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); - vec2 c = scale * (pos + rotate(imageSize/2, -radians)); - vec2 d = scale * (pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); + vec2 a = pos + scale * (rotate(-imageSize/2, -radians)); + vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); + vec2 c = pos + scale * (rotate(imageSize/2, -radians)); + vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); vec2 vertices[4] = vec2[4](a, b, d, c); return vertices[gl_VertexIndex]; } {fn invBilinear fn rotate} { - vec2 a = pos + rotate(-imageSize/2, -radians); - vec2 b = pos + rotate(vec2(imageSize.x, -imageSize.y)/2, -radians); - vec2 c = pos + rotate(imageSize/2, -radians); - vec2 d = pos + rotate(vec2(-imageSize.x, imageSize.y)/2, -radians); + vec2 a = pos + scale * (rotate(-imageSize/2, -radians)); + vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); + vec2 c = pos + scale * (rotate(imageSize/2, -radians)); + vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); vec2 p = gl_FragCoord.xy; vec2 uv = invBilinear(p, a, b, c, d); if( max( abs(uv.x-0.5), abs(uv.y-0.5))<0.5 ) { -- cgit v1.2.3 From b5712cb263f8347220c5c91bccfcc22d31b33ec1 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 2 Nov 2023 09:34:11 -0400 Subject: display: Handle bit at end of fbset resolution --- virtual-programs/display.folk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index 2853c065..e4ab2acd 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -140,7 +140,7 @@ namespace eval ::Display { if {$::isLaptop} { set WIDTH 640; set HEIGHT 480 } else { - regexp {mode "(\d+)x(\d+)"} [exec fbset] -> WIDTH HEIGHT + regexp {mode "(\d+)x(\d+)(?:-\d+)?"} [exec fbset] -> WIDTH HEIGHT } # TODO: Remove these / expel them to a shim page; these are only -- cgit v1.2.3 From df8bd6ea627b3bf0f8919d9621b5cea325f32afa Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sat, 11 Nov 2023 03:25:50 +0000 Subject: Support non-uniform image scaling --- virtual-programs/display/image.folk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk index 7415b260..de0408af 100644 --- a/virtual-programs/display/image.folk +++ b/virtual-programs/display/image.folk @@ -3,7 +3,7 @@ On process "display" { set rotate $::rotate # TODO: Do this with a wish, instead of hard-coding the global dict. dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize - vec2 pos float radians float scale + vec2 pos float radians vec2 scale fn rotate} { vec2 a = pos + scale * (rotate(-imageSize/2, -radians)); vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); @@ -108,6 +108,9 @@ On process "display" { set im [dict get $options image] set radians [dict get $options radians] set scale [dict_getdef $options scale 1.0] + if {[llength $scale] == 1} { + set scale [list $scale $scale] + } set gim [ImageCache::getOrInsert $im] -- cgit v1.2.3 From d2aa63f6a860204df9b43cf4ba0e6f61492a7306 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Sat, 11 Nov 2023 12:23:57 +0000 Subject: scale before rotating --- virtual-programs/display/image.folk | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/image.folk b/virtual-programs/display/image.folk index de0408af..b654f846 100644 --- a/virtual-programs/display/image.folk +++ b/virtual-programs/display/image.folk @@ -5,17 +5,17 @@ On process "display" { dict set ::pipelines "image" [Gpu::pipeline {sampler2D image vec2 imageSize vec2 pos float radians vec2 scale fn rotate} { - vec2 a = pos + scale * (rotate(-imageSize/2, -radians)); - vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); - vec2 c = pos + scale * (rotate(imageSize/2, -radians)); - vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); + vec2 a = pos + rotate(scale*-imageSize/2, -radians); + vec2 b = pos + rotate(scale*vec2(imageSize.x, -imageSize.y)/2, -radians); + vec2 c = pos + rotate(scale*imageSize/2, -radians); + vec2 d = pos + rotate(scale*vec2(-imageSize.x, imageSize.y)/2, -radians); vec2 vertices[4] = vec2[4](a, b, d, c); return vertices[gl_VertexIndex]; } {fn invBilinear fn rotate} { - vec2 a = pos + scale * (rotate(-imageSize/2, -radians)); - vec2 b = pos + scale * (rotate(vec2(imageSize.x, -imageSize.y)/2, -radians)); - vec2 c = pos + scale * (rotate(imageSize/2, -radians)); - vec2 d = pos + scale * (rotate(vec2(-imageSize.x, imageSize.y)/2, -radians)); + vec2 a = pos + rotate(scale*-imageSize/2, -radians); + vec2 b = pos + rotate(scale*vec2(imageSize.x, -imageSize.y)/2, -radians); + vec2 c = pos + rotate(scale*imageSize/2, -radians); + vec2 d = pos + rotate(scale*vec2(-imageSize.x, imageSize.y)/2, -radians); vec2 p = gl_FragCoord.xy; vec2 uv = invBilinear(p, a, b, c, d); if( max( abs(uv.x-0.5), abs(uv.y-0.5))<0.5 ) { -- cgit v1.2.3 From 66f3612bad25dbcfc192accdbb157c2b82874b85 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Wed, 15 Nov 2023 03:23:15 +0000 Subject: Use smoothstep for text rendering --- virtual-programs/display/text.folk | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index 858a9dc7..f4fbe587 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -68,7 +68,7 @@ On process "display" { return (vec2f) { width, y + em }; } $cc proc textShape {Font* font char* text - float x0 float y0 float scale float radians} Tcl_Obj* { + float x0 float y0 float scale float radians Tcl_Obj* color} Tcl_Obj* { Tcl_Obj* gpuAtlasImageSize = Tcl_ObjPrintf("%d %d", font->atlasImage.width, font->atlasImage.height); vec2f extent = vec2f_rotate(textExtent(font, text, scale), radians); @@ -103,7 +103,7 @@ On process "display" { gpuAtlasImageSize, atlasBounds, planeBounds, - pObj, Tcl_NewDoubleObj(radians), Tcl_NewDoubleObj(em) + pObj, Tcl_NewDoubleObj(radians), Tcl_NewDoubleObj(em), color }; Tcl_Obj* instance = Tcl_NewListObj(sizeof(args)/sizeof(args[0]), args); Tcl_ListObjAppendElement(NULL, instances, instance); @@ -145,6 +145,7 @@ On process "display" { vec4 atlasGlyphBounds vec4 planeGlyphBounds vec2 pos float radians float em + vec4 color fn rotate} { float left = planeGlyphBounds[0] * em; float bottom = planeGlyphBounds[1] * em; @@ -172,10 +173,12 @@ On process "display" { return vec4(0, 0, 0, 0); } vec3 msd = glyphMsd(atlas, atlasGlyphBounds/atlasSize.xyxy, glyphUv).rgb; + // https://blog.mapbox.com/drawing-text-with-signed-distance-fields-in-mapbox-gl-b0933af6f817 float sd = median(msd.r, msd.g, msd.b); - float screenPxDistance = 4.5*(sd - 0.5); - float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); - return mix(vec4(0, 0, 0, 0), vec4(1, 1, 1, 1), opacity); + float uBuffer = 0.2; + float uGamma = 0.2; + float opacity = smoothstep(uBuffer - uGamma, uBuffer + uGamma, sd); + return vec4(color.rgb, opacity * color.a); }] Wish $::thisProcess receives statements like \ @@ -192,13 +195,14 @@ On process "display" { set font [dict_getdef $options font "PTSans-Regular"] set text [dict get $options text] set radians [dict get $options radians] + set color [getColor [dict_getdef $options color white]] if {!([dict exists $::FontCache $font])} { throw {DISPLAY FONT {font doesn't exist}} "$font doesn't exist" } set font [dict get $::FontCache $font] - set instances [font textShape $font $text $x0 $y0 $scale $radians] + set instances [font textShape $font $text $x0 $y0 $scale $radians $color] # We need to batch into one wish so we don't deal with n^2 # checks for existing statements for n glyphs. -- cgit v1.2.3 From 6df1d57790da9d06340865d4c4dc3e880fd9c982 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Fri, 17 Nov 2023 03:54:10 +0000 Subject: Add horizontal text alignment --- virtual-programs/display/text.folk | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index f4fbe587..7e1f0325 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -65,16 +65,30 @@ On process "display" { x = x + advance * em; if (x > width) { width = x; } } - return (vec2f) { width, y + em }; + return (vec2f) { width, y }; } $cc proc textShape {Font* font char* text - float x0 float y0 float scale float radians Tcl_Obj* color} Tcl_Obj* { + float x0 float y0 float scale int halign float radians Tcl_Obj* color} Tcl_Obj* { Tcl_Obj* gpuAtlasImageSize = Tcl_ObjPrintf("%d %d", font->atlasImage.width, font->atlasImage.height); - vec2f extent = vec2f_rotate(textExtent(font, text, scale), radians); + vec2f extent = textExtent(font, text, scale); float em = scale * 25.0; - vec2f p0 = { x0 - extent.x/2.0, y0 - extent.y/2.0 }; + vec2f offset; + + switch (halign) { + case -1: // left align + offset = vec2f_rotate((vec2f){0, extent.y/2}, radians); + break; + case 0: // center + offset = vec2f_rotate((vec2f){extent.x/2.0, extent.y/2.0}, radians); + break; + case 1: // right align + offset = vec2f_rotate((vec2f){extent.x, extent.y/2}, radians); + break; + } + + vec2f p0 = (vec2f) { x0 - offset.x, y0 - offset.y }; vec2f p = p0; int lineNum = 0; @@ -194,15 +208,22 @@ On process "display" { set scale [dict_getdef $options scale 1.0] set font [dict_getdef $options font "PTSans-Regular"] set text [dict get $options text] + set halign [dict_getdef $options halign "center"] set radians [dict get $options radians] set color [getColor [dict_getdef $options color white]] + if {$halign == "left"} { + set halign_enum -1 + } elseif {$halign == "right"} { + set halign_enum 1 + } else { set halign_enum 0 } + if {!([dict exists $::FontCache $font])} { throw {DISPLAY FONT {font doesn't exist}} "$font doesn't exist" } set font [dict get $::FontCache $font] - set instances [font textShape $font $text $x0 $y0 $scale $radians $color] + set instances [font textShape $font $text $x0 $y0 $scale $halign_enum $radians $color] # We need to batch into one wish so we don't deal with n^2 # checks for existing statements for n glyphs. -- cgit v1.2.3 From 9274f593d7a5ec0b33882f6d8d76cd800a90d747 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Fri, 17 Nov 2023 05:28:44 +0000 Subject: Add vertical alignment --- virtual-programs/display/text.folk | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index 7e1f0325..0233a450 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -68,26 +68,39 @@ On process "display" { return (vec2f) { width, y }; } $cc proc textShape {Font* font char* text - float x0 float y0 float scale int halign float radians Tcl_Obj* color} Tcl_Obj* { + float x0 float y0 float scale int halign int valign float radians Tcl_Obj* color} Tcl_Obj* { Tcl_Obj* gpuAtlasImageSize = Tcl_ObjPrintf("%d %d", font->atlasImage.width, font->atlasImage.height); vec2f extent = textExtent(font, text, scale); float em = scale * 25.0; - vec2f offset; - + float x = 0; + float y = 0; switch (halign) { case -1: // left align - offset = vec2f_rotate((vec2f){0, extent.y/2}, radians); + x = 0; break; case 0: // center - offset = vec2f_rotate((vec2f){extent.x/2.0, extent.y/2.0}, radians); + x = extent.x/2.0; break; case 1: // right align - offset = vec2f_rotate((vec2f){extent.x, extent.y/2}, radians); + x = extent.x; + break; + } + + switch (valign) { + case -1: // top align + y = -em; + break; + case 0: // center + y = extent.y/2.0; + break; + case 1: // bottom align + y = extent.y; break; } + vec2f offset = vec2f_rotate((vec2f){x, y}, radians); vec2f p0 = (vec2f) { x0 - offset.x, y0 - offset.y }; vec2f p = p0; @@ -209,6 +222,7 @@ On process "display" { set font [dict_getdef $options font "PTSans-Regular"] set text [dict get $options text] set halign [dict_getdef $options halign "center"] + set valign [dict_getdef $options valign "center"] set radians [dict get $options radians] set color [getColor [dict_getdef $options color white]] @@ -218,12 +232,18 @@ On process "display" { set halign_enum 1 } else { set halign_enum 0 } + if {$valign == "top"} { + set valign_enum -1 + } elseif {$valign == "bottom"} { + set valign_enum 1 + } else { set valign_enum 0 } + if {!([dict exists $::FontCache $font])} { throw {DISPLAY FONT {font doesn't exist}} "$font doesn't exist" } set font [dict get $::FontCache $font] - set instances [font textShape $font $text $x0 $y0 $scale $halign_enum $radians $color] + set instances [font textShape $font $text $x0 $y0 $scale $halign_enum $valign_enum $radians $color] # We need to batch into one wish so we don't deal with n^2 # checks for existing statements for n glyphs. -- cgit v1.2.3 From 5c3fd25d7ef7f0b5690c3d3aa8aebf675db3ad40 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Fri, 17 Nov 2023 12:22:46 +0000 Subject: Change the text api slightly to use position instead of center --- virtual-programs/display/text.folk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index 0233a450..fa68aa40 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -213,8 +213,11 @@ On process "display" { When (non-capturing) /someone/ wishes to draw text with /...options/ { if {[dict exists $options center]} { + # This is deprecated lassign [dict get $options center] x0 y0 - } else { + } elseif {[dict exists $options position]} { + lassign [dict get $options position] x0 y0 + else { set x0 [dict get $options x] set y0 [dict get $options y] } -- cgit v1.2.3 From 35f00d4267d1ece3b6a86fe96769bfe92c8b743d Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Fri, 17 Nov 2023 12:59:53 +0000 Subject: fixup --- virtual-programs/display/text.folk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index fa68aa40..2afbdc72 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -217,7 +217,7 @@ On process "display" { lassign [dict get $options center] x0 y0 } elseif {[dict exists $options position]} { lassign [dict get $options position] x0 y0 - else { + } else { set x0 [dict get $options x] set y0 [dict get $options y] } -- cgit v1.2.3 From fb7c1bbc4a744a4fe573f962df736d285c70dc62 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Fri, 17 Nov 2023 12:50:51 +0000 Subject: Update title wish (and add margined text) --- virtual-programs/title.folk | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/title.folk b/virtual-programs/title.folk index 3187ed3c..565731c4 100644 --- a/virtual-programs/title.folk +++ b/virtual-programs/title.folk @@ -2,26 +2,43 @@ # for wishes of the form: # "Wish $tag is titled "This is a tag"" or "Wish $tag is footnoted "This is a footnote"" - When /thing/ has region /region/ { set radians [region angle $region] - set top [vec2 add [region top $region] [vec2 rotate [list 0 -12] $radians]] - set bot [vec2 add [region bottom $region] [vec2 rotate [list 0 16] $radians]] - When the collected matches for [list /someone/ wishes $thing is titled /text/] are /matches/ { set text [join [lmap match $matches {dict get $match text}] "\n"] if {$text eq ""} { return } - set scale 1 - Wish to draw text with center $top scale $scale text $text radians $radians + set scale [dict_getdef $match scale 1.0] + set pos [region top [region move $region up 10px]] + Wish to draw text with position $pos scale $scale text $text radians $radians valign bottom } - When the collected matches for [list /someone/ wishes $thing is footnoted /text/] are /matches/ { + When the collected matches for [list /someone/ wishes $thing is footnoted /text/ with scale /scale/] are /matches/ { set text [join [lmap match $matches {dict get $match text}] "\n"] if {$text eq ""} { return } - set scale 1 - Wish to draw text with center $bot scale $scale text $text radians $radians + set scale [dict_getdef $match scale 0.75] + set pos [region bottom [region move $region down 10px]] + Wish to draw text with position $pos scale $scale text $text radians $radians valign top + } + + When the collected matches for [list /someone/ wishes $thing is right margined /text/ with scale /scale/] are /matches/ { + set text [join [lmap match $matches {dict get $match text}] "\n"] + if {$text eq ""} { return } + + set scale [dict_getdef $match scale 0.75] + set pos [region right [region move $region right 10px]] + Wish to draw text with position $pos scale $scale text $text radians $radians halign left + } + + When the collected matches for [list /someone/ wishes $thing is left margined /text/ with scale /scale/] are /matches/ { + set text [join [lmap match $matches {dict get $match text}] "\n"] + if {$text eq ""} { return } + + set scale [dict_getdef $match scale 0.75] + set pos [region left [region move $region left 10px]] + Wish to draw text with position $pos scale $scale text $text radians $radians halign left } } + -- cgit v1.2.3 From 85ad16cff11a07c7ed27feb5a655586f2130768b Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Tue, 21 Nov 2023 02:14:34 +0000 Subject: API improvements --- virtual-programs/display/text.folk | 35 +++++++++++++++++++++-------------- virtual-programs/title.folk | 16 ++++++++-------- 2 files changed, 29 insertions(+), 22 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index 2afbdc72..b55cfeea 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -224,29 +224,36 @@ On process "display" { set scale [dict_getdef $options scale 1.0] set font [dict_getdef $options font "PTSans-Regular"] set text [dict get $options text] - set halign [dict_getdef $options halign "center"] - set valign [dict_getdef $options valign "center"] + set anchor [dict_getdef $options anchor "center"] set radians [dict get $options radians] set color [getColor [dict_getdef $options color white]] - if {$halign == "left"} { - set halign_enum -1 - } elseif {$halign == "right"} { - set halign_enum 1 - } else { set halign_enum 0 } - - if {$valign == "top"} { - set valign_enum -1 - } elseif {$valign == "bottom"} { - set valign_enum 1 - } else { set valign_enum 0 } + if {$anchor == "topleft"} { + set align [list -1 -1] + } elseif {$anchor == "top"} { + set align [list 0 -1] + } elseif {$anchor == "topright"} { + set align [list 1 -1] + } elseif {$anchor == "left"} { + set align [list -1 0] + } elseif {$anchor == "center"} { + set align [list 0 0] + } elseif {$anchor == "right"} { + set align [list 1 0] + } elseif {$anchor == "bottomleft"} { + set align [list -1 1] + } elseif {$anchor == "bottom"} { + set align [list 0 1] + } elseif {$anchor == "bottomright"} { + set align [list 1 1] + } if {!([dict exists $::FontCache $font])} { throw {DISPLAY FONT {font doesn't exist}} "$font doesn't exist" } set font [dict get $::FontCache $font] - set instances [font textShape $font $text $x0 $y0 $scale $halign_enum $valign_enum $radians $color] + set instances [font textShape $font $text $x0 $y0 $scale {*}$align $radians $color] # We need to batch into one wish so we don't deal with n^2 # checks for existing statements for n glyphs. diff --git a/virtual-programs/title.folk b/virtual-programs/title.folk index 565731c4..a430cc16 100644 --- a/virtual-programs/title.folk +++ b/virtual-programs/title.folk @@ -11,34 +11,34 @@ When /thing/ has region /region/ { set scale [dict_getdef $match scale 1.0] set pos [region top [region move $region up 10px]] - Wish to draw text with position $pos scale $scale text $text radians $radians valign bottom + Wish to draw text with position $pos scale $scale text $text radians $radians anchor bottom } - When the collected matches for [list /someone/ wishes $thing is footnoted /text/ with scale /scale/] are /matches/ { + When the collected matches for [list /someone/ wishes $thing is footnoted /text/] are /matches/ { set text [join [lmap match $matches {dict get $match text}] "\n"] if {$text eq ""} { return } set scale [dict_getdef $match scale 0.75] - set pos [region bottom [region move $region down 10px]] - Wish to draw text with position $pos scale $scale text $text radians $radians valign top + set pos [region bottomleft [region move $region down 20px]] + Wish to draw text with position $pos scale $scale text $text radians $radians anchor topleft } - When the collected matches for [list /someone/ wishes $thing is right margined /text/ with scale /scale/] are /matches/ { + When the collected matches for [list /someone/ wishes $thing is right-margined /text/] are /matches/ { set text [join [lmap match $matches {dict get $match text}] "\n"] if {$text eq ""} { return } set scale [dict_getdef $match scale 0.75] set pos [region right [region move $region right 10px]] - Wish to draw text with position $pos scale $scale text $text radians $radians halign left + Wish to draw text with position $pos scale $scale text $text radians $radians anchor left } - When the collected matches for [list /someone/ wishes $thing is left margined /text/ with scale /scale/] are /matches/ { + When the collected matches for [list /someone/ wishes $thing is left-margined /text/] are /matches/ { set text [join [lmap match $matches {dict get $match text}] "\n"] if {$text eq ""} { return } set scale [dict_getdef $match scale 0.75] set pos [region left [region move $region left 10px]] - Wish to draw text with position $pos scale $scale text $text radians $radians halign left + Wish to draw text with position $pos scale $scale text $text radians $radians anchor right } } -- cgit v1.2.3 From 151867f3fb28a79cd794391ed12511a754143f86 Mon Sep 17 00:00:00 2001 From: Naveen Michaud-Agrawal Date: Tue, 21 Nov 2023 02:35:55 +0000 Subject: Small hack to allow pointer warping to work Otherwise there is a eval error on the When when since the warp uses a statement like ``` When /obj/ points /direction/ with length /l/ at $warp ... ``` --- virtual-programs/points-at.folk | 2 ++ 1 file changed, 2 insertions(+) (limited to 'virtual-programs') diff --git a/virtual-programs/points-at.folk b/virtual-programs/points-at.folk index a037f98f..ed3fb8eb 100644 --- a/virtual-programs/points-at.folk +++ b/virtual-programs/points-at.folk @@ -1,8 +1,10 @@ When when /rect/ points /direction/ with length /l/ at /someone/ /lambda/ with environment /e/ { + if {[string match "/*" $rect]} { return } Wish $rect points $direction with length $l } When when /rect/ points /direction/ at /someone/ /lambda/ with environment /e/ { + if {[string match "/*" $rect]} { return } Wish $rect points $direction with length 1 } -- cgit v1.2.3 From fde19f3bf4509a3c48c9da5e718b1a5f29504c40 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 21 Nov 2023 12:16:44 -0500 Subject: music: hack: exclude folk-beads which uses systemd to manage jack --- virtual-programs/music.folk | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/music.folk b/virtual-programs/music.folk index f3574c64..726a3294 100644 --- a/virtual-programs/music.folk +++ b/virtual-programs/music.folk @@ -107,12 +107,14 @@ proc ::Music::exec {args} { proc ::Music::finishSetup {} { variable musicDir - exec jack_control start - exec jack_control ds alsa - exec jack_control dps device hw:HDMI,10 - exec jack_control dps rate 48000 - exec jack_control dps nperiods 2 - exec jack_control dps period 64 + if {$::thisNode ne "folk-beads"} { + exec jack_control start + exec jack_control ds alsa + exec jack_control dps device hw:HDMI,10 + exec jack_control dps rate 48000 + exec jack_control dps nperiods 2 + exec jack_control dps period 64 + } catch {exec pkill ghci} catch {exec pkill sclang} -- cgit v1.2.3 From 0f21d318e395ab976f29c3ae18fe2139c22511bf Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 21 Nov 2023 13:02:43 -0500 Subject: programs: Expose web printed-programs/; fault to folk0 --- virtual-programs/programs.folk | 32 +++++++++++++++++++----------- virtual-programs/web-printed-programs.folk | 9 +++++++++ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 virtual-programs/web-printed-programs.folk (limited to 'virtual-programs') diff --git a/virtual-programs/programs.folk b/virtual-programs/programs.folk index f42e1360..7c98632b 100644 --- a/virtual-programs/programs.folk +++ b/virtual-programs/programs.folk @@ -5,18 +5,26 @@ When (non-capturing) /type/ /obj/ has a program { On unmatch { puts "Removed $type $obj" } try { - set tempPath "$::env(HOME)/folk-printed-programs/$obj.folk.temp" + if {[file exists "$::env(HOME)/folk-printed-programs/$obj.folk.temp"]} { + set fd [open "$::env(HOME)/folk-printed-programs/$obj.folk.temp" r] + } else { + if {![file exists "$::env(HOME)/folk-printed-programs/$obj.folk"] && + ($::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial")} { + # HACK: 'Page fault' to folk0, try getting page from + # there. Ideally we would have some general (Avahi?) + # way of finding the 'authoritative' node on the local + # network, or broadcasting out, and getting pages from + # there. + exec curl --output "$::env(HOME)/folk-printed-programs/$obj.folk" \ + "http://folk0.local:4273/printed-programs/$obj.folk" + } + set fd [open "$::env(HOME)/folk-printed-programs/$obj.folk" r] + } + set code [read $fd] + close $fd - if {[file exists $tempPath]} { - set path [open "$::env(HOME)/folk-printed-programs/$obj.folk.temp" r] - } else { - set path [open "$::env(HOME)/folk-printed-programs/$obj.folk" r] + Claim $obj has program code $code + } on error error { + puts stderr "No code for $type $obj" } - set code [read $path] - close $path - - Claim $obj has program code $code - } on error error { - puts stderr "No code for $type $obj" - } } diff --git a/virtual-programs/web-printed-programs.folk b/virtual-programs/web-printed-programs.folk new file mode 100644 index 00000000..8c90db73 --- /dev/null +++ b/virtual-programs/web-printed-programs.folk @@ -0,0 +1,9 @@ +Wish the web server handles route {/printed-programs/(\d+)\.folk$} with handler { + regexp {/printed-programs/(\d+)\.folk$} $path -> id + set filename "../folk-printed-programs/$id.folk" + set fp [open $filename r] + set data [read $fp] + close $fp + + dict create statusAndHeaders "HTTP/1.1 200 OK\nConnection: close\nContent-Type: text/plain; charset=utf-8\n\n" body $data +} -- cgit v1.2.3 From 9c40b918eb12f50fc56a82e9957b4b0577b3341d Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 21 Nov 2023 13:34:26 -0500 Subject: print: Hack to forward Hex House print requests to folk0 --- virtual-programs/print.folk | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'virtual-programs') diff --git a/virtual-programs/print.folk b/virtual-programs/print.folk index 44a7d433..6197bdd1 100644 --- a/virtual-programs/print.folk +++ b/virtual-programs/print.folk @@ -174,8 +174,27 @@ proc nextId {} { set id } +proc remotePrintRequest {remoteNode clause} { + ::websocket::open "ws://$remoteNode.local:4273/ws" [list apply {{clause sock type msg} { + if {$type eq "connect"} { + ::websocket::send $sock text [list apply {{clause} { + Assert {*}$clause + after 5000 [list Retract {*}$clause] + Step + }} $clause] + after 10000 [list ::websocket::close $sock] + } + }} $clause] +} + if {![info exists ::printjobs]} {set ::printjobs [dict create]} When /someone/ wishes to print /code/ with job id /jobid/ { + if {$::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial"} { + # HACK: Forward the print request to folk0. + remotePrintRequest "folk0" [list $::thisNode wishes to print $code with job id $jobid] + return + } + puts "Wish to print jobid $jobid" if {[dict exists $::printjobs $jobid]} {return} @@ -205,6 +224,12 @@ When /someone/ wishes to print /code/ with job id /jobid/ { exec lpr $::env(HOME)/folk-printed-programs/$id.pdf } When /someone/ wishes to print program /id/ with code /code/ with job id /jobid/ { + if {$::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial"} { + # HACK: Forward the print request to folk0. + remotePrintRequest "folk0" [list $::thisNode wishes to print program $id with code $code with job id $jobid] + return + } + puts "Wish to print jobid $jobid" if {[dict exists $::printjobs $jobid]} {return} -- cgit v1.2.3