core: Get rid of GP_Color.
[gfxprim.git] / demos / c_simple / x11_windows.c
blob1c5b2d071404bc49ce86da700f0fa30ff4a82016
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Simple backend example.
29 #include <stdio.h>
30 #include <GP.h>
32 static void redraw(struct GP_Context *context)
34 GP_Pixel white_pixel, black_pixel;
36 black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
37 white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);
39 GP_Fill(context, black_pixel);
40 GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel);
41 GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel);
44 static int ev_loop(struct GP_Backend *backend, const char *name)
46 GP_Event ev;
48 if (backend == NULL)
49 return 0;
51 while (GP_BackendGetEvent(backend, &ev)) {
53 printf("-------------------------- %s\n", name);
55 GP_EventDump(&ev);
57 switch (ev.type) {
58 case GP_EV_KEY:
59 switch (ev.val.val) {
60 case GP_KEY_ESC:
61 case GP_KEY_Q:
62 GP_BackendExit(backend);
63 return 1;
64 break;
66 break;
67 case GP_EV_SYS:
68 switch (ev.code) {
69 case GP_EV_SYS_RESIZE:
70 GP_BackendResizeAck(backend);
71 break;
72 case GP_EV_SYS_QUIT:
73 GP_BackendExit(backend);
74 return 1;
75 break;
77 break;
80 printf("-----------------------------\n");
83 return 0;
86 int main(void)
88 GP_Backend *win_1, *win_2;
90 win_1 = GP_BackendX11Init(NULL, 0, 0, 300, 300, "win 1", 0);
91 win_2 = GP_BackendX11Init(NULL, 0, 0, 300, 300, "win 2", 0);
93 if (win_1 == NULL || win_2 == NULL) {
94 GP_BackendExit(win_1);
95 GP_BackendExit(win_2);
96 return 1;
99 /* Update the backend screen */
100 redraw(win_1->context);
101 redraw(win_2->context);
103 GP_BackendFlip(win_1);
104 GP_BackendFlip(win_2);
106 for (;;) {
108 * Wait for backend event.
110 * Either window is fine as they share connection.
112 GP_Backend *b = win_1 ? win_1 : win_2;
114 if (b == NULL)
115 return 0;
117 GP_BackendWait(b);
119 if (ev_loop(win_1, "win 1"))
120 win_1 = NULL;
122 if (ev_loop(win_2, "win 2"))
123 win_2 = NULL;
126 GP_BackendExit(win_1);
127 GP_BackendExit(win_2);
129 return 0;