home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.0 KB | 213 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PRMDash.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWSTDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifdef FW_BUILD_MAC // Macintosh-only
-
- #ifndef _ODMATH_
- #include <ODMath.h>
- #endif
-
- #ifndef PRMDASH_H
- #include "PRMDash.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_MacDash
- #endif
-
- //========================================================================================
- // class FW_CPrivMacDashDraw
- //========================================================================================
-
- struct SStyleInfo
- {
- short fDashCount;
- short fDashData[6];
- };
-
- static SStyleInfo gDashData[4] =
- {
- { 2, { 18, 5 } }, /* PS_DASH */
- { 2, { 3, 3 } }, /* PS_DOT */
- { 4, { 9, 6, 3, 5 } }, /* PS_DASHDOT */
- { 6, { 9, 3, 3, 3, 3, 3 } } /* PS_DASHDOTDOT */
- };
-
- const int kStyleDashCount = sizeof(gDashData) / sizeof(gDashData[0]);
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacDashDraw::FW_CPrivMacDashDraw
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacDashDraw::FW_CPrivMacDashDraw(FW_EStyleDash dash) :
- fCurSegN(0),
- fCurSegDraw(TRUE)
- {
- fIsOpaque = (dash & FW_kOpaque) != 0;
- short nDash = dash & ~FW_kOpaque;
-
- FW_ASSERT(nDash >= FW_kDash);
- FW_ASSERT(nDash <= FW_kDashDotDot);
-
- fDashCount = gDashData[nDash - 1].fDashCount;
- fDashDistances = gDashData[nDash - 1].fDashData;
-
- if (fIsOpaque)
- {
- ::GetForeColor(&fForeColor);
- ::GetBackColor(&fBackColor);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacDashDraw::~FW_CPrivMacDashDraw
- //----------------------------------------------------------------------------------------
-
- FW_CPrivMacDashDraw::~FW_CPrivMacDashDraw()
- {
- // Restore the colors
- if (fIsOpaque)
- {
- ::RGBForeColor(&fForeColor);
- ::RGBBackColor(&fBackColor);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacDashDraw::LineTo
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacDashDraw::LineTo(short h, short v)
- {
- PenState ps;
- ::GetPenState(&ps);
-
- short dh = h - ps.pnLoc.h;
- short dv = v - ps.pnLoc.v;
-
- if ((ps.pnSize.h > 1 || ps.pnSize.v > 1) || (dh == 0 && dv == 0))
- {
- ::LineTo(h, v);
- return;
- }
-
- InitAdjust(dh, dv);
-
- short steps = FW_Maximum(FW_Absolute((int)dh), FW_Absolute((int)dv));
-
- ODFixed fxHStep = ODFixedDivide(ODIntToFixed(dh), ODIntToFixed(steps));
- ODFixed fxVStep = ODFixedDivide(ODIntToFixed(dv), ODIntToFixed(steps));
-
- ODFixed fxLength;
- if (dh == 0)
- fxLength = ODIntToFixed(FW_Absolute((int)dv));
- else if (dv == 0)
- fxLength = ODIntToFixed(FW_Absolute((int)dh));
- else
- {
- ODWide w;
- w.lo = 0;
- w.hi = dh * dh + dv * dv;
- fxLength = ODWideSquareRoot(&w);
- }
-
- ODFixed fxStep = ODFixedDivide(fxLength, ODIntToFixed(steps));
-
- ODFixed fxDist = 0;
- ODFixed fxHCur = ODIntToFixed(ps.pnLoc.h);
- ODFixed fxVCur = ODIntToFixed(ps.pnLoc.v);
-
- ODFixed fxCurSeg = ODIntToFixed(fDashDistances[fCurSegN]);
-
- while (steps -- > 0)
- {
- fxHCur += fxHStep;
- fxVCur += fxVStep;
- fxDist += fxStep;
-
- if (fxDist >= fxCurSeg)
- {
- DrawOneSegment(ODFixedRound(fxHCur), ODFixedRound(fxVCur));
-
- fCurSegDraw = !fCurSegDraw;
- fCurSegN = (fCurSegN + 1) % fDashCount;
- fxDist = 0;
- fxCurSeg = ODIntToFixed(fDashDistances[fCurSegN]);
- }
- }
-
- // Draw the last segment - this also finalizes the pen position
- DrawOneSegment(h, v);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacDashDraw::InitAdjust
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacDashDraw::InitAdjust(short dh, short dv)
- {
- fAdjustH = 0;
- fAdjustV = 0;
-
- if (dv == 0)
- {
- if (dh > 0)
- fAdjustH = -1;
- else if(dh < 0)
- fAdjustH = 1;
- }
- else if (dh == 0)
- {
- if (dv > 0)
- fAdjustV = -1;
- else if(dv < 0)
- fAdjustV = 1;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivMacDashDraw::DrawOneSegment
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivMacDashDraw::DrawOneSegment(short h, short v)
- {
- #ifdef FW_DEBUG
- PenState ps;
- ::GetPenState(&ps);
- #endif
-
- if (fIsOpaque)
- {
- ::RGBForeColor(fCurSegDraw ? &fForeColor : &fBackColor);
- ::LineTo(h + fAdjustH, v + fAdjustV);
- }
- else if(fCurSegDraw)
- {
- ::LineTo(h + fAdjustH, v + fAdjustV);
- }
-
- ::MoveTo(h, v);
- }
-
- #endif // FW_BUILD_MAC
-