Ejemplo n.º 1
0
        private Point[] GetKnobLine(int l)
        {
            var pret = new Point[2];

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

            float radius = _knobRectangle.Width / 2;

            float degree = (_deltaAngle * Value) / (_maximum - _minimum);

            degree = MathManager.DegreeToRadians(degree + _startAngle);

            Point Pos = new Point(0, 0);

            Pos.X = (int)(cx + ((radius - (_drawRatio * 10)) * Math.Cos(degree)));
            Pos.Y = (int)(cy + ((radius - (_drawRatio * 10)) * Math.Sin(degree)));

            pret[0] = new Point(Pos.X, Pos.Y);

            Pos.X = (int)(cx + ((radius - (_drawRatio * 10) - l) * Math.Cos(degree)));
            Pos.Y = (int)(cy + ((radius - (_drawRatio * 10) - l) * Math.Sin(degree)));

            pret[1] = new Point(Pos.X, Pos.Y);

            return(pret);
        }
Ejemplo n.º 2
0
        private Point GetKnobPosition(int l)
        {
            float cx = _knobPoint.X;
            float cy = _knobPoint.Y;

            float radius = _knobRectangle.Width / 2;

            float degree = (_deltaAngle * Value) / (_maximum - _minimum);

            degree = MathManager.DegreeToRadians(degree + _startAngle);

            Point Pos = new Point(0, 0)
            {
                X = (int)(cx + ((radius - (KnobDistance * _drawRatio)) * Math.Cos(degree))), Y = (int)(cy + ((radius - (KnobDistance * _drawRatio)) * Math.Sin(degree)))
            };

            return(Pos);
        }
Ejemplo n.º 3
0
        private bool DrawDivisions(Graphics graphics, RectangleF rectangleF)
        {
            if (this == null)
            {
                return(false);
            }

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

            float w = rectangleF.Width;
            float h = rectangleF.Height;

            float tx;
            float ty;

            float incr         = MathManager.DegreeToRadians((_endAngle - _startAngle) / ((_scaleDivisions - 1) * (_scaleSubDivisions + 1)));
            float currentAngle = MathManager.DegreeToRadians(_startAngle);

            float radius     = _knobRectangle.Width / 2;
            float rulerValue = _minimum;

            Pen penL = new Pen(TickColor, 2 * _drawRatio);
            Pen penS = new Pen(TickColor, 1 * _drawRatio);

            SolidBrush br = new SolidBrush(ForeColor);

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

            if (_showLargeScale)
            {
                for (; n < _scaleDivisions; n++)
                {
                    // draw divisions
                    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)));

                    graphics.DrawLine(penL, ptStart, ptEnd);

                    // Draw graduations Strings
                    float fSize = 6F * _drawRatio;
                    if (fSize < 6)
                    {
                        fSize = 6;
                    }

                    Font font = new Font(Font.FontFamily, fSize);

                    double val  = Math.Round(rulerValue);
                    string str  = string.Format("{0,0:D}", (int)val);
                    SizeF  size = graphics.MeasureString(str, font);

                    if (_drawDivInside)
                    {
                        // graduations strings inside the knob
                        tx = (float)(cx + ((radius - (11 * _drawRatio)) * Math.Cos(currentAngle)));
                        ty = (float)(cy + ((radius - (11 * _drawRatio)) * Math.Sin(currentAngle)));
                    }
                    else
                    {
                        // graduation strings outside the knob
                        tx = (float)(cx + ((radius + (11 * _drawRatio)) * Math.Cos(currentAngle)));
                        ty = (float)(cy + ((radius + (11 * _drawRatio)) * Math.Sin(currentAngle)));
                    }

                    graphics.DrawString(str,
                                        font,
                                        br,
                                        tx - (float)(size.Width * 0.5),
                                        ty - (float)(size.Height * 0.5));

                    rulerValue += (_maximum - _minimum) / (_scaleDivisions - 1);

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

                    // Subdivisions
                    if (_scaleDivisions <= 0)
                    {
                        currentAngle += incr;
                    }
                    else
                    {
                        for (var j = 0; j <= _scaleSubDivisions; j++)
                        {
                            currentAngle += incr;

                            // if user want to display small graduations
                            if (_showSmallScale)
                            {
                                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)));

                                graphics.DrawLine(penS, ptStart, ptEnd);
                            }
                        }
                    }

                    font.Dispose();
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void DrawKnobTop()
        {
            Point     knobTopPoint     = new Point((_knobRectangle.X + (_knobRectangle.Width / 2)) - (KnobTopSize.Width / 2), (_knobRectangle.Y + (_knobRectangle.Height / 2)) - (KnobTopSize.Height / 2));
            Rectangle knobTopRectangle = new Rectangle(knobTopPoint, KnobTopSize);

            _offGraphics.FillEllipse(_knobTop.Brush, knobTopRectangle);

            GraphicsPath borderPath = new GraphicsPath();

            borderPath.AddEllipse(knobTopRectangle);
            VisualBorderRenderer.DrawBorderStyle(_offGraphics, _knobTopBorder, borderPath, State);

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

            float w = KnobTopSize.Width;

            // TODO: Adjust
            float incr         = MathManager.DegreeToRadians((_startAngle - _endAngle) / ((_buttonDivisions - 1) * (_scaleSubDivisions + 1)));
            float currentAngle = MathManager.DegreeToRadians(0);

            float radius = KnobTickSize.Width / 2;

            Pen penL = new Pen(TickColor, 2 * _drawRatio);

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

            for (; n < _buttonDivisions; n++)
            {
                // draw divisions
                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)));

                // TODO: draw lines along button border
                // gOffScreen.DrawLine(penL, ptStart, ptEnd);

                // Draw graduations Strings
                float fSize = 6F * _drawRatio;
                if (fSize < 6)
                {
                    fSize = 6;
                }

                Font font = new Font(Font.FontFamily, fSize);

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

                // Subdivisions
                if (_buttonDivisions <= 0)
                {
                    currentAngle += incr;
                }
                else
                {
                    for (var j = 0; j <= _scaleSubDivisions; j++)
                    {
                        currentAngle += incr;
                    }
                }

                font.Dispose();
            }
        }