Exemplo n.º 1
0
        void drawTo(Graphics g)
        {
            GraphicsUtil.TextPosition titlePos = new GraphicsUtil.TextPosition();
            GraphicsUtil.TextPosition valuePos = new GraphicsUtil.TextPosition();
            VectorRect bar    = new VectorRect();
            VectorRect handle = new VectorRect();
            Vector     vlow   = Vector.Zero;
            Vector     vhigh  = Vector.Zero;

            getPositions(ref titlePos, ref valuePos, ref bar, ref handle, ref vlow, ref vhigh);

            double hlen = 0;

            if (_showScale)
            {
                if (_slideDirection == SlideDirection.Horizontal)
                {
                    hlen = (vhigh.x - vlow.x) / scale;
                    if (grid == null)
                    {
                        grid = new GridCalculator(_minVal, _maxVal, 1e-12, 1e-12, 1.1, _minVal, _maxVal, _logScale, 0, hlen, (double)_scaleFont.Height * _lableLength);
                    }
                    else if (grid.high != hlen)
                    {
                        grid.reScreen(0, hlen);
                    }
                }
                else
                {
                    hlen = (vlow.y - vhigh.y) / scale;
                    if (grid == null)
                    {
                        grid = new GridCalculator(_minVal, _maxVal, 1e-12, 1e-12, 1.1, _minVal, _maxVal, _logScale, 0, hlen, (double)_scaleFont.Height);
                        grid.showEndLables = true;
                    }
                    else if (grid.high != hlen)
                    {
                        grid.reScreen(0, hlen);
                    }
                }
            }

            // Title
            if (_showTitle && (_title != null) && (_title.Length > 0))
            {
                titlePos.drawText(g, _titleFont, titleBrush, _title);
            }

            // Value
            if (_showValue)
            {
                String s = String.Format(getFormat(), _val);
                if ((unit != null) && (unit.Length > 0))
                {
                    s = s + " " + unit;
                }
                valuePos.drawText(g, _valueFont, valueBrush, s);
            }
            g.DrawRectangle(penSlide, bar.rectangle);

            g.FillRectangle(brushSlideMark, handle.rectangle);
            g.DrawRectangle(penSlideMark, handle.rectangle);

            if (_showScale)
            {
                GraphicsUtil.drawLine(g, vlow, vhigh, scalePen);
                Vector vr    = 0.5 * _slideScaleWidth * scale * ((vhigh - vlow).norm).vrot90();
                Vector vtext = Vector.Zero;
                if (_slideDirection == SlideDirection.Horizontal)
                {
                    vtext = Vector.V(0, _slideScaleWidth / 2 * scale);
                }
                else
                {
                    vtext = Vector.V(_slideScaleWidth / 2 * scale, 0);
                }

                for (int i = 0; i < grid.gridLength; i++)
                {
                    Vector vpos = vlow + (vhigh - vlow) * grid.grid[i].screen / hlen;
                    if (grid.grid[i].isMajor)
                    {
                        GraphicsUtil.drawLine(g, vpos - vr, vpos + vr, scalePen);
                    }
                    else
                    {
                        GraphicsUtil.drawLine(g, vpos - vr / 2, vpos + vr / 2, scalePen);
                    }

                    if (_showScaleValues && grid.grid[i].show && (grid.grid[i].name.Length > 0))
                    {
                        if (_slideDirection == SlideDirection.Horizontal)
                        {
                            GraphicsUtil.drawText(g, vpos + vtext, _scaleFont, scale,
                                                  grid.grid[i].name, 0, 2, 0, 1, Vector.V(1, 0), scaleFontBrush);
                        }
                        else
                        {
                            GraphicsUtil.drawText(g, vpos + vtext, _scaleFont, scale,
                                                  grid.grid[i].name, 0, 2, -1, 0, Vector.V(1, 0), scaleFontBrush);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void drawTo(Graphics g)
        {
            // Background
            //Brush brushBackground = new SolidBrush(BackColor);
            //g.FillRectangle(brushBackground, this.ClientRectangle);

            Rectangle shape = new Rectangle();

            GraphicsUtil.TextPosition tp = new GraphicsUtil.TextPosition();
            getShapeCoords(ref shape, ref tp);

            if ((_titlePos != RTTitlePos.Off) && (_title != null) && (_title.Length > 0))
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                tp.drawText(g, _titleFont, titleBrush, _title);
            }

            Pen       framePen = new Pen(_frameColor);
            Rectangle oshape   = shape;

            shape.Inflate(-1, -1);

            double ymin = 0, ymax = 0;

            Vector[] l = getShape(shape, ref ymin, ref ymax);

            Brush scaleBrush   = new SolidBrush(_scaleColor);
            Pen   majorGridPen = new Pen(_majorGridColor);
            Pen   minorGridPen = new Pen(_minorGridColor);

            for (int i = 0; i < gridY.gridLength; i++)
            {
                double y = shape.Bottom - gridY.grid[i].screen;
                string s = gridY.grid[i].name;
                if (gridY.grid[i].isMajor && _showYScale)
                {
                    GraphicsUtil.drawText(g, Vector.V(shape.Left, y), _scaleFont, scale, s, 0, 2, 1, 0, Vector.X, scaleBrush);
                }
                if (gridY.grid[i].isMajor && _showMajorYGrid)
                {
                    GraphicsUtil.drawLine(g, Vector.V(shape.Left, y), Vector.V(shape.Right, y), majorGridPen);
                }
                if (!gridY.grid[i].isMajor && _showMinorYGrid)
                {
                    GraphicsUtil.drawLine(g, Vector.V(shape.Left, y), Vector.V(shape.Right, y), minorGridPen);
                }
            }
            for (int i = 0; i < gridX.gridLength; i++)
            {
                double x = shape.Left + gridX.grid[i].screen;
                string s = gridX.grid[i].name;
                if (gridX.grid[i].isMajor && showXScale)
                {
                    GraphicsUtil.drawText(g, Vector.V(x, shape.Bottom), _scaleFont, scale, s, 0, 2, -1, 0, Vector.Y, scaleBrush);
                }
                if (gridX.grid[i].isMajor && _showMajorXGrid)
                {
                    GraphicsUtil.drawLine(g, Vector.V(x, shape.Bottom), Vector.V(x, shape.Top), majorGridPen);
                }
                if (!gridX.grid[i].isMajor && _showMinorXGrid)
                {
                    GraphicsUtil.drawLine(g, Vector.V(x, shape.Bottom), Vector.V(x, shape.Top), minorGridPen);
                }
            }

            g.DrawRectangle(framePen, oshape);

            Pen   anchorPen = new Pen(_anchorColor);
            Brush selBrush  = null;

            if (dragMode == DragMode.Holding)
            {
                selBrush = new SolidBrush(Color.Red);
            }
            Point[] p = new Point[l.Length];
            g.SetClip(shape);
            for (int i = 0; i < l.Length; i++)
            {
                p[i] = l[i].Point;
                if (i > 0)
                {
                    Rectangle A = new Rectangle(p[i].X - _anchorSize / 2, p[i].Y - _anchorSize / 2, _anchorSize, _anchorSize);
                    if ((dragMode == DragMode.Holding) && (dragSelect == i))
                    {
                        g.FillRectangle(selBrush, A);
                    }
                    else
                    {
                        g.DrawRectangle(anchorPen, A);
                    }
                }
            }
            Pen shapePen = new Pen(_shapeColor);

            g.DrawLines(shapePen, p);
        }