http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.04.2.tar.gz
[xscreensaver] / hacks / xlockmore.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2002 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 #if !defined(PROGCLASS) || !defined(HACK_INIT) || !defined(HACK_DRAW)
20 ERROR!  Define PROGCLASS, HACK_INIT, and HACK_DRAW before including xlockmore.h
21 #endif
22
23 #include "config.h"
24
25 #ifndef __STDC__
26 ERROR!  Sorry, xlockmore.h requires ANSI C (gcc, for example.)
27   /* (The ansi dependency is that we use string concatenation,
28      and cpp-based stringification of tokens.) */
29 #endif
30
31 #include <stdio.h>
32 #include <math.h>
33 #include "xlockmoreI.h"
34
35 #ifdef USE_GL
36 # include <GL/glx.h>
37   extern GLXContext *init_GL (ModeInfo *);
38   extern void clear_gl_error (void);
39   extern void check_gl_error (const char *type);
40   extern void do_fps (ModeInfo *);
41 # define FreeAllGL(dpy) /* */
42 #endif /* !USE_GL */
43
44 /* Accessor macros for the ModeInfo structure
45  */
46
47 #define MI_DISPLAY(MI)          ((MI)->dpy)
48 #define MI_WINDOW(MI)           ((MI)->window)
49 #define MI_NUM_SCREENS(MI)      (1)     /* Only manage one screen at a time; */
50 #define MI_SCREEN(MI)           (0)     /*  this might be fragile... */
51 #define MI_WIN_WHITE_PIXEL(MI)  ((MI)->white)
52 #define MI_WIN_BLACK_PIXEL(MI)  ((MI)->black)
53 #define MI_NPIXELS(MI)          ((MI)->npixels)
54 #define MI_PIXEL(MI,N)          ((MI)->pixels[(N)])
55 #define MI_WIN_WIDTH(MI)        ((MI)->xgwa.width)
56 #define MI_WIN_HEIGHT(MI)       ((MI)->xgwa.height)
57 #define MI_WIN_DEPTH(MI)        ((MI)->xgwa.depth)
58 #define MI_WIN_COLORMAP(MI)     ((MI)->xgwa.colormap)
59 #define MI_VISUAL(MI)           ((MI)->xgwa.visual)
60 #define MI_GC(MI)               ((MI)->gc)
61 #define MI_PAUSE(MI)            ((MI)->pause)
62 #define MI_WIN_IS_FULLRANDOM(MI)((MI)->fullrandom)
63 #define MI_WIN_IS_VERBOSE(MI)   (False)
64 #define MI_WIN_IS_INSTALL(MI)   (True)
65 #define MI_WIN_IS_MONO(MI)      (mono_p)
66 #define MI_WIN_IS_INROOT(MI)    ((MI)->root_p)
67 #define MI_WIN_IS_INWINDOW(MI)  (!(MI)->root_p)
68 #define MI_WIN_IS_ICONIC(MI)    (False)
69 #define MI_WIN_IS_WIREFRAME(MI) ((MI)->wireframe_p)
70 #define MI_WIN_IS_USE3D(MI)     ((MI)->threed)
71 #define MI_LEFT_COLOR(MI)       ((MI)->threed_left_color)
72 #define MI_RIGHT_COLOR(MI)      ((MI)->threed_right_color)
73 #define MI_BOTH_COLOR(MI)       ((MI)->threed_both_color)
74 #define MI_NONE_COLOR(MI)       ((MI)->threed_none_color)
75 #define MI_DELTA3D(MI)          ((MI)->threed_delta)
76 #define MI_CYCLES(MI)           ((MI)->cycles)
77 #define MI_BATCHCOUNT(MI)       ((MI)->batchcount)
78 #define MI_SIZE(MI)             ((MI)->size)
79 #define MI_IS_DRAWN(MI)         ((MI)->is_drawn)
80 #define MI_IS_FPS(MI)           ((MI)->fps_p)
81 #define MI_NCOLORS(MI)          ((MI)->npixels)
82 #define MI_NAME(MI)             (progname)
83
84 #define MI_COLORMAP(MI)         (MI_WIN_COLORMAP((MI)))
85 #define MI_WIDTH(MI)            (MI_WIN_WIDTH((MI)))
86 #define MI_HEIGHT(MI)           (MI_WIN_HEIGHT((MI)))
87 #define MI_IS_ICONIC(MI)        (MI_WIN_IS_ICONIC((MI)))
88 #define MI_IS_WIREFRAME(MI)     (MI_WIN_IS_WIREFRAME((MI)))
89 #define MI_IS_MONO(MI)          (MI_WIN_IS_MONO((MI)))
90 #define MI_COUNT(MI)            (MI_BATCHCOUNT((MI)))
91 #define MI_BLACK_PIXEL(MI)      (MI_WIN_BLACK_PIXEL(MI))
92 #define MI_WHITE_PIXEL(MI)      (MI_WIN_WHITE_PIXEL(MI))
93 #define MI_IS_FULLRANDOM(MI)    (MI_WIN_IS_FULLRANDOM(MI))
94 #define MI_IS_VERBOSE(MI)       (MI_WIN_IS_VERBOSE(MI))
95 #define MI_IS_INSTALL(MI)       (MI_WIN_IS_INSTALL(MI))
96 #define MI_IS_DEBUG(MI)         (False)
97 #define MI_IS_MOUSE(MI)         (False)
98
99 #define MI_CLEARWINDOW(mi) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi))
100
101 /* Some other utility macros.
102  */
103 #define SINF(n)                 ((float)sin((double)(n)))
104 #define COSF(n)                 ((float)cos((double)(n)))
105 #define FABSF(n)                ((float)fabs((double)(n)))
106
107 #undef MAX
108 #undef MIN
109 #undef ABS
110 #define MAX(a,b)((a)>(b)?(a):(b))
111 #define MIN(a,b)((a)<(b)?(a):(b))
112 #define ABS(a)((a)<0 ? -(a) : (a))
113
114 /* Maximum possible number of colors (*not* default number of colors.) */
115 #define NUMCOLORS 256
116
117 /* The globals that screenhack.c expects (initialized by xlockmore.c).
118  */
119 char *defaults[100];
120 XrmOptionDescRec options[100];
121
122 /* Prototypes for the actual drawing routines...
123  */
124 extern void HACK_INIT(ModeInfo *);
125 extern void HACK_DRAW(ModeInfo *);
126
127 #ifdef HACK_FREE
128   extern void HACK_FREE(ModeInfo *);
129 #else
130 # define HACK_FREE 0
131 #endif
132
133 #ifdef HACK_RESHAPE
134   extern void HACK_RESHAPE(ModeInfo *, int width, int height);
135 #else
136 # define HACK_RESHAPE 0
137 #endif
138
139 #ifdef HACK_HANDLE_EVENT
140   extern Bool HACK_HANDLE_EVENT(ModeInfo *, XEvent *e);
141 #else
142 # define HACK_HANDLE_EVENT 0
143 #endif
144
145
146 /* Emit code for the entrypoint used by screenhack.c, and pass control
147    down into xlockmore.c with the appropriate parameters.
148  */
149
150 char *progclass = PROGCLASS;
151
152 void screenhack (Display *dpy, Window window)
153 {
154   xlockmore_screenhack (dpy, window,
155
156 #ifdef WRITABLE_COLORS
157                         True,
158 #else
159                         False,
160 #endif
161
162 #ifdef UNIFORM_COLORS
163                         True,
164 #else
165                         False,
166 #endif
167
168 #ifdef SMOOTH_COLORS
169                         True,
170 #else
171                         False,
172 #endif
173
174 #ifdef BRIGHT_COLORS
175                         True,
176 #else
177                         False,
178 #endif
179
180 #ifdef EVENT_MASK
181                         EVENT_MASK,
182 #else
183                         0,
184 #endif
185
186                         HACK_INIT,
187                         HACK_DRAW,
188                         HACK_RESHAPE,
189                         HACK_HANDLE_EVENT,
190                         HACK_FREE);
191 }
192
193
194 const char *app_defaults = DEFAULTS ;