protected virtual void RecalcBrushes(Rectangle position, Painter.State state) { if (_lastPosition == null || _lastPosition.Value != position || _lastState == null ||_lastState.Value != state) { _lastState = state; if (state == State.Hover) _borderPen = new Pen(Color.FromArgb(0x3c, 0x7f, 0xb1), 1); else if (state == State.Pressed) _borderPen = new Pen(Color.FromArgb(0x18, 0x59, 0x8a), 1); else _borderPen = new Pen(Color.FromArgb(0x9a, 0x9a, 0x9a), 1); _leftBounds = new Rectangle(position.X, position.Y, 8, position.Height); _leftBrush = CreateLeftBrush(_leftBounds, state); _middleBounds = new Rectangle(_leftBounds.Right, _leftBounds.Y, (int)((float)position.Width - 16), position.Height); _middleBrush = CreateMiddleBrush(_middleBounds, state); _rightBounds = new Rectangle(_middleBounds.Right, _leftBounds.Y, 8, position.Height); _rightBrush = CreateRightBrush(_rightBounds, state); _upperGradientPath = new GraphicsPath(); _upperGradientPath.AddLine(position.X + 8, position.Y + 1, position.X + 8, position.Y + 5); _upperGradientPath.AddLine(position.X + 8, position.Y + 5, _middleBounds.Right, position.Y + 5); _upperGradientPath.AddLine(_middleBounds.Right, position.Y + 5, _rightBounds.Right - 1, position.Y + 1); _upperGradientPath.CloseAllFigures(); _upperGradientRect = new Rectangle(position.X + 8, position.Y + 1, 10, 4); _upperGradientBrush = new LinearGradientBrush(_upperGradientRect, Color.FromArgb(0xed, 0xed, 0xed), Color.FromArgb(0xdd, 0xdd, 0xe0), LinearGradientMode.Vertical); _lastPosition = position; } }
protected override Color BorderColor(Painter.State state) { if (state == State.Pressed) return Color.FromArgb(0x8b, 0x76, 0x54); else return Color.FromArgb(0x96, 0x9f, 0xa3); }
public override void Paint(Graphics g, Rectangle position, Painter.State buttonState, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { Rectangle layoutArea = Rectangle.FromLTRB(position.X + _paddingLeft, position.Y + _paddingTop, position.Right - _paddingRight, position.Bottom - _paddingBottom); if (layoutArea.Width <= 0 || layoutArea.Height <= 0) return; double layoutRatio = (double)layoutArea.Width / (double)layoutArea.Height; Rectangle targetRect; //maximize width if (layoutRatio < _targetRatio) { int targetWidth = layoutArea.Width; if(_maxWidth > 0) targetWidth = Math.Min(layoutArea.Width, _maxWidth); int targetHeight = (int)((double)targetWidth / _targetRatio); targetRect = new Rectangle(layoutArea.X, layoutArea.Y, targetWidth, targetHeight); } //maximize height else { int targetWidth = (int)((double)layoutArea.Height * _targetRatio); int targetHeight = layoutArea.Height; if (_maxWidth > 0 && targetWidth > _maxWidth) { targetWidth = _maxWidth; targetHeight = (int)((double)targetHeight / _targetRatio); } targetRect = new Rectangle(layoutArea.X, layoutArea.Y, targetWidth, targetHeight); } if (_vAlign == Alignment.Far) targetRect = new Rectangle(targetRect.X, layoutArea.Bottom - targetRect.Height, targetRect.Width, targetRect.Height); else if(_vAlign == Alignment.Center) targetRect = new Rectangle(targetRect.X, layoutArea.Top + (int)((double)layoutArea.Height / 2.0d - (double)targetRect.Height / 2.0d), targetRect.Width, targetRect.Height); if (_hAlign == Alignment.Far) targetRect = new Rectangle(layoutArea.Right - targetRect.Width, targetRect.Y, targetRect.Width, targetRect.Height); else if(_hAlign == Alignment.Center) targetRect = new Rectangle(targetRect.X + (int)((double)layoutArea.Width / 2.0d - (double)targetRect.Width / 2.0d), targetRect.Y, targetRect.Width, targetRect.Height); _subPainter.Paint(g, targetRect, buttonState, text, buttonImage, textFont, referencePosition); }
protected virtual Brush CreateLeftBrush(Rectangle bounds, Painter.State state) { if(state == State.Hover) return new LinearGradientBrush(bounds, Color.FromArgb(0xe3, 0xf4, 0xfc), Color.FromArgb(0xd6, 0xee, 0xfb), LinearGradientMode.Horizontal); else if (state == State.Pressed) return new LinearGradientBrush(bounds, Color.FromArgb(0xce, 0xed, 0xfa), Color.FromArgb(0xb5, 0xe4, 0xf7), LinearGradientMode.Horizontal); else return new LinearGradientBrush(bounds, Color.FromArgb(0xf5, 0xf5, 0xf5), Color.FromArgb(0xe9, 0xe9, 0xeb), LinearGradientMode.Horizontal); }
protected override Brush UpperBrush(Painter.State state, Rectangle bounds) { if (state == State.Normal) return new LinearGradientBrush(bounds, Color.FromArgb(0xd6, 0xde, 0xdf), Color.FromArgb(0xdb, 0xe2, 0xe4), LinearGradientMode.Vertical); else if (state == State.Hover) return new LinearGradientBrush(bounds, Color.FromArgb(0xfe, 0xfa, 0xe5), Color.FromArgb(0xfb, 0xe0, 0x91), LinearGradientMode.Vertical); else return new LinearGradientBrush(bounds, Color.FromArgb(0xcc, 0x96, 0x66), Color.FromArgb(0xff, 0xaa, 0x46), LinearGradientMode.Vertical); }
protected virtual Brush CreateMiddleBrush(Rectangle bounds, Painter.State state) { if(state == State.Hover) return new SolidBrush(Color.FromArgb(0xa9, 0xdb, 0xf6)); else if (state == State.Pressed) return new SolidBrush(Color.FromArgb(0x6f, 0xca, 0xf0)); else return new SolidBrush(Color.FromArgb(0xd9, 0xda, 0xdc)); }
protected override Brush LowerBrush(Painter.State state, Rectangle bounds) { if (state == State.Normal) return new LinearGradientBrush(bounds, Color.FromArgb(0xce, 0xd5, 0xd7), Color.FromArgb(0xdf, 0xe4, 0xe6), LinearGradientMode.Vertical); else if (state == State.Hover) return new LinearGradientBrush(bounds, Color.FromArgb(0xfe, 0xd2, 0x53), Color.FromArgb(0xff, 0xe3, 0x97), LinearGradientMode.Vertical); else return new LinearGradientBrush(bounds, Color.FromArgb(0xff, 0x9c, 0x26), Color.FromArgb(0xff, 0xc0, 0x4b), LinearGradientMode.Vertical); }
public PainterFilterSize(Painter subPainter, Alignment hAlign, Alignment vAlign, int paddingTop, int paddingLeft, int paddingRight, int paddingBottom, int maxWidth, double targetRatio) { _hAlign = hAlign; _vAlign = vAlign; _paddingTop = paddingTop; _paddingBottom = paddingBottom; _paddingLeft = paddingLeft; _paddingRight = paddingRight; _maxWidth = maxWidth; _targetRatio = targetRatio; _subPainter = subPainter; }
public static Painter Create(Painter backgroundPainter, SymbolEnum symbol, bool fill, int penWidth, Color forecolor, Color hoverColor, Color clickColor) { return(new StackedPainters( new PainterFilterNoText(backgroundPainter), new SymbolPainter(symbol, fill, penWidth, forecolor, hoverColor, clickColor))); }
public override void Paint(Graphics g, Rectangle position, Painter.State buttonState, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { Rectangle upperRect; Rectangle lowerRect; if (buttonState != State.Pressed) { upperRect = new Rectangle(position.Left, position.Top, position.Width, position.Height / 2 - position.Height / 8); lowerRect = new Rectangle(position.Left, position.Top + position.Height / 2 - position.Height / 8, position.Width, position.Height / 2 + position.Height / 8); } else { upperRect = new Rectangle(position.Left, position.Top, position.Width, Math.Max(1, position.Height / 2)); lowerRect = new Rectangle(position.Left, position.Top + position.Height / 2 , position.Width, Math.Max(1,position.Height / 2) ); } g.FillRectangle(UpperBrush(buttonState, upperRect), upperRect); g.FillRectangle(LowerBrush(buttonState, lowerRect), lowerRect); Rectangle borderRect = new Rectangle(position.X, position.Y, position.Width - BorderWidth(buttonState), position.Height - BorderWidth(buttonState)); g.DrawRectangle(new Pen(BorderColor(buttonState), BorderWidth(buttonState)), borderRect); Rectangle textBounds; if (buttonImage == null) textBounds = new Rectangle( position.X + 2, position.Y + 2, position.Width - 4, position.Height - 4); else { //There is an image, calculate the the width from te max height int imageHeight = position.Height - 10; double imageRatio = (double)buttonImage.Width / (double)buttonImage.Height; int imageWidth = (int)(imageRatio * (double)imageHeight); Rectangle imagePosition = new Rectangle(position.X + 5, position.Y + 5, imageWidth, imageHeight); textBounds = new Rectangle(imagePosition.Right + 2, position.Y + 2, position.Width - imagePosition.Width - 10, position.Height - 4); g.DrawImage(buttonImage, imagePosition, new Rectangle(0, 0, buttonImage.Width, buttonImage.Height), GraphicsUnit.Pixel); } StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; format.FormatFlags = StringFormatFlags.NoClip | StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap; if (referencePosition != null) { double xRatio = (double)position.Width / (double)referencePosition.Value.Width; double yRatio = (double)position.Height / (double)referencePosition.Value.Height; textFont = ScaledFont(textFont, xRatio, yRatio, text, textBounds, g, format); } //TextRenderer.DrawText(g, button.ButtonText, myFont, textBounds, FontColor(myState), Color.Transparent, TextFormatFlags.NoPadding | TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter); using (Brush frontBrush = new SolidBrush(FontColor(buttonState))) { //g.FillPath(frontBrush, GeneratePath(button.ButtonText, textBounds, myFont.Style)); g.DrawString(text, textFont, frontBrush, textBounds, format); } }
protected abstract Color FontColor(Painter.State state);
public void SetLargeThumbPainter(Painter largeThumbPainter) { _largeThumbPainter = largeThumbPainter; }
protected override int BorderWidth(Painter.State state) { return 1; }
public override void Paint(Graphics g, Rectangle position, Painter.State buttonState, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { foreach (Painter p in _painters) p.Paint(g, position, buttonState, text, buttonImage, textFont, referencePosition); }
public override void Paint(Graphics g, Rectangle position, Painter.State buttonState, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { GraphicsPath path; Pen myPen = _pen; if (buttonState == State.Hover) myPen = _hoverPen; else if (buttonState == State.Pressed) myPen = _clickPen; if (_symbol == SymbolEnum.TriangleDown) path = BuildTriangleDown(position); else if (_symbol == SymbolEnum.TriangleUp) path = BuildTriangleUp(position); else if (_symbol == SymbolEnum.GripH) path = BuildGripH(position); else throw new NotImplementedException("Symbol not implemented"); if (_fill && _noFill.Contains(_symbol) == false) { g.FillPath(_fillBrush, path); if (buttonState == State.Hover) g.DrawPath(myPen, path); else if (buttonState == State.Pressed) g.DrawPath(myPen, path); } else g.DrawPath(myPen, path); }
public static Painter Create(Painter backgroundPainter, SymbolEnum symbol, bool fill, int penWidth, Color forecolor, Color hoverColor, Color clickColor) { return new StackedPainters( new PainterFilterNoText(backgroundPainter), new SymbolPainter(symbol, fill, penWidth, forecolor, hoverColor, clickColor)); }
public void SetUpperButtonPainter(Painter upperButtonPainter) { _upperButtonPainter = upperButtonPainter; }
private bool AnyStateHasStatus(Painter.State state) { return _thumbState == state || _lowerButtonState == state || _upperButtonState == state || _beforeThumbState == state || _afterThumbState == state; }
public CustomScrollbar() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); PrepareBack(); _upperButtonPainter = new StackedPainters( new WindowsStyledButtonPainter(), new PainterFilterSize( new SymbolPainter(SymbolPainter.SymbolEnum.TriangleUp, true, 1, Color.Black, Color.Black, Color.Black), PainterFilterSize.Alignment.Center, PainterFilterSize.Alignment.Center, 0, 0, 0, 0, 10, 2)); _lowerButtonPainter = new StackedPainters( new WindowsStyledButtonPainter(), new PainterFilterSize( new SymbolPainter(SymbolPainter.SymbolEnum.TriangleDown, true, 1, Color.Black, Color.Black, Color.Black), PainterFilterSize.Alignment.Center, PainterFilterSize.Alignment.Center, 0, 0, 0, 0, 10, 2)); _smallThumbPainter = new WindowsStyledButtonPainter(); _largeThumbPainter = new StackedPainters( new WindowsStyledButtonPainter(), new PainterFilterSize( new SymbolPainter(SymbolPainter.SymbolEnum.GripH, true, 1, Color.Black, Color.Black, Color.Black), PainterFilterSize.Alignment.Center, PainterFilterSize.Alignment.Center, 0,0,0,0 ,10, 2) ); InvalidateThumbPosition(); _timer.Tick += new EventHandler(_timer_Tick); }
public void SetSmallThumbPainter(Painter smallThumbPainter) { _smallThumbPainter = smallThumbPainter; }
public override void Paint(Graphics g, Rectangle position, Painter.State state, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { if (position.Height < 10 || position.Width < 20) return; RecalcBrushes(position, state); g.FillRectangle(_leftBrush, _leftBounds); g.FillRectangle(_middleBrush, _middleBounds); g.FillRectangle(_rightBrush, _rightBounds); DrawBorder(g, position, state); g.FillPath(_upperGradientBrush, _upperGradientPath); }
public virtual void DrawBorder(Graphics g, Rectangle position, Painter.State state) { g.DrawRectangle(_borderPen, new Rectangle(position.X, position.Y, (int)(position.Width - _borderPen.Width), (int)(position.Height - _borderPen.Width))); }
public PainterFilterNoText(Painter p) { _subPainter = p; }
public PainterFilterNoText(Painter p) { _subPainter = p; }
public void SetLowerButtonPainter(Painter lowerButtonPainter) { _lowerButtonPainter = lowerButtonPainter; }
protected virtual Brush CreateRightBrush(Rectangle bounds, Painter.State state) { if(state == State.Hover) return new LinearGradientBrush(bounds, Color.FromArgb(0xa9, 0xdb, 0xf6), Color.FromArgb(0x9c, 0xca, 0xe3), LinearGradientMode.Horizontal); else if (state == State.Pressed) return new LinearGradientBrush(bounds, Color.FromArgb(0x6f, 0xca, 0xf0), Color.FromArgb(0x66, 0xba, 0xdd), LinearGradientMode.Horizontal); else return new LinearGradientBrush(bounds, Color.FromArgb(0xd5, 0xd5, 0xd8), Color.FromArgb(0xc0, 0xc0, 0xc4), LinearGradientMode.Horizontal); }
protected override Color FontColor(Painter.State state) { return Color.FromArgb(0x46, 0x46, 0x46); }
public override void Paint(Graphics g, Rectangle position, Painter.State buttonState, string text, Image buttonImage, Font textFont, Rectangle? referencePosition) { _subPainter.Paint(g, position, buttonState, "", buttonImage, textFont, referencePosition); }
protected abstract int BorderWidth(Painter.State state);
protected abstract Color BorderColor(Painter.State state);
protected abstract Brush LowerBrush(Painter.State state, Rectangle bounds);