Beispiel #1
0
        public override void Update()
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            if (!IsVisible)
            {
                return;
            }

            VG.vgLoadIdentity();
            if (!mIsRealUpdate)
            {
                // copy image from mCache
                VG.vgSetPixels(X - 1, Y - 1, mCache, 0, 0, Width + 2, Height + 2);
                return;
            }

            mIsRealUpdate = false;

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

            #region fill rect
            {
                var colStops = new float[25];// xRGBA

                VG.vgSetParameteri(mPaint, (int)VGPaintParamType.VG_PAINT_TYPE, (int)VGPaintType.VG_PAINT_TYPE_LINEAR_GRADIENT);

                if (State == ButtonState.Released)
                {
                    colStops[0]  = 0.0f; colStops[1] = 0x2c / 255f; colStops[2] = 0x2d / 255f; colStops[3] = 0x2f / 255f; colStops[4] = 1.0f;
                    colStops[5]  = 0.20f; colStops[6] = 0x34 / 255f; colStops[7] = 0x35 / 255f; colStops[8] = 0x37 / 255f; colStops[9] = 1.0f;
                    colStops[10] = 0.80f; colStops[11] = 0x34 / 255f; colStops[12] = 0x35 / 255f; colStops[13] = 0x37 / 255f; colStops[14] = 1.0f;
                    colStops[15] = 1.0f; colStops[16] = 0x43 / 255f; colStops[17] = 0x43 / 255f; colStops[18] = 0x47 / 255f; colStops[19] = 1.0f;
                }
                else
                {
                    colStops[0]  = 0.0f; colStops[1] = 0x47 / 255f; colStops[2] = 0x49 / 255f; colStops[3] = 0x4d / 255f; colStops[4] = 1.0f;
                    colStops[5]  = 0.20f; colStops[6] = 0x2e / 255f; colStops[7] = 0x30 / 255f; colStops[8] = 0x32 / 255f; colStops[9] = 1.0f;
                    colStops[10] = 0.80f; colStops[11] = 0x2e / 255f; colStops[12] = 0x30 / 255f; colStops[13] = 0x32 / 255f; colStops[14] = 1.0f;
                    colStops[15] = 1.0f; colStops[16] = 0x16 / 255f; colStops[17] = 0x19 / 255f; colStops[18] = 0x19 / 255f; colStops[19] = 1.0f;
                }

                VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_LINEAR_GRADIENT, 4, new float[] { X, Y, X, Y + Height });
                VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR_RAMP_STOPS, 20, colStops);

                VG.vgSetPaint(mPaint, VGPaintMode.VG_FILL_PATH);

                VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);

                VG.vgSetf(VGParamType.VG_STROKE_LINE_WIDTH, 1.0f);
                VG.vgSeti(VGParamType.VG_STROKE_CAP_STYLE, (int)VGCapStyle.VG_CAP_BUTT);
                VG.vgSeti(VGParamType.VG_STROKE_JOIN_STYLE, (int)VGJoinStyle.VG_JOIN_BEVEL);

                VGU.vguRoundRect(mPath, X, Y, Width, Height, mRound, mRound);
                VG.vgDrawPath(mPath, VGPaintMode.VG_FILL_PATH);
                VG.vgFinish();
            }
            #endregion

            #region draw line
            {
                VG.vgSetParameteri(mPaint, (int)VGPaintParamType.VG_PAINT_TYPE, (int)VGPaintType.VG_PAINT_TYPE_COLOR);
                var lineSize = 1.0f;

                if (State == ButtonState.Released)
                {
                    VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, new[] { 0x6b / 255f, 0x6c / 255f, 0x6c / 255f, 1.0f });
                }
                else
                {
                    lineSize = 3.0f;
                    VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4,
                                        IsLock()
                                            ? new[] { 0xd9 / 255f, 0x11 / 255f, 0x07 / 255f, 1.0f } // red
                                            : new[] { 0x31 / 255f, 0xa3 / 255f, 0x1f / 255f, 1.0f }); // freen
                }

                VG.vgSetPaint(mPaint, VGPaintMode.VG_STROKE_PATH);

                VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);

                VG.vgSetf(VGParamType.VG_STROKE_LINE_WIDTH, lineSize);
                VG.vgSeti(VGParamType.VG_STROKE_CAP_STYLE, (int)VGCapStyle.VG_CAP_BUTT);
                VG.vgSeti(VGParamType.VG_STROKE_JOIN_STYLE, (int)VGJoinStyle.VG_JOIN_BEVEL);

                VGU.vguRoundRect(mPath, X + (lineSize / 2f), Y + (lineSize / 2f), Width - lineSize, Height - lineSize, mRound, mRound);
                VG.vgDrawPath(mPath, VGPaintMode.VG_STROKE_PATH);
                VG.vgFinish();
            }
            #endregion


            base.Update();

            // copy render image to cache
            VG.vgGetPixels(mCache, 0, 0, X - 1, Y - 1, Width + 2, Height + 2);
        }
Beispiel #2
0
        public override void Update()
        {
            if (!IsVisible)
            {
                return;
            }

            if (Width == 0 || Height == 0)
            {
                return;
            }

            if (!mIsRealUpdate)
            {
                // copy image from mCache
                VG.vgSetPixels(X, Y, mCache, 0, 0, Width, Height);
                return;
            }

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

            #region draw line
            {
                VG.vgSetParameteri(mPaint, (int)VGPaintParamType.VG_PAINT_TYPE, (int)VGPaintType.VG_PAINT_TYPE_COLOR);

                float lineSize;
                if (!mActivated)
                {
                    VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, ParentWindow.Background.Value);
                    lineSize = 10.0f;
                }
                else
                {
                    VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR, 4, new[] { 0xe0 / 255f, 0x8f / 255f, 0x1e / 255f, 1.0f });
                    lineSize = 2.0f;
                }


                VG.vgSetPaint(mPaint, VGPaintMode.VG_STROKE_PATH);

                VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);


                VG.vgSetf(VGParamType.VG_STROKE_LINE_WIDTH, lineSize);
                VG.vgSeti(VGParamType.VG_STROKE_CAP_STYLE, (int)VGCapStyle.VG_CAP_BUTT);
                VG.vgSeti(VGParamType.VG_STROKE_JOIN_STYLE, (int)VGJoinStyle.VG_JOIN_BEVEL);

                VGU.vguRoundRect(mPath, X + (lineSize / 2f), Y + (lineSize / 2f), Width - lineSize, Height - lineSize, mRound, mRound);
                VG.vgDrawPath(mPath, VGPaintMode.VG_STROKE_PATH);
                VG.vgFinish();
            }
            #endregion

            #region fill rect
            {
                var colStops = new float[25];// xRGBA

                VG.vgSetParameteri(mPaint, (int)VGPaintParamType.VG_PAINT_TYPE, (int)VGPaintType.VG_PAINT_TYPE_LINEAR_GRADIENT);

                if (!mActivated)
                {
                    colStops[0]  = 0.0f; colStops[1] = 0xb3 / 255f; colStops[2] = 0xb4 / 255f; colStops[3] = 0xb5 / 255f; colStops[4] = 1.0f;
                    colStops[5]  = 0.20f; colStops[6] = 0xb3 / 255f; colStops[7] = 0xb4 / 255f; colStops[8] = 0xb5 / 255f; colStops[9] = 1.0f;
                    colStops[10] = 0.80f; colStops[11] = 0x8a / 255f; colStops[12] = 0x8b / 255f; colStops[13] = 0x8c / 255f; colStops[14] = 1.0f;
                    colStops[15] = 1.0f; colStops[16] = 0x8a / 255f; colStops[17] = 0x8b / 255f; colStops[18] = 0x8c / 255f; colStops[19] = 1.0f;
                }
                else
                {
                    colStops[0]  = 0.0f; colStops[1] = 0xef / 255f; colStops[2] = 0xf0 / 255f; colStops[3] = 0xf0 / 255f; colStops[4] = 1.0f;
                    colStops[5]  = 0.20f; colStops[6] = 0xef / 255f; colStops[7] = 0xf0 / 255f; colStops[8] = 0xf0 / 255f; colStops[9] = 1.0f;
                    colStops[10] = 0.80f; colStops[11] = 0xb6 / 255f; colStops[12] = 0xb6 / 255f; colStops[13] = 0xb6 / 255f; colStops[14] = 1.0f;
                    colStops[15] = 1.0f; colStops[16] = 0xb6 / 255f; colStops[17] = 0xb6 / 255f; colStops[18] = 0xb6 / 255f; colStops[19] = 1.0f;
                }

                VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_LINEAR_GRADIENT, 4, new float[] { X, Y + Height, X, Y });
                VG.vgSetParameterfv(mPaint, (int)VGPaintParamType.VG_PAINT_COLOR_RAMP_STOPS, 20, colStops);

                VG.vgSetPaint(mPaint, VGPaintMode.VG_FILL_PATH);

                VG.vgClearPath(mPath, VGPathCapabilities.VG_PATH_CAPABILITY_ALL);

                VG.vgSetf(VGParamType.VG_STROKE_LINE_WIDTH, 1.0f);
                VG.vgSeti(VGParamType.VG_STROKE_CAP_STYLE, (int)VGCapStyle.VG_CAP_BUTT);
                VG.vgSeti(VGParamType.VG_STROKE_JOIN_STYLE, (int)VGJoinStyle.VG_JOIN_BEVEL);

                var lineSize = 10.0f;
                VGU.vguRoundRect(mPath, X + (lineSize / 2f), Y + (lineSize / 2f), Width - lineSize, Height - lineSize, mRound, mRound);
                //VGU.vguRoundRect(mPath, X, Y, Width, Height, mRound, mRound);
                VG.vgDrawPath(mPath, VGPaintMode.VG_FILL_PATH);
                VG.vgFinish();
            }
            #endregion

            base.Update();

            // copy render image to cache
            VG.vgGetPixels(mCache, 0, 0, X, Y, Width, Height);
        }