Ejemplo n.º 1
0
        /// <summary>
        /// sets the control size
        /// it's more a hack
        /// </summary>
        /// <param name="finalSize"></param>
        /// <returns></returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            var result = base.ArrangeOverride(finalSize);

            if (DoubleUtil.IsDoubleFinite(finalSize.Width))
            {
                controlSize = finalSize;
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// sets the <see cref="Layout.Layoutable.Width"/>
        /// </summary>
        /// <param name="availableSize"></param>
        /// <returns></returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (DoubleUtil.IsDoubleFinite(Width) == false)
            {
                Width = controlSize.Width;
                return(new Size(controlSize.Width, Height));
            }

            var result = base.MeasureOverride(availableSize);

            return(result);
        }
Ejemplo n.º 3
0
        protected virtual void OnThumbDragDelta(VectorEventArgs e)
        {
            Thumb thumb = e.Source as Thumb;

            // Convert to Track's co-ordinate
            if (Track != null && thumb == Track.Thumb)
            {
                double newValue = Value + Track.ValueFromDistance(e.Vector.X, e.Vector.Y);
                if (DoubleUtil.IsDoubleFinite(newValue))
                {
                    UpdateValue(newValue);
                }

                // Show AutoToolTip if needed
                //if (this.AutoToolTipPlacement != AutoToolTipPlacement.None)
                //{
                //    if (_autoToolTip == null)
                //    {
                //        _autoToolTip = new ToolTip();
                //    }

                //    _autoToolTip.Content = GetAutoToolTipNumber();

                //    if (thumb.ToolTip != _autoToolTip)
                //    {
                //        thumb.ToolTip = _autoToolTip;
                //    }

                //    if (!_autoToolTip.IsOpen)
                //    {
                //        _autoToolTip.IsOpen = true;
                //    }
                //    ((Popup)_autoToolTip.Parent).Reposition();
                //}
            }
        }
Ejemplo n.º 4
0
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            var result = e.GetCurrentPoint(this);

            if (IsMoveToPointEnabled && Track != null &&
                Track.Thumb != null && Track.Thumb.IsPointerOver == false)
            {
                Point  pt       = e.GetPosition(Track);
                double newValue = Track.ValueFromPoint(pt);
                if (DoubleUtil.IsDoubleFinite(newValue))
                {
                    UpdateValue(newValue);
                }

                e.Handled = true;
            }

            if (result.Properties.IsLeftButtonPressed)
            {
                _OnMouseLeftButtonDown(e);
            }

            base.OnPointerPressed(e);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// sets the tick values
        /// </summary>
        /// <param name="dc"></param>
        public override void Render(DrawingContext dc)
        {
            if (DoubleUtil.IsDoubleFinite(Width) == false)
            {
                this.Width = controlSize.Width;
                //base.Render(dc);
                //return;
            }

            Size   size    = new Size(Width, Height);
            double range   = Maximum - Minimum;
            double tickLen = 0.0d;  // Height for Primary Tick (for Mininum and Maximum value)
            double tickLen2;        // Height for Secondary Tick
            double logicalToPhysical = 1.0;
            double progression       = 1.0d;
            Point  startPoint        = new Point(0d, 0d);
            Point  endPoint          = new Point(0d, 0d);

            // Take Thumb size in to account
            double halfReservedSpace = ReservedSpace * 0.5;

            switch (Placement)
            {
            case TickBarPlacement.Top:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width))
                {
                    return;
                }
                size              = new Size(size.Width - ReservedSpace, size.Height);
                tickLen           = -size.Height;
                startPoint        = new Point(halfReservedSpace, size.Height);
                endPoint          = new Point(halfReservedSpace + size.Width, size.Height);
                logicalToPhysical = size.Width / range;
                progression       = 1;
                break;

            case TickBarPlacement.Bottom:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Width))
                {
                    return;
                }
                size              = new Size(size.Width - ReservedSpace, size.Height);
                tickLen           = size.Height;
                startPoint        = new Point(halfReservedSpace, 0d);
                endPoint          = new Point(halfReservedSpace + size.Width, 0d);
                logicalToPhysical = size.Width / range;
                progression       = 1;
                break;

            case TickBarPlacement.Left:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                {
                    return;
                }
                size              = new Size(size.Width, size.Height - ReservedSpace);
                tickLen           = -size.Width;
                startPoint        = new Point(size.Width, size.Height + halfReservedSpace);
                endPoint          = new Point(size.Width, halfReservedSpace);
                logicalToPhysical = size.Height / range * -1;
                progression       = -1;
                break;

            case TickBarPlacement.Right:
                if (DoubleUtil.GreaterThanOrClose(ReservedSpace, size.Height))
                {
                    return;
                }
                size              = new Size(size.Width, size.Height - ReservedSpace);
                tickLen           = size.Width;
                startPoint        = new Point(0d, size.Height + halfReservedSpace);
                endPoint          = new Point(0d, halfReservedSpace);
                logicalToPhysical = size.Height / range * -1;
                progression       = -1;
                break;
            }
            ;

            tickLen2 = tickLen * 0.75;

            // Invert direciton of the ticks
            if (IsDirectionReversed)
            {
                progression        = -progression;
                logicalToPhysical *= -1;

                // swap startPoint & endPoint
                Point pt = startPoint;
                startPoint = endPoint;
                endPoint   = pt;
            }

            Pen pen = new Pen(Fill, 1.0d);

            bool             snapsToDevicePixels = false;//SnapsToDevicePixels
            DoubleCollection xLines = snapsToDevicePixels ? new DoubleCollection() : null;
            DoubleCollection yLines = snapsToDevicePixels ? new DoubleCollection() : null;

            // Is it Vertical?
            if ((Placement == TickBarPlacement.Left) || (Placement == TickBarPlacement.Right))
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency;
                if (interval > 0.0)
                {
                    double minInterval = (Maximum - Minimum) / size.Height;
                    if (interval < minInterval)
                    {
                        interval = minInterval;
                    }
                }

                // Draw Min & Max tick
                dc.DrawLine(pen, startPoint, new Point(startPoint.X + tickLen, startPoint.Y));
                dc.DrawLine(pen, new Point(startPoint.X, endPoint.Y),
                            new Point(startPoint.X + tickLen, endPoint.Y));

                if (snapsToDevicePixels)
                {
                    xLines.Add(startPoint.X);
                    yLines.Add(startPoint.Y - 0.5);
                    xLines.Add(startPoint.X + tickLen);
                    yLines.Add(endPoint.Y - 0.5);
                    xLines.Add(startPoint.X + tickLen2);
                }

                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;

                if (GetValue(TicksProperty)
                    != null)
                {
                    ticks = Ticks;
                }

                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++)
                    {
                        if (DoubleUtil.LessThanOrClose(ticks[i], Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i], Maximum))
                        {
                            continue;
                        }

                        double adjustedTick = ticks[i] - Minimum;

                        double y = adjustedTick * logicalToPhysical + startPoint.Y;
                        dc.DrawLine(pen,
                                    new Point(startPoint.X, y),
                                    new Point(startPoint.X + tickLen2, y));

                        if (snapsToDevicePixels)
                        {
                            yLines.Add(y - 0.5);
                        }
                    }
                }
                // Draw ticks using specified TickFrequency
                else if (interval > 0.0)
                {
                    for (double i = interval; i < range; i += interval)
                    {
                        double y = i * logicalToPhysical + startPoint.Y;

                        dc.DrawLine(pen,
                                    new Point(startPoint.X, y),
                                    new Point(startPoint.X + tickLen2, y));

                        if (snapsToDevicePixels)
                        {
                            yLines.Add(y - 0.5);
                        }
                    }
                }

                // Draw Selection Ticks
                if (IsSelectionRangeEnabled)
                {
                    double y0  = (SelectionStart - Minimum) * logicalToPhysical + startPoint.Y;
                    Point  pt0 = new Point(startPoint.X, y0);
                    Point  pt1 = new Point(startPoint.X + tickLen2, y0);
                    Point  pt2 = new Point(startPoint.X + tickLen2, y0 + Math.Abs(tickLen2) * progression);

                    //PathSegment[] segments = new PathSegment[] {
                    //    //new LineSegment(pt2, true),
                    //    //new LineSegment(pt0, true),
                    //    new LineSegment{Point=pt2 },
                    //    new LineSegment{Point=pt0 },
                    //};

                    PathSegments segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    PathGeometry geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };

                    dc.DrawGeometry(Fill, pen, geo);

                    y0  = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.Y;
                    pt0 = new Point(startPoint.X, y0);
                    pt1 = new Point(startPoint.X + tickLen2, y0);
                    pt2 = new Point(startPoint.X + tickLen2, y0 - Math.Abs(tickLen2) * progression);

                    segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };
                    dc.DrawGeometry(Fill, pen, geo);
                }
            }
            else  // Placement == Top || Placement == Bottom
            {
                // Reduce tick interval if it is more than would be visible on the screen
                double interval = TickFrequency;
                if (interval > 0.0)
                {
                    double minInterval = (Maximum - Minimum) / size.Width;
                    if (interval < minInterval)
                    {
                        interval = minInterval;
                    }
                }

                // Draw Min & Max tick
                dc.DrawLine(pen, startPoint, new Point(startPoint.X, startPoint.Y + tickLen));
                dc.DrawLine(pen, new Point(endPoint.X, startPoint.Y),
                            new Point(endPoint.X, startPoint.Y + tickLen));

                if (snapsToDevicePixels)
                {
                    xLines.Add(startPoint.X - 0.5);
                    yLines.Add(startPoint.Y);
                    xLines.Add(startPoint.X - 0.5);
                    yLines.Add(endPoint.Y + tickLen);
                    yLines.Add(endPoint.Y + tickLen2);
                }

                // This property is rarely set so let's try to avoid the GetValue
                // caching of the mutable default value
                DoubleCollection ticks = null;

                if (GetValue(TicksProperty)
                    != null)
                {
                    ticks = Ticks;
                }

                // Draw ticks using specified Ticks collection
                if ((ticks != null) && (ticks.Count > 0))
                {
                    for (int i = 0; i < ticks.Count; i++)
                    {
                        if (DoubleUtil.LessThanOrClose(ticks[i], Minimum) || DoubleUtil.GreaterThanOrClose(ticks[i], Maximum))
                        {
                            continue;
                        }
                        double adjustedTick = ticks[i] - Minimum;

                        double x = adjustedTick * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen,
                                    new Point(x, startPoint.Y),
                                    new Point(x, startPoint.Y + tickLen2));

                        if (snapsToDevicePixels)
                        {
                            xLines.Add(x - 0.5);
                        }
                    }
                }
                // Draw ticks using specified TickFrequency
                else if (interval > 0.0)
                {
                    for (double i = interval; i < range; i += interval)
                    {
                        double x = i * logicalToPhysical + startPoint.X;
                        dc.DrawLine(pen,
                                    new Point(x, startPoint.Y),
                                    new Point(x, startPoint.Y + tickLen2));

                        if (snapsToDevicePixels)
                        {
                            xLines.Add(x - 0.5);
                        }
                    }
                }

                // Draw Selection Ticks
                if (IsSelectionRangeEnabled)
                {
                    double x0  = (SelectionStart - Minimum) * logicalToPhysical + startPoint.X;
                    Point  pt0 = new Point(x0, startPoint.Y);
                    Point  pt1 = new Point(x0, startPoint.Y + tickLen2);
                    Point  pt2 = new Point(x0 + Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);

                    //PathSegment[] segments = new PathSegment[] {
                    //    new LineSegment(pt2, true),
                    //    new LineSegment(pt0, true),
                    //};

                    PathSegments segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    PathGeometry geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };

                    dc.DrawGeometry(Fill, pen, geo);

                    x0  = (SelectionEnd - Minimum) * logicalToPhysical + startPoint.X;
                    pt0 = new Point(x0, startPoint.Y);
                    pt1 = new Point(x0, startPoint.Y + tickLen2);
                    pt2 = new Point(x0 - Math.Abs(tickLen2) * progression, startPoint.Y + tickLen2);

                    segments = new PathSegments();
                    segments.Add(new LineSegment {
                        Point = pt2
                    });
                    segments.Add(new LineSegment {
                        Point = pt0
                    });

                    geo = new PathGeometry {
                        Figures = new PathFigures {
                            new PathFigure {
                                StartPoint = pt1, Segments = segments, IsClosed = true
                            }
                        }
                    };
                    dc.DrawGeometry(Fill, pen, geo);
                }
            }

            if (snapsToDevicePixels)
            {
                xLines.Add(Width);
                yLines.Add(Height);
                VisualXSnappingGuidelines = xLines;
                VisualYSnappingGuidelines = yLines;
            }
            return;
        }
Ejemplo n.º 6
0
        private static void OnTickPlacementChanged(SliderEx slider, AvaloniaPropertyChangedEventArgs e)
        {
            if (slider.TopTickBar == null || slider.BottomTickBar == null)
            {
                return;
            }

            //strange behaviour in the view
            //right now we skip this
            if (slider.Orientation == Orientation.Vertical)
            {
                return;
            }

            //TopTickBar.Width = this.Width;
            //BottomTickBar.Width = this.Width;

            if (slider.Track?.Thumb != null)
            {
                switch (slider.Orientation)
                {
                case Orientation.Horizontal:
                    if (DoubleUtil.IsDoubleFinite(slider.Track.Thumb.Width))
                    {
                        slider.TopTickBar.ReservedSpace = slider.Track.Thumb.Width;
                    }
                    break;

                case Orientation.Vertical:
                    if (DoubleUtil.IsDoubleFinite(slider.Track.Thumb.Height))
                    {
                        slider.TopTickBar.ReservedSpace = slider.Track.Thumb.Height;
                    }
                    break;
                }
            }

            if (slider.Orientation == Orientation.Horizontal)
            {
                slider.Track.Thumb.Classes.Set("HorizontalSliderUpThumbStyle", slider.TickPlacement == TickPlacement.TopLeft);
                slider.Track.Thumb.Classes.Set("HorizontalSliderDownThumbStyle", slider.TickPlacement == TickPlacement.BottomRight);
            }
            else
            {
                slider.Track.Thumb.Classes.Set("VerticalSliderLeftThumbStyle", slider.TickPlacement == TickPlacement.TopLeft);
                slider.Track.Thumb.Classes.Set("VerticalSliderRightThumbStyle", slider.TickPlacement == TickPlacement.BottomRight);
            }

            TickPlacement tickBarPlacement = (TickPlacement)e.NewValue;

            switch (tickBarPlacement)
            {
            case TickPlacement.None:
                slider.TopTickBar.IsVisible    = false;
                slider.BottomTickBar.IsVisible = false;
                break;

            case TickPlacement.TopLeft:
                slider.TopTickBar.IsVisible = true;
                if (slider.Orientation == Orientation.Horizontal)
                {
                    slider.TrackBackground.Margin = new Thickness(5, 2, 5, 0);
                }
                else
                {
                    slider.TrackBackground.Margin = new Thickness(2, 5, 0, 5);
                }
                break;

            case TickPlacement.BottomRight:
                slider.BottomTickBar.IsVisible = true;
                if (slider.Orientation == Orientation.Horizontal)
                {
                    slider.TrackBackground.Margin = new Thickness(5, 2, 5, 0);
                }
                else
                {
                    slider.TrackBackground.Margin = new Thickness(0, 5, 2, 5);
                }
                break;

            case TickPlacement.Both:
                slider.TopTickBar.IsVisible    = true;
                slider.BottomTickBar.IsVisible = true;
                break;
            }
        }