diff --git a/images/pic4.png b/images/pic4.png index 58881f2..b245662 100644 Binary files a/images/pic4.png and b/images/pic4.png differ diff --git a/src/data/events/brushes/arrow.py b/src/data/events/brushes/arrow.py index 578b0ef..2b28062 100644 --- a/src/data/events/brushes/arrow.py +++ b/src/data/events/brushes/arrow.py @@ -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 diff --git a/src/data/events/brushes/circle.py b/src/data/events/brushes/circle.py index 61a3a75..20bbcd6 100644 --- a/src/data/events/brushes/circle.py +++ b/src/data/events/brushes/circle.py @@ -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() \ No newline at end of file + + brush.fill() \ No newline at end of file diff --git a/src/data/events/brushes/erase.py b/src/data/events/brushes/erase.py index 08054df..4755c85 100644 --- a/src/data/events/brushes/erase.py +++ b/src/data/events/brushes/erase.py @@ -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) \ No newline at end of file diff --git a/src/data/events/brushes/grid.py b/src/data/events/brushes/grid.py index a5812f7..bad6ff4 100644 --- a/src/data/events/brushes/grid.py +++ b/src/data/events/brushes/grid.py @@ -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: diff --git a/src/data/events/brushes/line.py b/src/data/events/brushes/line.py index 0d76360..3cfe163 100644 --- a/src/data/events/brushes/line.py +++ b/src/data/events/brushes/line.py @@ -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() diff --git a/src/data/events/brushes/square.py b/src/data/events/brushes/square.py index 12b3ab0..3d193dd 100644 --- a/src/data/events/brushes/square.py +++ b/src/data/events/brushes/square.py @@ -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() \ No newline at end of file