~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« 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: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
using System;
28
28
using Gdk;
 
29
using System.Collections.Generic;
29
30
 
30
31
namespace Mono.TextEditor
31
32
{
108
109
                        return new HslColor (color);
109
110
                }
110
111
                
 
112
                public static HslColor FromHsl (double h, double s, double l)
 
113
                {
 
114
                        return new HslColor () {
 
115
                                H = h,
 
116
                                S = s,
 
117
                                L = l
 
118
                        };
 
119
                }
 
120
                
111
121
                public HslColor (double r, double g, double b) : this ()
112
122
                {
113
123
                        double v = System.Math.Max (r, g);
158
168
                        return System.Math.Sqrt (r * .241 + g * .691 + b * .068);
159
169
                }
160
170
                
 
171
                public static List<HslColor> GenerateHighlightColors (HslColor backGround, HslColor foreGround, int n)
 
172
                {
 
173
                        double bgH = (backGround.H == 0 && backGround.S == 0) ? 2 / 3.0 : backGround.H;
 
174
                        var result = new List<HslColor> ();
 
175
                        for (int i = 0; i < n; i++) {
 
176
                                double h = bgH + (i + 1.0) / (double)n;
 
177
                                
 
178
                                // for monochromatic backround the h value doesn't matter
 
179
                                if (i + 1 == n && !(backGround.H == 0 && backGround.S == 0))
 
180
                                        h = bgH + 0.5;
 
181
                                
 
182
                                if (h > 1.0)
 
183
                                        h -= 1.0;
 
184
                                        
 
185
                                double s = 0.85;
 
186
                                double l = 0.5;
 
187
                                if (backGround.H == 0 && backGround.S == 0 && backGround.L < 0.5)
 
188
                                        l = 0.8;
 
189
                                result.Add (Mono.TextEditor.HslColor.FromHsl (h, s, l));
 
190
                        }
 
191
                        return result;
 
192
                }
 
193
                
161
194
                public override string ToString ()
162
195
                {
163
196
                        return string.Format ("[HslColor: H={0}, S={1}, L={2}]", H, S, L);
164
197
                }
 
198
                
 
199
                public string ToPangoString ()
 
200
                {
 
201
                        var resultColor = (Cairo.Color)this;
 
202
                        return string.Format ("#{0:x2}{1:x2}{2:x2}",
 
203
                                (int)(resultColor.R * 255),
 
204
                                (int)(resultColor.G * 255), 
 
205
                                (int)(resultColor.B * 255));
 
206
                }
165
207
        }
166
208
}