Add shift indicator
This commit is contained in:
parent
c6f0ef5ec1
commit
68ee09b8c1
1 changed files with 63 additions and 2 deletions
|
@ -2,6 +2,9 @@ import math
|
|||
import cairo
|
||||
|
||||
class Gauge():
|
||||
pass
|
||||
|
||||
class Dial(Gauge):
|
||||
__slots = 'x', 'y', 'radius',
|
||||
|
||||
BEZEL_WIDTH = 16
|
||||
|
@ -45,18 +48,76 @@ class Gauge():
|
|||
cr.arc(*arc)
|
||||
cr.stroke()
|
||||
|
||||
class ShiftIndicator(Gauge):
|
||||
LIGHT_WIDTH = 48
|
||||
LIGHT_HEIGHT = 12
|
||||
LIGHT_SPACING = 8
|
||||
LIGHT_LOW = 0.25
|
||||
|
||||
LIGHT_COLORS = (
|
||||
(0.0, 1.0, 0.0),
|
||||
(0.6, 1.0, 0.0),
|
||||
(1.0, 1.0, 0.0),
|
||||
(1.0, 0.6, 0.0),
|
||||
(1.0, 0.0, 0.0),
|
||||
)
|
||||
|
||||
LIGHT_LEVELS = (
|
||||
(0, 8),
|
||||
(1, 7),
|
||||
(2, 6),
|
||||
(3, 5),
|
||||
(4,),
|
||||
)
|
||||
|
||||
__slots__ = 'x', 'y', 'redline',
|
||||
|
||||
def __init__(self, x: float, y: float, redline: float):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.redline = redline
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
for level in range(0, len(self.LIGHT_LEVELS)):
|
||||
r = self.LIGHT_LOW * self.LIGHT_COLORS[level][0]
|
||||
g = self.LIGHT_LOW * self.LIGHT_COLORS[level][1]
|
||||
b = self.LIGHT_LOW * self.LIGHT_COLORS[level][2]
|
||||
|
||||
cr.set_source_rgb(r, g, b)
|
||||
|
||||
for i in self.LIGHT_LEVELS[level]:
|
||||
x = i * (self.LIGHT_WIDTH + self.LIGHT_SPACING)
|
||||
|
||||
cr.rectangle(self.x + x,
|
||||
self.y,
|
||||
self.LIGHT_WIDTH,
|
||||
self.LIGHT_HEIGHT)
|
||||
|
||||
cr.fill()
|
||||
|
||||
class Cluster():
|
||||
WIDTH = 1280
|
||||
HEIGHT = 480
|
||||
|
||||
SHIFT_INDICATOR_X = 392
|
||||
SHIFT_INDICATOR_Y = 24
|
||||
|
||||
__slots__ = 'gauges',
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, redline: float):
|
||||
self.gauges = list()
|
||||
|
||||
for x in (self.HEIGHT / 2, self.WIDTH - self.HEIGHT / 2):
|
||||
self.gauges.append(Gauge(x, self.HEIGHT / 2, self.HEIGHT / 2))
|
||||
self.gauges.append(Dial(x, self.HEIGHT / 2, self.HEIGHT / 2))
|
||||
|
||||
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
|
||||
self.SHIFT_INDICATOR_Y,
|
||||
redline))
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
cr.set_source_rgb(0, 0, 0)
|
||||
cr.rectangle(0, 0, self.WIDTH, self.HEIGHT)
|
||||
cr.fill()
|
||||
|
||||
for gauge in self.gauges:
|
||||
gauge.draw_bg(cr)
|
||||
|
|
Loading…
Add table
Reference in a new issue