spiv: Fix image list counter
[gfxprim.git] / demos / c_simple / showimage.c
blob4208b201c0b5cf7fe7c40dcdbd224a6f58747c42
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 example that shows X11 window with image.
29 #include <stdio.h>
30 #include <errno.h>
31 #include <string.h>
33 #include <GP.h>
35 int main(int argc, char *argv[])
37 GP_Backend *backend;
38 GP_Pixmap *image;
40 if (argc != 2) {
41 fprintf(stderr, "Takes image as an argument\n");
42 return 1;
45 /* Load image */
46 image = GP_LoadImage(argv[1], NULL);
48 if (!image) {
49 fprintf(stderr, "Failed to load bitmap: %s\n", strerror(errno));
50 return 1;
53 /* Initalize backend */
54 backend = GP_BackendX11Init(NULL, 0, 0, image->w, image->h, argv[1], 0);
56 if (!backend) {
57 fprintf(stderr, "Failed to initalize backend\n");
58 return 1;
61 /* Blit image into the window and show it */
62 GP_Blit(image, 0, 0, image->w, image->h, backend->pixmap, 0, 0);
63 GP_BackendFlip(backend);
65 /* Wait for events */
66 for (;;) {
67 GP_Event ev;
69 GP_BackendWaitEvent(backend, &ev);
71 if (ev.type == GP_EV_KEY && ev.val.val == GP_KEY_Q) {
72 GP_BackendExit(backend);
73 return 0;
76 if (ev.type == GP_EV_SYS && ev.code == GP_EV_SYS_RESIZE) {
77 int cx, cy;
79 GP_BackendResizeAck(backend);
81 cx = ((int)backend->pixmap->w - (int)image->w) / 2;
82 cy = ((int)backend->pixmap->h - (int)image->h) / 2;
84 GP_Fill(backend->pixmap, 0);
85 GP_Blit_Clipped(image, 0, 0, image->w, image->h, backend->pixmap, cx, cy);
86 GP_BackendFlip(backend);
90 return 0;