summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-13 05:26:40 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-13 05:26:40 (GMT)
commitc8177f08319285773a532b5745a0915e12c29a0a (patch)
tree99386ee75d7db64c089237804c9a345901ad3f87 /meme/gui.c
parent54dbe1c4b48b545e937a31fe0a775491ea55cd01 (diff)
downloadmisc-c8177f08319285773a532b5745a0915e12c29a0a.zip
misc-c8177f08319285773a532b5745a0915e12c29a0a.tar.gz
misc-c8177f08319285773a532b5745a0915e12c29a0a.tar.bz2
meme/: new option "-l logfile" to append marker/measurement data to file
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 9bcb13d..d2ac9d6 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -839,7 +839,22 @@ static void print_marker(FILE *file)
}
-static void set_marker(const struct vertex *v)
+static void log_marker(const char *logfile)
+{
+ FILE *file;
+
+ file = fopen(logfile, "a");
+ if (!file) {
+ perror(logfile);
+ return;
+ }
+ print_marker(file);
+ if (fclose(file) == EOF)
+ perror(logfile);
+}
+
+
+static void set_marker(const struct vertex *v, const char *logfile)
{
if (select_marker(v))
return;
@@ -850,6 +865,8 @@ static void set_marker(const struct vertex *v)
mark_a = cursor;
print_marker(stderr);
+ if (logfile)
+ log_marker(logfile);
}
@@ -940,13 +957,13 @@ static void motion_event(SDL_Surface *s, SDL_MouseMotionEvent *motion)
}
-static void button_event(SDL_MouseButtonEvent *button)
+static void button_event(SDL_MouseButtonEvent *button, const char *logfile)
{
switch (button->button) {
case 1:
if (!cursor)
break;
- set_marker(cursor);
+ set_marker(cursor, logfile);
break;
case 2:
x_orig = mouse_x;
@@ -1126,7 +1143,7 @@ static void delayed_motion(void *user)
}
-static bool event_loop(SDL_Surface **surf)
+static bool event_loop(SDL_Surface **surf, const char *logfile)
{
SDL_Surface *s = *surf;
SDL_Event event;
@@ -1149,7 +1166,7 @@ static bool event_loop(SDL_Surface **surf)
break;
case SDL_MOUSEBUTTONDOWN:
update_mouse_pos(event.button.x, event.button.y);
- button_event(&event.button);
+ button_event(&event.button, logfile);
return 0;
case SDL_VIDEORESIZE:
xres = event.resize.w;
@@ -1210,7 +1227,7 @@ static bool event_loop(SDL_Surface **surf)
}
-void gui(void)
+void gui(const char *logfile)
{
SDL_Surface *surf;
@@ -1258,7 +1275,7 @@ fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
}
apply_changes(surf);
- if (event_loop(&surf))
+ if (event_loop(&surf, logfile))
break;
}
}