/// <summary> /// Initialize a new instance of the ViewLayoutViewport class. /// </summary> /// <param name="paletteMetrics">Palette source for metrics.</param> /// <param name="metricPadding">Metric used to get view padding.</param> /// <param name="metricOvers">Metric used to get overposition.</param> /// <param name="orientation">Orientation for the viewport children.</param> /// <param name="alignment">Alignment of the children within the viewport.</param> /// <param name="animateChange">Animate changes in the viewport.</param> public ViewLayoutViewport(IPaletteMetric paletteMetrics, PaletteMetricPadding metricPadding, PaletteMetricInt metricOvers, VisualOrientation orientation, RelativePositionAlign alignment, bool animateChange) { // Remember the source information _paletteMetrics = paletteMetrics; _metricPadding = metricPadding; _metricOvers = metricOvers; _orientation = orientation; _alignment = alignment; _animateChange = animateChange; // Default other state _offset = Point.Empty; _extent = Size.Empty; _rightToLeft = RightToLeft.No; _rightToLeftLayout = false; _fillSpace = false; _counterAlignment = RelativePositionAlign.Far; // Create a timer for animation effect _animationTimer = new Timer(); _animationTimer.Interval = _animationInterval; _animationTimer.Tick += new EventHandler(OnAnimationTick); }
/// <summary> /// Initialize a new instance of the KryptonLabel class. /// </summary> public KryptonLabel() { // The label cannot take the focus SetStyle(ControlStyles.Selectable, false); // Set default properties _style = LabelStyle.NormalControl; _useMnemonic = true; _orientation = VisualOrientation.Top; _target = null; _enabledTarget = true; // Create content storage _labelValues = new LabelValues(NeedPaintDelegate); _labelValues.TextChanged += new EventHandler(OnLabelTextChanged); // Create palette redirector _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl); // Create the palette provider _stateCommon = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); _stateDisabled = new PaletteContent(_stateCommon, NeedPaintDelegate); _stateNormal = new PaletteContent(_stateCommon, NeedPaintDelegate); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_stateNormal, this, VisualOrientation.Top); _drawContent.UseMnemonic = _useMnemonic; // Create the view manager instance ViewManager = new ViewManager(this, _drawContent); // We want to be auto sized by default, but not the property default! AutoSize = true; AutoSizeMode = AutoSizeMode.GrowAndShrink; }
/// <summary> /// Initialize a new instance of the KryptonButton class. /// </summary> public KryptonButton() { // We generate click events manually, suppress default // production of them by the base Control class SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false); // Set default button properties _style = ButtonStyle.Standalone; _dialogResult = DialogResult.None; _orientation = VisualOrientation.Top; _useMnemonic = true; // Create content storage _buttonValues = CreateButtonValues(NeedPaintDelegate); _buttonValues.TextChanged += new EventHandler(OnButtonTextChanged); // Create the palette storage _stateCommon = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); _stateDisabled = new PaletteTriple(_stateCommon, NeedPaintDelegate); _stateNormal = new PaletteTriple(_stateCommon, NeedPaintDelegate); _stateTracking = new PaletteTriple(_stateCommon, NeedPaintDelegate); _statePressed = new PaletteTriple(_stateCommon, NeedPaintDelegate); _stateDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); _stateFocus = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); // Create the override handling classes _overrideFocus = new PaletteTripleOverride(_stateFocus, _stateNormal, PaletteState.FocusOverride); _overrideNormal = new PaletteTripleOverride(_stateDefault, _overrideFocus, PaletteState.NormalDefaultOverride); _overrideTracking = new PaletteTripleOverride(_stateFocus, _stateTracking, PaletteState.FocusOverride); _overridePressed = new PaletteTripleOverride(_stateFocus, _statePressed, PaletteState.FocusOverride); // Create the view button instance _drawButton = new ViewDrawButton(_stateDisabled, _overrideNormal, _overrideTracking, _overridePressed, new PaletteMetricRedirect(Redirector), this, Orientation, UseMnemonic); // Only draw a focus rectangle when focus cues are needed in the top level form _drawButton.TestForFocusCues = true; // Create a button controller to handle button style behaviour _buttonController = new ButtonController(_drawButton, NeedPaintDelegate); // Assign the controller to the view element to treat as a button _drawButton.MouseController = _buttonController; _drawButton.KeyController = _buttonController; _drawButton.SourceController = _buttonController; // Need to know when user clicks the button view or mouse selects it _buttonController.Click += new MouseEventHandler(OnButtonClick); _buttonController.MouseSelect += new MouseEventHandler(OnButtonSelect); // Create the view manager instance ViewManager = new ViewManager(this, _drawButton); }
/// <summary> /// Initialize a new instance of the DragTargetControlEdge class. /// </summary> /// <param name="screenRect">Rectangle for screen area.</param> /// <param name="hotRect">Rectangle for hot area.</param> /// <param name="drawRect">Rectangle for draw area.</param> /// <param name="hint">Target hint which should be one of the edges.</param> /// <param name="controlElement">Workspace instance that contains cell.</param> /// <param name="allowFlags">Only drop pages that have one of these flags defined.</param> /// <param name="outsideEdge">Add to the outside edge (otherwise the inner edge).</param> public DragTargetControlEdge(Rectangle screenRect, Rectangle hotRect, Rectangle drawRect, DragTargetHint hint, KryptonDockingControl controlElement, KryptonPageFlags allowFlags, bool outsideEdge) : base(screenRect, hotRect, drawRect, hint, allowFlags) { _controlElement = controlElement; _outsideEdge = outsideEdge; // Find the orientation by looking for a matching hint (we need to exclude flags from the hint enum) switch (hint & DragTargetHint.ExcludeFlags) { case DragTargetHint.Transfer: case DragTargetHint.EdgeLeft: _edge = VisualOrientation.Left; break; case DragTargetHint.EdgeRight: _edge = VisualOrientation.Right; break; case DragTargetHint.EdgeTop: _edge = VisualOrientation.Top; break; case DragTargetHint.EdgeBottom: _edge = VisualOrientation.Bottom; break; default: Debug.Assert(false); throw new ArgumentOutOfRangeException("Hint must be an edge value."); } }
/// <summary> /// Initialize a new instance of the NavigatorBar class. /// </summary> /// <param name="navigator">Reference to owning navigator instance.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public NavigatorBar(KryptonNavigator navigator, NeedPaintHandler needPaint) { Debug.Assert(navigator != null); // Remember back reference _navigator = navigator; // Store the provided paint notification delegate NeedPaint = needPaint; // Default values _barAnimation = true; _barFirstItemInset = 0; _barLastItemInset = 0; _barOrientation = VisualOrientation.Top; _barMinimumHeight = _defaultBarMinimumHeight; _barMultiline = BarMultiline.Singleline; _checkButtonStyle = ButtonStyle.Standalone; _tabStyle = TabStyle.HighProfile; _tabBorderStyle = TabBorderStyle.RoundedOutsizeMedium; _itemAlignment = RelativePositionAlign.Near; _itemMinimumSize = _defaultItemMinimumSize; _itemMaximumSize = _defaultItemMaximumSize; _itemOrientation = ButtonOrientation.Auto; _itemSizing = BarItemSizing.SameHeight; _barMapImage = MapKryptonPageImage.Small; _barMapText = MapKryptonPageText.TextTitle; _barMapExtraText = MapKryptonPageText.None; }
/// <summary> /// Initialize a new instance of the ViewDrawNavOutlookStack class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavOutlookStack(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation) { // Are we mapping for the full or the mini mode? _full = (navigator.NavigatorMode == NavigatorMode.OutlookFull); }
/// <summary> /// Initialize a new instance of the ViewLayoutInsetOverlap class. /// </summary> public ViewLayoutInsetOverlap(ViewDrawCanvas drawCanvas) { Debug.Assert(drawCanvas != null); // Remember source of the rounding values _drawCanvas = drawCanvas; // Default other state _orientation = VisualOrientation.Top; }
/// <summary> /// Initialize a new instance of the ViewDrawCanvas class. /// </summary> /// <param name="paletteBack">Palette source for the background.</param> /// <param name="paletteBorder">Palette source for the border.</param> /// <param name="orientation">Visual orientation of the content.</param> public ViewDrawCanvas(IPaletteBack paletteBack, IPaletteBorder paletteBorder, VisualOrientation orientation) : this(paletteBack, paletteBorder, null, PaletteMetricPadding.HeaderGroupPaddingPrimary, orientation) { }
/// <summary> /// Initialize a new instance of the ViewDrawAutoHiddenTab class. /// </summary> /// <param name="page">Reference to the page this tab represents.</param> /// <param name="orientation">Visual orientation used for drawing the tab.</param> public ViewDrawAutoHiddenTab(KryptonPage page, VisualOrientation orientation) : base(page.StateDisabled.CheckButton, page.StateNormal.CheckButton, page.StateTracking.CheckButton, page.StatePressed.CheckButton, null, null, orientation, false) { _page = page; _orientation = orientation; }
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonTab class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavCheckButtonTab(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation, page.StateDisabled.Tab, page.StateNormal.Tab, page.StateTracking.Tab, page.StatePressed.Tab, page.StateSelected.Tab, page.OverrideFocus.Tab) { }
/// <summary> /// Initialize a new instance of the ViewDrawButton class. /// </summary> /// <param name="paletteDisabled">Palette source for the disabled state.</param> /// <param name="paletteNormal">Palette source for the normal state.</param> /// <param name="paletteTracking">Palette source for the tracking state.</param> /// <param name="palettePressed">Palette source for the pressed state.</param> /// <param name="paletteMetric">Palette source for metric values.</param> /// <param name="buttonValues">Source for content values.</param> /// <param name="orientation">Visual orientation of the content.</param> /// <param name="useMnemonic">Use mnemonics.</param> public ViewDrawButton(IPaletteTriple paletteDisabled, IPaletteTriple paletteNormal, IPaletteTriple paletteTracking, IPaletteTriple palettePressed, IPaletteMetric paletteMetric, IContentValues buttonValues, VisualOrientation orientation, bool useMnemonic) : this(paletteDisabled, paletteNormal, paletteTracking, palettePressed, paletteNormal, paletteTracking, palettePressed, paletteMetric, buttonValues, orientation, useMnemonic) { }
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonBase class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> /// <param name="overflow">Button is used on the overflow bar.</param> public ViewDrawNavCheckButtonBase(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation, bool overflow) : this(navigator, page, orientation, page.StateDisabled.OverflowButton, page.StateNormal.OverflowButton, page.StateTracking.OverflowButton, page.StatePressed.OverflowButton, page.StateSelected.OverflowButton, page.OverrideFocus.OverflowButton) { }
/// <summary> /// Initialize a new instance of the ViewLayoutCenter class. /// </summary> /// <param name="paletteMetric">Target for recovering metric values.</param> /// <param name="metricPadding">Metric to use for border padding.</param> /// <param name="orientation">Orientation of the element.</param> /// <param name="childElement">Optional element to add as child.</param> public ViewLayoutCenter(IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, VisualOrientation orientation, ViewBase childElement) { // Remember provided values _paletteMetric = paletteMetric; _metricPadding = metricPadding; _orientation = orientation; if (childElement != null) Add(childElement); }
/// <summary> /// Initialize a new instance of the ViewDrawContent class. /// </summary> /// <param name="paletteContent">Palette source for the content.</param> /// <param name="values">Reference to actual content values.</param> /// <param name="orientation">Visual orientation of the content.</param> public ViewDrawContent(IPaletteContent paletteContent, IContentValues values, VisualOrientation orientation) { // Cache the starting values _paletteContent = paletteContent; _values = values; _orientation = orientation; // Default other state _drawOnComposition = false; _testForFocusCues = false; }
/// <summary> /// Initialize a new instance of the ViewLayoutDocker class. /// </summary> public ViewLayoutDocker() { // Create child to dock style lookup _childDocking = new ViewDockStyleLookup(); // Default state _fillRectangle = Rectangle.Empty; _orientation = VisualOrientation.Top; _maxBorderEdges = PaletteDrawBorders.All; _preferredSizeAll = false; _removeChildBorders = false; _ignoreRightToLeftLayout = false; _padding = Padding.Empty; }
/// <summary> /// Draw a background for an expert style button that is checked. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> public static IDisposable DrawBackExpertChecked(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Draw the expert background which is gradient with highlight at bottom return DrawBackExpert(rect, backColor1, backColor2, orientation, context.Graphics, memento, true, false); } }
/// <summary> /// Initialize a new instance of the ViewDrawNavOutlookSelected class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavOutlookMini(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation, navigator.StateDisabled.MiniButton, navigator.StateNormal.MiniButton, navigator.StateTracking.MiniButton, navigator.StatePressed.MiniButton, navigator.StateSelected.MiniButton, navigator.OverrideFocus.MiniButton) { // Create the finish handler for when popup is removed _finishDelegate = new EventHandler(OnPopupFinished); }
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonBar class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> /// <param name="stateDisabled">Source for disabled state values.</param> /// <param name="stateNormal">Source for normal state values.</param> /// <param name="stateTracking">Source for tracking state values.</param> /// <param name="statePressed">Source for pressed state values.</param> /// <param name="stateSelected">Source for selected state values.</param> /// <param name="stateFocused">Source for focused state values.</param> public ViewDrawNavCheckButtonBar(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation, IPaletteTriple stateDisabled, IPaletteTriple stateNormal, IPaletteTriple stateTracking, IPaletteTriple statePressed, IPaletteTriple stateSelected, IPaletteTriple stateFocused) : base(navigator, page, orientation, stateDisabled, stateNormal, stateTracking, statePressed, stateSelected, stateFocused) { }
/// <summary> /// Create a new check item with initial settings. /// </summary> /// <param name="page">Page for which the check button is to be created.</param> /// <param name="orientation">Initial orientation of the check button.</param> protected override INavCheckItem CreateCheckItem(KryptonPage page, VisualOrientation orientation) { // Create a check button view element ViewDrawNavRibbonTab ribbonTab = new ViewDrawNavRibbonTab(Navigator, page); // Convert the button orientation to the appropriate visual orientations VisualOrientation orientBackBorder = ConvertButtonBorderBackOrientation(); VisualOrientation orientContent = ConvertButtonContentOrientation(); // Set the correct initial orientation of the button ribbonTab.SetOrientation(orientBackBorder, orientContent); return ribbonTab; }
/// <summary> /// Initialize a new instance of the ViewDrawCanvas class. /// </summary> /// <param name="paletteBack">Palette source for the background.</param> /// <param name="paletteBorder">Palette source for the border.</param> /// <param name="paletteMetric">Palette source for metric values.</param> /// <param name="metricPadding">Matric used to get padding values.</param> /// <param name="orientation">Visual orientation of the content.</param> public ViewDrawCanvas(IPaletteBack paletteBack, IPaletteBorder paletteBorder, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, VisualOrientation orientation) { // Cache the starting values _paletteBorder = paletteBorder; _paletteBack = paletteBack; _paletteMetric = paletteMetric; _metricPadding = metricPadding; _orientation = orientation; _includeBorderEdge = orientation; _applyIncludeBorderEdge = false; _drawTabBorder = false; _drawCanvas = true; }
/// <summary> /// Initialize a new instance of the ViewLayoutOutlookFull class. /// </summary> /// <param name="viewBuilder">View builder reference.</param> /// <param name="rootControl">Top level visual control.</param> /// <param name="viewportFiller">View element to place inside viewport.</param> /// <param name="paletteBorderEdge">Palette for use with the border edge.</param> /// <param name="paletteMetrics">Palette source for metrics.</param> /// <param name="metricPadding">Metric used to get view padding.</param> /// <param name="metricOvers">Metric used to get overposition.</param> /// <param name="orientation">Orientation for the viewport children.</param> /// <param name="alignment">Alignment of the children within the viewport.</param> /// <param name="animateChange">Animate changes in the viewport.</param> /// <param name="vertical">Is the viewport vertical.</param> /// <param name="needPaintDelegate">Delegate for notifying paint requests.</param> public ViewLayoutOutlookFull(ViewBuilderOutlookBase viewBuilder, VisualControl rootControl, ViewBase viewportFiller, PaletteBorderEdge paletteBorderEdge, IPaletteMetric paletteMetrics, PaletteMetricPadding metricPadding, PaletteMetricInt metricOvers, VisualOrientation orientation, RelativePositionAlign alignment, bool animateChange, bool vertical, NeedPaintHandler needPaintDelegate) : base(rootControl, viewportFiller, paletteBorderEdge, paletteMetrics, metricPadding, metricOvers, orientation, alignment, animateChange, vertical, needPaintDelegate) { Debug.Assert(viewBuilder != null); _viewBuilder = viewBuilder; }
/// <summary> /// Draw a background with glass effect where the fade is from the bottom. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> public static IDisposable DrawBackGlassBottom(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento) { using (Clipping clip = new Clipping(context.Graphics, path)) { MementoDouble cache; if ((memento == null) || !(memento is MementoDouble)) { if (memento != null) memento.Dispose(); cache = new MementoDouble(); memento = cache; } else cache = (MementoDouble)memento; // Draw the one pixel border around the area cache.first = DrawBackLinear(rect, false, ControlPaint.Light(backColor1), ControlPaint.LightLight(backColor1), orientation, context.Graphics, cache.first); // Reduce size on all but the upper edge ModifyRectByEdges(ref rect, 1, 0, 1, 1, orientation); // Draw the inside areas as a glass effect cache.second = DrawBackGlassRadial(rect, backColor1, backColor2, _glassColorTopD, _glassColorBottomD, 3f, 1.1f, orientation, context.Graphics, _fullGlassLength, cache.second); } return memento; }
/// <summary> /// Initialize a new instance of the ViewDrawSplitCanvas class. /// </summary> /// <param name="paletteBack">Palette source for the background.</param> /// <param name="paletteBorder">Palette source for the border.</param> /// <param name="paletteMetric">Palette source for metric values.</param> /// <param name="metricPadding">Matric used to get padding values.</param> /// <param name="orientation">Visual orientation of the content.</param> public ViewDrawSplitCanvas(IPaletteBack paletteBack, IPaletteBorder paletteBorder, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, VisualOrientation orientation) { // Cache the starting values _paletteBorder = paletteBorder; _paletteBack = paletteBack; _paletteBackDraw = new PaletteBackInheritForced(_paletteBack); _paletteBackDraw.ForceDraw = InheritBool.True; _paletteBackLight = new PaletteBackLightenColors(_paletteBack); _paletteMetric = paletteMetric; _paletteBorderNormal = paletteBorder; _paletteBackNormal = paletteBack; _metricPadding = metricPadding; _orientation = orientation; _drawTabBorder = false; _drawCanvas = true; _splitter = false; }
/// <summary> /// Initialize a new instance of the ViewLayoutRibbonScroller class. /// </summary> /// <param name="ribbon">Reference to owning ribbon control.</param> /// <param name="orientation">Scroller orientation.</param> /// <param name="insetForTabs">Should scoller be inset for use in tabs area.</param> /// <param name="needPaintDelegate">Delegate for notifying paint/layout requests.</param> public ViewLayoutRibbonScroller(KryptonRibbon ribbon, VisualOrientation orientation, bool insetForTabs, NeedPaintHandler needPaintDelegate) { // Cache provided values _orientation = orientation; _insetForTabs = insetForTabs; // Create the button and the separator _button = new ViewDrawRibbonScrollButton(ribbon, orientation); _separator = new ViewLayoutRibbonSeparator(GAP_LENGTH, true); // Create button controller for clicking the button RepeatButtonController rbc = new RepeatButtonController(ribbon, _button, needPaintDelegate); rbc.Click += new MouseEventHandler(OnButtonClick); _button.MouseController = rbc; // Add as child elements Add(_button); Add(_separator); }
/// <summary> /// Initialize a new instance of the NavigatorHeader class. /// </summary> /// <param name="navigator">Reference to owning navigator instance.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public NavigatorHeader(KryptonNavigator navigator, NeedPaintHandler needPaint) { Debug.Assert(navigator != null); // Remember back reference _navigator = navigator; // Store the provided paint notification delegate NeedPaint = needPaint; // Default values _headerStylePrimary = HeaderStyle.Primary; _headerStyleSecondary = HeaderStyle.Secondary; _headerStyleBar = HeaderStyle.Secondary; _headerPositionPrimary = VisualOrientation.Top; _headerPositionSecondary = VisualOrientation.Bottom; _headerPositionBar = VisualOrientation.Top; _headerVisiblePrimary = true; _headerVisibleSecondary = true; _headerVisibleBar = true; _headerValuesPrimary = new HeaderGroupMappingPrimary(_navigator, needPaint); _headerValuesSecondary = new HeaderGroupMappingSecondary(_navigator, needPaint); }
private static IDisposable DrawBackExpert(Rectangle drawRect, Color color1, Color color2, VisualOrientation orientation, Graphics g, IDisposable memento, bool total, bool tracking) { // Cannot draw a zero length rectangle if ((drawRect.Width > 0) && (drawRect.Height > 0)) { bool generate = true; MementoBackExpertChecked cache; // Access a cache instance and decide if cache resources need generating if (!(memento is MementoBackExpertChecked)) { memento?.Dispose(); cache = new MementoBackExpertChecked(drawRect, color1, color2, orientation); memento = cache; } else { cache = (MementoBackExpertChecked)memento; generate = !cache.UseCachedValues(drawRect, color1, color2, orientation); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); // If not drawing total area... if (!total) { // Update to draw the inside area instead drawRect.Inflate(-1, -1); cache.drawRect = drawRect; cache.clipPath = new GraphicsPath(); cache.clipPath.AddLine(drawRect.X + 1, drawRect.Y, drawRect.Right - 1, drawRect.Y); cache.clipPath.AddLine(drawRect.Right - 1, drawRect.Y, drawRect.Right, drawRect.Y + 1); cache.clipPath.AddLine(drawRect.Right, drawRect.Y + 1, drawRect.Right, drawRect.Bottom - 2); cache.clipPath.AddLine(drawRect.Right, drawRect.Bottom - 2, drawRect.Right - 2, drawRect.Bottom); cache.clipPath.AddLine(drawRect.Right - 2, drawRect.Bottom, drawRect.Left + 1, drawRect.Bottom); cache.clipPath.AddLine(drawRect.Left + 1, drawRect.Bottom, drawRect.Left, drawRect.Bottom - 2); cache.clipPath.AddLine(drawRect.Left, drawRect.Bottom - 2, drawRect.Left, drawRect.Y + 1); cache.clipPath.AddLine(drawRect.Left, drawRect.Y + 1, drawRect.X + 1, drawRect.Y); } else { cache.clipPath = new GraphicsPath(); cache.clipPath.AddRectangle(drawRect); } // Create rectangle that covers the enter area RectangleF gradientRect = new RectangleF(drawRect.X - 1, drawRect.Y - 1, drawRect.Width + 2, drawRect.Height + 2); // Cannot draw a zero length rectangle if ((gradientRect.Width > 0) && (gradientRect.Height > 0)) { // Draw entire area in a gradient color effect cache.entireBrush = new LinearGradientBrush(gradientRect, CommonHelper.WhitenColor(color1, 0.92f, 0.92f, 0.92f), color1, AngleFromOrientation(orientation)) { Blend = _rounded1Blend }; } RectangleF ellipseRect; PointF ellipseCenter; int ellipseHeight = Math.Max(1, drawRect.Height / 4); int ellipseWidth = Math.Max(1, (tracking ? drawRect.Width : drawRect.Width / 4)); // Ellipse is based on the orientation switch (orientation) { default: case VisualOrientation.Top: ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Bottom - ellipseHeight, drawRect.Width + (ellipseWidth * 2), ellipseHeight * 2); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom); break; case VisualOrientation.Bottom: ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, drawRect.Width + (ellipseWidth * 2), ellipseHeight * 2); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top); break; case VisualOrientation.Left: ellipseRect = new RectangleF(drawRect.Right - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + (ellipseHeight * 2)); ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2)); break; case VisualOrientation.Right: ellipseRect = new RectangleF(drawRect.Left - ellipseWidth, drawRect.Top - ellipseHeight, ellipseWidth * 2, drawRect.Height + (ellipseHeight * 2)); ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2)); break; } cache.ellipsePath = new GraphicsPath(); cache.ellipsePath.AddEllipse(ellipseRect); cache.insideLighten = new PathGradientBrush(cache.ellipsePath) { CenterPoint = ellipseCenter, CenterColor = color2, Blend = _rounded2Blend, SurroundColors = new Color[] { Color.Transparent } }; } if (cache.entireBrush != null) { using (Clipping clip = new Clipping(g, cache.clipPath)) { g.FillRectangle(cache.entireBrush, cache.drawRect); g.FillPath(cache.insideLighten, cache.ellipsePath); } } } return(memento); }
/// <summary> /// Initialize a new instance of the KryptonButton class. /// </summary> public KryptonButton() { // We generate click events manually, suppress default // production of them by the base Control class SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false); // Set default button properties _style = ButtonStyle.Standalone; DialogResult = DialogResult.None; _orientation = VisualOrientation.Top; _useMnemonic = true; // Create content storage Values = CreateButtonValues(NeedPaintDelegate); Values.TextChanged += OnButtonTextChanged; // Create the palette storage StateCommon = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); StateDisabled = new PaletteTriple(StateCommon, NeedPaintDelegate); StateNormal = new PaletteTriple(StateCommon, NeedPaintDelegate); StateTracking = new PaletteTriple(StateCommon, NeedPaintDelegate); StatePressed = new PaletteTriple(StateCommon, NeedPaintDelegate); OverrideDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); OverrideFocus = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate); // Create the override handling classes _overrideFocus = new PaletteTripleOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride); _overrideNormal = new PaletteTripleOverride(OverrideDefault, _overrideFocus, PaletteState.NormalDefaultOverride); _overrideTracking = new PaletteTripleOverride(OverrideFocus, StateTracking, PaletteState.FocusOverride); _overridePressed = new PaletteTripleOverride(OverrideFocus, StatePressed, PaletteState.FocusOverride); // Create the view button instance _drawButton = new ViewDrawButton(StateDisabled, _overrideNormal, _overrideTracking, _overridePressed, new PaletteMetricRedirect(Redirector), this, Orientation, UseMnemonic) { // Only draw a focus rectangle when focus cues are needed in the top level form TestForFocusCues = true }; // Create a button controller to handle button style behaviour _buttonController = new ButtonController(_drawButton, NeedPaintDelegate); // Assign the controller to the view element to treat as a button _drawButton.MouseController = _buttonController; _drawButton.KeyController = _buttonController; _drawButton.SourceController = _buttonController; // Need to know when user clicks the button view or mouse selects it _buttonController.Click += OnButtonClick; _buttonController.MouseSelect += OnButtonSelect; // Create the view manager instance ViewManager = new ViewManager(this, _drawButton); }
/// <summary> /// Internal rendering method. /// </summary> protected override IDisposable DrawRibbonTabSelected2010(RenderContext context, Rectangle rect, PaletteState state, IPaletteRibbonBack palette, VisualOrientation orientation, IDisposable memento, bool standard) { if ((rect.Width > 0) && (rect.Height > 0)) { Color c1 = palette.GetRibbonBackColor1(state); Color c2 = palette.GetRibbonBackColor2(state); Color c3 = palette.GetRibbonBackColor3(state); Color c4 = palette.GetRibbonBackColor4(state); Color c5 = palette.GetRibbonBackColor5(state); var generate = true; MementoRibbonTabSelected2010 cache; // Access a cache instance and decide if cache resources need generating if (memento is MementoRibbonTabSelected2010 selected2010) { cache = selected2010; generate = !cache.UseCachedValues(rect, c1, c2, c3, c4, c5, orientation); } else { memento?.Dispose(); cache = new MementoRibbonTabSelected2010(rect, c1, c2, c3, c4, c5, orientation); memento = cache; } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); // If we have a context color to use then modify the drawing colors if (c5 != Color.Empty) { if (!standard) { c5 = CommonHelper.MergeColors(c5, 0.65f, Color.Black, 0.35f); } c1 = Color.FromArgb(196, c5); } switch (orientation) { case VisualOrientation.Top: DrawRibbonTabSelectedTop2010(rect, c2, c3, c5, cache); break; case VisualOrientation.Left: DrawRibbonTabSelectedLeft2010(rect, c2, c3, c5, cache); break; case VisualOrientation.Right: DrawRibbonTabSelectedRight2010(rect, c2, c3, c5, cache); break; case VisualOrientation.Bottom: DrawRibbonTabSelectedBottom2010(rect, c2, c3, c5, cache); break; } cache.outsidePen = new Pen(c1); cache.centerPen = new Pen(c4); } context.Graphics.FillRectangle(cache.centerBrush, cache.rect); //context.Graphics.FillPath(cache.centerBrush, cache.outsidePath); //if (c5 != Color.Empty) // context.Graphics.FillPath(cache.insideBrush, cache.insidePath); //using (AntiAlias aa = new AntiAlias(context.Graphics)) // context.Graphics.DrawPath(cache.outsidePen, cache.outsidePath); context.Graphics.DrawRectangle(cache.outsidePen, cache.rect); //switch (orientation) //{ // case VisualOrientation.Top: // DrawRibbonTabSelectedTopDraw2010(rect, cache, context.Graphics); // break; // case VisualOrientation.Left: // DrawRibbonTabSelectedLeftDraw2010(rect, cache, context.Graphics); // break; // case VisualOrientation.Right: // DrawRibbonTabSelectedRightDraw2010(rect, cache, context.Graphics); // break; // case VisualOrientation.Bottom: // DrawRibbonTabSelectedBottomDraw2010(rect, cache, context.Graphics); // break; //} } return(memento); }
/// <summary> /// Internal rendering method. /// </summary> protected override IDisposable DrawRibbonTabTracking2010(PaletteRibbonShape shape, RenderContext context, Rectangle rect, PaletteState state, IPaletteRibbonBack palette, VisualOrientation orientation, IDisposable memento, bool standard) { if ((rect.Width > 0) && (rect.Height > 0)) { Color c1 = palette.GetRibbonBackColor1(state); Color c2 = palette.GetRibbonBackColor2(state); Color c3 = palette.GetRibbonBackColor3(state); Color c4 = palette.GetRibbonBackColor4(state); Color c5 = palette.GetRibbonBackColor5(state); var generate = true; MementoRibbonTabTracking2010 cache; // Access a cache instance and decide if cache resources need generating if (memento is MementoRibbonTabTracking2010 tracking2010) { cache = tracking2010; generate = !cache.UseCachedValues(rect, c1, c2, c3, c4, orientation); } else { memento?.Dispose(); cache = new MementoRibbonTabTracking2010(rect, c1, c2, c3, c4, orientation); memento = cache; } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); // If c5 has a colour then use that to highlight the tab if (c5 != Color.Empty) { if (!standard) { c5 = CommonHelper.MergeColors(c5, 0.65f, Color.Black, 0.35f); } c1 = c5; c2 = CommonHelper.MergeColors(c2, 0.8f, ControlPaint.Light(c5), 0.2f); c3 = CommonHelper.MergeColors(c3, 0.7f, c5, 0.3f); } switch (orientation) { case VisualOrientation.Top: DrawRibbonTabTrackingTop2010(rect, c3, c4, cache); break; case VisualOrientation.Left: DrawRibbonTabTrackingLeft2010(rect, c3, c4, cache); break; case VisualOrientation.Right: DrawRibbonTabTrackingRight2010(rect, c3, c4, cache); break; case VisualOrientation.Bottom: DrawRibbonTabTrackingBottom2010(rect, c3, c4, cache); break; } cache.outsidePen = new Pen(c1); cache.outsideBrush = new SolidBrush(c2); } // Fill the full background //context.Graphics.FillPath(cache.outsideBrush, cache.outsidePath); context.Graphics.FillRectangle(cache.outsideBrush, cache.rect); // Draw the border //using (AntiAlias aa = new AntiAlias(context.Graphics)) // context.Graphics.DrawPath(cache.outsidePen, cache.borderPath); context.Graphics.DrawRectangle(cache.outsidePen, cache.rect); // Fill the inside area //context.Graphics.FillPath(cache.insideBrush, cache.insidePath); } return(memento); }
/// <summary> /// Pixel accurate drawing of the requested text memento information. /// </summary> /// <param name="g">Graphics object used for drawing.</param> /// <param name="brush">Brush for drawing text with.</param> /// <param name="rect">Rectangle to draw text inside.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="orientation">Orientation for drawing text.</param> /// <param name="memento">Memento containing text context.</param> /// <param name="state">State of the source element.</param> /// <param name="composition">Should draw on a composition element.</param> /// <param name="glowing">When on composition draw with glowing.</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>True if draw succeeded; False is draw produced an error.</returns> public static bool DrawString(Graphics g, Brush brush, Rectangle rect, RightToLeft rtl, VisualOrientation orientation, bool composition, bool glowing, PaletteState state, AccurateTextMemento memento) { Debug.Assert(g != null); Debug.Assert(memento != null); // Cannot draw with a null graphics instance if (g == null) { throw new ArgumentNullException(nameof(g)); } // Cannot draw with a null memento instance if (memento == null) { throw new ArgumentNullException(nameof(memento)); } bool ret = true; // Is there a valid place to be drawn into if ((rect.Width > 0) && (rect.Height > 0)) { // Does the memento contain something to draw? if (!memento.IsEmpty) { int translateX = 0; int translateY = 0; float rotation = 0f; // Perform any transformations needed for orientation switch (orientation) { case VisualOrientation.Bottom: // Translate to opposite side of origin, so the rotate can // then bring it back to original position but mirror image translateX = (rect.X * 2) + rect.Width; translateY = (rect.Y * 2) + rect.Height; rotation = 180f; break; case VisualOrientation.Left: // Invert the dimensions of the rectangle for drawing upwards rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width); // Translate back from a quarter left turn to the original place translateX = rect.X - rect.Y - 1; translateY = rect.X + rect.Y + rect.Width; rotation = 270; break; case VisualOrientation.Right: // Invert the dimensions of the rectangle for drawing upwards rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width); // Translate back from a quarter right turn to the original place translateX = rect.X + rect.Y + rect.Height + 1; translateY = -(rect.X - rect.Y); rotation = 90f; break; } // Apply the transforms if we have any to apply if ((translateX != 0) || (translateY != 0)) { g.TranslateTransform(translateX, translateY); } if (rotation != 0f) { g.RotateTransform(rotation); } try { if (Application.RenderWithVisualStyles && composition && glowing) { //DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state, // SystemColors.ActiveCaptionText, true); if (Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 10586) { DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state, (state == PaletteState.Disabled) ? Color.FromArgb(170, 170, 170) : ContrastColor(AccentColorService.GetColorByTypeName("ImmersiveSystemAccent")), true); } else { DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state, SystemColors.ActiveCaptionText, true); } } else if (Application.RenderWithVisualStyles && composition) { //Check if correct in all cases SolidBrush tmpBrush = brush as SolidBrush; Color tmpColor = tmpBrush?.Color ?? SystemColors.ActiveCaptionText; DrawCompositionText(g, memento.Text, memento.Font, rect, state, tmpColor, true, memento.Format); } else { g.DrawString(memento.Text, memento.Font, brush, rect, memento.Format); } } catch { // Ignore any error from the DrawString, usually because the display settings // have changed causing Fonts to be invalid. Our controls will notice the change // and refresh the fonts but sometimes the draw happens before the fonts are // regenerated. Just ignore message and everything will sort itself out. Trust me! ret = false; } finally { // Remove the applied transforms if (rotation != 0f) { g.RotateTransform(-rotation); } if ((translateX != 0) || (translateY != 0)) { g.TranslateTransform(-translateX, -translateY); } } } } return(ret); }
/// <summary> /// Initialize a new instance of the RadioButton class. /// </summary> public KryptonRadioButton() { // Turn off standard click and double click events, we do that manually SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false); // Set default properties _style = LabelStyle.NormalControl; _orientation = VisualOrientation.Top; _checkPosition = VisualOrientation.Left; _checked = false; _useMnemonic = true; _autoCheck = true; // Create content storage Values = new LabelValues(NeedPaintDelegate); Values.TextChanged += OnRadioButtonTextChanged; Images = new RadioButtonImages(NeedPaintDelegate); // Create palette redirector _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl); _paletteRadioButtonImages = new PaletteRedirectRadioButton(Redirector, Images); // Create the palette provider StateCommon = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); StateDisabled = new PaletteContent(StateCommon, NeedPaintDelegate); StateNormal = new PaletteContent(StateCommon, NeedPaintDelegate); OverrideFocus = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); // Override the normal values with the focus, when the control has focus _overrideNormal = new PaletteContentInheritOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride, false); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_overrideNormal, Values, VisualOrientation.Top) { UseMnemonic = _useMnemonic, // Only draw a focus rectangle when focus cues are needed in the top level form TestForFocusCues = true }; // Create the check box image drawer and place inside element so it is always centered _drawRadioButton = new ViewDrawRadioButton(_paletteRadioButtonImages) { CheckState = _checked }; _layoutCenter = new ViewLayoutCenter { _drawRadioButton }; // Place check box on the left and the label in the remainder _layoutDocker = new ViewLayoutDocker { { _layoutCenter, ViewDockStyle.Left }, { _drawContent, ViewDockStyle.Fill } }; // Need a controller for handling mouse input _controller = new RadioButtonController(_drawRadioButton, _layoutDocker, NeedPaintDelegate); _controller.Click += OnControllerClick; _controller.Enabled = true; _layoutDocker.MouseController = _controller; _layoutDocker.KeyController = _controller; // Change the layout to match the inital right to left setting and orientation UpdateForOrientation(); // Create the view manager instance ViewManager = new ViewManager(this, _layoutDocker); // We want to be auto sized by default, but not the property default! AutoSize = true; AutoSizeMode = AutoSizeMode.GrowAndShrink; }
/// <summary> /// Initialize a new instance of the ViewLayoutScrollViewport class. /// </summary> /// <param name="rootControl">Top level visual control.</param> /// <param name="viewportFiller">View element to place inside viewport.</param> /// <param name="paletteBorderEdge">Palette for use with the border edge.</param> /// <param name="paletteMetrics">Palette source for metrics.</param> /// <param name="metricPadding">Metric used to get view padding.</param> /// <param name="metricOvers">Metric used to get overposition.</param> /// <param name="orientation">Orientation for the viewport children.</param> /// <param name="alignment">Alignment of the children within the viewport.</param> /// <param name="animateChange">Animate changes in the viewport.</param> /// <param name="vertical">Is the viewport vertical.</param> /// <param name="needPaintDelegate">Delegate for notifying paint requests.</param> public ViewLayoutScrollViewport(VisualControl rootControl, ViewBase viewportFiller, PaletteBorderEdge paletteBorderEdge, IPaletteMetric paletteMetrics, PaletteMetricPadding metricPadding, PaletteMetricInt metricOvers, VisualOrientation orientation, RelativePositionAlign alignment, bool animateChange, bool vertical, NeedPaintHandler needPaintDelegate) { Debug.Assert(rootControl != null); Debug.Assert(viewportFiller != null); Debug.Assert(needPaintDelegate != null); // We need a way to notify changes in layout _needPaintDelegate = needPaintDelegate; // By default we are showing the contained viewport in vertical scrolling _viewportVertical = vertical; // Our initial visual orientation should match the parameter Orientation = orientation; // Create the child viewport Viewport = new ViewLayoutViewport(paletteMetrics, metricPadding, metricOvers, ViewportOrientation(_viewportVertical), alignment, animateChange) { // Default to same alignment for both directions CounterAlignment = alignment, // We always want the viewport to fill any remainder space FillSpace = true }; // Put the provided element inside the viewport Viewport.Add(viewportFiller); // Hook into animation step events Viewport.AnimateStep += OnAnimateStep; // To prevent the contents of the viewport from being able to draw outside // the viewport (such as having child controls) we use a ViewLayoutControl // that uses a child control to restrict the drawing region. ViewControl = new ViewLayoutControl(rootControl, Viewport) { InDesignMode = rootControl.InDesignMode }; // Create the scrollbar and matching border edge ScrollbarV = new ViewDrawScrollBar(true); ScrollbarH = new ViewDrawScrollBar(false); BorderEdgeV = new ViewDrawBorderEdge(paletteBorderEdge, System.Windows.Forms.Orientation.Vertical); BorderEdgeH = new ViewDrawBorderEdge(paletteBorderEdge, System.Windows.Forms.Orientation.Horizontal); // Hook into scroll position changes ScrollbarV.ScrollChanged += OnScrollVChanged; ScrollbarH.ScrollChanged += OnScrollHChanged; // Add with appropriate docking style Add(ViewControl, ViewDockStyle.Fill); Add(BorderEdgeV, ViewDockStyle.Right); Add(BorderEdgeH, ViewDockStyle.Bottom); Add(ScrollbarV, ViewDockStyle.Right); Add(ScrollbarH, ViewDockStyle.Bottom); }
/// <summary> /// Add the check buttons for pages that should be on the overflow area. /// </summary> /// <param name="page">Reference to owning page.</param> /// <param name="checkOverflowOrient">Docking edge to dock against.</param> /// <param name="overflowInsertIndex">Index for inserting the new entry.</param> protected override void ReorderCheckButtonsOverflow(KryptonPage page, VisualOrientation checkOverflowOrient, ref int overflowInsertIndex) { // Do nothing, we never add the overflow buttons to the display }
/// <summary> /// Initialize a new instance of the ViewLayoutCenter class. /// </summary> /// <param name="paletteMetric">Target for recovering metric values.</param> /// <param name="metricPadding">Metric to use for border padding.</param> /// <param name="orientation">Orientation of the element.</param> public ViewLayoutCenter(IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, VisualOrientation orientation) : this(paletteMetric, metricPadding, orientation, null) { }
/// <summary> /// Initialize a new instance of the ViewDrawNavOutlookStack class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavOutlookStack(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation) =>
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonOutlook class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavOutlookOverflow(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation, true) { }
/// <summary> /// Helper routine to draw an image taking into account various properties. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="icon">Icon to be drawn.</param> /// <param name="iconRect">Destination rectangle.</param> /// <param name="orientation">Visual orientation.</param> protected static void DrawIconHelper(ViewContext context, Icon icon, Rectangle iconRect, VisualOrientation orientation) { Debug.Assert(context != null); // Validate reference parameter if (context == null) throw new ArgumentNullException("context"); try { // Finally, just draw the icon and let the transforms do the rest context.Graphics.DrawIcon(icon, iconRect); } finally { } }
/// <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 abstract GraphicsPath GetTabBorderPath(RenderContext context, Rectangle rect, IPaletteBorder palette, VisualOrientation orientation, PaletteState state, TabBorderStyle tabBorderStyle);
/// <summary> /// Draw a background for an expert style button has a square inside with highlight. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> /// <param name="light">Use the 'light' variation.</param> public static IDisposable DrawBackExpertSquareHighlight(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento, bool light) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { bool generate = true; MementoBackExpertSquareHighlight cache; // Access a cache instance and decide if cache resources need generating if (!(memento is MementoBackExpertSquareHighlight)) { memento?.Dispose(); cache = new MementoBackExpertSquareHighlight(rect, backColor1, backColor2, orientation); memento = cache; } else { cache = (MementoBackExpertSquareHighlight)memento; generate = !cache.UseCachedValues(rect, backColor1, backColor2, orientation); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); cache.backBrush = new SolidBrush(CommonHelper.WhitenColor(backColor1, 0.8f, 0.8f, 0.8f)); cache.innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2); RectangleF ellipseRect; PointF ellipseCenter; int ellipseWidth = Math.Max(1, rect.Width / 8); int ellipseHeight = Math.Max(1, rect.Height / 8); switch (orientation) { default: case VisualOrientation.Top: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 90f); ellipseRect = new RectangleF(rect.Left, rect.Top + (ellipseHeight * 2), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Bottom); break; case VisualOrientation.Bottom: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 270f); ellipseRect = new RectangleF(rect.Left, rect.Top - (ellipseHeight * 6), rect.Width, ellipseHeight * 12); ellipseCenter = new PointF(ellipseRect.Left + (ellipseRect.Width / 2), ellipseRect.Top); break; case VisualOrientation.Left: cache.innerBrush = new LinearGradientBrush(cache.innerRect, backColor1, backColor2, 180f); ellipseRect = new RectangleF(rect.Left + (ellipseHeight * 2), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Right, ellipseRect.Top + (ellipseRect.Height / 2)); break; case VisualOrientation.Right: cache.innerBrush = new LinearGradientBrush(rect, backColor1, backColor2, 0f); ellipseRect = new RectangleF(rect.Left - (ellipseHeight * 6), rect.Top, ellipseWidth * 12, rect.Height); ellipseCenter = new PointF(ellipseRect.Left, ellipseRect.Top + (ellipseRect.Height / 2)); break; } cache.innerBrush.SetSigmaBellShape(0.5f); cache.ellipsePath = new GraphicsPath(); cache.ellipsePath.AddEllipse(ellipseRect); cache.insideLighten = new PathGradientBrush(cache.ellipsePath) { CenterPoint = ellipseCenter, CenterColor = (light ? Color.FromArgb(64, Color.White) : Color.FromArgb(128, Color.White)), Blend = _rounded2Blend, SurroundColors = new Color[] { Color.Transparent } }; } context.Graphics.FillRectangle(cache.backBrush, rect); context.Graphics.FillRectangle(cache.innerBrush, cache.innerRect); context.Graphics.FillRectangle(cache.insideLighten, cache.innerRect); } return(memento); } }
/// <summary> /// Draw a background for an expert style button with pressed effect. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="rect">Rectangle to draw.</param> /// <param name="backColor1">First color.</param> /// <param name="backColor2">Second color.</param> /// <param name="orientation">Drawing orientation.</param> /// <param name="path">Clipping path.</param> /// <param name="memento">Cache used for drawing.</param> public static IDisposable DrawBackExpertPressed(RenderContext context, Rectangle rect, Color backColor1, Color backColor2, VisualOrientation orientation, GraphicsPath path, IDisposable memento) { using (Clipping clip = new Clipping(context.Graphics, path)) { // Cannot draw a zero length rectangle if ((rect.Width > 0) && (rect.Height > 0)) { bool generate = true; MementoBackExpertShadow cache; // Access a cache instance and decide if cache resources need generating if ((memento == null) || !(memento is MementoBackExpertShadow)) { if (memento != null) { memento.Dispose(); } cache = new MementoBackExpertShadow(rect, backColor1, backColor2); memento = cache; } else { cache = (MementoBackExpertShadow)memento; generate = !cache.UseCachedValues(rect, backColor1, backColor2); } // Do we need to generate the contents of the cache? if (generate) { rect.X -= 1; rect.Y -= 1; rect.Width += 2; rect.Height += 2; // Dispose of existing values cache.Dispose(); cache.path1 = CreateBorderPath(rect, _itemCut); cache.path2 = CreateBorderPath(new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2), _itemCut); cache.path3 = CreateBorderPath(new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4), _itemCut); cache.brush1 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.4f, backColor1, 0.6f)); cache.brush2 = new SolidBrush(CommonHelper.MergeColors(backColor2, 0.2f, backColor1, 0.8f)); cache.brush3 = new SolidBrush(backColor1); } using (AntiAlias aa = new AntiAlias(context.Graphics)) { context.Graphics.FillRectangle(cache.brush3, rect); context.Graphics.FillPath(cache.brush1, cache.path1); context.Graphics.FillPath(cache.brush2, cache.path2); context.Graphics.FillPath(cache.brush3, cache.path3); } } return(memento); } }
/// <summary> /// Set the orientation of the background/border and content. /// </summary> /// <param name="borderBackOrient">Orientation of the button border and background..</param> /// <param name="contentOrient">Orientation of the button contents.</param> public void SetOrientation(VisualOrientation borderBackOrient, VisualOrientation contentOrient) { _borderBackOrient = borderBackOrient; _viewContent.Orientation = contentOrient; }
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonBase class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> /// <param name="stateDisabled">Source for disabled state values.</param> /// <param name="stateNormal">Source for normal state values.</param> /// <param name="stateTracking">Source for tracking state values.</param> /// <param name="statePressed">Source for pressed state values.</param> /// <param name="stateSelected">Source for selected state values.</param> /// <param name="stateFocused">Source for focused state values.</param> public ViewDrawNavCheckButtonBase(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation, IPaletteTriple stateDisabled, IPaletteTriple stateNormal, IPaletteTriple stateTracking, IPaletteTriple statePressed, IPaletteTriple stateSelected, IPaletteTriple stateFocused) : base(stateDisabled, stateNormal, stateTracking, statePressed, null, null, orientation, true) { Debug.Assert(navigator != null); _navigator = navigator; _page = page; _lastClick = DateTime.Now.AddDays(-1); // Associate the page component with this view element Component = page; // Prevent user from unchecking the selected check button AllowUncheck = false; // Set the source for values to ourself ButtonValues = this; // Create a controller for managing button behavior IMouseController controller = CreateMouseController(); MouseController = controller; // Create overrides for getting the focus values _overrideDisabled = new PaletteTripleOverride(stateFocused, stateDisabled, PaletteState.FocusOverride); _overrideNormal = new PaletteTripleOverride(stateFocused, stateNormal, PaletteState.FocusOverride); _overrideTracking = new PaletteTripleOverride(stateFocused, stateTracking, PaletteState.FocusOverride); _overridePressed = new PaletteTripleOverride(stateFocused, statePressed, PaletteState.FocusOverride); _overrideSelected = new PaletteTripleOverride(stateFocused, stateSelected, PaletteState.FocusOverride); // Push values into the base class SetPalettes(_overrideDisabled, _overrideNormal, _overrideTracking, _overridePressed); SetCheckedPalettes(_overrideSelected, _overrideSelected, _overrideSelected); // Are we allowed to add button specs to the button? if (AllowButtonSpecs) { // Create button specification collection manager _buttonManager = new ButtonSpecNavManagerLayoutBar(Navigator, Navigator.InternalRedirector, Page.ButtonSpecs, null, new ViewLayoutDocker[] { LayoutDocker }, new IPaletteMetric[] { Navigator.StateCommon }, new PaletteMetricInt[] { PaletteMetricInt.PageButtonInset }, new PaletteMetricInt[] { PaletteMetricInt.PageButtonInset }, new PaletteMetricPadding[] { PaletteMetricPadding.PageButtonPadding }, new GetToolStripRenderer(Navigator.CreateToolStripRenderer), null); // Hook up the tooltip manager so that tooltips can be generated _buttonManager.ToolTipManager = Navigator.ToolTipManager; // Allow derived classes to update the remapping with different values UpdateButtonSpecMapping(); } }
/// <summary> /// Resets the BarOrientation property to its default value. /// </summary> public void ResetBarOrientation() { BarOrientation = VisualOrientation.Top; }
/// <summary> /// Initialize a new instance of the ViewDrawRibbonScrollButton class. /// </summary> /// <param name="ribbon">Reference to owning ribbon control.</param> /// <param name="orientation">Scroller orientation.</param> public ViewDrawRibbonScrollButton(KryptonRibbon ribbon, VisualOrientation orientation) { _ribbon = ribbon; Orientation = orientation; }
/// <summary> /// Initialize a new instance of the ViewDrawPanel class. /// </summary> /// <param name="paletteBack">Palette source for the background.</param> public ViewDrawPanel(IPaletteBack paletteBack) { Debug.Assert(paletteBack != null); _paletteBack = paletteBack; _orientation = VisualOrientation.Top; }
/// <summary> /// Initialize a new instance of the KryptonButton class. /// </summary> public KryptonCommandLinkButton() { // We generate click events manually, suppress default // production of them by the base Control class SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false); // Set default button properties base.AutoSize = false; DialogResult = DialogResult.None; _orientation = VisualOrientation.Top; _useMnemonic = true; // Create content storage CommandLinkImageValue = new ImageValue(NeedPaintDelegate); CommandLinkTextValues = new CommandLinkTextValues(NeedPaintDelegate); // Create the palette storage StateCommon = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonCommand, PaletteBorderStyle.ButtonCommand, PaletteContentStyle.ButtonCommand, NeedPaintDelegate); PaletteContentText contentShortText = StateCommon.Content.ShortText; contentShortText.Font = new Font(@"Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 0); contentShortText.TextH = PaletteRelativeAlign.Near; contentShortText.TextV = PaletteRelativeAlign.Center; StateCommon.Content.LongText.TextH = PaletteRelativeAlign.Near; StateCommon.Content.LongText.TextV = PaletteRelativeAlign.Far; StateDisabled = new PaletteTriple(StateCommon, NeedPaintDelegate); StateNormal = new PaletteTriple(StateCommon, NeedPaintDelegate); StateTracking = new PaletteTriple(StateCommon, NeedPaintDelegate); StatePressed = new PaletteTriple(StateCommon, NeedPaintDelegate); OverrideDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonCommand, PaletteBorderStyle.ButtonCommand, PaletteContentStyle.ButtonCommand, NeedPaintDelegate); OverrideFocus = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonCommand, PaletteBorderStyle.ButtonCommand, PaletteContentStyle.ButtonCommand, NeedPaintDelegate); OverrideFocus.Border.Draw = InheritBool.True; OverrideFocus.Border.DrawBorders = PaletteDrawBorders.All; OverrideFocus.Border.GraphicsHint = PaletteGraphicsHint.AntiAlias; // Force style update ButtonStyle = ButtonStyle.Command; // Create the override handling classes _overrideFocus = new PaletteTripleOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride); _overrideNormal = new PaletteTripleOverride(OverrideDefault, _overrideFocus, PaletteState.NormalDefaultOverride); _overrideTracking = new PaletteTripleOverride(OverrideFocus, StateTracking, PaletteState.FocusOverride); _overridePressed = new PaletteTripleOverride(OverrideFocus, StatePressed, PaletteState.FocusOverride); // Create the view button instance drawButton = new ViewDrawCommandLinkButton(StateDisabled, _overrideNormal, _overrideTracking, _overridePressed, new PaletteMetricRedirect(Redirector), CommandLinkImageValue, CommandLinkTextValues, Orientation, UseMnemonic) { // Only draw a focus rectangle when focus cues are needed in the top level form TestForFocusCues = true }; // Create a button controller to handle button style behaviour _buttonController = new ButtonController(drawButton, NeedPaintDelegate); // Assign the controller to the view element to treat as a button drawButton.MouseController = _buttonController; drawButton.KeyController = _buttonController; drawButton.SourceController = _buttonController; // Need to know when user clicks the button view or mouse selects it _buttonController.Click += OnButtonClick; _buttonController.MouseSelect += OnButtonSelect; // Create the view manager instance ViewManager = new ViewManager(this, drawButton); }
/// <summary> /// Initialize a new instance of the ViewDrawPanel class. /// </summary> public ViewDrawPanel() { _orientation = VisualOrientation.Top; _ignoreRender = false; }
/// <summary> /// Initialize a new instance of the ViewDrawButton class. /// </summary> /// <param name="paletteDisabled">Palette source for the disabled state.</param> /// <param name="paletteNormal">Palette source for the normal state.</param> /// <param name="paletteTracking">Palette source for the tracking state.</param> /// <param name="palettePressed">Palette source for the pressed state.</param> /// <param name="paletteCheckedNormal">Palette source for the normal checked state.</param> /// <param name="paletteCheckedTracking">Palette source for the tracking checked state.</param> /// <param name="paletteCheckedPressed">Palette source for the pressed checked state.</param> /// <param name="paletteMetric">Palette source for metric values.</param> /// <param name="buttonValues">Source for content values.</param> /// <param name="orientation">Visual orientation of the content.</param> /// <param name="useMnemonic">Use mnemonics.</param> public ViewDrawButton(IPaletteTriple paletteDisabled, IPaletteTriple paletteNormal, IPaletteTriple paletteTracking, IPaletteTriple palettePressed, IPaletteTriple paletteCheckedNormal, IPaletteTriple paletteCheckedTracking, IPaletteTriple paletteCheckedPressed, IPaletteMetric paletteMetric, IContentValues buttonValues, VisualOrientation orientation, bool useMnemonic) { // Remember the source information _paletteDisabled = paletteDisabled; _paletteNormal = paletteNormal; _paletteTracking = paletteTracking; _palettePressed = palettePressed; _paletteCheckedNormal = paletteCheckedNormal; _paletteCheckedTracking = paletteCheckedTracking; _paletteCheckedPressed = paletteCheckedPressed; CurrentPalette = _paletteNormal; // Default to not being checked Checked = false; AllowUncheck = true; _dropDown = false; _splitter = false; _dropDownPosition = VisualOrientation.Right; // Create the drop down view _drawDropDown = new ViewLayoutCenter(1); _drawDropDownButton = new ViewDrawDropDownButton(); _drawDropDown.Add(_drawDropDownButton); _drawOuterSeparator = new ViewLayoutSeparator(1); // Create the view used to draw the split edge _edgeRedirect = new PaletteBorderEdgeRedirect(_paletteNormal.PaletteBorder, null); _drawSplitBorder = new ViewDrawBorderEdge(new PaletteBorderEdge(_edgeRedirect, null), CommonHelper.VisualToOrientation(orientation)); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_paletteNormal.PaletteContent, buttonValues, orientation); _drawCanvas = new ViewDrawSplitCanvas(_paletteNormal.PaletteBack, _paletteNormal.PaletteBorder, paletteMetric, PaletteMetricPadding.None, orientation); // Use a docker layout to organize the contents of the canvas LayoutDocker = new ViewLayoutDocker { { _drawContent, ViewDockStyle.Fill }, { _drawSplitBorder, ViewDockStyle.Right }, { _drawDropDown, ViewDockStyle.Right }, { _drawOuterSeparator, ViewDockStyle.Right } }; LayoutDocker.Tag = this; // Pass the mnemonic default to the content view _drawContent.UseMnemonic = useMnemonic; // Place the content inside the canvas _drawCanvas.Add(LayoutDocker); // Set initial view element visible states UpdateDropDown(); // Place the canvas inside ourself Add(_drawCanvas); }
private void CreateNavCheckButtons() { // Maintain lookup between page and check button/button edge that represent it _pageLookup = new PageToNavCheckButton(); _buttonEdgeLookup = new PageToButtonEdge(); VisualOrientation checkButtonOrient = ResolveButtonOrientation(); RelativePositionAlign alignment = Navigator.Stack.StackAlignment; Orientation stackOrient = Navigator.Stack.StackOrientation; Orientation buttonEdgeOrient = (stackOrient == Orientation.Vertical ? Orientation.Horizontal : Orientation.Vertical); ViewDockStyle dockNear = (stackOrient == Orientation.Vertical ? ViewDockStyle.Top : ViewDockStyle.Left); ViewDockStyle dockFar = (stackOrient == Orientation.Vertical ? ViewDockStyle.Bottom : ViewDockStyle.Right); // Cache the border edge palette to use PaletteBorderEdge buttonEdgePalette = (Navigator.Enabled ? Navigator.StateNormal.BorderEdge : Navigator.StateDisabled.BorderEdge); // Start stacking from the top/left if not explicitly set to be far aligned bool dockTopLeft = (alignment != RelativePositionAlign.Far); // Create a check button to represent each krypton page foreach (KryptonPage page in Navigator.Pages) { // Create the draw view element for the check button and provide page it represents ViewDrawNavCheckButtonStack checkButton = new ViewDrawNavCheckButtonStack(Navigator, page, checkButtonOrient); // Provide the drag rectangle when requested for this button checkButton.ButtonDragRectangle += new EventHandler <ButtonDragRectangleEventArgs>(OnCheckButtonDragRect); checkButton.ButtonDragOffset += new EventHandler <ButtonDragOffsetEventArgs>(OnCheckButtonDragOffset); // Need to know when check button needs repainting checkButton.NeedPaint = NeedPaintDelegate; // Set the initial state checkButton.Visible = page.LastVisibleSet; checkButton.Enabled = page.Enabled; checkButton.Checked = (Navigator.SelectedPage == page); checkButton.Orientation = checkButtonOrient; // Create the border edge for use next to the check button ViewDrawBorderEdge buttonEdge = new ViewDrawBorderEdge(buttonEdgePalette, buttonEdgeOrient); buttonEdge.Visible = page.LastVisibleSet; // Add to lookup dictionary _pageLookup.Add(page, checkButton); _buttonEdgeLookup.Add(page, buttonEdge); // Add to the child collection with the correct docking style if (dockTopLeft) { _viewLayout.Insert(1, checkButton); _viewLayout.Insert(1, buttonEdge); _viewLayout.SetDock(buttonEdge, dockNear); _viewLayout.SetDock(checkButton, dockNear); } else { _viewLayout.Add(buttonEdge, dockFar); _viewLayout.Add(checkButton, dockFar); } // All entries after the selected page are docked at the bottom/right unless // we have been set to stack near or far, in which case we do not change. if (checkButton.Checked && (alignment == RelativePositionAlign.Center)) { dockTopLeft = false; } } // Need to monitor changes in the page collection to reflect in layout bar Navigator.Pages.Inserted += new TypedHandler <KryptonPage>(OnPageInserted); Navigator.Pages.Removed += new TypedHandler <KryptonPage>(OnPageRemoved); Navigator.Pages.Cleared += new EventHandler(OnPagesCleared); _events = true; }
private void PaintTab(int index, RenderContext RenderContext) { bool Selected = (SelectedIndex == index); Rectangle TabRect = GetTabRect(index); //If Selected Then TabRect.Inflate(0, 2) if ((Appearance & TabAppearance.Normal) == TabAppearance.Normal) { TabRect.Inflate(0, Selected ? 2 : 1); TabRect.X += 1; } PaletteState State = default(PaletteState); if (Selected) { State = PaletteState.Pressed; } else { State = TabRect.Contains(PointToClient(MousePosition)) ? PaletteState.Tracking : PaletteState.Normal; } VisualOrientation visualOrientation = (VisualOrientation)Alignment; if (PaletteTabButtonBackground.GetBackDraw(State) == InheritBool.True) { using (GraphicsPath BackPath = Renderer.RenderStandardBorder.GetBackPath(RenderContext, TabRect, PaletteTabButtonBorder, visualOrientation, State)) { MementoTabButtonBackground = Renderer.RenderStandardBack.DrawBack(RenderContext, TabRect, BackPath, PaletteTabButtonBackground, visualOrientation, State, MementoTabButtonBackground); } } if (PaletteTabButtonBorder.GetBorderDraw(State) == InheritBool.True) { Renderer.RenderStandardBorder.DrawBorder(RenderContext, TabRect, PaletteTabButtonBorder, visualOrientation, State); } else if (Selected) { using (Pen PBorder = new Pen(PaletteTabPageBorder.GetBorderColor1(PaletteState.Normal))) { Rectangle RBorder = TabRect; RBorder.Width -= 1; RenderContext.Graphics.DrawRectangle(PBorder, RBorder); } } // Draw tab image (TODO: adjust rendering for other Appearance settings) if (ImageList != null) { Image tabImage = null; if (TabPages[index].ImageIndex != -1) { int imageIndex = TabPages[index].ImageIndex; tabImage = ImageList.Images[imageIndex]; } else if (TabPages[index].ImageKey != null) { string imageKey = TabPages[index].ImageKey; tabImage = ImageList.Images[imageKey]; } if (tabImage != null) { int x = TabRect.X + (tabImage.Width / 2); int y = TabRect.Y + (TabRect.Height - tabImage.Height) / 2; RenderContext.Graphics.DrawImage(tabImage, x, y); TabRect.X += tabImage.Width; TabRect.Width -= tabImage.Width; } } if (TabFont == null || (!object.ReferenceEquals(TabFont, TabFontBold) & !object.ReferenceEquals(TabFont, TabFontRegular))) { if (RenderContext.Graphics.MeasureString(TabPages[index].Text, TabFontBold, TabRect.X, SF).Width <= TabRect.Width) { TabFont = TabFontBold; } else { TabFont = TabFontRegular; } } RenderContext.Graphics.DrawString(TabPages[index].Text, TabFont, TabBrush, TabRect, SF); }
/// <summary> /// Gets the padding used to position display elements completely inside border drawing. /// </summary> /// <param name="context">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 abstract Padding GetTabBorderDisplayPadding(ViewLayoutContext context, IPaletteBorder palette, PaletteState state, VisualOrientation orientation, TabBorderStyle tabBorderStyle);
/// <summary> /// Initialize a new instance of the ViewDrawDropDownButton class. /// </summary> public ViewDrawDropDownButton() { _orientation = VisualOrientation.Top; }
/// <summary> /// Perform layout calculations on the provided content. /// </summary> /// <param name="context">Layout context.</param> /// <param name="availableRect">Space available for laying out.</param> /// <param name="palette">Content palette details.</param> /// <param name="values">Content values.</param> /// <param name="orientation">Visual orientation of the content.</param> /// <param name="state">State associated with rendering.</param> /// <param name="composition">Drawing onto a composition element.</param> /// <param name="glowing">If composition, should glowing be drawn.</param> /// <returns>Memento with cached information.</returns> public abstract IDisposable LayoutContent(ViewLayoutContext context, Rectangle availableRect, IPaletteContent palette, IContentValues values, VisualOrientation orientation, PaletteState state, bool composition, bool glowing);
/// <summary> /// Initialize a new instance of the ViewDrawNavCheckButtonStack class. /// </summary> /// <param name="navigator">Owning navigator instance.</param> /// <param name="page">Page this check button represents.</param> /// <param name="orientation">Orientation for the check button.</param> public ViewDrawNavCheckButtonStack(KryptonNavigator navigator, KryptonPage page, VisualOrientation orientation) : base(navigator, page, orientation) { }
/// <summary> /// Helper routine to draw an image taking into account various properties. /// </summary> /// <param name="context">Rendering context.</param> /// <param name="image">Image to be drawn.</param> /// <param name="remapTransparent">Color that should become transparent.</param> /// <param name="imageRect">Destination rectangle.</param> /// <param name="orientation">Visual orientation.</param> /// <param name="effect">Drawing effect.</param> /// <param name="remapColor">Image color to remap.</param> /// <param name="remapNew">New color for remap.</param> protected static void DrawImageHelper(ViewContext context, Image image, Color remapTransparent, Rectangle imageRect, VisualOrientation orientation, PaletteImageEffect effect, Color remapColor, Color remapNew) { Debug.Assert(context != null); // Prevent problems with multiple threads using the same palette images // by only allowing a single thread to draw the provided image at a time lock (_threadLock) { // Validate reference parameter if (context == null) throw new ArgumentNullException("context"); // Use image attributes class to modify image drawing for effects ImageAttributes attribs = new ImageAttributes(); switch (effect) { case PaletteImageEffect.Disabled: attribs.SetColorMatrix(CommonHelper.MatrixDisabled); break; case PaletteImageEffect.GrayScale: attribs.SetColorMatrix(_matrixGrayScale, ColorMatrixFlag.SkipGrays); break; case PaletteImageEffect.GrayScaleRed: attribs.SetColorMatrix(_matrixGrayScaleRed, ColorMatrixFlag.SkipGrays); break; case PaletteImageEffect.GrayScaleGreen: attribs.SetColorMatrix(_matrixGrayScaleGreen, ColorMatrixFlag.SkipGrays); break; case PaletteImageEffect.GrayScaleBlue: attribs.SetColorMatrix(_matrixGrayScaleBlue, ColorMatrixFlag.SkipGrays); break; case PaletteImageEffect.Light: attribs.SetColorMatrix(_matrixLight); break; case PaletteImageEffect.LightLight: attribs.SetColorMatrix(_matrixLightLight); break; case PaletteImageEffect.Dark: attribs.SetColorMatrix(_matrixDark); break; case PaletteImageEffect.DarkDark: attribs.SetColorMatrix(_matrixDarkDark); break; case PaletteImageEffect.Inherit: // Should never happen! Debug.Assert(false); break; } // Do we need to remap a colors in the bitmap? if ((remapTransparent != Color.Empty) || ((remapColor != Color.Empty) && (remapNew != Color.Empty))) { List<ColorMap> colorMaps = new List<ColorMap>(); // Create remapping for the transparent color if (remapTransparent != Color.Empty) { ColorMap remap = new ColorMap(); remap.OldColor = remapTransparent; remap.NewColor = Color.Transparent; colorMaps.Add(remap); } // Create remapping from source to target colors if ((remapColor != Color.Empty) && (remapNew != Color.Empty)) { ColorMap remap = new ColorMap(); remap.OldColor = remapColor; remap.NewColor = remapNew; colorMaps.Add(remap); } attribs.SetRemapTable(colorMaps.ToArray(), ColorAdjustType.Bitmap); } int translateX = 0; int translateY = 0; float rotation = 0f; // Perform any transformations needed for orientation switch (orientation) { case VisualOrientation.Bottom: // Translate to opposite side of origin, so the rotate can // then bring it back to original position but mirror image translateX = imageRect.X * 2 + imageRect.Width; translateY = imageRect.Y * 2 + imageRect.Height; rotation = 180f; break; case VisualOrientation.Left: // Invert the dimensions of the rectangle for drawing upwards imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width); // Translate back from a quarter left turn to the original place translateX = imageRect.X - imageRect.Y; translateY = imageRect.X + imageRect.Y + imageRect.Width; rotation = -90f; break; case VisualOrientation.Right: // Invert the dimensions of the rectangle for drawing upwards imageRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Height, imageRect.Width); // Translate back from a quarter right turn to the original place translateX = imageRect.X + imageRect.Y + imageRect.Height; translateY = -(imageRect.X - imageRect.Y); rotation = 90f; break; } // Apply the transforms if we have any to apply if ((translateX != 0) || (translateY != 0)) context.Graphics.TranslateTransform(translateX, translateY); if (rotation != 0f) context.Graphics.RotateTransform(rotation); try { // Finally, just draw the image and let the transforms do the rest context.Graphics.DrawImage(image, imageRect, 0, 0, imageRect.Width, imageRect.Height, GraphicsUnit.Pixel, attribs); } catch (ArgumentException) { } finally { if (rotation != 0f) context.Graphics.RotateTransform(-rotation); // Remove the applied transforms if ((translateX != 0) | (translateY != 0)) context.Graphics.TranslateTransform(-translateX, -translateY); } } }
/// <summary> /// Pixel accurate drawing of the requested text memento information. /// </summary> /// <param name="g">Graphics object used for drawing.</param> /// <param name="brush">Brush for drawing text with.</param> /// <param name="rect">Rectangle to draw text inside.</param> /// <param name="rtl">Right to left setting for control.</param> /// <param name="orientation">Orientation for drawing text.</param> /// <param name="memento">Memento containing text context.</param> /// <param name="state">State of the source element.</param> /// <param name="composition">Should draw on a composition element.</param> /// <returns>True if draw succeeded; False is draw produced an error.</returns> public static bool DrawString(Graphics g, Brush brush, Rectangle rect, RightToLeft rtl, VisualOrientation orientation, bool composition, PaletteState state, AccurateTextMemento memento) { Debug.Assert(g != null); Debug.Assert(memento != null); // Cannot draw with a null graphics instance if (g == null) { throw new ArgumentNullException("g"); } // Cannot draw with a null memento instance if (memento == null) { throw new ArgumentNullException("memento"); } bool ret = true; // Is there a valid place to be drawn into if ((rect.Width > 0) && (rect.Height > 0)) { // Does the memento contain something to draw? if (!memento.IsEmpty) { int translateX = 0; int translateY = 0; float rotation = 0f; // Perform any transformations needed for orientation switch (orientation) { case VisualOrientation.Bottom: // Translate to opposite side of origin, so the rotate can // then bring it back to original position but mirror image translateX = rect.X * 2 + rect.Width; translateY = rect.Y * 2 + rect.Height; rotation = 180f; break; case VisualOrientation.Left: // Invert the dimensions of the rectangle for drawing upwards rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width); // Translate back from a quater left turn to the original place translateX = rect.X - rect.Y - 1; translateY = rect.X + rect.Y + rect.Width; rotation = 270; break; case VisualOrientation.Right: // Invert the dimensions of the rectangle for drawing upwards rect = new Rectangle(rect.X, rect.Y, rect.Height, rect.Width); // Translate back from a quater right turn to the original place translateX = rect.X + rect.Y + rect.Height + 1; translateY = -(rect.X - rect.Y); rotation = 90f; break; } // Apply the transforms if we have any to apply if ((translateX != 0) || (translateY != 0)) { g.TranslateTransform(translateX, translateY); } if (rotation != 0f) { g.RotateTransform(rotation); } try { if (composition) { DrawCompositionGlowingText(g, memento.Text, memento.Font, rect, state, SystemColors.ActiveCaptionText, true); } else { g.DrawString(memento.Text, memento.Font, brush, rect, memento.Format); } } catch { // Ignore any error from the DrawString, usually because the display settings // have changed causing Fonts to be invalid. Our controls will notice the change // and refresh the fonts but sometimes the draw happens before the fonts are // regenerated. Just ignore message and everything will sort itself out. Trust me! ret = false; } finally { // Remove the applied transforms if (rotation != 0f) { g.RotateTransform(-rotation); } if ((translateX != 0) || (translateY != 0)) { g.TranslateTransform(-translateX, -translateY); } } } } return(ret); }