예제 #1
0
        /// <summary>
        /// It initialize and controls the transformation of brush.
        /// </summary>
        /// <param name="startingPoint"> The starting point. </param>
        /// <param name="point"> The point. </param>
        public void InitializeController(Vector2 startingPoint, Vector2 point)
        {
            switch (this.Type)
            {
            case BrushType.None: break;

            case BrushType.Color: break;

            case BrushType.LinearGradient:
            case BrushType.RadialGradient:
            {
                this.Center = startingPoint;
                this.YPoint = point;
            }
            break;

            case BrushType.EllipticalGradient:
            case BrushType.Image:
            {
                this.Center = startingPoint;
                this.XPoint = BrushBase.YToX(point, startingPoint);
                this.YPoint = point;
            }
            break;

            default:
                break;
            }
        }
        /// <summary>
        /// Change the brush's type.
        /// </summary>
        /// <param name="type"> The new type. </param>
        /// <param name="transformer"> The transformer. </param>
        /// <param name="color"> The color. </param>
        /// <param name="photo"> The photo. </param>
        public void TypeChanged(BrushType type, Transformer transformer, Color color, Photo photo = null)
        {
            switch (type)
            {
            case BrushType.None:
                break;

            case BrushType.Color:
                this.ChangeColorCore(color);
                break;

            case BrushType.LinearGradient:
            case BrushType.RadialGradient:
                this.ChangingStopsCore(color);
                this.ChangingLinearGradientPointsCore(transformer);
                break;

            case BrushType.EllipticalGradient:
                this.ChangingStopsCore(color);
                this.ChangingEllipticalGradientPointsCore(transformer);
                break;

            case BrushType.Image:
            {
                // Photo
                if (photo is null)
                {
                    return;
                }

                Photocopier photocopier = photo.ToPhotocopier();
                float       width       = photo.Width;
                float       height      = photo.Height;

                this.Photocopier = photocopier;

                Vector2 center = this.Center;
                Vector2 yPoint = this.YPoint;

                //this.Center = center;
                this.XPoint = BrushBase.YToX(yPoint, center, width, height);
                //this.YPoint = yPoint;
                this.ChangingEllipticalGradientPointsCore(transformer);
            }
            break;

            default:
                break;
            }

            this.Type = type;
        }
예제 #3
0
        /// <summary>
        ///  Loads a <see cref="IBrush"/> from an XElement.
        /// </summary>
        /// <param name="element"> The source XElement. </param>
        /// <returns> The loaded <see cref="IBrush"/>. </returns>
        public static IBrush LoadBrush(XElement element)
        {
            BrushBase brush = new BrushBase();

            if (element.Attribute("Type") is XAttribute type)
            {
                brush.Type = XML.CreateBrushType(type.Value);
            }

            //Load
            {
                brush.Load(element);
            }

            return(brush);
        }
        private void ChangingEllipticalGradientPointsCore(Transformer transformer)
        {
            switch (this.Type)
            {
            case BrushType.None:
            case BrushType.Color:
                this.Center = transformer.Center;
                this.XPoint = transformer.CenterRight;
                this.YPoint = transformer.CenterBottom;
                break;

            case BrushType.LinearGradient:
            case BrushType.RadialGradient:
                this.XPoint = BrushBase.YToX(this.YPoint, this.Center);
                break;
            }
        }
예제 #5
0
        /// <summary>
        ///  Loads a <see cref="IBrush"/> from an XElement.
        /// </summary>
        /// <param name="element"> The source XElement. </param>
        /// <returns> The loaded <see cref="IBrush"/>. </returns>
        public static IBrush LoadBrush(XElement element)
        {
            BrushBase brush = new BrushBase();

            if (element.Attribute("Type") is XAttribute type)
            {
                try
                {
                    brush.Type = (BrushType)Enum.Parse(typeof(BrushType), type.Value);
                }
                catch (Exception) { }
            }

            // Load
            {
                brush.Load(element);
            }

            return(brush);
        }
예제 #6
0
        /// <summary>
        /// It controls the transformation of brush.
        /// </summary>
        /// <param name="mode"> The mode. </param>
        /// <param name="startingPoint"> The starting point. </param>
        /// <param name="point"> The point. </param>
        public void Controller(BrushHandleMode mode, Vector2 startingPoint, Vector2 point)
        {
            switch (this.Type)
            {
            case BrushType.None: break;

            case BrushType.Color: break;

            case BrushType.LinearGradient:
            {
                switch (mode)
                {
                case BrushHandleMode.Center:
                    this.Center = point;
                    return;

                case BrushHandleMode.YPoint:
                    this.YPoint = point;
                    return;
                }
            }
            break;

            case BrushType.RadialGradient:
            {
                switch (mode)
                {
                case BrushHandleMode.Center:
                {
                    Vector2 center = point;
                    Vector2 yPoint = center + this.StartingYPoint - this.StartingCenter;
                    this.Center = center;
                    this.YPoint = yPoint;
                }
                    return;

                case BrushHandleMode.YPoint:
                    this.YPoint = point;
                    return;
                }
            }
            break;

            case BrushType.EllipticalGradient:
            case BrushType.Image:
            {
                switch (mode)
                {
                case BrushHandleMode.Center:
                {
                    Vector2 center = point;

                    Vector2 offset = point - startingPoint;
                    this.Center = center;
                    this.XPoint = offset + this.StartingXPoint;
                    this.YPoint = offset + this.StartingYPoint;
                }
                    return;

                case BrushHandleMode.XPoint:
                {
                    float radiusY = Vector2.Distance(this.StartingYPoint, this.StartingCenter);
                    this.XPoint = point;
                    this.YPoint = BrushBase.XToY(point, this.StartingCenter, radiusY);
                }
                    return;

                case BrushHandleMode.YPoint:
                {
                    float radiusX = Vector2.Distance(this.StartingXPoint, this.StartingCenter);
                    this.XPoint = BrushBase.YToX(point, this.StartingCenter, radiusX);
                    this.YPoint = point;
                }
                    return;
                }
            }
                return;

            default:
                return;
            }
        }