This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 9f976bc10006bdd76c3c4709fa6baeb1dda15f3f (commit) from 5cd86d45da74ebf34224157f12d693e82b59f4b2 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/9f976bc10006bdd76c3c4709fa6baeb1dda15...
commit 9f976bc10006bdd76c3c4709fa6baeb1dda15f3f Author: Cyril Hrubis metan@ucw.cz Date: Sun Mar 31 23:56:57 2013 +0200
demos:c_simple: Make use of BackendWaitEvent().
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/c_simple/backend_example.c b/demos/c_simple/backend_example.c index c711f41..b0faf84 100644 --- a/demos/c_simple/backend_example.c +++ b/demos/c_simple/backend_example.c @@ -28,11 +28,25 @@
#include <GP.h>
+static void redraw(GP_Backend *self) +{ + GP_Context *context = self->context; + GP_Pixel white_pixel, black_pixel; + + black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); + white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); + + GP_Fill(context, black_pixel); + GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel); + GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel); + + /* Update the backend screen */ + GP_BackendFlip(self); +} + int main(int argc, char *argv[]) { GP_Backend *backend; - GP_Context *context; - GP_Pixel white_pixel, black_pixel; const char *backend_opts = "X11:100x100"; int opt;
@@ -56,51 +70,43 @@ int main(int argc, char *argv[])
backend = GP_BackendInit(backend_opts, "Backend Example", stderr);
- context = backend->context; - - black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context); - white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context); - - GP_Fill(context, black_pixel); - GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel); - GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel); + if (backend == NULL) { + fprintf(stderr, "Failed to initialize backendn"); + return 1; + }
- /* Update the backend screen */ - GP_BackendFlip(backend); + redraw(backend);
+ /* Handle events */ for (;;) { - /* Wait for backend event */ - GP_BackendWait(backend); - - /* Read and parse events */ GP_Event ev;
- while (GP_BackendGetEvent(backend, &ev)) { - - GP_EventDump(&ev); - - switch (ev.type) { - case GP_EV_KEY: - switch (ev.val.val) { - case GP_KEY_ESC: - case GP_KEY_Q: - GP_BackendExit(backend); - return 0; - break; - } + GP_BackendWaitEvent(backend, &ev); + + GP_EventDump(&ev); + + switch (ev.type) { + case GP_EV_KEY: + switch (ev.val.val) { + case GP_KEY_ESC: + case GP_KEY_Q: + GP_BackendExit(backend); + return 0; break; - case GP_EV_SYS: - switch (ev.code) { - case GP_EV_SYS_RESIZE: - GP_BackendResizeAck(backend); - break; - case GP_EV_SYS_QUIT: - GP_BackendExit(backend); - return 0; - break; - } + } + break; + case GP_EV_SYS: + switch (ev.code) { + case GP_EV_SYS_RESIZE: + GP_BackendResizeAck(backend); + redraw(backend); + break; + case GP_EV_SYS_QUIT: + GP_BackendExit(backend); + return 0; break; } + break; } }
diff --git a/demos/c_simple/fileview.c b/demos/c_simple/fileview.c index aa6ff0b..26ae4e0 100644 --- a/demos/c_simple/fileview.c +++ b/demos/c_simple/fileview.c @@ -122,7 +122,9 @@ void event_loop(void) { GP_Event ev;
- while (GP_BackendGetEvent(backend, &ev)) { + for (;;) { + GP_BackendWaitEvent(backend, &ev); + switch (ev.type) { case GP_EV_KEY: if (ev.code != GP_EV_KEY_DOWN) @@ -268,10 +270,7 @@ int main(int argc, char *argv[]) redraw_screen(); GP_BackendFlip(backend); - for (;;) { - GP_BackendWait(backend); - event_loop(); - } + event_loop();
return 0; } diff --git a/demos/c_simple/fonttest.c b/demos/c_simple/fonttest.c index e374ec9..f6516cb 100644 --- a/demos/c_simple/fonttest.c +++ b/demos/c_simple/fonttest.c @@ -190,7 +190,9 @@ void event_loop(void) { GP_Event ev;
- while (GP_BackendGetEvent(win, &ev)) { + for (;;) { + GP_BackendWaitEvent(win, &ev); + switch (ev.type) { case GP_EV_KEY: if (ev.code != GP_EV_KEY_DOWN) @@ -284,8 +286,7 @@ int main(int argc, char *argv[]) redraw_screen(); GP_BackendFlip(win);
- for (;;) { - GP_BackendWait(win); - event_loop(); - } + event_loop(); + + return 0; } diff --git a/demos/c_simple/shapetest.c b/demos/c_simple/shapetest.c index 0edfce1..9cebdd3 100644 --- a/demos/c_simple/shapetest.c +++ b/demos/c_simple/shapetest.c @@ -337,7 +337,9 @@ void event_loop(void)
GP_Event ev;
- while (GP_BackendGetEvent(backend, &ev)) { + for (;;) { + GP_BackendWaitEvent(backend, &ev); + GP_EventDump(&ev); shift_pressed = GP_EventGetKey(&ev, GP_KEY_LEFT_SHIFT) || @@ -498,11 +500,8 @@ int main(void) darkgray = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win);
print_instructions(); - redraw_screen(); + event_loop();
- for (;;) { - GP_BackendWait(backend); - event_loop(); - } + return 0; } diff --git a/demos/c_simple/showimage.c b/demos/c_simple/showimage.c index 8903515..3394230 100644 --- a/demos/c_simple/showimage.c +++ b/demos/c_simple/showimage.c @@ -66,15 +66,13 @@ int main(int argc, char *argv[])
/* Wait for events */ for (;;) { - GP_BackendWait(backend); - GP_Event ev;
- while (GP_BackendGetEvent(backend, &ev)) { - if (ev.type == GP_EV_KEY && ev.val.val == GP_KEY_Q) { - GP_BackendExit(backend); - return 0; - } + GP_BackendWaitEvent(backend, &ev); + + if (ev.type == GP_EV_KEY && ev.val.val == GP_KEY_Q) { + GP_BackendExit(backend); + return 0; } }
diff --git a/demos/c_simple/textaligntest.c b/demos/c_simple/textaligntest.c index 5ae84ab..39391b4 100644 --- a/demos/c_simple/textaligntest.c +++ b/demos/c_simple/textaligntest.c @@ -73,7 +73,9 @@ static void event_loop(void) { GP_Event ev;
- while (GP_BackendGetEvent(win, &ev)) { + for (;;) { + GP_BackendWaitEvent(win, &ev); + switch (ev.type) { case GP_EV_KEY: if (ev.code != GP_EV_KEY_DOWN) @@ -156,12 +158,9 @@ int main(int argc, char *argv[]) darkgray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context);
redraw_screen(); - GP_BackendFlip(win); + event_loop();
- for (;;) { - GP_BackendWait(win); - event_loop(); - } + return 0; }
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/backend_example.c | 84 ++++++++++++++++++++----------------- demos/c_simple/fileview.c | 9 ++-- demos/c_simple/fonttest.c | 11 +++-- demos/c_simple/shapetest.c | 11 ++--- demos/c_simple/showimage.c | 12 ++--- demos/c_simple/textaligntest.c | 11 ++--- 6 files changed, 70 insertions(+), 68 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.