From http://www.jwz.org/xscreensaver/xscreensaver-5.39.tar.gz
[xscreensaver] / hacks / bubbles.h
1 /* bubbles.h - definitions for bubbles screensaver */
2
3 /* $Id: bubbles.h,v 1.6 2006/02/25 20:11:57 jwz Exp $ */
4
5 #ifndef _BUBBLES_H_
6 #define _BUBBLES_H_
7
8 #ifdef HAVE_JWXYZ
9 # include "jwxyz.h"
10 #else
11 # include <X11/Xlib.h>
12 #endif
13
14 /***************************************************************************
15  *   Options you might like to change to affect the program's behaviour    *
16  ***************************************************************************/
17
18 /*
19  *   Uncommenting the following will enable support for reading bubbles from 
20  * files (using the -file and -directory options to bubbles).  This is
21  * disabled by default since such operations are inherently non-portable
22  * and we want the program to compile on as many systems as possible.  
23  *
24  *   If you uncomment this and you figure out how to get it working, please
25  * let me (J.Macnicol@student.anu.edu.au) know.  Diffs against the standard
26  * distribution would be appreciated.  Possible sources of problems are
27  * dirent and possibly the use of tmpnam().
28  */
29
30 /* #define BUBBLES_IO */
31
32 /*
33  *   The following only makes sense if BUBBLES_IO above is defined.
34  * 
35  *   Uncomment the following if you always want to use the -file or
36  * -directory options on the command line and never to use a default bubble
37  * compiled into the program.  This way you would save memory and disk space
38  * since if you do use -file or -directory only one bubble will be loaded
39  * into memory at any one time (and remember the default bubble is really
40  * uncompressed, unlike bubbles in files which can be compressed).  This
41  * is disabled by default only so people running the program for the first
42  * time with no knowldege of the command line options don't get error
43  * messages ;)
44  *
45  * NOTE: You will still need to have a bubbles_default.c file, else the
46  * build sequence will fail.  Well constructed bubbles_default.c files
47  * have #ifdef's which simply exclude everything else in the file at
48  * compile time.  The bubblestodefault script does this.
49  */
50
51 /* #define NO_DEFAULT_BUBBLE */
52
53 /*
54  * This turns on any debugging messages and sanity checks.  Hopefully you
55  * won't need this :)  It slows things down a bit, too.
56  *
57  * NOTE: If you uncomment this you will get some messages about unused
58  * functions when you compile.  You can ignore these - they refer to 
59  * convenient checking routines which simply aren't called but are left
60  * in case someone wants to use them.
61  */
62
63 /* #define DEBUG */
64
65 /***************************************************************************
66  *      Things you might need to change to get things working right        *
67  ***************************************************************************/
68
69 /*
70  *  Name of the gzip binary.  You shouldn't need to change this unless it's
71  * not in your PATH when the program is run, in which case you will need to
72  * substitute the full path here.  Keep the double quotes else things won't
73  * compile!
74  */
75
76 #define GZIP               "gzip"
77
78 /*
79  *  Likewise for the Bourne shell.
80  */
81
82 #define BOURNESH           "sh"
83
84 /*
85  * The name of the directory entry structure is different under Linux
86  * (under which this code is being developed) than other systems.  The case
87  * alternate form here is that given in Kernighan & Ritchie's C book (which
88  * must be authoratitive, no?) 
89  *
90  * 04/07/96 : People will have to hack this to get it working on some
91  * systems.  I believe it doesn't work on SGI, for example.
92  */
93
94 #ifdef _POSIX_SOURCE
95 #define STRUCT_DIRENT      struct dirent
96 #else
97 #define STRUCT_DIRENT      Dirent
98 #endif
99
100 /* 
101  * The naming of fields in struct dirent also seems to differ from system to
102  * system.  This may have to be extended to make things truly portable.
103  * What we want here is the name field from a dirent struct pointed to
104  * by "dp". 
105  *
106  * 04/07/96 : See above.  This may need to be changed too.
107  */
108
109 #ifdef _POSIX_SOURCE
110 #define DIRENT_NAME       dp->d_name
111 #else
112 #define DIRENT_NAME       dp->name
113 #endif
114
115 /* I don't know why this isn't defined. */
116 #ifdef linux
117 /* apparently it is defined in recent linuxes.  who knows. */
118 /*extern char *tempnam(char *, char *);*/
119 #endif
120
121 /****************************************************************************
122  *      Buffer lengths and things you probably won't need to touch          *
123  ****************************************************************************/
124
125 /* Maximum length of a full path name we can deal with */
126 #define PATH_BUF_SIZE      1024
127
128 /* Size of string passed to shell as command */
129 #define COMMAND_BUF_SIZE   2500
130
131 /* Size increments for read_line() buffers */
132 #define READ_LINE_BUF_SIZE 24
133
134 /* Maximum amount to drop a bubble */
135 #define MAX_DROPPAGE 20
136
137 /****************************************************************************
138  *                        End of options                                    *
139  ****************************************************************************/
140
141 /* Some machines define M_PI and not PI.  If they don't define either, use
142 own own.  Really, the accuracy of this is _not_ very important. */
143 #ifndef PI
144 # define PI  M_PI
145 # ifndef M_PI
146 #  define M_PI 3.1415926535
147 # endif
148 #endif
149
150 /* for delete_bubble_in_mesh() */
151 #define DELETE_BUBBLE      0
152 #define KEEP_BUBBLE        1
153
154 /* Status codes for read_line */
155 #define LINE_READ          0
156 #define EOF_REACHED        1
157 #define IO_ERROR           2
158
159 /* 
160  * Magic number for Bubble struct, in case it's trashed when debugging code
161  * (which happened to me often.... :(  
162  */
163
164 #define BUBBLE_MAGIC       5674
165
166 /* Useful macros */
167 #define MAX(A, B) ((A) > (B) ? (A) : (B))
168 #define MIN(A, B) ((A) < (B) ? (A) : (B))
169
170 /* How we represent bubbles */
171 struct bub {
172   int radius;
173   int step;  /* for rendered bubbles */
174   long area;
175   int x;
176   int y;
177   int magic;
178   int cell_index;
179   int visible;
180   struct bub *next;
181   struct bub *prev;
182 };
183
184 typedef struct bub Bubble;
185
186 /*
187  * How we represent pixmaps of rendered bubbles.  Because the range of radii
188  * available may not be continuous, we call each a step (for the lack of a
189  * better name...)
190  */
191
192 struct bub_step {
193   int radius;
194   long area;
195   int droppage;
196   Pixmap ball, shape_mask;
197   GC draw_gc, erase_gc;
198   struct bub_step *next;
199 };
200
201 typedef struct bub_step Bubble_Step;
202
203 extern void init_default_bubbles(void);
204 extern int num_default_bubbles;
205 typedef struct { const unsigned char *png; unsigned long size; } bubble_png;
206 extern bubble_png default_bubbles[];
207
208 #endif /* _BUBBLES_H_ */