コード例 #1
0
ファイル: TextArea.cs プロジェクト: Mokarski/Vagonka
        protected override void Draw()
        {
            //VG.vgSetfv(VGParamType.VG_CLEAR_COLOR, 4, new[] { 0.0f, 1.0f, 0.0f, 0.5f });
            //VG.vgClear(0, 0, Width, Height);
            //VG.vgFinish();

            VG.vgSeti(VGParamType.VG_MATRIX_MODE, (int)VGMatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);
            VG.vgLoadIdentity();

            #region draw text

            if (Text == null)
            {
                return;
            }

            VG.vgSetParameteri(mPaint, (int)VGPaintParamType.VG_PAINT_TYPE, (int)VGPaintType.VG_PAINT_TYPE_COLOR);
            VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, FontColor.Value);
            VG.vgSetPaint(mPaint, VGPaintMode.VG_FILL_PATH);

            float[] glyphOrigin = { 0.0f, 0.0f };

            // set glyph matrices
            VG.vgSetfv(VGParamType.VG_GLYPH_ORIGIN, 2, glyphOrigin);
            VG.vgSeti(VGParamType.VG_MATRIX_MODE, (int)VGMatrixMode.VG_MATRIX_GLYPH_USER_TO_SURFACE);
            VG.vgLoadIdentity();

            var widthText = (TextWidth > Width) ? Width : TextWidth;
            switch (TextAlign)
            {
            case Align.Left:
                VG.vgTranslate(TextOffset.X, TextOffset.Y);
                break;

            case Align.Center:
                VG.vgTranslate((Width - widthText + TextOffset.X) / 2f, TextOffset.Y);
                break;

            case Align.Right:
                VG.vgTranslate((Width - widthText - TextOffset.X), TextOffset.Y);
                break;
            }

            VG.vgTranslate(RotateCenter.X, RotateCenter.Y);
            VG.vgRotate(mRotate);
            VG.vgTranslate(-RotateCenter.X, -RotateCenter.Y);

            VG.vgScale(FontSize, FontSize);

            mFontRender.RenderText(Text);
            VG.vgFinish();

            #endregion
        }
コード例 #2
0
ファイル: RawButton.cs プロジェクト: Mokarski/Vagonka
        public override void Update()
        {
            VG.vgSeti(VGParamType.VG_IMAGE_MODE, (int)VGImageMode.VG_DRAW_IMAGE_NORMAL);

            VG.vgSeti(VGParamType.VG_MATRIX_MODE, (int)VGMatrixMode.VG_MATRIX_IMAGE_USER_TO_SURFACE);

            VG.vgLoadIdentity();
            VG.vgTranslate(X, Y);

            /*
             * int width, height;
             * var image = CopyImageToVgBuffer(File.ReadAllBytes(State == ButtonState.Released ? mUpImageUrl : mDownImageUrl), out width, out height);
             * if(image != IntPtr.Zero)
             * {
             *  VG.vgDrawImage(image);
             *  VG.vgDestroyImage(image);
             * }
             */
            base.Update();
        }
コード例 #3
0
ファイル: PressureGraphic.cs プロジェクト: Mokarski/Vagonka
        public override void Draw()
        {
            if (!IsVisible)
            {
                return;
            }

            // draw bg
            if (Background != null)
            {
                VG.vgSetfv(VGParamType.VG_CLEAR_COLOR, 4, Background.Value);
                VG.vgClear(X, Y, Width, Height);
                VG.vgFinish();
            }

            if (Arrows != null)
            {
                Arrows.Update(X, Y);
            }


            VG.vgSetf(VGParamType.VG_STROKE_LINE_WIDTH, 1.0f);
            VG.vgSetfv(VGParamType.VG_STROKE_DASH_PATTERN, 0, null);
            VG.vgSetParameterfv(mStrokePaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, new Color(0x575959FF).Value);
            VG.vgSetPaint(mStrokePaint, VGPaintMode.VG_STROKE_PATH);

            switch (Type)
            {
            case VisializationType.Realtime:
            {
                //mApplication.DebugTimeToConsole("realtime");

                #region Realtime
                if (Grid != null)
                {
                    Grid.Update(X, Y);
                }

                VG.vgSeti(VGParamType.VG_MATRIX_MODE, (int)VGMatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);


                // draw rectangles
                if (mGrapihcs.Count > 0)
                {
                    lock (mGrapihcs)
                        foreach (var data in from data in mGrapihcs where data != null where data.Data != null where data.Data.Length > 0 select data)
                        {
                            VG.vgLoadIdentity();
                            VG.vgTranslate(X + data.Position.X, Y + data.Position.Y);     // (40, 20)

                            var size = (data.Data.Length - 1) > (((uint)(kOxWidht)) - data.Position.X) ? (((uint)(kOxWidht)) - data.Position.X) : (data.Data.Length - 1);
                            for (var i = 0; i < size; i++)
                            {
                                VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);

                                var maxY = data.Data[i] < 5 ? 5 : data.Data[i];     // минимальное значение - 5 единиц, чтобы было видно секции
                                maxY  = data.Data[i] == ushort.MaxValue ? 5 : maxY; // проверяем флаг на наличие датчика
                                maxY /= 2;

                                VGU.vguRect(mPath, i * (kOxWidht / 177f), 0, (kOxWidht / 177f), maxY);

                                var color = (data.Data[i] == ushort.MaxValue)
                                                    ? Palette.White
                                                    : new Color(GetColor(data.Data[i]));

                                VG.vgSetParameterfv(mFillPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, color.Value);
                                VG.vgSetPaint(mFillPaint, VGPaintMode.VG_FILL_PATH);
                                VG.vgDrawPath(mPath, VGPaintMode.VG_FILL_PATH);

                                VG.vgDrawPath(mPath, VGPaintMode.VG_STROKE_PATH);
                            }
                        }
                }
                #endregion
            }
            break;

            case VisializationType.History:
            {
                if (HistoryReports != null)
                {
                    if (HistoryReports.Length > 0)
                    {
                        //Console.WriteLine("history: {0}", HistoryReports.Length);

                        VG.vgSeti(VGParamType.VG_MATRIX_MODE, (int)VGMatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);
                        VG.vgLoadIdentity();
                        VG.vgTranslate(X + 40, Y + 20);         // (40, 20)

                        foreach (var label in mVHistoryLabels)
                        {
                            label.Text = "";
                        }

                        var depth = 0;
                        for (var j = 0; j < HistoryReports.Length; j++)
                        {
                            var data = HistoryReports[j].Restore();

                            if (j % 5 == 0)
                            {
                                //Console.WriteLine("history: {0}", j);
                                var index = j / 5;
                                var date  = HistoryReports[j].Time;
                                mVHistoryLabels[2 * index].Text     = date.ToString("HH:mm");
                                mVHistoryLabels[2 * index + 1].Text = date.ToString("dd") + "/" + date.ToString("MM");
                            }

                            if (data != null)
                            {
                                var size = (data.Length - 1);

                                for (var i = 0; i < size; i++)
                                {
                                    if (data[i] == ushort.MaxValue)
                                    {
                                        continue;
                                    }

                                    VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);

                                    const int kRectHeight = 12;
                                    VGU.vguRect(mPath, i * (kOxWidht / 177f), depth * kRectHeight, (kOxWidht / 177f), kRectHeight);

                                    VG.vgSetParameterfv(mFillPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, new Color(GetColor(data[i])).Value);
                                    VG.vgSetPaint(mFillPaint, VGPaintMode.VG_FILL_PATH);
                                    VG.vgDrawPath(mPath, VGPaintMode.VG_FILL_PATH);

                                    VG.vgDrawPath(mPath, VGPaintMode.VG_STROKE_PATH);
                                }
                            }
                            else
                            {
                                Console.WriteLine("oooops");
                            }

                            depth++;
                        }
                    }
                }
            }
            break;
            }


            //base.Update();
        }
コード例 #4
0
ファイル: PressureGraphic.cs プロジェクト: Mokarski/Vagonka
        private void Init()
        {
            mTimer = new Timer(ProcessTimerEvent, null, Timeout.Infinite, Timeout.Infinite);

            mPath        = VG.vgCreatePath(0, VGPathDatatype.VG_PATH_DATATYPE_S_16, 1, 0, 0, 0, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);
            mFillPaint   = VG.vgCreatePaint();
            mStrokePaint = VG.vgCreatePaint();

            mGrapihcs = new List <GraphicsData>();

            var color = new VGSolidColor(new Color(0xD1D3D4FF));

            #region Lines & arrows
            {
                var path = VGPath.OpenVGPath();
                VG.vgLoadIdentity();

                const float kXBias = 3f;
                const float kYBias = 12f;

                VGU.vguLine(path, 0, 0, Width - 60, 0);          // OX
                //VGU.vguLine(path, 0, 0, 0, Height - 40); // OY
                VGU.vguLine(path, 0, 0, 0, Height - kYBias - 1); // OY



                var yArroyBias = Height - kYBias - 1;
                //var yArroyBias = Height - 40f;

                var pathData = new float[16];
                pathData[0] = -kXBias;
                pathData[1] = yArroyBias;          //0f;
                pathData[2] = 0f;
                pathData[3] = yArroyBias + kYBias; // kYBias;
                pathData[4] = kXBias;
                pathData[5] = yArroyBias;          //0f;
                VGU.vguPolygon(path, pathData, 3, VGboolean.VG_TRUE);

                var xArroyBias = Width - 60f;
                pathData[0] = xArroyBias;
                pathData[1] = -kXBias;
                pathData[2] = xArroyBias + kYBias;
                pathData[3] = 0f;
                pathData[4] = xArroyBias;
                pathData[5] = kXBias;
                VGU.vguPolygon(path, pathData, 3, VGboolean.VG_TRUE);

                var vgPath = new VGPath(path, color, color);
                vgPath.Move(35, 15);
                Arrows = vgPath;
            }

            #endregion

            #region Grid

            {
                var path = VGPath.OpenVGPath();
                VGU.vguLine(path, 0, 0, Width - 60, 0); // OX

                var vgPath = new VGPath(path, null, null);
                //vgPath.SetStroke(color);
                vgPath.SetStroke(color, new[] { 2.0f, 2.0f });
                vgPath.StrokeWidth = 0.5f;
                vgPath.Move(40, 20 + 180);

                Grid = vgPath;
            }

            #endregion

            #region childs
            mHLabels = new[]
            {
                new TextArea(this, 15, 0, 36, 18)
                {
                    Text = "1"
                },
                new TextArea(this, (int)(kOxWidht * 50 / 177), 0, 36, 18)
                {
                    Text = "50"
                },
                new TextArea(this, (int)(kOxWidht * 100 / 177), 0, 36, 18)
                {
                    Text = "100"
                },
                new TextArea(this, (int)(kOxWidht * 150 / 177), 0, 36, 18)
                {
                    Text = "150"
                }
            };

            var oyLabel = new TextArea(this, -10, Height, 60, 18)
            {
                Text = "P, бар"
            };
            mVRuntimeLabels = new[]
            {
                oyLabel,
                new TextArea(this, -10, 10, 36, 18)
                {
                    Text = "0"
                },

                new TextArea(this, -10, Height * 50 / kHeight, 36, 18)
                {
                    Text = "100"
                },
                new TextArea(this, -10, Height * 100 / kHeight, 36, 18)
                {
                    Text = "200"
                },
                new TextArea(this, -10, Height * 150 / kHeight, 36, 18)
                {
                    Text = "300"
                },
                new TextArea(this, -10, Height * 200 / kHeight, 36, 18)
                {
                    Text = "400"
                },
                new TextArea(this, -10, Height * 250 / kHeight, 36, 18)
                {
                    Text = "500"
                }
            };


            mVHistoryLabels = new[]
            {
                new TextArea(this, -15, Height * 10 / kHeight, 45, 18)
                {
                    Text = ""
                },
                new TextArea(this, -15, Height * 25 / kHeight, 45, 18)
                {
                    Text = ""
                },

                new TextArea(this, -15, Height * 60 / kHeight, 45, 18)
                {
                    Text = ""
                },
                new TextArea(this, -15, Height * 75 / kHeight, 45, 18)
                {
                    Text = ""
                },

                new TextArea(this, -15, Height * 110 / kHeight, 45, 18)
                {
                    Text = ""
                },
                new TextArea(this, -15, Height * 125 / kHeight, 45, 18)
                {
                    Text = ""
                },

                new TextArea(this, -15, Height * 160 / kHeight, 45, 18)
                {
                    Text = ""
                },
                new TextArea(this, -15, Height * 175 / kHeight, 45, 18)
                {
                    Text = ""
                },

                new TextArea(this, -15, Height * 210 / kHeight, 45, 18)
                {
                    Text = ""
                },
                new TextArea(this, -15, Height * 225 / kHeight, 45, 18)
                {
                    Text = ""
                }
            };

            foreach (var label in mHLabels)
            {
                label.SetFont(new Color(0xD1D3D4FF), 20);
                label.SetAlign(Align.Right);
            }


            foreach (var label in mVRuntimeLabels)
            {
                label.SetFont(new Color(0xD1D3D4FF), 20);
                label.SetAlign(Align.Right);
            }


            foreach (var label in mVHistoryLabels)
            {
                label.SetFont(new Color(0xD1D3D4FF), 20);
                label.SetAlign(Align.Right);
                label.Hide();
            }

            //mVRuntimeLabels[mVRuntimeLabels.Length - 2].SetFont(new Color(0x5EE82CFF), 20);// "180"

            var oxLabel = new TextArea(this, Width - 20, 0, 60, 18)
            {
                Text = "N"
            };
            oxLabel.SetFont(new Color(0xD1D3D4FF), 20);


            oyLabel.SetFont(new Color(0xD1D3D4FF), 20);
            oyLabel.SetAlign(Align.Left, new GfxPoint(0, 5));
            #endregion

            Move(170, 310);

            //ImageCacheBorder = 50; // work

            Type = VisializationType.Realtime;
        }