add screen dragging to spline graph

Signed-off-by: Jason Anderson-Young <jase.w.andersonyoung@gmail.com>
Change-Id: Ie2a4f3822f990903fc8a14d852136be396d4e437
diff --git a/frc971/control_loops/python/path_edit.py b/frc971/control_loops/python/path_edit.py
index 7c742c8..437b242 100755
--- a/frc971/control_loops/python/path_edit.py
+++ b/frc971/control_loops/python/path_edit.py
@@ -48,7 +48,10 @@
         # init editing / viewing modes and pointer location
         self.mode = Mode.kPlacing
         self.mousex = 0
+        self.lastx = 0
         self.mousey = 0
+        self.lasty = 0
+        self.drag_start = None
         self.module_path = os.path.dirname(os.path.realpath(sys.argv[0]))
         self.path_to_export = os.path.join(self.module_path,
                                            'points_for_pathedit.json')
@@ -406,6 +409,8 @@
             self.queue_draw()
 
     def do_button_release_event(self, event):
+        self.drag_start = None
+
         self.attempt_append_multisplines()
         self.mousex, self.mousey = self.input_transform.transform_point(
             event.x, event.y)
@@ -430,6 +435,9 @@
         self.mousex, self.mousey = self.input_transform.transform_point(
             event.x, event.y)
 
+        self.lastx = event.x
+        self.lasty = event.y
+
         if self.mode == Mode.kPlacing:
             if self.active_multispline.addPoint(self.mousex, self.mousey):
                 self.mode = Mode.kEditing
@@ -462,6 +470,9 @@
                                 index_multisplines, index_splines,
                                 index_points)
 
+                if self.control_point_index == None:
+                    self.drag_start = (event.x, event.y)
+
             multispline, result = Multispline.nearest_distance(
                 self.multisplines, cur_p)
             if result and result.fun < 0.1:
@@ -484,6 +495,14 @@
 
             multispline.update_lib_spline()
             self.graph.schedule_recalculate(self.multisplines)
+
+        if self.mode == Mode.kEditing and self.drag_start != None and self.control_point_index == None:
+
+            self.zoom_transform.translate(event.x - self.lastx,
+                                          event.y - self.lasty)
+            self.lastx = event.x
+            self.lasty = event.y
+
         self.queue_draw()
 
     def do_scroll_event(self, event):
@@ -505,9 +524,9 @@
         scale = (self.field.width + scale_by) / self.field.width
 
         # This restricts the amount it can be scaled.
-        if self.zoom_transform.xx <= 0.5:
+        if self.zoom_transform.xx <= 0.05:
             scale = max(scale, 1)
-        elif self.zoom_transform.xx >= 16:
+        elif self.zoom_transform.xx >= 32:
             scale = min(scale, 1)
 
         # undo the scaled translation that the old zoom transform did