Factor out more classes from cluster.py
This commit is contained in:
parent
48c1d9ae4c
commit
af993077ed
3 changed files with 55 additions and 48 deletions
|
@ -3,56 +3,10 @@ import cairo
|
|||
|
||||
from typing import Iterable, List
|
||||
|
||||
from hexagram.gauge import Gauge
|
||||
from hexagram.dial import Dial
|
||||
from hexagram.pattern import HexagonPattern
|
||||
|
||||
class Gauge():
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
raise NotImplementedError
|
||||
|
||||
class Dial(Gauge):
|
||||
__slots = 'x', 'y', 'radius',
|
||||
|
||||
BEZEL_WIDTH = 16
|
||||
|
||||
BEZEL_GRADIENT_STOPS = (
|
||||
(0, 1.0, 0.4, 1.0, 1.0),
|
||||
(1, 0.4, 0.0, 0.4, 0.0)
|
||||
)
|
||||
|
||||
def __init__(self, x: float, y: float, radius: float):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.radius = radius
|
||||
|
||||
def _gradient(self):
|
||||
gradient = cairo.LinearGradient(self.x - self.radius,
|
||||
self.y - self.radius,
|
||||
self.x + self.radius,
|
||||
self.y + self.radius)
|
||||
|
||||
for stop in self.BEZEL_GRADIENT_STOPS:
|
||||
gradient.add_color_stop_rgba(*stop)
|
||||
|
||||
return gradient
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
arc = (self.x,
|
||||
self.y,
|
||||
self.radius - self.BEZEL_WIDTH,
|
||||
0,
|
||||
2.0 * math.pi)
|
||||
|
||||
# Gauge face
|
||||
cr.set_source_rgba(0, 0, 0, 1)
|
||||
cr.arc(*arc)
|
||||
cr.fill()
|
||||
|
||||
# Gauge bezel
|
||||
cr.set_source(self._gradient())
|
||||
cr.set_line_width(self.BEZEL_WIDTH)
|
||||
cr.arc(*arc)
|
||||
cr.stroke()
|
||||
|
||||
class ShiftIndicator(Gauge):
|
||||
LIGHT_WIDTH = 48
|
||||
LIGHT_HEIGHT = 12
|
||||
|
|
48
py/hexagram/dial.py
Normal file
48
py/hexagram/dial.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import math
|
||||
import cairo
|
||||
|
||||
from hexagram.gauge import Gauge
|
||||
|
||||
class Dial(Gauge):
|
||||
__slots = 'x', 'y', 'radius',
|
||||
|
||||
BEZEL_WIDTH = 16
|
||||
|
||||
BEZEL_GRADIENT_STOPS = (
|
||||
(0, 1.0, 0.4, 1.0, 1.0),
|
||||
(1, 0.4, 0.0, 0.4, 0.0)
|
||||
)
|
||||
|
||||
def __init__(self, x: float, y: float, radius: float):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.radius = radius
|
||||
|
||||
def _gradient(self):
|
||||
gradient = cairo.LinearGradient(self.x - self.radius,
|
||||
self.y - self.radius,
|
||||
self.x + self.radius,
|
||||
self.y + self.radius)
|
||||
|
||||
for stop in self.BEZEL_GRADIENT_STOPS:
|
||||
gradient.add_color_stop_rgba(*stop)
|
||||
|
||||
return gradient
|
||||
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
arc = (self.x,
|
||||
self.y,
|
||||
self.radius - self.BEZEL_WIDTH,
|
||||
0,
|
||||
2.0 * math.pi)
|
||||
|
||||
# Gauge face
|
||||
cr.set_source_rgba(0, 0, 0, 1)
|
||||
cr.arc(*arc)
|
||||
cr.fill()
|
||||
|
||||
# Gauge bezel
|
||||
cr.set_source(self._gradient())
|
||||
cr.set_line_width(self.BEZEL_WIDTH)
|
||||
cr.arc(*arc)
|
||||
cr.stroke()
|
5
py/hexagram/gauge.py
Normal file
5
py/hexagram/gauge.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
import cairo
|
||||
|
||||
class Gauge():
|
||||
def draw_bg(self, cr: cairo.Context):
|
||||
raise NotImplementedError
|
Loading…
Add table
Reference in a new issue