/* * NPlot - A charting library for .NET * * RectangleBrushes.cs * Copyright (C) 2003-2006 Matt Howlett and others. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of NPlot nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ using System.Drawing; using System.Drawing.Drawing2D; namespace NPlot { /// /// Classes that implement this interface can provide a brush /// sized according to a given rectangle. /// public interface IRectangleBrush { /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The brush Brush Get(Rectangle rectangle); } /// /// Collection of useful brushes. /// public class RectangleBrushes { /// /// A brush with horizontal gradient. /// public class Horizontal : IRectangleBrush { private readonly Color c1_; private readonly Color c2_; /// /// Constructor /// /// Color on left. /// Color on right. public Horizontal(Color c1, Color c2) { c1_ = c1; c2_ = c2; } /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The horizontal brush public Brush Get(Rectangle rectangle) { return new LinearGradientBrush(rectangle, c1_, c2_, LinearGradientMode.Horizontal); } #region DefaultBrushes /// /// Default brush - fades from faint blue to white. /// public static Horizontal FaintBlueFade { get { return new Horizontal(Color.FromArgb(200, 200, 255), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static Horizontal FaintRedFade { get { return new Horizontal(Color.FromArgb(255, 200, 200), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static Horizontal FaintGreenFade { get { return new Horizontal(Color.FromArgb(200, 255, 200), Color.FromArgb(255, 255, 255)); } } #endregion } /// /// A brush with horizontal gradient that fades into center then out again. /// public class HorizontalCenterFade : IRectangleBrush { private readonly Color c1_; private readonly Color c2_; /// /// Constructor /// /// inner color /// outer color public HorizontalCenterFade(Color c1, Color c2) { c1_ = c1; c2_ = c2; } /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The horizontal center fade brush public Brush Get(Rectangle rectangle) { LinearGradientBrush brush = new LinearGradientBrush(rectangle, c1_, c2_, LinearGradientMode.Horizontal); float[] relativeIntensities = {0.0f, 0.9f, 1.0f, 0.9f, 0.0f}; float[] relativePositions = {0.0f, 0.4f, 0.5f, 0.6f, 1.0f}; Blend blend = new Blend(); blend.Factors = relativeIntensities; blend.Positions = relativePositions; brush.Blend = blend; return brush; } #region DefaultBrushes /// /// Default brush - fades from faint blue to white. /// public static HorizontalCenterFade FaintBlueFade { get { return new HorizontalCenterFade(Color.FromArgb(200, 200, 255), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static HorizontalCenterFade FaintRedFade { get { return new HorizontalCenterFade(Color.FromArgb(255, 200, 200), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static HorizontalCenterFade FaintGreenFade { get { return new HorizontalCenterFade(Color.FromArgb(200, 255, 200), Color.FromArgb(255, 255, 255)); } } #endregion } /// /// A solid brush /// public class Solid : IRectangleBrush { private readonly Brush brush_; /// /// Constructor /// /// brush color public Solid(Color c) { brush_ = new SolidBrush(c); } /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The solid brush public Brush Get(Rectangle rectangle) { return brush_; } #region Default Brushes /// /// AliceBlue solid brush. /// public static Solid AliceBlue { get { return new Solid(Color.AliceBlue); } } /// /// AntiqueWhite solid brush. /// public static Solid AntiqueWhite { get { return new Solid(Color.AntiqueWhite); } } /// /// Aqua solid brush. /// public static Solid Aqua { get { return new Solid(Color.Aqua); } } /// /// Aquamarine solid brush. /// public static Solid Aquamarine { get { return new Solid(Color.Aquamarine); } } /// /// Azure solid brush. /// public static Solid Azure { get { return new Solid(Color.Azure); } } /// /// Beige solid brush. /// public static Solid Beige { get { return new Solid(Color.Beige); } } /// /// Bisque solid brush. /// public static Solid Bisque { get { return new Solid(Color.Bisque); } } /// /// Black solid brush. /// public static Solid Black { get { return new Solid(Color.Black); } } /// /// BlanchedAlmond solid brush. /// public static Solid BlanchedAlmond { get { return new Solid(Color.BlanchedAlmond); } } /// /// Blue solid brush. /// public static Solid Blue { get { return new Solid(Color.Blue); } } /// /// BlueViolet solid brush. /// public static Solid BlueViolet { get { return new Solid(Color.BlueViolet); } } /// /// Brown solid brush. /// public static Solid Brown { get { return new Solid(Color.Brown); } } /// /// BurlyWood solid brush. /// public static Solid BurlyWood { get { return new Solid(Color.BurlyWood); } } /// /// CadetBlue solid brush. /// public static Solid CadetBlue { get { return new Solid(Color.CadetBlue); } } /// /// Chartreuse solid brush. /// public static Solid Chartreuse { get { return new Solid(Color.Chartreuse); } } /// /// Chocolate solid brush. /// public static Solid Chocolate { get { return new Solid(Color.Chocolate); } } /// /// Coral solid brush. /// public static Solid Coral { get { return new Solid(Color.Coral); } } /// /// CornflowerBlue solid brush. /// public static Solid CornflowerBlue { get { return new Solid(Color.CornflowerBlue); } } /// /// Cornsilk solid brush. /// public static Solid Cornsilk { get { return new Solid(Color.Cornsilk); } } /// /// Crimson solid brush. /// public static Solid Crimson { get { return new Solid(Color.Crimson); } } /// /// Cyan solid brush. /// public static Solid Cyan { get { return new Solid(Color.Cyan); } } /// /// DarkBlue solid brush. /// public static Solid DarkBlue { get { return new Solid(Color.DarkBlue); } } /// /// DarkCyan solid brush. /// public static Solid DarkCyan { get { return new Solid(Color.DarkCyan); } } /// /// DarkGoldenrod solid brush. /// public static Solid DarkGoldenrod { get { return new Solid(Color.DarkGoldenrod); } } /// /// DarkGray solid brush. /// public static Solid DarkGray { get { return new Solid(Color.DarkGray); } } /// /// DarkGreen solid brush. /// public static Solid DarkGreen { get { return new Solid(Color.DarkGreen); } } /// /// DarkKhaki solid brush. /// public static Solid DarkKhaki { get { return new Solid(Color.DarkKhaki); } } /// /// DarkMagenta solid brush. /// public static Solid DarkMagenta { get { return new Solid(Color.DarkMagenta); } } /// /// DarkOliveGreen solid brush. /// public static Solid DarkOliveGreen { get { return new Solid(Color.DarkOliveGreen); } } /// /// DarkOrange solid brush. /// public static Solid DarkOrange { get { return new Solid(Color.DarkOrange); } } /// /// DarkOrchid solid brush. /// public static Solid DarkOrchid { get { return new Solid(Color.DarkOrchid); } } /// /// DarkRed solid brush. /// public static Solid DarkRed { get { return new Solid(Color.DarkRed); } } /// /// DarkSalmon solid brush. /// public static Solid DarkSalmon { get { return new Solid(Color.DarkSalmon); } } /// /// DarkSeaGreen solid brush. /// public static Solid DarkSeaGreen { get { return new Solid(Color.DarkSeaGreen); } } /// /// DarkSlateBlue solid brush. /// public static Solid DarkSlateBlue { get { return new Solid(Color.DarkSlateBlue); } } /// /// DarkSlateGray solid brush. /// public static Solid DarkSlateGray { get { return new Solid(Color.DarkSlateGray); } } /// /// DarkTurquoise solid brush. /// public static Solid DarkTurquoise { get { return new Solid(Color.DarkTurquoise); } } /// /// DarkViolet solid brush. /// public static Solid DarkViolet { get { return new Solid(Color.DarkViolet); } } /// /// DeepPink solid brush. /// public static Solid DeepPink { get { return new Solid(Color.DeepPink); } } /// /// DeepSkyBlue solid brush. /// public static Solid DeepSkyBlue { get { return new Solid(Color.DeepSkyBlue); } } /// /// DimGray solid brush. /// public static Solid DimGray { get { return new Solid(Color.DimGray); } } /// /// DodgerBlue solid brush. /// public static Solid DodgerBlue { get { return new Solid(Color.DodgerBlue); } } /// /// Firebrick solid brush. /// public static Solid Firebrick { get { return new Solid(Color.Firebrick); } } /// /// FloralWhite solid brush. /// public static Solid FloralWhite { get { return new Solid(Color.FloralWhite); } } /// /// ForestGreen solid brush. /// public static Solid ForestGreen { get { return new Solid(Color.ForestGreen); } } /// /// Fuchsia solid brush. /// public static Solid Fuchsia { get { return new Solid(Color.Fuchsia); } } /// /// Gainsboro solid brush. /// public static Solid Gainsboro { get { return new Solid(Color.Gainsboro); } } /// /// GhostWhite solid brush. /// public static Solid GhostWhite { get { return new Solid(Color.GhostWhite); } } /// /// Gold solid brush. /// public static Solid Gold { get { return new Solid(Color.Gold); } } /// /// Goldenrod solid brush. /// public static Solid Goldenrod { get { return new Solid(Color.Goldenrod); } } /// /// Gray solid brush. /// public static Solid Gray { get { return new Solid(Color.Gray); } } /// /// Green solid brush. /// public static Solid Green { get { return new Solid(Color.Green); } } /// /// GreenYellow solid brush. /// public static Solid GreenYellow { get { return new Solid(Color.GreenYellow); } } /// /// Honeydew solid brush. /// public static Solid Honeydew { get { return new Solid(Color.Honeydew); } } /// /// HotPink solid brush. /// public static Solid HotPink { get { return new Solid(Color.HotPink); } } /// /// IndianRed solid brush. /// public static Solid IndianRed { get { return new Solid(Color.IndianRed); } } /// /// Indigo solid brush. /// public static Solid Indigo { get { return new Solid(Color.Indigo); } } /// /// Ivory solid brush. /// public static Solid Ivory { get { return new Solid(Color.Ivory); } } /// /// Khaki solid brush. /// public static Solid Khaki { get { return new Solid(Color.Khaki); } } /// /// Lavender solid brush. /// public static Solid Lavender { get { return new Solid(Color.Lavender); } } /// /// LavenderBlush solid brush. /// public static Solid LavenderBlush { get { return new Solid(Color.LavenderBlush); } } /// /// LawnGreen solid brush. /// public static Solid LawnGreen { get { return new Solid(Color.LawnGreen); } } /// /// LemonChiffon solid brush. /// public static Solid LemonChiffon { get { return new Solid(Color.LemonChiffon); } } /// /// LightBlue solid brush. /// public static Solid LightBlue { get { return new Solid(Color.LightBlue); } } /// /// LightCoral solid brush. /// public static Solid LightCoral { get { return new Solid(Color.LightCoral); } } /// /// LightCyan solid brush. /// public static Solid LightCyan { get { return new Solid(Color.LightCyan); } } /// /// LightGoldenrodYellow solid brush. /// public static Solid LightGoldenrodYellow { get { return new Solid(Color.LightGoldenrodYellow); } } /// /// LightGray solid brush. /// public static Solid LightGray { get { return new Solid(Color.LightGray); } } /// /// LightGreen solid brush. /// public static Solid LightGreen { get { return new Solid(Color.LightGreen); } } /// /// LightPink solid brush. /// public static Solid LightPink { get { return new Solid(Color.LightPink); } } /// /// LightSalmon solid brush. /// public static Solid LightSalmon { get { return new Solid(Color.LightSalmon); } } /// /// LightSeaGreen solid brush. /// public static Solid LightSeaGreen { get { return new Solid(Color.LightSeaGreen); } } /// /// LightSkyBlue solid brush. /// public static Solid LightSkyBlue { get { return new Solid(Color.LightSkyBlue); } } /// /// LightSlateGray solid brush. /// public static Solid LightSlateGray { get { return new Solid(Color.LightSlateGray); } } /// /// LightSteelBlue solid brush. /// public static Solid LightSteelBlue { get { return new Solid(Color.LightSteelBlue); } } /// /// LightYellow solid brush. /// public static Solid LightYellow { get { return new Solid(Color.LightYellow); } } /// /// Lime solid brush. /// public static Solid Lime { get { return new Solid(Color.Lime); } } /// /// LimeGreen solid brush. /// public static Solid LimeGreen { get { return new Solid(Color.LimeGreen); } } /// /// Color.Linen solid brush. /// public static Solid Linen { get { return new Solid(Color.Linen); } } /// /// Color.Magenta solid brush. /// public static Solid Magenta { get { return new Solid(Color.Magenta); } } /// /// Maroon solid brush. /// public static Solid Maroon { get { return new Solid(Color.Maroon); } } /// /// MediumAquamarine solid brush. /// public static Solid MediumAquamarine { get { return new Solid(Color.MediumAquamarine); } } /// /// MediumBlue solid brush. /// public static Solid MediumBlue { get { return new Solid(Color.MediumBlue); } } /// /// MediumOrchid solid brush. /// public static Solid MediumOrchid { get { return new Solid(Color.MediumOrchid); } } /// /// MediumPurple solid brush. /// public static Solid MediumPurple { get { return new Solid(Color.MediumPurple); } } /// /// MediumSeaGreen solid brush. /// public static Solid MediumSeaGreen { get { return new Solid(Color.MediumSeaGreen); } } /// /// MediumSlateBlue solid brush. /// public static Solid MediumSlateBlue { get { return new Solid(Color.MediumSlateBlue); } } /// /// MediumSpringGreen solid brush. /// public static Solid MediumSpringGreen { get { return new Solid(Color.MediumSpringGreen); } } /// /// MediumTurquoise solid brush. /// public static Solid MediumTurquoise { get { return new Solid(Color.MediumTurquoise); } } /// /// MediumVioletRed solid brush. /// public static Solid MediumVioletRed { get { return new Solid(Color.MediumVioletRed); } } /// /// MidnightBlue solid brush. /// public static Solid MidnightBlue { get { return new Solid(Color.MidnightBlue); } } /// /// MintCream solid brush. /// public static Solid MintCream { get { return new Solid(Color.MintCream); } } /// /// MistyRose solid brush. /// public static Solid MistyRose { get { return new Solid(Color.MistyRose); } } /// /// Moccasin solid brush. /// public static Solid Moccasin { get { return new Solid(Color.Moccasin); } } /// /// NavajoWhite solid brush. /// public static Solid NavajoWhite { get { return new Solid(Color.NavajoWhite); } } /// /// Navy solid brush. /// public static Solid Navy { get { return new Solid(Color.Navy); } } /// /// OldLace solid brush. /// public static Solid OldLace { get { return new Solid(Color.OldLace); } } /// /// Olive solid brush. /// public static Solid Olive { get { return new Solid(Color.Olive); } } /// /// OliveDrab solid brush. /// public static Solid OliveDrab { get { return new Solid(Color.OliveDrab); } } /// /// Orange solid brush. /// public static Solid Orange { get { return new Solid(Color.Orange); } } /// /// OrangeRed solid brush. /// public static Solid OrangeRed { get { return new Solid(Color.OrangeRed); } } /// /// Orchid solid brush. /// public static Solid Orchid { get { return new Solid(Color.Orchid); } } /// /// PaleGoldenrod solid brush. /// public static Solid PaleGoldenrod { get { return new Solid(Color.PaleGoldenrod); } } /// /// PaleGreen solid brush. /// public static Solid PaleGreen { get { return new Solid(Color.PaleGreen); } } /// /// PaleTurquoise solid brush. /// public static Solid PaleTurquoise { get { return new Solid(Color.PaleTurquoise); } } /// /// PaleVioletRed solid brush. /// public static Solid PaleVioletRed { get { return new Solid(Color.PaleVioletRed); } } /// /// PapayaWhip solid brush. /// public static Solid PapayaWhip { get { return new Solid(Color.PapayaWhip); } } /// /// PeachPuff solid brush. /// public static Solid PeachPuff { get { return new Solid(Color.PeachPuff); } } /// /// Peru solid brush. /// public static Solid Peru { get { return new Solid(Color.Peru); } } /// /// Pink solid brush. /// public static Solid Pink { get { return new Solid(Color.Pink); } } /// /// Plum solid brush. /// public static Solid Plum { get { return new Solid(Color.Plum); } } /// /// PowderBlue solid brush. /// public static Solid PowderBlue { get { return new Solid(Color.PowderBlue); } } /// /// Purple solid brush. /// public static Solid Purple { get { return new Solid(Color.Purple); } } /// /// Red solid brush. /// public static Solid Red { get { return new Solid(Color.Red); } } /// /// RosyBrown solid brush. /// public static Solid RosyBrown { get { return new Solid(Color.RosyBrown); } } /// /// RoyalBlue solid brush. /// public static Solid RoyalBlue { get { return new Solid(Color.RoyalBlue); } } /// /// SaddleBrown solid brush. /// public static Solid SaddleBrown { get { return new Solid(Color.SaddleBrown); } } /// /// Salmon solid brush. /// public static Solid Salmon { get { return new Solid(Color.Salmon); } } /// /// SandyBrown solid brush. /// public static Solid SandyBrown { get { return new Solid(Color.SandyBrown); } } /// /// SeaGreen solid brush. /// public static Solid SeaGreen { get { return new Solid(Color.SeaGreen); } } /// /// SeaShell solid brush. /// public static Solid SeaShell { get { return new Solid(Color.SeaShell); } } /// /// Sienna solid brush. /// public static Solid Sienna { get { return new Solid(Color.Sienna); } } /// /// Silver solid brush. /// public static Solid Silver { get { return new Solid(Color.Silver); } } /// /// SkyBlue solid brush. /// public static Solid SkyBlue { get { return new Solid(Color.SkyBlue); } } /// /// SlateBlue solid brush. /// public static Solid SlateBlue { get { return new Solid(Color.SlateBlue); } } /// /// SlateGray solid brush. /// public static Solid SlateGray { get { return new Solid(Color.SlateGray); } } /// /// Snow solid brush. /// public static Solid Snow { get { return new Solid(Color.Snow); } } /// /// SpringGreen solid brush. /// public static Solid SpringGreen { get { return new Solid(Color.SpringGreen); } } /// /// SteelBlue solid brush. /// public static Solid SteelBlue { get { return new Solid(Color.SteelBlue); } } /// /// Tan solid brush. /// public static Solid Tan { get { return new Solid(Color.Tan); } } /// /// Teal solid brush. /// public static Solid Teal { get { return new Solid(Color.Teal); } } /// /// Thistle solid brush. /// public static Solid Thistle { get { return new Solid(Color.Thistle); } } /// /// Tomato solid brush. /// public static Solid Tomato { get { return new Solid(Color.Tomato); } } /// /// Transparent solid brush. /// public static Solid Transparent { get { return new Solid(Color.Transparent); } } /// /// Turquoise solid brush. /// public static Solid Turquoise { get { return new Solid(Color.Turquoise); } } /// /// Violet solid brush. /// public static Solid Violet { get { return new Solid(Color.Violet); } } /// /// Wheat solid brush. /// public static Solid Wheat { get { return new Solid(Color.Wheat); } } /// /// White solid brush. /// public static Solid White { get { return new Solid(Color.White); } } /// /// WhiteSmoke solid brush. /// public static Solid WhiteSmoke { get { return new Solid(Color.WhiteSmoke); } } /// /// Yellow solid brush. /// public static Solid Yellow { get { return new Solid(Color.Yellow); } } /// /// YellowGreen solid brush. /// public static Solid YellowGreen { get { return new Solid(Color.YellowGreen); } } #endregion } /// /// A brush with vertical gradient. /// public class Vertical : IRectangleBrush { private readonly Color c1_; private readonly Color c2_; /// /// Constructor /// /// top color [or bottom?] /// bottom color [or top?] public Vertical(Color c1, Color c2) { c1_ = c1; c2_ = c2; } /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The vertical brush public Brush Get(Rectangle rectangle) { return new LinearGradientBrush(rectangle, c1_, c2_, LinearGradientMode.Vertical); } #region DefaultBrushes /// /// Default brush - fades from faint blue to white. /// public static Vertical FaintBlueFade { get { return new Vertical(Color.FromArgb(200, 200, 255), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static Vertical FaintRedFade { get { return new Vertical(Color.FromArgb(255, 200, 200), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static Vertical FaintGreenFade { get { return new Vertical(Color.FromArgb(200, 255, 200), Color.FromArgb(255, 255, 255)); } } #endregion } /// /// Brush with vertical gradient that fades into center then out again. /// public class VerticalCenterFade : IRectangleBrush { private readonly Color c1_; private readonly Color c2_; /// /// Constructor /// /// inner color /// outer color public VerticalCenterFade(Color c1, Color c2) { c1_ = c1; c2_ = c2; } /// /// Gets a brush according to the supplied rectangle. /// /// the rectangle used to construct the brush /// The vertical center fade brush public Brush Get(Rectangle rectangle) { LinearGradientBrush brush = new LinearGradientBrush(rectangle, c1_, c2_, LinearGradientMode.Vertical); float[] relativeIntensities = {0.0f, 0.9f, 1.0f, 0.9f, 0.0f}; float[] relativePositions = {0.0f, 0.4f, 0.5f, 0.6f, 1.0f}; Blend blend = new Blend(); blend.Factors = relativeIntensities; blend.Positions = relativePositions; brush.Blend = blend; return brush; } #region DefaultBrushes /// /// Default brush - fades from faint blue to white. /// public static VerticalCenterFade FaintBlueFade { get { return new VerticalCenterFade(Color.FromArgb(200, 200, 255), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static VerticalCenterFade FaintRedFade { get { return new VerticalCenterFade(Color.FromArgb(255, 200, 200), Color.FromArgb(255, 255, 255)); } } /// /// Default brush - fades from faint red to white. /// public static VerticalCenterFade FaintGreenFade { get { return new VerticalCenterFade(Color.FromArgb(200, 255, 200), Color.FromArgb(255, 255, 255)); } } #endregion } } }