From http://www.jwz.org/xscreensaver/xscreensaver-5.15.tar.gz
[xscreensaver] / hacks / xlockmore.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2011 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  *
12  * The definitions in this file make it possible to compile an xlockmore
13  * module into a standalone program, and thus use it with xscreensaver.
14  * By Jamie Zawinski <jwz@jwz.org> on 10-May-97; based on the ideas
15  * in the older xlock.h by Charles Hannum <mycroft@ai.mit.edu>.  (I had
16  * to redo it, since xlockmore has diverged so far from xlock...)
17  */
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif /* HAVE_CONFIG_H */
22
23 #ifndef __STDC__
24 ERROR!  Sorry, xlockmore.h requires ANSI C (gcc, for example.)
25   /* (The ansi dependency is that we use string concatenation,
26      and cpp-based stringification of tokens.) */
27 #endif
28
29 #include "screenhackI.h"
30 #include "xlockmoreI.h"
31
32 #ifdef USE_GL
33
34 # ifdef HAVE_COCOA
35 #  include <OpenGL/gl.h>
36 #  include <OpenGL/glu.h>
37 # else  /* !HAVE_COCOA -- real Xlib */
38 #  include <GL/glx.h>
39 #  include <GL/glu.h>
40 # endif /* !HAVE_COCOA */
41
42 # define FreeAllGL(dpy) /* */
43 #endif /* USE_GL */
44
45 # define ENTRYPOINT static
46
47 /* Accessor macros for the ModeInfo structure
48  */
49 #define MI_DISPLAY(MI)          ((MI)->dpy)
50 #define MI_WINDOW(MI)           ((MI)->window)
51 #define MI_NUM_SCREENS(MI)      ((MI)->num_screens)
52 #define MI_SCREEN(MI)           ((MI)->screen_number)
53 #define MI_WIN_WHITE_PIXEL(MI)  ((MI)->white)
54 #define MI_WIN_BLACK_PIXEL(MI)  ((MI)->black)
55 #define MI_NPIXELS(MI)          ((MI)->npixels)
56 #define MI_PIXEL(MI,N)          ((MI)->pixels[(N)])
57 #define MI_WIN_WIDTH(MI)        ((MI)->xgwa.width)
58 #define MI_WIN_HEIGHT(MI)       ((MI)->xgwa.height)
59 #define MI_WIN_DEPTH(MI)        ((MI)->xgwa.depth)
60 #define MI_DEPTH(MI)            ((MI)->xgwa.depth)
61 #define MI_WIN_COLORMAP(MI)     ((MI)->xgwa.colormap)
62 #define MI_VISUAL(MI)           ((MI)->xgwa.visual)
63 #define MI_GC(MI)               ((MI)->gc)
64 #define MI_PAUSE(MI)            ((MI)->pause)
65 #define MI_DELAY(MI)            ((MI)->pause)
66 #define MI_WIN_IS_FULLRANDOM(MI)((MI)->fullrandom)
67 #define MI_WIN_IS_VERBOSE(MI)   (False)
68 #define MI_WIN_IS_INSTALL(MI)   (True)
69 #define MI_WIN_IS_MONO(MI)      (mono_p)
70 #define MI_WIN_IS_INROOT(MI)    ((MI)->root_p)
71 #define MI_WIN_IS_INWINDOW(MI)  (!(MI)->root_p)
72 #define MI_WIN_IS_ICONIC(MI)    (False)
73 #define MI_WIN_IS_WIREFRAME(MI) ((MI)->wireframe_p)
74 #define MI_WIN_IS_USE3D(MI)     ((MI)->threed)
75 #define MI_LEFT_COLOR(MI)       ((MI)->threed_left_color)
76 #define MI_RIGHT_COLOR(MI)      ((MI)->threed_right_color)
77 #define MI_BOTH_COLOR(MI)       ((MI)->threed_both_color)
78 #define MI_NONE_COLOR(MI)       ((MI)->threed_none_color)
79 #define MI_DELTA3D(MI)          ((MI)->threed_delta)
80 #define MI_CYCLES(MI)           ((MI)->cycles)
81 #define MI_BATCHCOUNT(MI)       ((MI)->batchcount)
82 #define MI_SIZE(MI)             ((MI)->size)
83 #define MI_IS_DRAWN(MI)         ((MI)->is_drawn)
84 #define MI_IS_FPS(MI)           ((MI)->fps_p)
85 #define MI_NCOLORS(MI)          ((MI)->npixels)
86 #define MI_NAME(MI)             (progname)
87
88 #define MI_COLORMAP(MI)         (MI_WIN_COLORMAP((MI)))
89 #define MI_WIDTH(MI)            (MI_WIN_WIDTH((MI)))
90 #define MI_HEIGHT(MI)           (MI_WIN_HEIGHT((MI)))
91 #define MI_IS_ICONIC(MI)        (MI_WIN_IS_ICONIC((MI)))
92 #define MI_IS_WIREFRAME(MI)     (MI_WIN_IS_WIREFRAME((MI)))
93 #define MI_IS_MONO(MI)          (MI_WIN_IS_MONO((MI)))
94 #define MI_COUNT(MI)            (MI_BATCHCOUNT((MI)))
95 #define MI_BLACK_PIXEL(MI)      (MI_WIN_BLACK_PIXEL(MI))
96 #define MI_WHITE_PIXEL(MI)      (MI_WIN_WHITE_PIXEL(MI))
97 #define MI_IS_FULLRANDOM(MI)    (MI_WIN_IS_FULLRANDOM(MI))
98 #define MI_IS_VERBOSE(MI)       (MI_WIN_IS_VERBOSE(MI))
99 #define MI_IS_INSTALL(MI)       (MI_WIN_IS_INSTALL(MI))
100 #define MI_IS_DEBUG(MI)         (False)
101 #define MI_IS_MOUSE(MI)         (False)
102
103 #define MI_CLEARWINDOW(mi) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi))
104
105 /* Some other utility macros.
106  */
107 #define SINF(n)                 ((float)sin((double)(n)))
108 #define COSF(n)                 ((float)cos((double)(n)))
109 #define FABSF(n)                ((float)fabs((double)(n)))
110
111 #undef MAX
112 #undef MIN
113 #undef ABS
114 #define MAX(a,b)((a)>(b)?(a):(b))
115 #define MIN(a,b)((a)<(b)?(a):(b))
116 #define ABS(a)((a)<0 ? -(a) : (a))
117
118 /* Maximum possible number of colors (*not* default number of colors.) */
119 #define NUMCOLORS 256
120
121
122 /* In an Xlib world, we define two global symbols here:
123    a struct in `MODULENAME_xscreensaver_function_table',
124    and a pointer to that in `xscreensaver_function_table'.
125
126    In a Cocoa world, we only define the prefixed symbol;
127    the un-prefixed symbol does not exist.
128  */
129 #ifdef HAVE_COCOA
130 # define XSCREENSAVER_LINK(NAME)
131 #else
132 # define XSCREENSAVER_LINK(NAME) \
133    struct xscreensaver_function_table *xscreensaver_function_table = &NAME;
134 #endif
135
136
137 # if !defined(USE_GL) || defined(HAVE_COCOA)
138 #  define xlockmore_pick_gl_visual 0
139 #  define xlockmore_validate_gl_visual 0
140 # endif  /* !USE_GL || HAVE_COCOA */
141
142 # ifdef USE_GL
143 #  define XLOCKMORE_FPS xlockmore_gl_compute_fps
144 # else
145 #  define XLOCKMORE_FPS xlockmore_do_fps
146 # endif
147
148 #ifdef WRITABLE_COLORS
149 # undef WRITABLE_COLORS
150 # define WRITABLE_COLORS 1
151 #else
152 # define WRITABLE_COLORS 0
153 #endif
154
155 #if defined(UNIFORM_COLORS)
156 # define XLOCKMORE_COLOR_SCHEME color_scheme_uniform
157 #elif defined(SMOOTH_COLORS)
158 # define XLOCKMORE_COLOR_SCHEME color_scheme_smooth
159 #elif defined(BRIGHT_COLORS)
160 # define XLOCKMORE_COLOR_SCHEME color_scheme_bright
161 #else
162 # define XLOCKMORE_COLOR_SCHEME color_scheme_default
163 #endif
164
165 /* This is the macro that links this program in with the rest of
166    xscreensaver.  For example:
167
168      XSCREENSAVER_MODULE   ("Atlantis", atlantis)
169      XSCREENSAVER_MODULE_2 ("GLMatrix", glmatrix, matrix)
170
171    CLASS:   a string, the class name for resources.
172    NAME:    a token, the name of the executable.  Should be the same
173             as CLASS, but downcased.
174    PREFIX:  the symbol used in the function names, e.g., `draw_atlantis'.
175
176    NAME and PREFIX are usually the same.  If they are not, use
177    XSCREENSAVER_MODULE_2() instead of XSCREENSAVER_MODULE().
178  */
179 #define XSCREENSAVER_MODULE_2(CLASS,NAME,PREFIX)                        \
180                                                                         \
181   static struct xlockmore_function_table                                \
182          NAME ## _xlockmore_function_table = {                  \
183            CLASS,                                                       \
184            DEFAULTS,                                                    \
185            WRITABLE_COLORS,                                             \
186            XLOCKMORE_COLOR_SCHEME,                                      \
187            init_    ## PREFIX,                                          \
188            draw_    ## PREFIX,                                          \
189            reshape_ ## PREFIX,                                          \
190            refresh_ ## PREFIX,                                          \
191            release_ ## PREFIX,                                          \
192            PREFIX   ## _handle_event,                                   \
193            & PREFIX ## _opts                                            \
194   };                                                                    \
195                                                                         \
196   struct xscreensaver_function_table                                    \
197          NAME ## _xscreensaver_function_table = {                       \
198            0, 0, 0,                                                     \
199            xlockmore_setup,                                             \
200            & NAME ## _xlockmore_function_table,                         \
201            0, 0, 0, 0, 0,                                               \
202            XLOCKMORE_FPS,                                               \
203            xlockmore_pick_gl_visual,                                    \
204            xlockmore_validate_gl_visual };                              \
205                                                                         \
206   XSCREENSAVER_LINK (NAME ## _xscreensaver_function_table)
207
208 #define XSCREENSAVER_MODULE(CLASS,PREFIX)                               \
209       XSCREENSAVER_MODULE_2(CLASS,PREFIX,PREFIX)