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-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
32 #include <backends/GP_Backends.h>
36 static GP_Pixel black_pixel
;
37 static GP_Pixel white_pixel
;
39 static GP_Backend
*backend
= NULL
;
40 static GP_Pixmap
*pixmap
= NULL
;
42 static void sighandler(int signo
)
45 GP_BackendExit(backend
);
47 fprintf(stderr
, "Got signal %i\n", signo
);
52 static void init_backend(const char *backend_opts
)
54 backend
= GP_BackendInit(backend_opts
, "Particles");
56 if (backend
== NULL
) {
57 fprintf(stderr
, "Failed to initalize backend '%s'\n", backend_opts
);
62 int main(int argc
, char *argv
[])
64 const char *backend_opts
= "X11";
69 while ((opt
= getopt(argc
, argv
, "b:n:")) != -1) {
72 backend_opts
= optarg
;
75 particles
= atoi(optarg
);
78 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
82 // GP_SetDebugLevel(10);
84 signal(SIGINT
, sighandler
);
85 signal(SIGSEGV
, sighandler
);
86 signal(SIGBUS
, sighandler
);
87 signal(SIGABRT
, sighandler
);
89 init_backend(backend_opts
);
91 pixmap
= backend
->pixmap
;
93 black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, pixmap
);
94 white_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, pixmap
);
96 GP_Fill(pixmap
, black_pixel
);
97 GP_BackendFlip(backend
);
100 space
= space_create(particles
, 10<<8, 10<<8, (pixmap
->w
- 10)<<8, (pixmap
->h
- 10)<<8);
104 GP_BackendPoll(backend
);
108 /* Read and parse events */
111 while (GP_BackendGetEvent(backend
, &ev
)) {
117 if (ev
.code
!= GP_EV_KEY_DOWN
)
120 switch (ev
.val
.key
.key
) {
124 GP_BackendExit(backend
);
128 pause_flag
= !pause_flag
;
141 GP_BackendExit(backend
);
144 case GP_EV_SYS_RESIZE
:
145 GP_BackendResizeAck(backend
);
146 space_destroy(space
);
147 space
= space_create(particles
,
150 (pixmap
->h
- 10)<<8);
158 space_time_tick(space
, 1);
159 space_draw_particles(pixmap
, space
);
160 GP_BackendFlip(backend
);
164 GP_BackendExit(backend
);