Example #1
0
        public WpfVisual(BadgeCaps device, FrameworkElement element, int defaultWidth = -1, int defaultHeight = -1, bool dither = false, bool enableBlend = false)
        {
            if (defaultWidth <= 0)
            {
                defaultWidth = device.Width;
            }
            if (defaultHeight <= 0)
            {
                defaultHeight = device.Height;
            }

            Element = element;
            Element.Measure(new Size(defaultWidth, defaultHeight));
            Element.Arrange(new Rect(0, 0, defaultWidth, defaultHeight));

            ClipWidth  = (int)Math.Ceiling(Element.ActualWidth);
            ClipHeight = (int)Math.Ceiling(Element.ActualHeight);

            Dither      = dither;
            EnableBlend = enableBlend;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight, PixelFormat.TwoBits);
            m_renderTarget       = new RenderTargetBitmap(ClipWidth, ClipHeight, 96, 96, PixelFormats.Pbgra32);

            Update(0); // To avoid remeasuring on a background thread
            UpdateCachedImage();
        }
Example #2
0
        public RawVisual(int width, int height, IBadgeVisual bake)
        {
            ClipWidth = width;
            ClipHeight = height;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight);
            bake.Render(m_cachedIntermediate, 0, 0);
        }
Example #3
0
        public RawVisual(int width, int height, IBadgeVisual bake)
        {
            ClipWidth  = width;
            ClipHeight = height;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight, PixelFormat.TwoBits);
            bake.Render(m_cachedIntermediate, 0, 0);
        }
Example #4
0
        public RawVisual(int width, int height, bool enableBlend)
        {
            ClipWidth = width;
            ClipHeight = height;

            m_cachedIntermediate = new BadgeRenderTarget(width, height);
            if(enableBlend)
            {
                m_alphaMask = new byte[m_cachedIntermediate.IntermediateImage.Length];
            }
        }
Example #5
0
        public RawVisual(int width, int height, bool enableBlend)
        {
            ClipWidth  = width;
            ClipHeight = height;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight, PixelFormat.TwoBits);
            if (enableBlend)
            {
                m_alphaMask = new byte[m_cachedIntermediate.IntermediateImage.Length];
            }
        }
Example #6
0
 public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
 {
     if (m_currentItem != null)
     {
         m_currentItem.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
     }
     else if (m_currentTransition != null)
     {
         m_currentTransition.Item1.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
         m_currentTransition.Item2.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
     }
 }
Example #7
0
 public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
 {
     if (EnableBlend)
     {
         BadgeImage.Blit(
             rt.IntermediateImage, rt.IntermediateStride, rt.WidthInPixels, rt.Height,
             m_cachedIntermediate.IntermediateImage, m_alphaMask, m_cachedIntermediate.IntermediateStride, m_cachedIntermediate.WidthInPixels, m_cachedIntermediate.Height,
             parentRenderX + RenderX, parentRenderY + RenderY, ClipX, ClipY, ClipWidth, ClipHeight);
     }
     else
     {
         BadgeImage.Blit(
             rt.IntermediateImage, rt.IntermediateStride, rt.WidthInPixels, rt.Height,
             m_cachedIntermediate.IntermediateImage, m_cachedIntermediate.IntermediateStride, m_cachedIntermediate.WidthInPixels, m_cachedIntermediate.Height,
             parentRenderX + RenderX, parentRenderY + RenderY, ClipX, ClipY, ClipWidth, ClipHeight);
     }
 }
Example #8
0
        public WpfVisual(FrameworkElement element, int defaultWidth = BadgeCaps.Width, int defaultHeight = BadgeCaps.Height, bool dither = false, bool enableBlend = false)
        {
            Element = element;
            Element.Measure(new Size(defaultWidth, defaultHeight));
            Element.Arrange(new Rect(0, 0, defaultWidth, defaultHeight));

            ClipWidth = (int)Math.Ceiling(Element.ActualWidth);
            ClipHeight = (int)Math.Ceiling(Element.ActualHeight);

            Dither = dither;
            EnableBlend = enableBlend;

            m_cachedIntermediate = new BadgeRenderTarget(ClipWidth, ClipHeight);
            m_renderTarget = new RenderTargetBitmap(ClipWidth, ClipHeight, 96, 96, PixelFormats.Pbgra32);

            Update(0); // To avoid remeasuring on a background thread
            UpdateCachedImage();
        }
Example #9
0
 public BadgeFrameEventArgs(BadgeRenderTarget buffer)
 {
     Frame = buffer;
 }
Example #10
0
 public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
 {
 }
Example #11
0
        public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
        {
            UpdateCachedImage();

            if(EnableBlend)
            {
                BadgeImage.Blit(
                    rt.IntermediateImage, rt.Width, rt.Height,
                    m_cachedIntermediate.IntermediateImage, m_alphaMask, m_cachedIntermediate.Width, m_cachedIntermediate.Height,
                    parentRenderX + RenderX, parentRenderY + RenderY, ClipX, ClipY, ClipWidth, ClipHeight);
            }
            else
            {
                BadgeImage.Blit(
                    rt.IntermediateImage, rt.Width, rt.Height,
                    m_cachedIntermediate.IntermediateImage, m_cachedIntermediate.Width, m_cachedIntermediate.Height,
                    parentRenderX + RenderX, parentRenderY + RenderY, ClipX, ClipY, ClipWidth, ClipHeight);
            }
        }
Example #12
0
 public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
 {
     if(m_currentItem != null)
     {
         m_currentItem.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
     }
     else if(m_currentTransition != null)
     {
         m_currentTransition.Item1.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
         m_currentTransition.Item2.Element.Render(rt, parentRenderX + RenderX, parentRenderY + RenderY);
     }
 }
Example #13
0
 public void Render(BadgeRenderTarget rt, int parentRenderX, int parentRenderY)
 {
 }
Example #14
0
        void RunFrame()
        {
            var commands = new MemoryStream();

            if (m_prevBrightness != Brightness)
            {
                m_prevBrightness = Brightness;
                BadgeCommands.CreateUpdateBrightnessSetting(commands, Brightness);
            }

            if (UseFrameBuffer)
            {
                BadgeCaps device = Device;
                if (device != null && (m_renderTarget == null || !m_renderTarget.SameDimentions(device.Width, device.Height, device.BitsPerPixel == 1 ? PixelFormat.OneBit : PixelFormat.TwoBits)))
                {
                    m_renderTarget = new BadgeRenderTarget(device.Width, device.Height, device.BitsPerPixel == 1 ? PixelFormat.OneBit : PixelFormat.TwoBits);
                }

                if (m_renderTarget != null)
                {
                    var render = RenderFrame;
                    if (render != null)
                    {
                        render(this, new BadgeFrameEventArgs(Device, m_renderTarget));
                    }

                    if (Dither)
                    {
                        m_renderTarget.DitherImage();
                    }
                    m_renderTarget.PackBuffer(RotateFrame);

                    var ready = FrameReady;
                    if (ready != null)
                    {
                        ready(this, new BadgeFrameEventArgs(Device, m_renderTarget));
                    }

                    int writeBufferLength;
                    BadgeCommands.CreateWriteRect(commands, Target.BackBuffer, m_renderTarget.PackedFormat,
                                                  0, 0, (byte)m_renderTarget.WidthInBlocks, (byte)m_renderTarget.Height, out writeBufferLength);
                    commands.Write(m_renderTarget.PackedBuffer, 0, m_renderTarget.PackedBuffer.Length);
                    BadgeCommands.CreateSwap(commands, false, 0);
                }
            }
            else
            {
                var getCommands = GenerateCommands;
                if (getCommands != null)
                {
                    getCommands(this, new BadgeCommandEventArgs(Device, commands));
                }
            }

            var readyToSend = ReadyToSend;

            if (readyToSend != null)
            {
                readyToSend(this, new BadgeCommandEventArgs(Device, commands));
            }

            SendFrame(commands);
        }
Example #15
0
 public BadgeFrameEventArgs(BadgeCaps device, BadgeRenderTarget buffer)
 {
     Device = device;
     Frame  = buffer;
 }