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.points[1] = Point(eve.x, eve.y)
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
|
|
||||||
|
def set_brush_data(self, brush):
|
||||||
def process(self, brush: cairo.Context):
|
|
||||||
brush.set_line_width(self.size)
|
brush.set_line_width(self.size)
|
||||||
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
||||||
brush.set_source_rgba(*self.color)
|
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
|
x1, y1 = self.points[0].x, self.points[0].y
|
||||||
x2, y2 = self.points[1].x, self.points[1].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.points.append( Point(eve.x, eve.y) )
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
|
|
||||||
def process(self, brush: cairo.Context):
|
def set_brush_data(self, brush):
|
||||||
brush.set_source_rgba(*self.color)
|
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:
|
for point in self.points:
|
||||||
brush.move_to(point.x, point.y)
|
brush.move_to(point.x, point.y)
|
||||||
brush.arc(point.x, point.y, self.size, 0, 2 * 3.14)
|
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.point import Point
|
||||||
from data.points import Points
|
from data.points import Points
|
||||||
|
|
||||||
from . import BrushEvent
|
from . import Line
|
||||||
|
|
||||||
|
|
||||||
class Erase(BrushEvent):
|
class Erase(Line):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Erase, self).__init__()
|
super(Erase, self).__init__()
|
||||||
|
|
||||||
self.points: Points = Points()
|
self.points: Points = Points()
|
||||||
|
|
||||||
def __copy__(self):
|
def set_brush_data(self, brush):
|
||||||
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
|
|
||||||
|
|
||||||
brush.set_line_width(self.size)
|
brush.set_line_width(self.size)
|
||||||
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
||||||
brush.set_source_rgba(*self.color)
|
brush.set_source_rgba(*self.color)
|
||||||
brush.set_operator(cairo.OPERATOR_CLEAR);
|
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)
|
|
@@ -26,9 +26,12 @@ class Grid(BrushEvent):
|
|||||||
def update(self, eve):
|
def update(self, eve):
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
|
|
||||||
def process(self, brush: cairo.Context):
|
def set_brush_data(self, brush):
|
||||||
brush.set_source_rgba(*self.color)
|
brush.set_source_rgba(*self.color)
|
||||||
|
|
||||||
|
def process(self, brush: cairo.Context):
|
||||||
|
self.set_brush_data(brush)
|
||||||
|
|
||||||
# Draw vertical lines
|
# Draw vertical lines
|
||||||
x = 0
|
x = 0
|
||||||
while x < self.width:
|
while x < self.width:
|
||||||
|
@@ -28,15 +28,18 @@ class Line(BrushEvent):
|
|||||||
if len(self.points) < 2: return
|
if len(self.points) < 2: return
|
||||||
self.is_valid = True
|
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_width(self.size)
|
||||||
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
|
||||||
brush.set_source_rgba(*self.color)
|
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)
|
brush.move_to(self.points[0].x, self.points[0].y)
|
||||||
for point in self.points[1 : -1]:
|
for point in self.points[1 : -1]:
|
||||||
brush.line_to(point.x, point.y)
|
brush.line_to(point.x, point.y)
|
||||||
brush.stroke()
|
|
||||||
brush.move_to(point.x, point.y)
|
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.points[1] = Point(eve.x, eve.y)
|
||||||
self.is_valid = True
|
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):
|
def process(self, brush: cairo.Context):
|
||||||
|
self.set_brush_data(brush)
|
||||||
|
|
||||||
x1, y1 = self.points[0].x, self.points[0].y
|
x1, y1 = self.points[0].x, self.points[0].y
|
||||||
x2, y2 = self.points[1].x, self.points[1].y
|
x2, y2 = self.points[1].x, self.points[1].y
|
||||||
w = x2 - x1
|
w = x2 - x1
|
||||||
h = y2 - y1
|
h = y2 - y1
|
||||||
|
|
||||||
brush.set_source_rgba(*self.color)
|
|
||||||
brush.set_operator(cairo.OPERATOR_OVER);
|
|
||||||
brush.rectangle(x1, y1, w, h)
|
brush.rectangle(x1, y1, w, h)
|
||||||
|
|
||||||
brush.fill()
|
brush.fill()
|
Reference in New Issue
Block a user