]> git.cworth.org Git - acre/blobdiff - acre-x.c
Add another dataset style: ACRE_STYLE_BARS
[acre] / acre-x.c
index c1f7c414f42ef26b74cdb563d8ace4aba7e9dd67..c375c36efddee95a1d7afd4e74262a3d740f4cbd 100644 (file)
--- a/acre-x.c
+++ b/acre-x.c
@@ -103,6 +103,7 @@ handle_events(Display *dpy, Window window, Visual *visual,
 {
         XEvent xev;
         KeyCode quit_code = XKeysymToKeycode (dpy, XStringToKeysym("Q"));
+        KeyCode escape_code = XKeysymToKeycode (dpy, XStringToKeysym("Escape"));
         KeyCode left_code = XKeysymToKeycode (dpy, XStringToKeysym("Left"));
         KeyCode right_code = XKeysymToKeycode (dpy, XStringToKeysym("Right"));
         KeyCode plus_code = XKeysymToKeycode (dpy, XStringToKeysym("plus"));
@@ -120,36 +121,40 @@ handle_events(Display *dpy, Window window, Visual *visual,
                        draw (dpy, window, visual, acre,
                              width, height, x_min, x_max);
 
+#define PAN  0.05
+#define ZOOM PAN
                XNextEvent (dpy, &xev);
                 switch (xev.type) {
                 case KeyPress:
+                       need_redraw = true;
                        keycode = xev.xkey.keycode;
-                       if (keycode == quit_code)
+                       if (keycode == quit_code ||
+                           keycode == escape_code)
                        {
                                 return;
                        }
                        else if (keycode == left_code)
                        {
-                               shift = 0.25 * (x_max - x_min);
+                               shift = PAN * (x_max - x_min);
                                x_min += shift;
                                x_max += shift;
                        }
                        else if (keycode == right_code)
                        {
-                               shift = 0.25 * (x_max - x_min);
+                               shift = PAN * (x_max - x_min);
                                x_min -= shift;
                                x_max -= shift;
                        }
                        else if (keycode == plus_code ||
                                   keycode == equal_code)
                        {
-                               shift = 0.25 * (x_max - x_min);
+                               shift = ZOOM * (x_max - x_min);
                                x_min += shift;
                                x_max -= shift;
                        }
                        else if (keycode == minus_code)
                        {
-                               shift = 0.5 * (x_max - x_min);
+                               shift = (ZOOM/(1 - 2 * ZOOM)) * (x_max - x_min);
                                x_min -= shift;
                                x_max += shift;
                        }
@@ -157,7 +162,10 @@ handle_events(Display *dpy, Window window, Visual *visual,
                        {
                                acre_get_x_axis_data_range (acre, &x_min, &x_max);
                        }
-                       need_redraw = 1;
+                       else
+                       {
+                               need_redraw = false;
+                       }
                        break;
                 case ConfigureNotify:
                         width = xev.xconfigure.width;