home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume6
/
xplumb
/
part01
/
piece.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-11
|
7KB
|
160 lines
/*
* Copyright 1990 Digital Equipment Corporation
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital Equipment
* Corporation not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Digital Equipment Corporation makes no representations
* about the suitability of this software for any purpose. It is
* provided "as is" without express or implied warranty.
*
* DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
* ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Terry Weissman
* weissman@wsl.dec.com
*/
#include "plumbing.h"
static int numpieces = 0;
PieceRec::PieceRec(Direction updir, Direction downdir, Direction leftdir,
Direction rightdir, PieceRecFunc painter) {
out[Up] = updir;
out[Down] = downdir;
out[Left] = leftdir;
out[Right] = rightdir;
func = painter;
id = numpieces++;
piecelist[id] = this;
}
void PieceRec::Paint(Scrn scrn, int x, int y) {
int ssize = scrn->GetSSize();
Display *dpy = scrn->GetDpy();
Window window = scrn->GetWindow();
Pixmap pixmap = scrn->GetPieceCache(this);
if (!pixmap) {
pixmap = XCreatePixmap(dpy, window, ssize, ssize,
DefaultDepth(dpy, DefaultScreen(dpy)));
XFillRectangle(dpy, pixmap, scrn->GetBackgroundGC(), 0, 0,
ssize, ssize);
(*func)(scrn, dpy, pixmap, ssize, scrn->GetForegroundGC());
scrn->SetPieceCache(this, pixmap);
}
XCopyArea(dpy, pixmap, window, scrn->GetCopyGC(),
0, 0, ssize, ssize, x, y);
}
inline int L(int ssize) {return ssize / 3;}
inline int H(int ssize) {return 2 * ssize / 3;}
static void PaintNone(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, 0, ssize, ssize);
XDrawLine(dpy, pixmap, gc, 0, ssize, ssize, 0);
}
static void PaintHBar(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, L(ssize), ssize, L(ssize));
XDrawLine(dpy, pixmap, gc, 0, H(ssize), ssize, H(ssize));
}
static void PaintCross(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, L(ssize), L(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), L(ssize), L(ssize), 0);
XDrawLine(dpy, pixmap, gc, H(ssize), 0, H(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), L(ssize), ssize, L(ssize));
XDrawLine(dpy, pixmap, gc, 0, H(ssize), L(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), H(ssize), L(ssize), ssize);
XDrawLine(dpy, pixmap, gc, H(ssize), ssize, H(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), H(ssize), ssize, H(ssize));
}
static void PaintVBar(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, L(ssize), 0, L(ssize), ssize);
XDrawLine(dpy, pixmap, gc, H(ssize), 0, H(ssize), ssize);
}
static void PaintUL(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, L(ssize), L(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), L(ssize), L(ssize), 0);
XDrawLine(dpy, pixmap, gc, 0, H(ssize), H(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), H(ssize), H(ssize), 0);
}
static void PaintUR(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, L(ssize), 0, L(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), H(ssize), ssize, H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), 0, H(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), L(ssize), ssize, L(ssize));
}
static void PaintDL(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, L(ssize), H(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), L(ssize), H(ssize), ssize);
XDrawLine(dpy, pixmap, gc, 0, H(ssize), L(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), H(ssize), L(ssize), ssize);
}
static void PaintDR(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, L(ssize), ssize, L(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), L(ssize), ssize, L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), ssize, H(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), H(ssize), ssize, H(ssize));
}
static void PaintSUp(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, L(ssize), 0, L(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), H(ssize), H(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), H(ssize), H(ssize), 0);
}
static void PaintSDown(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, L(ssize), ssize, L(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), L(ssize), H(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), L(ssize), H(ssize), ssize);
}
static void PaintSLeft(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, 0, L(ssize), H(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), L(ssize), H(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, H(ssize), H(ssize), 0, H(ssize));
}
static void PaintSRight(Scrn, Display *dpy, Pixmap pixmap, int ssize, GC gc) {
XDrawLine(dpy, pixmap, gc, ssize, L(ssize), L(ssize), L(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), L(ssize), L(ssize), H(ssize));
XDrawLine(dpy, pixmap, gc, L(ssize), H(ssize), ssize, H(ssize));
}
void PieceInit() {
PieceNone = new PieceRec(BadDir, BadDir, BadDir, BadDir, PaintNone);
PieceHBar = new PieceRec(BadDir, BadDir, Right, Left, PaintHBar);
PieceVBar = new PieceRec(Down, Up, BadDir, BadDir, PaintVBar);
PieceCross = new PieceRec(Down, Up, Right, Left, PaintCross);
PieceUL = new PieceRec(Left, BadDir, Up, BadDir, PaintUL);
PieceUR = new PieceRec(Right, BadDir, BadDir, Up, PaintUR);
PieceDL = new PieceRec(BadDir, Left, Down, BadDir, PaintDL);
PieceDR = new PieceRec(BadDir, Right, BadDir, Down, PaintDR);
PieceStart[Up] = new PieceRec(BadDir, BadDir, BadDir, BadDir,
PaintSUp);
PieceStart[Down] = new PieceRec(BadDir, BadDir, BadDir, BadDir,
PaintSDown);
PieceStart[Left] = new PieceRec(BadDir, BadDir, BadDir, BadDir,
PaintSLeft);
PieceStart[Right] = new PieceRec(BadDir, BadDir, BadDir, BadDir,
PaintSRight);
}