فهرست منبع

Highlight starting point when attracting line

Also switch to round nodes, they seem more appealing.
Michael Pitidis 13 سال پیش
والد
کامیت
c1ff8a647e
2فایلهای تغییر یافته به همراه10 افزوده شده و 7 حذف شده
  1. 3 4
      canvas.py
  2. 7 3
      shape.py

+ 3 - 4
canvas.py

@@ -8,9 +8,6 @@ from PyQt4.QtOpenGL import *
 from shape import Shape
 
 # TODO:
-# - [maybe] Add 2 painters, one for the pixmap one for the shape,
-#   since performance on big images is a problem...
-# - [maybe] Highlight source vertex when "attracting" line.
 # - [maybe] Find optimal epsilon value.
 
 CURSOR_DEFAULT = Qt.ArrowCursor
@@ -28,7 +25,7 @@ class Canvas(QWidget):
 
     SELECT, EDIT = range(2)
 
-    epsilon = 9.0
+    epsilon = 11.0
 
     def __init__(self, *args, **kwargs):
         super(Canvas, self).__init__(*args, **kwargs)
@@ -99,9 +96,11 @@ class Canvas(QWidget):
                 # Attract line to starting point and colorise to alert the user:
                 pos = self.current[0]
                 color = self.current.line_color
+                self.current.highlightStart = True
             self.line[1] = pos
             self.line.line_color = color
             self.repaint()
+            self.current.highlightStart = False
             return
 
         # Polygon moving.

+ 7 - 3
shape.py

@@ -23,7 +23,7 @@ class Shape(object):
     fill_color = DEFAULT_FILL_COLOR
     sel_fill_color=QColor(0, 128, 255, 155)
     select_color = DEFAULT_SELECT_COLOR
-    point_type = P_SQUARE
+    point_type = P_ROUND
     point_size = 8
     scale = 1.0
 
@@ -32,6 +32,7 @@ class Shape(object):
         self.points = []
         self.fill = False
         self.selected = False
+        self.highlightStart = False
         if line_color is not None:
             # Override the class line_color attribute
             # with an object attribute. Currently this
@@ -60,7 +61,8 @@ class Shape(object):
             vrtx_path = QPainterPath()
 
             line_path.moveTo(QPointF(self.points[0]))
-            self.drawVertex(vrtx_path, self.points[0])
+            self.drawVertex(vrtx_path, self.points[0],
+                    highlight=self.highlightStart)
 
             for p in self.points[1:]:
                 line_path.lineTo(QPointF(p))
@@ -76,8 +78,10 @@ class Shape(object):
                     fillColor=self.fill_color
                 painter.fillPath(line_path,fillColor)
 
-    def drawVertex(self, path, point):
+    def drawVertex(self, path, point, highlight=False):
         d = self.point_size / self.scale
+        if highlight:
+            d *= 4
         if self.point_type == self.P_SQUARE:
             path.addRect(point.x() - d/2, point.y() - d/2, d, d)
         else: