X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=acre-x.c;h=194926a0ae7e8502d1a75f2903698950c74e486e;hb=fdff840db02a5d403e1423b070fd43cbbc52a07c;hp=c1f7c414f42ef26b74cdb563d8ace4aba7e9dd67;hpb=1a4594b5739b8448bf711a30b1c8bf23c0cd1912;p=acre diff --git a/acre-x.c b/acre-x.c index c1f7c41..194926a 100644 --- 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 = (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;