Oh gosh, we're starting to render foreground?

This commit is contained in:
XANTRONIX Development 2024-01-01 18:54:45 -05:00
parent 8d73d6c184
commit d4b3a40ab5
7 changed files with 68 additions and 1 deletions

View file

@ -111,3 +111,10 @@ class Cluster():
for gauge in self.gauges:
gauge.draw_bg(cr)
def draw_fg(self, cr: cairo.Context):
for gauge in self.gauges:
fn = getattr(gauge, 'draw_fg', None)
if fn is not None:
fn(cr)

View file

@ -15,6 +15,8 @@ class Dial(Gauge):
)
def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float, max_value: float):
super().__init__()
self.x = x
self.y = y
self.radius = radius
@ -102,3 +104,6 @@ class Dial(Gauge):
cr.set_line_width(self.BEZEL_WIDTH / 3)
cr.arc(self.x, self.y, self.radius / 2, 0, 2.0 * math.pi)
cr.stroke()
def draw_fg(self, cr: cairo.Context):
self.draw_needle(cr, 0.5, 0.89, self.value)

View file

@ -73,3 +73,6 @@ class FuelGauge(Dial):
cr.set_source_rgb(1, 1, 1)
self.draw_mark(cr, min_radius, 0.87, self.max_value - level)
def draw_fg(self, cr: cairo.Context):
pass

View file

@ -1,5 +1,13 @@
import cairo
class Gauge():
__slots__ = 'value',
def __init__(self):
self.value = None
def draw_bg(self, cr: cairo.Context):
raise NotImplementedError
def set_value(self, value):
self.value = value

View file

@ -19,6 +19,7 @@ class Speedo(Dial):
def __init__(self, x: float, y: float, radius: float, max_value: float, units: SpeedUnits=SpeedUnits.KPH):
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, max_value)
self.value = 0
self.units = units
def draw_bg(self, cr: cairo.Context):

View file

@ -4,8 +4,32 @@ import cairo
from hexagram.dial import Dial
class Gear(enum.Enum):
R = -1
N = 0
GEAR_1 = 1
GEAR_2 = 2
GEAR_3 = 3
GEAR_4 = 4
GEAR_5 = 5
GEAR_6 = 6
GEAR_7 = 7
GEAR_8 = 8
GEAR_9 = 9
GEAR_10 = 10
def __str__(self):
strs = {
-1: 'R', 0: 'N', 1: '1',
2: '2', 3: '3', 4: '4',
5: '5', 6: '6', 7: '7',
8: '8', 9: '9', 10: '10'
}
return strs.get(self.value, '?')
class Tacho(Dial):
__slots__ = 'units',
__slots__ = 'gear',
MIN_ANGLE = 232.0 * (math.pi / 180.0)
MAX_ANGLE = 488.0 * (math.pi / 180.0)
@ -15,6 +39,9 @@ class Tacho(Dial):
def __init__(self, x: float, y: float, radius: float, max_value: float):
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, max_value)
self.value = 0
self.gear: Gear = Gear.N
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
scale = value / self.max_value
angle = self.min_angle + ((self.max_angle - self.min_angle) * scale) - Dial.ANGLE_OFFSET
@ -51,3 +78,16 @@ class Tacho(Dial):
cr.set_source_rgb(1.0, 0.1, 0.1)
self.draw_number(cr, 0.69, speed, "%d" % int(speed / 1000))
def draw_fg(self, cr: cairo.Context):
super().draw_fg(cr)
cr.select_font_face("HEX:gon Bold Italic")
cr.set_font_size(self.radius * 0.25)
cr.set_source_rgb(1, 0.4, 1)
cr.move_to(self.x - (self.radius * 0.25) / 2,
self.y + (self.radius * 0.1))
cr.show_text(str(self.gear))

View file

@ -70,3 +70,6 @@ class ThermoGauge(Dial):
cr.set_source_rgb(1, 1, 1)
self.draw_mark(cr, 0.83, 0.87, self.max_value - level)
def draw_fg(self, cr: cairo.Context):
pass