コード例 #1
0
        private void Initialize(StreamingContext context)
        {
            _type        = LayerType.Image;
            _brush       = Window.Current.Compositor.CreateSurfaceBrush();
            _nineGrid    = Window.Current.Compositor.CreateNineGridBrush();
            _inputEffect = new BorderEffect()
            {
                Name   = _id,
                Source = new CompositionEffectSourceParameter(_id + "Image"),
            };

            _properties = new List <LayerProperty>();
            _properties.Add(new LayerProperty("Offset", _brush));
            _properties.Add(new LayerProperty("Scale", _brush));
            _properties.Add(new LayerProperty("RotationAngleInDegrees", _brush));
            _properties.Add(new LayerProperty("AnchorPoint", _brush));
            _properties.Add(new LayerProperty("Stretch", _brush));
            _properties.Add(new LayerProperty("HorizontalAlignmentRatio", _brush));
            _properties.Add(new LayerProperty("VerticalAlignmentRatio", _brush));
            _properties.Add(new LayerProperty("ExtendX", _inputEffect));
            _properties.Add(new LayerProperty("ExtendY", _inputEffect));
            _properties.Add(new LayerProperty("LeftInset", _nineGrid));
            _properties.Add(new LayerProperty("TopInset", _nineGrid));
            _properties.Add(new LayerProperty("RightInset", _nineGrid));
            _properties.Add(new LayerProperty("BottomInset", _nineGrid));
            _properties.Add(new LayerProperty("LeftInsetScale", _nineGrid));
            _properties.Add(new LayerProperty("TopInsetScale", _nineGrid));
            _properties.Add(new LayerProperty("RightInsetScale", _nineGrid));
            _properties.Add(new LayerProperty("BottomInsetScale", _nineGrid));
            _properties.Add(new LayerProperty("IsCenterHollow", _nineGrid));
        }
コード例 #2
0
        private void FullSwitch(bool isFull)
        {
            if (_isFull == isFull)
            {
                return;
            }

            _isFull = isFull;

            if (_isFull)
            {
                BorderRootEffect.Show();
                BorderEffect.Collapse();
                BorderTitle.Collapse();
                GridMain.HorizontalAlignment = HorizontalAlignment.Stretch;
                GridMain.VerticalAlignment   = VerticalAlignment.Stretch;
                PresenterMain.Margin         = new Thickness();
                BorderRoot.CornerRadius      = new CornerRadius(10);
                BorderRoot.Style             = ResourceHelper.GetResource <Style>("BorderClip");
            }
            else
            {
                BorderRootEffect.Collapse();
                BorderEffect.Show();
                BorderTitle.Show();
                GridMain.HorizontalAlignment = HorizontalAlignment.Center;
                GridMain.VerticalAlignment   = VerticalAlignment.Center;
                PresenterMain.Margin         = new Thickness(0, 0, 0, 10);
                BorderRoot.CornerRadius      = new CornerRadius();
                BorderRoot.Style             = null;
            }
        }
コード例 #3
0
 private void FullSwitch(bool isFull)
 {
     if (_isFull == isFull)
     {
         return;
     }
     _isFull = isFull;
     if (_isFull)
     {
         BorderEffect.Collapse();
         BorderTitle.Collapse();
         GridMain.HorizontalAlignment = HorizontalAlignment.Stretch;
         GridMain.VerticalAlignment   = VerticalAlignment.Stretch;
         GridMain.Margin      = new Thickness();
         PresenterMain.Margin = new Thickness();
     }
     else
     {
         BorderEffect.Show();
         BorderTitle.Show();
         GridMain.HorizontalAlignment = HorizontalAlignment.Center;
         GridMain.VerticalAlignment   = VerticalAlignment.Center;
         GridMain.Margin      = new Thickness(16);
         PresenterMain.Margin = new Thickness(0, 0, 0, 10);
     }
 }
コード例 #4
0
 public static PDFName PDFBorderEffectToPDFName(BorderEffect effect)
 {
     if (effect == BorderEffect.Cloudy)
     {
         return(new PDFName("C"));
     }
     return(new PDFName("S"));
 }
コード例 #5
0
 private void Initialize(StreamingContext context)
 {
     _type        = LayerType.Backdrop;
     _inputEffect = new BorderEffect()
     {
         Name   = _id,
         Source = new CompositionEffectSourceParameter(_id + "Image"),
     };
 }
コード例 #6
0
        private void EnsureEffectFactory()
        {
            if (s_effectFactory == null)
            {
                var effectDescription = new BorderEffect
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    Source  = new CompositionEffectSourceParameter("source")
                };

                s_effectFactory = _compositor.CreateEffectFactory(effectDescription);
            }
        }
コード例 #7
0
 private void CreateEffectBrush()
 {
     using (var effect = new BorderEffect
     {
         Name = nameof(BorderEffect),
         ExtendY = CanvasEdgeBehavior.Wrap,
         ExtendX = CanvasEdgeBehavior.Wrap,
         Source = new CompositionEffectSourceParameter(nameof(BorderEffect.Source))
     })
         using (var _effectFactory = _compositor.CreateEffectFactory(effect))
         {
             this.CompositionBrush = _effectFactory.CreateBrush();
         }
 }
コード例 #8
0
        async Task ShowBitmapOnTargetAsync(CanvasBitmap bitmap)
        {
            int scale = (int)Math.Ceiling(ActualSize.Y / bitmap.Size.Height);

            Height = bitmap.Size.Height / bitmap.Size.Width * ActualSize.X;

            _previousBitmap = bitmap;
            _previousColors = null;

            var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, CanvasDevice.GetSharedDevice());

            if (_patternBitmap is null)
            {
                _patternBitmap = await CanvasBitmap.LoadAsync(CanvasDevice.GetSharedDevice(), @"Assets\BackgroundPattern.png");
            }

            var surface = compositionGraphicsDevice.CreateDrawingSurface(
                new Size(bitmap.Size.Width * scale, bitmap.Size.Height * scale),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            using (var drawingSession = CanvasComposition.CreateDrawingSession(surface))
            {
                var border = new BorderEffect
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    Source  = _patternBitmap,
                };

                var scaleEffect = new ScaleEffect
                {
                    Scale             = new Vector2(scale, scale),
                    InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
                };

                scaleEffect.Source = border;
                drawingSession.DrawImage(scaleEffect);
                scaleEffect.Source = bitmap;
                drawingSession.DrawImage(scaleEffect);
            }

            var surfaceBrush = compositor.CreateSurfaceBrush(surface);

            _spriteVisual.Brush = surfaceBrush;
        }
コード例 #9
0
        private void Initialize(StreamingContext context)
        {
            _type         = LayerType.Lighting;
            _borderEffect = (BorderEffect)_inputEffect;
            _inputEffect  = new SceneLightingEffect()
            {
                AmbientAmount  = .3f,
                DiffuseAmount  = 1,
                SpecularAmount = .2f,
                SpecularShine  = 16,
            };

            _properties.Add(new LayerProperty("AmbientAmount", _inputEffect));
            _properties.Add(new LayerProperty("DiffuseAmount", _inputEffect));
            _properties.Add(new LayerProperty("SpecularAmount", _inputEffect));
            _properties.Add(new LayerProperty("SpecularShine", _inputEffect));
            _properties.Add(new LayerProperty("BrdfType", _inputEffect));
        }
コード例 #10
0
 protected override void OnAttached()
 {
     if (Control != null)
     {
         try
         {
             oldBackgroundColor = Control.Background.ColorFilter;
             Control.Background.SetColorFilter(
                 BorderEffect.GetBorderColor(Element).ToAndroid(),
                 PorterDuff.Mode.SrcIn
                 );
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
コード例 #11
0
        public static async Task <IGraphicsEffect> ConcatenateEffectWithTintAndBorderAsync(
            [NotNull] Compositor compositor,
            [NotNull] IGraphicsEffectSource source, [NotNull] IDictionary <String, CompositionBrush> parameters,
            Color color, float colorMix,
            [CanBeNull] CanvasControl canvas, [NotNull] Uri uri, int timeThreshold = 1000, bool reload = false)
        {
            // Setup the tint effect
            ArithmeticCompositeEffect tint = new ArithmeticCompositeEffect
            {
                MultiplyAmount = 0,
                Source1Amount  = 1 - colorMix,
                Source2Amount  = colorMix, // Mix the background with the desired tint color
                Source1        = source,
                Source2        = new ColorSourceEffect {
                    Color = color
                }
            };

            // Get the noise brush using Win2D
            CompositionSurfaceBrush noiseBitmap = canvas == null
                ? await LoadWin2DSurfaceBrushFromImageAsync(compositor, uri, reload)
                : await LoadWin2DSurfaceBrushFromImageAsync(compositor, canvas, uri, timeThreshold, reload);

            // Make sure the Win2D brush was loaded correctly
            if (noiseBitmap != null)
            {
                // Layer 4 - Noise effect
                BorderEffect borderEffect = new BorderEffect
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    Source  = new CompositionEffectSourceParameter(nameof(noiseBitmap))
                };
                BlendEffect blendEffect = new BlendEffect
                {
                    Background = tint,
                    Foreground = borderEffect,
                    Mode       = BlendEffectMode.Overlay
                };
                parameters.Add(nameof(noiseBitmap), noiseBitmap);
                return(blendEffect);
            }
            return(tint);
        }
コード例 #12
0
ファイル: RevealBrush.cs プロジェクト: cnbluefire/FDSforCU
        protected override void OnConnected()
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }
            compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content as UIElement).Compositor;
            var borderEffect = new BorderEffect()
            {
                Source  = new CompositionEffectSourceParameter("color"),
                ExtendX = CanvasEdgeBehavior.Clamp,
                ExtendY = CanvasEdgeBehavior.Clamp
            };

            var Brush = compositor.CreateEffectFactory(borderEffect).CreateBrush();

            Brush.SetSourceParameter("color", compositor.CreateColorBrush(Color));
            CompositionBrush = Brush;
        }
コード例 #13
0
        // Draw repeating pattern texture on backgound canvas.
        public async Task SetupBackgroundPatternAsync()
        {
            var compositor     = ElementCompositionPreview.GetElementVisual(this).Compositor;
            var canvasDevice   = CanvasDevice.GetSharedDevice();
            var graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice);

            var bitmap = await CanvasBitmap.LoadAsync(canvasDevice, @"Assets\BackgroundPattern.png");

            var drawingSurface = graphicsDevice.CreateDrawingSurface(
                bitmap.Size,
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(drawingSurface))
            {
                ds.Clear(Colors.Transparent);
                ds.DrawImage(bitmap);
            }

            var surfaceBrush = compositor.CreateSurfaceBrush(drawingSurface);

            surfaceBrush.Stretch = CompositionStretch.None;

            var border = new BorderEffect
            {
                ExtendX = CanvasEdgeBehavior.Wrap,
                ExtendY = CanvasEdgeBehavior.Wrap,
                Source  = new CompositionEffectSourceParameter("source"),
            };

            var fxFactory = compositor.CreateEffectFactory(border);
            var fxBrush   = fxFactory.CreateBrush();

            fxBrush.SetSourceParameter("source", surfaceBrush);

            var sprite = compositor.CreateSpriteVisual();

            sprite.Size  = new Vector2(4096);
            sprite.Brush = fxBrush;

            ElementCompositionPreview.SetElementChildVisual(_canvas, sprite);
        }
コード例 #14
0
        private ICanvasImage CreateBorder()
        {
            var borderEffect = new BorderEffect
            {
                Source = bitmapTiger
            };

            // Animation cycles through the different edge behavior modes.
            int enumValueCount = Utils.GetEnumAsList <CanvasEdgeBehavior>().Count;

            animationFunction = elapsedTime =>
            {
                borderEffect.ExtendX     =
                    borderEffect.ExtendY = (CanvasEdgeBehavior)(elapsedTime % enumValueCount);

                textLabel = "Mode: " + borderEffect.ExtendX;
            };

            return(AddSoftEdgedCrop(borderEffect));
        }
コード例 #15
0
 public RichTextBoxStyle(string id, string family, double?size, Brush background, Brush foreground, Brush borderBrush, Brush shadowBrush, FontWeight?weight, FontStyle?style, TextDecorationCollection decorations, HorizontalAlignment alignment, RichTextSpecialFormatting special, TextBlockPlusEffect effect, BorderEffect border, ShadowEffect shadow, Thickness margin, VerticalAlignment verticalAlign)
 {
     ID                = id;
     Family            = family;
     Size              = size;
     Background        = background;
     Foreground        = foreground;
     BorderBrush       = borderBrush;
     ShadowBrush       = shadowBrush;
     Weight            = weight;
     Style             = style;
     Decorations       = decorations;
     Alignment         = alignment;
     Special           = special;
     Effect            = effect;
     BorderType        = border;
     Shadow            = shadow;
     Margin            = margin;
     VerticalAlignment = verticalAlign;
 }
コード例 #16
0
        private async Task OnCreateResourcesAsync(EngineCreateResourcesEventArgs e)
        {
            var grass     = GrassSprite.Resolve(Entity);
            var snow      = SnowSprite.Resolve(Entity);
            var rock      = RockSprite.Resolve(Entity);
            var heightMap = _terrain.HeightMap.Resolve(Entity);

            if (!heightMap.IsPreScaled || !grass.IsPreScaled || !snow.IsPreScaled || !rock.IsPreScaled)
            {
                throw new ArgumentException("The heightmap, grass, snow and rock textures must be prescaled in order to be used for terrain rendering");
            }

            // Calculate average colors (these are used at small zoom levels)
            _grassColor = GetAverageColor(e.Sender, grass.Image);
            _snowColor  = GetAverageColor(e.Sender, snow.Image);
            _rockColor  = GetAverageColor(e.Sender, rock.Image);

            _normalHeightMap = await RenderNormalHeightMapAsync(e.Sender, heightMap.Image, _terrain.Height - _terrain.BaseHeight);

            var wrap       = CanvasEdgeBehavior.Wrap;
            var grassTiled = new BorderEffect {
                Source = grass.Image, ExtendX = wrap, ExtendY = wrap, CacheOutput = true
            };
            var snowTiled = new BorderEffect {
                Source = snow.Image, ExtendX = wrap, ExtendY = wrap, CacheOutput = true
            };
            var rockTiled = new BorderEffect {
                Source = rock.Image, ExtendX = wrap, ExtendY = wrap, CacheOutput = true
            };

            var shaderBytes = await Utilities.ReadBytesFromUriAsync(new Uri("ms-appx:///Shaders/TerrainShader.bin"));

            _terrainMap = new PixelShaderEffect(shaderBytes)
            {
                Source1     = _normalHeightMap,
                Source2     = grassTiled,
                Source3     = snowTiled,
                Source4     = rockTiled,
                CacheOutput = true
            };
        }
コード例 #17
0
        private void UpdateBorderEffectBrush()
        {
            ComboBoxItem itemX = ExtendXBox.SelectedValue as ComboBoxItem;
            ComboBoxItem itemY = ExtendYBox.SelectedValue as ComboBoxItem;

            if (itemX == null || itemY == null)
            {
                return;
            }

            var borderEffect = new BorderEffect
            {
                ExtendX = (CanvasEdgeBehavior)itemX.Tag,
                ExtendY = (CanvasEdgeBehavior)itemY.Tag,
                Source  = new CompositionEffectSourceParameter("source")
            };

            var brush = _compositor.CreateEffectFactory(borderEffect).CreateBrush();

            brush.SetSourceParameter("source", _image.Brush);
            _sprite.Brush = brush;
        }
コード例 #18
0
        protected override void OnConnected()
        {
            if (CompositionBrush == null)
            {
                var surface      = LoadedImageSurface.StartLoadFromUri(Source, new Size(480, 750));
                var surfaceBrush = Window.Current.Compositor.CreateSurfaceBrush(surface);
                surfaceBrush.Stretch = CompositionStretch.None;

                var borderEffect = new BorderEffect()
                {
                    Source  = new CompositionEffectSourceParameter("source"),
                    ExtendX = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap,
                    ExtendY = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap
                };

                var borderEffectFactory = Window.Current.Compositor.CreateEffectFactory(borderEffect);
                var borderEffectBrush   = borderEffectFactory.CreateBrush();
                borderEffectBrush.SetSourceParameter("source", surfaceBrush);

                CompositionBrush = borderEffectBrush;
            }
        }
コード例 #19
0
        private async void SetModernStyle()
        {
            var canvasDevice   = CanvasDevice.GetSharedDevice();
            var graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, canvasDevice);

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

            var drawingSurface = graphicsDevice.CreateDrawingSurface(bitmap.Size,
                                                                     DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

            using (var ds = CanvasComposition.CreateDrawingSession(drawingSurface))
            {
                ds.Clear(Colors.Transparent);
                ds.DrawImage(bitmap);
            }

            var surfaceBrush = _compositor.CreateSurfaceBrush(drawingSurface);

            surfaceBrush.Stretch = CompositionStretch.None;

            var border = new BorderEffect
            {
                ExtendX = CanvasEdgeBehavior.Wrap,
                ExtendY = CanvasEdgeBehavior.Wrap,
                Source  = new CompositionEffectSourceParameter("source")
            };

            var fxFactory = _compositor.CreateEffectFactory(border);
            var fxBrush   = fxFactory.CreateBrush();

            fxBrush.SetSourceParameter("source", surfaceBrush);

            headerSprite       = _compositor.CreateSpriteVisual();
            headerSprite.Size  = new Vector2((float)blurGlass.ActualWidth, (float)blurGlass.ActualHeight);
            headerSprite.Brush = fxBrush;

            ElementCompositionPreview.SetElementChildVisual(blurGlass, headerSprite);
        }
コード例 #20
0
 public void RemoveError(View view)
 {
     BorderEffect.SetHasBorderEffect(view, false);
 }
コード例 #21
0
        private ICanvasImage CreateBorder()
        {
            var borderEffect = new BorderEffect
            {
                Source = bitmapTiger
            };

            // Animation cycles through the different edge behavior modes.
            int enumValueCount = Utils.GetEnumAsList<CanvasEdgeBehavior>().Count;

            animationFunction = elapsedTime =>
            {
                borderEffect.ExtendX =
                borderEffect.ExtendY = (CanvasEdgeBehavior)(elapsedTime % enumValueCount);

                textLabel = "Mode: " + borderEffect.ExtendX;
            };

            return AddSoftEdgedCrop(borderEffect);
        }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Border" /> class.
 /// </summary>
 /// <param name="Width">Gets or sets border width.</param>
 /// <param name="EffectIntensity">Gets or sets effect intencity. Valid range of value is [0..2].</param>
 /// <param name="Style">Gets or sets border style.</param>
 /// <param name="Effect">Gets or sets border effect.</param>
 /// <param name="Dash">Gets or sets dash pattern.</param>
 /// <param name="Color">Gets or sets border color.</param>
 public Border(int?Width = default(int?), int?EffectIntensity = default(int?), BorderStyle Style = default(BorderStyle), BorderEffect Effect = default(BorderEffect), Dash Dash = default(Dash), Color Color = default(Color))
 {
     this.Width           = Width;
     this.EffectIntensity = EffectIntensity;
     this.Style           = Style;
     this.Effect          = Effect;
     this.Dash            = Dash;
     this.Color           = Color;
 }
コード例 #23
0
        protected override void OnConnected()
        {
            _connected = true;
            _negative  = IsInverted;

            if (_recreate || (CompositionBrush == null && Surface != null))
            {
                _recreate = false;

                var surface      = Surface;
                var surfaceBrush = Window.Current.Compositor.CreateSurfaceBrush(surface);
                surfaceBrush.Stretch = CompositionStretch.None;

                var borderEffect = new BorderEffect()
                {
                    Source  = new CompositionEffectSourceParameter("Source"),
                    ExtendX = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap,
                    ExtendY = Microsoft.Graphics.Canvas.CanvasEdgeBehavior.Wrap
                };

                IGraphicsEffect      effect;
                IEnumerable <string> animatableProperties;
                if (IsInverted)
                {
                    //var matrix = new ColorMatrixEffect
                    //{
                    //    ColorMatrix = new Matrix5x4
                    //    {
                    //        M11 = 1, M12 = 0, M13 = 0, M14 = 0,
                    //        M21 = 0, M22 = 1, M23 = 0, M24 = 0,
                    //        M31 = 0, M32 = 0, M33 = 1, M34 = 0,
                    //        M41 = 0, M42 = 0, M43 = 0, M44 =-1,
                    //        M51 = 0, M52 = 0, M53 = 0, M54 = 1
                    //    },
                    //    Source = borderEffect
                    //};
                    _tintEffect = null;

                    animatableProperties = new string[0];
                    effect = new GammaTransferEffect()
                    {
                        AlphaAmplitude = -1,
                        AlphaOffset    = 1,
                        RedDisable     = true,
                        GreenDisable   = true,
                        BlueDisable    = true,
                        Source         = new InvertEffect {
                            Source = borderEffect
                        }
                    };
                }
                else
                {
                    var tintEffect = _tintEffect = new TintEffect
                    {
                        Name   = "Tint",
                        Source = borderEffect,
                        Color  = Color.FromArgb((byte)(Intensity * 255), 0, 0, 0)
                    };

                    animatableProperties = new[] { "Tint.Color" };
                    effect = new BlendEffect
                    {
                        Background = tintEffect,
                        Foreground = new CompositionEffectSourceParameter("Backdrop"),
                        Mode       = BlendEffectMode.Overlay
                    };
                }

                var backdrop = Window.Current.Compositor.CreateBackdropBrush();

                var borderEffectFactory = Window.Current.Compositor.CreateEffectFactory(effect, animatableProperties);
                var borderEffectBrush   = borderEffectFactory.CreateBrush();
                borderEffectBrush.SetSourceParameter("Source", surfaceBrush);

                if (_tintEffect != null)
                {
                    borderEffectBrush.SetSourceParameter("Backdrop", backdrop);
                }

                CompositionBrush = borderEffectBrush;
            }
        }
コード例 #24
0
        private async Task ChatPhotoAsync(UpdateFileGenerationStart update, string[] args)
        {
            try
            {
                var conversion = JsonConvert.DeserializeObject <ChatPhotoConversion>(args[2]);

                var sticker = await _protoService.SendAsync(new GetFile(conversion.StickerFileId)) as Telegram.Td.Api.File;

                if (sticker == null || !sticker.Local.IsFileExisting())
                {
                    _protoService.Send(new FinishFileGeneration(update.GenerationId, new Error(500, "FILE_GENERATE_LOCATION_INVALID No sticker found")));
                    return;
                }

                Background background = null;

                var backgroundLink = await _protoService.SendAsync(new GetInternalLinkType(conversion.BackgroundUrl ?? string.Empty)) as InternalLinkTypeBackground;

                if (backgroundLink != null)
                {
                    background = await _protoService.SendAsync(new SearchBackground(backgroundLink.BackgroundName)) as Background;
                }
                else
                {
                    var freeform = new[] { 0xDBDDBB, 0x6BA587, 0xD5D88D, 0x88B884 };
                    background = new Background(0, true, false, string.Empty,
                                                new Document(string.Empty, "application/x-tgwallpattern", null, null, TdExtensions.GetLocalFile("Assets\\Background.tgv", "Background")),
                                                new BackgroundTypePattern(new BackgroundFillFreeformGradient(freeform), 50, false, false));
                }

                if (background == null || (background.Document != null && !background.Document.DocumentValue.Local.IsFileExisting()))
                {
                    _protoService.Send(new FinishFileGeneration(update.GenerationId, new Error(500, "FILE_GENERATE_LOCATION_INVALID No background found")));
                    return;
                }

                var device  = CanvasDevice.GetSharedDevice();
                var bitmaps = new List <CanvasBitmap>();

                var sfondo = new CanvasRenderTarget(device, 640, 640, 96, DirectXPixelFormat.B8G8R8A8UIntNormalized, CanvasAlphaMode.Premultiplied);

                using (var session = sfondo.CreateDrawingSession())
                {
                    if (background.Type is BackgroundTypePattern pattern)
                    {
                        if (pattern.Fill is BackgroundFillFreeformGradient freeform)
                        {
                            var colors    = freeform.GetColors();
                            var positions = new Vector2[]
                            {
                                new Vector2(0.80f, 0.10f),
                                new Vector2(0.35f, 0.25f),
                                new Vector2(0.20f, 0.90f),
                                new Vector2(0.65f, 0.75f),
                            };

                            using (var gradient = CanvasBitmap.CreateFromBytes(device, ChatBackgroundFreeform.GenerateGradientData(50, 50, colors, positions), 50, 50, DirectXPixelFormat.B8G8R8A8UIntNormalized))
                                using (var cache = await PlaceholderHelper.GetPatternBitmapAsync(device, null, background.Document.DocumentValue))
                                {
                                    using (var scale = new ScaleEffect {
                                        Source = gradient, BorderMode = EffectBorderMode.Hard, Scale = new Vector2(640f / 50f, 640f / 50f)
                                    })
                                        using (var colorize = new TintEffect {
                                            Source = cache, Color = Color.FromArgb(0x76, 00, 00, 00)
                                        })
                                            using (var tile = new BorderEffect {
                                                Source = colorize, ExtendX = CanvasEdgeBehavior.Wrap, ExtendY = CanvasEdgeBehavior.Wrap
                                            })
                                                using (var effect = new BlendEffect {
                                                    Foreground = tile, Background = scale, Mode = BlendEffectMode.Overlay
                                                })
                                                {
                                                    session.DrawImage(effect, new Rect(0, 0, 640, 640), new Rect(0, 0, 640, 640));
                                                }
                                }
                        }
                    }
                }

                bitmaps.Add(sfondo);

                var width  = (int)(512d * conversion.Scale);
                var height = (int)(512d * conversion.Scale);

                var animation = await Task.Run(() => LottieAnimation.LoadFromFile(sticker.Local.Path, new Windows.Graphics.SizeInt32 {
                    Width = width, Height = height
                }, false, null));

                if (animation == null)
                {
                    _protoService.Send(new FinishFileGeneration(update.GenerationId, new Error(500, "FILE_GENERATE_LOCATION_INVALID Can't load Lottie animation")));
                    return;
                }

                var composition = new MediaComposition();
                var layer       = new MediaOverlayLayer();

                var buffer = ArrayPool <byte> .Shared.Rent(width *height * 4);

                var framesPerUpdate = animation.FrameRate < 60 ? 1 : 2;
                var duration        = TimeSpan.Zero;

                for (int i = 0; i < animation.TotalFrame; i += framesPerUpdate)
                {
                    var bitmap = CanvasBitmap.CreateFromBytes(device, buffer, width, height, DirectXPixelFormat.B8G8R8A8UIntNormalized);
                    animation.RenderSync(bitmap, i);

                    var clip    = MediaClip.CreateFromSurface(bitmap, TimeSpan.FromMilliseconds(1000d / 30d));
                    var overlay = new MediaOverlay(clip, new Rect(320 - (width / 2d), 320 - (height / 2d), width, height), 1);

                    overlay.Delay = duration;

                    layer.Overlays.Add(overlay);
                    duration += clip.OriginalDuration;

                    bitmaps.Add(bitmap);
                }

                composition.OverlayLayers.Add(layer);
                composition.Clips.Add(MediaClip.CreateFromSurface(sfondo, duration));

                var temp = await _protoService.GetFileAsync(update.DestinationPath);

                var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
                profile.Audio                       = null;
                profile.Video.Bitrate               = 1800000;
                profile.Video.Width                 = 640;
                profile.Video.Height                = 640;
                profile.Video.FrameRate.Numerator   = 30;
                profile.Video.FrameRate.Denominator = 1;

                var progress = composition.RenderToFileAsync(temp, MediaTrimmingPreference.Precise, profile);
                progress.Progress = (result, delta) =>
                {
                    _protoService.Send(new SetFileGenerationProgress(update.GenerationId, 100, (int)delta));
                };

                var result = await progress;
                if (result == TranscodeFailureReason.None)
                {
                    _protoService.Send(new FinishFileGeneration(update.GenerationId, null));
                }
                else
                {
                    _protoService.Send(new FinishFileGeneration(update.GenerationId, new Error(500, result.ToString())));
                }

                ArrayPool <byte> .Shared.Return(buffer);

                foreach (var bitmap in bitmaps)
                {
                    bitmap.Dispose();
                }
            }
            catch (Exception ex)
            {
                _protoService.Send(new FinishFileGeneration(update.GenerationId, new Error(500, "FILE_GENERATE_LOCATION_INVALID " + ex.ToString())));
            }
        }
コード例 #25
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            if (effect == null)
            {
                effect = new GDIPlusCommonGraphics(gEffectGDI, Color.Gray, Color.Gray, true, 255, 1);
            }

            if (gr == null)
            {
                gr = new GDIPlusCommonGraphics(gGDI, Color.Black, Color.White, true, 255, 2);
            }
            Shape sh1                    = new shape.Ellipse(10, 10, 100, 60);
            Shape sh2                    = new shape.Ellipse(10, 100, 100, 60);
            Shape sh1WithShadow          = new ShadowEffect(sh1, effect);
            Shape sh2WithShadow          = new ShadowEffect(sh2, effect);
            Shape sh2WithShadowAndBorder = new BorderEffect(sh2WithShadow, effect);

            Shape DFstartBlock = new DFStartBlock(150, 5, 100);
            Shape DFforward1   = new DFForwardBlock(200, 76, 200, 100);
            Shape DFinput      = new DFInputBlock(150, 100, 100);
            Shape DFforward2   = new DFForwardBlock(200, 146, 200, 170);
            Shape DFprocess    = new DFProcessBlock(150, 170, 100);
            Shape DFforward3   = new DFForwardBlock(200, 236, 200, 260);
            Shape DFoutput     = new DFOutputBlock(150, 260, 100);
            Shape DFforward4   = new DFForwardBlock(200, 306, 200, 330);
            Shape DFendBlock   = new DFEndBlock(150, 330, 100);

            sh1WithShadow.draw(gr);
            sh2WithShadowAndBorder.draw(gr);

            Shape FCstart     = new FCStartBlock(280, 20, 100);
            Shape FCforward1  = new FCForwardBlock(330, 68, 330, 100);
            Shape FCinput     = new FCInputBlock(280, 100, 100);
            Shape FCforward2  = new FCForwardBlock(330, 146, 330, 170);
            Shape FCprocess   = new FCProcessBlock(280, 170, 100);
            Shape FCforward3  = new FCForwardBlock(330, 215, 330, 260);
            Shape FCoutput    = new FCOutputBlock(280, 260, 100);
            Shape FCforward4  = new FCForwardBlock(330, 306, 330, 330);
            Shape FCcondition = new FCConditionBlock(280, 330, 100);
            Shape FCforward5  = new FCForwardBlock(330, 376, 330, 400);
            Shape FCend       = new FCEndBlock(280, 400, 100);

            DFstartBlock.draw(gr);
            DFforward1.draw(gr);
            DFinput.draw(gr);
            DFforward2.draw(gr);
            DFprocess.draw(gr);
            DFforward3.draw(gr);
            DFoutput.draw(gr);
            DFforward4.draw(gr);
            DFendBlock.draw(gr);

            FCstart.draw(gr);
            FCforward1.draw(gr);
            FCinput.draw(gr);
            FCforward2.draw(gr);
            FCprocess.draw(gr);
            FCforward3.draw(gr);
            FCoutput.draw(gr);
            FCforward4.draw(gr);
            FCcondition.draw(gr);
            FCforward5.draw(gr);
            FCend.draw(gr);

            shapes.Add(sh1WithShadow);
            shapes.Add(sh2WithShadowAndBorder);
            shapes.Add(DFstartBlock);
            shapes.Add(DFinput);
            shapes.Add(DFprocess);
            shapes.Add(DFoutput);
            shapes.Add(DFendBlock);
            shapes.Add(DFforward1);
            shapes.Add(DFforward2);
            shapes.Add(DFforward3);
            shapes.Add(DFforward4);
            shapes.Add(FCstart);
            shapes.Add(FCinput);
            shapes.Add(FCoutput);
            shapes.Add(FCprocess);
            shapes.Add(FCcondition);
            shapes.Add(FCend);
            shapes.Add(FCforward1);
            shapes.Add(FCforward2);
            shapes.Add(FCforward3);
            shapes.Add(FCforward4);
            shapes.Add(FCforward5);
        }
コード例 #26
0
        public void ApplyStyle(RichTextBoxStyle style, RichTextBoxStyle linkStyle, bool useLinkButtons)
        {
            RichTextTag tag    = new RichTextTag();
            bool        isLink = false;

            this.IsHitTestVisible = false;

            if (this.Tag is RichTextTag)
            {
                tag = (RichTextTag)this.Tag;
                if (tag.Metadata != null)
                {
                    isLink = tag.Metadata.IsLink;
                }

                if (useLinkButtons)
                {
                    if (isLink)
                    {
                        if (_link == null)
                        {
                            Children.Remove(_element);
                            _element.Foreground = new SolidColorBrush(Colors.Red);

                            _link = new HyperlinkButton()
                            {
                                Content     = _element,
                                NavigateUri = new Uri(tag.Metadata["URL"]),
                                TargetName  = (tag.Metadata.ContainsKey("Target") ? tag.Metadata["Target"] : "_blank")
                            };
                            Children.Insert(0, _link);
                        }
                        this.IsHitTestVisible = true;
                    }
                    else
                    {
                        if (_link != null)
                        {
                            Children.Remove(_link);
                            _link = null;
                            Children.Insert(0, _element);
                        }
                    }
                }
            }

            _element.FontFamily      = new FontFamily(style.Family);
            _element.FontSize        = (style.Size != null ? (double)style.Size : 14);
            base.Background          = style.Background;
            _element.Foreground      = isLink ? linkStyle.Foreground : style.Foreground;
            _element.FontWeight      = (style.Weight != null ? (FontWeight)style.Weight : FontWeights.Normal);
            _element.FontStyle       = (style.Style != null ? (FontStyle)style.Style : FontStyles.Normal);
            _element.TextDecorations = isLink ? linkStyle.Decorations : style.Decorations;
            _effect       = style.Effect;
            _border       = style.BorderType;
            _shadowEffect = style.Shadow;

            HorizontalAlignment = style.Alignment;
            VerticalAlignment   = style.VerticalAlignment;

            if (style.ShadowBrush != null)
            {
                _shadowBrush = style.ShadowBrush;
            }

            if (style.Special == RichTextSpecialFormatting.Subscript)
            {
                _element.FontSize   *= RichTextBlock.SubScriptMultiplier;
                VerticalAlignment    = VerticalAlignment.Bottom;
                LineHeightMultiplier = 1 / RichTextBlock.SubScriptMultiplier;
            }
            else if (style.Special == RichTextSpecialFormatting.Superscript)
            {
                _element.FontSize   *= RichTextBlock.SuperScriptMultiplier;
                VerticalAlignment    = VerticalAlignment.Top;
                LineHeightMultiplier = 1 / RichTextBlock.SuperScriptMultiplier;
            }
            else
            {
                LineHeightMultiplier = 1;
            }

            Margin = new Thickness(style.Margin.Left, style.Margin.Top, style.Margin.Right, style.Margin.Bottom);

            UpdateStyle();
        }
コード例 #27
0
 public void ShowError(View view, string message)
 {
     BorderEffect.SetBorderColor(view, Color.Red);
     BorderEffect.SetHasBorderEffect(view, true);
 }