X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=acre-x.c;h=c375c36efddee95a1d7afd4e74262a3d740f4cbd;hb=refs%2Fheads%2Fmaster;hp=4e2cd0fa5e157a6786f98bc3eee090239dd4e90e;hpb=f9c8a5242190d3b96cb51a4e651caccfb451f122;p=acre diff --git a/acre-x.c b/acre-x.c index 4e2cd0f..c375c36 100644 --- a/acre-x.c +++ b/acre-x.c @@ -75,7 +75,7 @@ load_chart (void) static void draw (Display *dpy, Window window, Visual *visual, acre_t *acre, - int width, int height) + int width, int height, double x_min, double x_max) { cairo_t *cr; cairo_surface_t *surface; @@ -88,6 +88,7 @@ draw (Display *dpy, Window window, Visual *visual, acre_t *acre, cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); + acre_set_x_axis_range (acre, x_min, x_max); acre_draw (acre, cr, width, height); cairo_destroy (cr); @@ -102,19 +103,70 @@ 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")); + KeyCode equal_code = XKeysymToKeycode (dpy, XStringToKeysym("equal")); + KeyCode minus_code = XKeysymToKeycode (dpy, XStringToKeysym("minus")); + KeyCode home_code = XKeysymToKeycode (dpy, XStringToKeysym("Home")); + KeyCode keycode; bool need_redraw = false; + double x_min, x_max, shift; + + acre_get_x_axis_data_range (acre, &x_min, &x_max); while (1) { if (! XPending (dpy) && need_redraw) - draw (dpy, window, visual, acre, width, height); + 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: - if (xev.xkey.keycode == quit_code) { + need_redraw = true; + keycode = xev.xkey.keycode; + if (keycode == quit_code || + keycode == escape_code) + { return; - } - break; + } + else if (keycode == left_code) + { + shift = PAN * (x_max - x_min); + x_min += shift; + x_max += shift; + } + else if (keycode == right_code) + { + shift = PAN * (x_max - x_min); + x_min -= shift; + x_max -= shift; + } + else if (keycode == plus_code || + keycode == equal_code) + { + shift = ZOOM * (x_max - x_min); + x_min += shift; + x_max -= shift; + } + else if (keycode == minus_code) + { + shift = (ZOOM/(1 - 2 * ZOOM)) * (x_max - x_min); + x_min -= shift; + x_max += shift; + } + else if (keycode == home_code) + { + acre_get_x_axis_data_range (acre, &x_min, &x_max); + } + else + { + need_redraw = false; + } + break; case ConfigureNotify: width = xev.xconfigure.width; height = xev.xconfigure.height;