summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-14 14:51:27 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-14 14:55:31 (GMT)
commit4405e30b6c126bd25c7a52f15919c5fe2e4ff7cf (patch)
tree35edbafc4de622640e08c5935892f9642af0cfc6 /meme
parent06474f30bc0090c93a592a1cd35f5b1c4271d68e (diff)
downloadmisc-4405e30b6c126bd25c7a52f15919c5fe2e4ff7cf.zip
misc-4405e30b6c126bd25c7a52f15919c5fe2e4ff7cf.tar.gz
misc-4405e30b6c126bd25c7a52f15919c5fe2e4ff7cf.tar.bz2
meme/: generalize overlay handling (no globals, support multiple overlays)
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c8
-rw-r--r--meme/meme.c7
-rw-r--r--meme/overlay.c32
-rw-r--r--meme/overlay.h8
4 files changed, 31 insertions, 24 deletions
diff --git a/meme/gui.c b/meme/gui.c
index c518755..80aedf4 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -921,9 +921,9 @@ static void lineto(void *user, int x, int y)
}
-static void draw_overlay(SDL_Surface *s)
+static void draw_overlay(SDL_Surface *s, const struct overlay *overlay)
{
- overlay_draw(moveto, lineto, s);
+ overlay_draw(overlay, moveto, lineto, s);
}
@@ -1284,7 +1284,7 @@ static bool event_loop(SDL_Surface **surf, const char *logfile)
}
-void gui(const char *logfile)
+void gui(const char *logfile, const struct overlay *overlay)
{
SDL_Surface *surf;
@@ -1319,7 +1319,7 @@ time_start(&t);
time_stop(&t);
fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
if (show_overlay)
- draw_overlay(surf);
+ draw_overlay(surf, overlay);
SDL_UnlockSurface(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);
diff --git a/meme/meme.c b/meme/meme.c
index 0b1049d..80dd619 100644
--- a/meme/meme.c
+++ b/meme/meme.c
@@ -22,7 +22,7 @@
#include "slice.h"
-extern void gui(const char *logfile);
+extern void gui(const char *logfile, const struct overlay *overlay);
static bool count_edge(const struct vertex *a, const struct vertex *b,
@@ -66,6 +66,7 @@ int main(int argc, char **argv)
const char *logfile = NULL;
const char *overlay = NULL;
const char *slice = NULL;
+ const struct overlay *over = NULL;
struct time t_load;
while ((c = getopt(argc, argv, "l:o:s:")) != EOF)
@@ -108,9 +109,9 @@ int main(int argc, char **argv)
}
if (overlay)
- overlay_load(overlay);
+ over = overlay_load(overlay);
- gui(logfile);
+ gui(logfile, over);
return 0;
}
diff --git a/meme/overlay.c b/meme/overlay.c
index df3f3cf..fd85de4 100644
--- a/meme/overlay.c
+++ b/meme/overlay.c
@@ -24,22 +24,20 @@ struct point {
struct point *next;
};
-struct path {
+struct overlay {
struct point *points;
- struct path *next;
+ struct overlay *next;
};
-static struct path *paths = NULL;
-
-
-void overlay_draw(void (*moveto)(void *user, int x, int y),
+void overlay_draw(const struct overlay *overlay,
+ void (*moveto)(void *user, int x, int y),
void (*lineto)(void *user, int x, int y), void *user)
{
- const struct path *path;
+ const struct overlay *path;
const struct point *p;
- for (path = paths; path; path = path->next) {
+ for (path = overlay; path; path = path->next) {
p = path->points;
moveto(user, p->x, p->y);
for (p = p->next; p; p = p->next)
@@ -48,9 +46,10 @@ void overlay_draw(void (*moveto)(void *user, int x, int y),
}
-static void overlay_load_file(FILE *file)
+static struct overlay *overlay_load_file(FILE *file)
{
- struct path *path = NULL;
+ struct overlay *over = NULL;
+ struct overlay *path = NULL;
struct point *p;
int lineno = 0;
char buf[1024];
@@ -76,10 +75,10 @@ static void overlay_load_file(FILE *file)
}
if (!path) {
- path = alloc_type(struct path);
- path->next = paths;
+ path = alloc_type(struct overlay);
+ path->next = over;
path->points = NULL;
- paths = path;
+ over = path;
}
p = alloc_type(struct point);
p->x = round(x * 1000);
@@ -87,18 +86,21 @@ static void overlay_load_file(FILE *file)
p->next = path->points;
path->points = p;
}
+ return over;
}
-void overlay_load(const char *name)
+struct overlay *overlay_load(const char *name)
{
FILE *file;
+ struct overlay *over;
file = fopen(name, "r");
if (!file) {
perror(name);
exit(1);
}
- overlay_load_file(file);
+ over = overlay_load_file(file);
fclose(file);
+ return over;
}
diff --git a/meme/overlay.h b/meme/overlay.h
index 703d54e..dbab8b3 100644
--- a/meme/overlay.h
+++ b/meme/overlay.h
@@ -14,8 +14,12 @@
#ifndef OVERLAY_H
#define OVERLAY_H
-void overlay_draw(void (*moveto)(void *user, int x, int y),
+struct overlay;
+
+
+void overlay_draw(const struct overlay *overlay,
+ void (*moveto)(void *user, int x, int y),
void (*lineto)(void *user, int x, int y), void *user);
-void overlay_load(const char *name);
+struct overlay *overlay_load(const char *name);
#endif /* !STL_H */