Files
PixelBash/src/data/events/brushes/arrow.py

45 lines
996 B
Python

# Python imports
# Lib imports
import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import BrushEvent
class Arrow(BrushEvent):
def __init__(self):
super(Arrow, self).__init__()
self.points: Points = Points()
def __copy__(self):
copy = type(self)()
copy.color = self.color
return copy
def update(self, eve = None):
if len(self.points) < 2:
self.points.append( Point(eve.x, eve.y) )
return
self.points[1] = Point(eve.x, eve.y)
self.is_valid = True
def process(self, brush: cairo.Context):
brush.set_line_width(self.size)
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
brush.set_source_rgba(*self.color)
brush.set_operator(cairo.OPERATOR_OVER);
brush.move_to(self.points[0].x, self.points[0].y)
brush.line_to(self.points[1].x, self.points[1].y)
brush.stroke()