1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-22 14:05:20 +02:00

tools/: exit from sample mode by pressing Q or by closing the window

This commit is contained in:
Werner Almesberger 2012-06-21 18:48:54 -03:00
parent 4eb1065dd7
commit 87050bc12a
3 changed files with 27 additions and 3 deletions

View File

@ -315,9 +315,11 @@ static void samples(struct atrf_dsc *dsc)
y |= *s++ << 8;
if (debug)
fprintf(stderr, "\t%d %d\n", x, y);
plot(x, y);
if (!plot(x, y))
goto quit;
}
}
quit:
buf[0] = 0;
packet(dsc, SAMPLE, 0, 0, buf, PAYLOAD);
}

View File

@ -16,6 +16,8 @@
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "plot.h"
#define XRES 1024
#define YRES 1024
@ -44,8 +46,10 @@ static SDL_Rect front_rect = {
};
void plot(int x, int y)
int plot(int x, int y)
{
SDL_Event event;
if (!first) {
SDL_BlitSurface(back, &back_rect, surf, &front_rect);
SDL_LockSurface(surf);
@ -71,6 +75,24 @@ void plot(int x, int y)
first = 0;
last_x = x;
last_y = y;
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_q:
return 0;
default:
break;
}
break;
case SDL_QUIT:
return 0;
default:
break;
}
return 1;
}

View File

@ -14,7 +14,7 @@
#ifndef PLOT_H
#define PLOT_H
void plot(int x, int y);
int plot(int x, int y);
void plot_init(void);
#endif /* !PLOT_H */