/// <summary> /// Gets the border width. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Border width.</returns> public int GetBorderWidth(PaletteState state) { if (Width != -1) return Width; else return _inherit.GetBorderWidth(state); }
/// <summary> /// Gets the border width. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Border width.</returns> public override int GetBorderWidth(PaletteState state) { if (Apply) { int ret = _primary.GetBorderWidth(Override ? OverrideState : state); if (ret == -1) { ret = _backup.GetBorderWidth(state); } return(ret); } else { return(_backup.GetBorderWidth(state)); } }
/// <summary> /// Gets the border width. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Border width.</returns> public int GetBorderWidth(PaletteState state) { if (Width != -1) { return(Width); } else { return(_inherit.GetBorderWidth(state)); } }
/// <summary> /// Gets the border width. /// </summary> /// <param name="style">Border style.</param> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Integer width.</returns> public override int GetBorderWidth(PaletteBorderStyle style, PaletteState state) { IPaletteBorder inherit = GetInherit(state); if (inherit != null) { return(inherit.GetBorderWidth(state)); } else { return(Target.GetBorderWidth(style, state)); } }
/// <summary> /// Gets the border width. /// </summary> /// <param name="style">Border style.</param> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Integer width.</returns> public override int GetBorderWidth(PaletteBorderStyle style, PaletteState state) { IPaletteBorder inherit = GetInherit(state); return(inherit?.GetBorderWidth(state) ?? Target.GetBorderWidth(style, state)); }
/// <summary> /// Gets the border width. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Border width.</returns> public override int GetBorderWidth(PaletteState state) => _inherit.GetBorderWidth(state);
/// <summary> /// Generate a graphics path that encloses the border itself. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Target rectangle.</param> /// <param name="palette">Palette used for drawing.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <param name="state">State associated with rendering.</param> /// <param name="tabBorderStyle">Style of tab border.</param> /// <returns>GraphicsPath instance.</returns> public override GraphicsPath GetTabBorderPath(RenderContext context, Rectangle rect, IPaletteBorder palette, VisualOrientation orientation, PaletteState state, TabBorderStyle tabBorderStyle) { Debug.Assert(context != null); Debug.Assert(palette != null); // Validate parameter references if (context == null) throw new ArgumentNullException("context"); if (palette == null) throw new ArgumentNullException("palette"); Debug.Assert(context.Control != null); Debug.Assert(!context.Control.IsDisposed); // Use helper to create a border path in middle of the pen return CreateTabBorderBackPath(context.Control.RightToLeft, state, false, rect, palette.GetBorderWidth(state), tabBorderStyle, orientation, (palette.GetBorderGraphicsHint(state) == PaletteGraphicsHint.AntiAlias)); }
/// <summary> /// Draw border on the inside edge of the specified rectangle. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Target rectangle.</param> /// <param name="palette">Palette used for drawing.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <param name="state">State associated with rendering.</param> public override void DrawBorder(RenderContext context, Rectangle rect, IPaletteBorder palette, VisualOrientation orientation, PaletteState state) { Debug.Assert(context != null); Debug.Assert(palette != null); // Validate parameter references if (context == null) throw new ArgumentNullException("context"); if (palette == null) throw new ArgumentNullException("palette"); Debug.Assert(context.Control != null); Debug.Assert(!context.Control.IsDisposed); PaletteDrawBorders borders = palette.GetBorderDrawBorders(state); // Is there anything to actually draw? if ((rect.Width > 0) && (rect.Height > 0) && CommonHelper.HasABorder(borders)) { // Only use anti aliasing if the border is rounded SmoothingMode smoothMode = (palette.GetBorderRounding(state) > 0 ? SmoothingMode.AntiAlias : SmoothingMode.Default); // We want to draw using anti aliasing for a nice smooth effect using (GraphicsHint hint = new GraphicsHint(context.Graphics, palette.GetBorderGraphicsHint(state))) { // Cache commonly used values int borderWidth = palette.GetBorderWidth(state); // Get the orientation correct borders value borders = CommonHelper.OrientateDrawBorders(borders, orientation); // Is there any border to actually draw? if (borderWidth > 0) { using (Clipping clip = new Clipping(context.Graphics, rect)) { // We always create the first border path variant GraphicsPath borderPath0 = CreateBorderBackPath(true, true, rect, borders, borderWidth, palette.GetBorderRounding(state), (smoothMode == SmoothingMode.AntiAlias), 0); GraphicsPath borderPath1 = null; // We only need the second border path if the two borders used are opposite each other if ((borders == PaletteDrawBorders.TopBottom) || (borders == PaletteDrawBorders.LeftRight)) { borderPath1 = CreateBorderBackPath(true, true, rect, borders, borderWidth, palette.GetBorderRounding(state), (smoothMode == SmoothingMode.AntiAlias), 1); } // Get the rectangle to use when dealing with gradients Rectangle gradientRect = context.GetAlignedRectangle(palette.GetBorderColorAlign(state), rect); // Use standard helper routine to create appropriate color brush PaletteColorStyle colorStyle = palette.GetBorderColorStyle(state); using (Pen borderPen = new Pen(CreateColorBrush(gradientRect, palette.GetBorderColor1(state), palette.GetBorderColor2(state), colorStyle, palette.GetBorderColorAngle(state), orientation), borderWidth)) { if (colorStyle == PaletteColorStyle.Dashed) borderPen.DashPattern = new float[] { 2, 2 }; context.Graphics.DrawPath(borderPen, borderPath0); // Optionally also draw the second path if (borderPath1 != null) context.Graphics.DrawPath(borderPen, borderPath1); } Image borderImage = palette.GetBorderImage(state); PaletteImageStyle borderImageStyle = palette.GetBorderImageStyle(state); // Do we need to draw the image? if (ShouldDrawImage(borderImage)) { // Get the rectangle to use when dealing with gradients Rectangle imageRect = context.GetAlignedRectangle(palette.GetBorderImageAlign(state), rect); // Use standard helper routine to create appropriate image brush using (Pen borderPen = new Pen(CreateImageBrush(imageRect, borderImage, borderImageStyle), borderWidth)) { context.Graphics.DrawPath(borderPen, borderPath0); // Optionally also draw the second path if (borderPath1 != null) context.Graphics.DrawPath(borderPen, borderPath1); } } // Remember to dispose of resources borderPath0.Dispose(); if (borderPath1 != null) borderPath1.Dispose(); } } } } }
/// <summary> /// Generate a graphics path that is the outside edge of the border. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Target rectangle.</param> /// <param name="palette">Palette used for drawing.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <param name="state">State associated with rendering.</param> /// <returns>GraphicsPath instance.</returns> public override GraphicsPath GetOutsideBorderPath(RenderContext context, Rectangle rect, IPaletteBorder palette, VisualOrientation orientation, PaletteState state) { Debug.Assert(context != null); Debug.Assert(palette != null); // Validate parameter references if (context == null) throw new ArgumentNullException("context"); if (palette == null) throw new ArgumentNullException("palette"); Debug.Assert(context.Control != null); Debug.Assert(!context.Control.IsDisposed); // Use helper to create a border path on the outside return CreateBorderBackPath(true, false, rect, CommonHelper.OrientateDrawBorders(palette.GetBorderDrawBorders(state), orientation), palette.GetBorderWidth(state), palette.GetBorderRounding(state), (palette.GetBorderGraphicsHint(state) == PaletteGraphicsHint.AntiAlias), 0); }
/// <summary> /// Gets the padding used to position display elements completely inside border drawing. /// </summary> /// <param name="context">View layout context.</param> /// <param name="palette">Palette used for drawing.</param> /// <param name="state">State associated with rendering.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <param name="tabBorderStyle">Style of tab border.</param> /// <returns>Padding structure detailing all four edges.</returns> public override Padding GetTabBorderDisplayPadding(ViewLayoutContext context, IPaletteBorder palette, PaletteState state, VisualOrientation orientation, TabBorderStyle tabBorderStyle) { Debug.Assert(palette != null); // Validate parameter reference if (palette == null) throw new ArgumentNullException("palette"); // Get the width of the border int borderWidth = palette.GetBorderWidth(state); // Cache the right to left setting bool rtl = (context.Control.RightToLeft == RightToLeft.Yes); Padding ret = Padding.Empty; switch (tabBorderStyle) { case TabBorderStyle.DockEqual: case TabBorderStyle.SquareEqualMedium: case TabBorderStyle.SquareEqualSmall: case TabBorderStyle.SquareEqualLarge: case TabBorderStyle.RoundedEqualMedium: case TabBorderStyle.RoundedEqualSmall: case TabBorderStyle.RoundedEqualLarge: ret = new Padding(borderWidth, borderWidth, borderWidth, 0); break; case TabBorderStyle.DockOutsize: ret = new Padding(borderWidth + _spacingTabDockOutsize, borderWidth + _spacingTabSquareOutsizeLarge, borderWidth + _spacingTabDockOutsize, 0); break; case TabBorderStyle.SquareOutsizeMedium: case TabBorderStyle.SquareOutsizeSmall: case TabBorderStyle.SquareOutsizeLarge: case TabBorderStyle.RoundedOutsizeMedium: case TabBorderStyle.RoundedOutsizeSmall: case TabBorderStyle.RoundedOutsizeLarge: ret = new Padding(borderWidth + _spacingTabOutsizePadding, borderWidth + _spacingTabOutsizePadding, borderWidth + _spacingTabOutsizePadding, 0); break; case TabBorderStyle.SlantEqualNear: case TabBorderStyle.SlantOutsizeNear: // Calculte the extra needed for the outsize variant int x = (tabBorderStyle == TabBorderStyle.SlantOutsizeNear ? _spacingTabOutsizePadding : 0); switch(orientation) { case VisualOrientation.Top: if (rtl) ret = new Padding(borderWidth + x, borderWidth + x, borderWidth + x + _spacingTabSlantPadding - 1, 0); else ret = new Padding(borderWidth + x + _spacingTabSlantPadding - 1, borderWidth + x, borderWidth + x, 0); break; case VisualOrientation.Left: ret = new Padding(borderWidth + x + _spacingTabSlantPadding - 1, borderWidth + x, borderWidth + x, 0); break; case VisualOrientation.Right: ret = new Padding(borderWidth + x, borderWidth + x, borderWidth + x + _spacingTabSlantPadding - 1, 0); break; case VisualOrientation.Bottom: if (rtl) ret = new Padding(borderWidth + x + _spacingTabSlantPadding - 1, borderWidth + x, borderWidth + x, 0); else ret = new Padding(borderWidth + x, borderWidth + x, borderWidth + x + _spacingTabSlantPadding - 1, 0); break; } break; case TabBorderStyle.SlantEqualFar: case TabBorderStyle.SlantOutsizeFar: // Calculte the extra needed for the outsize variant int y = (tabBorderStyle == TabBorderStyle.SlantOutsizeFar ? _spacingTabOutsizePadding : 0); switch (orientation) { case VisualOrientation.Top: if (rtl) ret = new Padding(borderWidth + y + _spacingTabSlantPadding - 1, borderWidth + y, borderWidth + y, 0); else ret = new Padding(borderWidth + y, borderWidth + y, borderWidth + y + _spacingTabSlantPadding - 1, 0); break; case VisualOrientation.Left: ret = new Padding(borderWidth + y, borderWidth + y, borderWidth + y + _spacingTabSlantPadding - 1, 0); break; case VisualOrientation.Right: ret = new Padding(borderWidth + y + _spacingTabSlantPadding - 1, borderWidth + y, borderWidth + y, 0); break; case VisualOrientation.Bottom: if (rtl) ret = new Padding(borderWidth + y, borderWidth + y, borderWidth + y + _spacingTabSlantPadding - 1, 0); else ret = new Padding(borderWidth + y + _spacingTabSlantPadding - 1, borderWidth + y, borderWidth + y, 0); break; } break; case TabBorderStyle.SlantEqualBoth: case TabBorderStyle.SlantOutsizeBoth: // Calculte the extra needed for the outsize variant int z = (tabBorderStyle == TabBorderStyle.SlantOutsizeBoth ? _spacingTabOutsizePadding : 0); ret = new Padding(borderWidth + z + _spacingTabSlantPadding - 1, borderWidth + z, borderWidth + z + _spacingTabSlantPadding - 1, 0); break; case TabBorderStyle.OneNote: // Is the current tab selected? bool selected = (state == PaletteState.CheckedNormal) || (state == PaletteState.CheckedPressed) || (state == PaletteState.CheckedTracking); // Find the correct edge padding values to use int lp = (selected ? _spacingTabOneNoteLPS : _spacingTabOneNoteLPI); int tp = (selected ? _spacingTabOneNoteTPS : _spacingTabOneNoteTPI); int bp = (selected ? _spacingTabOneNoteBPS : _spacingTabOneNoteBPI); int rp = (selected ? _spacingTabOneNoteRPS : _spacingTabOneNoteRPI); switch (orientation) { case VisualOrientation.Top: if (rtl) ret = new Padding(borderWidth + rp, borderWidth + tp, borderWidth + lp, bp); else ret = new Padding(borderWidth + lp, borderWidth + tp, borderWidth + rp, bp); break; case VisualOrientation.Left: ret = new Padding(borderWidth + rp, borderWidth + tp, borderWidth + lp, bp); break; case VisualOrientation.Right: ret = new Padding(borderWidth + lp, borderWidth + tp, borderWidth + rp, bp); break; case VisualOrientation.Bottom: if (rtl) ret = new Padding(borderWidth + lp, borderWidth + tp, borderWidth + rp, bp); else ret = new Padding(borderWidth + rp, borderWidth + tp, borderWidth + lp, bp); break; } break; case TabBorderStyle.SmoothEqual: ret = new Padding(borderWidth + _spacingTabSmoothLRE, borderWidth + _spacingTabSmoothTE, borderWidth + _spacingTabSmoothLRE, 0); break; case TabBorderStyle.SmoothOutsize: ret = new Padding(borderWidth + _spacingTabSmoothLRO, borderWidth + _spacingTabSmoothTO, borderWidth + _spacingTabSmoothLRO, 0); break; default: // Should never happen! Debug.Assert(false); break; } return ret; }
/// <summary> /// Gets the raw padding used per edge of the border. /// </summary> /// <param name="palette">Palette used for drawing.</param> /// <param name="state">State associated with rendering.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <returns>Padding structure detailing all four edges.</returns> public override Padding GetBorderRawPadding(IPaletteBorder palette, PaletteState state, VisualOrientation orientation) { Debug.Assert(palette != null); // Validate parameter reference if (palette == null) throw new ArgumentNullException("palette"); PaletteDrawBorders borders = palette.GetBorderDrawBorders(state); // If there is at least one border to be drawn if (CommonHelper.HasABorder(borders)) { int borderWidth = palette.GetBorderWidth(state); switch (borders) { case PaletteDrawBorders.Bottom: return new Padding(0, 0, 0, borderWidth); case PaletteDrawBorders.BottomLeft: return new Padding(borderWidth, 0, 0, borderWidth); case PaletteDrawBorders.BottomLeftRight: return new Padding(borderWidth, 0, borderWidth, borderWidth); case PaletteDrawBorders.BottomRight: return new Padding(0, 0, borderWidth, borderWidth); case PaletteDrawBorders.Left: return new Padding(borderWidth, 0, 0, 0); case PaletteDrawBorders.LeftRight: return new Padding(borderWidth, 0, borderWidth, 0); case PaletteDrawBorders.Top: return new Padding(0, borderWidth, 0, 0); case PaletteDrawBorders.Right: return new Padding(0, 0, borderWidth, 0); case PaletteDrawBorders.TopBottom: return new Padding(0, borderWidth, 0, borderWidth); case PaletteDrawBorders.TopBottomLeft: return new Padding(borderWidth, borderWidth, 0, borderWidth); case PaletteDrawBorders.TopBottomRight: return new Padding(0, borderWidth, borderWidth, borderWidth); case PaletteDrawBorders.TopLeft: return new Padding(borderWidth, borderWidth, 0, 0); case PaletteDrawBorders.TopLeftRight: return new Padding(borderWidth, borderWidth, borderWidth, 0); case PaletteDrawBorders.TopRight: return new Padding(0, borderWidth, borderWidth, 0); case PaletteDrawBorders.All: return new Padding(borderWidth); default: // Should never happen! Debug.Assert(false); return Padding.Empty; } } else return Padding.Empty; }
/// <summary> /// Gets the padding used to position display elements completely inside border drawing. /// </summary> /// <param name="palette">Palette used for drawing.</param> /// <param name="state">State associated with rendering.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <returns>Padding structure detailing all four edges.</returns> public override Padding GetBorderDisplayPadding(IPaletteBorder palette, PaletteState state, VisualOrientation orientation) { Debug.Assert(palette != null); // Validate parameter reference if (palette == null) throw new ArgumentNullException("palette"); PaletteDrawBorders borders = palette.GetBorderDrawBorders(state); // If there is at least one border to be drawn if (CommonHelper.HasABorder(borders)) { int borderWidth = palette.GetBorderWidth(state); // Divide the rounding effect by PI to get the actual pixel distance needed // for offseting. But add 2 so it starts indenting on a rounding of just 1. int roundPadding = Convert.ToInt16((palette.GetBorderRounding(state) + borderWidth + 2) / Math.PI); // If not involving rounding then padding for an edge is just the border width int squarePadding = borderWidth; // Borders thicker than 1 need extra offsetting, by half the extra width if (borderWidth > 1) { int halfExtra = borderWidth / 2; roundPadding += halfExtra; } // Enforce the width of the border as the minimum to ensure // it still works as expected for small values of rounding if (roundPadding < borderWidth) roundPadding = borderWidth; switch (borders) { case PaletteDrawBorders.Bottom: return new Padding(0, 0, 0, squarePadding); case PaletteDrawBorders.BottomLeft: return new Padding(roundPadding, 0, 0, roundPadding); case PaletteDrawBorders.BottomLeftRight: return new Padding(roundPadding, 0, roundPadding, roundPadding); case PaletteDrawBorders.BottomRight: return new Padding(0, 0, roundPadding, roundPadding); case PaletteDrawBorders.Left: return new Padding(squarePadding, 0, 0, 0); case PaletteDrawBorders.LeftRight: return new Padding(squarePadding, 0, squarePadding, 0); case PaletteDrawBorders.Top: return new Padding(0, squarePadding, 0, 0); case PaletteDrawBorders.Right: return new Padding(0, 0, squarePadding, 0); case PaletteDrawBorders.TopBottom: return new Padding(0, squarePadding, 0, squarePadding); case PaletteDrawBorders.TopBottomLeft: return new Padding(roundPadding, roundPadding, 0, roundPadding); case PaletteDrawBorders.TopBottomRight: return new Padding(0, roundPadding, roundPadding, roundPadding); case PaletteDrawBorders.TopLeft: return new Padding(roundPadding, roundPadding, 0, 0); case PaletteDrawBorders.TopLeftRight: return new Padding(roundPadding, roundPadding, roundPadding, 0); case PaletteDrawBorders.TopRight: return new Padding(0, roundPadding, roundPadding, 0); case PaletteDrawBorders.All: return new Padding(roundPadding); default: // Should never happen! Debug.Assert(false); return Padding.Empty; } } else return Padding.Empty; }
/// <summary> /// Evaluate if transparent painting is needed for background or border palettes. /// </summary> /// <param name="paletteBack">Background palette to test.</param> /// <param name="paletteBorder">Background palette to test.</param> /// <param name="state">Element state associated with palette.</param> /// <returns>True if transparent painting required.</returns> public override bool EvalTransparentPaint(IPaletteBack paletteBack, IPaletteBorder paletteBorder, PaletteState state) { int rounding = paletteBorder.GetBorderRounding(state); // If the border takes up some visual space if (paletteBorder.GetBorderWidth(state) > 0) { // If the border is not being painted then it must be transparent if (paletteBorder.GetBorderDraw(state) == InheritBool.False) return true; else { // If there is rounding causing transparent corners if (paletteBorder.GetBorderRounding(state) > 0) return true; else { // If the first color has alpha channel then has transparency if (paletteBorder.GetBorderColor1(state).A < 255) return true; else { // Does the draw style require use of the second color? if (paletteBorder.GetBorderColorStyle(state) != PaletteColorStyle.Solid) { // If the second color has alpha channel then has transparency if (paletteBorder.GetBorderColor2(state).A < 255) return true; } } } } } // The border does not cause transparency, check the background return EvalTransparentPaint(paletteBack, state); }
/// <summary> /// Draw border on the inside edge of the specified rectangle. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Target rectangle.</param> /// <param name="palette">Palette used for drawing.</param> /// <param name="orientation">Visual orientation of the border.</param> /// <param name="state">State associated with rendering.</param> /// <param name="tabBorderStyle">Style of tab border.</param> public override void DrawTabBorder(RenderContext context, Rectangle rect, IPaletteBorder palette, VisualOrientation orientation, PaletteState state, TabBorderStyle tabBorderStyle) { Debug.Assert(context != null); Debug.Assert(palette != null); // Validate parameter references if (context == null) throw new ArgumentNullException("context"); if (palette == null) throw new ArgumentNullException("palette"); Debug.Assert(context.Control != null); Debug.Assert(!context.Control.IsDisposed); // Is there anything to actually draw? if ((rect.Width > 0) && (rect.Height > 0)) { // Decide if we need to use anti aliasing for a smoother looking visual using (GraphicsHint hint = new GraphicsHint(context.Graphics, palette.GetBorderGraphicsHint(state))) { // Cache commonly used values int borderWidth = palette.GetBorderWidth(state); // Is there any border to actually draw? if (borderWidth > 0) { // Create the path that represents the entire tab border using (GraphicsPath borderPath = CreateTabBorderBackPath(context.Control.RightToLeft, state, true, rect, borderWidth, tabBorderStyle, orientation, (palette.GetBorderGraphicsHint(state) == PaletteGraphicsHint.AntiAlias))) { // Get the rectangle to use when dealing with gradients Rectangle gradientRect = context.GetAlignedRectangle(palette.GetBorderColorAlign(state), rect); // Use standard helper routine to create appropriate color brush using(Brush borderBrush = CreateColorBrush(gradientRect, palette.GetBorderColor1(state), palette.GetBorderColor2(state), palette.GetBorderColorStyle(state), palette.GetBorderColorAngle(state), orientation)) { using (Pen borderPen = new Pen(borderBrush, borderWidth)) context.Graphics.DrawPath(borderPen, borderPath); } Image borderImage = palette.GetBorderImage(state); // Do we need to draw the image? if (ShouldDrawImage(borderImage)) { // Get the rectangle to use when dealing with gradients Rectangle imageRect = context.GetAlignedRectangle(palette.GetBorderImageAlign(state), rect); // Get the image style to use for the image brush PaletteImageStyle borderImageStyle = palette.GetBorderImageStyle(state); // Use standard helper routine to create appropriate image brush using (Pen borderPen = new Pen(CreateImageBrush(imageRect, borderImage, borderImageStyle), borderWidth)) { context.Graphics.DrawPath(borderPen, borderPath); } } } } } } }
/// <summary> /// Gets the border width. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>Border width.</returns> public override int GetBorderWidth(PaletteState state) { return(_inherit.GetBorderWidth(state)); }