PageRenderTime 39ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/src/Effects/ColorFillEffect.cs

https://bitbucket.org/tuldok89/openpdn
C# | 121 lines | 97 code | 14 blank | 10 comment | 3 complexity | 0eab8c0b6c31bb0d8c670188eb5ac963 MD5 | raw file
  1. /////////////////////////////////////////////////////////////////////////////////
  2. // Paint.NET //
  3. // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
  4. // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
  5. // See src/Resources/Files/License.txt for full licensing and attribution //
  6. // details. //
  7. // . //
  8. /////////////////////////////////////////////////////////////////////////////////
  9. using PaintDotNet;
  10. using PaintDotNet.IndirectUI;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Drawing;
  14. using System.Windows.Forms;
  15. namespace PaintDotNet.Effects
  16. {
  17. // This effect is for testing purposes only.
  18. #if false
  19. public sealed class ColorFillEffect
  20. : InternalPropertyBasedEffect
  21. {
  22. public ColorFillEffect()
  23. : base("Color Fill", null, null, EffectFlags.Configurable)
  24. {
  25. if (PdnInfo.IsFinalBuild)
  26. {
  27. throw new InvalidOperationException("This effect should never make it in to a released build");
  28. }
  29. }
  30. public enum PropertyNames
  31. {
  32. AngleChooser,
  33. CheckBox,
  34. DoubleSlider,
  35. DoubleVectorPanAndSlider,
  36. DoubleVectorSlider,
  37. Int32ColorWheel,
  38. Int32IncrementButton,
  39. Int32Slider,
  40. StaticListDropDown,
  41. StaticListRadioButton,
  42. StringText,
  43. }
  44. private ColorBgra color;
  45. protected override PropertyCollection OnCreatePropertyCollection()
  46. {
  47. List<Property> props = new List<Property>();
  48. props.Add(new DoubleProperty(PropertyNames.AngleChooser, 0, -180, +180));
  49. props.Add(new BooleanProperty(PropertyNames.CheckBox, true));
  50. props.Add(new DoubleProperty(PropertyNames.DoubleSlider, 0, 0, 100));
  51. props.Add(new DoubleVectorProperty(PropertyNames.DoubleVectorPanAndSlider, Pair.Create(0.0, 0.0), Pair.Create(-1.0, -1.0), Pair.Create(+1.0, +1.0)));
  52. props.Add(new DoubleVectorProperty(PropertyNames.DoubleVectorSlider, Pair.Create(0.0, 0.0), Pair.Create(-1.0, -1.0), Pair.Create(+1.0, +1.0)));
  53. props.Add(new Int32Property(PropertyNames.Int32ColorWheel, 0, 0, 0xffffff));
  54. props.Add(new Int32Property(PropertyNames.Int32IncrementButton, 0, 0, 255));
  55. props.Add(new Int32Property(PropertyNames.Int32Slider, 0, 0, 100));
  56. props.Add(StaticListChoiceProperty.CreateForEnum<System.Drawing.GraphicsUnit>(PropertyNames.StaticListDropDown, GraphicsUnit.Millimeter, false));
  57. props.Add(StaticListChoiceProperty.CreateForEnum<System.Drawing.GraphicsUnit>(PropertyNames.StaticListRadioButton, GraphicsUnit.Document, false));
  58. props.Add(new StringProperty(PropertyNames.StringText, "hello", 100));
  59. return new PropertyCollection(props);
  60. }
  61. protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
  62. {
  63. ControlInfo configUI = CreateDefaultConfigUI(props);
  64. configUI.SetPropertyControlType(PropertyNames.AngleChooser, PropertyControlType.AngleChooser);
  65. configUI.SetPropertyControlType(PropertyNames.CheckBox, PropertyControlType.CheckBox);
  66. configUI.SetPropertyControlType(PropertyNames.DoubleSlider, PropertyControlType.Slider);
  67. configUI.SetPropertyControlType(PropertyNames.DoubleVectorPanAndSlider, PropertyControlType.PanAndSlider);
  68. configUI.SetPropertyControlType(PropertyNames.DoubleVectorSlider, PropertyControlType.Slider);
  69. configUI.SetPropertyControlType(PropertyNames.Int32ColorWheel, PropertyControlType.ColorWheel);
  70. configUI.SetPropertyControlType(PropertyNames.Int32IncrementButton, PropertyControlType.IncrementButton);
  71. configUI.SetPropertyControlType(PropertyNames.Int32Slider, PropertyControlType.Slider);
  72. configUI.SetPropertyControlType(PropertyNames.StaticListDropDown, PropertyControlType.DropDown);
  73. configUI.SetPropertyControlType(PropertyNames.StaticListRadioButton, PropertyControlType.RadioButton);
  74. configUI.SetPropertyControlType(PropertyNames.StringText, PropertyControlType.TextBox);
  75. foreach (object propertyName in Enum.GetValues(typeof(PropertyNames)))
  76. {
  77. configUI.SetPropertyControlValue(propertyName, ControlInfoPropertyNames.DisplayName, string.Empty);
  78. }
  79. return configUI;
  80. }
  81. protected override void OnCustomizeConfigUIWindowProperties(PropertyCollection props)
  82. {
  83. base.OnCustomizeConfigUIWindowProperties(props);
  84. //props[ControlInfoPropertyNames.WindowIsSizable].Value = true;
  85. }
  86. protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
  87. {
  88. int colorValue = newToken.GetProperty<Int32Property>(PropertyNames.Int32ColorWheel).Value;
  89. color = ColorBgra.FromOpaqueInt32(colorValue);
  90. base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
  91. }
  92. protected override void OnRender(Rectangle[] renderRects, int startIndex, int length)
  93. {
  94. foreach (Rectangle rect in renderRects)
  95. {
  96. for (int y = rect.Top; y < rect.Bottom; ++y)
  97. {
  98. for (int x = rect.Left; x < rect.Right; ++x)
  99. {
  100. DstArgs.Surface[x, y] = color;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. #endif
  107. }