//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 13JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Create the gradient brush. * @param ff_xmin the top left coordinate. * @param ff_ymin the top left coordinate. * @param ff_xmax the bottom right coordinate. * @param ff_ymax the bottom right coordinate. * @param ff_angle the angle for this gradient. * @param type the type of the gradient brush. */ public LinearGradientBrushFP(int ffXmin, int ffYmin, int ffXmax, int ffYmax, int ffAngle) { _bounds.Reset(ffXmin, ffYmin, ffXmax == ffXmin ? ffXmin + 1 : ffXmax, ffYmax == ffYmin ? ffYmin + 1 : ffYmax); _matrix = new MatrixFP(); _centerPt.Reset(ffXmin + (ffXmax - ffXmin) / 2, ffYmin + (ffYmax - ffYmin) / 2); _matrix.Translate(-_centerPt.X, -_centerPt.Y); _matrix.Rotate(-ffAngle); //matrix.translate((ff_xmin + ff_xmax) / 2,(ff_ymin + ff_ymax) / 2); var ffAng = MathFP.Atan(MathFP.Div(_bounds.GetHeight(), _bounds.GetWidth() == 0 ? 1 : _bounds.GetWidth())); var ffLen = PointFP.Distance(_bounds.GetHeight(), _bounds.GetWidth()); _ffLength = MathFP.Mul(ffLen, MathFP.Max( MathFP.Abs(MathFP.Cos(ffAngle - ffAng)), MathFP.Abs(MathFP.Cos(ffAngle + ffAng)))); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 09NOV2008 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * @inheritDoc * @param x the x coordinate * @param y the y coordinate * @param singlePoint * @return the color at given position. */ public override int GetColorAt(int x, int y, bool singlePoint) { var p = new PointFP(x << SingleFP.DECIMAL_BITS, y << SingleFP.DECIMAL_BITS); _nextPt.X = p.X + SingleFP.ONE; _nextPt.Y = p.Y; var newCenterPt = new PointFP(_centerPt); if (_finalMatrix != null) { p.Transform(_finalMatrix); //newCenterPt.transform(finalMatrix); } _ffCurrpos = MathFP.Div(PointFP.Distance(p.X - newCenterPt.X, p.Y - newCenterPt.Y), _ffRadius); var pos = _ffCurrpos >> SingleFP.DECIMAL_BITS - RATIO_BITS; switch (FillMode) { case REFLECT: pos = pos % (RATIO_MAX * 2); pos = pos < 0 ? pos + RATIO_MAX * 2 : pos; pos = (pos < RATIO_MAX) ? pos : RATIO_MAX * 2 - pos; break; case REPEAT: pos = pos % RATIO_MAX; pos = pos < 0 ? pos + RATIO_MAX : pos; break; case NO_CYCLE: pos = pos < 0 ? 0 : (pos > RATIO_MAX ? RATIO_MAX : pos); break; } return(_gradientColors[pos]); }