public static void GradientFill(IntPtr hDC, ref RECT rect, uint colorA, uint colorB, bool vertical)
        {
            var vertices = new TRIVERTEX[2];

            vertices[0].x     = rect.Left;
            vertices[0].y     = rect.Top;
            vertices[0].Red   = (ushort)((colorA & 0xFF) << 8);
            vertices[0].Green = (ushort)(((colorA >> 8) & 0xFF) << 8);
            vertices[0].Blue  = (ushort)(((colorA >> 16) & 0xFF) << 8);

            vertices[1].x     = rect.Right;
            vertices[1].y     = rect.Bottom;
            vertices[1].Red   = (ushort)((colorB & 0xFF) << 8);
            vertices[1].Green = (ushort)(((colorB >> 8) & 0xFF) << 8);
            vertices[1].Blue  = (ushort)(((colorB >> 16) & 0xFF) << 8);


            GRADIENT_RECT r;

            r.UpperLeft  = 0;
            r.LowerRight = 1;

            GCHandle pinnedArray = GCHandle.Alloc(vertices, GCHandleType.Pinned);

            GradientFill(hDC, pinnedArray.AddrOfPinnedObject(), 2, ref r, 1, vertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H);
            pinnedArray.Free();
        }
Example #2
0
        public static void PictureDrawGradientFillTriangle(ref int dwColour1, ref int dwColour2, ref int dwColour3, ref int dwColour4, PictureBox myFrm)
        {
            GRADIENT_TRIANGLE[] grTri = new GRADIENT_TRIANGLE[2];
            TRIVERTEX[]         vert  = new TRIVERTEX[4];

            //Colour at upper-left corner
            TRIVERTEX with_1 = vert[0];

            with_1.x     = 0;
            with_1.Y     = 0;
            with_1.Red   = LongToSignedShort(((short)(dwColour1 & 0xFF)) * 256);
            with_1.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF00) / 0x100) * 256));
            with_1.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF0000) / 0x10000) * 256));
            with_1.Alpha = (short)0;

            //Colour at upper-right corner
            TRIVERTEX with_2 = vert[1];

            ///with_2.x = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsX(myFrm.ClientRectangle.Width) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            with_2.Y     = 0;
            with_2.Red   = LongToSignedShort(((short)(dwColour2 & 0xFF)) * 256);
            with_2.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF00) / 0x100) * 256));
            with_2.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF0000) / 0x10000) * 256));
            with_2.Alpha = (short)0;

            //Colour at lower-right corner
            TRIVERTEX with_3 = vert[2];

            ///with_3.x = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsX(myFrm.ClientRectangle.Width) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            ///with_3.Y = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsY(myFrm.ClientRectangle.Height) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelY());
            with_3.Red   = LongToSignedShort(((short)(dwColour3 & 0xFF)) * 256);
            with_3.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour3 & 0xFF00) / 0x100) * 256));
            with_3.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour3 & 0xFF0000) / 0x10000) * 256));
            with_3.Alpha = (short)0;

            //Colour at lower-left corner
            TRIVERTEX with_4 = vert[3];

            with_4.x = 0;
            ///with_4.Y = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsY(myFrm.ClientRectangle.Height) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            with_4.Red   = LongToSignedShort(((short)(dwColour4 & 0xFF)) * 256);
            with_4.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour4 & 0xFF00) / 0x100) * 256));
            with_4.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour4 & 0xFF0000) / 0x10000) * 256));
            with_4.Alpha = (short)0;

            GRADIENT_TRIANGLE with_5 = grTri[0];

            with_5.Vertex1 = 0;
            with_5.Vertex2 = 1;
            with_5.Vertex3 = 2;

            GRADIENT_TRIANGLE with_6 = grTri[1];

            with_6.Vertex1 = 0;
            with_6.Vertex2 = 2;
            with_6.Vertex3 = 3;

            myFrm.Image = null;
        }
Example #3
0
 public static extern bool GradientFill(
     IntPtr          hdc,
     TRIVERTEX[]     pVertex,
     uint            dwNumVertex,
     GRADIENT_RECT[] pMesh,
     uint            dwNumMesh,
     uint            dwMode
     );
Example #4
0
        public static void GradientFill(Graphics g, Rectangle rect, Color startColor, Color endColor, FillDirection fillDir)
        {
            TRIVERTEX[] vertex = new TRIVERTEX[]
            {
                new TRIVERTEX(rect.X, rect.Y, startColor),
                new TRIVERTEX(rect.Right, rect.Bottom, endColor)
            };
            GRADIENT_RECT[] grect = new GRADIENT_RECT[] {
                new GRADIENT_RECT(0, 1)
            };

            IntPtr hdc = g.GetHdc();

            GradientFill(hdc, vertex, (uint)vertex.Length, grect, (uint)grect.Length, (uint)fillDir);
            g.ReleaseHdc(hdc);
        }
Example #5
0
        public static void Pack(BufferChunk chunk, TRIVERTEX[] vertices)
        {
            int nVertices = vertices.Length;

            // Pack the vertices, starting with the length
            chunk += nVertices;
            for (int i = 0; i < nVertices; i++)
            {
                chunk += vertices[i].x;
                chunk += vertices[i].y;
                chunk += vertices[i].Alpha;
                chunk += vertices[i].Blue;
                chunk += vertices[i].Green;
                chunk += vertices[i].Red;
            }
        }
Example #6
0
        /// <summary>
        /// Fills <see cref="Rectangle"/> with Colors that smoothly fades from one side to the other.
        /// </summary>
        /// <param name="rectangle"><see cref="Rectangle"/> to fill</param>
        /// <param name="startColor">Start Color for the fill</param>
        /// <param name="endColor">End Color for the fill</param>
        /// <param name="direction">Direction of the fade from Start to End</param>
        /// <remarks>
        /// This method only supports linear gradient fills
        /// </remarks>
        /// <exception cref="PlatformNotSupportedException">
        /// Thrown when this method is used in a device older than Pocket PC 2003
        /// </exception>
        public void GradientFill(Rectangle rectangle, Color startColor,
                                 Color endColor, GradientFillDirection direction)
        {
            var tva = new TRIVERTEX[2];

            tva[0] = new TRIVERTEX(rectangle.Right, rectangle.Bottom, endColor);
            tva[1] = new TRIVERTEX(rectangle.X, rectangle.Y, startColor);
            var gra = new[] { new GRADIENT_RECT(0, 1) };

            var hdc = Surface.GetHdc();

            try
            {
                if (Environment.OSVersion.Platform == PlatformID.WinCE)
                {
                    NativeMethods.GradientFill(
                        hdc,
                        tva,
                        (uint)tva.Length,
                        gra,
                        (uint)gra.Length,
                        (uint)direction);
                }
                else
                {
                    NativeMethods.GdiGradientFill(
                        hdc,
                        tva,
                        (uint)tva.Length,
                        gra,
                        (uint)gra.Length,
                        (uint)direction);
                }
            }
            catch (MissingMethodException)
            {
                throw new PlatformNotSupportedException("Gradient Fill is not supported in this platform");
            }
            finally
            {
                Surface.ReleaseHdc(hdc);
            }
        }
Example #7
0
        public static void DrawGradientFill(int dwColour1, int dwColour2, Form myFrm)
        {
            TRIVERTEX[]   vert = new TRIVERTEX[2];
            GRADIENT_RECT grRc = new GRADIENT_RECT();

            //Colour at upper-left corner
            TRIVERTEX with_1 = vert[0];

            with_1.x     = 0;
            with_1.Y     = 0;
            with_1.Red   = LongToSignedShort(((short)(dwColour1 & 0xFF)) * 256);
            with_1.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF00) / 0x100) * 256));
            with_1.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF0000) / 0x10000) * 256));
            with_1.Alpha = (short)0;


            //Colour at bottom-right corner
            TRIVERTEX with_2 = vert[1];

            ///with_2.x = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsX(myFrm.ClientRectangle.Width) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            ///with_2.Y = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsY(myFrm.ClientRectangle.Height) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelY());
            with_2.Red   = LongToSignedShort(((short)(dwColour2 & 0xFF)) * 256);
            with_2.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF00) / 0x100) * 256));
            with_2.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF0000) / 0x10000) * 256));
            with_2.Alpha = (short)0;

            grRc.LowerRight = 0;
            grRc.UpperLeft  = 1;

            myFrm = new Form();
            myFrm.Show();

            //parameters:
            //hdc - display context handle of the target window
            //vert(0) - first member of interest in the vert() array
            //2 - number of vert() array members (not ubound(vert))
            //grRc - GRADIENT_RECT info
            //1 - number of grRc structures passed
            //GRADIENT_FILL_RECT_DIRECTION - fill operation -
            //will toggle between 0 and 1, the values of
            //GRADIENT_FILL_RECT_H and GRADIENT_FILL_RECT_V.
            ///	GradientFill(myFrm.CreateGraphics().GetHdc().ToInt32(), ref vert[0], 2, ref grRc, 1, System.Math.Abs(GRADIENT_FILL_RECT_DIRECTION));
        }
    TRIVERTEX[] UnpackTRIVERTEX(BufferChunk chunk)
    {
        int nVertices = chunk.NextInt32();

        TRIVERTEX[] pVertex = new TRIVERTEX[nVertices];

        // Pack the vertices, starting with the length
        for (int i = 0; i < nVertices; i++)
        {
            pVertex[i].x = chunk.NextInt32();
            pVertex[i].y = chunk.NextInt32();
            pVertex[i].Alpha = chunk.NextUInt16();
            pVertex[i].Blue = chunk.NextUInt16();
            pVertex[i].Green = chunk.NextUInt16();
            pVertex[i].Red = chunk.NextUInt16();
        }

        return pVertex;
    }
Example #9
0
        public void FillRect(Rect rect, Color color1, Color color2, bool horizontalGradient)
        {
            TRIVERTEX[] points = new TRIVERTEX[] { new TRIVERTEX(), new TRIVERTEX() };

            points[0].x     = rect.left;
            points[0].y     = rect.top;
            points[0].Red   = Convert.ToInt16(color1.Red << 8);
            points[0].Green = Convert.ToInt16(color1.Green << 8);
            points[0].Blue  = Convert.ToInt16(color1.Blue << 8);

            points[1].x     = rect.right;
            points[1].y     = rect.bottom;
            points[1].Red   = Convert.ToInt16(color2.Red << 8);
            points[1].Green = Convert.ToInt16(color2.Green << 8);
            points[1].Blue  = Convert.ToInt16(color2.Blue << 8);

            GRADIENT_RECT gradientRect = new GRADIENT_RECT(0, 1);

            NativeMethods.GradientFill(Handle, points, 2, ref gradientRect, 1, horizontalGradient ? 0 : 1);
        }
    // Gradient Fills
    public override void GradientRectangle(TRIVERTEX[] pVertex, GRADIENT_RECT[] pMesh, uint dwMode)
    {
        BufferChunk chunk = new BufferChunk(1024);
        chunk += GDI32.EMR_GRADIENTFILL;

        // Pack the vertices
        Pack(chunk, pVertex);

        // Pack the gradient mesh
        Pack(chunk, pMesh);

        // pack the mode
        chunk += dwMode;

        PackCommand(chunk);
    }
Example #11
0
 public static extern bool GradientFill(IntPtr hdc, TRIVERTEX[] pVertex, uint nVertex, GRADIENT_RECT[] pMesh, uint nCount, uint ulMode);
Example #12
0
 public GradientRect(TRIVERTEX[] vertices, GRADIENT_RECT[] mesh, GradientRectDirection style)
 {
     fVertices = vertices;
     fGradientRect = mesh;
     fGradientDirection = style;
 }
Example #13
0
        public static void DrawGradientFillTriangle(ref int dwColour1, ref int dwColour2, ref int dwColour3, ref int dwColour4, ref Form myFrm)
        {
            GRADIENT_TRIANGLE[] grTri = new GRADIENT_TRIANGLE[2];
            TRIVERTEX[]         vert  = new TRIVERTEX[4];

            //Colour at upper-left corner
            TRIVERTEX with_1 = vert[0];

            with_1.x     = 0;
            with_1.Y     = 0;
            with_1.Red   = LongToSignedShort(((short)(dwColour1 & 0xFF)) * 256);
            with_1.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF00) / 0x100) * 256));
            with_1.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour1 & 0xFF0000) / 0x10000) * 256));
            with_1.Alpha = (short)0;

            //Colour at upper-right corner
            TRIVERTEX with_2 = vert[1];

            ///with_2.x = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsX(myFrm.ClientRectangle.Width) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            with_2.Y     = 0;
            with_2.Red   = LongToSignedShort(((short)(dwColour2 & 0xFF)) * 256);
            with_2.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF00) / 0x100) * 256));
            with_2.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour2 & 0xFF0000) / 0x10000) * 256));
            with_2.Alpha = (short)0;

            //Colour at lower-right corner
            TRIVERTEX with_3 = vert[2];

            ///with_3.x = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsX(myFrm.ClientRectangle.Width) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            ///with_3.Y = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsY(myFrm.ClientRectangle.Height) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelY());
            with_3.Red   = LongToSignedShort(((short)(dwColour3 & 0xFF)) * 256);
            with_3.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour3 & 0xFF00) / 0x100) * 256));
            with_3.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour3 & 0xFF0000) / 0x10000) * 256));
            with_3.Alpha = (short)0;

            //Colour at lower-left corner
            TRIVERTEX with_4 = vert[3];

            with_4.x = 0;
            ///with_4.Y = System.Convert.ToInt32(Microsoft.VisualBasic.Compatibility.VB6.Support.PixelsToTwipsY(myFrm.ClientRectangle.Height) / Microsoft.VisualBasic.Compatibility.VB6.Support.TwipsPerPixelX());
            with_4.Red   = LongToSignedShort(((short)(dwColour4 & 0xFF)) * 256);
            with_4.Green = LongToSignedShort(System.Convert.ToInt32(((dwColour4 & 0xFF00) / 0x100) * 256));
            with_4.Blue  = LongToSignedShort(System.Convert.ToInt32(((dwColour4 & 0xFF0000) / 0x10000) * 256));
            with_4.Alpha = (short)0;

            GRADIENT_TRIANGLE with_5 = grTri[0];

            with_5.Vertex1 = 0;
            with_5.Vertex2 = 1;
            with_5.Vertex3 = 2;

            GRADIENT_TRIANGLE with_6 = grTri[1];

            with_6.Vertex1 = 0;
            with_6.Vertex2 = 2;
            with_6.Vertex3 = 3;

            myFrm = new Form();
            myFrm.Show();

            //parameters:
            //hdc - display context handle of the target window
            //vert(0) - first member of interest in the vert() array
            //4 - number of vert() array members (not ubound(vert))
            //grTri(0) - first member of interest in the grTri() array
            //2 - number of grTri() array members (not ubound(grTri)
            //GRADIENT_FILL_TRIANGLE - fill operation
            ///GradientFill(myFrm.CreateGraphics().GetHdc().ToInt32(), ref vert[0], 4, ref grTri[0], 2, GRADIENT_FILL_TRIANGLE);
        }
    public override void GradientTriangle(TRIVERTEX[] pVertex, GRADIENT_TRIANGLE[] pMesh, uint dwMode)
    {
        EMRGRADIENTFILL gradFill = new EMRGRADIENTFILL();
        gradFill.rclBounds = RECT.Empty;
        gradFill.nVer = (uint)pVertex.Length;
        gradFill.nTri = (uint)pMesh.Length;
        gradFill.ulMode = dwMode;
        gradFill.Ver = pVertex;

        PackCommand(gradFill);
    }
Example #15
0
 public static extern bool GradientTriangle(
   [In] SafeHandle hdc,                   // handle to DC
   TRIVERTEX[] pVertex,        // array of vertices
   int dwNumVertex,         // number of vertices
   GRADIENT_TRIANGLE[] pMesh,               // array of gradients
   int dwNumMesh,           // size of gradient array
   int dwMode               // gradient fill mode
 );
Example #16
0
        public static void GradientFill(Graphics g, Rectangle rect, Color startColor, Color endColor, FillDirection fillDir)
        {
            TRIVERTEX[] vertex = new TRIVERTEX[]
            {
                new TRIVERTEX(rect.X,rect.Y,startColor),
                new TRIVERTEX(rect.Right,rect.Bottom,endColor)
            };
            GRADIENT_RECT[] grect = new GRADIENT_RECT[] {
                new GRADIENT_RECT(0,1)
            };

            IntPtr hdc = g.GetHdc();
            GradientFill(hdc, vertex, (uint)vertex.Length, grect, (uint)grect.Length, (uint)fillDir);
            g.ReleaseHdc(hdc);
        }
Example #17
0
 public virtual void GradientTriangle(TRIVERTEX[] pVertex, GRADIENT_TRIANGLE[] pMesh, int dwMode)
 {
     GDI32.GradientTriangle(DeviceContext, pVertex, pVertex.Length, pMesh, pMesh.Length, dwMode);
 }
Example #18
0
 private static extern Int32 GradientFill(
     IntPtr hdc, TRIVERTEX[] pVertex,
     uint dwNumVertex,
     GRADIENT_RECT[] pMesh,
     uint dwNumMesh,
     uint dwMode);
Example #19
0
 public virtual void GradientFill(TRIVERTEX[] pVertex, GRADIENT_TRIANGLE[] pMesh, uint dwMode)
 {
     GDI32.GradientFill(HDC, pVertex, (uint)pVertex.Length, pMesh, (uint)pMesh.Length, dwMode);
 }
 static extern bool GradientFill(IntPtr hdc, TRIVERTEX[] pVertex, uint nVertex, int[] pMesh, int nCount, int ulMode);