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 example that loads and show image from zip container into X11 window.
35 static GP_Backend
*backend
;
36 static GP_Pixmap
*image
;
37 static GP_Container
*container
;
40 * Try to load next image in container, if image has different size than the
41 * window request resize and blit it at the resize event in the main loop.
43 * Note that the resize event needs not to be granted so we really should have
44 * plan b (which is omited here for the sake of simplicity).
46 static void load_next(void)
50 image
= GP_ContainerLoadNext(container
, NULL
);
55 if (image
->w
!= backend
->pixmap
->w
||
56 image
->h
!= backend
->pixmap
->h
) {
57 GP_BackendResize(backend
, image
->w
, image
->h
);
61 GP_Blit_Clipped(image
, 0, 0, image
->w
, image
->h
, backend
->pixmap
, 0, 0);
62 GP_BackendFlip(backend
);
65 int main(int argc
, char *argv
[])
69 fprintf(stderr
, "Takes path to zip or cbz as an argument\n");
73 /* Open zip container */
74 container
= GP_OpenZip(argv
[1]);
76 if (container
== NULL
) {
77 fprintf(stderr
, "Failed to open container: %s\n", strerror(errno
));
82 image
= GP_ContainerLoadNext(container
, NULL
);
85 fprintf(stderr
, "Failed to load image %s\n", strerror(errno
));
89 /* Initalize backend */
90 backend
= GP_BackendX11Init(NULL
, 0, 0, image
->w
, image
->h
, argv
[1], 0);
92 if (backend
== NULL
) {
93 fprintf(stderr
, "Failed to initalize backend\n");
97 /* Blit image into the window and show it */
98 GP_Blit_Clipped(image
, 0, 0, image
->w
, image
->h
, backend
->pixmap
, 0, 0);
99 GP_BackendFlip(backend
);
101 /* Wait for events */
105 GP_BackendWaitEvent(backend
, &ev
);
109 if (!ev
.code
== GP_EV_KEY_DOWN
)
112 switch (ev
.val
.val
) {
114 GP_BackendExit(backend
);
123 if (ev
.code
== GP_EV_SYS_RESIZE
) {
124 GP_BackendResizeAck(backend
);
125 GP_Blit_Clipped(image
, 0, 0, image
->w
, image
->h
,
126 backend
->pixmap
, 0, 0);
127 GP_BackendFlip(backend
);