draw hover snap point
This commit is contained in:
parent
a0fe5aa6aa
commit
6c91677c11
@ -24,7 +24,7 @@ class SketchWidget:
|
|||||||
'arrow': gtk.gdk.Cursor(gtk.gdk.ARROW),
|
'arrow': gtk.gdk.Cursor(gtk.gdk.ARROW),
|
||||||
'crosshair': gtk.gdk.Cursor(gtk.gdk.CROSSHAIR),
|
'crosshair': gtk.gdk.Cursor(gtk.gdk.CROSSHAIR),
|
||||||
}
|
}
|
||||||
self.current_snap_point = None
|
self.hover_snap_point = None
|
||||||
|
|
||||||
# Configuration parameters
|
# Configuration parameters
|
||||||
self.line_width = 1.5
|
self.line_width = 1.5
|
||||||
@ -34,6 +34,7 @@ class SketchWidget:
|
|||||||
self.background_color = (0.0, 0.05, 0.1, 1.0)
|
self.background_color = (0.0, 0.05, 0.1, 1.0)
|
||||||
self.line_color = (0.1, 0.6, 1.0, 1.0)
|
self.line_color = (0.1, 0.6, 1.0, 1.0)
|
||||||
self.axis_color = (1.0, 0.0, 0.0, 1.0)
|
self.axis_color = (1.0, 0.0, 0.0, 1.0)
|
||||||
|
self.hover_color = (1.0, 1.0, 1.0, 1.0)
|
||||||
self.constraint_color = (0.8, 1.0, 0.0, 1.0)
|
self.constraint_color = (0.8, 1.0, 0.0, 1.0)
|
||||||
self.snap_angle = 10
|
self.snap_angle = 10
|
||||||
self.hv_snap_dist = 10
|
self.hv_snap_dist = 10
|
||||||
@ -132,6 +133,11 @@ class SketchWidget:
|
|||||||
for c in self.drawingConstraints:
|
for c in self.drawingConstraints:
|
||||||
self.drawConstraint(c)
|
self.drawConstraint(c)
|
||||||
|
|
||||||
|
if self.hover_snap_point is not None:
|
||||||
|
glColor(*self.hover_color)
|
||||||
|
s, p = self.hover_snap_point
|
||||||
|
self.drawConnect(Connect(s, p, s, p))
|
||||||
|
|
||||||
if gldrawable.is_double_buffered():
|
if gldrawable.is_double_buffered():
|
||||||
gldrawable.swap_buffers()
|
gldrawable.swap_buffers()
|
||||||
else:
|
else:
|
||||||
@ -408,6 +414,8 @@ class SketchWidget:
|
|||||||
self.drawingConstraints = []
|
self.drawingConstraints = []
|
||||||
self.drawingShape.setPt(1, this_pt)
|
self.drawingShape.setPt(1, this_pt)
|
||||||
self.queue_redraw()
|
self.queue_redraw()
|
||||||
|
sp = self.get_closest_snap_point(x, y)
|
||||||
|
self.update_hover_snap_point(sp)
|
||||||
|
|
||||||
def do_circle_left_click(self, x, y):
|
def do_circle_left_click(self, x, y):
|
||||||
pt = self.screenPtToPt((x, self.size[1] - y))
|
pt = self.screenPtToPt((x, self.size[1] - y))
|
||||||
@ -428,10 +436,14 @@ class SketchWidget:
|
|||||||
r = self.dist_bw(self.drawingShape.getPt(0), pt)
|
r = self.dist_bw(self.drawingShape.getPt(0), pt)
|
||||||
self.drawingShape.setRadius(r)
|
self.drawingShape.setRadius(r)
|
||||||
self.queue_redraw()
|
self.queue_redraw()
|
||||||
|
else:
|
||||||
|
sp = self.get_closest_snap_point(x, y)
|
||||||
|
self.update_hover_snap_point(sp)
|
||||||
|
|
||||||
def cancel_drawing_shape(self):
|
def cancel_drawing_shape(self):
|
||||||
self.drawingShape = None
|
self.drawingShape = None
|
||||||
self.drawingConstraints = []
|
self.drawingConstraints = []
|
||||||
|
self.hover_snap_point = None
|
||||||
|
|
||||||
def merge_in_drawing_shape(self):
|
def merge_in_drawing_shape(self):
|
||||||
self.sketch.shapes.append(self.drawingShape)
|
self.sketch.shapes.append(self.drawingShape)
|
||||||
@ -445,6 +457,11 @@ class SketchWidget:
|
|||||||
y = pt2[1] - pt1[1]
|
y = pt2[1] - pt1[1]
|
||||||
return math.sqrt(x * x + y * y)
|
return math.sqrt(x * x + y * y)
|
||||||
|
|
||||||
|
def dist2_bw(self, pt1, pt2):
|
||||||
|
x = pt2[0] - pt1[0]
|
||||||
|
y = pt2[1] - pt1[1]
|
||||||
|
return x * x + y * y
|
||||||
|
|
||||||
def update_snap_points(self):
|
def update_snap_points(self):
|
||||||
self.snap_points = {}
|
self.snap_points = {}
|
||||||
for s in self.sketch.shapes:
|
for s in self.sketch.shapes:
|
||||||
@ -454,3 +471,27 @@ class SketchWidget:
|
|||||||
for i in range(shape.nPts()):
|
for i in range(shape.nPts()):
|
||||||
pt = self.ptToScreenPt(shape.getPt(i))
|
pt = self.ptToScreenPt(shape.getPt(i))
|
||||||
self.snap_points[(shape, i)] = pt
|
self.snap_points[(shape, i)] = pt
|
||||||
|
|
||||||
|
def get_closest_snap_point(self, x, y):
|
||||||
|
closest_point = None
|
||||||
|
closest_dist = self.snap_dist * self.snap_dist * 2
|
||||||
|
for p in self.snap_points:
|
||||||
|
shape, ptNum = p
|
||||||
|
pt = self.ptToScreenPt(shape.getPt(ptNum))
|
||||||
|
dist = self.dist2_bw((x, self.size[1] - y), pt)
|
||||||
|
if dist < closest_dist:
|
||||||
|
closest_dist = dist
|
||||||
|
closest_point = p
|
||||||
|
if closest_dist <= self.snap_dist * self.snap_dist:
|
||||||
|
return closest_point
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update_hover_snap_point(self, sp):
|
||||||
|
if sp is not None:
|
||||||
|
if sp != self.hover_snap_point:
|
||||||
|
self.hover_snap_point = sp
|
||||||
|
self.queue_redraw()
|
||||||
|
else:
|
||||||
|
if self.hover_snap_point is not None:
|
||||||
|
self.hover_snap_point = None
|
||||||
|
self.queue_redraw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user