public LinearGradientBrush(Rectangle rect, Color color1, Color color2,
                                   float angle, int fillType)
        {
            _start             = new Point(rect.X, rect.Y);
            _end               = new Point(rect.X + rect.Width, rect.Y + rect.Height);
            _gradientTransform = new AffineTransform();
            _fractions         = new[] { 0, 100 };
            _colors            = new[] { color1, color2 };
            bool opaque = true;

            for (int i = 0; i < _colors.Length; i++)
            {
                opaque = opaque && (_colors[i].GetAlpha() == 0xff);
            }
            _transparency = opaque ? Color.OPAQUE : Color.TRANSLUCENT;
            RectangleFP r = Utils.ToRectangleFP(rect);

            _wrappedBrushFP = new LinearGradientBrushFP(r.GetLeft(), r.GetTop(),
                                                        r.GetRight(), r.GetBottom(),
                                                        MathFP.ToRadians(SingleFP.FromFloat(angle)));
            for (int i = 0; i < _colors.Length; i++)
            {
                ((LinearGradientBrushFP)_wrappedBrushFP)
                .SetGradientColor(SingleFP.FromFloat(_fractions[i]
                                                     / 255.0f),
                                  _colors[i]._value);
            }
            ((LinearGradientBrushFP)_wrappedBrushFP).UpdateGradientTable();
            _wrappedBrushFP.SetMatrix(Utils.ToMatrixFP(_gradientTransform));
            _wrappedBrushFP.FillMode = fillType;
        }
Example #2
0
        public void Add(Mask mask)
        {
            RectangleFP rect = mask.Bounds;

            FPInt minx = FPMath.Min(_bounds.Left, rect.Left);
            FPInt maxx = FPMath.Max(_bounds.Right, rect.Right);
            FPInt miny = FPMath.Min(_bounds.Top, rect.Top);
            FPInt maxy = FPMath.Min(_bounds.Bottom, rect.Bottom);

            _bounds = new RectangleFP(minx, miny, maxx - minx, maxy - miny);

            _components.Add(mask);
        }
Example #3
0
        public CompositeMask(Mask mask)
        {
            _type = MaskType.Point;
            _pos = mask.Position;
            _bounds = mask.Bounds;

            if (mask is CompositeMask) {
                _components = new List<Mask>((mask as CompositeMask)._components);
            }
            else {
                _components = new List<Mask>();
                _components.Add(mask);
            }
        }
Example #4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Calculate the union of the two rectangle.
         * @param r
         * @return
         */
        public RectangleFP Union(RectangleFP r)
        {
            if (!r.IsEmpty())
            {
                if (IsEmpty())
                {
                    Reset(r);
                }
                else
                {
                    Reset(MathFP.Min(_ffXmin, r._ffXmin),
                          MathFP.Max(_ffXmax, r._ffXmax),
                          MathFP.Min(_ffYmin, r._ffYmin),
                          MathFP.Max(_ffYmax, r._ffYmax));
                }
            }
            return(this);
        }
Example #5
0
        public TriangleMask(PointFP p0, PointFP p1, PointFP p2)
        {
            _type = MaskType.Triangle;
            _p0 = p0;
            _p1 = p1;
            _p2 = p2;

            VectorFP a = (VectorFP)_pos + _p0;
            VectorFP b = (VectorFP)_pos + _p1;
            VectorFP c = (VectorFP)_pos + _p2;

            _det = (b.Y - c.Y) * (a.X - c.X) + (c.X - b.X) * (a.Y - c.Y);
            //_det = 1 / _det;

            FPInt minx = FPMath.Min(_p0.X, FPMath.Min(_p1.X, _p2.X));
            FPInt maxx = FPMath.Max(_p0.X, FPMath.Max(_p1.X, _p2.X));
            FPInt miny = FPMath.Min(_p0.Y, FPMath.Min(_p1.Y, _p2.Y));
            FPInt maxy = FPMath.Max(_p0.Y, FPMath.Max(_p1.Y, _p2.Y));

            _bound = new RectangleFP(minx, miny, maxx - minx, maxy - miny);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 15JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Constructs a {@code LinearGradientBrush}.
         *
         * @param start the gradient axis start {@code Point} in user space
         * @param end the gradient axis end {@code Point} in user space
         * @param fractions numbers ranging from 0 to 255 specifying the
         *                  distribution of colors along the gradient
         * @param colors array of colors corresponding to each fractional Value
         * @param fillType either {@code NO_CYCLE}, {@code REFLECT},
         *                    or {@code REPEAT}
         * @param gradientTransform transform to apply to the gradient
         *
         * @throws NullPointerException
         * if one of the points is null,
         * or {@code fractions} array is null,
         * or {@code colors} array is null,
         * or {@code cycleMethod} is null,
         * or {@code colorSpace} is null,
         * or {@code gradientTransform} is null
         * @throws IllegalArgumentException
         * if start and end points are the same points,
         * or {@code fractions.length != colors.length},
         * or {@code colors} is less than 2 in size,
         * or a {@code fractions} Value is less than 0.0 or greater than 1.0,
         * or the {@code fractions} are not provided in strictly increasing order
         */
        public LinearGradientBrush(Point start, Point end,
                                   int[] fractions, Color[] colors,
                                   AffineTransform gradientTransform, int fillType)
        {
            if (fractions == null)
            {
                throw new NullReferenceException("Fractions array cannot be null");
            }

            if (colors == null)
            {
                throw new NullReferenceException("Colors array cannot be null");
            }

            if (gradientTransform == null)
            {
                throw new NullReferenceException("Gradient transform cannot be " +
                                                 "null");
            }

            if (fractions.Length != colors.Length)
            {
                throw new ArgumentException("Colors and fractions must " +
                                            "have equal size");
            }

            if (colors.Length < 2)
            {
                throw new ArgumentException("User must specify at least " +
                                            "2 colors");
            }

            // check that values are in the proper range and progress
            // in increasing order from 0 to 1
            int previousFraction = -255;

            for (int i = 0; i < fractions.Length; i++)
            {
                int currentFraction = fractions[i];
                if (currentFraction < 0 || currentFraction > 255)
                {
                    throw new ArgumentException("Fraction values must " +
                                                "be in the range 0 to 255: " +
                                                currentFraction);
                }

                if (currentFraction <= previousFraction)
                {
                    throw new ArgumentException("Keyframe fractions " +
                                                "must be increasing: " +
                                                currentFraction);
                }

                previousFraction = currentFraction;
            }

            // We have to deal with the cases where the first gradient stop is not
            // equal to 0 and/or the last gradient stop is not equal to 1.
            // In both cases, create a new point and replicate the previous
            // extreme point's color.
            bool fixFirst = false;
            bool fixLast  = false;
            int  len      = fractions.Length;
            int  off      = 0;

            if (fractions[0] != 0)
            {
                // first stop is not equal to zero, fix this condition
                fixFirst = true;
                len++;
                off++;
            }
            if (fractions[fractions.Length - 1] != 255)
            {
                // last stop is not equal to one, fix this condition
                fixLast = true;
                len++;
            }

            this._fractions = new int[len];
            Array.Copy(fractions, 0, this._fractions, off, fractions.Length);
            this._colors = new Color[len];
            Array.Copy(colors, 0, this._colors, off, colors.Length);

            if (fixFirst)
            {
                this._fractions[0] = 0;
                this._colors[0]    = colors[0];
            }
            if (fixLast)
            {
                this._fractions[len - 1] = 255;
                this._colors[len - 1]    = colors[colors.Length - 1];
            }

            // copy the gradient transform
            this._gradientTransform = new AffineTransform(gradientTransform);

            // determine transparency
            bool opaque = true;

            for (int i = 0; i < colors.Length; i++)
            {
                opaque = opaque && (colors[i].GetAlpha() == 0xff);
            }
            _transparency = opaque ? Color.OPAQUE : Color.TRANSLUCENT;

            // check input parameters
            if (start == null || end == null)
            {
                throw new NullReferenceException("Start and end points must be" +
                                                 "non-null");
            }

            if (start.Equals(end))
            {
                throw new ArgumentException("Start point cannot equal" +
                                            "endpoint");
            }

            // copy the points...
            this._start = new Point(start.GetX(), start.GetY());
            this._end   = new Point(end.GetX(), end.GetY());

            Rectangle   rectangle = new Rectangle(start, end);
            float       dx        = start.X - end.X;
            float       dy        = start.Y - end.Y;
            double      angle     = MathEx.Atan2(dy, dx);
            int         intAngle  = SingleFP.FromDouble(angle);
            RectangleFP r         = Utils.ToRectangleFP(rectangle);

            _wrappedBrushFP = new LinearGradientBrushFP(r.GetLeft(), r.GetTop(),
                                                        r.GetRight(), r.GetBottom(),
                                                        intAngle);
            for (int i = 0; i < colors.Length; i++)
            {
                ((LinearGradientBrushFP)_wrappedBrushFP).SetGradientColor
                    (SingleFP.FromFloat(fractions[i] / 100.0f),
                    colors[i]._value);
            }
            ((LinearGradientBrushFP)_wrappedBrushFP).UpdateGradientTable();
            _wrappedBrushFP.SetMatrix(Utils.ToMatrixFP(gradientTransform));
            _wrappedBrushFP.FillMode = fillType;
        }
Example #7
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Check to see this rectange intersect with given rectange.
         * @param r
         * @return
         */
        public bool IntersectsWith(RectangleFP r)
        {
            return(_ffXmin <= r._ffXmax && r._ffXmin <= _ffXmax &&
                   _ffYmin <= r._ffYmax && r._ffYmin <= _ffYmax);
        }
Example #8
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * reset the rectangle.
         * @param r
         * @return
         */
        public RectangleFP Reset(RectangleFP r)
        {
            return(Reset(r._ffXmin, r._ffYmin, r._ffXmax, r._ffYmax));
        }
Example #9
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Copy constructor.
         * @param r
         */
        public RectangleFP(RectangleFP r)
        {
            Reset(r);
        }