checkin for Dennis Hayes <dennish@raytek.com>, see ChangeLog
[mono.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / ColorBlend.cs
1 //\r
2 // System.Drawing.Drawing2D.ColorBlend.cs\r
3 //\r
4 // Author:\r
5 //   Dennis Hayes (dennish@Raytek.com)\r
6 //\r
7 // (C) 2002/3 Ximian, Inc\r
8 //\r
9 using System;\r
10 \r
11 namespace System.Drawing.Drawing2D\r
12 {\r
13         public sealed class ColorBlend {\r
14                 private int count;\r
15                 private float [] positions;\r
16                 private Color [] colors;\r
17 \r
18                 public ColorBlend(int count) {\r
19                         //FIXME: \r
20                         if(count < 2){\r
21                                 throw new ArgumentOutOfRangeException("Count", count, "Must be at least 2");\r
22                         }\r
23                         if(count == 2){\r
24                                 //FIXME: call ColorBlend!\r
25                                 count = 2;\r
26                                 positions = new float [1];\r
27                                 colors = new Color [1];\r
28                                 positions[0] = 0.0F;\r
29                                 positions[1] = 1.0F;\r
30                                 colors[0] = Color.FromArgb(0,0,0);\r
31                                 colors[1] = Color.FromArgb(255,255,255);\r
32                         }\r
33                         this.count = count;\r
34                         int i;\r
35                         for(i = 0; i < count; i++){\r
36                                 positions[i] = (1.0F/count) * i;\r
37                                 //FIXME: Do real default color blend\r
38                                 //FIXME: I used 254 to prevent overflow, should use 255, if anyone cares?\r
39                                 colors[i] = Color.FromArgb((1/count) * i * 254,(1/count) * i * 254,(1/count) * i * 254);\r
40                         }\r
41                         //fix any rounding errors that would generate an invald list.\r
42                         positions[0] = 0.0F;\r
43                         positions[1] = 1.0F;\r
44                         colors[0] = Color.FromArgb(0,0,0);\r
45                         colors[1] = Color.FromArgb(255,255,255);\r
46 \r
47                 }\r
48 \r
49                 public ColorBlend() {\r
50                         count = 2;\r
51                         positions = new float [1];\r
52                         colors = new Color [1];\r
53                         positions[0] = 0.0F;\r
54                         positions[1] = 1.0F;\r
55                         colors[0] = Color.FromArgb(0,0,0);\r
56                         colors[1] = Color.FromArgb(255,255,255);\r
57                 }\r
58 \r
59                 public Color [] Colors{\r
60                         get {\r
61                                 return colors;\r
62                         }\r
63                         set{\r
64                                 count = value.GetUpperBound(0) + 1;\r
65                                 colors = value;\r
66                         }\r
67                 }\r
68 \r
69                 public float [] Positions{\r
70                         get {\r
71                                 return Positions;\r
72                         }\r
73                         set{\r
74                                 count = value.GetUpperBound(0) + 1;\r
75                                 positions = value;                              \r
76                         }\r
77                 }\r
78         }\r
79 \r
80 }\r