Exemple #1
0
        public void DrawFigure(Graphics g, IDictionary <string, object> props)
        {
            PointF     location  = new PointF((float)props["Left"], (float)props["Top"]);
            SizeF      size      = new SizeF((float)props["Width"], (float)props["Height"]);
            RectangleF rect      = new RectangleF(location, size);
            int        spinvalve = (int)props["SpinValve"];
            int        pv        = (int)props["PV"];
            bool       noparam   = String.IsNullOrWhiteSpace((string)props["PtName"]);
            Color      backcolor;
            Color      forecolor;

            if (noparam || !noparam && !props["Quality"].ToString().Equals("GOOD"))
            {
                backcolor = Color.Blue;
                forecolor = Color.DarkBlue;
            }
            else
            {
                backcolor = (Color)props["BackColor" + pv];
                forecolor = (Color)props["ForeColor" + pv];
            }
            List <PointF> points = new List <PointF>();

            DrawUtils.AddPointsRange(points, new PointF[4]
            {
                new PointF(rect.X, rect.Y),
                new PointF(rect.X + rect.Width, rect.Y + rect.Height),
                new PointF(rect.X + rect.Width, rect.Y),
                new PointF(rect.X, rect.Y + rect.Height)
            });
            float[] angles = new float[4] {
                0, 90, -45, 45
            };
            using (Pen pen = new Pen(forecolor, (pv < 3) ? 1f : 2f))
            {
                using (Brush brush = new SolidBrush(backcolor))
                {
                    #region прорисовка по типу линии
                    DrawUtils.Rotate(points, angles[spinvalve], rect);
                    g.FillPolygon(brush, DrawUtils.GetPoints(points));
                    g.DrawPolygon(pen, DrawUtils.GetPoints(points));
                    #endregion
                }
            }
            bool quit       = (bool)props["QuitAlarms"];
            bool alarms     = (bool)props["HasAlarms"];
            bool lostalarms = (bool)props["HasLostAlarms"];
            bool blink      = (bool)props["Blink"];
            if (!quit && blink && (alarms || lostalarms))
            {
                rect = new RectangleF(location, size);
                using (Pen alarmpen = new Pen(backcolor))
                {
                    alarmpen.Width = 2;
                    g.DrawPolygon(alarmpen, DrawUtils.GetPoints(points));
                }
            }
        }
Exemple #2
0
        public RectangleF SizedBoundsRect(IDictionary <string, object> props)
        {
            PointF        location  = new PointF((float)props["Left"], (float)props["Top"]);
            SizeF         size      = new SizeF((float)props["Width"], (float)props["Height"]);
            RectangleF    rect      = new RectangleF(location, size);
            int           spinvalve = (int)props["SpinValve"];
            List <PointF> points    = new List <PointF>();

            DrawUtils.AddPointsRange(points, new PointF[4]
            {
                new PointF(rect.X, rect.Y),
                new PointF(rect.X + rect.Width, rect.Y + rect.Height),
                new PointF(rect.X + rect.Width, rect.Y),
                new PointF(rect.X, rect.Y + rect.Height)
            });
            float[] angles = new float[4] {
                0, 90, -45, 45
            };
            DrawUtils.Rotate(points, angles[spinvalve], rect);
            float minX, maxX, minY, maxY;

            minX = rect.Right;
            minY = rect.Bottom;
            maxX = rect.Left;
            maxY = rect.Top;
            foreach (PointF pnt in points)
            {
                if (minX > pnt.X)
                {
                    minX = pnt.X;
                }
                if (minY > pnt.Y)
                {
                    minY = pnt.Y;
                }
                if (maxX < pnt.X)
                {
                    maxX = pnt.X;
                }
                if (maxY < pnt.Y)
                {
                    maxY = pnt.Y;
                }
            }
            rect.X    = minX;
            rect.Y    = minY;
            rect.Size = new SizeF(maxX - minX, maxY - minY);
            return(rect);
        }
Exemple #3
0
        private void cbValveSpin_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            Graphics g  = e.Graphics;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            int spinkind = e.Index;

            // Draw the background of the item.
            e.DrawBackground();
            Rectangle rect      = new Rectangle(e.Bounds.X, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1);
            Rectangle valverect = rect;

            valverect.Inflate(-5, -5);
            valverect.Height /= 2;
            valverect.Offset(0, valverect.Height / 2);
            DrawUtils.AddPointsRange(points, new PointF[4]
            {
                new PointF(valverect.X, valverect.Y),
                new PointF(valverect.X + valverect.Width, valverect.Y + valverect.Height),
                new PointF(valverect.X + valverect.Width, valverect.Y),
                new PointF(valverect.X, valverect.Y + valverect.Height)
            });
            g.FillRectangle(SystemBrushes.ButtonFace, rect);
            g.DrawRectangle(SystemPens.ControlDark, rect);
            Color backcolor = (Color)drw.Props["BackColor" + tbValveState.Value];
            Color forecolor = (Color)drw.Props["ForeColor" + tbValveState.Value];

            float[] angles = new float[4] {
                0, 90, -45, 45
            };
            using (Pen pen = new Pen(forecolor, (tbValveState.Value < 3) ? 1f : 2f))
            {
                using (Brush brush = new SolidBrush(backcolor))
                {
                    DrawUtils.Rotate(points, angles[spinkind], rect);
                    g.FillPolygon(brush, DrawUtils.GetPoints(points));
                    g.DrawPolygon(pen, DrawUtils.GetPoints(points));
                }
            }
            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }