don't force invalidate map widget unless moved
* make the app-state a single-level table so we can easily copy it and check for changes * call invalidate_rect only if we've moved or changed orientation
This commit is contained in:
parent
2406a15db9
commit
ccca847e3c
@ -86,7 +86,8 @@ label.readout {
|
|||||||
:lon 0
|
:lon 0
|
||||||
:zoom 17
|
:zoom 17
|
||||||
:course 0 ; direction of travel
|
:course 0 ; direction of travel
|
||||||
:orientation {:target 0 :actual 0} ; map rotation angle from north
|
:orientation-target 0 ; map rotation angle from north
|
||||||
|
:orientation-actual 0 ; map rotation angle from north
|
||||||
:tiles {}
|
:tiles {}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -259,7 +260,7 @@ label.readout {
|
|||||||
(draw-onto-map-surface bounds app-state.zoom)))))
|
(draw-onto-map-surface bounds app-state.zoom)))))
|
||||||
|
|
||||||
(g:translate (+ (/ viewport-width 2)) (+ (/ viewport-height 2)))
|
(g:translate (+ (/ viewport-width 2)) (+ (/ viewport-height 2)))
|
||||||
(g:rotate (* (/ (- 360 app-state.orientation.actual) 180) math.pi))
|
(g:rotate (* (/ (- 360 app-state.orientation-actual) 180) math.pi))
|
||||||
(g:translate (- (/ viewport-width 2)) (- (/ viewport-height 2)))
|
(g:translate (- (/ viewport-width 2)) (- (/ viewport-height 2)))
|
||||||
|
|
||||||
(g:set_source_surface map-surface (- offset-x) (- offset-y))
|
(g:set_source_surface map-surface (- offset-x) (- offset-y))
|
||||||
@ -302,7 +303,8 @@ label.readout {
|
|||||||
|
|
||||||
|
|
||||||
(fn update-app-state [new-vals]
|
(fn update-app-state [new-vals]
|
||||||
(let [old-bounds
|
(let [old-state (merge {} app-state)
|
||||||
|
old-bounds
|
||||||
(map-bounds app-state.lat app-state.lon app-state.zoom)]
|
(map-bounds app-state.lat app-state.lon app-state.zoom)]
|
||||||
(merge app-state new-vals)
|
(merge app-state new-vals)
|
||||||
(let [bounds
|
(let [bounds
|
||||||
@ -311,22 +313,29 @@ label.readout {
|
|||||||
(fetch-tiles bounds app-state.tiles app-state.zoom)
|
(fetch-tiles bounds app-state.tiles app-state.zoom)
|
||||||
(set map-surface nil)))
|
(set map-surface nil)))
|
||||||
|
|
||||||
(when (> (math.abs (- app-state.orientation.target app-state.course)) 20)
|
(when (> (math.abs (- app-state.orientation-target app-state.course)) 20)
|
||||||
(set app-state.orientation.target app-state.course)
|
(set app-state.orientation-target app-state.course)
|
||||||
; (-> state-widgets.rose (: :get_window) (: :invalidate_rect nil))
|
; (-> state-widgets.rose (: :get_window) (: :invalidate_rect nil))
|
||||||
(set map-surface nil))
|
(set map-surface nil))
|
||||||
|
|
||||||
(when (not (= app-state.orientation.target app-state.orientation.actual))
|
(when (not (= app-state.orientation-target app-state.orientation-actual))
|
||||||
(set app-state.orientation.actual
|
(set app-state.orientation-actual
|
||||||
(+ app-state.orientation.actual
|
(+ app-state.orientation-actual
|
||||||
(* 0.05 (- app-state.orientation.target app-state.orientation.actual))))
|
(* 0.05 (- app-state.orientation-target app-state.orientation-actual))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(each [name widget (pairs state-widgets)]
|
(each [name widget (pairs state-widgets)]
|
||||||
(case name
|
(case name
|
||||||
:speed (widget:set_label
|
:speed (widget:set_label
|
||||||
(string.format "%.1f km/h" (* app-state.speed 3.6)))
|
(string.format "%.1f km/h" (* app-state.speed 3.6)))
|
||||||
:osm (: (widget:get_window) :invalidate_rect nil)
|
:osm
|
||||||
|
(when (not (and ; false
|
||||||
|
(= old-state.lat app-state.lat)
|
||||||
|
(= old-state.lon app-state.lon)
|
||||||
|
(= old-state.orientation-actual
|
||||||
|
app-state.orientation-actual)
|
||||||
|
))
|
||||||
|
(: (widget:get_window) :invalidate_rect nil))
|
||||||
:arrow (: (widget:get_window) :invalidate_rect nil)
|
:arrow (: (widget:get_window) :invalidate_rect nil)
|
||||||
:rose (: (widget:get_window) :invalidate_rect nil)
|
:rose (: (widget:get_window) :invalidate_rect nil)
|
||||||
:time (widget:set_label
|
:time (widget:set_label
|
||||||
@ -357,7 +366,7 @@ label.readout {
|
|||||||
(fn [self g]
|
(fn [self g]
|
||||||
(g:set_source_rgb 0.4 0.0 0.1)
|
(g:set_source_rgb 0.4 0.0 0.1)
|
||||||
(g:translate (// height 2) (// height 2))
|
(g:translate (// height 2) (// height 2))
|
||||||
(g:rotate (* (/ (- app-state.course app-state.orientation.actual)
|
(g:rotate (* (/ (- app-state.course app-state.orientation-actual)
|
||||||
180) math.pi))
|
180) math.pi))
|
||||||
(g:translate (// height -2) (// height -2))
|
(g:translate (// height -2) (// height -2))
|
||||||
(g:set_line_width 4)
|
(g:set_line_width 4)
|
||||||
@ -389,7 +398,7 @@ label.readout {
|
|||||||
(g:stroke)
|
(g:stroke)
|
||||||
|
|
||||||
(g:translate (// height 2) (// height 2))
|
(g:translate (// height 2) (// height 2))
|
||||||
(g:rotate (- (deg->rad app-state.orientation.actual)))
|
(g:rotate (- (deg->rad app-state.orientation-actual)))
|
||||||
(g:translate (// height -2) (// height -2))
|
(g:translate (// height -2) (// height -2))
|
||||||
|
|
||||||
(g:set_line_width 2)
|
(g:set_line_width 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user