/// <summary> /// Perform rendering before child elements are rendered. /// </summary> /// <param name="context">Rendering context.</param> public override void RenderBefore(RenderContext context) { IPaletteElementColor elementColors = null; switch (State) { default: case PaletteState.Normal: elementColors = _drawTrackBar.StateNormal.Position; break; case PaletteState.Disabled: elementColors = _drawTrackBar.StateDisabled.Position; break; case PaletteState.Tracking: elementColors = _drawTrackBar.StateTracking.Position; break; case PaletteState.Pressed: elementColors = _drawTrackBar.StatePressed.Position; break; } context.Renderer.RenderGlyph.DrawTrackPositionGlyph(context, State, elementColors, ClientRectangle, _drawTrackBar.Orientation, _drawTrackBar.TickStyle); }
/// <summary> /// Update the the primary and backup palettes. /// </summary> /// <param name="primary">New primary palette.</param> /// <param name="backup">New backup palette.</param> public void SetPalettes(IPaletteElementColor primary, IPaletteElementColor backup) { // Store incoming alternatives _primary = primary; _backup = backup; }
/// <summary> /// Sets the inheritance parent. /// </summary> /// <param name="inheritTick">Source for inheriting tick values.</param> /// <param name="inheritTrack">Source for inheriting track values.</param> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritTick, IPaletteElementColor inheritTrack, IPaletteElementColor inheritPosition) { Tick.SetInherit(inheritTick); Track.SetInherit(inheritTrack); Position.SetInherit(inheritPosition); }
/// <summary> /// Sets the inheritence parent. /// </summary> /// <param name="inheritTick">Source for inheriting tick values.</param> /// <param name="inheritTrack">Source for inheriting track values.</param> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritTick, IPaletteElementColor inheritTrack, IPaletteElementColor inheritPosition) { _tickState.SetInherit(inheritTick); _trackState.SetInherit(inheritTrack); _positionState.SetInherit(inheritPosition); }
/// <summary> /// Initialize a new instance of the PaletteTrackBarPositionStates class. /// </summary> /// <param name="inheritPosition">Source for inheriting position values.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public PaletteTrackBarPositionStates(IPaletteElementColor inheritPosition, NeedPaintHandler needPaint) { Debug.Assert(inheritPosition != null); // Store the provided paint notification delegate NeedPaint = needPaint; // Create storage that maps onto the inherit instances _positionState = new PaletteElementColor(inheritPosition, needPaint); }
/// <summary> /// Initialize a new instance of the PaletteTrackBarPositionStates class. /// </summary> /// <param name="inheritPosition">Source for inheriting position values.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public PaletteTrackBarPositionStates(IPaletteElementColor inheritPosition, NeedPaintHandler needPaint) { Debug.Assert(inheritPosition != null); // Store the provided paint notification delegate NeedPaint = needPaint; // Create storage that maps onto the inherit instances Position = new PaletteElementColor(inheritPosition, needPaint); }
/// <summary> /// Initialize a new instance of the PaletteElementColorInheritOverride class. /// </summary> /// <param name="primary">First choice inheritence.</param> /// <param name="backup">Backup inheritence.</param> public PaletteElementColorInheritOverride(IPaletteElementColor primary, IPaletteElementColor backup) { Debug.Assert(primary != null); Debug.Assert(backup != null); // Store incoming alternatives _primary = primary; _backup = backup; // Default other state Apply = true; Override = true; OverrideState = PaletteState.Normal; }
/// <summary> /// Initialize a new instance of the PaletteElementColorInheritOverride class. /// </summary> /// <param name="primary">First choice inheritence.</param> /// <param name="backup">Backup inheritence.</param> public PaletteElementColorInheritOverride(IPaletteElementColor primary, IPaletteElementColor backup) { Debug.Assert(primary != null); Debug.Assert(backup != null); // Store incoming alternatives _primary = primary; _backup = backup; // Default other state _apply = true; _override = true; _state = PaletteState.Normal; }
/// <summary> /// Initialize a new instance of the PaletteElementColor class. /// </summary> /// <param name="inheritElementColor">Source for inheriting values.</param> /// <param name="needPaint">Delegate for notifying changes in value.</param> public PaletteElementColor(IPaletteElementColor inheritElementColor, NeedPaintHandler needPaint) { // Remember inheritance _inheritElementColor = inheritElementColor; // Store the provided paint notification delegate NeedPaint = needPaint; // Define default values _color1 = Color.Empty; _color2 = Color.Empty; _color3 = Color.Empty; _color4 = Color.Empty; _color5 = Color.Empty; }
/// <summary> /// Initialize a new instance of the PaletteElementColor class. /// </summary> /// <param name="inheritElementColor">Source for inheriting values.</param> /// <param name="needPaint">Delegate for notifying changes in value.</param> public PaletteElementColor(IPaletteElementColor inheritElementColor, NeedPaintHandler needPaint) { // Remember inheritance _inheritElementColor = inheritElementColor; // Store the provided paint notification delegate NeedPaint = needPaint; // Define default values _color1 = Color.Empty; _color2 = Color.Empty; _color3 = Color.Empty; _color4 = Color.Empty; _color5 = Color.Empty; }
/// <summary> /// Draw the track bar track glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="volumeControl">Drawing as a volume control or standard slider.</param> public override void DrawTrackGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool volumeControl) { // The position indicator leavesa gap at the left/right ends for horizontal and top/bottom for vertical // so we do not draw that last pixel so that when the indicator is at the end the track does not stick out if (orientation == Orientation.Horizontal) drawRect.Inflate(-1, 0); else drawRect.Inflate(0, -1); using (Pen border1Pen = new Pen(elementPalette.GetElementColor1(state)), border2Pen = new Pen(elementPalette.GetElementColor2(state))) { using (SolidBrush insideBrush = new SolidBrush(elementPalette.GetElementColor3(state))) { if (!volumeControl) { context.Graphics.FillRectangle(insideBrush, drawRect.X + 1, drawRect.Y + 1, drawRect.Width - 2, drawRect.Height - 2); context.Graphics.DrawLines(border1Pen, new Point[]{ new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.X, drawRect.Y), new Point(drawRect.X, drawRect.Bottom - 1)}); context.Graphics.DrawLines(border2Pen, new Point[]{ new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1)}); } else { if (orientation == Orientation.Horizontal) { using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillPolygon(insideBrush, new Point[]{ new Point(drawRect.X, drawRect.Bottom - 2), new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 2)}); context.Graphics.DrawLines(border1Pen, new Point[]{ new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 2), new Point(drawRect.Right - 1, drawRect.Y)}); } } else { using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillPolygon(insideBrush, new Point[]{ new Point(drawRect.X + 1, drawRect.Bottom - 1), new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.X, drawRect.Y + 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1)}); context.Graphics.DrawLines(border1Pen, new Point[]{ new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.X, drawRect.Y + 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1), new Point(drawRect.Right - 1, drawRect.Y + 1)}); } } } } } }
/// <summary> /// Sets the inheritence parent. /// </summary> public void SetInherit(IPaletteElementColor inheritElementColor) { _inheritElementColor = inheritElementColor; }
/// <summary> /// Sets the inheritence parent. /// </summary> /// <param name="inheritTick">Source for inheriting tick values.</param> /// <param name="inheritTrack">Source for inheriting track values.</param> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritTick, IPaletteElementColor inheritTrack, IPaletteElementColor inheritPosition) { _tickState.SetInherit(inheritTick); _trackState.SetInherit(inheritTrack); _positionState.SetInherit(inheritPosition); }
/// <summary> /// Sets the inheritence parent. /// </summary> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritPosition) { Position.SetInherit(inheritPosition); }
/// <summary> /// Draw the track bar track glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="volumeControl">Drawing as a volume control or standard slider.</param> public override void DrawTrackGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool volumeControl) { // The position indicator leavesa gap at the left/right ends for horizontal and top/bottom for vertical // so we do not draw that last pixel so that when the indicator is at the end the track does not stick out if (orientation == Orientation.Horizontal) { drawRect.Inflate(-1, 0); } else { drawRect.Inflate(0, -1); } using (Pen border1Pen = new Pen(elementPalette.GetElementColor1(state))) { using (SolidBrush insideBrush = new SolidBrush(elementPalette.GetElementColor2(state))) { if (!volumeControl) { context.Graphics.FillRectangle(insideBrush, drawRect.X + 1, drawRect.Y + 1, drawRect.Width - 2, drawRect.Height - 2); context.Graphics.DrawLines(border1Pen, new Point[] { new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.X, drawRect.Y), new Point(drawRect.X, drawRect.Bottom - 1) }); context.Graphics.DrawLines(border1Pen, new Point[] { new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1) }); //context.Graphics.FillRectangle(insideBrush, drawRect); //context.Graphics.DrawRectangle(border1Pen, drawRect); } else { if (orientation == Orientation.Horizontal) { using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillPolygon(insideBrush, new Point[] { new Point(drawRect.X, drawRect.Bottom - 2), new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 2) }); context.Graphics.DrawLines(border1Pen, new Point[] { new Point(drawRect.Right - 1, drawRect.Y), new Point(drawRect.Right - 1, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X, drawRect.Bottom - 2), new Point(drawRect.Right - 1, drawRect.Y) }); } } else { using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillPolygon(insideBrush, new Point[] { new Point(drawRect.X + 1, drawRect.Bottom - 1), new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.X, drawRect.Y + 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1) }); context.Graphics.DrawLines(border1Pen, new Point[] { new Point(drawRect.Right - 1, drawRect.Y + 1), new Point(drawRect.X, drawRect.Y + 1), new Point(drawRect.X, drawRect.Bottom - 1), new Point(drawRect.X + 1, drawRect.Bottom - 1), new Point(drawRect.Right - 1, drawRect.Y + 1) }); } } } } } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="state"></param> /// <param name="elementPalette"></param> /// <param name="drawRect"></param> /// <param name="orientation"></param> /// <param name="topRight"></param> /// <param name="positionSize"></param> /// <param name="minimum"></param> /// <param name="maximum"></param> /// <param name="frequency"></param> public override void DrawTrackTicksGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool topRight, Size positionSize, int minimum, int maximum, int frequency) { base.DrawTrackTicksGlyph(context, state, elementPalette, drawRect, orientation, topRight, positionSize, minimum, maximum, frequency); }
/// <summary> /// Draw the track bar ticks glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain ticks.</param> /// <param name="orientation">Orientation of the drawing area.</param> /// <param name="topRight">Drawing on the topRight or the bottomLeft.</param> /// <param name="positionSize">Size of the position indicator.</param> /// <param name="minimum">First value.</param> /// <param name="maximum">Last value.</param> /// <param name="frequency">How often ticks are drawn.</param> public override void DrawTrackTicksGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool topRight, Size positionSize, int minimum, int maximum, int frequency) { // Never want a frequency less than 1 if (frequency <= 0) frequency = 1; float range = maximum - minimum; using (Pen tickPen = new Pen(elementPalette.GetElementColor1(state))) { if (orientation == Orientation.Horizontal) { // Reduce area by half the position indicator on each side int halfPosition = positionSize.Width / 2; drawRect.X += halfPosition; drawRect.Width -= positionSize.Width; // Draw a marker for each value between min and max float factor = (range == 0) ? float.MinValue : (float)drawRect.Width / range; float top = drawRect.Y + 1; float bottom = drawRect.Bottom - 2; for (int i = minimum, y = 0; i <= maximum; i += frequency, y += frequency) { float offset = drawRect.X + (factor * y); if (!topRight) { top = drawRect.Y + 2; bottom = drawRect.Bottom - 2; if ((i == minimum) || (i == maximum)) top -= 1; } else { top = drawRect.Y + 1; bottom = drawRect.Bottom - 3; if ((i == minimum) || (i == maximum)) bottom += 1; } context.Graphics.DrawLine(tickPen, offset, top, offset, bottom); } } else { // Reduce area by half the position indicator on each side int halfPosition = positionSize.Height / 2; drawRect.Y += halfPosition; drawRect.Height -= positionSize.Height; // Draw a marker for each value between min and max float factor = (range == 0) ? float.MinValue : (float)drawRect.Height / range; float left = drawRect.X + 1; float right = drawRect.Right - 2; for (int i = minimum, y = 0; i <= maximum; i += frequency, y += frequency) { float offset = drawRect.Y + (factor * y); if (topRight) { left = drawRect.X + 2; right = drawRect.Right - 2; if ((i == minimum) || (i == maximum)) left -= 1; } else { left = drawRect.X + 1; right = drawRect.Right - 3; if ((i == minimum) || (i == maximum)) right += 1; } context.Graphics.DrawLine(tickPen, left, offset, right, offset); } } } }
/// <summary> /// Draw the track bar position glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="tickStyle">Tick marks that surround the position.</param> public override void DrawTrackPositionGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, TickStyle tickStyle) { GraphicsPath border = null; drawRect.Inflate(-1, -1); if (orientation == Orientation.Horizontal) { switch (tickStyle) { case TickStyle.None: case TickStyle.Both: border = CreatePositionPathsBoth(drawRect); break; case TickStyle.TopLeft: border = CreatePositionPathsTop(drawRect); break; case TickStyle.BottomRight: border = CreatePositionPathsBottom(drawRect); break; } } else { switch (tickStyle) { case TickStyle.None: case TickStyle.Both: border = CreatePositionPathsBoth(drawRect); break; case TickStyle.TopLeft: border = CreatePositionPathsLeft(drawRect); break; case TickStyle.BottomRight: border = CreatePositionPathsRight(drawRect); break; } } if (border != null) { using (AntiAlias aa = new AntiAlias(context.Graphics)) { using (SolidBrush insideBrush = new SolidBrush(elementPalette.GetElementColor2(state))) context.Graphics.FillPath(insideBrush, border); using (Pen borderPen = new Pen(elementPalette.GetElementColor1(state))) context.Graphics.DrawPath(borderPen, border); } border.Dispose(); } }
/// <summary> /// Draw the track bar position glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="tickStyle">Tick marks that surround the position.</param> public abstract void DrawTrackPositionGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, TickStyle tickStyle);
/// <summary> /// Sets the inheritence parent. /// </summary> public void SetInherit(IPaletteElementColor inheritElementColor) { _inheritElementColor = inheritElementColor; }
/// <summary> /// Update the the primary and backup palettes. /// </summary> /// <param name="primary">New primary palette.</param> /// <param name="backup">New backup palette.</param> public void SetPalettes(IPaletteElementColor primary, IPaletteElementColor backup) { // Store incoming alternatives _primary = primary; _backup = backup; }
/// <summary> /// Sets the inheritence parent. /// </summary> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritPosition) { _positionState.SetInherit(inheritPosition); }
/// <summary> /// Draw the track bar track glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="volumeControl">Drawing as a volume control or standard slider.</param> public abstract void DrawTrackGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool volumeControl);
/// <summary> /// Draw the track bar position glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain the track.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="tickStyle">Tick marks that surround the position.</param> public override void DrawTrackPositionGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, TickStyle tickStyle) { GraphicsPath outside = null; GraphicsPath border = null; GraphicsPath inside = null; if (orientation == Orientation.Horizontal) { switch (tickStyle) { case TickStyle.None: case TickStyle.Both: CreatePositionPathsBoth(drawRect, ref outside, ref border, ref inside); break; case TickStyle.TopLeft: CreatePositionPathsTop(drawRect, ref outside, ref border, ref inside); break; case TickStyle.BottomRight: CreatePositionPathsBottom(drawRect, ref outside, ref border, ref inside); break; } } else { switch (tickStyle) { case TickStyle.None: case TickStyle.Both: CreatePositionPathsBoth(drawRect, ref outside, ref border, ref inside); break; case TickStyle.TopLeft: CreatePositionPathsLeft(drawRect, ref outside, ref border, ref inside); break; case TickStyle.BottomRight: CreatePositionPathsRight(drawRect, ref outside, ref border, ref inside); break; } } if ((outside != null) && (border != null) && (inside != null)) { using (AntiAlias aa = new AntiAlias(context.Graphics)) { using(Pen outsidePen = new Pen(elementPalette.GetElementColor1(state)), borderPen = new Pen(elementPalette.GetElementColor2(state))) { context.Graphics.DrawPath(outsidePen, outside); using(SolidBrush insideBrush = new SolidBrush(elementPalette.GetElementColor3(state))) context.Graphics.FillPath(insideBrush, border); context.Graphics.DrawPath(borderPen, border); using (LinearGradientBrush innerBrush = new LinearGradientBrush(inside.GetBounds(), elementPalette.GetElementColor4(state), elementPalette.GetElementColor5(state), 90f)) { context.Graphics.FillPath(innerBrush, inside); } } } outside.Dispose(); border.Dispose(); inside.Dispose(); } }
/// <summary> /// Draw the track bar ticks glyph. /// </summary> /// <param name="context">Render context.</param> /// <param name="state">Element state.</param> /// <param name="elementPalette">Source of palette colors.</param> /// <param name="drawRect">Drawing rectangle that should contain ticks.</param> /// <param name="orientation">Orientation of the drawing area.</param> /// <param name="topRight">Drawing on the topRight or the bottomLeft.</param> /// <param name="positionSize">Size of the position indicator.</param> /// <param name="minimum">First value.</param> /// <param name="maximum">Last value.</param> /// <param name="frequency">How often ticks are drawn.</param> public abstract void DrawTrackTicksGlyph(RenderContext context, PaletteState state, IPaletteElementColor elementPalette, Rectangle drawRect, Orientation orientation, bool topRight, Size positionSize, int minimum, int maximum, int frequency);
/// <summary> /// Sets the inheritence parent. /// </summary> /// <param name="inheritPosition">Source for inheriting position values.</param> public void SetInherit(IPaletteElementColor inheritPosition) { _positionState.SetInherit(inheritPosition); }