summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-12 13:05:23 -0300
committerWerner Almesberger <werner@almesberger.net>2014-09-12 13:05:23 -0300
commit11871c02868983d0926ed2cb5445d447237b0d5b (patch)
tree25487c7f559772868ce1d84640b25fd1d9c99d8b /meme
parent31a859415efab1e8a93eb0349adabc018b74d91e (diff)
downloadmisc-11871c02868983d0926ed2cb5445d447237b0d5b.tar.gz
misc-11871c02868983d0926ed2cb5445d447237b0d5b.tar.bz2
misc-11871c02868983d0926ed2cb5445d447237b0d5b.zip
meme/gui.c (gui): move event loop to event_loop and fix indentation
Diffstat (limited to 'meme')
-rw-r--r--meme/gui.c67
1 files changed, 38 insertions, 29 deletions
diff --git a/meme/gui.c b/meme/gui.c
index ab143b2..49ed887 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -406,10 +406,45 @@ static void extrema(void)
/* ----- Main loop --------------------------------------------------------- */
+static bool event_loop(SDL_Surface *s)
+{
+ SDL_Event event;
+ bool redraw = 0;
+
+ while (!redraw) {
+ SDL_WaitEvent(&event);
+
+ switch (event.type) {
+ case SDL_MOUSEMOTION:
+ motion_event(s, &event.motion);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ 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 1;
+ default:
+ break;
+ }
+ break;
+ case SDL_QUIT:
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
void gui(void)
{
SDL_Surface *surf;
- SDL_Event event;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
@@ -429,8 +464,6 @@ void gui(void)
zoom = 7;
while (1) {
- bool redraw;
-
discard_changes();
SDL_LockSurface(surf);
draw(surf);
@@ -442,31 +475,7 @@ void gui(void)
apply_changes(surf);
}
- redraw = 0;
- while (SDL_WaitEvent(&event) && !redraw) {
- switch (event.type) {
- case SDL_MOUSEMOTION:
- motion_event(surf, &event.motion);
- break;
- case SDL_MOUSEBUTTONDOWN:
- 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;
- }
- }
+ if (event_loop(surf))
+ break;
}
}