예제 #1
0
    internal static GlowBitmap Create(GlowDrawingContext drawingContext, GlowBitmapPart bitmapPart, Color color)
    {
        var orCreateAlphaMask =
            GetOrCreateAlphaMask(bitmapPart);

        var glowBitmap =
            new GlowBitmap(
                drawingContext.ScreenDC,
                orCreateAlphaMask.Width,
                orCreateAlphaMask.Height);

        for (var i = 0; i < orCreateAlphaMask.DIBits.Length; i += BytesPerPixelBgra32)
        {
            var b    = orCreateAlphaMask.DIBits[i + 3];
            var val  = PremultiplyAlpha(color.R, b);
            var val2 = PremultiplyAlpha(color.G, b);
            var val3 = PremultiplyAlpha(color.B, b);
            Marshal.WriteByte(glowBitmap.DIBits, i, val3);
            Marshal.WriteByte(glowBitmap.DIBits, i + 1, val2);
            Marshal.WriteByte(glowBitmap.DIBits, i + 2, val);
            Marshal.WriteByte(glowBitmap.DIBits, i + 3, b);
        }

        return(glowBitmap);
    }
예제 #2
0
            }             // func WmNcHitTest

            #endregion

            #region -- Bitmaps --------------------------------------------------------

            private void CreateBitmaps()
            {
                var offset = 3 * (int)direction;

                for (var i = 0; i < 3; i++)
                {
                    activeBitmaps[i]   = GlowBitmap.FromImage(i + offset, activeColor);
                    inactiveBitmaps[i] = GlowBitmap.FromImage(i + offset, inactiveColor);
                }
            }             // proc CreateBitmaps
예제 #3
0
            }             // proc DestroyBitmaps

            private void ChangeBitmaps(GlowBitmap[] bitmaps, Color newColor)
            {
                var offset = 3 * (int)direction;

                for (var i = 0; i < 3; i++)
                {
                    bitmaps[i].Dispose();
                    bitmaps[i] = null;
                    bitmaps[i] = GlowBitmap.FromImage(i + offset, newColor);
                }
            }
예제 #4
0
            public GlowDrawingHelper(IntPtr handle)
            {
                windowHandle = handle;
                GetBounds(handle);

                hdcScreen                     = NativeMethods.GetDC(IntPtr.Zero);
                hdcWindow                     = NativeMethods.CreateCompatibleDC(hdcScreen);
                hdcBackground                 = NativeMethods.CreateCompatibleDC(hdcScreen);
                blendFunc.BlendOp             = 0;
                blendFunc.BlendFlags          = 0;
                blendFunc.SourceConstantAlpha = 255;
                blendFunc.AlphaFormat         = 1;
                windowBitmap                  = new GlowBitmap(hdcScreen, width, height);
                NativeMethods.SelectObject(hdcWindow, windowBitmap.Handle);
            }             // ctor
예제 #5
0
            private void BlendVertical(GlowBitmap[] bitmaps, int offset)
            {
                GlowBitmap bmpTop    = bitmaps[0];
                GlowBitmap bmpMiddle = bitmaps[1];
                GlowBitmap bmpBottom = bitmaps[2];

                int yMiddle = bmpTop.Height;
                int yBottom = height - bmpBottom.Height;
                int hMiddle = yBottom - yMiddle;

                Blend(bmpTop, 0, 0, bmpTop.Width, bmpTop.Height);
                if (hMiddle > 0)
                {
                    Blend(bmpMiddle, 0, yMiddle, bmpMiddle.Width, hMiddle);
                }
                Blend(bmpBottom, 0, yBottom, bmpBottom.Width, bmpBottom.Height);
            }
예제 #6
0
            private void BlendHorizontal(GlowBitmap[] bitmaps, int offset)
            {
                GlowBitmap bmpLeft   = bitmaps[0];
                GlowBitmap bmpMiddle = bitmaps[1];
                GlowBitmap bmpRight  = bitmaps[2];

                int xLeft   = offset;
                int xMiddle = xLeft + bmpLeft.Width;
                int xRight  = width - offset - bmpRight.Width;
                int wMiddle = xRight - xMiddle;

                Blend(bmpLeft, xLeft, 0, bmpLeft.Width, bmpLeft.Height);
                if (wMiddle > 0)
                {
                    Blend(bmpMiddle, xMiddle, 0, wMiddle, bmpMiddle.Height);
                }
                Blend(bmpRight, xRight, 0, bmpRight.Width, bmpRight.Height);
            }
예제 #7
0
            }             // ctor

            public static GlowBitmap FromImage(int imagePos, Color color)
            {
                CreateAlphaMask();
                CachedBitmapInfo alphaMask = alphaMasks[imagePos];
                IntPtr           hdc       = NativeMethods.GetDC(IntPtr.Zero);
                var glowBitmap             = new GlowBitmap(hdc, alphaMask.Width, alphaMask.Height);

                for (int i = 0; i < alphaMask.DIBits.Length; i += 4)
                {
                    byte alpha = alphaMask.DIBits[i + 3];
                    byte red   = (byte)((double)(color.R * alpha) / 255.0);
                    byte green = (byte)((double)(color.G * alpha) / 255.0);
                    byte blue  = (byte)((double)(color.B * alpha) / 255.0);
                    Marshal.WriteByte(glowBitmap.DIBits, i, blue);
                    Marshal.WriteByte(glowBitmap.DIBits, i + 1, green);
                    Marshal.WriteByte(glowBitmap.DIBits, i + 2, red);
                    Marshal.WriteByte(glowBitmap.DIBits, i + 3, alpha);
                }
                NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                return(glowBitmap);
            }             // ctor static
 internal GlowDrawingContext(int width, int height)
 {
     ScreenDC = InteropMethods.GetDC(IntPtr.Zero);
     if (ScreenDC == IntPtr.Zero)
     {
         return;
     }
     WindowDC = InteropMethods.CreateCompatibleDC(ScreenDC);
     if (WindowDC == IntPtr.Zero)
     {
         return;
     }
     BackgroundDC = InteropMethods.CreateCompatibleDC(ScreenDC);
     if (BackgroundDC == IntPtr.Zero)
     {
         return;
     }
     Blend.BlendOp             = 0;
     Blend.BlendFlags          = 0;
     Blend.SourceConstantAlpha = 255;
     Blend.AlphaFormat         = 1;
     _windowBitmap             = new GlowBitmap(ScreenDC, width, height);
     InteropMethods.SelectObject(WindowDC, _windowBitmap.Handle);
 }
예제 #9
0
 private void Blend(GlowBitmap bmp, int xOriginDest, int yOriginDest, int widthDest, int heightDest)
 {
     NativeMethods.SelectObject(hdcBackground, bmp.Handle);
     NativeMethods.AlphaBlend(hdcWindow, xOriginDest, yOriginDest, widthDest, heightDest, hdcBackground, 0, 0, bmp.Width, bmp.Height, blendFunc);
 }