Пример #1
0
        private void TurnIndicatorOff(object sender, RoutedEventArgs e)
        {
            IndicatorPushButton indicator = Control as IndicatorPushButton;

            if (indicator != null)
            {
                indicator.Indicator = false;
            }
        }
Пример #2
0
        private void BottomPaddingChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            Slider slider = sender as Slider;

            if (!System.Windows.Input.Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && slider != null && slider.IsFocused)
            {
                IndicatorPushButton indicator = Control as IndicatorPushButton;
                if (indicator != null)
                {
                    indicator.TextFormat.PaddingTop = indicator.TextFormat.PaddingBottom;
                }
            }
        }
        private PathFigure GetArrowFigure(bool Right, IndicatorPushButton pushButton)
        {
            double y                = pushButton.Height / 2d;
            double arrowLength      = pushButton.Width * pushButton.GlyphScale;
            double padding          = (pushButton.Width - arrowLength) / 2d;
            double arrowLineLength  = arrowLength * .6d;
            double headHeightOffset = pushButton.GlyphThickness * 2d;

            Point lineStart, lineEnd, head, head1, head2;

            if (Right)
            {
                lineStart = new Point(padding, y);
                lineEnd   = new Point(lineStart.X + arrowLineLength, y);
                head      = new Point(pushButton.Width - padding, y);
                head1     = new Point(lineEnd.X, y - headHeightOffset);
                head2     = new Point(lineEnd.X, y + headHeightOffset);
            }
            else
            {
                lineStart = new Point(pushButton.Width - padding, y);
                lineEnd   = new Point(lineStart.X - arrowLineLength, y);
                head      = new Point(padding, y);
                head2     = new Point(lineEnd.X, y - headHeightOffset);
                head1     = new Point(lineEnd.X, y + headHeightOffset);
            }

            PathFigure arrow = new PathFigure();

            arrow.StartPoint = lineStart;
            arrow.Segments.Add(new LineSegment(lineEnd, true));
            arrow.Segments.Add(new LineSegment(head1, false));
            arrow.Segments.Add(new LineSegment(head, false));
            arrow.Segments.Add(new LineSegment(head2, false));
            arrow.Segments.Add(new LineSegment(lineEnd, false));

            return(arrow);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            IndicatorPushButton pushButton = Visual as IndicatorPushButton;

            if (pushButton.Pushed && pushButton.Indicator && _pushedImage != null)
            {
                drawingContext.DrawImage(_pushedIndicatorOnImage, _imageRect);
            }
            else if (pushButton.Pushed && !pushButton.Indicator && _pushedImage != null)
            {
                drawingContext.DrawImage(_pushedImage, _imageRect);
            }
            else if (!pushButton.Pushed && pushButton.Indicator && _indicatorOnImage != null)
            {
                drawingContext.DrawImage(_indicatorOnImage, _imageRect);
            }
            else if (_image != null)
            {
                drawingContext.DrawImage(_image, _imageRect);
            }

            if (pushButton.Pushed)
            {
                drawingContext.PushTransform(new TranslateTransform(pushButton.TextPushOffset.X, pushButton.TextPushOffset.Y));
            }

            if (pushButton.Glyph != PushButtonGlyph.None)
            {
                drawingContext.DrawGeometry(pushButton.Indicator ? _onGlyphBrush : _offGlyphBrush, pushButton.Indicator ? _onGlyphPen : _offGlyphPen, _glyphPath);
            }
            pushButton.TextFormat.RenderText(drawingContext, pushButton.Indicator ? _onTextBrush : _offTextBrush, pushButton.Text, _imageRect);

            if (pushButton.Pushed)
            {
                drawingContext.Pop();
            }
        }
        protected override void OnRefresh()
        {
            IndicatorPushButton pushButton = Visual as IndicatorPushButton;

            if (pushButton != null)
            {
                _imageRect.Width        = pushButton.Width;
                _imageRect.Height       = pushButton.Height;
                _image                  = ConfigManager.ImageManager.LoadImage(pushButton.Image);
                _pushedImage            = ConfigManager.ImageManager.LoadImage(pushButton.PushedImage);
                _indicatorOnImage       = ConfigManager.ImageManager.LoadImage(pushButton.IndicatorOnImage);
                _pushedIndicatorOnImage = ConfigManager.ImageManager.LoadImage(pushButton.PushedIndicatorOnImage);
                _onTextBrush            = new SolidColorBrush(pushButton.OnTextColor);
                _offTextBrush           = new SolidColorBrush(pushButton.TextColor);

                _onGlyphBrush = new SolidColorBrush(pushButton.OnGlyphColor);
                _onGlyphPen   = new Pen(_onGlyphBrush, pushButton.GlyphThickness);

                _offGlyphBrush = new SolidColorBrush(pushButton.GlyphColor);
                _offGlyphPen   = new Pen(_offGlyphBrush, pushButton.GlyphThickness);

                Point center = new Point(pushButton.Width / 2d, pushButton.Height / 2d);
                _glyphPath = new PathGeometry();
                switch (pushButton.Glyph)
                {
                case PushButtonGlyph.Circle:
                    double          radius  = (Math.Min(pushButton.Width, pushButton.Height) / 2d) * pushButton.GlyphScale;
                    EllipseGeometry ellipse = new EllipseGeometry(center, radius, radius);
                    _onGlyphBrush  = null;
                    _offGlyphBrush = null;
                    _glyphPath.AddGeometry(ellipse);
                    break;

                case PushButtonGlyph.RightArrow:
                    _glyphPath.Figures.Add(GetArrowFigure(true, pushButton));
                    break;

                case PushButtonGlyph.LeftArrow:
                    _glyphPath.Figures.Add(GetArrowFigure(false, pushButton));
                    break;

                case PushButtonGlyph.UpCaret:
                    double     offsetX = center.X * pushButton.GlyphScale;
                    double     offsetY = offsetX / 2d;
                    PathFigure figure  = new PathFigure();
                    figure.IsClosed   = false;
                    figure.IsFilled   = false;
                    figure.StartPoint = new Point(center.X - offsetX, center.Y + offsetY);
                    figure.Segments.Add(new LineSegment(new Point(center.X, center.Y - offsetY), true));
                    figure.Segments.Add(new LineSegment(new Point(center.X + offsetX, center.Y + offsetY), true));
                    _glyphPath.Figures.Add(figure);
                    break;
                }
            }
            else
            {
                _image                  = null;
                _pushedImage            = null;
                _onTextBrush            = null;
                _offTextBrush           = null;
                _onTextBrush            = null;
                _onGlyphPen             = null;
                _offTextBrush           = null;
                _offGlyphPen            = null;
                _glyphPath              = null;
                _indicatorOnImage       = null;
                _pushedIndicatorOnImage = null;
            }
        }
        private PathFigure GetArrowFigure(bool Right, IndicatorPushButton pushButton)
        {
            double y = pushButton.Height / 2d;
            double arrowLength = pushButton.Width * pushButton.GlyphScale;
            double padding = (pushButton.Width - arrowLength) / 2d;
            double arrowLineLength = arrowLength * .6d;
            double headHeightOffset = pushButton.GlyphThickness * 2d;

            Point lineStart, lineEnd, head, head1, head2;

            if (Right)
            {
                lineStart = new Point(padding, y);
                lineEnd = new Point(lineStart.X + arrowLineLength, y);
                head = new Point(pushButton.Width - padding, y);
                head1 = new Point(lineEnd.X, y - headHeightOffset);
                head2 = new Point(lineEnd.X, y + headHeightOffset);
            }
            else
            {
                lineStart = new Point(pushButton.Width - padding, y);
                lineEnd = new Point(lineStart.X - arrowLineLength, y);
                head = new Point(padding, y);
                head2 = new Point(lineEnd.X, y - headHeightOffset);
                head1 = new Point(lineEnd.X, y + headHeightOffset);
            }

            PathFigure arrow = new PathFigure();
            arrow.StartPoint = lineStart;
            arrow.Segments.Add(new LineSegment(lineEnd, true));
            arrow.Segments.Add(new LineSegment(head1, false));
            arrow.Segments.Add(new LineSegment(head, false));
            arrow.Segments.Add(new LineSegment(head2, false));
            arrow.Segments.Add(new LineSegment(lineEnd, false));

            return arrow;
        }