home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-22 | 69.5 KB | 2,178 lines |
- Newsgroups: alt.sources
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!opusc!usceast!patterso
- From: patterso@cs.scarolina.edu (Mitchell Patterson)
- Subject: xmas -- Christmas tree for X
- Message-ID: <patterso.724718909@sycamore.cs.scarolina.edu>
- Summary: Christmas display hack
- Keywords: xmas X tree Kibo
- Sender: usenet@usceast.cs.scarolina.edu (USENET News System)
- Organization: USC Department of Computer Science
- Distribution: usa
- Date: 18 Dec 92 22:48:29 GMT
- Lines: 2164
-
- This here's a little X program I've written so I can have a virtual
- Christmas. It works with xsaver or standalone. There's an imake plus
- a regular Makefile, man pages, the works.
-
- MLP
- o / snip snip
- -----x--------------------------------------------------------------
- o \
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README
- # Imakefile
- # Makefile.noimake
- # screenhack.h
- # vroot.h
- # xmas.h
- # screenhack.c
- # resources.c
- # usleep.c
- # xmas.c
- # pt_in_tri.c
- # candy.c
- # gift.c
- # snow.c
- # ornament.c
- # color.c
- # xmas.man
- # This archive created: Fri Dec 18 17:43:40 1992
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'README'" '(2913 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'README'
- XHowdy.
- X
- XAnd so this is xmas, an X display hack that draws a Christmas tree on the
- Xroot window or in a window of its own.
- X
- XIf you're using a Sun, how 'bout take a look at the note on SunOS's
- XXmu library. It's at the bottom of this file in the Notes section.
- X
- XHow To Build It:
- X----------------
- XIf you have imake, type
- X xmkmf
- X make
- Xand that should do it. (Chyeah, right, Garth.)
- X
- XIf you don't have imake, edit Makefile.noimake to change whatever config
- Xstuff is necessary and then type
- X make -f Makefile.noimake
- Xand that should do it.
- X
- XInstallation:
- X-------------
- XIf you have imake, type
- X make man
- X make install BINDIR="<wherever xmas should go>"
- X make install.man MANDIR="<wherever the man page should go>"
- X
- XIf you don't have imake, type
- X make -f Makefile.noimake man
- X make -f Makefile.noimake install\
- X BINDIR="wherever xmas should go" MANDIR="wherever manpage goes"
- X
- XFor example, if you wanted xmas to go /usr/local/xmas and its man page to
- Xgo to /usr/local/man/man1, you'd type
- X make install BINDIR="/usr/local/xmas" MANDIR="/usr/local/man/man1"
- X
- XRunning Xmas:
- X-------------
- XIf you don't want to RTM, and I don't blame you, type
- X xmas -help
- Xfor a usage message that explains the options and gives you an
- Xexample invocation of the program. You'll also see the message if you
- Xgive an invalid option. In that case, xmas also whines about the bad
- Xoption(s).
- X
- XNotes:
- X------
- X* Type "make -f Makefile.noimake doc" for a man page with all the nroff
- X control stuff removed.
- X
- X* This thing has been tested on Sun SPARC2's, DECstations, IBM RS/6000's,
- X and NCD monochrome X terminals. It seems to work on all of them. I've
- X tried SunOS cc, AIX cc, and gcc on the Sun.
- X
- X* The code is kind of ugly, but I wanted to post it before Christmas. The
- X next version will be cleaner.
- X
- X* xmas works just fine with xscreensaver. That's a cool program to get,
- X if you don't already have it. And if you want to write little display
- X hacks like this one, you can't beat screenhack, which comes with
- X xscreensaver. It's at export.lcs.mit.edu, I think.
- X
- X* If you use imake on a Sun, and you get the following error message from
- X the loader:
- X "ld: Undefined symbol
- X _get_wmShellWidgetClass
- X _get_applicationShellWidgetClass,"
- X you have two choices. One is to ignore the message; xmas works fine
- X even if make says it failed. The other is to edit the Makefile produced
- X by imake. Find the line that says "EXTRA_LIBRARIES" and change it from
- X EXTRA_LIBRARIES = -lXmu -lXext -lXt -lX11 -lm
- X to
- X EXTRA_LIBRARIES = -Bstatic -lXmu -Bdynamic -lXext -lXt -lX11 -lm
- X There's a problem with the Xmu library as a shared object on Suns;
- X the -B's tell SunOS ld to link with the static Xmu library and use
- X the default shared libraries for everything else. Makefile.noimake
- X takes care of this problem for you.
- X
- XMerry Christmas, everybody.
- X
- XMitch Patterson
- Xmpatters@cs.scarolina.edu
- SHAR_EOF
- if test 2913 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 2913 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Imakefile'" '(335 characters)'
- if test -f 'Imakefile'
- then
- echo shar: will not over-write existing file "'Imakefile'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Imakefile'
- X#
- X# Imakefile for xmas. Don't ask me what any of this stuff does.
- X#
- XEXTRA_LIBRARIES = -lXmu -lXext -lXt -lX11 -lm
- XSRCS = screenhack.c\
- X resources.c\
- X usleep.c\
- X xmas.c\
- X pt_in_tri.c\
- X candy.c\
- X gift.c\
- X color.c\
- X snow.c\
- X ornament.c
- XOBJS = $(SRCS:.c=.o)
- XComplexProgramTarget(xmas)
- SHAR_EOF
- if test 335 -ne "`wc -c < 'Imakefile'`"
- then
- echo shar: error transmitting "'Imakefile'" '(should have been 335 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'Makefile.noimake'" '(3473 characters)'
- if test -f 'Makefile.noimake'
- then
- echo shar: will not over-write existing file "'Makefile.noimake'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'Makefile.noimake'
- X# If you don't have imake, this should do the trick.
- X#
- X# Makefile for xmas and every other X program I write. Only the
- X# names change.
- X#
- X# Type "make" to make the program.
- X# Type "make install" to put it where it needs to go.
- X# Type "make doc" to create a text-only man page.
- X# Type "make man" to create an nroff-formatted man page.
- X# Type "make clean" to remove the executable, the object files, and any
- X# core dump that might be laying around.
- X#
- X#---------------------------------------------------------------------------
- X# Configuration stuff:
- X#---------------------------------------------------------------------------
- X#
- X# Where this thing should go.
- X#
- XBINDIR = /usr/local/xmas
- X#
- X# Where man pages should go.
- X#
- XMANDIR = /usr/local/xmas
- X#
- X# Where the include files live, if they're someplace weird.
- X#
- XINCL =
- X#
- X# Where the libraries live, if they aren't in the usual places. On
- X# Suns you'll probably want to leave the directive for /usr/lib/X11;
- X# that way you don't have to worry about defining LD_LIBRARY_PATH in
- X# your environment.
- X#
- XLIBDIRS = -L/usr/local/lib -L/usr/lib/X11
- X#
- X# Preprocessor and compiler flags. On Ultrix machines, use the CFLAGS
- X# definition that incorporates CPPFLAGS.
- X# The _NO_PROTO is for non-ANSI compilers, like SunOS cc.
- X#
- XCPPFLAGS = $(INCL) -D_NO_PROTO
- X#CPPFLAGS = $(INCL)
- XCFLAGS = -g
- X#CFLAGS = -g $(CPPFLAGS)
- X#
- X# Which libraries to use and where they live. If you're not on a Sun,
- X# the second definition should work just fine.
- X#
- X# SunOS Xmu is screwed, so I link it statically.
- X#
- XLIBS = $(LIBDIRS) -Bstatic -lXmu -Bdynamic -lXext -lXt -lX11 -lm
- X#LIBS = $(LIBDIRS) -lXmu -lXext -lXt -lX11 -lm
- X#
- X# Flags to the loader. You probably won't have to mess with this one.
- X#
- XLDFLAGS = $(LIBS)
- X#
- X#---------------------------------------------------------------------------
- X# Nothing below this point should have to change.
- X#---------------------------------------------------------------------------
- X#
- X# Our application & its constituents.
- X#
- XAPP = xmas
- XOBJS = screenhack.o\
- X resources.o\
- X usleep.o\
- X xmas.o\
- X pt_in_tri.o\
- X candy.o\
- X gift.o\
- X snow.o\
- X ornament.o\
- X color.o
- XHEADERS = screenhack.h\
- X vroot.h\
- X xmas.h
- XDOCSRC = xmas.man
- XDOCTXT = xmas.doc
- XMANPAGE = xmas.1
- X#
- X# Application target.
- X#
- Xcompile:
- X -mv Makefile Makefile.bak
- X cp Makefile.noimake Makefile
- X make $(APP)
- X
- X$(APP): $(OBJS)
- X $(CC) -o $@ $(OBJS) $(LDFLAGS)
- X
- X$(OBJS): $(HEADERS)
- X#
- X# Installation
- X#
- Xinstall: $(APP) $(MANPAGE)
- X cp $(APP) $(BINDIR)
- X chmod 755 $(BINDIR)/$(APP)
- X cp $(MANPAGE) $(MANDIR)
- X#
- X# Archive this baby.
- X#
- Xshar:
- X shar -a README Imakefile Makefile.noimake\
- X $(HEADERS) $(OBJS:.o=.c)\
- X $(DOCSRC) > xmas.shar
- X#
- X# Make docs.
- X#
- X$(DOCTXT) doc: $(DOCSRC)
- X nroff -man < $(DOCSRC) | sed 's/.//g' > $(DOCTXT)
- X#
- X# Make man page
- X#
- X$(MANPAGE) man: $(DOCSRC)
- X nroff -man < $(DOCSRC) > $(MANPAGE)
- X#
- X# Cleanup target.
- X#
- Xclean:
- X rm -f $(APP) $(OBJS) $(DOCTXT) $(MANPAGE) Makefile Makefile.bak core
- X#
- X# The Anal-Retentive Parser
- X#
- Xlint:
- X @for i in $(OBJS:.o=.c);\
- X do\
- X echo "*** Linting $$i ***" ;\
- X $(LINT) $(CPPFLAGS) $$i;\
- X done
- X#
- X# backups
- X#
- Xback bak backups:
- X @if [ ! -d BACKUPS ];\
- X then\
- X echo "ERROR: No directory named BACKUPS.";\
- X elif [ ! -w BACKUPS ];\
- X then\
- X echo "ERROR: BACKUPS is not writeable";\
- X else\
- X make real-backups;\
- X fi
- X
- Xreal-backups:
- X -cp $(OBJS:.o=.c) $(HEADERS) $(DOCSRC)\
- X README Imakefile Makefile.noimake\
- X BACKUPS
- SHAR_EOF
- echo shar: 1 control character may be missing from "'Makefile.noimake'"
- if test 3473 -ne "`wc -c < 'Makefile.noimake'`"
- then
- echo shar: error transmitting "'Makefile.noimake'" '(should have been 3473 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'screenhack.h'" '(1182 characters)'
- if test -f 'screenhack.h'
- then
- echo shar: will not over-write existing file "'screenhack.h'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'screenhack.h'
- X#ifndef _SCREENHACK_H_
- X#define _SCREENHACK_H_
- X
- X#include <X11/Xlib.h>
- X#include <X11/Xresource.h>
- X#include <X11/Xos.h>
- X#include "vroot.h"
- X
- Xextern Bool mono_p;
- Xextern char *progname;
- Xextern char *progclass;
- Xextern XrmDatabase db;
- Xextern XrmOptionDescRec options [];
- Xextern int options_size;
- Xextern char *defaults [];
- X
- X#if __STDC__
- X# define P(x)x
- X#else
- X# define P(x)()
- X#endif
- X
- Xextern void screenhack P((Display*,Window));
- X
- X#define usleep screenhack_usleep
- X
- Xextern void screenhack_usleep P((unsigned long));
- Xextern char *get_string_resource P((char*,char*));
- Xextern Bool get_boolean_resource P((char*,char*));
- Xextern int get_integer_resource P((char*,char*));
- Xextern unsigned int get_pixel_resource P((char*,char*,Display*,Colormap));
- X
- Xvoid hsv_to_rgb P((int,double,double,unsigned short*,
- X unsigned short*,unsigned short*));
- Xvoid rgb_to_hsv P((unsigned short,unsigned short,unsigned short,
- X int*,double*,double*));
- Xvoid cycle_hue P((XColor*,int));
- X
- Xstatic double _frand_tmp_;
- X#define frand(f) \
- X (_frand_tmp_ = (((double) random()) / \
- X (((unsigned int)~0) / ((double) (f+f)))), \
- X _frand_tmp_ < 0 ? -_frand_tmp_ : _frand_tmp_)
- X
- X#undef P
- X#endif /* _SCREENHACK_H_ */
- SHAR_EOF
- if test 1182 -ne "`wc -c < 'screenhack.h'`"
- then
- echo shar: error transmitting "'screenhack.h'" '(should have been 1182 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'vroot.h'" '(5068 characters)'
- if test -f 'vroot.h'
- then
- echo shar: will not over-write existing file "'vroot.h'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'vroot.h'
- X/*****************************************************************************/
- X/** Copyright 1991 by Andreas Stolcke **/
- X/** Copyright 1990 by Solbourne Computer Inc. **/
- X/** Longmont, Colorado **/
- X/** **/
- X/** All Rights Reserved **/
- X/** **/
- X/** Permission to use, copy, modify, and distribute this software and **/
- X/** its documentation for any purpose and without fee is hereby **/
- X/** granted, provided that the above copyright notice appear in all **/
- X/** copies and that both that copyright notice and this permis- **/
- X/** sion notice appear in supporting documentation, and that the **/
- X/** name of Solbourne not be used in advertising **/
- X/** in publicity pertaining to distribution of the software without **/
- X/** specific, written prior permission. **/
- X/** **/
- X/** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
- X/** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/
- X/** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/
- X/** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/
- X/** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
- X/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
- X/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
- X/** OR PERFORMANCE OF THIS SOFTWARE. **/
- X/*****************************************************************************/
- X/*
- X * vroot.h -- Virtual Root Window handling header file
- X *
- X * This header file redefines the X11 macros RootWindow and DefaultRootWindow,
- X * making them look for a virtual root window as provided by certain `virtual'
- X * window managers like swm and tvtwm. If none is found, the ordinary root
- X * window is returned, thus retaining backward compatibility with standard
- X * window managers.
- X * The function implementing the virtual root lookup remembers the result of
- X * its last invocation to avoid overhead in the case of repeated calls
- X * on the same display and screen arguments.
- X * The lookup code itself is taken from Tom LaStrange's ssetroot program.
- X *
- X * Most simple root window changing X programs can be converted to using
- X * virtual roots by just including
- X *
- X * #include <X11/vroot.h>
- X *
- X * after all the X11 header files. It has been tested on such popular
- X * X clients as xphoon, xfroot, xloadimage, and xaqua.
- X * It also works with the core clients xprop, xwininfo, xwd, and editres
- X * (and is necessary to get those clients working under tvtwm).
- X * It does NOT work with xsetroot; get the xsetroot replacement included in
- X * the tvtwm distribution instead.
- X *
- X * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
- X * - replaced all NULL's with properly cast 0's, 5/6/91
- X * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
- X * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
- X */
- X
- X#ifndef _VROOT_H_
- X#define _VROOT_H_
- X
- X#if !defined(lint) && !defined(SABER)
- Xstatic char vroot_rcsid[] = "$Id: vroot.h,v 1.4 1991/09/30 19:23:16 stolcke Exp stolcke $";
- X#endif
- X
- X#include <X11/X.h>
- X#include <X11/Xatom.h>
- X#include <X11/Xlib.h>
- X
- Xstatic Window
- XVirtualRootWindowOfScreen(screen)
- X Screen *screen;
- X{
- X static Screen *save_screen = (Screen *)0;
- X static Window root = (Window)0;
- X
- X if (screen != save_screen) {
- X Display *dpy = DisplayOfScreen(screen);
- X Atom __SWM_VROOT = None;
- X int i;
- X Window rootReturn, parentReturn, *children;
- X unsigned int numChildren;
- X
- X root = RootWindowOfScreen(screen);
- X
- X /* go look for a virtual root */
- X __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
- X if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
- X &children, &numChildren)) {
- X for (i = 0; i < numChildren; i++) {
- X Atom actual_type;
- X int actual_format;
- X unsigned long nitems, bytesafter;
- X Window *newRoot = (Window *)0;
- X
- X if (XGetWindowProperty(dpy, children[i],
- X __SWM_VROOT, 0, 1, False, XA_WINDOW,
- X &actual_type, &actual_format,
- X &nitems, &bytesafter,
- X (unsigned char **) &newRoot) == Success
- X && newRoot) {
- X root = *newRoot;
- X break;
- X }
- X }
- X if (children)
- X XFree((char *)children);
- X }
- X
- X save_screen = screen;
- X }
- X
- X return root;
- X}
- X
- X#undef RootWindowOfScreen
- X#define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
- X
- X#undef RootWindow
- X#define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
- X
- X#undef DefaultRootWindow
- X#define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
- X
- X#endif /* _VROOT_H_ */
- SHAR_EOF
- if test 5068 -ne "`wc -c < 'vroot.h'`"
- then
- echo shar: error transmitting "'vroot.h'" '(should have been 5068 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xmas.h'" '(3993 characters)'
- if test -f 'xmas.h'
- then
- echo shar: will not over-write existing file "'xmas.h'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'xmas.h'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X/*
- X** Which release are we?
- X*/
- X#define RELEASE "1.6"
- X
- X/*
- X** Convert degrees to radians for the C trig functions.
- X*/
- X#define DEG2RAD(x) ((x) * M_PI / 180.0)
- X
- X/*
- X** XDrawArc() divides a degree into 64 clicks. This draws a half-circle,
- X** which is what I use for the top of a candycane.
- X*/
- X#define HALF_CIRCLE (180 * 64)
- X
- X/*
- X** We have 400 lights.
- X*/
- X#define NUM_LIGHTS 400
- X
- X/*
- X** Size of our lights. 1-dot lights are a little too small.
- X*/
- X#define LIGHT_HEIGHT 2
- X#define LIGHT_WIDTH 2
- X
- X/*
- X** This is the length of the arms of the star at the top of the tree.
- X*/
- X#define STAR_ARM_LENGTH 5
- X
- X/*
- X** Percentage of the window that serves as the top and bottom margin.
- X*/
- X#define MARGIN 10
- X
- X/*
- X** Default values for the usage message.
- X*/
- X#define DEF_BG "black" /* default background color */
- X#define DEF_STARCOLOR "yellow" /* default star color */
- X#define DEF_STARBLINKS "it doesn't" /* used in usage message */
- X#define DEF_DELAY 1500 /* default cycle time */
- X#define DEF_SEED 131 /* default seed for randoms */
- X#define DEF_GIFTLABEL "no gift" /* used in usage message */
- X#define DEF_GIFTCOLOR "blue" /* default color of gift */
- X#define DEF_GIFTLABELCOLOR "white" /* default color for tag text */
- X#define DEF_NUM_CANDYCANES 0 /* default number of candy canes */
- X#define DEF_CANDY_LENGTH 30 /* length of candy cane */
- X#define DEF_CANDY_WIDTH 10 /* width of candy cane */
- X#define DEF_CANDY_HEIGHT 10 /* height of candy cane */
- X#define DEF_SNOW "no snow" /* used in usage message */
- X#define NUM_SNOWFLAKES 1000 /* number of snowflakes */
- X#define DEF_NUM_ORNAMENTS 0 /* default number of ornaments */
- X#define DEF_BACKING_STORE "True" /* default flag for backing store */
- X
- X/*
- X** Macros for access into the color table.
- X*/
- X#define BACKGROUND 0
- X#define STARCOLOR 1
- X#define BOXCOLOR 2
- X#define TEXTCOLOR 3
- X#define WHITE 4
- X#define RED (WHITE + 1)
- X#define GREEN (WHITE + 2)
- X#define ORANGE (WHITE + 3)
- X#define YELLOW (WHITE + 4)
- X
- X#define NUM_COLORS 9
- X
- X/*
- X** We want to exclude a few of the colors from the choices for
- X** Christmas lights; these make the exclusion changeproof.
- X*/
- X#define FIRST_LIGHT WHITE /* lowest valid light color */
- X#define LAST_LIGHT YELLOW /* highest valid light color */
- X
- X/*
- X** How far does snow travel in a single fall cycle?
- X*/
- X#define MAX_SNOWFALL_RATE 100
- X
- X/*
- X** Time in microseconds for a single snowfall cycle.
- X*/
- X#define SNOWFALL_TIME 200000
- X
- X/*
- X** Snow starts above the window.
- X*/
- X#define SNOW_START (-1)
- X
- X/*
- X** It takes too long to make all the snowflakes fall every cycle, so
- X** now flakes have a 1 in 5 chance of dropping.
- X*/
- X#define SNOWFLAKES_CHANCE 5
- X
- X/*
- X** I let snowdrifts get higher if a column is within this tolerance of the
- X** height of its neighbors.
- X*/
- X#define SNOWFALL_TOLERANCE 2
- X
- X/*
- X** The bitmaps I use for ornaments are 16 by 16.
- X*/
- X#define BITMAP_WIDTH 16
- X#define BITMAP_HEIGHT 16
- X
- X/*
- X** SunOS doesn't have a header for these.
- X*/
- Xvoid srand48();
- Xlong lrand48();
- Xdouble drand48();
- X
- X/*
- X** Functions defined in the xmas code.
- X*/
- Xvoid pt_in_triangle();
- Xvoid draw_candy();
- Xvoid draw_gift();
- Xvoid snow_init();
- Xvoid draw_snow();
- Xvoid draw_ornaments();
- Xvoid color_init();
- Xunsigned long get_color();
- SHAR_EOF
- if test 3993 -ne "`wc -c < 'xmas.h'`"
- then
- echo shar: error transmitting "'xmas.h'" '(should have been 3993 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'screenhack.c'" '(4496 characters)'
- if test -f 'screenhack.c'
- then
- echo shar: will not over-write existing file "'screenhack.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'screenhack.c'
- X/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
- X *
- X * Permission to use, copy, modify, distribute, and sell this software and its
- X * documentation for any purpose is hereby granted without fee, provided that
- X * the above copyright notice appear in all copies and that both that
- X * copyright notice and this permission notice appear in supporting
- X * documentation. No representations are made about the suitability of this
- X * software for any purpose. It is provided "as is" without express or
- X * implied warranty.
- X */
- X
- X/* This file contains simple code to open a window or draw on the root.
- X The idea being that, when writing a graphics hack, you can just link
- X with this .o to get all of the uninteresting junk out of the way.
- X
- X - create a procedure `screenhack(dpy, window)'
- X
- X - create a variable `char *progclass' which names this program's
- X resource class.
- X
- X - create a variable `char defaults []' for the default resources.
- X
- X - create a variable `XrmOptionDescRec options []' for the command-line,
- X and `int options_size' which is `XtNumber (options)'.
- X
- X And that's it...
- X */
- X
- X#include <stdio.h>
- X#include <X11/Intrinsic.h>
- X#include <X11/Xmu/Error.h>
- X#include "screenhack.h"
- X
- Xchar *progname;
- Xchar *progclass;
- XXrmDatabase db;
- XBool mono_p;
- X
- X
- Xstatic XrmOptionDescRec default_options [] = {
- X { "-root", ".root", XrmoptionNoArg, "True" },
- X { "-window", ".root", XrmoptionNoArg, "False" },
- X { "-mono", ".mono", XrmoptionNoArg, "True" },
- X { "-install", ".installColormap", XrmoptionNoArg, "True" }
- X};
- X
- Xstatic char *default_defaults[] = {
- X "*root: false",
- X "*geometry: 500x500", /* this should be .geometry, but nooooo... */
- X "*mono: false",
- X "*installColormap: false",
- X 0
- X};
- X
- Xstatic XrmOptionDescRec *merged_options;
- Xstatic int merged_options_size;
- Xstatic char **merged_defaults;
- X
- Xstatic void
- Xmerge_options ()
- X{
- X int options_sizeof = options_size * sizeof (options[0]);
- X int defaults_size;
- X merged_options_size = XtNumber (default_options) + options_size;
- X merged_options = (XrmOptionDescRec *)
- X malloc (sizeof (default_options) + options_sizeof);
- X bcopy (options, merged_options, options_sizeof);
- X bcopy (default_options, merged_options + options_size,
- X sizeof (default_options));
- X
- X for (defaults_size = 0; defaults [defaults_size]; defaults_size++);
- X merged_defaults = (char **)
- X malloc (sizeof (default_defaults) + (defaults_size * sizeof (char *)));
- X bcopy (default_defaults, merged_defaults, sizeof (default_defaults));
- X bcopy (defaults, merged_defaults - 1 +
- X (sizeof (default_defaults) / sizeof (default_defaults[0])),
- X ((defaults_size + 1) * sizeof (defaults[0])));
- X}
- X
- X
- X/* Make the X errors print out the name of this program, so we have some
- X clue which one has a bug when they die under the screensaver.
- X */
- X
- Xstatic int
- Xscreenhack_ehandler (dpy, error)
- X Display *dpy;
- X XErrorEvent *error;
- X{
- X fprintf (stderr, "\nX error in %s:\n", progname);
- X if (XmuPrintDefaultErrorMessage (dpy, error, stderr))
- X exit (-1);
- X else
- X fprintf (stderr, " (nonfatal.)\n");
- X return 0;
- X}
- X
- X
- Xmain (argc, argv)
- X int argc;
- X char **argv;
- X{
- X XtAppContext app;
- X Widget toplevel;
- X Display *dpy;
- X Window window;
- X Colormap cmap;
- X
- X merge_options ();
- X toplevel = XtAppInitialize (&app, progclass, merged_options,
- X merged_options_size, &argc, argv,
- X merged_defaults, 0, 0);
- X dpy = XtDisplay (toplevel);
- X db = XtDatabase (dpy);
- X XtGetApplicationNameAndClass (dpy, &progname, &progclass);
- X XSetErrorHandler (screenhack_ehandler);
- X
- Xif ( argc > 1 )
- X {
- X usage(argc, argv);
- X exit (1);
- X }
- X
- X cmap = DefaultColormap (dpy, DefaultScreen (dpy));
- X mono_p = get_boolean_resource ("mono", "Boolean");
- X if (CellsOfScreen (DefaultScreenOfDisplay (dpy)) <= 2)
- X mono_p = True;
- X if (get_boolean_resource ("root", "Boolean"))
- X {
- X window = RootWindowOfScreen (XtScreen (toplevel));
- X XtDestroyWidget (toplevel);
- X }
- X else
- X {
- X XtRealizeWidget (toplevel);
- X window = XtWindow (toplevel);
- X if (get_boolean_resource ("installColormap", "InstallColormap"))
- X {
- X cmap = XCreateColormap (dpy, window,
- X DefaultVisualOfScreen (XtScreen (toplevel)),
- X AllocNone);
- X XSetWindowColormap (dpy, window, cmap);
- X }
- X }
- X XSetWindowBackground (dpy, window,
- X get_pixel_resource ("background", "Background",
- X dpy, cmap));
- X XClearWindow (dpy, window);
- X/*
- X XSync (dpy, False);
- X*/
- X XFlush(dpy);
- X srandom ((int) time ((time_t *) 0));
- X screenhack (dpy, window);
- X}
- SHAR_EOF
- if test 4496 -ne "`wc -c < 'screenhack.c'`"
- then
- echo shar: error transmitting "'screenhack.c'" '(should have been 4496 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'resources.c'" '(3123 characters)'
- if test -f 'resources.c'
- then
- echo shar: will not over-write existing file "'resources.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'resources.c'
- X/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
- X *
- X * Permission to use, copy, modify, distribute, and sell this software and its
- X * documentation for any purpose is hereby granted without fee, provided that
- X * the above copyright notice appear in all copies and that both that
- X * copyright notice and this permission notice appear in supporting
- X * documentation. No representations are made about the suitability of this
- X * software for any purpose. It is provided "as is" without express or
- X * implied warranty.
- X */
- X
- X#include <X11/Xlib.h>
- X#include <X11/Xresource.h>
- X#include <stdio.h>
- X
- X/* Resource functions. Assumes: */
- X
- Xextern char *progname;
- Xextern char *progclass;
- Xextern XrmDatabase db;
- X
- X#ifndef isupper
- X# define isupper(c) ((c) >= 'A' && (c) <= 'Z')
- X#endif
- X#ifndef _tolower
- X# define _tolower(c) ((c) - 'A' + 'a')
- X#endif
- X
- Xchar *
- Xget_string_resource (res_name, res_class)
- X char *res_name, *res_class;
- X{
- X XrmValue value;
- X char *type, *p;
- X char full_name [1024], full_class [1024];
- X strcpy (full_name, progname);
- X strcat (full_name, ".");
- X strcat (full_name, res_name);
- X strcpy (full_class, progclass);
- X strcat (full_class, ".");
- X strcat (full_class, res_class);
- X if (XrmGetResource (db, full_name, full_class, &type, &value))
- X {
- X char *str = (char *) malloc (value.size + 1);
- X strncpy (str, (char *) value.addr, value.size);
- X str [value.size] = 0;
- X return str;
- X }
- X return 0;
- X}
- X
- XBool
- Xget_boolean_resource (res_name, res_class)
- X char *res_name, *res_class;
- X{
- X char *tmp, buf [100];
- X char *s = get_string_resource (res_name, res_class);
- X char *os = s;
- X if (! s) return 0;
- X for (tmp = buf; *s; s++)
- X *tmp++ = isupper (*s) ? _tolower (*s) : *s;
- X *tmp = 0;
- X free (os);
- X
- X if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes"))
- X return 1;
- X if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no"))
- X return 0;
- X fprintf (stderr, "%s: %s must be boolean, not %s.\n",
- X progname, res_class, buf);
- X return 0;
- X}
- X
- Xint
- Xget_integer_resource (res_name, res_class)
- X char *res_name, *res_class;
- X{
- X int val;
- X char *s = get_string_resource (res_name, res_class);
- X if (!s) return 0;
- X if (1 == sscanf (s, " %d %c", &val))
- X {
- X free (s);
- X return val;
- X }
- X fprintf (stderr, "%s: %s must be an integer, not %s.\n",
- X progname, res_name, s);
- X free (s);
- X return 0;
- X}
- X
- Xunsigned int
- Xget_pixel_resource (res_name, res_class, dpy, cmap)
- X char *res_name, *res_class;
- X Display *dpy;
- X Colormap cmap;
- X{
- X int val;
- X XColor color;
- X char *s = get_string_resource (res_name, res_class);
- X if (!s) goto DEFAULT;
- X
- X if (! XParseColor (dpy, cmap, s, &color))
- X {
- X fprintf (stderr, "%s: can't parse color %s\n", progname, s);
- X goto DEFAULT;
- X }
- X if (! XAllocColor (dpy, cmap, &color))
- X {
- X fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s);
- X goto DEFAULT;
- X }
- X free (s);
- X return color.pixel;
- X DEFAULT:
- X free (s);
- X return (strcmp (res_class, "Background")
- X ? WhitePixel (dpy, DefaultScreen (dpy))
- X : BlackPixel (dpy, DefaultScreen (dpy)));
- X}
- SHAR_EOF
- if test 3123 -ne "`wc -c < 'resources.c'`"
- then
- echo shar: error transmitting "'resources.c'" '(should have been 3123 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'usleep.c'" '(2381 characters)'
- if test -f 'usleep.c'
- then
- echo shar: will not over-write existing file "'usleep.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'usleep.c'
- X/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
- X *
- X * Permission to use, copy, modify, distribute, and sell this software and its
- X * documentation for any purpose is hereby granted without fee, provided that
- X * the above copyright notice appear in all copies and that both that
- X * copyright notice and this permission notice appear in supporting
- X * documentation. No representations are made about the suitability of this
- X * software for any purpose. It is provided "as is" without express or
- X * implied warranty.
- X */
- X
- X#include <X11/Xlib.h>
- X#include <X11/Xos.h> /* lazy way out */
- X
- X/* usleep() doesn't exist everywhere, and select() is faster anyway.
- X */
- X
- X#ifndef VMS
- X
- X#ifdef NO_SELECT
- X /* If you don't have select() or usleep(), I guess you lose...
- X Maybe you have napms() instead? Let me know.
- X */
- Xvoid
- Xscreenhack_usleep (usecs)
- X unsigned long usecs;
- X{
- X usleep (usecs);
- X}
- X
- X#else /* ! NO_SELECT */
- X
- Xvoid
- Xscreenhack_usleep (usecs)
- X unsigned long usecs;
- X{
- X struct timeval tv;
- X tv.tv_sec = usecs / 1000000L;
- X tv.tv_usec = usecs % 1000000L;
- X (void) select (0, 0, 0, 0, &tv);
- X}
- X
- X#endif /* ! NO_SELECT */
- X
- X#else /* VMS */
- X
- X#define SEC_DELTA "0000 00:00:01.00"
- X#define TICK_DELTA "0000 00:00:00.08"
- Xstatic int bin_sec_delta[2], bin_tick_delta[2], deltas_set = 0;
- X
- Xstatic void
- Xset_deltas ()
- X{
- X int status;
- X extern int SYS$BINTIM ();
- X $DESCRIPTOR (str_sec_delta, SEC_DELTA);
- X $DESCRIPTOR (str_tick_delta, TICK_DELTA);
- X if (!deltas_set)
- X {
- X status = SYS$BINTIM (&str_sec_delta, &bin_sec_delta);
- X if (!(status & 1))
- X {
- X fprintf (stderr, "%s: cannot convert delta time ", progname);
- X fprintf (stderr, SEC_DELTA);
- X fprintf (stderr, "; status code = %d\n", status);
- X exit (status);
- X }
- X status = SYS$BINTIM (&str_tick_delta, &bin_tick_delta);
- X if (!(status & 1))
- X {
- X fprintf (stderr, "%s: cannot convert delta time ", progname);
- X fprintf (stderr, TICK_DELTA);
- X fprintf (stderr, "; status code = %d\n", status);
- X exit (status);
- X }
- X deltas_set = 1;
- X }
- X}
- X
- Xvoid
- Xscreenhack_usleep (usecs)
- X unsigned long usecs;
- X{
- X int status, *bin_delta;
- X extern int SYS$SCHWDK (), SYS$HIBER ();
- X
- X if (!deltas_set) set_deltas ();
- X bin_delta = (usecs == TICK_INTERVAL) ? &bin_tick_delta : &bin_sec_delta;
- X status = SYS$SCHDWK (0, 0, bin_delta, 0);
- X if ((status & 1)) (void) SYS$HIBER ();
- X}
- X
- X#endif /*VMS */
- SHAR_EOF
- if test 2381 -ne "`wc -c < 'usleep.c'`"
- then
- echo shar: error transmitting "'usleep.c'" '(should have been 2381 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xmas.c'" '(15642 characters)'
- if test -f 'xmas.c'
- then
- echo shar: will not over-write existing file "'xmas.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'xmas.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X/*
- X** HERSTORY:
- X13 December 92:
- XFinally got the snow code working, more or less.
- X
- X11 December 92:
- XSwitched a couple of lines to draw the candy last.
- X
- XSnow tended to ablate canes and ornaments. I added code to copy the window
- Xto an XImage during initialization, which allows me to restore the correct
- Xpixel value after snow leaves a pixel.
- X
- X10 December 92:
- XAdded beautiful snowfall code.
- X
- XAdded extra command-line options to ignore misspellings.
- X
- XAdded code to support backing store.
- X
- XAdded ornaments.
- X
- X9 December 92:
- XMoved color and snow code to modules of their own.
- X
- XMoved gift-drawing code to another file.
- X
- XMoved cane-drawing code to another file. I'm finally starting to clean
- Xup the code a little.
- X
- XAdded -snow option. I think I'm getting carried away here.
- X
- X8 December 92:
- XAdded code to draw candycanes randomly, if the user requests them.
- X
- XMoved the triangle code into its own module to clean things up a little.
- X
- XAdded #defines for the default resource values so it'll be easier to
- Xupdate the usage message when a default value changes.
- X
- X7 December 92:
- XChanged xmas_blink so it redraws the star every cycle, even if the
- Xstar doesn't blink; this is a fix for obscuration. I need to do the
- Xsame thing for the gift box.
- X
- XImproved the Makefile, wrote an Imakefile, and did a README to get this
- Xthing ready to post.
- X
- XChanged screenhack so it calls a function called usage() if there are
- Xarguments left over from resource-parsing. This lets me give better
- Xerror messages.
- X
- XAdded code to draw a gift (complete with label) under the tree. It's
- Xkind of cheesy.
- X
- XAdded code to toggle the star's twinkle; by default, it doesn't.
- X
- X6 December 92:
- XAdded code to let users change seed that generates the lights and other
- Xstuff.
- X
- XAdded support for the -install option; it's no longer good enough to use
- Xthe default colormap.
- X*/
- X
- X#include <stdio.h>
- X#include <math.h>
- X#include <X11/Xlib.h>
- X#include "screenhack.h"
- X#include "vroot.h"
- X#include "xmas.h"
- X
- X/*
- X** These arrays are our lights: their X and Y positions, their color,
- X** and whether or not they were lit last cycle.
- X*/
- Xstatic int Xs[NUM_LIGHTS];
- Xstatic int Ys[NUM_LIGHTS];
- Xstatic unsigned long Cs[NUM_LIGHTS];
- Xstatic int Lit[NUM_LIGHTS];
- X
- X/*
- X** Graphics contexts. We use a separate one for the star because it
- X** needs a 0 line width, while the lights are 2 pixels wide, and I
- X** didn't want to screw with changing the line attributes all the
- X** time.
- X*/
- Xstatic GC theGC;
- Xstatic GC StarGC;
- X
- X/*
- X** Dimensions of the window.
- X*/
- Xstatic int Width;
- Xstatic int Height;
- X
- X/*
- X** Records the state of the star.
- X*/
- Xstatic int StarLight;
- X
- X/*
- X** Does the star blink?
- X*/
- Xstatic int StarBlinks;
- X
- X/*
- X** The star's points, cached so we don't have to recalc every time.
- X*/
- Xstatic int StarX[5];
- Xstatic int StarY[5];
- X
- X/*
- X** These variables are referenced by screenhack; they're used to grab
- X** resource values, etc.
- X*/
- Xchar *progclass = "Xmas";
- X
- X/*
- X** I'd like for the usage message to automagically know about changes
- X** in the default values, but that's tough to do because of the way
- X** Xlib handles resources. So...if you change a default, change the
- X** corresponding #define. Otherwise our poor users will be confused.
- X** All of the #defines need to be strings except for DEF_DELAY,
- X** DEF_SEED, and DEF_CANDYCANES, which should be ints.
- X** (An ANSI compiler would handle this a lot better.)
- X*/
- Xchar *defaults[] =
- X {
- X "*background: black",
- X "*starColor: yellow",
- X "*starBlinks: false",
- X "*delay: 1500",
- X "*seed: 131",
- X "*giftLabel: Nobody",
- X "*giftColor: blue",
- X "*giftLabelColor: white",
- X "*numCandycanes: 0",
- X "*snow: false",
- X "*numOrnaments: 0",
- X "*backingStore: true",
- X NULL
- X };
- X
- X/*
- X** Some of these are duplicated. The capitalization conventions
- X** in X confuse people, so I'm trying to cover a lot of the cases.
- X*/
- XXrmOptionDescRec options[] =
- X {
- X { "-background", ".background", XrmoptionSepArg, 0 },
- X { "-starColor", ".starColor", XrmoptionSepArg, 0 },
- X { "-starBlinks", ".starBlinks", XrmoptionNoArg, "True" },
- X { "-delay", ".delay", XrmoptionSepArg, 0 },
- X { "-seed", ".seed", XrmoptionSepArg, 0 },
- X { "-giftLabel", ".giftLabel", XrmoptionSepArg, 0 },
- X { "-giftlabel", ".giftLabel", XrmoptionSepArg, 0 },
- X { "-giftColor", ".giftColor", XrmoptionSepArg, 0 },
- X { "-giftcolor", ".giftColor", XrmoptionSepArg, 0 },
- X { "-giftLabelColor", ".giftLabelColor", XrmoptionSepArg, 0 },
- X { "-numCandycanes", ".numCandycanes", XrmoptionSepArg, 0 },
- X { "-numCandyCanes", ".numCandycanes", XrmoptionSepArg, 0 },
- X { "-candycanes", ".numCandycanes", XrmoptionSepArg, 0 },
- X { "-snow", ".snow", XrmoptionNoArg, "True" },
- X { "-numOrnaments", ".numOrnaments", XrmoptionSepArg, 0 },
- X { "-numornaments", ".numOrnaments", XrmoptionSepArg, 0 },
- X { "-ornaments", ".numOrnaments", XrmoptionSepArg, 0 },
- X { "-backingStore", ".backingStore", XrmoptionSepArg, 0 }
- X };
- X
- Xint options_size = (sizeof(options) / sizeof(options[0]));
- X
- X/*
- X** A better usage message. Pass it the arg count and the arg vector.
- X*/
- Xvoid usage(argc, argv)
- Xint argc;
- Xchar **argv;
- X{
- Xint i;
- X
- Xfprintf(stderr, "XMAS Release %s\n", RELEASE);
- Xif ( strcmp(argv[1], "-help") )
- X {
- X fprintf(stderr, "Invalid %s: ", ( argc > 2 ? "options" : "option"));
- X for ( i = 1; i < argc; i++ )
- X fprintf(stderr, "%s ", argv[i]);
- X fprintf(stderr, "\n");
- X }
- Xfprintf(stderr, "Usage: %s [-option...]\n", *argv);
- Xfprintf(stderr, "where valid options are:\n");
- Xfprintf(stderr, "\t-display <display -name> (default is %s)\n",
- X XDisplayName(NULL));
- Xfprintf(stderr, "\t-root (display on root window)\n");
- Xfprintf(stderr, "\t-window (this is the default)\n");
- Xfprintf(stderr,
- X "\t-mono (for monochrome displays)\n");
- Xfprintf(stderr, "\t-install (create colormap)\n");
- Xfprintf(stderr, "\t-background <background-color> (default is %s)\n",
- X DEF_BG);
- Xfprintf(stderr, "\t-starColor <star-color> (default is %s)\n",
- X DEF_STARCOLOR);
- Xfprintf(stderr,
- X "\t-starBlinks (default is %s)\n",
- X DEF_STARBLINKS);
- Xfprintf(stderr, "\t-delay <delay-ms> (default is %dms)\n",
- X DEF_DELAY);
- Xfprintf(stderr, "\t-seed <random-seed> (default is %d)\n",
- X DEF_SEED);
- Xfprintf(stderr, "\t-giftLabel <recipient> (default is %s)\n",
- X DEF_GIFTLABEL);
- Xfprintf(stderr, "\t-giftLabelColor <label-color> (default is %s)\n",
- X DEF_GIFTLABELCOLOR);
- Xfprintf(stderr, "\t-giftColor <gift-color> (default is %s)\n",
- X DEF_GIFTCOLOR);
- Xfprintf(stderr, "\t-numCandycanes <number-of-canes> (default is %d)\n",
- X DEF_NUM_CANDYCANES);
- Xfprintf(stderr, "\t-snow (default is %s)\n",
- X DEF_SNOW);
- Xfprintf(stderr, "\t-numOrnaments <num-of-ornaments> (default is %d)\n",
- X DEF_NUM_ORNAMENTS);
- Xfprintf(stderr, "\t-backingStore <True or False> (default is %s)\n",
- X DEF_BACKING_STORE);
- Xfprintf(stderr, "Example: %s -giftLabel Elvis -delay 2000\n", *argv);
- X}
- X
- X/*
- X** This is screenhack's entry to this application. It grabs any resource
- X** values the user entered and enters an infinite loop in which it
- X** first checks to see if the window has changed, initializing the tree
- X** if so; blinks the lights; and sleeps for the specified delay time.
- X*/
- Xvoid screenhack(dpy, win)
- XDisplay *dpy;
- XWindow win;
- X{
- Xunsigned long bg; /* background color */
- Xunsigned long star_color; /* star color */
- Xint star_blinks; /* does star blink? */
- Xint delay; /* blink time in ms */
- Xlong seed; /* seed for random number generator */
- Xchar *gift; /* name for gift */
- Xunsigned long gift_color; /* what color's the gift? */
- Xunsigned long gift_lbl_color; /* color of gift label */
- Xint n_canes; /* number of candy canes */
- Xint snow; /* white christmas? */
- Xint n_ornaments; /* number of ornaments */
- Xint backing_store; /* use backing store? */
- XXWindowAttributes win_attr; /* window info */
- XXSetWindowAttributes win_vals; /* used if we set backing store */
- Xint first_cycle = 1; /* first cycle? */
- Xint timecount = 0; /* count cycle times */
- X
- Xbacking_store = get_boolean_resource("backingStore", "BackingStore");
- Xif ( backing_store )
- X {
- X win_vals.backing_store = WhenMapped;
- X win_vals.backing_planes = AllPlanes;
- X XChangeWindowAttributes(dpy, win,
- X CWBackingStore | CWBackingPlanes, &win_vals);
- X }
- X
- Xdelay = get_integer_resource("delay", "Delay");
- Xdelay *= 1000;
- Xseed = get_integer_resource("seed", "Seed");
- Xstar_blinks = get_boolean_resource("starBlinks", "StarBlinks");
- Xgift = get_string_resource("giftLabel", "GiftLabel");
- Xn_canes = get_integer_resource("numCandycanes", "NumCandycanes");
- Xsnow = get_boolean_resource("snow", "Snow");
- Xn_ornaments = get_integer_resource("numOrnaments", "NumOrnaments");
- X
- Xwhile ( 1 )
- X {
- X XGetWindowAttributes(dpy, win, &win_attr);
- X/*
- X** screenhack.c does an XSync(), but it doesn't always make the window
- X** viewable in time for the XGetImage() in snow.c to work. I'm trying to
- X** fix it here by looping until the window is up on the screen.
- X*/
- X while ( win_attr.map_state != IsViewable )
- X XGetWindowAttributes(dpy, win, &win_attr);
- X
- X if ( (win_attr.width != Width) || (win_attr.height != Height) )
- X {
- X if ( first_cycle )
- X {
- X first_cycle = 0;
- X bg = get_pixel_resource("background", "Background",
- X dpy, win_attr.colormap);
- X star_color = get_pixel_resource("starColor", "StarColor",
- X dpy, win_attr.colormap);
- X gift_color = get_pixel_resource("giftColor", "GiftColor",
- X dpy, win_attr.colormap);
- X gift_lbl_color =
- X get_pixel_resource("giftLabelColor", "GiftLabelColor",
- X dpy, win_attr.colormap);
- X }
- X xmas_init(dpy, win, bg, star_color,
- X win_attr.width, win_attr.height, seed,
- X win_attr.colormap, star_blinks,
- X gift, gift_color, gift_lbl_color,
- X n_canes, n_ornaments);
- X if ( snow )
- X snow_init(dpy, win, win_attr.width, win_attr.height);
- X }
- X
- X if ( snow )
- X {
- X if ( (timecount += SNOWFALL_TIME) >= delay )
- X {
- X xmas_blink(dpy, win);
- X timecount = 0;
- X }
- X draw_snow(dpy, win, win_attr.width, win_attr.height);
- X usleep(SNOWFALL_TIME);
- X }
- X else
- X {
- X xmas_blink(dpy, win);
- X usleep(delay);
- X }
- X }
- X}
- X
- X/*
- X** Initialize the application by finding how big a window we have,
- X** calculating the tree's dimensions, the positions of the lights, etc.
- X*/
- Xint xmas_init(dpy, win, bg, star_color, width, height, seed,
- X cmap, star_blinks, gift, gift_color, gift_lbl_color,
- X num_canes, num_ornaments)
- XDisplay *dpy; /* display connection */
- XWindow win; /* window we should draw to */
- Xunsigned long bg; /* background color */
- Xunsigned long star_color; /* color of star at top of tree */
- Xint width; /* how wide is our window? */
- Xint height; /* how high is our window? */
- Xlong seed; /* seed for randoms */
- XColormap cmap; /* which colormap to use */
- Xint star_blinks; /* does the star blink? */
- Xchar *gift; /* who's the present for? */
- Xunsigned long gift_color; /* gift color */
- Xunsigned long gift_lbl_color; /* gift label color */
- Xint num_canes; /* number of candycanes */
- Xint num_ornaments; /* number of ornaments to draw */
- X{
- Xint i; /* loop control */
- XXGCValues gcv; /* values for graphics context */
- Xint star_x; /* center of star */
- Xint star_y; /* Y portion of star's center */
- Xint Xa, Ya; /* vertex A */
- Xint Xb, Yb; /* vertex B */
- Xint Xc, Yc; /* vertex C */
- X
- XWidth = width;
- XHeight = height;
- XStarBlinks = star_blinks;
- X
- XStarGC = XCreateGC(dpy, win, 0, NULL);
- X
- Xgcv.line_width = LIGHT_WIDTH;
- Xgcv.foreground = bg;
- XtheGC = XCreateGC(dpy, win, GCLineWidth | GCForeground, &gcv);
- X
- XXFillRectangle(dpy, win, theGC, 0, 0, Width, Height);
- X
- Xcolor_init(dpy, cmap, bg, star_color, gift_color, gift_lbl_color);
- X
- Xsrand48((long) time((time_t *) NULL));
- X
- X/*
- X** Calculate the positions of the lights.
- X*/
- XXa = Width >> 1;
- XYa = Height / MARGIN;
- XXb = Width >> 2;
- XXc = 3 * Xb;
- XYb = Yc = Height - (Height / MARGIN);
- Xfor ( i = 0; i < NUM_LIGHTS; i++ )
- X {
- X pt_in_triangle(Xa, Ya, Xb, Yb, Xc, Yc, &(Xs[i]), &(Ys[i]));
- X Cs[i] =
- X get_color((lrand48() % (LAST_LIGHT - FIRST_LIGHT + 1)) + FIRST_LIGHT);
- X }
- X
- X/*
- X** Calculate the points of the star at the top of the tree.
- X*/
- Xstar_x = Width / 2;
- Xstar_y = Height / MARGIN;
- Xfor ( i = 0; i < 5; i++ )
- X {
- X/*
- X** We bias the angle by -90; otherwise, it looks vaguely Satanic.
- X** Not quite the Christmas message I was going for.
- X*/
- X StarX[i] = STAR_ARM_LENGTH * cos(DEG2RAD(-90.0 + 72.0 * i)) + star_x;
- X StarY[i] = STAR_ARM_LENGTH * sin(DEG2RAD(-90.0 + 72.0 * i)) + star_y;
- X }
- X
- Xif ( strcmp(gift, "Nobody") )
- X draw_gift(dpy, win, theGC, Width, Height,
- X gift, gift_color, gift_lbl_color);
- X
- Xif ( num_ornaments )
- X draw_ornaments(dpy, win, theGC, Xa, Ya, Xb, Yb, Xc, Yc, num_ornaments);
- X
- Xif ( num_canes )
- X draw_candy(dpy, win, theGC, Xa, Ya, Xb, Yb, Xc, Yc, num_canes);
- X}
- X
- X/*
- X** Blink the pretty lights and the star.
- X*/
- Xxmas_blink(dpy, win)
- XDisplay *dpy; /* display connection */
- XWindow win; /* window ID */
- X{
- Xint i; /* loop control */
- Xint star_x; /* X part of star's center */
- Xint star_y; /* Y part of star's center */
- Xint lit_before; /* previous state of a light */
- X
- X/*
- X** Figure out what a light wants to do. If it wants to be
- X** turned off, and it was turned on last cycle, turn it off; if it's
- X** on this cycle, and wasn't on last cycle, turn it on. Otherwise
- X** ignore it. See, this is an OPTIMIZED Christmas tree. Much better
- X** than the real thing.
- X*/
- Xfor ( i = 0; i < NUM_LIGHTS; i++ )
- X {
- X lit_before = Lit[i];
- X Lit[i] = lrand48() % 2;
- X if ( lit_before && !Lit[i] )
- X {
- X XSetForeground(dpy, theGC, get_color(BACKGROUND));
- X XDrawLine(dpy, win, theGC,
- X Xs[i], Ys[i], Xs[i], Ys[i] + LIGHT_HEIGHT);
- X }
- X else if ( !lit_before && Lit[i] )
- X {
- X XSetForeground(dpy, theGC, Cs[i]);
- X XDrawLine(dpy, win, theGC,
- X Xs[i], Ys[i], Xs[i], Ys[i] + LIGHT_HEIGHT);
- X }
- X }
- X
- X/*
- X** Draw a twinkling star on top of the tree.
- X*/
- Xif ( StarBlinks )
- X {
- X star_x = Width / 2;
- X star_y = Height / MARGIN;
- X XSetForeground(dpy, StarGC,
- X StarLight ? get_color(BACKGROUND) : get_color(STARCOLOR));
- X for ( i = 0; i < 5; i++ )
- X {
- X XDrawLine(dpy, win, StarGC, star_x, star_y, StarX[i], StarY[i]);
- X }
- X StarLight = 1 - StarLight;
- X }
- X}
- SHAR_EOF
- if test 15642 -ne "`wc -c < 'xmas.c'`"
- then
- echo shar: error transmitting "'xmas.c'" '(should have been 15642 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'pt_in_tri.c'" '(1264 characters)'
- if test -f 'pt_in_tri.c'
- then
- echo shar: will not over-write existing file "'pt_in_tri.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'pt_in_tri.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <math.h>
- X
- Xdouble drand48();
- X
- X/*
- X** Algorithm for random points in a triangle is from Glassner's _Graphics
- X** Gems_ (Academic Press, 1990). It's a book worth getting.
- X*/
- Xvoid pt_in_triangle(Xa, Ya, Xb, Yb, Xc, Yc, x_ptr, y_ptr)
- Xint Xa, Ya; /* first vertex */
- Xint Xb, Yb; /* second vertex */
- Xint Xc, Yc; /* third vertex */
- Xint *x_ptr, *y_ptr; /* where to store point */
- X{
- Xdouble s, t; /* two random numbers on [0.0,1.0] */
- Xdouble a; /* barycentric coordinate (s and t are the others) */
- X
- Xs = drand48();
- Xt = drand48();
- Xif ( (s + t) > 1 )
- X {
- X s = 1 - s;
- X t = 1 - t;
- X }
- Xa = 1.0 - s - t;
- X*x_ptr = a * Xa + s * Xb + t * Xc;
- X*y_ptr = a * Ya + s * Yb + t * Yc;
- X}
- SHAR_EOF
- if test 1264 -ne "`wc -c < 'pt_in_tri.c'`"
- then
- echo shar: error transmitting "'pt_in_tri.c'" '(should have been 1264 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'candy.c'" '(1830 characters)'
- if test -f 'candy.c'
- then
- echo shar: will not over-write existing file "'candy.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'candy.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <X11/Xlib.h>
- X#include "xmas.h"
- X
- X/*
- X** Draw a set of candycanes inside a triangle.
- X*/
- Xvoid draw_candy(dpy, win, gc, Xa, Ya, Xb, Yb, Xc, Yc, num_canes)
- XDisplay *dpy; /* connection to display */
- XWindow win; /* window ID */
- XGC gc; /* graphics context */
- Xint Xa, Ya; /* vertex A of triangle */
- Xint Xb, Yb; /* vertex B of triangle */
- Xint Xc, Yc; /* vertex C of triangle */
- Xint num_canes; /* number of candycanes to draw */
- X{
- XXGCValues gcv; /* values for XChangeGC() */
- Xint i; /* loop control */
- Xint candy_x; /* X coord of candycane's origin */
- Xint candy_y; /* Y coord of candycane's origin */
- X
- Xgcv.foreground = get_color(RED);
- Xgcv.background = get_color(WHITE);
- Xgcv.line_style = LineDoubleDash;
- XXChangeGC(dpy, gc, GCForeground | GCBackground | GCLineStyle, &gcv);
- X
- Xfor ( i = 0; i < num_canes; i++ )
- X {
- X pt_in_triangle(Xa, Ya, Xb, Yb, Xc, Yc, &candy_x, &candy_y);
- X XDrawArc(dpy, win, gc, candy_x, candy_y,
- X DEF_CANDY_WIDTH, DEF_CANDY_HEIGHT, 0, HALF_CIRCLE);
- X XDrawLine(dpy, win, gc,
- X candy_x + DEF_CANDY_WIDTH, candy_y,
- X candy_x + DEF_CANDY_WIDTH, candy_y + DEF_CANDY_LENGTH);
- X }
- X}
- SHAR_EOF
- if test 1830 -ne "`wc -c < 'candy.c'`"
- then
- echo shar: error transmitting "'candy.c'" '(should have been 1830 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'gift.c'" '(2211 characters)'
- if test -f 'gift.c'
- then
- echo shar: will not over-write existing file "'gift.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'gift.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <X11/Xlib.h>
- X#include "xmas.h"
- X
- X/*
- X** Draw a gift under the tree. This is the weakest of the xmas functions.
- X*/
- Xvoid draw_gift(dpy, win, gc, width, height, to_whom, box_color, text_color)
- XDisplay *dpy; /* display connection */
- XWindow win; /* window/pixmap */
- XGC gc; /* graphics context */
- Xint width; /* width of window */
- Xint height; /* height of window */
- Xchar *to_whom; /* for whom is the gift? */
- Xunsigned long box_color; /* what color should the box be? */
- Xunsigned long text_color; /* to_whom color */
- X{
- Xchar tag[64]; /* formatted tag for gift */
- XXFontStruct *font_sp; /* font info */
- Xint dir; /* string direction */
- Xint asc; /* max string ascent */
- Xint dec; /* max string descent */
- XXCharStruct ovr; /* overall string info */
- Xint gift_width; /* gift is sized to fit tag */
- Xint gift_height; /* height of gift */
- X
- Xsprintf(tag, "To: %s", to_whom);
- Xfont_sp = XLoadQueryFont(dpy, "fixed");
- XXQueryTextExtents(dpy, font_sp->fid, tag, strlen(tag),
- X &dir, &asc, &dec, &ovr);
- Xgift_width = ovr.lbearing + ovr.width;
- Xgift_height = asc + dec;
- XXSetForeground(dpy, gc, box_color);
- XXSetFont(dpy, gc, font_sp->fid);
- XXFillRectangle(dpy, win, gc, width / 2 + 10, height - gift_height - 10,
- X gift_width, gift_height);
- XXSetForeground(dpy, gc, text_color);
- XXDrawString(dpy, win, gc,
- X width / 2 + 10 + ovr.lbearing, height - 10 - dec,
- X tag, strlen(tag));
- X}
- SHAR_EOF
- if test 2211 -ne "`wc -c < 'gift.c'`"
- then
- echo shar: error transmitting "'gift.c'" '(should have been 2211 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'snow.c'" '(3388 characters)'
- if test -f 'snow.c'
- then
- echo shar: will not over-write existing file "'snow.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'snow.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <stdio.h>
- X#include <X11/Xlib.h>
- X#include <math.h>
- X#include "xmas.h"
- X
- X/*
- X** Arrays of snowflake coordinates.
- X*/
- Xstatic int Xs[NUM_SNOWFLAKES];
- Xstatic int Ys[NUM_SNOWFLAKES];
- X
- X/*
- X** Snow piles up at the bottom of the window. This array keeps track
- X** of how high the snow is. Since the window's size can change, this
- X** thing needs to be dynamically resized based on the width in pixels
- X** of the window.
- X*/
- Xstatic int *Snowfall = NULL;
- X
- X/*
- X** Graphics contexts. These have to change way too many times to restore
- X** the correct background pixel values.
- X*/
- Xstatic GC SnowGC;
- Xstatic GC BackgroundGC;
- X
- X/*
- X** When we snow through something, we need to know what color we
- X** snowed through so we can restore it. There's no way to retrieve
- X** pixel information from a window, so we create an XImage of the
- X** window and restore from it.
- X*/
- Xstatic XImage *WindowImage = NULL;
- X
- X/*
- X** Fill the snowflake arrays with initial values. I start the snow
- X** "above" the window so you don't see a mass of it at the top of
- X** the screen.
- X*/
- Xvoid snow_init(dpy, win, width, height)
- XDisplay *dpy; /* display connection */
- XWindow win; /* window ID */
- Xint width; /* width of window we snow in */
- Xint height; /* height of window we snow in */
- X{
- Xint i; /* loop control */
- XXGCValues gcv; /* values for GC */
- X
- Xif ( WindowImage != NULL )
- X XDestroyImage(WindowImage);
- XWindowImage = XGetImage(dpy, win, 0, 0, width, height, AllPlanes, XYPixmap);
- X
- Xgcv.foreground = get_color(BACKGROUND);
- XBackgroundGC = XCreateGC(dpy, win, GCForeground, &gcv);
- Xgcv.foreground = get_color(WHITE);
- XSnowGC = XCreateGC(dpy, win, GCForeground, &gcv);
- X
- Xfor ( i = 0; i < NUM_SNOWFLAKES; i++ )
- X {
- X Xs[i] = lrand48() % width;
- X Ys[i] = SNOW_START;
- X }
- Xif ( Snowfall != NULL )
- X free(Snowfall);
- Xif ( (Snowfall = (int *) calloc(width, sizeof(int))) == NULL )
- X fprintf(stderr, "Can't allocate space for %d ints\n", width);
- X}
- X
- X/*
- X** Draw random snowflakes in a window.
- X*/
- Xvoid draw_snow(dpy, win, width, height)
- XDisplay *dpy; /* display connection */
- XWindow win; /* window ID */
- Xint width; /* width of snowfield */
- Xint height; /* height of window */
- X{
- Xint i; /* loop control */
- X
- Xfor ( i = 0; i < NUM_SNOWFLAKES; i++ )
- X {
- X if ( !(lrand48() % SNOWFLAKES_CHANCE) )
- X {
- X if ( Ys[i] > SNOW_START && Ys[i] < (height - Snowfall[Xs[i]]) )
- X {
- X XSetForeground(dpy, BackgroundGC,
- X XGetPixel(WindowImage, Xs[i], Ys[i]));
- X XDrawPoint(dpy, win, BackgroundGC, Xs[i], Ys[i]);
- X }
- X Ys[i] += (lrand48() % MAX_SNOWFALL_RATE);
- X if ( Ys[i] < (height - 1) )
- X XDrawPoint(dpy, win, SnowGC, Xs[i], Ys[i]);
- X else
- X {
- X XDrawPoint(dpy, win, SnowGC, Xs[i], height - Snowfall[Xs[i]]);
- X Snowfall[Xs[i]]++;
- X Xs[i] = lrand48() % width;
- X Ys[i] = SNOW_START;
- X }
- X }
- X }
- X}
- SHAR_EOF
- if test 3388 -ne "`wc -c < 'snow.c'`"
- then
- echo shar: error transmitting "'snow.c'" '(should have been 3388 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'ornament.c'" '(2833 characters)'
- if test -f 'ornament.c'
- then
- echo shar: will not over-write existing file "'ornament.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'ornament.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <stdio.h>
- X#include <X11/Xlib.h>
- X#include "xmas.h"
- X
- X/*
- X** These are the bitmap files from which we get our ornaments.
- X*/
- Xstatic char *Bitmap_files[] =
- X {
- X "/usr/include/X11/bitmaps/icon",
- X "/usr/include/X11/bitmaps/keyboard16",
- X "/usr/include/X11/bitmaps/opendot",
- X "/usr/include/X11/bitmaps/star",
- X "/usr/include/X11/bitmaps/target",
- X "/usr/include/X11/bitmaps/tie_fighter",
- X "/usr/include/X11/bitmaps/xlogo16",
- X };
- X
- X#define NUM_BITMAPS (sizeof(Bitmap_files) / sizeof(char *))
- X
- X/*
- X** These are our ornaments. The ones I've picked are all 16 by 16.
- X*/
- Xstatic Pixmap Bitmaps[NUM_BITMAPS];
- X
- X/*
- X** Draw some ornaments on the tree.
- X*/
- Xvoid draw_ornaments(dpy, win, gc, Xa, Ya, Xb, Yb, Xc, Yc, num_ornaments)
- XDisplay *dpy; /* connection to display */
- XWindow win; /* window ID */
- XGC gc; /* graphics context */
- Xint Xa, Ya; /* vertex A of triangle */
- Xint Xb, Yb; /* vertex B of triangle */
- Xint Xc, Yc; /* vertex C of triangle */
- Xint num_ornaments; /* number of ornaments to draw */
- X{
- Xint i; /* loop control */
- Xint orn_x; /* X coord of ornament's origin */
- Xint orn_y; /* Y coord of ornament's origin */
- Xunsigned width; /* ornament width */
- Xunsigned height; /* ornament height */
- Xint x_hot; /* cursor hotspot's X coord */
- Xint y_hot; /* cursor hotspot's Y coord */
- Xint which_bitmap; /* which bitmap to use */
- X
- XXSetBackground(dpy, gc, get_color(BACKGROUND));
- X
- Xfor ( i = 0; i < num_ornaments; i++ )
- X {
- X which_bitmap = lrand48() % NUM_BITMAPS;
- X if ( Bitmaps[which_bitmap] == NULL )
- X {
- X XReadBitmapFile(dpy, win, Bitmap_files[which_bitmap],
- X &width, &height, &(Bitmaps[which_bitmap]),
- X &x_hot, &y_hot);
- X }
- X XSetForeground(dpy, gc,
- X get_color( (lrand48() % (LAST_LIGHT - FIRST_LIGHT + 1))
- X + FIRST_LIGHT));
- X pt_in_triangle(Xa, Ya, Xb, Yb, Xc, Yc, &orn_x, &orn_y);
- X XCopyPlane(dpy, Bitmaps[which_bitmap], win, gc,
- X 0, 0, BITMAP_WIDTH, BITMAP_HEIGHT, orn_x, orn_y, 1);
- X }
- X
- Xfor ( i = 0; i < NUM_BITMAPS; i++ )
- X {
- X if ( Bitmaps[i] != NULL )
- X XFreePixmap(dpy, Bitmaps[i]);
- X Bitmaps[i] = NULL;
- X }
- X}
- SHAR_EOF
- if test 2833 -ne "`wc -c < 'ornament.c'`"
- then
- echo shar: error transmitting "'ornament.c'" '(should have been 2833 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'color.c'" '(2158 characters)'
- if test -f 'color.c'
- then
- echo shar: will not over-write existing file "'color.c'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'color.c'
- X/* xmas, Copyright 1992 Mitchell L. Patterson (mpatters@cs.scarolina.edu)
- X**
- X** Permission to use, copy, modify, distribute, and sell this software and its
- X** documentation for any purpose is hereby granted without fee, provided that
- X** the above copyright notice appear in all copies and that both that
- X** copyright notice and this permission notice appear in supporting
- X** documentation. No representations are made about the suitability of this
- X** software for any purpose. It is provided "as is" without express or
- X** implied warranty.
- X**/
- X
- X#include <X11/Xlib.h>
- X#include "xmas.h"
- X
- X/*
- X** Internal array of pixel values; these are allocated in color_init
- X** and retrieved by users with get_color().
- X*/
- Xstatic unsigned long Colors[NUM_COLORS];
- X
- X/*
- X** Names of the colors we'll use for lights. These should parallel
- X** the colorname #defines in xmas.h.
- X*/
- Xstatic char *ColorNames[] =
- X {
- X "white",
- X "red",
- X "green",
- X "orange",
- X "yellow"
- X };
- X
- X/*
- X** Initialize the color functions.
- X*/
- Xvoid color_init(dpy, cmap, bg, star_color, box_color, text_color)
- XDisplay *dpy; /* display connection */
- XColormap cmap; /* colormap */
- Xunsigned long bg; /* background pixel */
- Xunsigned long star_color; /* star pixel */
- Xunsigned long box_color; /* gift pixel */
- Xunsigned long text_color; /* text pixel */
- X{
- Xint i; /* loop control */
- XXColor real; /* value returned by XAlloc... */
- XXColor ideal; /* real-world RGB values, ignored */
- X
- XColors[BACKGROUND] = bg;
- XColors[STARCOLOR] = star_color;
- XColors[BOXCOLOR] = box_color;
- XColors[TEXTCOLOR] = text_color;
- X
- Xfor ( i = FIRST_LIGHT; i <= LAST_LIGHT; i++ )
- X {
- X XAllocNamedColor(dpy, cmap, ColorNames[i - FIRST_LIGHT], &real, &ideal);
- X Colors[i] = real.pixel;
- X }
- X}
- X
- X/*
- X** Retrieve a pixel from the color table. If the color number passed
- X** in is invalid, return the background color.
- X*/
- Xunsigned long get_color(which_color)
- Xint which_color; /* xmas.h's #define for a particular color */
- X{
- Xreturn (which_color < 0 || which_color >= NUM_COLORS) ?
- X Colors[BACKGROUND]
- X : Colors[which_color];
- X}
- SHAR_EOF
- if test 2158 -ne "`wc -c < 'color.c'`"
- then
- echo shar: error transmitting "'color.c'" '(should have been 2158 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xmas.man'" '(3274 characters)'
- if test -f 'xmas.man'
- then
- echo shar: will not over-write existing file "'xmas.man'"
- else
- sed 's/^ X//' << \SHAR_EOF > 'xmas.man'
- X.TH XMAS 1 "18 December 1992"
- X.SH NAME
- Xxmas \- Christmas display hack
- X.SH SYNOPSIS
- X.B xmas
- X[\-display \fIdisplay\fP]
- X[\-root]
- X[\-window]
- X[\-mono]
- X[\-install]
- X[\-background \fIbackground-color\fP]
- X[\-starColor \fIstar-color\fP]
- X[\-starBlinks]
- X[\-delay \fIdelay-ms\fP]
- X[\-seed \fIrandomseed\fP]
- X[\-giftLabel \fIrecipient\fP]
- X[\-giftLabelColor \fIlabel-color\fP]
- X[\-giftColor \fIgift-color\fP]
- X[\-numCandycanes \fInumber-of-canes\fP]
- X[\-snow]
- X[\-numOrnaments \fInumber-of-ornaments\fP]
- X[\-backingStore \fIboolean\fP]
- X.SH OPTIONS
- X.PP
- X.TP 8
- X.B -display \fIdisplay\fP
- XDirect output to a server other than the default.
- X.PP
- X.TP 8
- X.B -root
- XUse the root (or virtual root) window.
- X.PP
- X.TP 8
- X.B -window
- XCreate a window. This is the default.
- X.PP
- X.TP 8
- X.B -install
- XCreate a new colormap instead of using the default colormap.
- X.PP
- X.TP 8
- X.B "-background \fIbackground-color\fP"
- XUse the named color for the window background. The default is black.
- X.PP
- X.TP 8
- X.B "-starColor \fIstar-color\fP"
- XPaint the star in the named color. The default is yellow.
- X.PP
- X.TP 8
- X.B -starBlinks
- XBlink the star every cycle. By default, the star is lit all the time.
- X.PP
- X.TP 8
- X.B "-delay \fIdelay-ms\fP"
- XChange the blink time of the lights. The default is 1500 milliseconds.
- X.PP
- X.TP 8
- X.B "-seed \fIrandomseed\fP"
- XUse the given integer seed as the initializer for light placement.
- X.PP
- X.TP 8
- X.B "-giftLabel \fIrecipient\fP"
- XDraw a present under the tree and label it with the recipient's name. The
- Xdefault is to not draw a gift.
- X.PP
- X.TP 8
- X.B "-giftLabelColor \fIlabel-color\fP"
- XDraw the label on the gift, assuming there is one, in the named color.
- XThe default color is white.
- X.PP
- X.TP 8
- X.B "-giftColor \fIgift-color\fP"
- XDraw the gift, assuming there is one, in the named color. The default
- Xcolor is blue.
- X.PP
- X.TP 8
- X.B "-numCandycanes \fInumber-of-canes\fP"
- XDraw the given number of candycanes on the tree. The default is to
- Xdraw no candycanes.
- X.PP
- X.TP 8
- X.B -snow
- XDraw snowfall in the background. Snowfall is pretty, but the calculations
- Xand graphics requests slurp CPU time. Snowfall also interferes with
- Xthe -delay option; delay times are roughly double what they should be
- Xwhen it's snowing.
- X.PP
- X.TP 8
- X.B "-numOrnaments \fInumber-of-ornaments\fP"
- XDraw the given number of ornaments on the tree. The default is to draw
- Xno ornaments.
- X.PP
- X.TP 8
- X.B "-backingStore \fIboolean\fP"
- XToggle the use of backing store. The default value is True, meaning
- Xbacking store should be used. Backing store is expensive in server
- Xmemory and should not be used if server resources are necessary for
- Xmore important clients.
- X.PP
- XAll of the command-line options can be specified in an X resource file
- Xsuch as
- X.I .Xdefaults
- Xby changing the leading dash to an asterisk or (more properly) by
- Xspecifying the value as follows:
- X.PP
- Xxmas.background: green
- X.PP
- XSome of the options have synonyms to keep xmas from complaining about
- Xspelling errors: "numCandycanes" can be entered on the command line
- Xas "numCandyCanes" or "candycanes"; "numOrnaments" can be entered as
- X"numornaments" or "ornaments." The synonyms do not work in resource
- Xfiles.
- X.SH DESCRIPTION
- X.I Xmas
- Xdraws a Christmas tree in its own window, or on the root window, and blinks
- Xits lights randomly. Not much else to it.
- X.SH AUTHOR
- XMitch Patterson
- X.br
- Xmpatters@cs.scarolina.edu
- SHAR_EOF
- if test 3274 -ne "`wc -c < 'xmas.man'`"
- then
- echo shar: error transmitting "'xmas.man'" '(should have been 3274 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
- --
- -----------------------------------------------------------------------------
- "For who could have known -- phlegm, tons of phlegm, awaited us."
- BOZO MADRID #23: BOZO'S GOT A COLD
- Mitch Patterson - eXpert eXplorer project - patterso@usceast.cs.scarolina.edu
-