summaryrefslogtreecommitdiff
path: root/meme/overlay.c
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/overlay.c
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/overlay.c')
-rw-r--r--meme/overlay.c32
1 files changed, 17 insertions, 15 deletions
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;
}