using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Netron.Diagramming.Core {
///
/// The art pallet consists of the often used colors, brushes, font etc. used by the painting methods.
/// You can set the pallet at starup of the diagram control
///
public static class ArtPalette {
#region Fields
private static Font mTitleFont = new Font("Arial", 20F, FontStyle.Bold);
// ------------------------------------------------------------------
///
/// The default color for new pages.
///
// ------------------------------------------------------------------
static Color mDefaultPageColor = Color.White;
// ------------------------------------------------------------------
///
/// The default color for the page background.
///
// ------------------------------------------------------------------
static Color mDefaultPageBackgroundColor = Color.DarkGray;
// ------------------------------------------------------------------
///
/// whether shadows of entities are painted
///
// ------------------------------------------------------------------
private static bool mEnableShadows = true;
// ------------------------------------------------------------------
///
/// the font for the marks on the rulers
///
// ------------------------------------------------------------------
private static Font mRulerFont = new Font(
"Arial", 7.0F, FontStyle.Regular);
// ------------------------------------------------------------------
///
/// the ruler pen
///
// ------------------------------------------------------------------
private static Pen mRulerPen = Pens.Black;
// ------------------------------------------------------------------
///
/// the background of the rulers
///
// ------------------------------------------------------------------
private static Brush mRulerFillBrush = Brushes.White;
///
/// the brush with which to paint the ghosts
///
private static Brush mGhostBrush = new SolidBrush(Color.FromArgb(120, Color.LightYellow));
///
/// the ghost pen
///
private static Pen mGhostPen = new Pen(Color.Green, 1.5f);
///
/// the pen to draw the interconnecting folder lines
///
private static Pen mFolderLinesPen = new Pen(Color.Gray, 1.0F);
///
/// the pen used for drawing the tracker
///
private static Pen mTrackerPen = new Pen(Color.DimGray, 1.5F);
///
/// the brush used to paint the grips
///
private static Brush mGripBrush = Brushes.WhiteSmoke;
///
/// Default font for drawing text
///
private static Font mDefaultFont = new Font("Tahoma", 8.5F);
///
/// the font used to draw bold text
///
private static Font mDefaultBoldFont = new Font("Tahoma", 8.5F, FontStyle.Bold);
///
/// randomizer for generating random colors of a certain style
///
private static Random rnd = new Random();
///
/// Default black pen
///
private static Pen mBlackPen = new Pen(Brushes.Black, 1F);
///
/// the global shadow brush
///
private static Brush mShadowBrush = new SolidBrush(Color.FromArgb(30, Color.Black));
///
/// Default red pen
///
private static Pen mHighlightPen = new Pen(Brushes.OrangeRed, 1.7F);
///
/// the global shadow pen
///
private static Pen mShadowPen = new Pen(Color.FromArgb(30, Color.Black), 1F);
///
/// the pen used to paint the connections
///
private static Pen mConnectionPen = new Pen(Color.Silver, 1F);
///
/// the pen used to paint the highlighted connection
///
private static Pen mConnectionHighlightPen = new Pen(Color.Red, 2.5F);
private static IPaintStyle mTransparentPaintStyle = new SolidPaintStyle(Color.Transparent);
#endregion
#region Properties
// ------------------------------------------------------------------
///
/// Gets or sets the default color for new pages.
///
// ------------------------------------------------------------------
public static Color DefaultPageColor {
get {
return mDefaultPageColor;
}
set {
mDefaultPageColor = value;
}
}
// ------------------------------------------------------------------
///
/// Gets or sets the default color for the background of new pages.
///
// ------------------------------------------------------------------
public static Color DefaultPageBackgroundColor {
get {
return mDefaultPageBackgroundColor;
}
set {
mDefaultPageBackgroundColor = value;
}
}
///
/// Gets or sets the title font used on the canvas to display the title of the current page.
///
/// The title font.
public static Font TitleFont {
get { return mTitleFont; }
set { mTitleFont = value; }
}
///
/// Gets or sets the global value indicating whether to enable entities shadows.
///
/// true to enable shadows; otherwise, false.
public static bool EnableShadows {
get { return mEnableShadows; }
set { mEnableShadows = value; }
}
///
/// Gets the ruler font.
///
/// The ruler font.
public static Font RulerFont {
get { return mRulerFont; }
}
///
/// Gets the pen with which the ruler is drawn.
///
/// The ruler pen.
public static Pen RulerPen {
get { return mRulerPen; }
}
///
/// Gets the ruller fill brush.
///
/// The ruller fill brush.
public static Brush RullerFillBrush {
get {
return mRulerFillBrush;
}
}
///
/// Gets the brush with which the ghosts are painted.
///
/// The ghost brush.
public static Brush GhostBrush {
get {
return mGhostBrush;
}
}
///
/// Gets the pen to draw the multi-point ghost lines.
///
/// The ghost pen.
public static Pen GhostPen {
get {
return mGhostPen;
}
}
///
/// Gets the pen used to draw the dashed line between nodes.
///
/// The folder lines pen.
public static Pen FolderLinesPen {
get {
return mFolderLinesPen;
}
}
///
/// Gets or sets the connection pen.
///
/// The connection pen.
public static Pen ConnectionPen {
get {
return mConnectionPen;
}
set {
mConnectionPen = value;
}
}
///
/// Gets or sets the pen used to paint the highlighted connection.
///
/// The connection highlight pen.
public static Pen ConnectionHighlightPen {
get {
return mConnectionHighlightPen;
}
set {
mConnectionHighlightPen = value;
}
}
///
/// Gets or sets the grip brush.
///
/// The grip brush.
public static Brush GripBrush {
get { return mGripBrush; }
set { mGripBrush = value; }
}
#endregion
#region Methods
///
/// Inits the static instance.
///
public static void Init() {
mTrackerPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
mBlackPen.LineJoin = LineJoin.Round;
//AdjustableArrowCap ccap = new AdjustableArrowCap(5, 7, true);
//mConnectionPen.EndCap = LineCap.Custom;
//mConnectionPen.CustomEndCap = ccap;
//mConnectionHighlightPen.EndCap = LineCap.Custom;
//mConnectionHighlightPen.CustomEndCap = ccap;
mFolderLinesPen.DashStyle = DashStyle.Dot;
}
///
/// Gets or sets the default font to render text on the canvas.
///
/// The font.
public static Font DefaultFont {
get {
return ArtPalette.mDefaultFont;
}
set {
ArtPalette.mDefaultFont = value;
}
}
///
/// Gets or sets the default bold font to render text on the canvas.
///
/// The font.
public static Font DefaultBoldFont {
get {
return ArtPalette.mDefaultBoldFont;
}
set {
ArtPalette.mDefaultBoldFont = value;
}
}
///
/// Gets the black pen.
///
/// The black pen.
public static Pen BlackPen {
get {
return ArtPalette.mBlackPen;
}
set {
ArtPalette.mBlackPen = value;
}
}
///
/// Gets the tracker pen.
///
/// The red pen.
public static Pen TrackerPen {
get {
return ArtPalette.mTrackerPen;
}
set { ArtPalette.mTrackerPen = value; }
}
///
/// Gets the red pen.
///
/// The red pen.
public static Pen HighlightPen {
get {
return ArtPalette.mHighlightPen;
}
set {
ArtPalette.mHighlightPen = value;
}
}
///
/// Gets the shadow brush.
///
/// The shadow brush.
public static Brush ShadowBrush {
get {
return ArtPalette.mShadowBrush;
}
set {
ArtPalette.mShadowBrush = value;
}
}
///
/// Gets the shadow pen to paint the shadow of the connections.
///
/// The shadow pen.
public static Pen ConnectionShadow {
get {
return ArtPalette.mShadowPen;
}
set {
ArtPalette.mShadowPen = value;
}
}
///
/// Gets a random color from the whole available color spectrum.
///
/// The random color.
///
///
///
/// wdfgsdfgsdfs
///
public static Color RandomColor {
get {
return Color.FromArgb(rnd.Next(10, 250), rnd.Next(10, 250), rnd.Next(10, 250));
}
}
///
/// Gets a random blue color.
/// You can generate any variation of a certain color range by specifying the HSV range and a utility function will convert it to
/// an RGB value ().
///
///
/// The random blues.
public static Color RandomBlues {
get {
return (Color)Utils.HSL2RGB(
(rnd.NextDouble() * 20D + 150D) / 255D,
(rnd.NextDouble() * 150D + 100D) / 255D,
(rnd.NextDouble() * 50D + 150D) / 255D);
}
}
///
/// Gets a random low saturation color.
///
/// The random color.
public static Color RandomLowSaturationColor {
get {
return (Color)Utils.HSL2RGB(
(rnd.NextDouble() * 255D) / 255D,
(rnd.NextDouble() * 20D + 30D) / 255D,
(rnd.NextDouble() * 20D + 130D) / 255D);
}
}
///
/// Gets the solid brush.
///
/// The color.
/// The alpha.
///
public static Brush GetSolidBrush(Color color, int alpha) {
return new SolidBrush(Color.FromArgb(alpha, color));
}
///
/// Gets the gradient brush.
///
/// The start color.
/// The end color.
/// The rectangle.
/// The angle.
///
public static Brush GetGradientBrush(Color startColor, Color endColor, Rectangle rectangle, float angle) {
return new LinearGradientBrush(rectangle, startColor, endColor, angle);
}
///
/// Gets the default solid .
///
///
public static IPaintStyle GetDefaultSolidPaintStyle() {
return new SolidPaintStyle(ArtPalette.RandomLowSaturationColor);
}
///
/// Gets the default gradient .
///
///
public static IPaintStyle GetDefaultGradientPaintStyle() {
return new GradientPaintStyle();
}
///
/// Gets the transparent .
///
///
public static IPaintStyle GetTransparentPaintStyle() {
return mTransparentPaintStyle;
}
///
/// Returns the default paint style for the whole control.
///
///
public static IPaintStyle GetDefaultPaintStyle() {
return GetDefaultGradientPaintStyle();
}
///
/// Gets the default .
///
///
public static IPenStyle GetDefaultPenStyle() {
return new PenStyle(); //this returns a black, standard pen.
}
///
/// The used when the ConnectorStyle is
/// 'Simple'.
///
///
public static IPenStyle GetSimpleConnectorPenStyle() {
LinePenStyle penStyle = new LinePenStyle();
penStyle.DashStyle = DashStyle.Solid;
penStyle.Color = Color.Blue;
return penStyle;
}
///
/// Returns the used when the
/// ConnectorStyle is 'Simple'.
///
///
public static IPaintStyle GetSimpleConnectorPaintStyle() {
return new SolidPaintStyle(Color.Transparent);
}
#endregion
}
}