diff --git a/py/hexagram/cluster.py b/py/hexagram/cluster.py index 129db8e..73947fc 100644 --- a/py/hexagram/cluster.py +++ b/py/hexagram/cluster.py @@ -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) diff --git a/py/hexagram/dial.py b/py/hexagram/dial.py index 3c656ea..c28b921 100644 --- a/py/hexagram/dial.py +++ b/py/hexagram/dial.py @@ -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) diff --git a/py/hexagram/fuel.py b/py/hexagram/fuel.py index 393cfef..eacacbf 100644 --- a/py/hexagram/fuel.py +++ b/py/hexagram/fuel.py @@ -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 diff --git a/py/hexagram/gauge.py b/py/hexagram/gauge.py index b443e3a..6401a27 100644 --- a/py/hexagram/gauge.py +++ b/py/hexagram/gauge.py @@ -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 diff --git a/py/hexagram/speedo.py b/py/hexagram/speedo.py index 0693ab5..98524b3 100644 --- a/py/hexagram/speedo.py +++ b/py/hexagram/speedo.py @@ -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): diff --git a/py/hexagram/tacho.py b/py/hexagram/tacho.py index 8628269..91ab094 100644 --- a/py/hexagram/tacho.py +++ b/py/hexagram/tacho.py @@ -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)) diff --git a/py/hexagram/thermo.py b/py/hexagram/thermo.py index 457f2e8..4985f7d 100644 --- a/py/hexagram/thermo.py +++ b/py/hexagram/thermo.py @@ -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