From 2d2f592d734f11a57982c38e807d5ec3f3506789 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 7 Jun 2025 12:26:58 +0100 Subject: [PATCH] add pixel dimensions in bounds --- pkgs/maps/main.fnl | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 656909c..57987ae 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -79,12 +79,19 @@ label.readout { (let [min-tile-x (math.floor (- tile-x (/ map-width tile-size 2))) max-tile-x (math.floor (+ tile-x (/ map-width tile-size 2))) min-tile-y (math.floor (- tile-y (/ map-height tile-size 2))) - max-tile-y (math.floor (+ tile-y (/ map-height tile-size 2)))] + max-tile-y (math.floor (+ tile-y (/ map-height tile-size 2))) + num-tiles-x (+ 1 (- max-tile-x min-tile-x)) + num-tiles-y (+ 1 (- max-tile-y min-tile-y))] + { :min { :x min-tile-x :y min-tile-y } :max { :x max-tile-x :y max-tile-y } - :num-tiles-x (+ 1 (- max-tile-x min-tile-x)) - :num-tiles-y (+ 1 (- max-tile-y min-tile-y)) + : num-tiles-x + : num-tiles-y + :pixels { + :x (* tile-size num-tiles-x) + :y (* tile-size num-tiles-y) + } })) ;; 720 width is 2.8 * 256 pixel tiles @@ -195,10 +202,10 @@ label.readout { g (cairo.Context.create surface)] (g:set_source_rgb 0.7 0.8 0.8) - (g:rectangle 0 0 (* tile-size num-tiles-x) (* tile-size num-tiles-y)) + (g:rectangle 0 0 bounds.pixels.x bounds.pixels.y) (g:fill) - (cairo-roads g lines bounds) + (cairo-roads g lines bounds) (g:set_source_rgb 0.2 0.2 0.2) (g:set_font_size (+ road-width 1)) @@ -235,16 +242,16 @@ label.readout { bounds (map-bounds-tile tile-x tile-y) offset-x (- (* tile-size (- tile-x bounds.min.x)) (/ map-width 2)) offset-y (- (* tile-size (- tile-y bounds.min.y)) (/ map-height 2))] + (when (not map-surface) - (let [window (widget:get_window) - { : lat : lon : zoom } app-state] + (let [window (widget:get_window)] (set map-surface (doto (window:create_similar_surface cairo.Content.COLOR - (* tile-size bounds.num-tiles-x) - (* tile-size bounds.num-tiles-y)) - (draw-onto-map-surface bounds zoom))))) + bounds.pixels.x + bounds.pixels.y) + (draw-onto-map-surface bounds app-state.zoom))))) (g:set_source_surface map-surface (- offset-x) (- offset-y)) (g:set_operator cairo.Operator.SOURCE)