home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Shareware 1999 March
/
PCShareware-3-99.iso
/
IMPLE
/
DJGPP.RAR
/
DJGPP2
/
XLIB-SR0.ZIP
/
SRC
/
XLIBEMU
/
DRAW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-03
|
11KB
|
522 lines
/* $Id: draw.c 1.4 1994/02/20 19:58:26 ulrich Exp $ */
/*
* draw.c
*
* X library drawing functions.
*/
#include "Xlibemu.h"
#ifdef DEBUG
#include <stdio.h>
#endif
/* Active drawing window context */
Drawable _DrawDrawable = None;
Region _DrawRegion;
BoxRec _DrawClip;
int _DrawRegionXOffset;
int _DrawRegionYOffset;
REGION _TempRegion;
int
_WDrawScreenContext (Drawable d)
{
GrSetContext (NULL);
GrResetClipBox ();
if (d->type == 2) {
_DrawRegion = ((Window) d)->visible_region;
_DrawClip = ((Window) d)->border_port;
}
else {
_TempRegion.rects = &_TempRegion.extents;
_TempRegion.numRects = 1;
_TempRegion.extents.x1 = 0;
_TempRegion.extents.y1 = 0;
_TempRegion.extents.x2 = GrSizeX();
_TempRegion.extents.y2 = GrSizeY();
_TempRegion.size = 1;
_DrawRegion = &_TempRegion;
_DrawClip = _TempRegion.extents;
}
_DrawDrawable = None;
_DrawRegionXOffset = 0;
_DrawRegionYOffset = 0;
return 1;
}
/* This functions must by called by XFreePixmap and XDestroyWindow */
void
_WDrawInvalid (Drawable d)
{
if (d == _DrawDrawable) _DrawDrawable = None;
}
int
_WDrawContext (Drawable d, GC gc)
{
if (d == _DrawDrawable)
return 1;
if (d == None)
return 0;
switch (d->type) {
case 0:
case 1:
return 0;
case 2:
{
Window w = (Window) d;
if (w->viewable == 0 ||
w->visibility == VisibilityFullyObscured)
return 0;
GrSetContext (w->context);
_DrawRegionXOffset = w->window_port.x1;
_DrawRegionYOffset = w->window_port.y1;
if (gc != None &&
gc->values.subwindow_mode == IncludeInferiors) {
_TempRegion.rects = &_TempRegion.extents;
_TempRegion.numRects = 1;
_TempRegion.extents = w->window_port;
_TempRegion.size = 1;
_DrawRegion = &_TempRegion;
}
else {
_DrawRegion = w->visible_region;
}
_DrawClip = w->window_port;
break;
}
case 3:
GrSetContext (((Pixmap) d)->context);
_DrawRegionXOffset = 0;
_DrawRegionYOffset = 0;
_TempRegion.rects = &_TempRegion.extents;
_TempRegion.numRects = 1;
_TempRegion.extents.x1 = 0;
_TempRegion.extents.y1 = 0;
_TempRegion.extents.x2 = GrSizeX();
_TempRegion.extents.y2 = GrSizeY();
_TempRegion.size = 1;
_DrawRegion = &_TempRegion;
_DrawClip = _TempRegion.extents;
break;
default:
exit (1);
}
_DrawDrawable = d;
return 1;
}
void
_WDrawRegion (void (*primitive)(),
long a1, long a2, long a3, long a4, long a5)
{
BoxPtr pbox;
int i;
#if 0
_XPrintRegion (_DrawRegion);
#endif
pbox = _DrawRegion->rects;
for (i = _DrawRegion->numRects; --i >= 0; pbox++) {
if (! EXTENTCHECK (pbox, &_DrawClip)) continue;
GrSetClipBox (pbox->x1 - _DrawRegionXOffset,
pbox->y1 - _DrawRegionYOffset,
pbox->x2 - _DrawRegionXOffset - 1,
pbox->y2 - _DrawRegionYOffset - 1);
(*primitive) (a1, a2, a3, a4, a5);
}
}
void
_WDrawRegion7 (void (*primitive)(),
long a1, long a2, long a3, long a4, long a5, long a6, long a7)
{
BoxPtr pbox;
int i;
#if 0
_XPrintRegion (_DrawRegion);
#endif
pbox = _DrawRegion->rects;
for (i = _DrawRegion->numRects; --i >= 0; pbox++) {
if (! EXTENTCHECK (pbox, &_DrawClip)) continue;
GrSetClipBox (pbox->x1 - _DrawRegionXOffset,
pbox->y1 - _DrawRegionYOffset,
pbox->x2 - _DrawRegionXOffset - 1,
pbox->y2 - _DrawRegionYOffset - 1);
(*primitive) (a1, a2, a3, a4, a5, a6, a7);
}
}
int
XDrawLine
(Display* display,
Drawable drawable,
GC gc,
int x1,
int y1,
int x2,
int y2)
{
WGC ext = (WGC) gc;
if (_WDrawContext (drawable, gc) == 0)
return 0;
FlushGC(display, gc);
_WDrawRegion (ext->Line, x1, y1, x2, y2, ext->line_arg);
return 1;
}
int
XDrawLines
(Display* display,
Drawable drawable,
GC gc,
XPoint* points,
int npoints,
int mode)
{
int i, x1, y1, x2, y2;
WGC ext = (WGC) gc;
if (_WDrawContext (drawable, gc) == 0)
return 0;
FlushGC(display, gc);
x1 = points->x;
y1 = points->y;
points++;
if (mode == CoordModePrevious) {
for (; --npoints >= 1; points++) {
x2 = x1 + points->x;
y2 = y1 + points->y;
_WDrawRegion (ext->Line, x1, y1, x2, y2, ext->line_arg);
x1 = x2;
y1 = y2;
}
}
else /* if (mode == CoordModeOrigin) */ {
for (; --npoints >= 1; points++) {
x2 = points->x;
y2 = points->y;
_WDrawRegion (ext->Line, x1, y1, x2, y2, ext->line_arg);
x1 = x2;
y1 = y2;
}
}
return 1;
}
int
XDrawSegments
(Display* display,
Drawable drawable,
GC gc,
XSegment* segments,
int nsegments)
{
WGC ext = (WGC) gc;
if (_WDrawContext (drawable, gc) == 0)
return 0;
FlushGC(display, gc);
for (; --nsegments >= 0; segments++) {
_WDrawRegion (ext->Line,
(int)segments->x1, (int)segments->y1,
(int)segments->x2, (int)segments->y2, ext->line_arg);
}
return 1;
}
int
XDrawPoint(
Display* display,
Drawable d,
GC gc,
int x,
int y)
{
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
_WDrawRegion (ext->Plot, x, y, ext->line_arg, 0, 0);
return 1;
}
int
XDrawPoints(
Display* display,
Drawable d,
GC gc,
XPoint* points,
int npoints,
int mode)
{
int x, y;
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
if (mode == CoordModePrevious) {
x = y = 0;
for (; --npoints >= 0; points++) {
x += points->x;
y += points->y;
_WDrawRegion (ext->Plot, x, y, ext->line_arg, 0, 0);
}
}
else /* if (mode == CoordModeOrigin) */ {
for (; --npoints >= 0; points++) {
x = points->x;
y = points->y;
_WDrawRegion (ext->Plot, x, y, ext->line_arg, 0, 0);
}
}
return Success;
}
int
XDrawRectangle(
Display* display,
Drawable d,
GC gc,
int x,
int y,
unsigned int width,
unsigned int height)
{
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
_WDrawRegion (ext->Box, x, y, x + width, y + height, ext->line_arg);
return 1;
}
int
XDrawRectangles(
Display* display,
Drawable d,
GC gc,
XRectangle* rectangles,
int nrectangles)
{
int x1, y1, x2, y2;
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
for (; --nrectangles >= 0; rectangles++) {
x1 = rectangles->x;
y1 = rectangles->y;
x2 = x1 + rectangles->width;
y2 = y1 + rectangles->height;
_WDrawRegion (ext->Box, x1, y1, x2, y2, ext->line_arg);
}
return 1;
}
int XDrawArc(
Display* display,
Drawable d,
GC gc,
int x,
int y,
unsigned int width,
unsigned int height,
int angle1,
int angle2)
{
XArc arc;
arc.x = x;
arc.y = y;
arc.width = width;
arc.height = height;
arc.angle1 = angle1;
arc.angle2 = angle2;
return XDrawArcs (display, d, gc, &arc, 1);
}
int XDrawArcs(
Display* display,
Drawable d,
GC gc,
XArc* arcs,
int narcs)
{
int xc, yc, xa, ya, start, end;
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
for (; --narcs >= 0; arcs++) {
xa = arcs->width / 2;
ya = arcs->height / 2;
xc = arcs->x + xa;
yc = arcs->y + ya;
start = (arcs->angle1 * 10) / 64;
end = start + (arcs->angle2 * 10) / 64;
if (end < start) { int temp = end; end = start; start = temp; };
_WDrawRegion7 (ext->EllipseArc, xc, yc, xa, ya, start, end, ext->line_arg);
}
return 0;
}
int
XFillArc(
Display* display,
Drawable d,
GC gc,
int x,
int y,
unsigned int width,
unsigned int height,
int angle1,
int angle2
)
{
XArc arc;
arc.x = x;
arc.y = y;
arc.width = width;
arc.height = height;
arc.angle1 = angle1;
arc.angle2 = angle2;
return XFillArcs (display, d, gc, &arc, 1);
}
int
XFillArcs(
Display* display,
Drawable d,
GC gc,
XArc* arcs,
int narcs)
{
int xc, yc, xa, ya, start, end;
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
for (; --narcs >= 0; arcs++) {
xa = arcs->width / 2;
ya = arcs->height / 2;
xc = arcs->x + xa;
yc = arcs->y + ya;
start = (arcs->angle1 * 10) / 64;
end = start + (arcs->angle2 * 10) / 64;
if (end < start) { int temp = end; end = start; start = temp; };
_WDrawRegion7 (ext->FilledEllipseArc, xc, yc, xa, ya, start, end, ext->fill_arg);
}
return 0;
}
int
XFillPolygon(
Display* display,
Drawable d,
GC gc,
XPoint* points,
int npoints,
int shape,
int mode)
{
int i, x, y;
int *opoints = (int *) alloca (npoints * 2 * sizeof(int));
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
if (mode == CoordModePrevious) {
x = y = 0;
for (i = 0; i < npoints; i++) {
x += points->x;
y += points->y;
points++;
opoints[2*i+0] = x;
opoints[2*i+1] = y;
}
}
else /* if (mode == CoordModeOrigin) */ {
for (i = 0; i < npoints; i++) {
x = points->x;
y = points->y;
points++;
opoints[2*i+0] = x;
opoints[2*i+1] = y;
}
}
_WDrawRegion (ext->FilledPolygon,
npoints, (long) opoints, ext->fill_arg, 0, 0);
return 1;
}
int
XFillRectangle(
Display* display,
Drawable d,
GC gc,
int x,
int y,
unsigned int width,
unsigned int height)
{
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
_WDrawRegion (ext->FilledBox, x, y, x + width - 1, y + height - 1, ext->fill_arg);
return 1;
}
int
XFillRectangles(
Display* display,
Drawable d,
GC gc,
XRectangle* rectangles,
int nrectangles)
{
int x1, y1, x2, y2;
WGC ext = (WGC) gc;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
for (; --nrectangles >= 0; rectangles++) {
x1 = rectangles->x;
y1 = rectangles->y;
x2 = x1 + rectangles->width - 1;
y2 = y1 + rectangles->height - 1;
_WDrawRegion (ext->FilledBox, x1, y1, x2, y2, ext->fill_arg);
}
return 1;
}
int
XFlush(
Display* display
)
{
return 1;
}