Exemple #1
0
        /// <summary>
        /// Dropws the shadow_ draw.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs" /> instance containing the event data.</param>
        protected void DropShadow_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            Color[] colors = new Color[(int)(sender.Size.Width * sender.Size.Height)];
            for (int x = 0; x < sender.ActualWidth; x++)
            {
                if (x < sender.ActualWidth)
                {
                    colors[x] = Colors.{ ThemeResource SystemControlForegroundChromeHighBrush };
                }
            }

            using (CanvasBitmap bitmap = CanvasBitmap.CreateFromColors(sender, colors, (int)sender.Size.Width, (int)sender.Size.Height))
            {
                using (ShadowEffect shadow = new ShadowEffect())
                {
                    shadow.Source       = bitmap;
                    shadow.BlurAmount   = 3;
                    shadow.Optimization = EffectOptimization.Speed;

                    args.DrawingSession.DrawImage(shadow);
                }
            }
        }
#endif
    }
        public static void Run()
        {
            // ExStart:ShadowEffectOfShape
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Load your source excel file
            Workbook wb = new Workbook(dataDir + "sample.xlsx");

            // Access first worksheet
            Worksheet ws = wb.Worksheets[0];

            // Access first shape
            Shape sh = ws.Shapes[0];

            // Set the shadow effect of the shape, Set its Angle, Blur, Distance and Transparency properties
            ShadowEffect se = sh.ShadowEffect;

            se.Angle        = 150;
            se.Blur         = 4;
            se.Distance     = 45;
            se.Transparency = 0.3;

            // Save the workbook in xlsx format
            wb.Save(dataDir + "output_out_.xlsx");
            // ExEnd:ShadowEffectOfShape
        }
Exemple #3
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Load your source excel file
            Workbook wb = new Workbook(sourceDir + "sampleShadowEffectOfShape.xlsx");

            // Access first worksheet
            Worksheet ws = wb.Worksheets[0];

            // Access first shape
            Shape sh = ws.Shapes[0];

            // Set the shadow effect of the shape, Set its Angle, Blur, Distance and Transparency properties
            ShadowEffect se = sh.ShadowEffect;

            se.Angle        = 150;
            se.Blur         = 4;
            se.Distance     = 45;
            se.Transparency = 0.3;

            // Save the workbook in xlsx format
            wb.Save(outputDir + "outputShadowEffectOfShape.xlsx");

            Console.WriteLine("ShadowEffectOfShape executed successfully.");
        }
Exemple #4
0
        void DrawShadows(Scene scene)
        {
            foreach (Shadow shadow in scene.Shadows)
            {
                if (shadow.Vertices != null)
                {
                    float[]  vertices = new float[2 * 4];
                    Color4[] colors   = new Color4[4];
                    for (int i = 0; i < 4; i++)
                    {
                        vertices[i * 2 + 0] = shadow.Vertices[i].X;
                        vertices[i * 2 + 1] = shadow.Vertices[i].Y;
                        colors[i].R         = 0.0f;
                        colors[i].G         = 0.0f;
                        colors[i].B         = 0.0f;
                        colors[i].A         = 0.2f;
                    }

                    Geometry shadowGeometry =
                        new Geometry(OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, shadow.Vertices, shadow.Colors, null, null);

                    ShadowEffect.Begin();
                    ShadowEffect.WorldViewMatrix = Camera.ProjectionMatrix * Camera.ViewMatrix;

                    shadowGeometry.Draw();

                    ShadowEffect.End();
                    GL.BindVertexArray(0);
                }
            }
        }
        protected override void OnDraw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var radius = Radius;
            var center = new Vector2((float)sender.Size.Width / 2f, (float)sender.Size.Height / 2f);

            using (var renderTarget = new CanvasRenderTarget(sender, sender.Size))
            {
                using (var ds = renderTarget.CreateDrawingSession())
                {
                    ds.FillEllipse(center, radius, radius, new CanvasSolidColorBrush(sender, ForeColor));
                }
                using (var effect = new ShadowEffect())
                {
                    effect.Source      = renderTarget;
                    effect.ShadowColor = ShadowColor;
                    effect.BlurAmount  = (float)ShadowRadius;

                    using (args.DrawingSession)
                    {
                        args.DrawingSession.DrawImage(effect, 1, 1);
                        args.DrawingSession.DrawImage(renderTarget);
                    }
                }
            }
        }
Exemple #6
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);
                            }
        }
Exemple #7
0
        public void Dispose()
        {
            _cl?.Dispose();
            _cl = null;

            shadow?.Dispose();
            shadow = null;
        }
Exemple #8
0
        public void Dispose()
        {
            _cl?.Dispose();
            _cl = null;

            shadow?.Dispose();
            shadow = null;
        }
        void Update()
        {
            if (View == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                return;
            }

            var radius = (float)ShadowEffect.GetRadius(Element);

            if (radius < 0)
            {
                radius = defaultRadius;
            }

            var opacity = ShadowEffect.GetOpacity(Element);

            if (opacity < 0)
            {
                opacity = defaultOpacity;
            }

            var androidColor = ShadowEffect.GetColor(Element).MultiplyAlpha(opacity).ToAndroid();
            var offsetX      = (float)ShadowEffect.GetOffsetX(Element);
            var offsetY      = (float)ShadowEffect.GetOffsetY(Element);
            var cornerRadius = Element is IBorderElement borderElement ? borderElement.CornerRadius : 0;

            if (View is AButton button)
            {
                button.StateListAnimator = null;
            }
            else if (View is not AButton && View is ATextView textView)
            {
                textView.SetShadowLayer(radius, offsetX, offsetY, androidColor);
                return;
            }

            var pixelOffsetX      = View.Context.ToPixels(offsetX);
            var pixelOffsetY      = View.Context.ToPixels(offsetY);
            var pixelCornerRadius = View.Context.ToPixels(cornerRadius);

            View.OutlineProvider = new ShadowOutlineProvider(pixelOffsetX, pixelOffsetY, pixelCornerRadius);
            View.Elevation       = View.Context.ToPixels(radius);
            if (View.Parent is ViewGroup group)
            {
                group.SetClipToPadding(false);
            }

#pragma warning disable
            if (Build.VERSION.SdkInt < BuildVersionCodes.P)
            {
                return;
            }

            View.SetOutlineAmbientShadowColor(androidColor);
            View.SetOutlineSpotShadowColor(androidColor);
#pragma warning restore
        }
        private void ApplyShadowEffect(ShadowEffect effect)
        {
            var textblock = (Control as ElmSharp.Label).EdjeObject["elm.text"];
            var sb        = new StringBuilder(textblock.TextStyle);

            sb.Remove(sb.Length - 1, 1);                                                                                  // remove '
            sb.AppendFormat(" style=far_soft_shadow,{0} shadow_color={1}'", GetLabelDirection(effect), GetColor(effect)); // add shadow style & color

            textblock.TextStyle = sb.ToString();
        }
Exemple #11
0
        static void TestEffectInputs(TypeInfo effectType, IEffect effect)
        {
            var inputProperties = (from property in effectType.DeclaredProperties
                                   where property.PropertyType == typeof(IEffectInput)
                                   select property).ToList();

            // Should have the same number of strongly typed properties as elements in the inputs collection.
            Assert.AreEqual(inputProperties.Count, effect.Inputs.Count);

            // Initial input values should all be null.
            for (int i = 0; i < effect.Inputs.Count; i++)
            {
                Assert.IsNull(effect.Inputs[i]);
                Assert.IsNull(inputProperties[i].GetValue(effect));
            }

            var testValue1 = new GaussianBlurEffect();
            var testValue2 = new ShadowEffect();

            var whichIndexIsProperty = new List <int>();

            // Changing strongly typed properties should change the inputs collection.
            for (int i = 0; i < effect.Inputs.Count; i++)
            {
                // Change a property value, and see which input changes.
                inputProperties[i].SetValue(effect, testValue1);
                int whichIndexIsThis = effect.Inputs.IndexOf(testValue1);
                Assert.IsTrue(whichIndexIsThis >= 0);
                whichIndexIsProperty.Add(whichIndexIsThis);

                // Change the same property value again, and make sure the same input changes.
                inputProperties[i].SetValue(effect, testValue2);
                Assert.AreSame(testValue2, effect.Inputs[whichIndexIsThis]);

                // Change the property value to null.
                inputProperties[i].SetValue(effect, null);
                Assert.IsNull(effect.Inputs[whichIndexIsThis]);
            }

            // Should not have any duplicate property mappings.
            Assert.AreEqual(whichIndexIsProperty.Count, whichIndexIsProperty.Distinct().Count());

            // In reverse, changing the inputs collection should change strongly typed properties.
            for (int i = 0; i < effect.Inputs.Count; i++)
            {
                effect.Inputs[whichIndexIsProperty[i]] = testValue1;
                Assert.AreSame(testValue1, inputProperties[i].GetValue(effect));

                effect.Inputs[whichIndexIsProperty[i]] = testValue2;
                Assert.AreSame(testValue2, inputProperties[i].GetValue(effect));

                effect.Inputs[whichIndexIsProperty[i]] = null;
                Assert.IsNull(inputProperties[i].GetValue(effect));
            }
        }
 protected override void OnAttached()
 {
     try {
         Control.Layer.CornerRadius  = (nfloat)ShadowEffect.GetRadius(Element);
         Control.Layer.ShadowColor   = ShadowEffect.GetColor(Element).ToCGColor();
         Control.Layer.ShadowOffset  = new CGSize((double)ShadowEffect.GetDistanceX(Element), (double)ShadowEffect.GetDistanceY(Element));
         Control.Layer.ShadowOpacity = 1.0f;
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
     }
 }
Exemple #13
0
        private static void DrawShadowCore(CanvasDrawingSession drawingSession, ICanvasImage image, Windows.UI.Color shadowColor, float shadowBlurAmount, float shadowOffset)
        {
            ICanvasImage shadow = new ShadowEffect
            {
                Source      = image,
                ShadowColor = shadowColor,
                BlurAmount  = shadowBlurAmount,
            };

            drawingSession.DrawImage(shadow, shadowOffset, shadowOffset);
            drawingSession.DrawImage(image);
        }
Exemple #14
0
        async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
        {
            // Draw the icon image into a command list.
            var iconImage = new CanvasCommandList(device);

            using (var ds = iconImage.CreateDrawingSession())
            {
                appInfo.DrawIconImage(ds, iconInfo);
            }

            // Rasterize into a rendertarget.
            var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                // Initialize with the appropriate background color.
                ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor);

                // Work out where to position the icon image.
                var imageBounds = iconImage.GetBounds(ds);

                imageBounds.Height *= 1 + iconInfo.BottomPadding;

                float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f);

                float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons;

                ds.Transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) *
                               Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) *
                               Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2);

                // Optional shadow effet.
                if (appInfo.AddShadow)
                {
                    var shadow = new ShadowEffect
                    {
                        Source     = iconImage,
                        BlurAmount = 12,
                    };

                    ds.DrawImage(shadow);
                }

                // draw the main icon image.
                ds.DrawImage(iconImage);
            }

            // Save to a file.
            using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting))
            {
                await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png);
            }
        }
Exemple #15
0
        internal static void ApplyTextLayer(CanvasDrawingSession session)
        {
            var shadow = new ShadowEffect()
            {
                BlurAmount   = 0.01f,
                ShadowColor  = Colors.White,
                Optimization = EffectOptimization.Quality
            };

            shadow.Source = renderText;
            session.DrawImage(shadow);
        }
Exemple #16
0
    public void OnDestroy()
    {
        myTarget = (ShadowEffect)target;

        //myTarget.SetDelegate();
        DestroyImmediate(myTarget.shadow);

        if (myTarget.shadow != null)
        {
            DestroyImmediate(myTarget.shadow);
        }
    }
Exemple #17
0
 protected override void OnAttached()
 {
     try {
         var   control   = Control as Android.Widget.TextView;
         float radius    = (float)ShadowEffect.GetRadius(Element);
         float distanceX = (float)ShadowEffect.GetDistanceX(Element);
         float distanceY = (float)ShadowEffect.GetDistanceY(Element);
         Android.Graphics.Color color = ShadowEffect.GetColor(Element).ToAndroid();
         control.SetShadowLayer(radius, distanceX, distanceY, color);
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
     }
 }
Exemple #18
0
        private ICanvasImage GetShipShadow(int index)
        {
            var shadowEffect = new ShadowEffect
            {
                Source = shipImages[index]
            };
            var finalShadow = new Transform2DEffect
            {
                Source          = shadowEffect,
                TransformMatrix = Matrix3x2.CreateTranslation(1, 1)
            };

            return(finalShadow);
        }
Exemple #19
0
        private static void Changed(BindableObject bindable, object oldValue, object newValue)
        {
            var view = (View)bindable;

            if (view != null)
            {
                var effect = view.Effects.FirstOrDefault(e => e is ShadowEffect);
                if (effect == null)
                {
                    effect = new ShadowEffect();
                    view.Effects.Add(effect);
                }
            }
        }
Exemple #20
0
        static void TestEffectSources(TypeInfo effectType, IGraphicsEffect effect)
        {
            var sourceProperties = (from property in effectType.DeclaredProperties
                                    where property.PropertyType == typeof(IGraphicsEffectSource)
                                    select property).ToList();

            // Should have the same number of strongly typed properties as the effect has sources.
            Assert.AreEqual(sourceProperties.Count, EffectAccessor.GetSourceCount(effect));

            // Initial source values should all be null.
            for (int i = 0; i < EffectAccessor.GetSourceCount(effect); i++)
            {
                Assert.IsNull(EffectAccessor.GetSource(effect, i));
                Assert.IsNull(sourceProperties[i].GetValue(effect));
            }

            var testValue1 = new GaussianBlurEffect();
            var testValue2 = new ShadowEffect();

            var whichIndexIsProperty = new List <int>();

            // Changing strongly typed properties should change the sources reported by IGraphicsEffectD2D1Interop.
            for (int i = 0; i < EffectAccessor.GetSourceCount(effect); i++)
            {
                // Change a property value, and see which source changes.
                sourceProperties[i].SetValue(effect, testValue1);

                int whichIndexIsThis = 0;

                while (EffectAccessor.GetSource(effect, whichIndexIsThis) != testValue1)
                {
                    whichIndexIsThis++;
                    Assert.IsTrue(whichIndexIsThis < EffectAccessor.GetSourceCount(effect));
                }

                whichIndexIsProperty.Add(whichIndexIsThis);

                // Change the same property value again, and make sure the same source changes.
                sourceProperties[i].SetValue(effect, testValue2);
                Assert.AreSame(testValue2, EffectAccessor.GetSource(effect, whichIndexIsThis));

                // Change the property value to null.
                sourceProperties[i].SetValue(effect, null);
                Assert.IsNull(EffectAccessor.GetSource(effect, whichIndexIsThis));
            }

            // Should not have any duplicate property mappings.
            Assert.AreEqual(whichIndexIsProperty.Count, whichIndexIsProperty.Distinct().Count());
        }
Exemple #21
0
        protected override void LoadContent()
        {
            base.LoadContent();

            // Effekte und Texturen laden
            shapeEffect           = new ShapeEffect(Content.Load <Effect>("Effects/Shape"));
            shapeEffect.Normalmap = Content.Load <Texture2D>("Textures/Normalmap");
            shapeEffect.Texture   = Content.Load <Texture2D>("Textures/Texture");
            shapeEffect.Heightmap = Content.Load <Texture2D>("Textures/Heightmap");

            shadowEffect = new ShadowEffect(Content.Load <Effect>("Effects/Shadow"));

            // Models laden
            shape.Model = Content.Load <Model>("Models/Shapes");
            room.Model  = Content.Load <Model>("Models/Cube");
        }
Exemple #22
0
    public override void OnInspectorGUI()
    {
        myTarget = (ShadowEffect)target;
        EditorUtility.SetDirty(myTarget);

        myTarget.SetPosition();
        myTarget.RestartShadow();

        GUILayout.Label("Wysokość obiektu");
        myTarget.objectHeight = EditorGUILayout.Slider(myTarget.objectHeight, 0.05f, 0.15f);
        GUILayout.Label("Moc cienia obiektu");
        myTarget.shadowIntensity             = (int)EditorGUILayout.Slider(myTarget.shadowIntensity, 0, 255);
        myTarget.shadowScale                 = EditorGUILayout.Vector3Field("", myTarget.shadowScale);
        myTarget.shadow.transform.localScale = myTarget.shadowScale;

        myTarget.shadow = (GameObject)EditorGUILayout.ObjectField(myTarget.shadow, typeof(GameObject), true);
    }
Exemple #23
0
        void Update()
        {
            if (View == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                return;
            }

            var radius = (float)ShadowEffect.GetRadius(Element);

            if (radius < 0)
            {
                radius = defaultRadius;
            }

            var opacity = ShadowEffect.GetOpacity(Element);

            if (opacity < 0)
            {
                opacity = defaultOpacity;
            }

            var androidColor = ShadowEffect.GetColor(Element).MultiplyAlpha(opacity).ToAndroid();

            if (View is TextView textView)
            {
                var offsetX = (float)ShadowEffect.GetOffsetX(Element);
                var offsetY = (float)ShadowEffect.GetOffsetY(Element);
                textView.SetShadowLayer(radius, offsetX, offsetY, androidColor);
                return;
            }

            View.OutlineProvider = (Element as VisualElement)?.BackgroundColor.A > 0
                                ? ViewOutlineProvider.PaddedBounds
                                : ViewOutlineProvider.Bounds;

            View.Elevation = View.Context.ToPixels(radius);

            if (Build.VERSION.SdkInt < BuildVersionCodes.P)
            {
                return;
            }

            View.SetOutlineAmbientShadowColor(androidColor);
            View.SetOutlineSpotShadowColor(androidColor);
        }
        private string GetLabelDirection()
        {
            var distanceX = ShadowEffect.GetDistanceX(Element);
            var distanceY = ShadowEffect.GetDistanceY(Element);

            if (distanceX < 0.0 && distanceY < 0.0)
            {
                return("top_left");
            }
            else if (distanceX == 0.0 && distanceY < 0.0)
            {
                return("top");
            }
            else if (distanceX > 0.0 && distanceY < 0.0)
            {
                return("top_right");
            }
            else if (distanceX > 0.0 && distanceY == 0.0)
            {
                return("right");
            }
            else if (distanceX > 0.0 && distanceY > 0.0)
            {
                return("bottom_right");
            }
            else if (distanceX == 0.0 && distanceY > 0.0)
            {
                return("bottom");
            }
            else if (distanceX < 0.0 && distanceY > 0.0)
            {
                return("bottom_left");
            }
            else if (distanceX < 0.0 && distanceY == 0.0)
            {
                return("left");
            }
            else
            {
                // platform default
                return("");
            }
        }
Exemple #25
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;
 }
Exemple #26
0
 protected override void OnAttached()
 {
     try {
         UIView control = Control as UIView;
         if (control == null)
         {
             control = Container as UIView;
         }
         ShadowEffect effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect);
         if (effect != null && control != null)
         {
             control.Layer.ShadowRadius  = effect.Radius;
             control.Layer.ShadowColor   = effect.Color.ToCGColor();
             control.Layer.ShadowOffset  = new CGSize(effect.DistanceX, effect.DistanceY);
             control.Layer.ShadowOpacity = effect.Opacity;
         }
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: " + ex.Message);
     }
 }
        void UpdateShadow()
        {
            if (shadow == null)
            {
                return;
            }

            var radius  = (float)ShadowEffect.GetRadius(Element);
            var opacity = (float)ShadowEffect.GetOpacity(Element);
            var color   = ShadowEffect.GetColor(Element).ToWindowsColor();
            var offsetX = (float)ShadowEffect.GetOffsetX(Element);
            var offsetY = (float)ShadowEffect.GetOffsetY(Element);

            shadow.Color      = color;
            shadow.BlurRadius = radius < 0 ? defaultRadius : radius;
            shadow.Opacity    = opacity < 0 ? defaultOpacity : opacity;
            shadow.Offset     = new Vector3(offsetX, offsetY, 0);

            UpdateShadowMask();
        }
Exemple #28
0
        /// <summary>
        /// Draws all of the drawables in order
        /// </summary>
        /// <param name="args"></param>
        /// <param name="drawables">The drawables that is to be drawn</param>
        public static void Draw(CanvasAnimatedDrawEventArgs args, Drawable[] drawables)
        {
            foreach (Drawable currentItem in drawables)
            {
                if (currentItem.isHover)
                {
                    var highligt = new ShadowEffect()
                    {
                        ShadowColor = Color.FromArgb(255, 255, 255, 255), Source = currentItem.Scaling(currentItem.Bitmap, currentItem.ImageSize), BlurAmount = 10
                    };
                    args.DrawingSession.DrawImage(highligt, currentItem.ActualPosition); //Draw highlighteffect if the drawable object is hoverd
                }

                //Check to hide gamepiece when finished
                if (!currentItem.isHidden)
                {
                    args.DrawingSession.DrawImage(currentItem.Scaling(currentItem.Bitmap, currentItem.ImageSize), currentItem.ActualPosition);
                }
            }
        }
 protected override void OnAttached()
 {
     if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Lollipop)
     {
         return;
     }
     try {
         if (!(Control is Android.Views.View control))
         {
             control = Container as Android.Views.View;
         }
         ShadowEffect effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect);
         if (effect != null && control != null)
         {
             float elevation = effect.Elevation;
             control.Elevation = elevation;
         }
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: " + ex.Message);
     }
 }
Exemple #30
0
        public static LayerInfo Load(PsdBinaryReader reader)
        {
            var signature = reader.ReadAsciiChars(4);

            if (signature != "8BIM")
            {
                throw new PsdInvalidException("Could not read LayerInfo due to signature mismatch." + signature);
            }

            var key    = reader.ReadAsciiChars(4);
            var length = reader.ReadInt32();
//            var startPosition = reader.BaseStream.Position;

//            UnityEngine.Debug.Log("EffectLayerFactory key:" + key);

            LayerInfo result;

            switch (key)
            {
            case "iglw":
            case "oglw":
                result = new GlowEffect(reader, key);
                break;

            case "dsdw":
            case "isdw":
                result = new ShadowEffect(reader, key);
                break;

            case "bevl":
                result = new BevelEffect(reader, key);
                break;

            default:
                result = new RawLayerInfo(reader, key, (int)length);
                break;
            }

            return(result);
        }
 private static string GetLabelDirection(ShadowEffect effect)
 {
     if (effect.DistanceX < 0.0 && effect.DistanceY < 0.0)
     {
         return("top_left");
     }
     else if (effect.DistanceX == 0.0 && effect.DistanceY < 0.0)
     {
         return("top");
     }
     else if (effect.DistanceX > 0.0 && effect.DistanceY < 0.0)
     {
         return("top_right");
     }
     else if (effect.DistanceX > 0.0 && effect.DistanceY == 0.0)
     {
         return("right");
     }
     else if (effect.DistanceX > 0.0 && effect.DistanceY > 0.0)
     {
         return("bottom_right");
     }
     else if (effect.DistanceX == 0.0 && effect.DistanceY > 0.0)
     {
         return("bottom");
     }
     else if (effect.DistanceX < 0.0 && effect.DistanceY > 0.0)
     {
         return("bottom_left");
     }
     else if (effect.DistanceX < 0.0 && effect.DistanceY == 0.0)
     {
         return("left");
     }
     else
     {
         // platform default
         return("");
     }
 }
        void canvas_CreateResources(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Fix the source rendertarget at 96 DPI, but let the destination rendertarget inherit
            // its DPI from the CanvasControl. This means their DPI will differ when run on a high
            // DPI display, so we can make sure the region mapping functions handle that correctly.
            sourceRenderTarget = new CanvasRenderTarget(sender, width, height, 96);
            destRenderTarget = new CanvasRenderTarget(sender, width, height);

            // Effect graph applies a subtle blur to the image, and also creates a shadow
            // with a larger blur amount and offset translation.
            blurEffect = new GaussianBlurEffect
            {
                Source = sourceRenderTarget,
                BlurAmount = 2
            };

            shadowEffect = new ShadowEffect
            {
                Source = sourceRenderTarget,
                BlurAmount = 6
            };

            compositeEffect = new CompositeEffect
            {
                Sources =
                {
                    new Transform2DEffect
                    {
                        Source = shadowEffect,
                        TransformMatrix = Matrix3x2.CreateTranslation(16, 16),
                    },

                    blurEffect
                }
            };

            // Arrange a bunch of text characters.
            var textFormat = new CanvasTextFormat
            {
                FontFamily = "Comic Sans MS",
                FontSize = 60,
            };

            characterLayouts = new List<CanvasTextLayout>();
            characterPositions = new List<Vector2>();

            var position = Vector2.Zero;

            for (char character = 'a'; character <= 'z'; character++)
            {
                var textLayout = new CanvasTextLayout(sender, character.ToString(), textFormat, width, height);

                characterLayouts.Add(textLayout);
                characterPositions.Add(position);

                if (character == 'm')
                {
                    position.X = 0;
                    position.Y += (float)textLayout.LayoutBounds.Height;
                }
                else
                {
                    position.X += (float)textLayout.LayoutBounds.Width;
                }
            }
        }
        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);
            }
        }
Exemple #34
0
        async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
        {
            // Draw the icon image into a command list.
            var commandList = new CanvasCommandList(device);

            using (var ds = commandList.CreateDrawingSession())
            {
                appInfo.DrawIconImage(ds, iconInfo);
            }

            ICanvasImage iconImage = commandList;

            // Rasterize into a rendertarget.
            var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                // Initialize with the appropriate background color.
                ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor);

                // Work out where to position the icon image.
                var imageBounds = iconImage.GetBounds(ds);

                imageBounds.Height *= 1 + iconInfo.BottomPadding;

                float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f);

                float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons;

                var transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) *
                                Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) *
                                Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2);

                if (iconInfo.Monochrome)
                {
                    // Optionally convert to monochrome.
                    iconImage = new DiscreteTransferEffect
                    {
                        Source = new Transform2DEffect
                        {
                            Source = new LuminanceToAlphaEffect { Source = iconImage },
                            TransformMatrix = transform
                        },

                        RedTable   = new float[] { 1 },
                        GreenTable = new float[] { 1 },
                        BlueTable  = new float[] { 1 },
                        AlphaTable = new float[] { 0, 1 }
                    };
                }
                else
                {
                    ds.Transform = transform;

                    // Optional shadow effect.
                    if (appInfo.AddShadow)
                    {
                        var shadow = new ShadowEffect
                        {
                            Source = iconImage,
                            BlurAmount = 12,
                        };

                        ds.DrawImage(shadow);
                    }
                }

                // draw the main icon image.
                ds.DrawImage(iconImage);
            }

            // Save to a file.
            using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting))
            {
                await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png);
            }
        }