SvgGradientStop.cs 2.45 KB
Newer Older
davescriven's avatar
davescriven committed
1
2
3
4
5
6
7
8
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;

namespace Svg
{
9
10
11
    /// <summary>
    /// Represents a colour stop in a gradient.
    /// </summary>
12
    [SvgElement("stop")]
davescriven's avatar
davescriven committed
13
14
15
16
17
18
    public class SvgGradientStop : SvgElement
    {
        private SvgUnit _offset;
        private Color _colour;
        private float _opacity;

19
20
21
        /// <summary>
        /// Gets or sets the offset, i.e. where the stop begins from the beginning, of the gradient stop.
        /// </summary>
davescriven's avatar
davescriven committed
22
23
24
25
        [SvgAttribute("offset")]
        public SvgUnit Offset
        {
            get { return this._offset; }
davescriven's avatar
davescriven committed
26
27
28
29
            set
            {
                this._offset = value.ToPercentage();
            }
davescriven's avatar
davescriven committed
30
31
        }

32
33
34
        /// <summary>
        /// Gets or sets the colour of the gradient stop.
        /// </summary>
davescriven's avatar
davescriven committed
35
36
37
38
39
40
41
42
        [SvgAttribute("stop-color")]
        [TypeConverter(typeof(SvgColourConverter))]
        public Color Colour
        {
            get { return this._colour; }
            set { this._colour = value; }
        }

43
44
45
        /// <summary>
        /// Gets or sets the opacity of the gradient stop (0-1).
        /// </summary>
davescriven's avatar
davescriven committed
46
47
48
49
50
51
52
        [SvgAttribute("stop-opacity")]
        public float Opacity
        {
            get { return this._opacity; }
            set { this._opacity = value; }
        }

53
54
55
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgGradientStop"/> class.
        /// </summary>
davescriven's avatar
davescriven committed
56
57
58
59
60
61
62
        public SvgGradientStop()
        {
            this._offset = new SvgUnit(0.0f);
            this._colour = Color.Transparent;
            this._opacity = 1.0f;
        }

63
64
65
66
67
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgGradientStop"/> class.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <param name="colour">The colour.</param>
davescriven's avatar
davescriven committed
68
69
70
71
72
73
        public SvgGradientStop(SvgUnit offset, Color colour)
        {
            this._offset = offset;
            this._colour = colour;
            this._opacity = 1.0f;
        }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89


		public override SvgElement DeepCopy()
		{
			return DeepCopy<SvgGradientStop>();
		}

		public override SvgElement DeepCopy<T>()
		{
			var newObj = base.DeepCopy<T>() as SvgGradientStop;
			newObj.Offset = this.Offset;
			newObj.Colour = this.Colour;
			newObj.Opacity = this.Opacity;

			return newObj;
		}
davescriven's avatar
davescriven committed
90
91
    }
}