Correcting transparent line draw issues; moving brush settings to method call; refactored erase to extend line
This commit is contained in:
BIN
images/pic4.png
BIN
images/pic4.png
Binary file not shown.
Before Width: | Height: | Size: 410 KiB After Width: | Height: | Size: 413 KiB |
@@ -32,12 +32,14 @@ class Arrow(BrushEvent):
|
||||
self.points[1] = Point(eve.x, eve.y)
|
||||
self.is_valid = True
|
||||
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
def set_brush_data(self, brush):
|
||||
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.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
self.set_brush_data(brush)
|
||||
|
||||
x1, y1 = self.points[0].x, self.points[0].y
|
||||
x2, y2 = self.points[1].x, self.points[1].y
|
||||
|
@@ -27,11 +27,15 @@ class Circle(BrushEvent):
|
||||
self.points.append( Point(eve.x, eve.y) )
|
||||
self.is_valid = True
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
def set_brush_data(self, brush):
|
||||
brush.set_source_rgba(*self.color)
|
||||
brush.set_operator(cairo.OPERATOR_OVER);
|
||||
brush.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
self.set_brush_data(brush)
|
||||
|
||||
for point in self.points:
|
||||
brush.move_to(point.x, point.y)
|
||||
brush.arc(point.x, point.y, self.size, 0, 2 * 3.14)
|
||||
brush.fill()
|
||||
|
||||
brush.fill()
|
@@ -7,36 +7,17 @@ import cairo
|
||||
from data.point import Point
|
||||
from data.points import Points
|
||||
|
||||
from . import BrushEvent
|
||||
from . import Line
|
||||
|
||||
|
||||
class Erase(BrushEvent):
|
||||
class Erase(Line):
|
||||
def __init__(self):
|
||||
super(Erase, self).__init__()
|
||||
|
||||
self.points: Points = Points()
|
||||
|
||||
def __copy__(self):
|
||||
copy = type(self)()
|
||||
copy.color = self.color
|
||||
|
||||
return copy
|
||||
|
||||
|
||||
def update(self, eve):
|
||||
self.points.append( Point(eve.x, eve.y) )
|
||||
self.is_valid = True
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
if len(self.points) < 2: return
|
||||
|
||||
def set_brush_data(self, brush):
|
||||
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_CLEAR);
|
||||
|
||||
brush.move_to(self.points[0].x, self.points[0].y)
|
||||
for point in self.points[1 : -1]:
|
||||
brush.line_to(point.x, point.y)
|
||||
brush.stroke()
|
||||
brush.move_to(point.x, point.y)
|
||||
brush.set_operator(cairo.OPERATOR_CLEAR)
|
@@ -26,9 +26,12 @@ class Grid(BrushEvent):
|
||||
def update(self, eve):
|
||||
self.is_valid = True
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
def set_brush_data(self, brush):
|
||||
brush.set_source_rgba(*self.color)
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
self.set_brush_data(brush)
|
||||
|
||||
# Draw vertical lines
|
||||
x = 0
|
||||
while x < self.width:
|
||||
|
@@ -28,15 +28,18 @@ class Line(BrushEvent):
|
||||
if len(self.points) < 2: return
|
||||
self.is_valid = True
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
|
||||
def set_brush_data(self, brush):
|
||||
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.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
self.set_brush_data(brush)
|
||||
|
||||
brush.move_to(self.points[0].x, self.points[0].y)
|
||||
for point in self.points[1 : -1]:
|
||||
brush.line_to(point.x, point.y)
|
||||
brush.stroke()
|
||||
brush.move_to(point.x, point.y)
|
||||
|
||||
brush.stroke()
|
||||
|
@@ -31,13 +31,18 @@ class Square(BrushEvent):
|
||||
self.points[1] = Point(eve.x, eve.y)
|
||||
self.is_valid = True
|
||||
|
||||
def set_brush_data(self, brush):
|
||||
brush.set_source_rgba(*self.color)
|
||||
brush.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
def process(self, brush: cairo.Context):
|
||||
self.set_brush_data(brush)
|
||||
|
||||
x1, y1 = self.points[0].x, self.points[0].y
|
||||
x2, y2 = self.points[1].x, self.points[1].y
|
||||
w = x2 - x1
|
||||
h = y2 - y1
|
||||
|
||||
brush.set_source_rgba(*self.color)
|
||||
brush.set_operator(cairo.OPERATOR_OVER);
|
||||
brush.rectangle(x1, y1, w, h)
|
||||
|
||||
brush.fill()
|
Reference in New Issue
Block a user