int main(void) { GP_Backend *win_1, *win_2; win_1 = GP_BackendX11Init(NULL, 0, 0, 300, 300, "win 1", 0); win_2 = GP_BackendX11Init(NULL, 0, 0, 300, 300, "win 2", 0); if (win_1 == NULL || win_2 == NULL) { GP_BackendExit(win_1); GP_BackendExit(win_2); return 1; } /* Update the backend screen */ redraw(win_1->context); redraw(win_2->context); GP_BackendFlip(win_1); GP_BackendFlip(win_2); for (;;) { /* * Wait for backend event. * * Either window is fine as they share connection. */ GP_Backend *b = win_1 ? win_1 : win_2; if (b == NULL) return 0; GP_BackendWait(b); if (ev_loop(win_1, "win 1")) win_1 = NULL; if (ev_loop(win_2, "win 2")) win_2 = NULL; } GP_BackendExit(win_1); GP_BackendExit(win_2); return 0; }
int main(int argc, char *argv[]) { const char *backend_opts = "X11"; int opt; while ((opt = getopt(argc, argv, "b:h")) != -1) { switch (opt) { case 'b': backend_opts = optarg; break; case 'h': GP_BackendInit(NULL, NULL, stderr); return 0; break; default: fprintf(stderr, "Invalid paramter '%c'\n", opt); return 1; } } backend = GP_BackendInit(backend_opts, "Input Test", stderr); if (backend == NULL) { fprintf(stderr, "Failed to initalize backend '%s'\n", backend_opts); return 1; } win = backend->context; red = GP_ColorToContextPixel(GP_COL_RED, win); green = GP_ColorToContextPixel(GP_COL_GREEN, win); white = GP_ColorToContextPixel(GP_COL_WHITE, win); black = GP_ColorToContextPixel(GP_COL_BLACK, win); GP_Fill(win, black); GP_BackendFlip(backend); for (;;) { GP_BackendWait(backend); event_loop(); } }
static void event_loop(void) { for (;;) { GP_BackendWait(backend); while (GP_BackendEventsQueued(backend)) { GP_Event ev; GP_BackendGetEvent(backend, &ev); GP_EventDump(&ev); switch (ev.type) { case GP_EV_KEY: draw_event(&ev); switch (ev.val.key.key) { case GP_KEY_ESC: GP_BackendExit(backend); exit(0); break; case GP_BTN_LEFT: GP_HLineXXY(win, ev.cursor_x - 3, ev.cursor_x + 3, ev.cursor_y, red); GP_VLineXYY(win, ev.cursor_x, ev.cursor_y - 3, ev.cursor_y + 3, red); GP_BackendFlip(backend); break; default: break; } break; case GP_EV_REL: switch (ev.code) { static int size = 0; case GP_EV_REL_POS: if (GP_EventGetKey(&ev, GP_BTN_LEFT)) { GP_PutPixel(win, ev.cursor_x, ev.cursor_y, green); } int align = GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM; GP_TextClear(win, NULL, 20, 40, align, black, size); size = GP_Print(win, NULL, 20, 40, align, white, black, "X=%3u Y=%3u dX=%3i dY=%3i", ev.cursor_x, ev.cursor_y, ev.val.rel.rx, ev.val.rel.ry); GP_BackendFlip(backend); break; } 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); exit(0); break; } break; } } } }