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