From ef73ec928b677f6c9ff3024cc09a926b48438964 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 26 Sep 2023 19:07:27 -0400 Subject: display: Reintroduce stroke color support --- virtual-programs/display.folk | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index 3fc02d85..cc31575d 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -33,6 +33,8 @@ On process { Gpu::ImageManager::imageManagerInit namespace eval Display { + namespace eval Colors { source "pi/Colors.tcl" } + variable rotate [Gpu::fn {vec2 v float a} vec2 { float s = sin(a); float c = cos(a); @@ -153,7 +155,7 @@ On process { return mix(vec4(0, 0, 0, 0), vec4(1, 1, 1, 1), opacity); }] - variable line [Gpu::pipeline {vec2 from vec2 to float thickness} { + variable line [Gpu::pipeline {vec2 from vec2 to float thickness vec4 color} { vec2 vertices[4] = vec2[4]( min(from, to) - thickness, vec2(max(from.x, to.x) + thickness, min(from.y, to.y) - thickness), @@ -169,17 +171,22 @@ On process { q = abs(q) - vec2(l, thickness)*0.5; float dist = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0); - return dist < 0.0 ? vec4(1, 0, 1, 1) : vec4(0, 0, 0, 0); + return dist < 0.0 ? color : vec4(0, 0, 0, 0); }] proc start {} { Gpu::drawStart } + proc getColor {color} { + if {[info exists Colors::$color]} { return [set Colors::$color] } \ + else { return $Colors::white } + } + proc stroke {points width color} { variable line for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} { set from [lindex $points $i] set to [lindex $points [expr $i+1]] - Gpu::draw $line $from $to $width + Gpu::draw $line $from $to $width [getColor $color] } } proc circle {x y radius thickness color} {} -- cgit v1.2.3