Ejemplo n.º 1
0
        public void getPosAndDir(ref Vector pos, ref Vector dir, ref VectorRect r, ref int _rank)
        {
            RTForm owr = element;

            if (owr == null)
            {
                pos  = Vector.Zero;
                dir  = Vector.Zero;
                r    = VectorRect.Empty;
                rank = 0;
                return;
            }
            pos = owr.owner.fromScreen(Vector.V(owr.Location) + Vector.V(Location) + getAnchor());
            switch (_orientation)
            {
            case RTOrientation.East: dir = Vector.V(1, 0); break;

            case RTOrientation.North: dir = Vector.V(0, -1); break;

            case RTOrientation.West: dir = Vector.V(-1, 0); break;

            case RTOrientation.South: dir = Vector.V(0, 1); break;
            }
            if (rank < 0)
            {
                calcRank();
            }
            _rank = rank; //  owr.GetIOs().IndexOf(this);
            r     = new VectorRect(owr.owner.fromScreen(Vector.V(owr.Location)), owr.owner.fromScreen(Vector.V(owr.Location) + Vector.V(owr.Size)));
        }
Ejemplo n.º 2
0
        void drawTo(Graphics g)
        {
            // Background
            // Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);

            Vector center = Vector.Zero;
            Vector size   = Vector.Zero;

            GraphicsUtil.TextPosition titlePosition = null;

            getWfCoords(ref center, ref size, ref titlePosition);
            if (titlePosition != null)
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                titlePosition.drawText(g, _titleFont, titleBrush, _title);
            }

            Rectangle fr = VectorRect.FromCenterSize(center, size).rectangle;

            g.DrawRectangle(framePen, fr.Left - 1, fr.Top - 1, fr.Width + 2, fr.Height + 2);
            buildMap();
            updateBitmap();
            InterpolationMode imode = g.InterpolationMode;
            PixelOffsetMode   pmode = g.PixelOffsetMode;

            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode   = PixelOffsetMode.Half;
            g.DrawImage(bmap, fr, 0, 0, bmap.Width, bmap.Height, GraphicsUnit.Pixel);
            g.InterpolationMode = imode;
            g.PixelOffsetMode   = pmode;
            // needsRedraw = false;
        }
Ejemplo n.º 3
0
 public void updateConnections()
 {
     for (int i = 0; i < connections.Count; i++)
     {
         Vector     p1 = Vector.V();
         Vector     p2 = Vector.V();
         Vector     dir1 = Vector.V();
         Vector     dir2 = Vector.V();
         VectorRect R1 = new VectorRect();
         VectorRect R2 = new VectorRect();
         int        rank1 = 0, rank2 = 0;
         connectedIOs[connections[i].i1].getPosAndDir(ref p1, ref dir1, ref R1, ref rank1);
         connectedIOs[connections[i].i2].getPosAndDir(ref p2, ref dir2, ref R2, ref rank2);
         if (connections[i].bc == null)
         {
             connections[i].bc = new GraphicsUtil.BlockConnection(
                 owner.toScreen(p1), dir1, owner.toScreen(R1), (10 + 5 * rank1) * owner.scale,
                 owner.toScreen(p2), dir2, owner.toScreen(R2), (10 + 5 * rank2) * owner.scale);
         }
         else
         {
             connections[i].bc.A  = owner.toScreen(p1);
             connections[i].bc.B  = owner.toScreen(p2);
             connections[i].bc.VA = owner.toScreen(R1);
             connections[i].bc.VB = owner.toScreen(R2);
         }
     }
 }
Ejemplo n.º 4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (dragMode == DragMode.Dial)
            {
                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);


                // Hit in Dial Region
                double n = 0;
                if (_slideDirection == SlideDirection.Horizontal)
                {
                    n = (e.X - vlow.x) / (vhigh.x - vlow.x);
                }
                else
                {
                    n = (e.Y - vlow.y) / (vhigh.y - vlow.y);
                }
                if (n < 0)
                {
                    n = 0;
                }
                if (n > 1.0)
                {
                    n = 1;
                }

                if (logScale)
                {
                    if ((_minVal <= 0) || (_maxVal <= 0) || (_minVal == _maxVal))
                    {
                        _val = _minVal;
                    }
                    else
                    {
                        _val = Math.Exp(n * (Math.Log(_maxVal) - Math.Log(_minVal)) + Math.Log(_minVal));
                    }
                }
                else
                {
                    _val = n * (_maxVal - _minVal) + _minVal;
                }
                newValue();
                Invalidate();
                dragMode = DragMode.Idle;
            }
            else
            {
                forwardOnMouseUp(e);
            }
        }
Ejemplo n.º 5
0
        public static VectorRect containingRects(VectorRect a, VectorRect b)
        {
            double mx = min(a.LL.x, a.UR.x, b.LL.x, b.UR.x);
            double my = min(a.LL.y, a.UR.y, b.LL.y, b.UR.y);
            double nx = max(a.LL.x, a.UR.x, b.LL.x, b.UR.x);
            double ny = max(a.LL.y, a.UR.y, b.LL.y, b.UR.y);

            return(new VectorRect(mx, my, nx, ny));
        }
Ejemplo n.º 6
0
        public static VectorRect containingThreePoints(Vector A, Vector B, Vector C)
        {
            double minx = min(A.x, B.x, C.x);
            double miny = min(A.y, B.y, C.y);
            double maxx = max(A.x, B.x, C.x);
            double maxy = max(A.y, B.y, C.y);

            return(VectorRect.FromTwoPoints(minx, miny, maxx, maxy));
        }
Ejemplo n.º 7
0
        void drawTo(Graphics g)
        {
            // Background
            //Brush brushBackground = new SolidBrush(BackColor);
            //g.FillRectangle(brushBackground, this.ClientRectangle);

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

            GraphicsUtil.TextPosition tpos = new GraphicsUtil.TextPosition();
            GraphicsUtil.dualSplit(ClientSize, _valueSize, scale, ref valueCenter, ref tpos, _titlePos);

            if (_titlePos != GraphicsUtil.TextAlignment.off)
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                tpos.drawText(g, _titleFont, titleBrush, _title);
            }

            Rectangle valueR = VectorRect.FromCenterSize(valueCenter, Vector.V(_valueSize) * scale).rectangle;

            // Frame
            if (_drawFrame)
            {
                Pen framePen = new Pen(_frameColor);
                g.DrawRectangle(framePen, valueR);
                valueR.Inflate(-1, -1);
                g.SetClip(valueR);
            }


            // Value
            Brush  textBrush = new SolidBrush(_valueColor);
            String s         = "";

            switch (_inputType)
            {
            case RTFlexInputType.String:
                s = _stringVal;
                break;

            case RTFlexInputType.Float:
                s = String.Format(getFormat(), _floatVal);
                if ((unit != null) && (unit.Length > 0))
                {
                    s = s + " " + unit;
                }
                break;

            case RTFlexInputType.Integer:
                s = String.Format("{0}", _intVal);
                if ((unit != null) && (unit.Length > 0))
                {
                    s = s + " " + unit;
                }
                break;
            }
            GraphicsUtil.drawText(g, valueCenter, _valueFont, scale, s, 0, 2, 0, 0, Vector.X, textBrush);
        }
Ejemplo n.º 8
0
        Rectangle getButton()
        {
            Vector center, textpos;
            int    ax, ay;

            center  = Vector.V();
            textpos = Vector.V();
            ax      = ay = 0;
            getButtonCoords(ref center, ref textpos, ref ax, ref ay);
            return(VectorRect.FromCenterSize(center, Vector.V(_buttonDim) * scale).rectangle);
        }
Ejemplo n.º 9
0
 public BlockConnection()
 {
     _A       = Vector.V(1, 0);
     _B       = Vector.V(-1, 0);
     _Adir    = Vector.V(1, 0);
     _Bdir    = Vector.V(-1, 0);
     _VA      = VectorRect.Empty;
     _VB      = VectorRect.Empty;
     _stdgapA = 20;
     _stdgapB = 20;
     valid    = false;
 }
Ejemplo n.º 10
0
 public BlockConnection(
     Vector __A, Vector __Adir, VectorRect __VA, double __stdgapA,
     Vector __B, Vector __Bdir, VectorRect __VB, double __stdgapB)
 {
     _A       = __A;
     _B       = __B;
     _Adir    = __Adir;
     _Bdir    = __Bdir;
     _VA      = __VA;
     _VB      = __VB;
     _stdgapA = __stdgapA;
     _stdgapB = __stdgapB;
     valid    = false;
 }
Ejemplo n.º 11
0
        public static void drawArc(Graphics g, Vector center, double phi1, double phi2, double r, Pen p)
        {
            RectangleF rf = VectorRect.FromCenterSize(center, Vector.V(2 * r, 2 * r)).rectangleF;

            phi1 = -phi1;
            phi2 = -phi2;
            if (phi1 > phi2)
            {
                double temp = phi1;
                phi1 = phi2;
                phi2 = temp;
            }
            g.DrawArc(p, rf, (float)(phi1 * 180 / Math.PI), (float)((phi2 - phi1) * 180 / Math.PI));
        }
Ejemplo n.º 12
0
 public bool inside(VectorRect vr)
 {
     if ((list == null) || (list.Count < 1))
     {
         return(false);
     }
     foreach (Vector v in list)
     {
         if (!vr.inside(v))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 13
0
 public void selectOnContained(VectorRect vr, APSelection sel)
 {
     if (_isNamed)
     {
         bool selected = false;
         foreach (RTIO io in connectedIOs)
         {
             if (!selected)
             {
                 Vector pstart, pstop, textpos, textdir;
                 getNamedPoints(io, out pstart, out pstop, out textpos, out textdir);
                 Vector vv = textpos +
                             Vector.V(textdir.y, -textdir.x) * owner.Font.Height * owner.scale;
                 VectorRect vx = VectorRect.containingThreePoints(pstart, pstop, vv);
                 if (owner.toScreen(vr).inside(vx))
                 {
                     selected = true;
                 }
             }
         }
         if (selected)
         {
             foreach (ProcessingConnection pc in connections)
             {
                 pc.selected = true;
             }
             sel.select(this);
         }
     }
     else
     {
         updateConnections();
         VectorRect v = owner.toScreen(vr);
         for (int i = 0; i < connections.Count; i++)
         {
             if (connections[i].bc.inside(v))
             {
                 sel.select(this, i);
             }
         }
     }
 }
Ejemplo n.º 14
0
        public static void drawVBar(Graphics g, Vector center, Vector dim, double grade, Pen framePen, Brush fillBrush)
        {
            if (double.IsNaN(grade) || double.IsInfinity(grade))
            {
                grade = 0;
            }
            if (grade < 0)
            {
                grade = 0;
            }
            if (grade > 1.0)
            {
                grade = 1.0;
            }
            Rectangle r  = VectorRect.FromPointSize(center - dim / 2, dim).rectangle;
            Rectangle rf = VectorRect.FromPointSize(center + Vector.V(-dim.x / 2, -dim.y / 2 + (1 - grade) * dim.y), Vector.V(dim.x, grade * dim.y)).rectangle;

            g.FillRectangle(fillBrush, rf);
            g.DrawRectangle(framePen, r);
        }
Ejemplo n.º 15
0
        void drawTo(Graphics g)
        {
            // Background
            // Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);

            Vector center = Vector.Zero;
            Vector size   = Vector.Zero;

            GraphicsUtil.TextPosition titlePosition = null;


            getWfCoords(ref center, ref size, ref titlePosition);
            if (titlePosition != null)
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                titlePosition.drawText(g, _titleFont, titleBrush, _title);
            }

            Rectangle fr = VectorRect.FromCenterSize(center, size).rectangle;

            g.DrawRectangle(framePen, fr.Left - 1, fr.Top - 1, fr.Width + 2, fr.Height + 2);
            if ((bmap == null) || (data.Length != bmap.Height * bmap.Width * 4))
            {
                bmap = new Bitmap(_timeSteps, _ySteps, PixelFormat.Format32bppRgb);
            }
            BitmapData bmd = bmap.LockBits(new Rectangle(0, 0, bmap.Width, bmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);

            Marshal.Copy(data, 0, bmd.Scan0, bmap.Width * bmap.Height * 4);
            bmap.UnlockBits(bmd);
            InterpolationMode imode = g.InterpolationMode;
            PixelOffsetMode   pmode = g.PixelOffsetMode;

            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode   = PixelOffsetMode.Half;
            g.DrawImage(bmap, fr, 0, 0, bmap.Width, bmap.Height, GraphicsUnit.Pixel);
            g.InterpolationMode = imode;
            g.PixelOffsetMode   = pmode;

            // needsRedraw = false;
        }
Ejemplo n.º 16
0
        public static void drawRotor(Graphics g, double openAngle,
                                     Vector center, Vector dim, double grade, GridCalculator grid, Pen framePen, Pen linePen)
        {
            g.SetClip(VectorRect.FromCenterSize(center, dim).rectangle);
            if (double.IsNaN(grade) || double.IsInfinity(grade))
            {
                grade = 0;
            }
            if (grade < 0)
            {
                grade = 0;
            }
            if (grade > 1.0)
            {
                grade = 1.0;
            }
            double phi0 = (90 + openAngle / 2) * Math.PI / 180;
            double phi1 = (90 - openAngle / 2) * Math.PI / 180;
            double a    = 0.3;
            double rad  = (dim.y - 1) / (1.0 - a * Math.Sin(phi1));
            Vector rotc = center + Vector.V(0, rad - (dim.y - 1) / 2);

            drawArc(g, rotc, phi0, phi1, rad, framePen);
            drawArc(g, rotc, phi0, phi1, rad * a, framePen);
            double phid = phi1 + grade * (phi0 - phi1);

            if (grid != null)
            {
                for (int i = 0; i < grid.gridLength; i++)
                {
                    double alpha = -Math.PI / 2 + grid.grid[i].screen * Math.PI / 180;
                    Vector vout  = Vector.V(rad, 0).rot(alpha);
                    Vector vin   = Vector.V(rad * ((grid.grid[i].isMajor) ? (0.8) : (0.9)), 0).rot(alpha);
                    drawLine(g, rotc + vin, rotc + vout, framePen);
                }
            }
            drawLine(g, rotc - Vector.V(rad * a, 0).rot(phid), rotc - Vector.V(rad * 0.95, 0).rot(phid), linePen);
            drawLine(g, rotc - Vector.V(rad * a, 0).rot(phi0), rotc - Vector.V(rad, 0).rot(phi0), framePen);
            drawLine(g, rotc - Vector.V(rad * a, 0).rot(phi1), rotc - Vector.V(rad, 0).rot(phi1), framePen);
            g.ResetClip();
        }
Ejemplo n.º 17
0
        public void selectOnContained(VectorRect vr, APSelection sel)
        {
            VectorRect  rf;
            SystemPanel p = owner;

            if (p == null)
            {
                return;
            }
            if (_shrinked)
            {
                Vector dimS = Vector.V(_shrinkSize.Width, _shrinkSize.Height);
                rf = VectorRect.FromCenterSize(center, dimS);
            }
            else
            {
                rf = VectorRect.FromCenterSize(center, dim);
            }
            if (vr.inside(rf))
            {
                sel.select(this);
            }
        }
Ejemplo n.º 18
0
        void drawTo(Graphics g)
        {
            // Background
            //Brush brushBackground = new SolidBrush(BackColor);
            // g.FillRectangle(brushBackground, this.ClientRectangle);

            Vector center = Vector.V();
            Vector textpos = Vector.V();
            int    ax = 0, ay = 0;

            getLEDCoords(ref center, ref textpos, ref ax, ref ay);
            if ((_titlePos != RTTitlePos.Off) && (_title != null) && (_title.Length > 0))
            {
                Brush titleBrush = new SolidBrush(_titleColor);
                GraphicsUtil.drawText(g, textpos, _titleFont, scale, _title, 0, 2, ax, ay, Vector.V(1, 0), titleBrush);
            }

            Rectangle btnr      = VectorRect.FromCenterSize(center, Vector.V(_LEDDim) * scale).rectangle;
            Brush     fillBrush = new SolidBrush((_LEDState) ? _fillOnColor : _fillOffColor);
            Pen       framePen  = new Pen((_LEDState) ? _frameOnColor : _frameOffColor);

            g.FillRectangle(fillBrush, btnr);
            g.DrawRectangle(framePen, btnr);

            if (_LEDState && (_onText != null) && (_onText.Length > 0))
            {
                Brush textBrush = new SolidBrush(_textOnColor);
                GraphicsUtil.drawText(g, center, _textFont, scale, _onText, 0, 2, 0, 0, Vector.V(1, 0), textBrush);
            }
            else if (!_LEDState && (_offText != null) && (_offText.Length > 0))
            {
                Brush textBrush = new SolidBrush(_textOffColor);
                GraphicsUtil.drawText(g, center, _textFont, scale, _offText, 0, 2, 0, 0, Vector.V(1, 0), textBrush);
            }

            // needsRedraw = false;
        }
Ejemplo n.º 19
0
        private void getNamedPoints(RTIO io, out Vector pstart, out Vector pstop,
                                    out Vector textpos, out Vector textdir)
        {
            Vector     pos  = Vector.Zero;
            Vector     dir  = Vector.Zero;
            VectorRect vr   = VectorRect.Empty;
            int        rank = 0;

            io.getPosAndDir(ref pos, ref dir, ref vr, ref rank);
            pstart = owner.toScreen(pos);
            VectorBox vx = GraphicsUtil.sizeText(owner.netNameFont, _name, 2, -1, -1);

            pstop = pstart + dir * owner.scale * (vx.boundingDim().x + 20);
            if (dir.x < 0)
            {
                textpos = pstop - dir * owner.scale * 10;
                textdir = -dir;
            }
            else
            {
                textpos = pstart + dir * owner.scale * 10;
                textdir = dir;
            }
        }
Ejemplo n.º 20
0
 public VectorRect(VectorRect a)
 {
     LL = a.LL;
     UR = a.UR;
 }
Ejemplo n.º 21
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        void getPositions(ref GraphicsUtil.TextPosition titlePos,
                          ref GraphicsUtil.TextPosition valuePos,
                          ref VectorRect bar, ref VectorRect handle,
                          ref Vector vlow, ref Vector vhigh)
        {
            double y0 = 0;
            double y1 = Height - 1;

            if (_showTitle)
            {
                titlePos       = new GraphicsUtil.TextPosition(Vector.V(Width / 2, 0), 0, 1);
                titlePos.scale = scale;
                y0            += scale * _titleFont.Height * 1.5;
            }
            else
            {
                titlePos = null;
            }

            if (_showValue)
            {
                valuePos       = new GraphicsUtil.TextPosition(Vector.V(Width / 2, Height - 1), 0, -1);
                valuePos.scale = scale;
                y1            -= scale * _valueFont.Height * 1.5;
            }
            else
            {
                valuePos = null;
            }


            // Calculate the required space for the slider, the scale and the scale values
            double w = _slideKnob;

            if (_showScale)
            {
                w += _slideScaleDist;
                w += _slideScaleWidth;
                if (_showScaleValues)
                {
                    if (_slideDirection == SlideDirection.Horizontal)
                    {
                        w += _scaleFont.Height;
                    }
                    else
                    {
                        w += _scaleFont.Height * _lableLength;
                    }
                }
            }
            w *= scale;

            double start = 0;

            if (_slideDirection == SlideDirection.Horizontal)
            {
                start = (y1 + y0) / 2 - w / 2 + _slideKnob / 2 * scale;
                double wbar = Width - 3 * _slideWidth * scale;
                bar = VectorRect.FromCenterSize(Vector.V(Width / 2, start),
                                                Vector.V(Width - 2, _slideWidth * scale));

                double sp = (Width / 2 - wbar / 2) + slidePos() * wbar;
                handle = VectorRect.FromCenterSize(Vector.V(sp, start),
                                                   Vector.V(_slideWidth * scale, _slideKnob * scale));

                if (_showScale)
                {
                    start += _slideKnob / 2 * scale + _slideScaleDist * scale;
                }
                vlow  = Vector.V(Width / 2 - wbar / 2, start);
                vhigh = Vector.V(Width / 2 + wbar / 2, start);
            }
            else
            {
                start = Width / 2 - w / 2 + _slideKnob / 2 * scale;
                double wbar = y1 - y0 - 3 * _slideWidth * scale;
                bar = VectorRect.FromCenterSize(Vector.V(start, (y1 + y0) / 2),
                                                Vector.V(_slideWidth * scale, y0 - y1 - 2));
                double sp = (y1 + y0) / 2 + wbar / 2 - slidePos() * wbar;
                handle = VectorRect.FromCenterSize(Vector.V(start, sp),
                                                   Vector.V(_slideKnob * scale, _slideWidth * scale));
                if (_showScale)
                {
                    start += _slideKnob / 2 * scale + _slideScaleDist * scale;
                }
                vlow  = Vector.V(start, (y1 + y0) / 2 + wbar / 2);
                vhigh = Vector.V(start, (y1 + y0) / 2 - wbar / 2);
            }
        }
Ejemplo n.º 23
0
 public static VectorRect containingRects(VectorRect a)
 {
     return(new VectorRect(a));
 }
Ejemplo n.º 24
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            switch (dragMode)
            {
            case DragMode.None:
                break;

            case DragMode.MouseDown:
                // Just Mouse up again --> a click
                Vector mp = fromScreen(new Vector(e.Location.X, e.Location.Y));
                foreach (ProcessingNet n in nets)
                {
                    n.selectOnHit(mp, selection);
                }
                if (selection.items > 0)
                {
                    Invalidate();
                }
                dragMode = DragMode.None;
                break;

            case DragMode.MouseDownRight:
                // Click
                Vector mpr = fromScreen(new Vector(e.Location.X, e.Location.Y));
                foreach (ProcessingNet n in nets)
                {
                    n.selectOnHit(mpr, selection);
                }
                if (selection.items > 0)
                {
                    Invalidate();
                }
                dragMode = DragMode.None;
                if (selection.items == 1)
                {
                    ProcessingNet n = selection.getNet(0);
                    if (n != null)
                    {
                        showNetContextMenu(e.Location, n);
                    }
                }
                selection.unselect();
                break;

            case DragMode.SelectWin:
                // unSelectAll();
                dragStop = fromScreen(new Vector(e.Location.X, e.Location.Y));
                VectorRect selwin = VectorRect.FromTwoPoints(dragStart, dragStop);
                foreach (RTForm f in elements)
                {
                    f.selectOnContained(selwin, selection);
                }
                foreach (ProcessingNet n in nets)
                {
                    n.selectOnContained(selwin, selection);
                }
                showCaret = false;
                dragMode  = DragMode.None;
                Invalidate();
                break;
            }
        }
Ejemplo n.º 25
0
 public VectorRect toScreenVR(VectorRect v)
 {
     return(new VectorRect(toScreen(v.LL), toScreen(v.UR)));
 }
Ejemplo n.º 26
0
 public VectorRect toScreen(VectorRect r)
 {
     return(new VectorRect(toScreen(r.LL), toScreen(r.UR)));
 }
Ejemplo n.º 27
0
 public bool inside(VectorRect r)
 {
     return(inside(r.LL) && inside(r.UR));
 }
Ejemplo n.º 28
0
        // private static double sqr(double s) { return s * s; }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            double scl = scale;

            if ((e.X < 0) || (e.X >= Width) || (e.Y < 0) || (e.Y >= Height))
            {
                return;
            }

            if (_showValue && e.Y >= Height - 1 - valueFont.Height * scale)
            {
                // Hit in Value
                // Show Value Selector Window
                NumericInputWin dw = new NumericInputWin(this,
                                                         ((_title != null) && (_title.Length > 0)) ? _title : null,
                                                         ((_unit != null) && (_unit.Length > 0)) ? _unit : null,
                                                         getFormat(), true, _minVal, _val, _maxVal, _logScale);
                dw.StartPosition = FormStartPosition.Manual;
                dw.Location      = PointToScreen(e.Location);
                dw.ShowDialog();
                _val = dw.value;
                newValue();
                Invalidate();
                return;
            }

            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);


            VectorRect vr = VectorRect.containingRects(bar, handle);

            if (vr.inside(e.X, e.Y))
            {
                // Hit in Dial Region
                double n = 0;
                if (_slideDirection == SlideDirection.Horizontal)
                {
                    n = (e.X - vlow.x) / (vhigh.x - vlow.x);
                }
                else
                {
                    n = (e.Y - vlow.y) / (vhigh.y - vlow.y);
                }
                if (n < 0)
                {
                    n = 0;
                }
                if (n > 1.0)
                {
                    n = 1;
                }

                if (logScale)
                {
                    if ((_minVal <= 0) || (_maxVal <= 0) || (_minVal == _maxVal))
                    {
                        _val = _minVal;
                    }
                    else
                    {
                        _val = Math.Exp(n * (Math.Log(_maxVal) - Math.Log(_minVal)) + Math.Log(_minVal));
                    }
                }
                else
                {
                    _val = n * (_maxVal - _minVal) + _minVal;
                }
                newValue();
                Invalidate();
                dragMode  = DragMode.Dial;
                dragStart = e.Location;
            }
            else
            {
                forwardOnMouseDown(e);
            }
        }
Ejemplo n.º 29
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            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);

            VectorRect vr = VectorRect.containingRects(bar, handle);

            if (vr.inside(e.X, e.Y))
            {
                ((HandledMouseEventArgs)e).Handled = true;
                if (_logScale)
                {
                    if ((_minVal <= 0) || (_maxVal <= 0) || (_maxVal == _minVal))
                    {
                        return;
                    }
                    if (_val <= 0)
                    {
                        return;
                    }
                    double v = Math.Log(_val) + (double)e.Delta / 2000 * (Math.Log(_maxVal) - Math.Log(_minVal));
                    if (v < Math.Log(_minVal))
                    {
                        v = Math.Log(_minVal);
                    }
                    if (v > Math.Log(_maxVal))
                    {
                        v = Math.Log(_maxVal);
                    }
                    _val = Math.Exp(v);
                    Invalidate();
                    newValue();
                }
                else
                {
                    if (_minVal >= _maxVal)
                    {
                        return;
                    }
                    double v = _val + (double)e.Delta / 2000 * (_maxVal - _minVal);
                    if (v < _minVal)
                    {
                        v = _minVal;
                    }
                    if (v > _maxVal)
                    {
                        v = _maxVal;
                    }
                    _val = v;
                    Invalidate();
                    newValue();
                }
            }
            else
            {
                forwardOnMouseWheel(e);
            }
        }
Ejemplo n.º 30
0
        Rectangle getShapeRect()
        {
            double atop, abottom, aleft, aright;

            atop    = Height / 2 - _shapeDim.Height * scale / 2;
            abottom = atop + _shapeDim.Height * scale - 1;
            double textheight  = _titleFont.GetHeight() * scale * 1.1;
            double scaleHeight = _scaleFont.GetHeight() * scale * 1.1;

            switch (_titlePos)
            {
            case RTTitlePos.Off:
                if (_showXScale)
                {
                    if (_showYScale)
                    {
                        atop = scaleHeight / 2;
                    }
                    else
                    {
                        atop = 0;
                    }
                    abottom = atop + _shapeDim.Height * scale - 1;
                }
                else
                {
                    atop    = Height / 2 - _shapeDim.Height * scale / 2;
                    abottom = atop + _shapeDim.Height * scale - 1;
                }
                break;

            case RTTitlePos.TopLeft:
            case RTTitlePos.TopCenter:
            case RTTitlePos.TopRight:
                atop    = textheight;
                abottom = atop + _shapeDim.Height * scale - 1;
                break;

            case RTTitlePos.BottomLeft:
            case RTTitlePos.BottomCenter:
            case RTTitlePos.BottomRight:
                if (_showYScale)
                {
                    atop = scaleHeight / 2;
                }
                else
                {
                    atop = 0;
                }
                abottom = atop + _shapeDim.Height * scale - 1;
                break;
            }
            if (_showYScale)
            {
                if (_showXScale)
                {
                    aright = Width - 1 - scaleHeight / 2;
                }
                else
                {
                    aright = Width - 1;
                }
                aleft = aright - (_shapeDim.Width * scale + 1);
            }
            else
            {
                aleft  = Width / 2 - _shapeDim.Width * scale / 2;
                aright = aleft + _shapeDim.Width * scale - 1;
            }
            //aleft = Width / 2 - _shapeDim.Width * scale / 2;
            //aright = aleft + _shapeDim.Width * scale - 1;
            return(VectorRect.FromTwoPoints(aleft, atop, aright, abottom).rectangle);
        }