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_backend_exit(backend
);
47 fprintf(stderr
, "Got signal %i\n", signo
);
52 static void init_backend(const char *backend_opts
)
54 backend
= gp_backend_init(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 signal(SIGINT
, sighandler
);
83 signal(SIGSEGV
, sighandler
);
84 signal(SIGBUS
, sighandler
);
85 signal(SIGABRT
, sighandler
);
87 init_backend(backend_opts
);
89 pixmap
= backend
->pixmap
;
91 black_pixel
= gp_rgb_to_pixmap_pixel(0x00, 0x00, 0x00, pixmap
);
92 white_pixel
= gp_rgb_to_pixmap_pixel(0xff, 0xff, 0xff, pixmap
);
94 gp_fill(pixmap
, black_pixel
);
95 gp_backend_flip(backend
);
98 space
= space_create(particles
, 10<<8, 10<<8, (pixmap
->w
- 10)<<8, (pixmap
->h
- 10)<<8);
102 gp_backend_poll(backend
);
106 /* Read and parse events */
109 while (gp_backend_get_event(backend
, &ev
)) {
115 if (ev
.code
!= GP_EV_KEY_DOWN
)
118 switch (ev
.val
.key
.key
) {
122 gp_backend_exit(backend
);
126 pause_flag
= !pause_flag
;
139 gp_backend_exit(backend
);
142 case GP_EV_SYS_RESIZE
:
143 gp_backend_resize_ack(backend
);
144 space_destroy(space
);
145 space
= space_create(particles
,
148 (pixmap
->h
- 10)<<8);
156 space_time_tick(space
, 1);
157 space_draw_particles(pixmap
, space
);
158 gp_backend_flip(backend
);
162 gp_backend_exit(backend
);