Пример #1
0
        void drawTo(Graphics g)
        {
            // Contact Point
            Vector    center = Vector.V(0, 0);
            Vector    textdir = Vector.V(1, 0);
            Vector    textpos = Vector.V(1, 0);
            Vector    dos = Vector.V(1, 0);
            int       alx = 0; int aly = 0;
            int       cwidth = 1;
            Rectangle r      = getRectangle();

            center = Vector.V(r);
            switch (_orientation)
            {
            case RTOrientation.East:
                cwidth  = Height;
                dos     = Vector.V(1, 0);
                textdir = Vector.V(1, 0);
                textpos = Vector.V(Width - cwidth, Height / 2);
                alx     = 1;
                aly     = 0;
                break;

            case RTOrientation.North:
                cwidth  = Width;
                dos     = Vector.V(0, -1);
                textdir = Vector.V(0, -1);
                textpos = Vector.V(Width / 2, cwidth);
                alx     = 1;
                aly     = 0;
                break;

            case RTOrientation.West:
                cwidth  = Height;
                dos     = Vector.V(-1, 0);
                textdir = Vector.V(1, 0);
                textpos = Vector.V(cwidth, Height / 2);
                alx     = -1;
                aly     = 0;
                break;

            case RTOrientation.South:
                cwidth  = Width;
                dos     = Vector.V(0, 1);
                textdir = Vector.V(0, -1);
                textpos = Vector.V(Width / 2, Height - 1 - cwidth);
                alx     = -1;
                aly     = 0;
                break;
            }
            g.DrawRectangle(contactPen, r);
            switch (_IOtype)
            {
            case ProcessingIOType.SignalInput:
                GraphicsUtil.drawArrow(g, center + dos * cwidth / 2 * 0.8, center - dos * cwidth / 2 * 0.8,
                                       (_highlighted) ? contactHighlightPen : contactPen);
                break;

            case ProcessingIOType.SignalOutput:
                GraphicsUtil.drawArrow(g, center - dos * cwidth / 2 * 0.8, center + dos * cwidth / 2 * 0.8,
                                       (_highlighted) ? contactHighlightPen : contactPen);
                break;

            case ProcessingIOType.DataInput:
                GraphicsUtil.drawDoubleArrow(g, center + dos * cwidth / 2 * 0.8, center - dos * cwidth / 2 * 0.8,
                                             (_highlighted) ? contactHighlightPen : contactPen);
                break;

            case ProcessingIOType.DataOutput:
                GraphicsUtil.drawDoubleArrow(g, center - dos * cwidth / 2 * 0.8, center + dos * cwidth / 2 * 0.8,
                                             (_highlighted) ? contactHighlightPen : contactPen);
                break;
            }

            // Title
            if (_showTitle && (_title != null) && (_title.Length > 0))
            {
                GraphicsUtil.drawText(g, textpos, _titleFont, scale,
                                      _title, 0, 2, alx, aly, textdir, titleBrush);
            }
        }
Пример #2
0
        public void draw(Graphics g)
        {
            if (_isNamed)
            {
                bool selected = false;
                foreach (ProcessingConnection pc in connections)
                {
                    if (pc.selected)
                    {
                        selected = true;
                    }
                }

                Pen drawPen = null;
                if (selected)
                {
                    drawPen = penLineSelected;
                }
                else
                {
                    if (valid)
                    {
                        drawPen = penLineOk;
                    }
                    else
                    {
                        drawPen = penLineBad;
                    }
                }
                if (netType == ProcessingNetType.Data)
                {
                    drawPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                }
                else
                {
                    drawPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                }
                foreach (RTIO io in connectedIOs)
                {
                    Vector pstart, pstop, textpos, textdir;
                    getNamedPoints(io, out pstart, out pstop, out textpos, out textdir);
                    Point p1 = pstart.Point;
                    Point p2 = pstop.Point;
                    g.DrawLine(penBack, p1, p2);
                    g.DrawLine(drawPen, p1, p2);
                    GraphicsUtil.drawText(g, textpos,
                                          owner.netNameFont, owner.scale,
                                          _name, 0, 2, -1, -1, textdir, owner.netNameBrush);
                }
            }
            else
            {
                updateConnections();
                foreach (ProcessingConnection pc in connections)
                {
                    Pen drawpen = null;
                    if (pc.selected)
                    {
                        drawpen = penLineSelected;
                    }
                    else
                    {
                        if (valid)
                        {
                            drawpen = penLineOk;
                        }
                        else
                        {
                            drawpen = penLineBad;
                        }
                    }
                    if (netType == ProcessingNetType.Data)
                    {
                        drawpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                    }
                    else
                    {
                        drawpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                    }
                    pc.bc.draw(g, penBack, drawpen);
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
        void drawTo(Graphics g)
        {
            // Background
            // Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);
            Rectangle seq      = this.ClientRectangle;
            Pen       framePen = new Pen(frameColor);

            getSequencerGeometry(ref seq);
            g.DrawRectangle(framePen, seq);
            if (_hlCol >= 0)
            {
                int       x1 = seq.X + _hlCol * seq.Width / _columns;
                int       x2 = seq.X + (_hlCol + 1) * seq.Width / _columns;
                Rectangle hl = new Rectangle(x1, seq.Y, x2 - x1 - 1, seq.Height);
                Brush     hb = new SolidBrush(_highLightColor);
                g.FillRectangle(hb, hl);
            }
            if ((dragMode == DragMode.Holding) && (dragcol >= 0) && (dragcol >= 0))
            {
                int   x1 = seq.X + dragcol * seq.Width / _columns;
                int   x2 = seq.X + (dragcol + 1) * seq.Width / _columns;
                int   y1 = seq.Y + (_rows - 1 - (dragrow + 1)) * seq.Height / _rows;
                int   y2 = seq.Y + (_rows - 1 - dragrow) * seq.Height / _rows;
                Brush hs = new SolidBrush(_selectColor);
                g.FillRectangle(hs, new Rectangle(x1, 0, x2 - x1 + 1, seq.Y - 1));
                g.FillRectangle(hs, new Rectangle(0, y2, seq.X - 1, y2 - y1 + 1));
            }

            if (_showColHeads)
            {
                Brush colheadbrush = new SolidBrush(_colHeadColor);
                for (int c = 0; c < _columns; c++)
                {
                    Vector tp = new Vector(seq.X + (double)seq.Width / _columns * (c + 0.5), seq.Y);
                    GraphicsUtil.drawText(g, tp, _colHeadFont, scale, string.Format("{0}", (c % _takt) + 1), 0, 2, 0, -1, Vector.X, colheadbrush);
                }
            }
            if (_showRowHeads)
            {
                Brush rowheadbrush = new SolidBrush(_rowHeadColor);
                for (int r = 0; r < _rows; r++)
                {
                    Vector tp = new Vector(seq.X, seq.Y + (double)seq.Height / _rows * (r + 0.5));
                    GraphicsUtil.drawText(g, tp, _rowHeadFont, scale, notename(_rows - r), 0, 2, 1, 0, Vector.X, rowheadbrush);
                }
            }
            for (int c = 1; c < _columns; c++)
            {
                int cx = seq.X + seq.Width * c / _columns;
                g.DrawLine(framePen, cx, seq.Y, cx, seq.Y + seq.Height - 1);
            }
            for (int r = 1; r < _rows; r++)
            {
                int cy = seq.Y + seq.Height * r / _rows;
                g.DrawLine(framePen, seq.X, cy, seq.X + seq.Width - 1, cy);
            }
            Brush fb = new SolidBrush(fillOnColor);

            for (int r = 0; r < _rows; r++)
            {
                for (int c = 0; c < _columns; c++)
                {
                    if (_data[r, c] > 0)
                    {
                        Vector ctr = Vector.V(seq.X + (c + 0.5) * seq.Width / _columns, seq.Y + (_rows - 1 - r + 0.5) * seq.Height / _rows);
                        // ((SolidBrush)fb).Color = fillOnColor;
                        GraphicsUtil.fillCircle(g, ctr, (double)seq.Width / _columns / 3, fb);
                    }
                }
            }
        }
Пример #5
0
        void drawTo(Graphics g)
        {
            double scl = scale;

            // Background
            //Brush brushBackground = new SolidBrush(BackColor);
            //g.FillRectangle(brushBackground, this.ClientRectangle);

            Vector center = Vector.V(Width / 2, Height / 2);

            // Title
            if (_showTitle && (_title != null) && (_title.Length > 0))
            {
                Brush textBrush = new SolidBrush(_titleColor);
                // g.DrawString(_title, _titleFont, textBrush, Width / 2, Height / 2);
                GraphicsUtil.drawText(g, center - Vector.V(0, _dialDiameter / 2 * scl), _titleFont, scl,
                                      _title, 0, 2, 0, -1, Vector.X, textBrush);
            }


            // Dial
            double     rad     = _dialDiameter * scl / 2;
            RectangleF rf      = Vector.RFC(center, Vector.diag(rad * 2 * 0.8));
            Pen        knobPen = new Pen(_dialColor);

            g.DrawEllipse(knobPen, rf);

            /*Brush brushRotKnob = new SolidBrush(_dialColor);
             * g.FillEllipse(brushRotKnob, rf);
             * Pen penRotKnob = new Pen(Color.AliceBlue);
             * rf = Vector.RFC(center, Vector.diag(rad * 2 * 0.8 * 0.9));
             * g.DrawEllipse(penRotKnob, rf);*/


            double slp        = dialPos();
            double phi        = Math.PI * 1 / 4 - (1 - slp) * Math.PI * 3 / 2;
            Pen    penRotMark = new Pen(_dialMarkColor);
            Vector pointpos   = center + Vector.V(rad * 0.6, 0).rot(phi);

            g.DrawEllipse(penRotMark, VectorRect.FromCenterSize(pointpos, Vector.V(rad / 5, rad / 5)).rectangleF);
            // g.DrawLine(penRotMark, (center + Vector.V(rad * 0.7, 0).rot(phi)).PointF, (center + Vector.V(rad * 0.3, 0).rot(phi)).PointF);


            if (_showScale)
            {
                // Grid
                grid.logScale = _logScale;
                grid.newRange(_minVal, _maxVal);
                Pen penRotScale = new Pen(_scaleColor);
                for (int i = 0; i < grid.gridLength; i++)
                {
                    double alpha = Math.PI / 4 - (1 - grid.grid[i].screen / grid.high) * 1.5 * Math.PI;
                    Vector vin   = Vector.V(rad * 0.85, 0).rot(alpha);
                    Vector vout  = Vector.V(rad * ((grid.grid[i].isMajor) ? (0.98) : (0.9)), 0).rot(alpha);
                    g.DrawLine(penRotScale, (center + vin).PointF, (center + vout).PointF);
                }
            }

            // Value
            if (_showValue)
            {
                String s         = String.Format(getFormat(), _val);
                Brush  textBrush = new SolidBrush(_valueColor);
                if ((unit != null) && (unit.Length > 0))
                {
                    s = s + " " + unit;
                }
                GraphicsUtil.drawText(g, center + Vector.V(0, _dialDiameter / 2 * scl), _valueFont, scl,
                                      s, 0, 2, 0, 1, Vector.X, textBrush);
            }
        }
Пример #6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            Vector valueCenter = Vector.V(0, 0);

            GraphicsUtil.TextPosition tpos = new GraphicsUtil.TextPosition();
            GraphicsUtil.dualSplit(ClientSize, _valueSize, scale, ref valueCenter, ref tpos, _titlePos);
            Rectangle valueR = VectorRect.FromCenterSize(valueCenter, Vector.V(_valueSize)).rectangle;

            if (valueR.Contains(e.Location))
            {
                // Hit in Value
                // Show Value Selector Window
                FlexibleInputWin dw;
                switch (_inputType)
                {
                case RTFlexInputType.String:
                    dw = new FlexibleInputWin(_title, _stringVal);
                    dw.StartPosition = FormStartPosition.Manual;
                    dw.Location      = PointToScreen(new Point(0, 0));
                    dw.ShowDialog();
                    _stringVal = dw.stringValue;
                    break;

                case RTFlexInputType.Integer:
                    if (_minVal < _maxVal)
                    {
                        dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0))?_unit:null, (int)_minVal, (int)_maxVal, _intVal);
                    }
                    else
                    {
                        dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _intVal);
                    }
                    dw.StartPosition = FormStartPosition.Manual;
                    dw.Location      = PointToScreen(new Point(0, 0));
                    dw.ShowDialog();
                    _intVal = dw.intValue;
                    break;

                case RTFlexInputType.Float:
                    if (_minVal < _maxVal)
                    {
                        dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _minVal, _maxVal, _floatVal, _format);
                    }
                    else
                    {
                        dw = new FlexibleInputWin(_title, ((_unit != null) && (_unit.Length > 0)) ? _unit : null, _floatVal, _format);
                    }
                    dw.StartPosition = FormStartPosition.Manual;
                    dw.Location      = PointToScreen(new Point(0, 0));
                    dw.ShowDialog();
                    _floatVal = dw.floatValue;
                    break;
                }
                newValue();
                Invalidate();
            }
        }
Пример #7
0
        void drawTo(Graphics g)
        {
            // Background
            // Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);

            Rectangle sel, up, down;

            sel  = new Rectangle();
            up   = new Rectangle();
            down = new Rectangle();
            getFrames(ref sel, ref up, ref down);

            if ((_title != null) && (_title.Length > 0))
            {
                Brush tBrush = new SolidBrush(_titleColor);
                GraphicsUtil.drawText(g, Vector.V(sel.Left, Height / 2), _titleFont, scale, _title, 0, 2, 1, 0, Vector.V(1, 0), tBrush);
            }
            Pen framePen = new Pen(frontColor);

            g.DrawRectangle(framePen, sel);
            sel.Inflate(-1, -1);
            switch (_choiceType)
            {
            case ChoiceType.ListDefined:
                if ((_entries != null) && (_entries.Count > 0) && (selectedItem >= 0) && (selectedItem < _entries.Count))
                {
                    _entries[_selectedItem].draw(g, backColor, frontColor, sel);
                }
                if ((_entries != null) && (_entries.Count > 0))
                {
                    if (_selectedItem < _entries.Count - 1)
                    {
                        GraphicsUtil.drawTriangle(g, Vector.V(up), (double)up.Height, Vector.V(0, -1), framePen);
                    }
                    if (_selectedItem > 0)
                    {
                        GraphicsUtil.drawTriangle(g, Vector.V(down), (double)up.Height, Vector.V(0, 1), framePen);
                    }
                }
                break;

            case ChoiceType.Numeric:
                g.FillRectangle(backBrush, sel);
                g.DrawRectangle(framePen, sel);
                GraphicsUtil.drawText(g, Vector.V(sel), _valueFont, scale,
                                      String.Format("{0}", _numericMin + _selectedItem), 0, 2, 0, 0, Vector.X, frontBrush);
                if (_selectedItem < (_numericMax - _numericMin))
                {
                    GraphicsUtil.drawTriangle(g, Vector.V(up), (double)up.Height, Vector.V(0, -1), framePen);
                }
                if (_selectedItem > 0)
                {
                    GraphicsUtil.drawTriangle(g, Vector.V(down), (double)up.Height, Vector.V(0, 1), framePen);
                }
                break;

            case ChoiceType.NumericOff:
                g.FillRectangle(backBrush, sel);
                g.DrawRectangle(framePen, sel);
                if (_selectedItem == -1)
                {
                    GraphicsUtil.drawText(g, Vector.V(sel), _valueFont, scale,
                                          _offString, 0, 2, 0, 0, Vector.X, frontBrush);
                }
                else
                {
                    GraphicsUtil.drawText(g, Vector.V(sel), _valueFont, scale,
                                          String.Format("{0}", _numericMin + _selectedItem), 0, 2, 0, 0, Vector.X, frontBrush);
                }
                if (_selectedItem < (_numericMax - _numericMin))
                {
                    GraphicsUtil.drawTriangle(g, Vector.V(up), (double)up.Height, Vector.V(0, -1), framePen);
                }
                if (_selectedItem >= 0)
                {
                    GraphicsUtil.drawTriangle(g, Vector.V(down), (double)up.Height, Vector.V(0, 1), framePen);
                }
                break;
            }
        }
Пример #8
0
        private void doPaint(Graphics g)
        {
            // Brush backBrush = new SolidBrush(Color.DarkMagenta);
            Rectangle cr           = ClientRectangle;
            Rectangle deleteButton = getDeleteButton();
            Rectangle shrinkButton = getShrinkButton();
            Rectangle activeButton = getActiveButton();

            int x1 = 0;
            int x2 = Width - 1;

            x2 -= deleteButton.Width;
            if (_hasActiveSwitch)
            {
                x1 += activeButton.Width;
            }
            if (_canShrink)
            {
                x2 -= shrinkButton.Width;
            }
            int centerpos = (x1 + x2) / 2;

            cr.Width  -= 1;
            cr.Height -= 1;
            if (_selected)
            {
                g.DrawRectangle(selectPen, cr);
            }
            else
            {
                g.DrawRectangle(framePen, cr);
            }

            if (_shrinked)
            {
                if ((_shrinkTitle != null) && (_shrinkTitle.Length > 0))
                {
                    GraphicsUtil.drawText(g, Vector.V(centerpos, 0), _titleFont, scale,
                                          _shrinkTitle, 0, 2, 0, 1, Vector.X, titleBrush);
                }
            }
            else
            {
                if ((_title != null) && (_title.Length > 0))
                {
                    GraphicsUtil.drawText(g, Vector.V(centerpos, 0), _titleFont, scale,
                                          _title, 0, 2, 0, 1, Vector.X, titleBrush);
                }
            }

            //if (_selected)
            //    framePen = new Pen(Color.Red);
            // g.DrawLine(framePen, new PointF((float)scale * 5, (float)scale * 15), new PointF((float) (Width - scale*5), (float)scale * 15));

            if ((dragMode == DragMode.DeleteBtn) && onDeleteButton)
            {
                GraphicsUtil.drawButton(g, deleteButton, GraphicsUtil.ButtonType.Delete, framePen, symbolOnPen);
            }
            else
            {
                GraphicsUtil.drawButton(g, deleteButton, GraphicsUtil.ButtonType.Delete, framePen, symbolPen);
            }
            if (_canShrink)
            {
                if ((dragMode == DragMode.ShrinkBtn) && onShrinkButton)
                {
                    GraphicsUtil.drawButton(g, shrinkButton, (_shrinked) ? GraphicsUtil.ButtonType.Expand : GraphicsUtil.ButtonType.Shrink, framePen, symbolOnPen);
                }
                else
                {
                    GraphicsUtil.drawButton(g, shrinkButton, (_shrinked) ? GraphicsUtil.ButtonType.Expand : GraphicsUtil.ButtonType.Shrink, framePen, symbolPen);
                }
            }
            if (_hasActiveSwitch)
            {
                bool showActive = _active;
                if ((dragMode == DragMode.ActiveBtn) && onActiveButton)
                {
                    showActive = !_active;
                }
                if (showActive)
                {
                    g.FillRectangle(activeBrush, activeButton);
                    GraphicsUtil.drawButton(g, activeButton, GraphicsUtil.ButtonType.Active, framePen, activePen);
                }
                else
                {
                    GraphicsUtil.drawButton(g, activeButton, GraphicsUtil.ButtonType.InActive, framePen, passivePen);
                }
            }
        }
Пример #9
0
 public void drawText(Graphics g, Font f, Brush b, string s)
 {
     GraphicsUtil.drawText(g, anchor, f, scale, s, bx, spacing, ax, ay, dir, b);
 }