Exemplo n.º 1
0
        private void LayoutMark(ref Size sizeLabel, DialMarkContext context)
        {
            Shape shape;
            Label label = null;
            Style style = context.isMajor ? context.styleLarge : context.styleSmall;
            bool isPoly = true;

            if (style.TargetType == typeof(Polygon))
                shape = new Polygon();
            else
            {
                shape = new Ellipse();
                isPoly = false;
            }

            shape.Style = style;
            context.canvas.Children.Add(shape);

            if (context.isMajor)
            {

                label = new Label();
                label.Style = context.styleDialNumeral;
                label.Content = context.labelValue.ToString();

                label.Background = new SolidColorBrush(); // transparent
                label.BorderThickness = new Thickness(0.0);
                label.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                label.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;

                label.FontSize = context.dialNumeralFontSize;
            }

            Point outerPoint = PointOnEllipse(DialRadiusX, DialRadiusY, context.angle);
            Point innerPoint = PointOnEllipse(context.radiusXInner, context.radiusYInner, context.angle);

            Double eAngle = Math.Atan2(innerPoint.Y, innerPoint.X) * 180.0 / Math.PI;
            Double outerLen = Math.Pow(Math.Pow(outerPoint.X, 2.0) + Math.Pow(outerPoint.Y, 2.0), 0.5);
            Double innerLen = Math.Pow(Math.Pow(innerPoint.X, 2.0) + Math.Pow(innerPoint.Y, 2.0), 0.5);
            Double adjustedWidth = outerLen - innerLen;

            {
                TransformGroup tGroup = new TransformGroup();
                ScaleTransform stf = new ScaleTransform(context.dialMarkerScale * adjustedWidth / context.gaugeWidth, 1.0);
                TranslateTransform ttf;
                if (isPoly)
                    ttf = new TranslateTransform(-(outerLen - DialMarkerGapBase), 0.0);
                else // unsue why this is needed for ellipse / circle
                    ttf = new TranslateTransform(-(outerLen - DialMarkerGapBase), - shape.Height / 2.0);
                RotateTransform rtf = new RotateTransform(eAngle);

                tGroup.Children.Add(stf);
                tGroup.Children.Add(ttf);
                tGroup.Children.Add(rtf);
                shape.RenderTransform = tGroup;

                AdjustDropShadow(shape, eAngle + Rotation);

                //context.canvas.Children.Add(shape);
            }

            if (label != null)
            {
                context.canvas.Children.Add(label);

                label.Measure(new Size(Double.MaxValue, Double.MaxValue));
                label.Margin = new Thickness(0.0);
                label.Padding = new Thickness(0.0);
                sizeLabel = label.DesiredSize;
                label.Width = sizeLabel.Width;
                label.Height = sizeLabel.Height;

                TransformGroup tGroup = new TransformGroup();
                ScaleTransform stf = new ScaleTransform(adjustedWidth / context.gaugeWidth, 1.0);
                RotateTransform rtf = new RotateTransform(-Rotation, sizeLabel.Width / 2.0 + 5.0, sizeLabel.Height / 2.0);

                tGroup.Children.Add(stf);
                tGroup.Children.Add(rtf);
                label.RenderTransform = tGroup;

                Point labelPoint =
                    PointOnEllipse(context.radiusXInner - (context.dialNumeralGap + sizeLabel.Width / 2.0),
                    context.radiusYInner - (context.dialNumeralGap + sizeLabel.Height / 2.5), context.angle);

                label.SetValue(Canvas.TopProperty, -(labelPoint.Y + sizeLabel.Height / 2.0));
                label.SetValue(Canvas.LeftProperty, -(labelPoint.X + 5.0 + sizeLabel.Width / 2.0));

                if ((label.Effect != null)
                && (label.Effect.GetType() == typeof(DropShadowEffect)))
                {
                    DropShadowEffect shadow = new DropShadowEffect();
                    shadow.Color = ((DropShadowEffect)shape.Effect).Color;
                    shadow.Opacity = ((DropShadowEffect)shape.Effect).Opacity;
                    shadow.BlurRadius = ((DropShadowEffect)shape.Effect).BlurRadius;
                    shadow.ShadowDepth = ((DropShadowEffect)shape.Effect).ShadowDepth;
                    shadow.Direction = DropShadowAngle;
                    label.Effect = shadow;
                }
            }
        }
Exemplo n.º 2
0
        private void LayoutDialSection(bool isLeft, bool fullDial, ref Size sizeLabel, DialMarkContext context)
        {
            int marks;
            int minorMarks = isLeft ? Scale1LeftMinorMarks : Scale1RightMinorMarks;
            int scale1Multiplier = geometry.Scale1Multiplier;

            Double majorIncrement;
            Double minorIncrement;

            if (isLeft)
                marks = geometry.Scale1LeftMarks;
            else
                marks = geometry.Scale1RightMarks;

            majorIncrement = fullDial ? DialArc / (marks) : DialArc / (2.0 * marks);
            minorIncrement = majorIncrement / (minorMarks + 1);

            if (DialReverse)
            {
                majorIncrement = -majorIncrement;
                minorIncrement = -minorIncrement;
            }

            context.labelValue = (Double)(isLeft ? (geometry.Scale1Min / scale1Multiplier) :
                (fullDial ? (geometry.Scale1Min / scale1Multiplier) : (geometry.Scale1Centre / scale1Multiplier)));
            Double labelIncrement = (Double)(isLeft ? ((geometry.Scale1Centre - geometry.Scale1Min) / (scale1Multiplier * geometry.Scale1LeftMarks)) :
                (fullDial ? ((geometry.Scale1Max - geometry.Scale1Min) / (scale1Multiplier * geometry.Scale1RightMarks)) :
                ((geometry.Scale1Max - geometry.Scale1Centre) / (scale1Multiplier * geometry.Scale1RightMarks))));

            Double majorAngle = isLeft ? MinAngle : (fullDial ? MinAngle : 90.0);
            if (DialReverse && (isLeft || fullDial))
                majorAngle += DialArc;

            // Start with a Major Mark
            context.isMajor = true;
            context.angle = majorAngle;

            if (isLeft || fullDial)
                LayoutMark(ref sizeLabel, context);

            for (int iMajor = 0; iMajor < marks; iMajor++)
            {
                context.isMajor = false;
                for (int iMinor = 1; iMinor <= minorMarks; iMinor++)
                {
                    context.angle = majorAngle + (iMinor * minorIncrement);
                    LayoutMark(ref sizeLabel, context);
                }

                context.labelValue += labelIncrement;
                majorAngle += majorIncrement;
                context.angle = majorAngle;
                context.isMajor = true;
                LayoutMark(ref sizeLabel, context);
            }
        }