def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): "[extends superclass version]" self.node.pos = self.node_offset + V(x, y) res = super(DragNode, self).on_mouse_drag(x, y, dx, dy, buttons, modifiers) # superclass method handles tip & highlighting specific to this potential release-point return res
def draw_tooltip_text( self, text, pos, size): #doc # todo: use size text_object = self._tip_text_object if text_object.text != text: text_object.text = text text_object.x, text_object.y = pos + V(10, -20) # assume LL corner of text # GUESS and stub; # maybe be smarter, let caller pass offset directions to avoid; # future: transform from model to pane coords text_object.draw()
def hit_test(self, x, y): HALO_RADIUS = 2 # or maybe 1? p1 = self.nodes[0].pos p2 = self.nodes[1].pos direction_along_edge = unitVector(p2 - p1) unit_normal_to_edge = rotate2d_90(direction_along_edge) vec = V(x,y) - p1 distance_from_edge_line = abs(dot(vec, unit_normal_to_edge)) if distance_from_edge_line > HALO_RADIUS: return False distance_along_edge_line = dot(vec, direction_along_edge) if HALO_RADIUS <= distance_along_edge_line <= vlen(p2 - p1) - HALO_RADIUS: # For our purposes, exclude points too near the endpoints -- # matches to a rectangle centered on the edge and not within # halo radius (along the edge) of the endpoints. (If node radius # is larger, near-endpoint behavior won't matter anyway, since we # treat nodes as being in front of edges.) return True return False
def on_mouse_release_would_do(self, x, y, button, modifiers): model = self.model obj = self.pane.find_object(x, y, excluding=[self.node] + list(self.node.edges)) # might be None hh = self.tool._f_HighlightGraphics_descriptions if isinstance(obj, model.Node): return Transition(indicators=[ hh.tip_text("merge with existing node", obj), hh.highlight_merge(self.node, obj), ], command=("cmd_MergeNodes", self.node, obj), next_state=(HuntForNode, None)) elif V(x, y) != self.dragstart_pos: # it moved; don't draw edges from it during subsequent mouse motion # (future: small motions should not count, for this or for dragging; # could be done here, or by caller not sending drag events at first) return Transition(None, None, (HuntForNode, None)) else: # it didn't move; do perhaps draw edges from it during subsequent motion return Transition(None, None, (HuntForNode, self.node))
def get_pos(self): return V(self.x, self.y)
def on_mouse_release(self, x, y, button, modifiers): "[extends superclass version]" self.node.pos = self.node_offset + V(x, y) res = super(DragNode, self).on_mouse_release(x, y, button, modifiers) return res