home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 6
/
FreshFish_September1994.bin
/
bbs
/
misc
/
cp-4.3.lha
/
cP
/
Source
/
drawview.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-03
|
32KB
|
1,400 lines
#include "cp.h"
#define SIZETIC 5 /* size major tik in pixels */
#define BOXOFF 10 /* add to filename box size */
#define TIKCOLOR 2 /* color for tiks */
#define BORDER 20 /* size between filename boxes */
struct RastPort *rp;
struct ViewPort *vp;
struct World wd;
struct CurView cv;
struct CurView ov;
WORD WIDTH;
WORD HEIGHT;
WORD OFFSET;
WORD xoff;
WORD yoff;
LONG precision = 2L;
/* Draw everything if full is TRUE autoscale */
void DrawView ( BOOL full )
{
vp = &(Scr-> ViewPort); /* Always reinit since could be new screen */
rp = PlotWindowWnd-> RPort;
if (cv.xmin>=cv.xmax||cv.ymin>=cv.ymax) FindWorld ();
if( !(IsListEmpty(SetList)))
{
if( full ) FindWorld ();
if (! HandlePlotWindowIDCMP()) Death(0);
SetAPen(rp,1);
OFFSET = rp->Font->tf_YSize + 2 * BORDER + Scr-> BarHeight;
HEIGHT = PlotWindowWnd-> Height - OFFSET - ( CPANEL ? 4 : 3 ) * GADHEIGHT;
yoff = OFFSET + HEIGHT;
xoff = rp-> Font-> tf_XSize * 6 + BORDER + SIZETIC;
DrawFileNameBoxes( yoff - HEIGHT);
if ( WIDTH < BORDER || HEIGHT < BORDER ) Death(20);
DrawColorBox( xoff , yoff, WIDTH, HEIGHT, 14);
XAxis();
YAxis();
LabelTitle();
DrawAllSets ();
if ( sym ) SymAllSets();
if ( grid ) Grid();
}
else
Erase( TRUE );
}
/* Draw all sets in SetList */
void DrawAllSets ()
{
WORD p = 4;
struct Set *node;
for ( node = (struct Set *)SetList-> lh_Head; node-> snode.ln_Succ; node = (struct Set *)node-> snode.ln_Succ )
{
SetAPen(rp,min(p,lastcolor));
DrawSet ( node-> FirstPoint );
p++;
if ( p > lastcolor - 2 ) p = 4;
if(! HandlePlotWindowIDCMP()) Death(5);
}
}
/* Draw symbols on all sets */
void SymAllSets ()
{
struct Set *node;
SetDrMd( rp, JAM2);
if (depth > 2)
SetAPen(rp,15);
else
SetAPen(rp,1);
for ( node = (struct Set *)SetList-> lh_Head; node-> snode.ln_Succ; node = (struct Set *)node-> snode.ln_Succ )
{
SymSet ( node-> FirstPoint );
if(! HandlePlotWindowIDCMP()) Death(5);
}
}
/* Adjust view so all data sets show */
void FindWorld ()
{
struct Set *node;
node = (struct Set *)SetList-> lh_Head;
wd.xmax = node-> xmax;
wd.xmin = node-> xmin;
wd.ymax = node-> ymax;
wd.ymin = node-> ymin;
for ( node = (struct Set *)SetList-> lh_Head; node-> snode.ln_Succ; node = (struct Set *)node-> snode.ln_Succ )
{
wd.xmax = max( wd.xmax, node-> xmax);
wd.xmin = min( wd.xmin, node-> xmin);
wd.ymax = max( wd.ymax, node-> ymax);
wd.ymin = min( wd.ymin, node-> ymin);
}
ov.xmax = cv.xmax = wd.xmax;
ov.xmin = cv.xmin = wd.xmin;
ov.ymax = cv.ymax = wd.ymax;
ov.ymin = cv.ymin = wd.ymin;
wd.xdelta = wd.xmax - wd.xmin;
wd.ydelta = wd.ymax - wd.ymin;
ov.xdelta = cv.xdelta = wd.xdelta;
ov.ydelta = cv.ydelta = wd.ydelta;
}
/* Draw one set */
void DrawSet ( struct Point *ThisPoint )
{
LONG qx, qy;
LONG le, te, re, be;
struct Rectangle rect;
struct Region *new_region;
struct Region *old_region;
rect.MinX = xoff;
rect.MaxX = xoff + WIDTH;
rect.MinY = yoff - HEIGHT;
rect.MaxY = yoff;
le = PlotWindowWnd-> LeftEdge;
te = PlotWindowWnd-> TopEdge;
re = PlotWindowWnd-> LeftEdge + PlotWindowWnd-> Width;
be = PlotWindowWnd-> TopEdge + PlotWindowWnd-> Height;
if ( ! (new_region = NewRegion())) return;
if ( ! (OrRectRegion( new_region, &rect))) return;
if (( old_region = InstallClipRegion( PlotWindowWnd-> WLayer, new_region ))) return;
qx = ScaleX( ThisPoint-> xval);
qy = ScaleY( ThisPoint-> yval);
if ( qx < le ) qx = le;
if ( qx > re ) qx = re;
if ( qy < te ) qy = te;
if ( qy > be ) qy = be;
Move ( rp, qx, qy );
do
{
ThisPoint = ThisPoint-> NextPoint;
qx = ScaleX( ThisPoint-> xval);
/* need to change if not time sampled data */
if ( qx < le ) continue;
if ( qx > re && RealTime ) break;
qy = ScaleY( ThisPoint-> yval);
if ( qy < te ) qy = te;
if ( qy > be ) qy = be;
Draw ( rp, qx, qy);
} while ( ThisPoint-> NextPoint );
new_region = InstallClipRegion(PlotWindowWnd->WLayer, old_region);
DisposeRegion(new_region);
}
/* draw symbols on one set */
void SymSet ( struct Point *ThisPoint )
{
LONG qx, qy;
WORD dx, dy;
BOOL clip;
dx = xoff + WIDTH;
dy = yoff - HEIGHT;
do {
clip = FALSE;
qx = ScaleX( ThisPoint-> xval);
qy = ScaleY( ThisPoint-> yval);
if ( qx < xoff )
{
qx = xoff;
clip = TRUE;
}
else if ( qx > dx )
{
qx = dx;
clip = TRUE;
}
if ( qy > yoff )
{
qy = yoff;
clip = TRUE;
}
else if ( qy < dy )
{
qy = dy;
clip = TRUE;
}
if ( !clip )
{
Move ( rp, qx - 1, qy + 1);
Draw ( rp, qx + 1, qy - 1);
Move ( rp, qx + 1, qy + 1);
Draw ( rp, qx - 1, qy - 1);
}
ThisPoint = ThisPoint-> NextPoint;
} while ( ThisPoint );
}
/* Draw recessed bevel box filled with color */
void DrawColorBox ( WORD xs ,WORD ys , WORD xw ,WORD yh, WORD color)
{
SetAPen( rp, (MONO ? 0 : color));
RectFill( rp, xs, ys - yh - 1, xs + xw, ys + 1 );
DrawBevelBox( rp, xs - 2, ys - yh - 1 , xw + 5, yh + 4, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE);
}
/* Draw Color boxes with filenames in them */
WORD DrawFileNameBoxes( WORD ys)
{
struct Set *node;
struct TextExtent txex;
WORD p = 4, h = 0, w = 0, xs, ns = 0;
for ( node = (struct Set *)SetList-> lh_Head; node-> snode.ln_Succ; node = (struct Set *)node-> snode.ln_Succ )
{
TextExtent( rp, node-> fn, strlen( node-> fn ), &txex);
w = max( w, txex.te_Width);
h = max( h, txex.te_Height);
ns++;
}
w += BOXOFF;
h += BOXOFF;
SetBPen( rp, 1);
if ( ns > 1 )
xs = PlotWindowWnd-> Width - w - BORDER;
else
{
xs = ( PlotWindowWnd-> Width / 2 - w / 2);
ys = (WORD)(txex.te_Height * 1.5);
}
WIDTH = PlotWindowWnd-> Width - (ns > 1 ? w + 2 * BORDER : xoff) - xoff; /* if only one set fnbox on top so width = windowwidth - 2*xoff */
Erase(FALSE); /* need to erase before drawing fnboxes but could not get calc width till now */
if (NOFNAME) /* if not drawing filename boxes set box symetrical and return */
{
WIDTH = PlotWindowWnd-> Width - ( 2 * xoff);
return((WORD)xoff);
}
for ( node = (struct Set *)SetList-> lh_Head; node-> snode.ln_Succ; node = (struct Set *)node-> snode.ln_Succ )
{
SetAPen( rp, p);
ys += h;
TextExtent( rp, node-> fn, strlen( node-> fn ), &txex);
if ( MONO == FALSE ) DrawColorBox( xs , ys, w, h, p );
SetDrMd( rp, (JAM2 | INVERSVID));
Move ( rp, xs + w/2 - txex.te_Width/2 , ys - BOXOFF / 2 );
Text( rp, node-> fn, strlen( node-> fn));
ys += BORDER;
SetDrMd( rp, JAM2);
p++;
if ( p > lastcolor - 2 ) p = 4;
}
return (WORD)( ns > 1 ? w + 2 * BORDER : xoff ); /* return no longer used for anything */
}
/* Adjust xmin and xmax to even nubers and draw tiks with text */
void XAxis()
{
LOGX ? logXAxis() : linXAxis();
}
/* Adjust ymin and ymax to even nubers and draw tiks with text */
void YAxis()
{
LOGY ? logYAxis() : linYAxis();
}
void logXAxis()
{
LONG j, k, l;
double q, r;
struct TextExtent txex;
/* Cant do negative log scale set lin */
if( cv.xmin <= 0.0 )
{
SetWindowTitles( PlotWindowWnd, NULL, "Cant do