commit beca254bf6e1532c4db8640c71bd96dbdaff8462
parent 4c2bed5ef03fb937bdd4f156c6f54f768f01f700
Author: Daniel Barlow <dan@telent.net>
Date: Fri, 6 Jun 2025 21:31:31 +0100
rename cairo-the-map -> draw-onto-map-surface
and make it take a surface directly, not a window
Diffstat:
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl
@@ -180,7 +180,7 @@ label.readout {
(var map-surface nil)
-(fn cairo-the-map [window]
+(fn draw-onto-map-surface [surface]
(let [{ : lat : lon : zoom } app-state
{ : num-tiles-x : num-tiles-y &as bounds } (map-bounds lat lon zoom)
road-width 14
@@ -192,13 +192,8 @@ label.readout {
#(set map-surface nil)
))))
- (let [map-surface
- (window:create_similar_surface
- cairo.Content.COLOR
- (* tile-size (+ 1 num-tiles-x))
- (* tile-size (+ 1 num-tiles-y)))
- seen-road-names {}
- g (cairo.Context.create map-surface)]
+ (let [seen-road-names {}
+ 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))
@@ -233,18 +228,23 @@ label.readout {
(g:fill)
(g:restore)))))
- map-surface)))
+ surface)))
(fn on-osm-draw [widget g]
- (when (not map-surface)
- (let [window (widget:get_window)]
- (set map-surface (cairo-the-map window))))
-
(let [(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom)
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)]
+ (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))))
(g:set_source_surface map-surface (- offset-x) (- offset-y))
(g:set_operator cairo.Operator.SOURCE)