ColorBlend.cs 1.8 KB

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