Exemple #1
0
        private void UpdateRingThumb()
        {
            if (_ringThumb == null)
            {
                return;
            }

            if (_containerGrid.ActualHeight <= 2 * (RingThickness + ThumbBorderThickness) ||
                _containerGrid.ActualWidth <= 2 * (RingThickness + ThumbBorderThickness))
            {
                return;
            }

            //VisualTreeDebugger2.DebugVisualTree(_ringThumb, true);

            // Hue ring needs to be smaller than available container space so the thumb fits
            var hueRingSize = Math.Min(
                _containerGrid.ActualWidth - 2 * ThumbBorderThickness,
                _containerGrid.ActualHeight - 2 * ThumbBorderThickness);

            //if (_ringThumb.Width != hueRingSize + 2 * ThumbBorderThickness)
            {
                _ringThumb.Width  = hueRingSize + 2 * ThumbBorderThickness;
                _ringThumb.Height = hueRingSize + 2 * ThumbBorderThickness;

                _ringThumb.BeginUpdate();

                // Half of the thumb border stroke goes outside the radius and the other half goes inside,
                // so radius needs to be 0.5 border thickness larger than the hue ring's outer radius.
                // Less 1 to make sure there is an overlap.
                _ringThumb.Center =
                    new Point(
                        hueRingSize / 2 + ThumbBorderThickness,
                        hueRingSize / 2 + ThumbBorderThickness);
                _ringThumb.Radius      = (hueRingSize + ThumbBorderThickness) / 2 - 1;
                _ringThumb.InnerRadius = _ringThumb.Radius - RingThickness - ThumbBorderThickness + 2;
                _ringThumb.StartAngle  = this.Value - ThumbArcAngle / 2;
                _ringThumb.EndAngle    = this.Value + ThumbArcAngle / 2;
                //_ringThumb.StartAngle = - ThumbArcAngle / 2;
                //_ringThumb.EndAngle = ThumbArcAngle / 2;
                _ringThumb.EndUpdate();
            }

            _ringThumb.Stroke =
                new SolidColorBrush(
                    ColorExtensions.FromHsv(this.Value, 0.5, 1.0));
        }