Added secondary mode button logic; added arrow bi-directionality; cleaned up primary button box

This commit is contained in:
2025-09-22 00:42:25 -05:00
parent 49237d39e4
commit 662fec201b
16 changed files with 341 additions and 82 deletions

View File

@@ -1,6 +1,7 @@
from .brush_event import BrushEvent
from .grid import Grid
from .arrow import Arrow
from .dual_arrow import DualArrow
from .line import Line
from .circle import Circle
from .square import Square

View File

@@ -6,7 +6,6 @@ import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import BrushEvent
@@ -15,14 +14,6 @@ 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:
@@ -44,11 +35,23 @@ class Arrow(BrushEvent):
x1, y1 = self.points[0].x, self.points[0].y
x2, y2 = self.points[1].x, self.points[1].y
# Arrow body
self.draw_arrow_body(brush, x1, y1, x2, y2)
self.draw_end_arrow_head(brush, x1, y1, x2, y2)
def draw_start_arrow_head(self, brush, x1, y1, x2, y2):
ah1, ay1, \
ah2, ay2 = self.get_arrow_head_points(x2, y2, x1, y1)
brush.move_to(x1, y1)
brush.line_to(ah1, ay1)
brush.move_to(x1, y1)
brush.line_to(ah2, ay2)
def draw_arrow_body(self, brush, x1, y1, x2, y2):
brush.move_to(x1, y1)
brush.line_to(x2, y2)
# Arrow head
def draw_end_arrow_head(self, brush, x1, y1, x2, y2):
ah1, ay1, \
ah2, ay2 = self.get_arrow_head_points(x1, y1, x2, y2)

View File

@@ -6,6 +6,9 @@ import cairo
# Application imports
from data.events.event import Event
from data.points import Points
class UnboundException(Exception):
...
@@ -19,6 +22,8 @@ class BrushEvent(Event):
self.size: int = 12
self.color: [] = [0.0, 0.0, 0.0, 1.0]
self.points: Points = Points()
def update(self, eve):
raise UnboundException("Method hasn't been overriden...")

View File

@@ -5,7 +5,6 @@ import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import BrushEvent
@@ -14,14 +13,6 @@ class Circle(BrushEvent):
def __init__(self):
super(Circle, 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) )

View File

@@ -0,0 +1,24 @@
# Python imports
# Lib imports
import cairo
# Application imports
from .arrow import Arrow
class DualArrow(Arrow):
def __init__(self):
super(DualArrow, self).__init__()
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
self.draw_start_arrow_head(brush, x1, y1, x2, y2)
self.draw_arrow_body(brush, x1, y1, x2, y2)
self.draw_end_arrow_head(brush, x1, y1, x2, y2)

View File

@@ -4,9 +4,6 @@
import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import Line
@@ -14,8 +11,6 @@ class Erase(Line):
def __init__(self):
super(Erase, self).__init__()
self.points: Points = Points()
def set_brush_data(self, brush):
brush.set_line_width(self.size)
brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE

View File

@@ -16,12 +16,6 @@ class Grid(BrushEvent):
self.grid_spacing = 12 # px
self.color = [0.2, 0.2, 0.2, 0.64] # light gray
def __copy__(self):
copy = type(self)()
copy.color = self.color
return copy
def update(self, eve):
self.is_valid = True

View File

@@ -5,7 +5,6 @@ import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import BrushEvent
@@ -14,14 +13,6 @@ class Line(BrushEvent):
def __init__(self):
super(Line, self).__init__()
self.points: Points = Points()
def __copy__(self):
copy = type(self)()
copy.color = self.color
return copy
def update(self, eve = None):
self.points.append( Point(eve.x, eve.y) )

View File

@@ -5,7 +5,6 @@ import cairo
# Application imports
from data.point import Point
from data.points import Points
from . import BrushEvent
@@ -14,14 +13,6 @@ class Square(BrushEvent):
def __init__(self):
super(Square, self).__init__()
self.points: Points = Points()
def __copy__(self):
copy = type(self)()
copy.color = self.color
return copy
def update(self, eve):
if len(self.points) < 2: