Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
a47026f5d3 | |||
7543e775e5 |
@ -66,7 +66,7 @@ label.readout {
|
|||||||
:lon 0
|
:lon 0
|
||||||
:zoom 17
|
:zoom 17
|
||||||
:course 0 ; direction of travel
|
:course 0 ; direction of travel
|
||||||
:orientation 0 ; map rotation angle from north
|
:orientation {:target 0 :actual 0} ; map rotation angle from north
|
||||||
:tiles {}
|
:tiles {}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -186,8 +186,10 @@ label.readout {
|
|||||||
(set biggest-n (- i 1)))))
|
(set biggest-n (- i 1)))))
|
||||||
(let [[x y] (. points biggest-n)
|
(let [[x y] (. points biggest-n)
|
||||||
[nx ny] (. points (+ 1 biggest-n))
|
[nx ny] (. points (+ 1 biggest-n))
|
||||||
angle (math.atan (- ny y) (- nx x))]
|
angle (math.atan (- ny y) (- nx x))
|
||||||
(if (> nx x)
|
screen-angle (- angle
|
||||||
|
(/ (* app-state.orientation.target math.pi) 180))]
|
||||||
|
(if (< (math.abs screen-angle) (/ math.pi 2))
|
||||||
(values
|
(values
|
||||||
(* tile-size (- x bounds.min.x))
|
(* tile-size (- x bounds.min.x))
|
||||||
(* tile-size (- y bounds.min.y))
|
(* tile-size (- y bounds.min.y))
|
||||||
@ -271,7 +273,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) 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))
|
||||||
@ -322,15 +324,22 @@ label.readout {
|
|||||||
(when (not (bounds= old-bounds bounds))
|
(when (not (bounds= old-bounds bounds))
|
||||||
(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)))
|
||||||
(set app-state.orientation
|
(when (> (math.abs (- app-state.orientation.target app-state.course)) 20)
|
||||||
(+ app-state.orientation
|
(set app-state.orientation.target app-state.course)
|
||||||
(* 0.05 (- app-state.course app-state.orientation))))
|
(set map-surface nil))
|
||||||
|
|
||||||
|
(when (not (= app-state.orientation.target app-state.orientation.actual))
|
||||||
|
(set app-state.orientation.actual
|
||||||
|
(+ 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 (: (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)
|
||||||
:time (widget:set_label
|
:time (widget:set_label
|
||||||
(hhmmss (+ utc-offset app-state.time-of-day)))
|
(hhmmss (+ utc-offset app-state.time-of-day)))
|
||||||
))))
|
))))
|
||||||
@ -359,7 +368,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)
|
(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)
|
||||||
@ -370,6 +379,48 @@ label.readout {
|
|||||||
true)
|
true)
|
||||||
}))))
|
}))))
|
||||||
|
|
||||||
|
(fn deg->rad [degrees]
|
||||||
|
(* math.pi (/ degrees 180)))
|
||||||
|
|
||||||
|
(fn rose []
|
||||||
|
(let [height 60]
|
||||||
|
(register-widget
|
||||||
|
:rose
|
||||||
|
(Gtk.Label {
|
||||||
|
:halign Gtk.Align.START
|
||||||
|
:valign Gtk.Align.START
|
||||||
|
:width height :height height
|
||||||
|
:on_draw
|
||||||
|
(fn [self g]
|
||||||
|
(g:save)
|
||||||
|
(g:set_line_width 1)
|
||||||
|
(g:set_source_rgb 0.4 0.0 0.1)
|
||||||
|
(g:arc (// height 2) (// height 2) 15
|
||||||
|
0 (* 2 math.pi))
|
||||||
|
(g:stroke)
|
||||||
|
|
||||||
|
(g:translate (// height 2) (// height 2))
|
||||||
|
(g:rotate (- (deg->rad app-state.orientation.actual)))
|
||||||
|
(g:translate (// height -2) (// height -2))
|
||||||
|
|
||||||
|
(g:set_line_width 2)
|
||||||
|
(g:move_to (// height 2) height)
|
||||||
|
(g:line_to (// height 2) 0)
|
||||||
|
|
||||||
|
(g:move_to 10 20)
|
||||||
|
(g:line_to (// height 2) 0)
|
||||||
|
(g:line_to (- height 10) 20)
|
||||||
|
(g:stroke)
|
||||||
|
|
||||||
|
(g:set_source_rgb 1 1 0)
|
||||||
|
(g:move_to (// height -2) (// height -2))
|
||||||
|
(g:text_path "N")
|
||||||
|
(g:fill)
|
||||||
|
|
||||||
|
(g:restore)
|
||||||
|
true)
|
||||||
|
}))))
|
||||||
|
|
||||||
|
|
||||||
(local socket-path (or (. arg 1) "/var/run/gnss-share.sock"))
|
(local socket-path (or (. arg 1) "/var/run/gnss-share.sock"))
|
||||||
|
|
||||||
@ -426,6 +477,7 @@ label.readout {
|
|||||||
(: :add (osm-widget))
|
(: :add (osm-widget))
|
||||||
(: :add_overlay (readouts))
|
(: :add_overlay (readouts))
|
||||||
(: :add_overlay (arrow))
|
(: :add_overlay (arrow))
|
||||||
|
(: :add_overlay (rose))
|
||||||
))
|
))
|
||||||
|
|
||||||
(window:show_all)
|
(window:show_all)
|
||||||
|
Loading…
Reference in New Issue
Block a user