Esempio n. 1
0
        public void TestGeneratedGradient(SKCanvas canvas)
        {
            // Create new Orange
            var Orange = new KimonoColor(255, 128, 0, 255);

            // Create new Purple
            var Purple = new KimonoColor(128, 0, 255, 255);

            // The Gradient's Color List
            SKColor[] GradientColors = { new SKColor(255, 255, 255, 255), Orange.Color, Purple.Color, new SKColor(0, 0, 0, 255) };

            // The Gradient's Weight List
            float[] GradientWeights = { 0f, 0.3047369f, 0.7118111f, 0.9662447f };

            // Create new Gradient
            var Gradient = new KimonoGradient(KimonoGradientType.LinearGradient, new KimonoHandle(0, 0), new KimonoHandle(168, 168), 88f, SKShaderTileMode.Clamp, GradientColors, GradientWeights);
            // Mix paint
            var paint = new SKPaint()
            {
                Shader = Gradient.Shader
            };

            // Draw rect
            var rect = new SKRect(0, 0, 640, 480);

            canvas.DrawRect(rect, paint);
        }
 /// <summary>
 /// Raises the remove gradient event.
 /// </summary>
 /// <param name="gradient">Gradient.</param>
 internal void RaiseRemoveGradient(KimonoGradient gradient)
 {
     // Inform caller of event
     if (RemoveGradient != null)
     {
         RemoveGradient(gradient);
     }
 }
 /// <summary>
 /// Raises the make duplicate event.
 /// </summary>
 /// <param name="gradient">Gradient.</param>
 internal void RaiseMakeDuplicate(KimonoGradient gradient)
 {
     // Inform caller of event
     if (MakeDuplicate != null)
     {
         MakeDuplicate(gradient);
     }
 }
 /// <summary>
 /// Raises the gradient modified event.
 /// </summary>
 /// <param name="gradient">Gradient.</param>
 internal void RaiseGradientModified(KimonoGradient gradient)
 {
     // Inform caller of event
     if (GradientModified != null)
     {
         GradientModified(gradient);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Conforms the gradient to shape by fitting it to the bounds of the shape.
        /// </summary>
        /// <param name="gradient">The <c>KimonoGradient</c> to conform.</param>
        /// <param name="paint">The <c>SKPaint</c> that the gradient is being attached to.</param>
        public virtual void ConformGradientToShape(KimonoGradient gradient, SKPaint paint)
        {
            // Anything to process?
            if (gradient == null)
            {
                return;
            }

            // Generate conforming coordinates
            var start = new SKPoint();
            var end   = new SKPoint();

            CalculateConfromingGradientCoordinates(gradient, out start, out end);

            // Apply change to the paint
            paint.Shader = gradient.ConformingShader(start, end);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds the given gradient to the collection of named gradients that are used
        /// in the generation of other Kimono Objects. If a gradient is already in
        /// the collection, its `ElementName` is returned.
        /// </summary>
        /// <returns>The `ElementName` for the supporting gradient.</returns>
        /// <param name="gradient">The `KimonoGradient` to add.</param>
        public static string AddSupportingGradient(KimonoGradient gradient)
        {
            // Scan all gradients
            foreach (KimonoGradient supportingGradient in SupportingGradients)
            {
                // Already in the collection?
                if (supportingGradient == gradient)
                {
                    return(supportingGradient.ElementName);
                }
            }

            // Generate element name and add to collection
            gradient.ElementName = MakeElementName(gradient.Name);
            SupportingGradients.Add(gradient);

            // Return the new element name
            return(gradient.ElementName);
        }
Esempio n. 7
0
        /// <summary>
        /// Calculates the confroming gradient coordinates.
        /// </summary>
        /// <param name="gradient">Gradient.</param>
        /// <param name="startPoint">Start point.</param>
        /// <param name="endPoint">End point.</param>
        public virtual void CalculateConfromingGradientCoordinates(KimonoGradient gradient, out SKPoint startPoint, out SKPoint endPoint)
        {
            // Generate conforming coordinates
            startPoint = new SKPoint();
            endPoint   = new SKPoint();

            // Anything to process?
            if (gradient == null)
            {
                return;
            }

            // Save current values
            var start = gradient.StartPoint.Clone();
            var end   = gradient.EndPoint.Clone();

            // Calculate ratio of change
            var offsetX = 0f;
            var shrinkX = true;
            var offsetY = 0f;
            var shrinkY = true;

            // Adjust start and end points
            if (Width < gradient.PreviewWidth)
            {
                offsetX = Width / gradient.PreviewWidth;
                shrinkX = true;
            }
            else
            {
                offsetX = gradient.PreviewWidth / Width;
                shrinkX = false;
            }

            if (Height < gradient.PreviewHeight)
            {
                offsetY = Height / gradient.PreviewHeight;
                shrinkY = true;
            }
            else
            {
                offsetY = gradient.PreviewHeight / Height;
                shrinkY = false;
            }

            // Calculate resized X positions
            if (shrinkX)
            {
                start.X = (start.X * offsetX) + Rect.Left;
                end.X   = (end.X * offsetX) + Rect.Left;
            }
            else
            {
                start.X = (start.X / offsetX) + Rect.Left;
                end.X   = (end.X / offsetX) + Rect.Left;
            }

            // Calculate resized Y positions
            if (shrinkY)
            {
                start.Y = (start.Y * offsetY) + Rect.Top;
                end.Y   = (end.Y * offsetY) + Rect.Top;
            }
            else
            {
                start.Y = (start.Y / offsetY) + Rect.Top;
                end.Y   = (end.Y / offsetY) + Rect.Top;
            }

            // Save new coordinates
            startPoint.X = start.X;
            startPoint.Y = start.Y;

            endPoint.X = end.X;
            endPoint.Y = end.Y;
        }