idk...This is happening?
This commit is contained in:
parent
f3d33400d7
commit
8d304bf663
3 changed files with 22 additions and 18 deletions
|
@ -71,13 +71,14 @@ class Cluster():
|
|||
self.speedo = Speedo(self.HEIGHT / 2,
|
||||
self.HEIGHT / 2,
|
||||
self.HEIGHT / 2,
|
||||
350.0)
|
||||
180.0)
|
||||
|
||||
self.tacho = Dial(self.WIDTH - self.HEIGHT / 2,
|
||||
self.HEIGHT / 2,
|
||||
self.HEIGHT / 2,
|
||||
232.0 * (math.pi / 180.0),
|
||||
488.0 * (math.pi / 180.0))
|
||||
488.0 * (math.pi / 180.0),
|
||||
8000)
|
||||
|
||||
self.gauges.append(self.speedo)
|
||||
self.gauges.append(self.tacho)
|
||||
|
|
|
@ -3,8 +3,10 @@ import cairo
|
|||
|
||||
from hexagram.gauge import Gauge
|
||||
|
||||
ANGLE_OFFSET = 1.658
|
||||
|
||||
class Dial(Gauge):
|
||||
__slots = 'x', 'y', 'radius', 'min_angle', 'max_angle',
|
||||
__slots = 'x', 'y', 'radius', 'min_angle', 'max_angle', 'max_value',
|
||||
|
||||
BEZEL_WIDTH = 16
|
||||
|
||||
|
@ -13,12 +15,13 @@ class Dial(Gauge):
|
|||
(1, 0.4, 0.0, 0.4, 0.0)
|
||||
)
|
||||
|
||||
def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float):
|
||||
def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float, max_value: float):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.radius = radius
|
||||
self.min_angle = min_angle
|
||||
self.max_angle = max_angle
|
||||
self.max_value = max_value
|
||||
|
||||
def _gradient(self):
|
||||
gradient = cairo.LinearGradient(self.x - self.radius,
|
||||
|
@ -32,17 +35,16 @@ class Dial(Gauge):
|
|||
return gradient
|
||||
|
||||
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
|
||||
angle = self.min_angle + ((self.max_angle - self.min_angle) * value) - 1.658;
|
||||
scale = value / self.max_value
|
||||
angle = self.min_angle + ((self.max_angle - self.min_angle) * scale) - ANGLE_OFFSET
|
||||
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
cr.move_to(self.x + radius * self.radius * math.cos(angle),
|
||||
cr.move_to(self.x + radius * self.radius * math.cos(angle) - 20,
|
||||
self.y + radius * self.radius * math.sin(angle))
|
||||
|
||||
cr.save()
|
||||
cr.rotate(angle + 1.658)
|
||||
#cr.rotate(angle + ANGLE_OFFSET)
|
||||
cr.show_text(text)
|
||||
cr.stroke()
|
||||
cr.restore()
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
arc = (self.x,
|
||||
|
|
|
@ -12,20 +12,21 @@ class Speedo(Dial):
|
|||
MIN_ANGLE = 232.0 * (math.pi / 180.0)
|
||||
MAX_ANGLE = 488.0 * (math.pi / 180.0)
|
||||
|
||||
__slots__ = 'units', 'max_speed',
|
||||
FONT_FACE = "Helvetica"
|
||||
|
||||
def __init__(self, x: float, y: float, radius: float, max_speed: float, units: SpeedUnits=SpeedUnits.KPH):
|
||||
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE)
|
||||
__slots__ = 'units',
|
||||
|
||||
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.units = units
|
||||
self.max_speed = max_speed
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
super().draw_bg(cr)
|
||||
|
||||
cr.select_font_face("Helvetica")
|
||||
cr.set_font_size(self.radius * 0.125)
|
||||
cr.select_font_face(self.FONT_FACE)
|
||||
cr.set_font_size(self.radius * 0.1)
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
|
||||
for speed in range(0, int(self.max_speed), 50):
|
||||
self.draw_number(cr, 0.75, speed, str(int(speed)))
|
||||
for speed in range(0, int(self.max_value)+1, 20):
|
||||
self.draw_number(cr, 0.75, speed, "%02d" % int(speed))
|
||||
|
|
Loading…
Add table
Reference in a new issue