ftp://ftp.uni-heidelberg.de/pub/X11/contrib/applications/xscreensaver-2.07.tar.gz
[xscreensaver] / hacks / xlockmore.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997 Jamie Zawinski <jwz@netscape.com>
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@netscape.com> 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 #endif
39
40 /* Accessor macros for the ModeInfo structure
41  */
42
43 #define MI_DISPLAY(MI)          ((MI)->dpy)
44 #define MI_WINDOW(MI)           ((MI)->window)
45 #define MI_NUM_SCREENS(MI)      (1)     /* Only manage one screen at a time; */
46 #define MI_SCREEN(MI)           (0)     /*  this might be fragile... */
47 #define MI_WIN_WHITE_PIXEL(MI)  ((MI)->white)
48 #define MI_WIN_BLACK_PIXEL(MI)  ((MI)->black)
49 #define MI_NPIXELS(MI)          ((MI)->npixels)
50 #define MI_PIXEL(MI,N)          ((MI)->pixels[(N)])
51 #define MI_WIN_WIDTH(MI)        ((MI)->xgwa.width)
52 #define MI_WIN_HEIGHT(MI)       ((MI)->xgwa.height)
53 #define MI_WIN_DEPTH(MI)        ((MI)->xgwa.depth)
54 #define MI_WIN_COLORMAP(MI)     ((MI)->xgwa.colormap)
55 #define MI_VISUAL(MI)           ((MI)->xgwa.visual)
56 #define MI_GC(MI)               ((MI)->gc)
57 #define MI_PAUSE(MI)            ((MI)->pause)
58 #define MI_WIN_IS_FULLRANDOM(MI)((MI)->fullrandom)
59 #define MI_WIN_IS_VERBOSE(MI)   (False)
60 #define MI_WIN_IS_INSTALL(MI)   (True)
61 #define MI_WIN_IS_MONO(MI)      (mono_p)
62 #define MI_WIN_IS_INROOT(MI)    ((MI)->root_p)
63 #define MI_WIN_IS_INWINDOW(MI)  (!(MI)->root_p)
64 #define MI_WIN_IS_ICONIC(MI)    (False)
65 #define MI_WIN_IS_WIREFRAME(MI) ((MI)->wireframe_p)
66 #define MI_WIN_IS_USE3D(MI)     ((MI)->threed)
67 #define MI_LEFT_COLOR(MI)       ((MI)->threed_left_color)
68 #define MI_RIGHT_COLOR(MI)      ((MI)->threed_right_color)
69 #define MI_BOTH_COLOR(MI)       ((MI)->threed_both_color)
70 #define MI_NONE_COLOR(MI)       ((MI)->threed_none_color)
71 #define MI_DELTA3D(MI)          ((MI)->threed_delta)
72 #define MI_CYCLES(MI)           ((MI)->cycles)
73 #define MI_BATCHCOUNT(MI)       ((MI)->batchcount)
74 #define MI_SIZE(MI)             ((MI)->size)
75
76 /* Some other utility macros.
77  */
78 #define SINF(n)                 ((float)sin((double)(n)))
79 #define COSF(n)                 ((float)cos((double)(n)))
80 #define FABSF(n)                ((float)fabs((double)(n)))
81
82 #undef MAX
83 #undef MIN
84 #undef ABS
85 #define MAX(a,b)((a)>(b)?(a):(b))
86 #define MIN(a,b)((a)<(b)?(a):(b))
87 #define ABS(a)((a)<0 ? -(a) : (a))
88
89 /* Maximum possible number of colors (*not* default number of colors.) */
90 #define NUMCOLORS 256
91
92 /* The globals that screenhack.c expects (initialized by xlockmore.c).
93  */
94 char *defaults[100];
95 XrmOptionDescRec options[100];
96
97 /* Prototypes for the actual drawing routines...
98  */
99 extern void HACK_INIT(ModeInfo *);
100 extern void HACK_DRAW(ModeInfo *);
101
102 #ifdef HACK_FREE
103   extern void HACK_FREE(ModeInfo *);
104 #else
105 # define HACK_FREE 0
106 #endif
107
108
109 /* Emit code for the entrypoint used by screenhack.c, and pass control
110    down into xlockmore.c with the appropriate parameters.
111  */
112
113 char *progclass = PROGCLASS;
114
115 void screenhack (Display *dpy, Window window)
116 {
117   xlockmore_screenhack (dpy, window,
118
119 #ifdef WRITABLE_COLORS
120                         True,
121 #else
122                         False,
123 #endif
124
125 #ifdef UNIFORM_COLORS
126                         True,
127 #else
128                         False,
129 #endif
130
131 #ifdef SMOOTH_COLORS
132                         True,
133 #else
134                         False,
135 #endif
136
137 #ifdef BRIGHT_COLORS
138                         True,
139 #else
140                         False,
141 #endif
142
143                         HACK_INIT,
144                         HACK_DRAW,
145                         HACK_FREE);
146 }
147
148
149 const char *app_defaults = DEFAULTS ;