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;
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);
{
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) {
+ 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 = (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);
+ }
+ need_redraw = 1;
+ break;
case ConfigureNotify:
width = xev.xconfigure.width;
height = xev.xconfigure.height;