From 2e7ab60d703a741383f3873449a60ab744d844c4 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Tue, 17 May 2016 16:18:29 +0200 Subject: [PATCH] zoom in/out in timeline --- common/utils/T/tracer/gui/gui.h | 2 ++ common/utils/T/tracer/gui/timeline.c | 16 ++++++++++++++++ common/utils/T/tracer/view/time.c | 27 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h index bb1a495849..e470d2d366 100644 --- a/common/utils/T/tracer/gui/gui.h +++ b/common/utils/T/tracer/gui/gui.h @@ -81,6 +81,8 @@ int new_color(gui *gui, char *color); * - click { int: button } (if enabled) * - timeline * - resize { int: width } + * - scrollup { void *: NULL } + * - scrolldown { void *: NULL } */ /* same type as in gui_defs.h */ diff --git a/common/utils/T/tracer/gui/timeline.c b/common/utils/T/tracer/gui/timeline.c index 0902078071..e627567aaf 100644 --- a/common/utils/T/tracer/gui/timeline.c +++ b/common/utils/T/tracer/gui/timeline.c @@ -54,6 +54,21 @@ static void allocate(gui *_gui, widget *_this, gui_notify(_gui, "resize", _this, &width); } +static void button(gui *_g, widget *_this, int x, int y, int button, int up) +{ + struct gui *g = _g; + struct timeline_widget *this = _this; + LOGD("BUTTON timeline %p xy %d %d button %d up %d\n", _this, x, y, button, up); + /* scroll up */ + if (button == 4 && up == 0) { + gui_notify(g, "scrollup", _this, NULL); + } + /* scroll down */ + if (button == 5 && up == 0) { + gui_notify(g, "scrolldown", _this, NULL); + } +} + /*************************************************************************/ /* creation function */ /*************************************************************************/ @@ -87,6 +102,7 @@ widget *new_timeline(gui *_gui, int width, int number_of_sublines, w->common.paint = paint; w->common.hints = hints; w->common.allocate = allocate; + w->common.button = button; gunlock(g); diff --git a/common/utils/T/tracer/view/time.c b/common/utils/T/tracer/view/time.c index 0ef609e59a..9d6607b32b 100644 --- a/common/utils/T/tracer/view/time.c +++ b/common/utils/T/tracer/view/time.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <pthread.h> +#include <string.h> /****************************************************************************/ /* timeview */ @@ -37,7 +38,7 @@ struct time { time_t tstart_time; /* timestamp (in seconds) of starting in t */ int subcount; /* number of subviews */ struct timespec latest_time; /* time of latest received tick */ - int64_t pixel_length; /* unit: nanosecond (maximum 1 hour/pixel) */ + double pixel_length; /* unit: nanosecond (maximum 1 hour/pixel) */ }; /* TODO: put that function somewhere else (utils.c) */ @@ -150,6 +151,27 @@ gotit: return 0; } +static void scroll(void *private, gui *g, + char *notification, widget *w, void *notification_data) +{ + struct time *this = private; + double mul = 1.2; + double pixel_length; + + if (pthread_mutex_lock(&this->lock)) abort(); + + if (!strcmp(notification, "scrollup")) mul = 1 / mul; + + pixel_length = this->pixel_length * mul; + if (pixel_length < 1) pixel_length = 1; + if (pixel_length > (double)3600 * 1000000000) + pixel_length = (double)3600 * 1000000000; + + this->pixel_length = pixel_length; + + if (pthread_mutex_unlock(&this->lock)) abort(); +} + view *new_view_time(int number_of_seconds, float refresh_rate, gui *g, widget *w) { @@ -168,6 +190,9 @@ view *new_view_time(int number_of_seconds, float refresh_rate, ret->subcount = 0; ret->pixel_length = 10 * 1000000; /* 10ms */ + register_notifier(g, "scrollup", w, scroll, ret); + register_notifier(g, "scrolldown", w, scroll, ret); + if (pthread_mutex_init(&ret->lock, NULL)) abort(); new_thread(time_thread, ret); -- GitLab