annotate src/paranormal/misc.c @ 2409:f67bdd91620a

Add some UI niceities.
author William Pitcock <nenolod@atheme.org>
date Mon, 18 Feb 2008 02:57:17 -0600
parents 56bb18dd3fdd
children f1b6f1b2cdb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1892
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
1 /*
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
2 * paranormal: iterated pipeline-driven visualization plugin
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
5 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
8 * the Free Software Foundation; under version 2 of the License.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
9 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
10 * This program is distributed in the hope that it will be useful,
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
13 * GNU General Public License for more details.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
14 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
15 * You should have received a copy of the GNU General Public License
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
16 * along with this program; if not, write to the Free Software
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
18 */
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 302
diff changeset
19
1943
56bb18dd3fdd paranormal: CONFIG_H removal
William Pitcock <nenolod@atheme.org>
parents: 1892
diff changeset
20 #include <config.h>
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
21
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
22 #include <stdlib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
23 #include <stdio.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
24
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
25 #include <glib.h>
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
26
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
27 #include "paranormal.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
28 #include "actuators.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
29 #include "pn_utils.h"
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
30
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
31 /* ******************** misc_floater ******************** */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
32 static struct pn_actuator_option_desc misc_floater_opts[] =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
33 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
34 { "value", "The colour value for the floater.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
35 OPT_TYPE_INT, { ival: 255 } },
188
0d826917c56f [svn] - 64-bit safety (pass 1 of 2)
nenolod
parents: 186
diff changeset
36 { NULL }
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
37 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
38
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
39 typedef enum
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
40 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
41 float_up = 0x1,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
42 float_down = 0x2,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
43 float_left = 0x4,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
44 float_right = 0x8,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
45 } FloaterDirection;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
46
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
47 struct floater_state_data
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
48 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
49 FloaterDirection dir;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
50 gint x;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
51 gint y;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
52 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
53
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
54 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
55 misc_floater_init(gpointer *data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
56 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
57 struct floater_state_data *opaque_data = g_new0(struct floater_state_data, 1);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
58 *data = opaque_data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
59 opaque_data->x = rand() % pn_image_data->width;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
60 opaque_data->y = rand() % pn_image_data->height;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
61 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
62 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
63
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
64 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
65 misc_floater_cleanup(gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
66 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
67 g_free(data);
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
68 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
69
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
70 /*
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
71 * This implementation isn't very great.
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
72 * Anyone want to improve it? :(
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
73 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
74 static void
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
75 misc_floater_exec(const struct pn_actuator_option *opts, gpointer data)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
76 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
77 struct floater_state_data *opaque_data = (struct floater_state_data *) data;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
78 guchar value = (opts[0].val.ival < 0 || opts[0].val.ival > 255) ? 255 : opts[0].val.ival;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
79
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
80 /* determine the root coordinate first */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
81 if (opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
82 opaque_data->y -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
83 if (opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
84 opaque_data->y += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
85
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
86 if (opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
87 opaque_data->x -= 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
88 if (opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
89 opaque_data->x += 1;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
90
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
91 /* make sure we're within surface boundaries. segfaults suck, afterall. */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
92 if (opaque_data->x + 1 <= pn_image_data->width &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
93 opaque_data->x - 1 >= 0 &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
94 opaque_data->y + 1 <= pn_image_data->height &&
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
95 opaque_data->y - 1 >= 0)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
96 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
97 /* draw it. i could use a loop here, but i don't see much reason in it,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
98 * so i don't think i will at this time. -nenolod
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
99 */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
100 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
101 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x + 1, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
102 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x - 1, opaque_data->y)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
103 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y + 1)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
104 pn_image_data->surface[0][PN_IMG_INDEX(opaque_data->x, opaque_data->y - 1)] = value;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
105 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
106
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
107 /* check if we need to change direction yet, and if so, do so. */
302
b185ed2f8fa2 [svn] - improve beat detection
nenolod
parents: 188
diff changeset
108 if (pn_new_beat == TRUE)
186
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
109 opaque_data->dir = (FloaterDirection) rand() % 15; /* sum of all dir values */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
110
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
111 /* now adjust the direction so we stay in boundary */
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
112 if (opaque_data->x - 1 <= 0 && opaque_data->dir & float_left)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
113 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
114 opaque_data->dir &= ~float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
115 opaque_data->dir |= float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
116 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
117
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
118 if (opaque_data->x + 1 >= pn_image_data->width && opaque_data->dir & float_right)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
119 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
120 opaque_data->dir &= ~float_right;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
121 opaque_data->dir |= float_left;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
122 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
123
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
124 if (opaque_data->y - 1 <= 0 && opaque_data->dir & float_up)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
125 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
126 opaque_data->dir &= ~float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
127 opaque_data->dir |= float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
128 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
129
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
130 if (opaque_data->y + 1 >= pn_image_data->height && opaque_data->dir & float_down)
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
131 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
132 opaque_data->dir &= ~float_down;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
133 opaque_data->dir |= float_up;
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
134 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
135 }
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
136
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
137 struct pn_actuator_desc builtin_misc_floater =
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
138 {
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
139 "misc_floater",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
140 "Floating Particle",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
141 "A floating particle.",
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
142 0, misc_floater_opts,
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
143 misc_floater_init, misc_floater_cleanup, misc_floater_exec
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
144 };
49f532942eec [svn] - add floating particles.
nenolod
parents:
diff changeset
145