Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            pe.Graphics.InterpolationMode = InterpolationMode.Bilinear;
            pe.Graphics.PixelOffsetMode   = PixelOffsetMode.Half;

            Rectangle r = ClientRectangle;

            int halfWidth  = r.Width / 2;
            int halfHeight = r.Height / 2;

            var linearGradientBrush = new LinearGradientBrush(r,
                                                              TopColor, BottomColor, LinearGradientMode.Vertical);

            pe.Graphics.FillRectangle(linearGradientBrush, r);

            int topY    = 10;
            int BottomY = r.Height - 25;

            var font = new Font(this.Font, FontStyle.Bold);

            using (Brush br = new SolidBrush(AllColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("ALL", font, br, new Point(halfWidth - 12, halfHeight - 10));

            using (Brush br = new SolidBrush(TopColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("T", font, br, new Point(halfWidth - 7, topY));

            using (Brush br = new SolidBrush(BottomColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("B", font, br, new Point(halfWidth - 7, BottomY));

            topY    = 0;
            BottomY = r.Height - 32;

            const int hitSize = 32;

            TopHit    = new Rectangle(r.X, topY, r.Width, hitSize);
            BottomHit = new Rectangle(r.X, BottomY, r.Width, hitSize);
            AllHit    = new Rectangle(r.X, halfHeight - 16, r.Width, hitSize);

            if (mouseLoc != Point.Empty)
            {
                if (AllHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, AllHit, AllColor);
                }
                if (TopHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, TopHit, TopColor);
                }
                if (BottomHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, BottomHit, BottomColor);
                }
            }

            //  pe.Graphics.FillRectangle(linearGradientBrush, ClientRectangle);

            base.OnPaint(pe);
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            pe.Graphics.InterpolationMode = InterpolationMode.Bilinear;
            pe.Graphics.PixelOffsetMode   = PixelOffsetMode.Half;

            Rectangle r = ClientRectangle;

            int halfWidth  = r.Width / 2;
            int halfHeight = r.Height / 2;

            int LeftX   = 10;
            int RightX  = r.Width - 30;
            int topY    = 10;
            int BottomY = r.Height - 25;

            var linearGradientBrush = new LinearGradientBrush(r,
                                                              TopColor, BottomColor, LinearGradientMode.Vertical);

            pe.Graphics.FillRectangle(linearGradientBrush, r);

            var font = new Font(this.Font, FontStyle.Bold);

            using (Brush br = new SolidBrush(AllColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("ALL", font, br, new Point(halfWidth - 12, halfHeight - 10));

            using (Brush br = new SolidBrush(TopColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("T", font, br, new Point(halfWidth - 7, topY));

            using (Brush br = new SolidBrush(BottomColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("B", font, br, new Point(halfWidth - 7, BottomY));

            //  pe.Graphics.FillRectangle(linearGradientBrush, ClientRectangle);

            const int hitSize = 40;

            TopHit    = new Rectangle(halfWidth - 10, topY, hitSize, hitSize);
            BottomHit = new Rectangle(halfWidth - 10, BottomY, hitSize, hitSize);
            AllHit    = new Rectangle(halfWidth - 10, halfHeight - 10, hitSize, hitSize);

            base.OnPaint(pe);
        }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            pe.Graphics.InterpolationMode = InterpolationMode.Bilinear;
            pe.Graphics.PixelOffsetMode   = PixelOffsetMode.Half;

            LinearGradientBrush linearGradientBrush =
                new LinearGradientBrush(ClientRectangle, TopLeftColor, BottomRightColor, 0f, true);

            ColorBlend cblend = new ColorBlend(3);

            cblend.Colors = new Color[4] {
                TopLeftColor, TopRightColor, BottomLeftColor, BottomRightColor
            };
            cblend.Positions = new float[4] {
                0f, 0.5f, 0.5f, 1f
            };
            linearGradientBrush.InterpolationColors = cblend;

            Color     c1 = TopLeftColor;
            Color     c2 = BottomLeftColor;
            Color     c3 = TopRightColor;
            Color     c4 = BottomRightColor;
            Rectangle r  = ClientRectangle;

            float delta12R = 1f * (c2.R - c1.R) / r.Height;
            float delta12G = 1f * (c2.G - c1.G) / r.Height;
            float delta12B = 1f * (c2.B - c1.B) / r.Height;
            float delta12A = 1f * (c2.A - c1.A) / r.Height;
            float delta34R = 1f * (c4.R - c3.R) / r.Height;
            float delta34G = 1f * (c4.G - c3.G) / r.Height;
            float delta34B = 1f * (c4.B - c3.B) / r.Height;
            float delta34A = 1f * (c4.A - c3.A) / r.Height;

            var destRect = ClientRectangle;

            var image = Toolbox.Library.Properties.Resources.CheckerBackground;

            pe.Graphics.DrawImage(Toolbox.Library.Properties.Resources.CheckerBackground,
                                  ClientRectangle, destRect, GraphicsUnit.Pixel);

            for (int y = 0; y < r.Height; y++)
            {
                Color c12 = Color.FromArgb(
                    c1.A + (int)(y * delta12A),
                    c1.R + (int)(y * delta12R),
                    c1.G + (int)(y * delta12G),
                    c1.B + (int)(y * delta12B));
                Color c34 = Color.FromArgb(
                    c3.A + (int)(y * delta34A),
                    c3.R + (int)(y * delta34R),
                    c3.G + (int)(y * delta34G),
                    c3.B + (int)(y * delta34B));
                using (LinearGradientBrush lgBrush = new LinearGradientBrush(
                           new Rectangle(0, y, r.Width, 1), c12, c34, 0f))
                {
                    pe.Graphics.FillRectangle(lgBrush, 0, y, r.Width, 1);
                }
            }

            int halfWidth  = r.Width / 2;
            int halfHeight = r.Height / 2;

            int LeftX   = 0;
            int RightX  = r.Width - 32;
            int topY    = 0;
            int BottomY = r.Height - 32;

            var font = new Font(this.Font, FontStyle.Bold);

            const int hitSize = 32;

            TopLeftHit     = new Rectangle(LeftX, topY, hitSize, hitSize);
            TopRightHit    = new Rectangle(RightX, topY, hitSize, hitSize);
            BottomLeftHit  = new Rectangle(LeftX, BottomY, hitSize, hitSize);
            BottomRightHit = new Rectangle(RightX, BottomY, hitSize, hitSize);
            TopHit         = new Rectangle(halfWidth - 16, topY, hitSize, hitSize);
            BottomHit      = new Rectangle(halfWidth - 16, BottomY, hitSize, hitSize);
            LeftHit        = new Rectangle(LeftX, halfHeight - 16, hitSize, hitSize);
            RightHit       = new Rectangle(RightX, halfHeight - 16, hitSize, hitSize);
            AllHit         = new Rectangle(halfWidth - 16, halfHeight - 16, hitSize, hitSize);

            LeftX   = 10;
            RightX  = r.Width - 30;
            topY    = 10;
            BottomY = r.Height - 25;

            if (DisplayHitboxes)
            {
                pe.Graphics.FillRectangle(new SolidBrush(Color.Blue), TopLeftHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Purple), TopRightHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Green), BottomLeftHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Yellow), BottomRightHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Red), TopHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Red), RightHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Red), LeftHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Red), BottomHit);
                pe.Graphics.FillRectangle(new SolidBrush(Color.Pink), AllHit);
            }

            using (Brush br = new SolidBrush(AllColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("ALL", font, br, new Point(halfWidth - 10, halfHeight - 10));

            using (Brush br = new SolidBrush(TopLeftColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("TL", font, br, new Point(LeftX, topY));

            using (Brush br = new SolidBrush(TopRightColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("TR", font, br, new Point(RightX, topY));

            using (Brush br = new SolidBrush(BottomLeftColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("BL", font, br, new Point(LeftX, BottomY));

            using (Brush br = new SolidBrush(BottomRightColor.GrayScale(true).Inverse()))
                pe.Graphics.DrawString("BR", font, br, new Point(RightX, BottomY));

            if (mouseLoc != Point.Empty)
            {
                if (AllHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, AllHit, AllColor);
                }
                if (TopLeftHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, TopLeftHit, TopLeftColor);
                }
                if (TopRightHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, TopRightHit, TopRightColor);
                }
                if (BottomLeftHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, BottomLeftHit, BottomLeftColor);
                }
                if (BottomRightHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, BottomRightHit, BottomRightColor);
                }
                if (TopHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, TopHit, ColorBlend(TopRightColor, TopLeftColor));
                }
                if (BottomHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, BottomHit, ColorBlend(BottomRightColor, BottomLeftColor));
                }
                if (RightHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, RightHit, ColorBlend(BottomRightColor, TopRightColor));
                }
                if (LeftHit.IsHit(mouseLoc))
                {
                    DrawSelectionOutline(pe, LeftHit, ColorBlend(BottomLeftColor, TopLeftColor));
                }
            }

            base.OnPaint(pe);
        }