# HG changeset patch # User drewp@bigasterisk.com # Date 2005-06-18 06:09:28 # Node ID 50ba9ec2b17e52c000262798945edfb950305a93 # Parent 3b73f0a58a54df5f239e6f5aef555f580a5bb6af you can now delete curve points diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -347,7 +347,7 @@ root.bind("",savekey) root.bind("", lambda evt: dispatcher.send('reload all subs')) create_status_lines(root) -for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse", +for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; Del point under mouse; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse", "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]: tk.Label(root,text=helpline, font="Helvetica -12 italic", anchor='w').pack(side='top',fill='x') diff --git a/light9/curve.py b/light9/curve.py --- a/light9/curve.py +++ b/light9/curve.py @@ -71,6 +71,11 @@ def angle_between(base, p0, p1): dot = max(-1,min(1,dot)) return math.degrees(math.acos(dot)) +def slope(p1,p2): + if p2[0] == p1[0]: + return 0 + return (p2[1] - p1[1]) / (p2[0] - p1[0]) + class Sketch: """a sketch motion on a curveview, with temporary points while you draw, and simplification when you release""" @@ -117,10 +122,6 @@ class Sketch: self.curveview.update_curve() - def slope(self,p1,p2): - if p2[0] == p1[0]: - return 0 - return (p2[1] - p1[1]) / (p2[0] - p1[0]) class Curveview(tk.Canvas): def __init__(self,master,curve,**kw): @@ -302,11 +303,26 @@ class Curveview(tk.Canvas): lambda ev,i=i: self.dotmotion(ev,i)) self.bind("", lambda ev,i=i: self.dotrelease(ev,i)) + #self.tag_bind('handle%d' % i, "", + # lambda ev, i=i: self.remove_point_idx(i)) + self.dots[i]=dot + def delpoint(ev): + # had a hard time tag_binding to the points, so i trap at + # the widget level (which might be nice anyway when there + # are multiple pts selected) + tags = self.gettags(self.find_closest(ev.x, ev.y)) + try: + handletags = [t for t in tags if t.startswith('handle')] + i = int(handletags[0][6:]) + except IndexError: + return + self.remove_point_idx(i) + self.bind("", delpoint) + self.highlight_selected_dots() - def newpointatmouse(self, ev): p = self.world_from_screen(ev.x,ev.y) x, y = p @@ -319,6 +335,10 @@ class Curveview(tk.Canvas): self.unselect() self.curve.insert_pt(p) self.update_curve() + + def remove_point_idx(self, i): + self.curve.points.pop(i) + self.update_curve() def highlight_selected_dots(self): for i,d in self.dots.items():