public void CompositeFrame(CompositeVideoFrameContext context)
        {
            IDirect3DSurface outputSurface = context.OutputFrame.Direct3DSurface;
            using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, outputSurface))
            using (CanvasDrawingSession drawSession = renderTarget.CreateDrawingSession())
            {
                foreach (var overlaySurface in context.SurfacesToOverlay)
                {
                    var overlay = context.GetOverlayForSurface(overlaySurface);

                    var width = (float)overlay.Position.Width;
                    var height = (float)overlay.Position.Height;
                    using (var overlayBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, overlaySurface))
                    using (var videoBrush = new CanvasImageBrush(_canvasDevice, overlayBitmap))
                    {
                        var scale = width / overlay.Clip.GetVideoEncodingProperties().Width;
                        videoBrush.Transform = Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation((float)overlay.Position.X, (float)overlay.Position.Y);
                        drawSession.FillEllipse(new Vector2((float)overlay.Position.X + width / 2, (float)overlay.Position.Y + height / 2), width / 2, height / 2, videoBrush);
                    }
                }

                drawSession.DrawText("Party\nTime!", new Vector2(_backgroundProperties.Width / 1.5f, 100), Windows.UI.Colors.CornflowerBlue,
                    new CanvasTextFormat()
                    {
                        FontSize = (float)_backgroundProperties.Width / 13,
                        FontWeight = new FontWeight() { Weight = 999 },
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Center
                    });
            }
        }
Ejemplo n.º 2
0
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            var inputSurface = context.InputFrame.Direct3DSurface;
            var outputSurface = context.OutputFrame.Direct3DSurface;

            using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, inputSurface))
            using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, outputSurface))
            using (var ds = renderTarget.CreateDrawingSession())
            using (var brush = new CanvasImageBrush(canvasDevice, inputBitmap))
            using (var textCommandList = new CanvasCommandList(canvasDevice))
            {
                using (var clds = textCommandList.CreateDrawingSession())
                {
                    clds.DrawText(
                        "Win2D\nMediaClip",
                        (float)inputBitmap.Size.Width / 2,
                        (float)inputBitmap.Size.Height / 2,
                        brush,
                        new CanvasTextFormat()
                        {
                            FontSize = (float)inputBitmap.Size.Width / 5,
                            FontWeight = new FontWeight() { Weight = 999 },
                            HorizontalAlignment = CanvasHorizontalAlignment.Center,
                            VerticalAlignment = CanvasVerticalAlignment.Center
                        });
                }

                var background = new GaussianBlurEffect()
                {
                    BlurAmount = 10,
                    BorderMode = EffectBorderMode.Hard,
                    Source = new BrightnessEffect()
                    {
                        BlackPoint = new Vector2(0.5f, 0.7f),
                        Source = new SaturationEffect()
                        {
                            Saturation = 0,
                            Source = inputBitmap
                        }
                    }
                };

                var shadow = new ShadowEffect()
                {
                    Source = textCommandList,
                    BlurAmount = 10
                };

                var composite = new CompositeEffect()
                {
                    Sources = { background, shadow, textCommandList }
                };

                ds.DrawImage(composite);
            }
        }
Ejemplo n.º 3
0
        private void BackgroundCanvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(Task.Run(async () =>
            {
                // Load the background image and create an image brush from it
                this.backgroundImage = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Background.jpg"));
                this.backgroundBrush = new CanvasImageBrush(sender, this.backgroundImage);

                // Set the brush's edge behaviour to wrap, so the image repeats if the drawn region is too big
                this.backgroundBrush.ExtendX = this.backgroundBrush.ExtendY = CanvasEdgeBehavior.Wrap;

                this.resourcesLoaded = true;
            }).AsAsyncAction());
        }
        public void Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;
            using (var ds = args.DrawingSession)
            {
                ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);
                var brush = new CanvasImageBrush(sender, this.effect)
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    SourceRectangle = new Rect(0, bitmap.SizeInPixels.Height - 96, 96, 96)
                };

                ds.FillRectangle(0, 0, (float)this.ActualWidth, (float)this.ActualHeight, brush);
            }
            sender.Invalidate();
        }
Ejemplo n.º 5
0
        void m_canvasControl_CreateResources(CanvasControl sender, object args)
        {
            UpdateCanvasControlSize();
            m_imageBrush = new CanvasImageBrush(sender);

            m_offscreenTarget = new CanvasRenderTarget(sender, new Size(100, 100));

            using (CanvasDrawingSession ds = m_offscreenTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.DarkBlue);
                ds.FillRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.DarkRed);
                ds.DrawRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.LightGreen);
                ds.DrawText("Abc", 0, 0, Colors.LightGray);
                ds.DrawText("Def", 25, 25, Colors.LightGray);
                ds.DrawText("Efg", 50, 50, Colors.LightGray);
            }
        }
Ejemplo n.º 6
0
        private void BackgroundCanvas32_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(Task.Run(async() =>
            {
                // Load the background image and create an image brush from it
                backgroundImage32 = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/CheckboardPattern_3264.png"));
                backgroundBrush32 = new CanvasImageBrush(sender, backgroundImage32)
                {
                    Opacity = 0.3f
                };

                // Set the brush's edge behaviour to wrap, so the image repeats if the drawn region is too big
                backgroundBrush32.ExtendX = backgroundBrush32.ExtendY = CanvasEdgeBehavior.Wrap;

                //this.resourcesLoaded32 = true;
            }).AsAsyncAction());
        }
Ejemplo n.º 7
0
        private ICanvasBrush CreateBackgroundBrush(ICanvasResourceCreator device)
        {
            var bitmap = new CanvasRenderTarget(device, 16, 16, 96); // TODO: Dpi?

            using (var drawingSession = bitmap.CreateDrawingSession())
            {
                drawingSession.Clear(Colors.Gray);
                drawingSession.FillRectangle(0, 0, 8, 8, Colors.LightGray);
                drawingSession.FillRectangle(8, 8, 8, 8, Colors.LightGray);
            }

            var brush = new CanvasImageBrush(device, bitmap);

            brush.ExtendX = CanvasEdgeBehavior.Wrap;
            brush.ExtendY = CanvasEdgeBehavior.Wrap;

            return(brush);
        }
Ejemplo n.º 8
0
            public OpacityDemo(DrawImageEmulations example, CanvasControl sender)
            {
                fillPattern         = example.checkedFillPattern;
                premultipliedSource = CreateSourceImage(sender, CanvasAlphaMode.Premultiplied);
                ignoreSource        = CreateSourceImage(sender, CanvasAlphaMode.Ignore);

                premultipliedTarget = new CanvasRenderTarget[2]
                {
                    CreateTarget(sender, CanvasAlphaMode.Premultiplied),
                    CreateTarget(sender, CanvasAlphaMode.Premultiplied)
                };

                ignoreTarget = new CanvasRenderTarget[2]
                {
                    CreateTarget(sender, CanvasAlphaMode.Ignore),
                    CreateTarget(sender, CanvasAlphaMode.Ignore)
                };
            }
Ejemplo n.º 9
0
        public bool SetImageBrushBitmap()
        {
            if (Bitmap == null)
            {
                return(false);
            }

            CanvasImageBrush brush = Brush as CanvasImageBrush;

            if (brush == null)
            {
                return(false);
            }

            brush.Image = Bitmap;

            return(true);
        }
        public void Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var size = sender.Size;

            using (var ds = args.DrawingSession)
            {
                ds.DrawImage(effect, (size.ToVector2() - currentEffectSize) / 2);
                var brush = new CanvasImageBrush(sender, this.effect)
                {
                    ExtendX         = CanvasEdgeBehavior.Wrap,
                    ExtendY         = CanvasEdgeBehavior.Wrap,
                    SourceRectangle = new Rect(0, bitmap.SizeInPixels.Height - 96, 96, 96)
                };

                ds.FillRectangle(0, 0, (float)this.ActualWidth, (float)this.ActualHeight, brush);
            }
            sender.Invalidate();
        }
Ejemplo n.º 11
0
        // called when the CanvasAnimatedControl control first starts drawing.
        void drawingBoard_Setup(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            var filelocation = new Uri("ms-appx:///Assets/Pictures/lauren_mayberry.jpg"); //343 × 515

            // previously:
            // lauren = await CanvasBitmap.LoadAsync(sender, filelocation);
            lauren = CanvasBitmap.LoadAsync(sender, filelocation).AsTask().Result;

            _blur = new GaussianBlurEffect {
                BlurAmount = 3.0f, Source = lauren
            };

            lauren_brush = new CanvasImageBrush(sender, _blur)
            {
                SourceRectangle = new Rect(0, 0, 343, 343), // I have no idea about these params.
                Opacity         = 0.9f,
                ExtendX         = CanvasEdgeBehavior.Wrap,
                ExtendY         = CanvasEdgeBehavior.Wrap
            };
        }
Ejemplo n.º 12
0
        private async void canvas_CreateResources(CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            prebakedDrawing = new CanvasRenderTarget(sender, sender.Size);

            CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/BG.png"));

            backgroundBitmapBrush = new CanvasImageBrush(sender, bitmap);
            backgroundBitmapBrush.SourceRectangle = new Rect(bitmap.Bounds.X, bitmap.Bounds.Y, bitmap.Bounds.Width, bitmap.Bounds.Height);
            backgroundBitmapBrush.ExtendX         = CanvasEdgeBehavior.Wrap;
            backgroundBitmapBrush.ExtendY         = CanvasEdgeBehavior.Wrap;
            backgroundBitmapBrush.Interpolation   = CanvasImageInterpolation.NearestNeighbor;

            piecesBitmap = await CanvasBitmap.LoadAsync(sender, new Uri("ms-appx:///Assets/Pieces.png"));

            headingTextFormat            = new CanvasTextFormat();
            headingTextFormat.FontFamily = "Times New Roman";
            headingTextFormat.FontSize   = 30;

            finishedLoadingResources = true;
        }
Ejemplo n.º 13
0
            public OffsetDemo(DrawImageEmulations example, CanvasControl sender)
            {
                fillPattern = example.checkedFillPattern;

                var rt = new CanvasRenderTarget(sender, (float)example.tiger.Size.Width, (float)example.tiger.Size.Height, sender.Dpi / 3);

                using (var ds = rt.CreateDrawingSession())
                {
                    ds.DrawImage(example.tiger, rt.Bounds);
                }
                sourceBitmap = rt;

                sourceEffect = new HueRotationEffect()
                {
                    Source = sourceBitmap,
                    Angle  = 1
                };

                showSourceRectRT = new CanvasRenderTarget(sender, (float)rt.Size.Width, (float)rt.Size.Height, rt.Dpi);
            }
Ejemplo n.º 14
0
        void Canvas_CreateResources(CanvasControl sender, object args)
        {
            defaultDpiBitmap = CreateTestBitmap(sender, defaultDpi);
            highDpiBitmap    = CreateTestBitmap(sender, highDpi);
            lowDpiBitmap     = CreateTestBitmap(sender, lowDpi);

            autoDpiRenderTarget = new CanvasRenderTarget(sender, testSize, testSize);
            highDpiRenderTarget = new CanvasRenderTarget(sender, testSize, testSize, highDpi);
            lowDpiRenderTarget  = new CanvasRenderTarget(sender, testSize, testSize, lowDpi);

            saturationEffect = new SaturationEffect {
                Saturation = 0
            };

            imageBrush = new CanvasImageBrush(sender);

            imageSource         = new CanvasImageSource(sender, controlSize, controlSize);
            imageControl.Source = imageSource;

            swapChain = new CanvasSwapChain(sender, controlSize, controlSize);
            swapChainPanel.SwapChain = swapChain;
        }
Ejemplo n.º 15
0
        private void OnRender(EngineDrawEventArgs args)
        {
            var coordinateSystem = Entity.Level.RootEntity.GetImplementation <ICoordinateSystem>();
            var lineTransform    = Entity.GetImplementation <ILineTransform>();

            if (coordinateSystem == null || lineTransform == null)
            {
                return;
            }

            var startPoint = coordinateSystem.TransformToDips(lineTransform.Point1);
            var endPoint   = coordinateSystem.TransformToDips(lineTransform.Point2);

            var sprite = Sprite.Resolve(Entity);

            if (sprite == null)
            {
                // Use Color
                // TODO: Stroke width?
                args.DrawingSession.DrawLine(startPoint, endPoint, Color);
            }
            else
            {
                // Use Sprite
                // TODO: Respect sprite size and adjust stroke width accordingly
                // TODO: Rotate sprite depending on the angle of the line
                if (_spriteBrush == null)
                {
                    var brush = new CanvasImageBrush(args.Sender, sprite.Image);
                    brush.ExtendX = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap;
                    brush.ExtendY = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap;
                    _spriteBrush  = brush;
                }

                args.DrawingSession.DrawLine(startPoint, endPoint, _spriteBrush);
            }
        }
Ejemplo n.º 16
0
 public void Draw(CanvasDrawingSession graphics, float scale)
 {
     if (_points != null && _points.Count > 0)
     {
         ICanvasBrush brush;
         if (DrawingColor == Colors.Transparent)
         {
             if (_brush_image == null)
             {
                 return;
             }
             brush = new CanvasImageBrush(graphics, _brush_image);
         }
         else
         {
             brush = new CanvasSolidColorBrush(graphics, DrawingColor);
         }
         if (_points.Count == 1)
         {
             graphics.DrawLine((float)_points[0].X * scale, (float)_points[0].Y * scale, (float)_points[0].X * scale, (float)_points[0].Y * scale, brush, DrawingSize * scale);
         }
         else
         {
             var style = new CanvasStrokeStyle();
             style.DashCap  = CanvasCapStyle.Round;
             style.StartCap = CanvasCapStyle.Round;
             style.EndCap   = CanvasCapStyle.Round;
             for (int i = 0; i < _points.Count - 1; ++i)
             {
                 graphics.DrawLine((float)_points[i].X * scale, (float)_points[i].Y * scale, (float)_points[i + 1].X * scale, (float)_points[i + 1].Y * scale, brush, DrawingSize * scale, style);
             }
         }
         StoredDrawingSession = graphics;
         StoredScale          = scale;
     }
 }
Ejemplo n.º 17
0
        void m_canvasControl_CreateResources(CanvasControl sender, object args)
        {
            m_bitmap_tiger      = null;
            m_bitmap_colorGrids = null;

            UpdateCanvasControlSize();
            m_imageBrush = new CanvasImageBrush(sender);

            m_offscreenTarget = new CanvasRenderTarget(sender, 100, 100);

            using (CanvasDrawingSession ds = m_offscreenTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.DarkBlue);
                ds.FillRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.DarkRed);
                ds.DrawRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.LightGreen);
                ds.DrawText("Abc", 0, 0, Colors.LightGray);
                ds.DrawText("Def", 25, 25, Colors.LightGray);
                ds.DrawText("Efg", 50, 50, Colors.LightGray);
            }

            CanvasGradientStop[] stops = new CanvasGradientStop[4];
            stops[0].Position     = 0;
            stops[0].Color        = Colors.Black;
            stops[1].Position     = 1;
            stops[1].Color        = Colors.White;
            stops[2].Position     = 0.2f;
            stops[2].Color        = Colors.Purple;
            stops[3].Position     = 0.7f;
            stops[3].Color        = Colors.Green;
            m_linearGradientBrush = CanvasLinearGradientBrush.CreateRainbow(sender, 0.0f);
            m_radialGradientBrush = new CanvasRadialGradientBrush(
                sender,
                stops,
                CanvasEdgeBehavior.Clamp,
                CanvasAlphaMode.Premultiplied);
        }
Ejemplo n.º 18
0
        private void DrawBackgroundBrush()
        {
            var dpi = GraphicsInformation.Dpi;

            if (_backgroundBrush != null)
            {
                _backgroundBrush.Dispose();
                _backgroundBrush = null;
            }

            using (var renderTarget = new CanvasRenderTarget(_device, 16, 16, dpi))
            {
                using (var drawingSession = renderTarget.CreateDrawingSession())
                {
                    drawingSession.Clear(Colors.Gray);
                    drawingSession.FillRectangle(8, 0, 8, 8, Colors.DarkGray);
                    drawingSession.FillRectangle(0, 8, 8, 8, Colors.DarkGray);
                }

                _backgroundBrush         = new CanvasImageBrush(_device, renderTarget);
                _backgroundBrush.ExtendX = CanvasEdgeBehavior.Wrap;
                _backgroundBrush.ExtendY = CanvasEdgeBehavior.Wrap;
            }
        }
Ejemplo n.º 19
0
        public Renderer(CoreWindow window)
        {
            this.window = window;
            window.PointerPressed += window_PointerPressed;
            window.PointerMoved += window_PointerMoved;
            window.PointerReleased += window_PointerReleased;

            device = new CanvasDevice();
            swapChainManager = new SwapChainManager(window, device);

            var effect = new GaussianBlurEffect()
            {
                BlurAmount = 5,
                Source = inputEffect
            };

            outputEffect = new Transform2DEffect()
            {
                Source = effect
            };

            imageBrush = new CanvasImageBrush(device);
            imageBrush.Opacity = 0.99f;
        }
Ejemplo n.º 20
0
        public Renderer(CoreWindow window)
        {
            this.window             = window;
            window.PointerPressed  += window_PointerPressed;
            window.PointerMoved    += window_PointerMoved;
            window.PointerReleased += window_PointerReleased;

            device           = new CanvasDevice();
            swapChainManager = new SwapChainManager(window, device);

            var effect = new GaussianBlurEffect()
            {
                BlurAmount = 5,
                Source     = inputEffect
            };

            outputEffect = new Transform2DEffect()
            {
                Source = effect
            };

            imageBrush         = new CanvasImageBrush(device);
            imageBrush.Opacity = 0.99f;
        }
Ejemplo n.º 21
0
 internal virtual void tileImage(CanvasBitmap canvasBitmap, int x, int y, int w, int h)
 {
     CanvasImageBrush brush = new CanvasImageBrush(graphics.Device, canvasBitmap);
     brush.ExtendX = CanvasEdgeBehavior.Wrap;
     brush.ExtendY = CanvasEdgeBehavior.Wrap;
     System.Numerics.Matrix3x2 currentTransform = graphics.Transform;
     graphics.Transform = System.Numerics.Matrix3x2.CreateTranslation(x, y);
     graphics.FillRectangle(0, 0, w, h, brush);
     graphics.Transform = currentTransform;
 }
Ejemplo n.º 22
0
            public OpacityDemo(DrawImageEmulations example, CanvasControl sender)
            {
                fillPattern = example.checkedFillPattern;
                premultipliedSource = CreateSourceImage(sender, CanvasAlphaMode.Premultiplied);
                ignoreSource = CreateSourceImage(sender, CanvasAlphaMode.Ignore);

                premultipliedTarget = new CanvasRenderTarget[2]
                {
                    CreateTarget(sender, CanvasAlphaMode.Premultiplied),
                    CreateTarget(sender, CanvasAlphaMode.Premultiplied)
                };

                ignoreTarget = new CanvasRenderTarget[2]
                {
                    CreateTarget(sender, CanvasAlphaMode.Ignore),
                    CreateTarget(sender, CanvasAlphaMode.Ignore)
                };
            }
Ejemplo n.º 23
0
 public DestRectDemo(DrawImageEmulations example, CanvasControl sender)
 {
     fillPattern = example.checkedFillPattern;
     sourceBitmap = example.tiger;
     sourceEffect = new HueRotationEffect()
     {
         Source = sourceBitmap,
         Angle = 1
     };
 }
Ejemplo n.º 24
0
            public OffsetDemo(DrawImageEmulations example, CanvasControl sender)
            {
                fillPattern = example.checkedFillPattern;

                var rt = new CanvasRenderTarget(sender, (float)example.tiger.Size.Width, (float)example.tiger.Size.Height, sender.Dpi / 3);
                using (var ds = rt.CreateDrawingSession())
                {
                    ds.DrawImage(example.tiger, rt.Bounds);
                }
                sourceBitmap = rt;

                sourceEffect = new HueRotationEffect()
                {
                    Source = sourceBitmap,
                    Angle = 1
                };

                showSourceRectRT = new CanvasRenderTarget(sender, (float)rt.Size.Width, (float)rt.Size.Height, rt.Dpi);
            }
Ejemplo n.º 25
0
        private void canvasControl_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            modeInstance = null;

            args.TrackAsyncAction(canvasControl_CreateResourcesAsync(sender).AsAsyncAction());

            var checks = CanvasBitmap.CreateFromColors(sender, new Color[] { Colors.Gray, Colors.Black, Colors.Black, Colors.Gray }, 2, 2);
            checkedFillPattern = new CanvasImageBrush(sender, checks)
            {
                ExtendX = CanvasEdgeBehavior.Wrap,
                ExtendY = CanvasEdgeBehavior.Wrap,
                Transform = Matrix3x2.CreateScale(16),
                Interpolation = CanvasImageInterpolation.NearestNeighbor
            };
        }
Ejemplo n.º 26
0
 void m_canvasControl_CreateResources(CanvasControl sender, object args)
 {
     UpdateCanvasControlSize();
     m_imageBrush = new CanvasImageBrush(sender);
 }
Ejemplo n.º 27
0
        //Load first live tile data
        async Task <bool> LoadTileDataFirst()
        {
            try
            {
                Debug.WriteLine("Loading data for the first live tile.");

                //Check if the location name is too long
                BgStatusWeatherCurrentLocation = AVFunctions.StringCut(BgStatusWeatherCurrentLocation, 25, String.Empty);

                //Load and set empty time tile texts
                TextPositionSet(Setting_TextPositions.NoInformation, String.Empty);

                //Load and set current battery text
                if (TextPositionUsed(Setting_TextPositions.Battery))
                {
                    if (!String.IsNullOrEmpty(BatteryLevel) && BatteryLevel != "error")
                    {
                        TextBatteryLevel  = "🗲 " + BatteryLevel + "%";
                        WordsBatteryLevel = BatteryLevel + " percent battery left";
                    }
                    else
                    {
                        TextBatteryLevel  = "🗲 Unknown";
                        WordsBatteryLevel = "unknown battery level";
                    }

                    TextPositionSet(Setting_TextPositions.Battery, TextBatteryLevel);
                }

                //Load and set countdown event
                if (TextPositionUsed(Setting_TextPositions.Countdown))
                {
                    if (!String.IsNullOrEmpty(CountdownEventName) && !String.IsNullOrEmpty(CountdownEventDate))
                    {
                        TextCountdownEvent = CountdownEventName + " (" + AVFunctions.ToTitleCase(CountdownEventDate) + "d)";
                    }
                    else
                    {
                        TextCountdownEvent = "No countdown event";
                    }

                    TextPositionSet(Setting_TextPositions.Countdown, TextCountdownEvent);
                }

                //Load and set calendar event
                if (TextPositionUsed(Setting_TextPositions.CalendarName) || TextPositionUsed(Setting_TextPositions.CalendarDateTime))
                {
                    if (!String.IsNullOrEmpty(CalendarAppoName))
                    {
                        TextPositionSet(Setting_TextPositions.CalendarName, CalendarAppoName);
                    }
                    else
                    {
                        TextPositionSet(Setting_TextPositions.CalendarName, "No calendar event");
                    }

                    if (!String.IsNullOrEmpty(CalendarAppoEstimated))
                    {
                        TextPositionSet(Setting_TextPositions.CalendarDateTime, CalendarAppoEstimated);
                    }
                    else if (!String.IsNullOrEmpty(CalendarAppoDateTime))
                    {
                        TextPositionSet(Setting_TextPositions.CalendarDateTime, CalendarAppoDateTime);
                    }
                    else
                    {
                        TextPositionSet(Setting_TextPositions.CalendarDateTime, "No calendar date");
                    }
                }

                //Load and set current week number
                if (TextPositionUsed(Setting_TextPositions.WeekNumber) || setDisplayDateWeekNumber || setLiveTileSizeName == "WideWords")
                {
                    TextWeekNumber  = "W" + WeekNumberCurrent;
                    WordsWeekNumber = "week number " + WeekNumberCurrent;

                    TextPositionSet(Setting_TextPositions.WeekNumber, "Week " + WeekNumberCurrent);
                }

                //Check for active alarms and timers
                if (setDisplayAlarm && TimerAlarmActive)
                {
                    TextAlarmClock  = "⏰";
                    WordsAlarmClock = "the timer alarm is on";
                }

                //Set weather tile texts
                if ((TextPositionUsed(Setting_TextPositions.WeatherFull) || TextPositionUsed(Setting_TextPositions.WeatherInfo) || TextPositionUsed(Setting_TextPositions.WeatherTempTextDegrees) || TextPositionUsed(Setting_TextPositions.WeatherTempTextSymbol) || TextPositionUsed(Setting_TextPositions.WeatherTempAsciiIcon)) && setBackgroundDownload && setDownloadWeather)
                {
                    if (TextPositionUsed(Setting_TextPositions.WeatherFull))
                    {
                        TextPositionSet(Setting_TextPositions.WeatherFull, BgStatusWeatherCurrent);
                    }
                    if (TextPositionUsed(Setting_TextPositions.WeatherInfo))
                    {
                        TextPositionSet(Setting_TextPositions.WeatherInfo, BgStatusWeatherCurrentText);
                    }
                    if (TextPositionUsed(Setting_TextPositions.WeatherTempTextSymbol))
                    {
                        TextPositionSet(Setting_TextPositions.WeatherTempTextSymbol, BgStatusWeatherCurrentTemp);
                    }
                    if (TextPositionUsed(Setting_TextPositions.WeatherTempAsciiIcon))
                    {
                        TextPositionSet(Setting_TextPositions.WeatherTempAsciiIcon, "☼ " + BgStatusWeatherCurrentTemp);
                    }
                    if (TextPositionUsed(Setting_TextPositions.WeatherTempTextDegrees))
                    {
                        if (BgStatusWeatherCurrentTemp.Contains("!"))
                        {
                            TextPositionSet(Setting_TextPositions.WeatherTempTextDegrees, BgStatusWeatherCurrentTemp.Replace("°", "").Replace("!", "") + " degrees!");
                        }
                        else
                        {
                            TextPositionSet(Setting_TextPositions.WeatherTempTextDegrees, BgStatusWeatherCurrentTemp.Replace("°", "") + " degrees");
                        }
                    }
                }

                //Set wind speed and direction tile texts
                if (TextPositionUsed(Setting_TextPositions.WindSpeed) && setBackgroundDownload && setDownloadWeather)
                {
                    TextPositionSet(Setting_TextPositions.WindSpeed, "≋ " + BgStatusWeatherCurrentWindSpeed);
                }

                //Set rain chance tile texts
                if (TextPositionUsed(Setting_TextPositions.RainChance) && setBackgroundDownload && setDownloadWeather)
                {
                    TextPositionSet(Setting_TextPositions.RainChance, "☂ " + BgStatusWeatherCurrentRainChance);
                }

                //Set location tile texts
                if (TextPositionUsed(Setting_TextPositions.Location) && setBackgroundDownload && setDownloadWeather)
                {
                    TextPositionSet(Setting_TextPositions.Location, BgStatusWeatherCurrentLocation);
                }

                //Load light Live Tile Resources
                if (setLiveTileSizeLight)
                {
                    //Set light live tiles icons style
                    TileLight_TileIcon = "ms-appx:///Assets/WeatherSquare" + WeatherIconStyle + "/" + WeatherIconCurrent + ".png";

                    //Load live tile background photo or color
                    if (setLiveTileSizeName == "MediumRoundImage")
                    {
                        if (await AVFunctions.LocalFileExists("TimeMeTilePhoto.png"))
                        {
                            TileLight_BackgroundPhotoXml = "ms-appdata:///local/TimeMeTilePhoto.png";
                        }
                        else
                        {
                            TileLight_BackgroundPhotoXml = "ms-appx:///Assets/Tiles/TimeMeTilePhoto.png";
                        }
                    }
                    else if (setDisplayBackgroundPhoto)
                    {
                        if (await AVFunctions.LocalFileExists("TimeMeTilePhoto.png"))
                        {
                            TileLight_BackgroundPhotoXml = "<image src=\"ms-appdata:///local/TimeMeTilePhoto.png\" placement=\"background\" hint-overlay=\"" + setDisplayBackgroundBrightnessInt + "\"/>";
                        }
                        else
                        {
                            TileLight_BackgroundPhotoXml = "<image src=\"ms-appx:///Assets/Tiles/TimeMeTilePhoto.png\" placement=\"background\" hint-overlay=\"" + setDisplayBackgroundBrightnessInt + "\"/>";
                        }
                    }
                    else if (setDisplayBackgroundColor)
                    {
                        if (await AVFunctions.LocalFileExists("TimeMeTileColor.png"))
                        {
                            TileLight_BackgroundPhotoXml = "<image src=\"ms-appdata:///local/TimeMeTileColor.png\" placement=\"background\" hint-overlay=\"0\"/>";
                        }
                        else
                        {
                            TileLight_BackgroundPhotoXml = "<image src=\"ms-appx:///Assets/Tiles/TimeMeTileColor.png\" placement=\"background\" hint-overlay=\"0\"/>";
                        }
                    }
                }
                //Load heavy Live Tile Resources
                else
                {
                    Debug.WriteLine("Loading live tile image and font resources.");
                    //Set current weather and battery for words back tile
                    if (setLiveTileSizeName == "WideWords")
                    {
                        if (setBackgroundDownload && setDownloadWeather)
                        {
                            //Enable Tile Background Render
                            TileLive_BackRender = true;

                            //Set Weather Degrees text
                            if (BgStatusWeatherCurrentTemp.Contains("!"))
                            {
                                WordsWeatherDegree = BgStatusWeatherCurrentTemp.Replace("°", "").Replace("!", "").Replace("-", "min ") + " degrees outside!";
                            }
                            else
                            {
                                WordsWeatherDegree = BgStatusWeatherCurrentTemp.Replace("°", "").Replace("-", "min ") + " degrees outside";
                            }

                            //Set Weather Description Text
                            if (BgStatusWeatherCurrentText.Length > 10)
                            {
                                if (BgStatusWeatherCurrentText.Length >= 13)
                                {
                                    WordsWeatherInfo = BgStatusWeatherCurrentText.ToLower();
                                }
                                else
                                {
                                    WordsWeatherInfo = BgStatusWeatherCurrentText.ToLower() + " out";
                                }
                            }
                            else
                            {
                                WordsWeatherInfo = BgStatusWeatherCurrentText.ToLower() + " outside";
                            }

                            //Set Weather Location Text
                            WordsWeatherLocation = BgStatusWeatherCurrentLocation;
                            if (WordsWeatherLocation.Length < 7)
                            {
                                WordsWeatherLocation = "near town " + WordsWeatherLocation;
                            }
                            else if (WordsWeatherLocation.Length < 15)
                            {
                                WordsWeatherLocation = "near " + WordsWeatherLocation;
                            }

                            //Check for empty strings on the back tile
                            if (String.IsNullOrEmpty(WordsBatteryLevel))
                            {
                                WordsBatteryLevel = WordsWeatherLocation;
                            }
                            if (String.IsNullOrEmpty(WordsAlarmClock))
                            {
                                WordsAlarmClock = WordsWeekNumber;
                            }
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(WordsAlarmClock))
                            {
                                WordsAlarmClock = WordsWeekNumber;
                            }
                            if (String.IsNullOrEmpty(WordsWeatherDegree))
                            {
                                if (!String.IsNullOrEmpty(WordsAlarmClock))
                                {
                                    WordsWeatherDegree = WordsAlarmClock;
                                }
                                else
                                {
                                    WordsWeatherDegree = WordsBatteryLevel;
                                }
                            }
                        }
                    }

                    //Load live tile dimensions
                    if (setLiveTileSizeName.Contains("Medium"))
                    {
                        //Set Medium Tile Sizes
                        if (setShowMoreTiles)
                        {
                            LiveTileWidth          = 230;
                            LiveTileHeight         = 230;
                            LiveTileWidthResize    = 409;
                            LiveTileHeightResize   = 230;
                            LiveTileWidthCropping  = 89;
                            LiveTileHeightCropping = 0;

                            LiveTilePadding         = 14;
                            BottomTextHeight1       = -106;
                            BottomTextHeight2       = -74;
                            BottomTextHeight3       = -42;
                            BottomTextHeight4       = -10; //Bottom32
                            BottomTextCenterHeight1 = BottomTextHeight1 - 2;
                            BottomTextCenterHeight2 = BottomTextHeight2 - 2;
                            BottomTextCenterHeight3 = BottomTextHeight3 - 2;
                            BottomTextCenterHeight4 = BottomTextHeight4 - 2;
                        }
                        else
                        {
                            LiveTileWidth          = 336;
                            LiveTileHeight         = 336;
                            LiveTileWidthResize    = 597;
                            LiveTileHeightResize   = 336;
                            LiveTileWidthCropping  = 130;
                            LiveTileHeightCropping = 0;

                            LiveTilePadding         = 18;
                            BottomTextHeight1       = -147;
                            BottomTextHeight2       = -102;
                            BottomTextHeight3       = -57;
                            BottomTextHeight4       = -12; //Bottom45
                            BottomTextCenterHeight1 = BottomTextHeight1 - 2;
                            BottomTextCenterHeight2 = BottomTextHeight2 - 2;
                            BottomTextCenterHeight3 = BottomTextHeight3 - 2;
                            BottomTextCenterHeight4 = BottomTextHeight4 - 2;
                        }
                    }
                    else
                    {
                        //Set Wide Tile Sizes
                        if (setShowMoreTiles)
                        {
                            LiveTileWidth          = 480;
                            LiveTileHeight         = 235;
                            LiveTileWidthResize    = 480;
                            LiveTileHeightResize   = 270;
                            LiveTileWidthCropping  = 0;
                            LiveTileHeightCropping = 17;

                            LiveTilePadding         = 14;
                            BottomTextHeight1       = -106;
                            BottomTextHeight2       = -74;
                            BottomTextHeight3       = -42;
                            BottomTextHeight4       = -10; //Bottom32
                            BottomTextCenterHeight1 = BottomTextHeight1 - 2;
                            BottomTextCenterHeight2 = BottomTextHeight2 - 2;
                            BottomTextCenterHeight3 = BottomTextHeight3 - 2;
                            BottomTextCenterHeight4 = BottomTextHeight4 - 2;
                        }
                        else
                        {
                            LiveTileWidth          = 510;
                            LiveTileHeight         = 250;
                            LiveTileWidthResize    = 510;
                            LiveTileHeightResize   = 287;
                            LiveTileWidthCropping  = 0;
                            LiveTileHeightCropping = 17;

                            LiveTilePadding         = 16;
                            BottomTextHeight1       = -112;
                            BottomTextHeight2       = -78;
                            BottomTextHeight3       = -44;
                            BottomTextHeight4       = -10; //Bottom34
                            BottomTextCenterHeight1 = BottomTextHeight1 - 2;
                            BottomTextCenterHeight2 = BottomTextHeight2 - 2;
                            BottomTextCenterHeight3 = BottomTextHeight3 - 2;
                            BottomTextCenterHeight4 = BottomTextHeight4 - 2;
                        }
                    }

                    //Load and set Win2D settings
                    Win2DCanvasDevice       = new CanvasDevice();
                    Win2DCanvasRenderTarget = new CanvasRenderTarget(Win2DCanvasDevice, LiveTileWidth, LiveTileHeight, 96); //96Wide-90Wide / 96Med-66Med

                    //Load live tile font colors
                    Win2DFontColorCusto = Color.FromArgb(Convert.ToByte(setLiveTileColorFont.Substring(1, 2), 16), Convert.ToByte(setLiveTileColorFont.Substring(3, 2), 16), Convert.ToByte(setLiveTileColorFont.Substring(5, 2), 16), Convert.ToByte(setLiveTileColorFont.Substring(7, 2), 16));
                    Win2DFontColorTrans = Color.FromArgb(Convert.ToByte(140), Convert.ToByte(setLiveTileColorFont.Substring(3, 2), 16), Convert.ToByte(setLiveTileColorFont.Substring(5, 2), 16), Convert.ToByte(setLiveTileColorFont.Substring(7, 2), 16));
                    Win2DFontColorWhite = Color.FromArgb(Convert.ToByte(255), Convert.ToByte(255), Convert.ToByte(255), Convert.ToByte(255));

                    //Load live tile font weights
                    Win2DFontWeightText = FontWeights.Normal;
                    switch (setLiveTileFontWeight)
                    {
                    case 0: { Win2DFontWeightTitle = FontWeights.Light; Win2DFontWeightBody = FontWeights.Light; Win2DFontWeightSub = FontWeights.Light; break; }

                    case 1: { Win2DFontWeightTitle = FontWeights.Normal; Win2DFontWeightBody = FontWeights.Normal; Win2DFontWeightSub = FontWeights.Normal; break; }

                    case 2: { Win2DFontWeightTitle = FontWeights.SemiBold; Win2DFontWeightBody = FontWeights.SemiBold; Win2DFontWeightSub = FontWeights.SemiBold; break; }
                    }
                    if (setDisplayHourBold)
                    {
                        switch (setLiveTileFontWeight)
                        {
                        case 0: { Win2DFontWeightTitle = FontWeights.Normal; break; }

                        case 1: { Win2DFontWeightTitle = FontWeights.SemiBold; break; }

                        case 2: { Win2DFontWeightTitle = FontWeights.Bold; break; }
                        }
                    }

                    //Load live tile background
                    if (setDisplayBackgroundPhoto)
                    {
                        if (await AVFunctions.LocalFileExists("TimeMeTilePhoto.png"))
                        {
                            StorageFile StorageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("TimeMeTilePhoto.png");

                            using (IRandomAccessStream OpenAsync = await StorageFile.OpenAsync(FileAccessMode.Read))
                            {
                                using (InMemoryRandomAccessStream InMemoryRandomAccessStream = new InMemoryRandomAccessStream())
                                {
                                    BitmapEncoder BitmapEncoder = await BitmapEncoder.CreateForTranscodingAsync(InMemoryRandomAccessStream, await BitmapDecoder.CreateAsync(OpenAsync));

                                    OpenAsync.Dispose();

                                    //Resize original image 1:1
                                    BitmapEncoder.BitmapTransform.ScaledWidth  = (uint)LiveTileWidthResize;
                                    BitmapEncoder.BitmapTransform.ScaledHeight = (uint)LiveTileHeightResize;

                                    //Crop image to tile size
                                    BitmapBounds BitmapBounds = new BitmapBounds();
                                    BitmapBounds.Width  = (uint)LiveTileWidth;
                                    BitmapBounds.Height = (uint)LiveTileHeight;
                                    BitmapBounds.X      = (uint)LiveTileWidthCropping;
                                    BitmapBounds.Y      = (uint)LiveTileHeightCropping;
                                    BitmapEncoder.BitmapTransform.Bounds = BitmapBounds;

                                    await BitmapEncoder.FlushAsync();

                                    await InMemoryRandomAccessStream.FlushAsync();

                                    Win2DCanvasBitmap = await CanvasBitmap.LoadAsync(Win2DCanvasDevice, InMemoryRandomAccessStream);
                                }
                            }
                        }
                        else
                        {
                            Win2DCanvasBitmap = await CanvasBitmap.LoadAsync(Win2DCanvasDevice, new Uri("ms-appx:///Assets/Tiles/TimeMeTilePhoto.png", UriKind.Absolute));
                        }
                        if (setLiveTileTimeCutOut)
                        {
                            Win2DCanvasImageBrush = new CanvasImageBrush(Win2DCanvasDevice, Win2DCanvasBitmap)
                            {
                                Opacity = setDisplayBackgroundBrightnessFloat
                            };
                        }
                    }
                    else if (setDisplayBackgroundColor || setLiveTileTimeCutOut)
                    {
                        Win2DCanvasColor = Color.FromArgb(Convert.ToByte(setLiveTileColorBackground.Substring(1, 2), 16), Convert.ToByte(setLiveTileColorBackground.Substring(3, 2), 16), Convert.ToByte(setLiveTileColorBackground.Substring(5, 2), 16), Convert.ToByte(setLiveTileColorBackground.Substring(7, 2), 16));
                    }
                    else
                    {
                        Win2DCanvasColor = Colors.Transparent;
                    }
                }
                return(true);
            }
            catch { return(false); }
        }
        protected ICanvasBrush GetBackgroundBrush(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args, CanvasImageBrush item, TimeSpan ellapsed)
        {
            var b = Bounds; //TransformBounds(Bounds);


            var ib = item.SourceRectangle ?? item.Image.GetBounds(sender);

            var scale = b.Width / ib.Width;

            if (ib.Height * scale < b.Height)
            {
                scale = b.Height / ib.Height;
            }

            ib.Height *= scale;
            ib.Width  *= scale;

            var offset = new Vector2((float)(b.Width - ib.Width), (float)(b.Height - ib.Height)) / 2f;


            var transform = Matrix3x2.CreateScale((float)scale);  // * Matrix3x2.CreateScale((float) (1f/scale));

            transform.Translation = new Vector2((float)b.X + offset.X, (float)b.Y + offset.Y);
            item.Transform        = transform;
            return(item);
        }
Ejemplo n.º 29
0
 void m_canvasControl_CreateResources(CanvasControl sender, object args)
 {
     UpdateCanvasControlSize();
     m_imageBrush = new CanvasImageBrush(sender);
 }
Ejemplo n.º 30
0
        void Canvas_CreateResources(CanvasControl sender, object args)
        {
            mainDeviceResources = new PerDeviceResources(sender);

            imageBrush = new CanvasImageBrush(sender);

            imageSource = new CanvasImageSource(sender, controlSize, controlSize);
            imageControl.Source = imageSource;

            swapChain = new CanvasSwapChain(sender, controlSize, controlSize);
            swapChainPanel.SwapChain = swapChain;
        }
        void CreateBrushes(CanvasAnimatedControl sender, CanvasBitmap bitmapTiger)
        {
            var bitmapSize = bitmapTiger.Size;
            var scale = (radius * 2) / (float)bitmapSize.Height;

            var backgroundEffect = new Transform2DEffect()
            {
                Source = bitmapTiger,
                TransformMatrix = Matrix3x2.CreateScale(scale, scale) * Matrix3x2.CreateTranslation(center - radius, center - radius)
            };

            backgroundBrush = new CanvasImageBrush(sender, backgroundEffect)
            {
                SourceRectangle = new Rect(0, 0, size, size),
                Opacity = 0.6f
            };

            hueRotationEffect = new HueRotationEffect()
            {
                Source = backgroundEffect,
                Angle = (float)Math.PI * 0.5f
            };

            var foregroundEffect = new GaussianBlurEffect()
            {
                Source = hueRotationEffect,
                BlurAmount = 10
            };

            foregroundBrush = new CanvasImageBrush(sender, foregroundEffect)
            {
                SourceRectangle = new Rect(0, 0, size, size)
            };
        }
Ejemplo n.º 32
0
        async void ConvertBrush(ICanvasResourceCreator resourceCreator, Brush xamBrush, BrushWrapper brushWrapper)
        {
            if (xamBrush == null)
            {
                brushWrapper.Brush = null;
            }

            else if (xamBrush is SolidColorBrush)
            {
                brushWrapper.Brush = new CanvasSolidColorBrush(resourceCreator, ConvertColor((xamBrush as SolidColorBrush).Color));
            }
            else if (xamBrush is LinearGradientBrush)
            {
                LinearGradientBrush  xamGradient   = xamBrush as LinearGradientBrush;
                CanvasGradientStop[] gradientStops = new CanvasGradientStop[xamGradient.GradientStops.Count];

                for (int i = 0; i < xamGradient.GradientStops.Count; i++)
                {
                    gradientStops[i] = new CanvasGradientStop
                    {
                        Position = (float)xamGradient.GradientStops[i].Offset,
                        Color    = ConvertColor(xamGradient.GradientStops[i].Color)
                    };
                }

                // enumeration values of 0, 1, 2 translated to 0, 2, 1
                CanvasEdgeBehavior edgeBehavior = (CanvasEdgeBehavior)((3 - (int)xamGradient.SpreadMethod) % 3);

                CanvasLinearGradientBrush winGradient = new CanvasLinearGradientBrush(resourceCreator,
                                                                                      gradientStops,
                                                                                      edgeBehavior,
                                                                                      CanvasAlphaMode.Straight);

                // TODO: Opacity and Transform

                brushWrapper.Brush      = winGradient;
                brushWrapper.StartPoint = ConvertPoint(xamGradient.StartPoint);
                brushWrapper.EndPoint   = ConvertPoint(xamGradient.EndPoint);
            }
            else if (xamBrush is ImageBrush)
            {
                ImageBrush xamImageBrush = (ImageBrush)xamBrush;

                CanvasImageBrush imageBrush = new CanvasImageBrush(resourceCreator);
                imageBrush.ExtendX  = CanvasEdgeBehavior.Wrap;
                imageBrush.ExtendY  = CanvasEdgeBehavior.Wrap;
                brushWrapper.Brush  = imageBrush;
                brushWrapper.Bitmap = null;

                // TODO: Perhaps a few try and catch blocks would be appropriate here. You know. Just in case.

                if (xamImageBrush.ImageSource != null)
                {
                    CanvasBitmap bitmap = null;

                    if (xamImageBrush.ImageSource is UriImageSource)
                    {
                        bitmap = await CanvasBitmap.LoadAsync(resourceCreator, ((UriImageSource)xamImageBrush.ImageSource).Uri.ToString());
                    }
                    else if (xamImageBrush.ImageSource is StreamImageSource)
                    {
                        StreamImageSource streamSource = (StreamImageSource)xamImageBrush.ImageSource;
                        var func = ((StreamImageSource)xamImageBrush.ImageSource).Stream;

                        Task <Stream> task = func(new CancellationToken());

                        // TODO: Is this OK if it's not awaited?
                        // Otherwise we have a problem because the resourceCreator must be valid in the next step
                        Stream stream = task.Result;

                        bitmap = await CanvasBitmap.LoadAsync(resourceCreator, stream.AsRandomAccessStream());
                    }
                    else if (xamImageBrush.ImageSource is FileImageSource)
                    {
                        FileImageSource fileSource = (FileImageSource)xamImageBrush.ImageSource;
                        bitmap = await CanvasBitmap.LoadAsync(resourceCreator, fileSource.File);
                    }

                    brushWrapper.Bitmap = bitmap;
                    CanvasControl.Invalidate();
                }
            }
        }
Ejemplo n.º 33
0
        public void Loadd2()
        {
            var MAIN = new Transform2DEffect {
                Source = Shape,
            };

            //直接读CanvasRenderTarget又不行(0x88990025) sessionblend.Mutiply也没有
            //blendcopy要读底图颜色不过UpdateCanvas太慢了 已经写不出橡皮擦了
            ICanvasImage ccc()
            {
                if (Texture == null)
                {
                    return(MAIN);
                }
                return(new ArithmeticCompositeEffect {
                    Source1 = MAIN,
                    Source2 = new TileEffect {
                        Source = Texture,
                        SourceRectangle = new Rect(0, 0, Texture.Size.Width, Texture.Size.Height)
                    },
                    MultiplyAmount = 1,
                    Source1Amount = 0,
                    Source2Amount = 0,
                });
            }

            var ECAN = new TileEffect {
                Source = new GaussianBlurEffect {
                    Source = Canvas,
                }
            };
            var ERAS = new CompositeEffect {
                Sources =
                {
                    new ArithmeticCompositeEffect            {
                        Source1 = new ArithmeticCompositeEffect{
                            MultiplyAmount = 0,
                            Source1        = new CompositeEffect {
                                Sources =
                                {
                                    new PremultiplyEffect    {
                                        Source = new ColorSourceEffect{
                                            Color = color
                                        }
                                    },
                                    new LinearTransferEffect {
                                        Source = ECAN, AlphaSlope = blend
                                    }
                                }
                            },
                            Source1Amount = 1 - dilution,
                            Source2       = ECAN,
                            Source2Amount = dilution,
                        },
                        Source2 = new InvertEffect           {
                            Source = new LuminanceToAlphaEffect{
                                Source = ccc()
                            }
                        },
                        MultiplyAmount = 1,
                        Source1Amount  = 0,
                        Source2Amount  = 0,
                    },
                    new CompositeEffect                      {
                        Sources =
                        {
                            Canvas,
                            new LuminanceToAlphaEffect       {
                                Source = ccc(),
                            },
                        },
                        Mode = CanvasComposite.DestinationOut
                    }
                },
                Mode = CanvasComposite.Add
            };
            var brush = new CanvasImageBrush(device)
            {
                Image           = ERAS,
                SourceRectangle = new Rect(new Point(0, 0), Canvas.Size)
            };

            dynamicbrush = (p, v, size) => {
                checkRandom(out Matrix3x2 x, ref p, ref v, ref size);
                ECAN.SourceRectangle = new Rect(p.X + v.X * size, p.Y + v.Y * size, 1, 1);
                MAIN.TransformMatrix = x;
                UpdateCanvas();
                // session.Blend = CanvasBlend.Copy;
                // session.FillCircle(p, size*2, brush);
                session.DrawImage(ERAS, CanvasComposite.Copy);
            };
        }
Ejemplo n.º 34
0
	    private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
	    {
			// blobs
			_blobs = new List<Blob>();
			var rnd = new Random();
		    for (int i = 0; i < BlobCount; i++)
		    {
			    _blobs.Add(new Blob
			    {
				    Position = new Vector2((float) (rnd.NextDouble()*sender.Size.Width), (float) (rnd.NextDouble()*sender.Size.Height)),
				    Velocity = new Vector2(BlobVelocityScale *  (float) ((rnd.NextDouble()*3.0f) - 1.5f), BlobVelocityScale * (float) ((rnd.NextDouble()*3.0f) - 1.5f))
			    });
		    }
			// texture
		    var rgb = new CanvasRadialGradientBrush(sender, new[]
		    {
				new CanvasGradientStop
				{
					Color = Color.FromArgb(255, 128, 128, 255),
					Position = 0.0f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(128, 128, 128, 255),
					Position = 0.6f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(0, 128, 128, 255),
					Position = 1.0f
				}
		    });
		    rgb.RadiusX = rgb.RadiusY = BlobSize;
		    _blobBrush = rgb;
			// table transfer table
			ttt = new List<float>();
			for (int i = 0; i < 100; i++)
			{
				ttt.Add(i < Threshold ? 0.0f : 1.0f);
			}
			// setup
			_blobRenderTarget = new CanvasRenderTarget(sender, sender.Size);
			_pre = new PremultiplyEffect {Source = _blobRenderTarget};
			_tte = new TableTransferEffect {ClampOutput = true, Source = _pre};
			_tte.AlphaTable = _tte.RedTable = _tte.GreenTable = _tte.BlueTable = ttt.ToArray();
			_un = new UnPremultiplyEffect {Source = _tte};
			_gbe = new GaussianBlurEffect {BlurAmount = 8.0f, Source = _un};
		    _mask = new CanvasImageBrush(sender) {SourceRectangle = new Rect(new Point(), sender.Size)};
	    }
Ejemplo n.º 35
0
		private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
		{
			//guides
			_center = new Vector2((float)(sender.Size.Width / 2.0), (float)(sender.Size.Height / 2.0f));
			_size = (float) Math.Min(sender.Size.Height, sender.Size.Width);
			_half = _size / 2.0f;
			_ringCount = Convert.ToInt32(Math.Floor((_half - (StartOffset + EndOffset))/(RingPadding + RingStrokeWidth)));
			var nudge = _size * 0.174f;

			//mask
			var crt = new CanvasRenderTarget(sender, _size, _size, sender.Dpi);
			using (var session = crt.CreateDrawingSession())
			{
				session.Clear(new Vector4(0, 0, 0, 0));
				var pa = new CanvasGradientMeshPatch[4];
				pa[0] = CanvasGradientMesh.CreateCoonsPatch(
					new[]
					{
						new Vector2(_half, 0.0f), //center top
						new Vector2(_half, 0.0f), //center top
						new Vector2(_size, 0.0f), //right top
						new Vector2(_size, _half), //right middle
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_size, _half), //right middle
						new Vector2(_size, _size), //right bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(-nudge, _size), //left bottom (nudged left)
						new Vector2(-nudge, 0.0f), //left top (nudged left)
					},
					new[]
					{
						new Vector4(1, 1, 1, 1), new Vector4(1, 1, 1, 1),
						new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0),
					},
					new[]
					{
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased,
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased
					});

				var gm = new CanvasGradientMesh(session, pa);
				session.DrawGradientMesh(gm);
			}
			var ib = new CanvasImageBrush(sender, crt);
			_brush = ib;

			//animation pattern
			_pattern = new List<double>();
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < _ringCount; j++)
				{
					_pattern.Add(0.0);
				}
			}
			for (int i = 0; i < _ringCount; i++)
			{
				_pattern.Add((1.0/_ringCount)*(i + 1));
			}
			for (int i = _ringCount - 1; i > 0; i--)
			{
				_pattern.Add((1.0 / _ringCount) * (i));
			}
			for (int j = 0; j < _ringCount; j++)
			{
				_pattern.Add(0.0);
			}
		}
Ejemplo n.º 36
0
        void Canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(LoadCanvasResources(sender).AsAsyncAction());

            imageBrush = new CanvasImageBrush(sender);

            imageSource = new CanvasImageSource(sender, controlSize, controlSize);
            imageControl.Source = imageSource;

            virtualImageSource = new CanvasVirtualImageSource(sender, controlSize, controlSize);
            virtualImageControl.Source = virtualImageSource.Source;

            swapChain = new CanvasSwapChain(sender, controlSize, controlSize);
            swapChainPanel.SwapChain = swapChain;
        }