summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorNaveen Michaud-Agrawal <naveen.michaudagrawal@gmail.com>2023-11-17 05:28:44 +0000
committerNaveen Michaud-Agrawal <naveen.michaudagrawal@gmail.com>2023-11-17 05:28:44 +0000
commit9274f593d7a5ec0b33882f6d8d76cd800a90d747 (patch)
tree6e6417346affbd979433f0e3715ed13f40313e73 /virtual-programs
parentAdd horizontal text alignment (diff)
downloadfolk-9274f593d7a5ec0b33882f6d8d76cd800a90d747.tar.gz
folk-9274f593d7a5ec0b33882f6d8d76cd800a90d747.zip
Add vertical alignment
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/display/text.folk34
1 files changed, 27 insertions, 7 deletions
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.