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

namespace Svg
{
    public sealed class SvgColourServer : SvgPaintServer
    {
10
        public SvgColourServer() : this(Color.Black)
davescriven's avatar
davescriven committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        {
        }

        public SvgColourServer(Color colour)
        {
            this._colour = colour;
        }

        private Color _colour;

        public Color Colour
        {
            get { return this._colour; }
            set { this._colour = value; }
        }

27
        public override Brush GetBrush(SvgVisualElement styleOwner, float opacity)
davescriven's avatar
davescriven committed
28
29
30
31
        {
            int alpha = (int)((opacity * (this.Colour.A/255) ) * 255);
            Color colour = Color.FromArgb(alpha, this.Colour);

32
            return new SolidBrush(colour);
davescriven's avatar
davescriven committed
33
34
35
36
37
38
39
40
        }

        public override string ToString()
        {
            Color c = this.Colour;

            // Return the name if it exists
            if (c.IsKnownColor)
41
            {
davescriven's avatar
davescriven committed
42
                return c.Name;
43
            }
davescriven's avatar
davescriven committed
44
45
46
47

            // Return the hex value
            return String.Format("#{0}", c.ToArgb().ToString("x").Substring(2));
        }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


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


		public override SvgElement DeepCopy<T>()
		{
			var newObj = base.DeepCopy<T>() as SvgColourServer;
			newObj.Colour = this.Colour;
			return newObj;

		}

64
65
66
67
68
69
70
71
        public override bool Equals(object obj)
        {
            var objColor = obj as SvgColourServer;
            if (objColor == null)
                return false;

            return this.Colour.ToArgb() == objColor.Colour.ToArgb();
        }
davescriven's avatar
davescriven committed
72
73
    }
}