~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor/HslColor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
                        set;
47
47
                }
48
48
                
49
 
                static Gdk.Color black = new  Gdk.Color (0, 0, 0);
50
 
                public static implicit operator Color (HslColor hsl)
 
49
                void ToRgb(out double r, out double g, out double b)
51
50
                {
52
 
                        double r = 0, g = 0, b = 0;
53
 
                        
54
 
                        if (hsl.L == 0)
55
 
                                return black;
56
 
                        
57
 
                        if (hsl.S == 0) {
58
 
                                r = g = b = hsl.L;
 
51
                        if (L == 0) {
 
52
                                r = g = b = 0;
 
53
                                return;
 
54
                        }
 
55
                        
 
56
                        if (S == 0) {
 
57
                                r = g = b = L;
59
58
                        } else {
60
 
                                double temp2 = hsl.L <= 0.5 ? hsl.L * (1.0 + hsl.S) : hsl.L + hsl.S -(hsl.L * hsl.S);
61
 
                                double temp1 = 2.0 * hsl.L - temp2;
 
59
                                double temp2 = L <= 0.5 ? L * (1.0 + S) : L + S -(L * S);
 
60
                                double temp1 = 2.0 * L - temp2;
62
61
                                
63
 
                                double[] t3 = new double[] { hsl.H + 1.0 / 3.0, hsl.H, hsl.H - 1.0 / 3.0};
 
62
                                double[] t3 = new double[] { H + 1.0 / 3.0, H, H - 1.0 / 3.0};
64
63
                                double[] clr= new double[] { 0, 0, 0};
65
64
                                for (int i = 0; i < 3; i++) {
66
65
                                        if (t3[i] < 0)
81
80
                                g = clr[1];
82
81
                                b = clr[2];
83
82
                        }
 
83
                }
 
84
                
 
85
                public static implicit operator Color (HslColor hsl)
 
86
                {
 
87
                        double r = 0, g = 0, b = 0;
 
88
                        hsl.ToRgb (out r, out g, out b);
84
89
                        return new Color ((byte)(255 * r), 
85
90
                                          (byte)(255 * g), 
86
91
                                          (byte)(255 * b));
87
92
                }
88
93
                
 
94
                public static implicit operator Cairo.Color (HslColor hsl)
 
95
                {
 
96
                        double r = 0, g = 0, b = 0;
 
97
                        hsl.ToRgb (out r, out g, out b);
 
98
                        return new Cairo.Color (r, g, b);
 
99
                }
 
100
                
89
101
                public static implicit operator HslColor (Color color)
90
102
                {
91
103
                        return new HslColor (color);
92
104
                }
93
105
                
94
 
                public HslColor (Color color) : this ()
95
 
                {
96
 
                        double r = color.Red   / (double)ushort.MaxValue;
97
 
                        double g = color.Green / (double)ushort.MaxValue;
98
 
                        double b = color.Blue  / (double)ushort.MaxValue;
99
 
 
 
106
                public static implicit operator HslColor (Cairo.Color color)
 
107
                {
 
108
                        return new HslColor (color);
 
109
                }
 
110
                
 
111
                public HslColor (double r, double g, double b) : this ()
 
112
                {
100
113
                        double v = System.Math.Max (r, g);
101
114
                        v = System.Math.Max (v, b);
102
115
 
129
142
                        this.H /= 6.0;
130
143
                }
131
144
                
 
145
                public HslColor (Color color) : this (color.Red / (double)ushort.MaxValue, color.Green / (double)ushort.MaxValue, color.Blue / (double)ushort.MaxValue)
 
146
                {
 
147
                }
 
148
                
 
149
                public HslColor (Cairo.Color color) : this (color.R, color.G, color.B)
 
150
                {
 
151
                }
 
152
                
132
153
                public static double Brightness (Gdk.Color c)
133
154
                {
134
155
                        double r = c.Red / (double)ushort.MaxValue;