1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Simple backend example.
32 static void redraw(struct GP_Pixmap
*pixmap
)
34 GP_Pixel white_pixel
, black_pixel
;
36 black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, pixmap
);
37 white_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, pixmap
);
39 GP_Fill(pixmap
, black_pixel
);
40 GP_Line(pixmap
, 0, 0, pixmap
->w
- 1, pixmap
->h
- 1, white_pixel
);
41 GP_Line(pixmap
, 0, pixmap
->h
- 1, pixmap
->w
- 1, 0, white_pixel
);
44 static int ev_loop(struct GP_Backend
*backend
, const char *name
)
51 while (GP_BackendGetEvent(backend
, &ev
)) {
53 printf("-------------------------- %s\n", name
);
62 GP_BackendExit(backend
);
69 case GP_EV_SYS_RESIZE
:
70 GP_BackendResizeAck(backend
);
71 redraw(backend
->pixmap
);
72 GP_BackendFlip(backend
);
75 GP_BackendExit(backend
);
82 printf("-----------------------------\n");
90 GP_Backend
*win_1
, *win_2
;
92 win_1
= GP_BackendX11Init(NULL
, 0, 0, 300, 300, "win 1", 0);
93 win_2
= GP_BackendX11Init(NULL
, 0, 0, 300, 300, "win 2", 0);
95 if (win_1
== NULL
|| win_2
== NULL
) {
96 GP_BackendExit(win_1
);
97 GP_BackendExit(win_2
);
101 /* Update the backend screen */
102 redraw(win_1
->pixmap
);
103 redraw(win_2
->pixmap
);
105 GP_BackendFlip(win_1
);
106 GP_BackendFlip(win_2
);
110 * Wait for backend event.
112 * Either window is fine as they share connection.
114 GP_Backend
*b
= win_1
? win_1
: win_2
;
121 if (ev_loop(win_1
, "win 1"))
124 if (ev_loop(win_2
, "win 2"))
128 GP_BackendExit(win_1
);
129 GP_BackendExit(win_2
);