aboutsummaryrefslogtreecommitdiff
path: root/mavigator-dashboard/src/main/scala/mavigator/dashboard/ui/Hud.scala
blob: 18c5c27daf85cd51a61fc8b1fdd533d6a4781182 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package mavigator.dashboard.ui

import mavigator.util.Environment
import mavigator.dashboard.ui.instruments._

import scalatags.JsDom.all._
import rx._

class Hud(attitude: Rx[(Double, Double)])(implicit env: Environment) {

  private def overlay(name: String, z: Int, thinnerThanWide: Boolean = false) = {
    val direction = if (thinnerThanWide) "row" else "column"
    div(
      style:=
        "position: absolute; left: 0; right: 0; top: 0; bottom: 0;" +
        s"display: flex; align-content: center; align-items: stretch; flex-direction: $direction;"+
        s"z-index: $z;"
    )(
      `object`(`type`:="image/svg+xml", "data".attr:=env.asset("images/hud/" + name + ".svg"), style := "flex: 1 1 100%;")
    )
  }

  object Horizon extends SvgInstrument[(Double, Double)] {
    import SvgInstrument._

    val value = attitude

    lazy val element = `object`(`type`:="image/svg+xml", "data".attr:=env.asset("images/hud/horizon.svg"), style:="flex: 1 1 100%;").render
    lazy val horizon = part("horizon")
    lazy val moveable = Seq(horizon)
  
    protected def update(pitchRoll: (Double, Double)) = {
      rotate(horizon, pitchRoll._2)
      //translate(horizon, 0, (pitchRoll._1 * 180 / math.Pi).toInt) // 1deg === 1px
    }
  }

  val element = div(
      style:=
        "position: absolute; left: 0; right: 0; top: 0; bottom: 0;" +
        "display: flex; align-content: stretch; align-items: stretch; flex-direction: row;"+
        "z-index: 0;"
  )(
       Horizon.element
    )
}