Ugly hack but I have a fuel gauge???
This commit is contained in:
parent
7f468c715c
commit
cec20b55bd
2 changed files with 70 additions and 1 deletions
|
@ -8,6 +8,7 @@ from hexagram.gauge import Gauge
|
|||
from hexagram.dial import Dial
|
||||
from hexagram.speedo import Speedo
|
||||
from hexagram.tacho import Tacho
|
||||
from hexagram.fuel import FuelGauge
|
||||
|
||||
class ShiftIndicator(Gauge):
|
||||
__slots__ = 'x', 'y', 'rpm_redline', 'rpm_max',
|
||||
|
@ -64,7 +65,7 @@ class Cluster():
|
|||
SHIFT_INDICATOR_X = 392
|
||||
SHIFT_INDICATOR_Y = 24
|
||||
|
||||
__slots__ = 'gauges', 'speedo', 'tacho',
|
||||
__slots__ = 'gauges', 'speedo', 'tacho', 'fuel',
|
||||
|
||||
def __init__(self, rpm_redline: float, rpm_max: float):
|
||||
self.gauges: List[Gauge] = list()
|
||||
|
@ -79,7 +80,12 @@ class Cluster():
|
|||
self.HEIGHT / 2,
|
||||
8000)
|
||||
|
||||
self.fuel = FuelGauge(self.HEIGHT / 2,
|
||||
self.HEIGHT / 2,
|
||||
self.HEIGHT / 2)
|
||||
|
||||
self.gauges.append(self.speedo)
|
||||
self.gauges.append(self.fuel)
|
||||
self.gauges.append(self.tacho)
|
||||
|
||||
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
|
||||
|
|
63
py/hexagram/fuel.py
Normal file
63
py/hexagram/fuel.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
import enum
|
||||
import math
|
||||
import cairo
|
||||
|
||||
from hexagram.dial import Dial
|
||||
|
||||
class FuelGauge(Dial):
|
||||
MIN_ANGLE = 144.0 * (math.pi / 180.0)
|
||||
MAX_ANGLE = 216.0 * (math.pi / 180.0)
|
||||
|
||||
MAX_VALUE = 15
|
||||
|
||||
FONT_FACE = "Muli"
|
||||
|
||||
def __init__(self, x: float, y: float, radius: float):
|
||||
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, self.MAX_VALUE)
|
||||
|
||||
def draw_value(self, cr: cairo.Context, radius: float, value: float, text: str, x_offset: float):
|
||||
scale = (self.max_value - value) / self.max_value
|
||||
angle = self.min_angle + ((self.max_angle - self.min_angle) * scale) - self.ANGLE_OFFSET
|
||||
|
||||
cr.move_to(self.x + radius * self.radius * math.cos(angle) + x_offset,
|
||||
self.y + radius * self.radius * math.sin(angle))
|
||||
|
||||
cr.show_text(text)
|
||||
cr.stroke()
|
||||
|
||||
def draw_mark(self, cr: cairo.Context, min_radius: float, max_radius: float, value: float):
|
||||
angle = self.min_angle + \
|
||||
((self.max_angle - self.min_angle) * (value / self.max_value)) - self.ANGLE_OFFSET
|
||||
|
||||
cr.move_to(self.x + (min_radius * self.radius) * math.cos(angle),
|
||||
self.y + (min_radius * self.radius) * math.sin(angle))
|
||||
|
||||
cr.line_to(self.x + (max_radius * self.radius) * math.cos(angle),
|
||||
self.y + (max_radius * self.radius) * math.sin(angle))
|
||||
|
||||
cr.stroke()
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
cr.select_font_face(self.FONT_FACE,
|
||||
cairo.FontSlant.NORMAL,
|
||||
cairo.FontWeight.BOLD)
|
||||
|
||||
cr.set_font_size(self.radius * 0.1)
|
||||
|
||||
cr.set_source_rgb(1, 0, 0)
|
||||
self.draw_value(cr, 0.75, 0, "0", -10)
|
||||
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
self.draw_value(cr, 0.75, 15, "1", 0)
|
||||
|
||||
cr.set_line_width(6.0)
|
||||
|
||||
for level in range(0, self.MAX_VALUE+1):
|
||||
if level < 4:
|
||||
min_radius = 0.84
|
||||
cr.set_source_rgb(1, 0, 0)
|
||||
else:
|
||||
min_radius = 0.82
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
|
||||
self.draw_mark(cr, min_radius, 0.87, self.max_value - level)
|
Loading…
Add table
Reference in a new issue