Example #1
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;
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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));
        }
Example #5
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;
        }
Example #6
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();
        }
Example #7
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);
            }
        }
Example #8
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;
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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();
            }
        }