From 521bc409e5fbe4c4da34f4455ee1da6bd378198c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 2 Jun 2025 21:53:26 +0100 Subject: [PATCH] render road names (badly) --- pkgs/maps/main.fnl | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 82fb1ff..f04350d 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -119,7 +119,28 @@ label.readout { (local cq (cqueues.new)) -(var map-surface nil) +(fn cairo-roads-path [g lines bounds] + (each [_ line (pairs lines)] + (case line.points + [[sx sy] & more] + (do + (g:save) + (g:move_to (* tile-size (- sx bounds.min.x)) + (* tile-size (- sy bounds.min.y))) + (each [_ [x y] (ipairs more)] + (let [x1 (* tile-size (- x bounds.min.x)) + y1 (* tile-size (- y bounds.min.y))] + (g:line_to x1 y1))) + (g:stroke) + (g:restore))))) + +(fn label-coords [line bounds] + (case line.points + [[sx sy] & more] + (values + (* tile-size (- sx bounds.min.x)) + (* tile-size (- sy bounds.min.y))))) + (fn cairo-the-map [window] (let [{ : lat : lon : zoom } app-state @@ -144,37 +165,20 @@ label.readout { (g:rectangle 0 0 (* tile-size num-tiles-x) (* tile-size num-tiles-y)) (g:fill) - (each [_ line (pairs lines)] - (case line.points - [[sx sy] & more] - (do - (g:save) - (g:set_source_rgb 0 0 0) - (g:set_line_width road-width) - (g:move_to (* tile-size (- sx bounds.min.x)) - (* tile-size (- sy bounds.min.y))) - (each [_ [x y] (ipairs more)] - (let [x1 (* tile-size (- x bounds.min.x)) - y1 (* tile-size (- y bounds.min.y))] - (g:line_to x1 y1))) - (g:stroke) - (g:restore)))) + (g:set_source_rgb 0 0 0) + (g:set_line_width road-width) + (cairo-roads-path g lines bounds) + (g:set_source_rgb 1 1 1) + (g:set_line_width (- road-width 2)) + (cairo-roads-path g lines bounds) + (g:set_source_rgb 0.2 0.2 0.2) (each [_ line (pairs lines)] - (case line.points - [[sx sy] & more] - (do - (g:save) - (g:set_source_rgb 1 1 1) - (g:set_line_width (- road-width 2)) - (g:move_to (* tile-size (- sx bounds.min.x)) - (* tile-size (- sy bounds.min.y))) - (each [_ [x y] (ipairs more)] - (let [x1 (* tile-size (- x bounds.min.x)) - y1 (* tile-size (- y bounds.min.y))] - (g:line_to x1 y1))) - (g:stroke) - (g:restore)))) + (case line.name + n (let [(x y) (label-coords line bounds)] + (when (and x y) + (g:move_to x y) + (g:show_text n))))) map-surface)))