예제 #1
0
        public override void RecalcLayout()
        {
            if (NeedRecalcLayout == true)
            {
                base.RecalcLayout();

                _LabelPoint = null;

                if (String.IsNullOrEmpty(_Text) == false)
                {
                    if (Scale is GaugeCircularScale)
                        CalcCircularLabelPoint(Scale as GaugeCircularScale);

                    else if (Scale is GaugeLinearScale)
                        CalcLinearLabelPoint(Scale as GaugeLinearScale);
                }
            }
        }
예제 #2
0
        private bool CanDisplayLabel(LabelPoint labelPoint)
        {
            if (labelPoint.Visible == false)
                return (false);

            if (Scale.HasCustomLabels == true)
            {
                foreach (GaugeCustomLabel label in Scale.CustomLabels)
                {
                    if (label.Visible == true)
                    {
                        if (label.Layout.Placement == Layout.Placement)
                        {
                            if (label.Value == Scale.MinValue + labelPoint.Interval)
                                return (false);
                        }
                    }
                }
            }

            return (true);
        }
예제 #3
0
        private Color GetLabelColor(LabelPoint lp)
        {
            Color labelColor = Scale.GetRangeLabelColor(lp.Interval);

            if (labelColor.IsEmpty == true)
                labelColor = Scale.GetSectionLabelColor(lp.Interval);

            if (labelColor.IsEmpty == true)
                labelColor = Layout.ForeColor;

            return (labelColor);
        }
예제 #4
0
        private SolidBrush GetLabelBrush(SolidBrush br, LabelPoint lp)
        {
            Color color = GetLabelColor(lp);

            if (br == null || br.Color != color)
            {
                if (br != null)
                    br.Dispose();

                br = new SolidBrush(color);
            }

            return (br);
        }
예제 #5
0
        private string GetLabelText(LabelPoint labelPoint)
        {
            double n = Scale.GetIntervalValue(labelPoint.Interval);

            if (String.IsNullOrEmpty(_FormatString) == false)
            {
                try
                {
                    switch (_FormatString[0])
                    {
                        case 'X':
                        case 'x':
                            return (String.Format("{0:" + _FormatString + "}", (int) n));

                        default:
                            return (String.Format("{0:" + _FormatString + "}", n));
                    }
                }
                catch
                {
                }
            }

            return (n.ToString());
        }
예제 #6
0
        private void CalcVerticalLabelPoints(GaugeLinearScale scale,
            int n, double dpt, double labelInterval, double labelIntervalOffset)
        {
            double interval = (_ShowMinLabel == true ?
                0 : labelIntervalOffset > 0 ? labelIntervalOffset : labelInterval);

            int x = scale.ScaleBounds.X + Offset;

            _LabelPoints = new LabelPoint[n];

            for (int i = 0; i < n; i++)
            {
                _LabelPoints[i] = new LabelPoint();

                if (interval + Scale.MinValue > Scale.MaxValue)
                    interval = Scale.MaxValue - Scale.MinValue;

                int y = (scale.Reversed == true)
                     ? (int)(Scale.Bounds.Top + dpt * interval)
                     : (int)(Scale.Bounds.Bottom - dpt * interval);

                _LabelPoints[i].Point = new Point(x, y);
                _LabelPoints[i].Interval = interval;

                if (interval >= labelIntervalOffset)
                    interval += labelInterval;
                else
                    interval = labelIntervalOffset;
            }
        }
예제 #7
0
        private void CalcCircularLabelPoints(GaugeCircularScale scale)
        {
            double labelInterval = (_Interval.Equals(double.NaN) ?
                scale.MajorTickMarks.Interval : _Interval);

            double labelIntervalOffset = (_IntervalOffset.Equals(double.NaN) ?
                scale.MajorTickMarks.IntervalOffset : _IntervalOffset);

            double spread = scale.MaxValue - scale.MinValue;
            double dpt = scale.SweepAngle / spread;

            int n = GetPointCount(spread, labelInterval, labelIntervalOffset);

            if (n > 0)
            {
                double startAngle = scale.StartAngle;
                double interval = (_ShowMinLabel == true ? 0 : labelIntervalOffset > 0 ? labelIntervalOffset : labelInterval);

                int dir = (scale.Reversed ? -1 : 1);

                if (scale.Reversed == true)
                    startAngle += scale.SweepAngle;

                _LabelPoints = new LabelPoint[n];

                for (int i = 0; i < n; i++)
                {
                    _LabelPoints[i] = new LabelPoint();

                    if (interval + scale.MinValue > scale.MaxValue)
                        interval = scale.MaxValue - scale.MinValue;

                    _LabelPoints[i].Angle = (float)(startAngle + (interval * dpt) * dir);
                    _LabelPoints[i].Point = scale.GetPoint(Radius, _LabelPoints[i].Angle);
                    _LabelPoints[i].Interval = interval;

                    if (interval >= labelIntervalOffset)
                        interval += labelInterval;
                    else
                        interval = labelIntervalOffset;
                }
            }
            else
            {
                _LabelPoints = null;
            }
        }
예제 #8
0
        private void CalcCircularLabelPoint(GaugeCircularScale scale)
        {
            if (Radius > 0)
            {
                _LabelPoint = new LabelPoint();

                _LabelPoint.Angle = _GaugePin.Angle;
                _LabelPoint.Point = scale.GetPoint(Radius, _LabelPoint.Angle);
            }
        }
예제 #9
0
        internal void PaintAdaptiveLabel(Graphics g,
            string text, Brush br, LabelPoint lp, Font font)
        {
            SizeF tw = g.MeasureString(text, font);

            if (Layout.Placement == DisplayPlacement.Near)
                tw.Width += text.Length;

            float c = (float)(Math.PI * _Radius * 2);

            if (c > 0)
            {
                float radians = (float)GetRadians(lp.Angle);
                float radOffset = (float)GetRadians((180 * tw.Width) / c);
                float radCenter = radians;

                radians -= radOffset;

                bool flip = false;

                if (_Layout.AutoOrientLabel == true)
                {
                    flip = ((GetDegrees(radCenter) % 360) < 180);

                    if (flip == true)
                        radians += (radOffset * 2);
                }

                int n = (int)Math.Ceiling((double)text.Length / 32);

                for (int i = 0; i < n; i++)
                {
                    int len = Math.Min(text.Length - (i * 32), 32);

                    radians = PaintAdaptiveText(g,
                        text.Substring(i * 32, len), br, font, radians, flip);
                }
            }
        }
예제 #10
0
        private void CalcLinearLabelPoint(GaugeLinearScale scale)
        {
            _LabelPoint = new LabelPoint();

            if (scale.Orientation == Orientation.Horizontal)
            {
                _LabelPoint.Point = new Point(
                    _GaugePin.Bounds.X + _GaugePin.Bounds.Width / 2,
                    scale.ScaleBounds.Y + Offset);
            }
            else
            {
                _LabelPoint.Point = new Point(
                   scale.ScaleBounds.X + Offset,
                   _GaugePin.Bounds.Y + _GaugePin.Bounds.Height / 2);
            }
        }
예제 #11
0
        internal void PaintNonRotatedLabel(Graphics g,
            string text, Brush br, LabelPoint lp, Font font)
        {
            SizeF sz = g.MeasureString(text, font);
            Size size = sz.ToSize();

            float fontAngle = 360 - ((lp.Angle + Layout.Angle + 90) % 360);

            g.TranslateTransform(lp.Point.X, lp.Point.Y);
            g.RotateTransform((lp.Angle + 90) % 360);

            g.TranslateTransform(0, GetRadiusDelta(size.Width, size.Height, fontAngle));
            g.RotateTransform(fontAngle % 360);

            g.DrawString(text, font, br,
                new Point(-size.Width / 2, -size.Height / 2));

            g.ResetTransform();
        }
예제 #12
0
        private void PaintLinearRotatedLabel(Graphics g, string text,
            Brush br, LabelPoint lp, Font font, GaugeLinearScale scale)
        {
            SizeF sz = g.MeasureString(text, font);
            Size size = sz.ToSize();

            float fontAngle = Layout.Angle;

            g.TranslateTransform(lp.Point.X, lp.Point.Y);

            if (scale.Orientation == Orientation.Horizontal)
                g.TranslateTransform(0, -GetRadiusDelta(size.Width, size.Height, fontAngle));
            else
                g.TranslateTransform(-GetRadiusDelta(size.Height, size.Width, fontAngle), 0);

            g.RotateTransform(fontAngle % 360);

            g.DrawString(text, font, br,
                         new Point(-size.Width / 2, -size.Height / 2));

            g.ResetTransform();
        }
예제 #13
0
        private void PaintCircularRotatedLabel(
            Graphics g, string text, Brush br, LabelPoint lp, Font font)
        {
            SizeF sz = g.MeasureString(text, font);
            Size size = sz.ToSize();

            float fontAngle = Layout.Angle;

            if (Layout.AutoOrientLabel == true)
            {
                if (((fontAngle + lp.Angle) % 360) < 180)
                    fontAngle += 180;
            }

            g.TranslateTransform(lp.Point.X, lp.Point.Y);
            g.RotateTransform((lp.Angle + 90) % 360);

            g.TranslateTransform(0, GetRadiusDelta(size.Width, size.Height, fontAngle));
            g.RotateTransform(fontAngle % 360);

            g.DrawString(text, font, br,
                new Point(-size.Width / 2, -size.Height / 2));

            g.ResetTransform();
        }
예제 #14
0
        internal void PaintRotatedLabel(Graphics g,
            string text, Brush br, LabelPoint lp, Font font)
        {
            if (Scale is GaugeCircularScale)
                PaintCircularRotatedLabel(g, text, br, lp, font);

            else if (Scale is GaugeLinearScale)
                PaintLinearRotatedLabel(g, text, br, lp, font, Scale as GaugeLinearScale);
        }
예제 #15
0
 internal void PaintLabel(Graphics g,
     string text, Brush br, LabelPoint lp, Font font)
 {
     if (Scale.Style == GaugeScaleStyle.Circular)
     {
         if (Layout.AdaptiveLabel == true)
         {
             PaintAdaptiveLabel(g, text, br, lp, font);
         }
         else
         {
             if (Layout.RotateLabel == true)
                 PaintRotatedLabel(g, text, br, lp, font);
             else
                 PaintNonRotatedLabel(g, text, br, lp, font);
         }
     }
     else
     {
         PaintRotatedLabel(g, text, br, lp, font);
     }
 }