From 68ee09b8c19f34ba648b027a6b0b7c702175b2d4 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 29 Dec 2023 18:43:06 -0500 Subject: [PATCH] Add shift indicator --- py/hexagram/cluster.py | 65 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/py/hexagram/cluster.py b/py/hexagram/cluster.py index 9bee2dc..84d52af 100644 --- a/py/hexagram/cluster.py +++ b/py/hexagram/cluster.py @@ -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)