add pixel dimensions in bounds

This commit is contained in:
Daniel Barlow 2025-06-07 12:26:58 +01:00
parent 1ee968d3a2
commit 2d2f592d73

View File

@ -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)