Ejemplo n.º 1
0
        public override bool DrawNeedle(Graphics Gr, RectangleF rc)
        {
            if (this.AnalogMeter == null)
            {
                return(false);
            }

            float w, h;

            w = rc.Width;
            h = rc.Height;

            double minValue     = this.AnalogMeter.MinValue;
            double maxValue     = this.AnalogMeter.MaxValue;
            double currValue    = this.AnalogMeter.Value;
            float  startAngle   = this.AnalogMeter.GetStartAngle();
            float  endAngle     = this.AnalogMeter.GetEndAngle();
            PointF needleCenter = this.AnalogMeter.GetNeedleCenter();

            float radius = (float)(w / 2 - (w * 0.12));
            float val    = (float)(maxValue - minValue);

            val  = (float)((100 * (currValue - minValue)) / val);
            val  = ((endAngle - startAngle) * val) / 100;
            val += startAngle;

            float angle = LBMath.GetRadian(val);

            float cx = needleCenter.X;
            float cy = needleCenter.Y;

            PointF ptStart = new PointF(0, 0);
            PointF ptEnd   = new PointF(0, 0);

            GraphicsPath pth1 = new GraphicsPath();

            ptStart.X = cx;
            ptStart.Y = cy;
            angle     = LBMath.GetRadian(val + 10);
            // this controls needle width
            ptEnd.X = (float)(cx + (w * .01F) * Math.Cos(angle));
            ptEnd.Y = (float)(cy + (w * .01F) * Math.Sin(angle));
            pth1.AddLine(ptStart, ptEnd);

            ptStart = ptEnd;
            angle   = LBMath.GetRadian(val);
            ptEnd.X = (float)(cx + (radius * 1.5f) * Math.Cos(angle));
            ptEnd.Y = (float)(cy + (radius * 1.5f) * Math.Sin(angle));

            pth1.AddLine(ptStart, ptEnd);

            /*/
             * ptStart = ptEnd;
             * angle = LBMath.GetRadian(val - 10);
             * ptEnd.X = (float)(cx + (w * .09F) * Math.Cos(angle));
             * ptEnd.Y = (float)(cy + (w * .09F) * Math.Sin(angle));
             * pth1.AddLine ( ptStart, ptEnd );
             *
             * pth1.CloseFigure();
             * /*/

            SolidBrush br = new SolidBrush(Color.Red);

            // Pen pen = new Pen ( this.AnalogMeter.NeedleColor );
            Pen pen = new Pen(Color.Red);

            pen.Width = 2;
            Gr.DrawPath(pen, pth1);
            Gr.FillPath(br, pth1);

            return(true);
        }
Ejemplo n.º 2
0
        public override bool DrawDivisions(Graphics Gr, RectangleF rc)
        {
            if (this.AnalogMeter == null)
            {
                return(false);
            }

            float  startAngle        = this.AnalogMeter.GetStartAngle();
            float  endAngle          = this.AnalogMeter.GetEndAngle();
            float  scaleDivisions    = this.AnalogMeter.ScaleDivisions;
            float  scaleSubDivisions = this.AnalogMeter.ScaleSubDivisions;
            double minValue          = this.AnalogMeter.MinValue;
            double maxValue          = this.AnalogMeter.MaxValue;
            Color  scaleColor        = this.AnalogMeter.ScaleColor;

            float cx = needleCenter.X;
            float cy = needleCenter.Y;
            float w  = rc.Width;
            float h  = rc.Height;

            float incr         = LBMath.GetRadian((endAngle - startAngle) / ((scaleDivisions - 1) * (scaleSubDivisions + 1)));
            float currentAngle = LBMath.GetRadian(startAngle);
            float radius       = (float)(w / 2 - (w * 0.08));
            float rulerValue   = (float)minValue;

            Pen        pen = new Pen(scaleColor, (2 * drawRatio));
            SolidBrush br  = new SolidBrush(scaleColor);

            PointF     ptStart  = new PointF(0, 0);
            PointF     ptEnd    = new PointF(0, 0);
            PointF     ptCenter = new PointF(0, 0);
            RectangleF rcTick   = new RectangleF(0, 0, 0, 0);
            SizeF      sizeMax  = new SizeF(10 * drawRatio, 10 * drawRatio);
            SizeF      sizeMin  = new SizeF(4 * drawRatio, 4 * drawRatio);

            int n = 0;

            for ( ; n < scaleDivisions; n++)
            {
                //Draw Thick Line
                ptCenter.X      = (float)(cx + (radius - w / 90) * Math.Cos(currentAngle));
                ptCenter.Y      = (float)(cy + (radius - w / 90) * Math.Sin(currentAngle));
                ptStart.X       = ptCenter.X - (5 * drawRatio);
                ptStart.Y       = ptCenter.Y - (5 * drawRatio);
                rcTick.Location = ptStart;
                rcTick.Size     = sizeMax;
                Gr.FillEllipse(br, rcTick);

                //Draw Strings
                Font font = new Font(this.AnalogMeter.Font.FontFamily, (float)(8F * drawRatio), FontStyle.Italic);

                float  tx  = (float)(cx + (radius - (20 * drawRatio)) * Math.Cos(currentAngle));
                float  ty  = (float)(cy + (radius - (20 * drawRatio)) * Math.Sin(currentAngle));
                double val = Math.Round(rulerValue);
                String str = String.Format("{0,0:D}", (int)val);

                SizeF size = Gr.MeasureString(str, font);
                Gr.DrawString(str,
                              font,
                              br,
                              tx - (float)(size.Width * 0.5),
                              ty - (float)(size.Height * 0.5));

                rulerValue += (float)((maxValue - minValue) / (scaleDivisions - 1));

                if (n == scaleDivisions - 1)
                {
                    break;
                }

                if (scaleDivisions <= 0)
                {
                    currentAngle += incr;
                }
                else
                {
                    for (int j = 0; j <= scaleSubDivisions; j++)
                    {
                        currentAngle += incr;

                        ptCenter.X      = (float)(cx + (radius - w / 90) * Math.Cos(currentAngle));
                        ptCenter.Y      = (float)(cy + (radius - w / 90) * Math.Sin(currentAngle));
                        ptStart.X       = ptCenter.X - (2 * drawRatio);
                        ptStart.Y       = ptCenter.Y - (2 * drawRatio);
                        rcTick.Location = ptStart;
                        rcTick.Size     = sizeMin;
                        Gr.FillEllipse(br, rcTick);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public virtual bool DrawDivisions(Graphics Gr, RectangleF rc)
        {
            if (this.AnalogMeter == null)
            {
                return(false);
            }

            float  startAngle        = this.AnalogMeter.GetStartAngle();
            float  endAngle          = this.AnalogMeter.GetEndAngle();
            float  scaleDivisions    = this.AnalogMeter.ScaleDivisions;
            float  scaleSubDivisions = this.AnalogMeter.ScaleSubDivisions;
            double minValue          = this.AnalogMeter.MinValue;
            double maxValue          = this.AnalogMeter.MaxValue;
            Color  scaleColor        = this.AnalogMeter.ScaleColor;

            float cx = needleCenter.X;
            float cy = needleCenter.Y;
            float w  = rc.Width;
            float h  = rc.Height;

            float incr         = LBMath.GetRadian((endAngle - startAngle) / ((scaleDivisions - 1) * (scaleSubDivisions + 1)));
            float currentAngle = LBMath.GetRadian(startAngle);
            float radius       = (float)(w / 2 - (w * 0.08));
            float rulerValue   = (float)minValue;

            Pen        pen = new Pen(scaleColor, (1 * drawRatio));
            SolidBrush br  = new SolidBrush(scaleColor);

            PointF ptStart = new PointF(0, 0);
            PointF ptEnd   = new PointF(0, 0);
            int    n       = 0;

            for (; n < scaleDivisions; n++)
            {
                //Draw Thick Line
                ptStart.X = (float)(cx + radius * Math.Cos(currentAngle));
                ptStart.Y = (float)(cy + radius * Math.Sin(currentAngle));
                ptEnd.X   = (float)(cx + (radius - w / 20) * Math.Cos(currentAngle));
                ptEnd.Y   = (float)(cy + (radius - w / 20) * Math.Sin(currentAngle));
                Gr.DrawLine(pen, ptStart, ptEnd);

                //Draw Strings
                Font font = new Font(this.AnalogMeter.Font.FontFamily, (float)(6F * drawRatio));

                float  tx  = (float)(cx + (radius - (20 * drawRatio)) * Math.Cos(currentAngle));
                float  ty  = (float)(cy + (radius - (20 * drawRatio)) * Math.Sin(currentAngle));
                double val = Math.Round(rulerValue);
                String str = String.Format("{0,0:D}", (int)val);

                SizeF size = Gr.MeasureString(str, font);
                Gr.DrawString(str,
                              font,
                              br,
                              tx - (float)(size.Width * 0.5),
                              ty - (float)(size.Height * 0.5));

                rulerValue += (float)((maxValue - minValue) / (scaleDivisions - 1));

                if (n == scaleDivisions - 1)
                {
                    font.Dispose();
                    break;
                }

                if (scaleDivisions <= 0)
                {
                    currentAngle += incr;
                }
                else
                {
                    for (int j = 0; j <= scaleSubDivisions; j++)
                    {
                        currentAngle += incr;
                        ptStart.X     = (float)(cx + radius * Math.Cos(currentAngle));
                        ptStart.Y     = (float)(cy + radius * Math.Sin(currentAngle));
                        ptEnd.X       = (float)(cx + (radius - w / 50) * Math.Cos(currentAngle));
                        ptEnd.Y       = (float)(cy + (radius - w / 50) * Math.Sin(currentAngle));
                        Gr.DrawLine(pen, ptStart, ptEnd);
                    }
                }

                font.Dispose();
            }

            return(true);
        }