summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 00:26:17 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 00:26:17 -0300
commit6def231e45616899c67bf3294fba9d16bac2bf73 (patch)
tree71d025fd58181c7b5e087755a42789af37f4f842 /meme
parente1931049c7fc1d23e93bd2ae4783ec03cd9adfed (diff)
downloadmisc-6def231e45616899c67bf3294fba9d16bac2bf73.tar.gz
misc-6def231e45616899c67bf3294fba9d16bac2bf73.tar.bz2
misc-6def231e45616899c67bf3294fba9d16bac2bf73.zip
meme/gui.c: process keys: Q to quit, G to toggle grid (edges)
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 9473e46..f126760 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -27,6 +27,7 @@
static int x_orig, y_orig;
static int x_min, x_max, y_min, y_max, z_min, z_max;
static int zoom;
+static bool show_grid = 1;
static bool coord(int w, int h, int x, int y,
@@ -50,10 +51,9 @@ static bool coord(int w, int h, int x, int y,
}
-static void grid_draw(SDL_Surface *s, int w, int h)
+static void surface_draw(SDL_Surface *s, int w, int h)
{
const struct facet *f;
- const struct edge *e;
Sint16 xa, ya, xb, yb, xc, yc;
int z3;
Uint32 c;
@@ -71,6 +71,14 @@ static void grid_draw(SDL_Surface *s, int w, int h)
filledTrigonColor(s, xa, ya, xb, yb, xc, yc, c);
}
+}
+
+
+static void edges_draw(SDL_Surface *s, int w, int h)
+{
+ const struct edge *e;
+ Sint16 xa, ya, xb, yb;
+
for (e = edges; e; e = e->next) {
if (!coord(w, h, e->a->x, e->a->y, &xa, &ya))
continue;
@@ -84,7 +92,9 @@ static void grid_draw(SDL_Surface *s, int w, int h)
static void draw(SDL_Surface *s)
{
SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 0xff, 0xff, 0xff));
- grid_draw(s, XRES, YRES);
+ surface_draw(s, XRES, YRES);
+ if (show_grid)
+ edges_draw(s, XRES, YRES);
}
@@ -186,6 +196,18 @@ void gui(void)
button_event(&event.button);
redraw = 1;
break;
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_g:
+ show_grid = !show_grid;
+ redraw = 1;
+ break;
+ case SDLK_q:
+ return;
+ default:
+ break;
+ }
+ break;
case SDL_QUIT:
return;
}