using System.Drawing; using System.Drawing.Drawing2D; using JD.Application.View.WindowLess; using JD.Collections; namespace JD.Timeline.View { /// /// Groups common style properties. /// /// /// Holds a cache of GDI resources to avoid creating and deleted gdi handles on each paint. public class StyleSheet { #region Cache private static readonly PenCache _penCache = new PenCache(); private static readonly BrushCache _brushCache = new BrushCache(); public static PenCache Pens { get { return _penCache; } } public static BrushCache Brushes { get { return _brushCache; } } public static StringFormat EllipsisStringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter }; #endregion #region Constants public static Color LineColor = Color.FromArgb(60, 60, 60); public static Color TrackLightColor = Color.FromArgb(78, 78, 78); public static Color TrackDarkColor = Color.FromArgb(70, 70, 70); public static Color TrackSelectedLightColor = Color.DodgerBlue.Add(10); public static Color TrackSelectedDarkColor = Color.DodgerBlue.Add(-10); public static Color TrackForeColor = Color.FromArgb(180, 180, 180); public static Color BackgroundColor = Color.FromArgb(78, 78, 78); public static Color ClipEdgeColor = Color.FromArgb(128, 130, 129); public static Color ClipEdgeSelectedColor = Color.FromArgb(228, 230, 221); public static Brush CurvePointBrush = Brushes[Color.Yellow]; public static Pen CurvePointPen = Pens[Color.Gray]; #endregion #region Methods public static Brush GetTrackTreeBrush(Rectangle bounds, bool isAlternate, bool isSelected) { return GetTrackBrush(bounds, isAlternate, isSelected, 255); } public static Brush GetTrackBrush(Rectangle bounds, bool isAlternate) { return GetTrackBrush(bounds, isAlternate, false, 200); } public static Brush GetTrackBrush(Rectangle bounds, bool isAlternate, bool selected, int alpha) { var lightColor = (selected ? TrackSelectedLightColor : TrackLightColor).WithAlpha(alpha); var darkColor = (selected ? TrackSelectedDarkColor : TrackDarkColor).WithAlpha(alpha); if (isAlternate) { lightColor = lightColor.Add(15); darkColor = darkColor.Add(15); } return new LinearGradientBrush(bounds, lightColor, darkColor, LinearGradientMode.Vertical); } #endregion #region Nested public class PenCache : AbstractKeyedCache { protected override Pen CreateValue(Color key) { return new Pen(key); } } public class BrushCache : AbstractKeyedCache { protected override Brush CreateValue(Color key) { return new SolidBrush(key); } } #endregion } }