zoom in/out in timeline
This commit is contained in:
@@ -81,6 +81,8 @@ int new_color(gui *gui, char *color);
|
|||||||
* - click { int: button } (if enabled)
|
* - click { int: button } (if enabled)
|
||||||
* - timeline
|
* - timeline
|
||||||
* - resize { int: width }
|
* - resize { int: width }
|
||||||
|
* - scrollup { void *: NULL }
|
||||||
|
* - scrolldown { void *: NULL }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* same type as in gui_defs.h */
|
/* same type as in gui_defs.h */
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ static void allocate(gui *_gui, widget *_this,
|
|||||||
gui_notify(_gui, "resize", _this, &width);
|
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 */
|
/* creation function */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
@@ -87,6 +102,7 @@ widget *new_timeline(gui *_gui, int width, int number_of_sublines,
|
|||||||
w->common.paint = paint;
|
w->common.paint = paint;
|
||||||
w->common.hints = hints;
|
w->common.hints = hints;
|
||||||
w->common.allocate = allocate;
|
w->common.allocate = allocate;
|
||||||
|
w->common.button = button;
|
||||||
|
|
||||||
gunlock(g);
|
gunlock(g);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* timeview */
|
/* timeview */
|
||||||
@@ -37,7 +38,7 @@ struct time {
|
|||||||
time_t tstart_time; /* timestamp (in seconds) of starting in t */
|
time_t tstart_time; /* timestamp (in seconds) of starting in t */
|
||||||
int subcount; /* number of subviews */
|
int subcount; /* number of subviews */
|
||||||
struct timespec latest_time; /* time of latest received tick */
|
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) */
|
/* TODO: put that function somewhere else (utils.c) */
|
||||||
@@ -150,6 +151,27 @@ gotit:
|
|||||||
return 0;
|
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,
|
view *new_view_time(int number_of_seconds, float refresh_rate,
|
||||||
gui *g, widget *w)
|
gui *g, widget *w)
|
||||||
{
|
{
|
||||||
@@ -168,6 +190,9 @@ view *new_view_time(int number_of_seconds, float refresh_rate,
|
|||||||
ret->subcount = 0;
|
ret->subcount = 0;
|
||||||
ret->pixel_length = 10 * 1000000; /* 10ms */
|
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();
|
if (pthread_mutex_init(&ret->lock, NULL)) abort();
|
||||||
|
|
||||||
new_thread(time_thread, ret);
|
new_thread(time_thread, ret);
|
||||||
|
|||||||
Reference in New Issue
Block a user