private void InitShadow() { if (SelectedPie != null && PieShadowHost != null) { var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; SizeBind = compositor.CreateExpressionAnimation("host.Size"); SizeBind.SetReferenceParameter("host", ElementCompositionPreview.GetElementVisual(PieShadowHost)); ShadowVisual = compositor.CreateSpriteVisual(); ShadowVisual.StartAnimation("Size", SizeBind); Shadow = compositor.CreateDropShadow(); Shadow.Color = Colors.Black; Shadow.Opacity = 0.8f; Shadow.BlurRadius = 6f; Shadow.Mask = SelectedPie.GetAlphaMask(); ShadowVisual.Shadow = Shadow; if (IsShadowEnable) { if (ElementCompositionPreview.GetElementChildVisual(PieShadowHost) == null) { ElementCompositionPreview.SetElementChildVisual(PieShadowHost, ShadowVisual); } } } }
public InsideDropShadowPanel() { _hostVisual = ElementCompositionPreview.GetElementVisual(this); _compositor = _hostVisual.Compositor; // Create a drop shadow _dropShadow = _compositor.CreateDropShadow(); _dropShadow.Color = Color.FromArgb(255, 75, 75, 80); _dropShadow.BlurRadius = 15.0f; // was 15.0f //if (shadowTarget != null) //{ // // Associate the shape of the shadow with the shape of the target element // dropShadow.Mask = shadowTarget.GetAlphaMask(); //} // Create a Visual to hold the shadow _shadowVisual = _compositor.CreateSpriteVisual(); _shadowVisual.Shadow = _dropShadow; // Add the shadow as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(this, _shadowVisual); this.SizeChanged += PanelSizeChanged; }
public static void SetDropShadow(this FrameworkElement element, DropShadow shadow, FrameworkElement sizingElement = null) { var compositor = shadow.Compositor; var shadowVisual = compositor.CreateSpriteVisual(); shadowVisual.Shadow = shadow; if (sizingElement == null) { sizingElement = element; } sizingElement.SizeChanged += (s, e) => { if (e.PreviousSize.Equals(e.NewSize)) { return; } shadowVisual.Size = sizingElement.RenderSize.ToVector2(); }; shadowVisual.Size = sizingElement.RenderSize.ToVector2(); element.SetChildVisual(shadowVisual); }
public FenceWindow(FenceInfo fenceInfo) { InitializeComponent(); DropShadow.ApplyShadows(this); BlurUtil.EnableBlur(Handle); WindowUtil.HideFromAltTab(Handle); DesktopUtil.GlueToDesktop(Handle); var family = new FontFamily("Segoe UI"); titleFont = new Font(family, 17); iconFont = new Font(family, 9); AllowDrop = true; this.fenceInfo = fenceInfo; Text = fenceInfo.Name; Location = new Point(fenceInfo.PosX, fenceInfo.PosY); Width = fenceInfo.Width; Height = fenceInfo.Height; prevHeight = Height; lockedToolStripMenuItem.Checked = fenceInfo.Locked; minifyToolStripMenuItem.Checked = fenceInfo.CanMinify; Minify(); }
private void SetupVisual() { var hostVisual = ElementCompositionPreview.GetElementVisual(element: ShadowHost); var compositor = hostVisual.Compositor; // Create a drop shadow DropShadow dropShadow = compositor.CreateDropShadow(); dropShadow.Color = Color.FromArgb(255, 22, 33, 44); dropShadow.BlurRadius = 15.0f; dropShadow.Offset = new Vector3(12.5f, 2.5f, 0.0f); // Associate the shape of the shadow with the shape of the target element dropShadow.Mask = CircleImage.GetAlphaMask(); // Create a Visual to hold the shadow SpriteVisual shadowVisual = compositor.CreateSpriteVisual(); shadowVisual.Shadow = dropShadow; // Add the shadow as a child of the host (Ellipse) in the visual tree ElementCompositionPreview.SetElementChildVisual(element: ShadowHost, visual: shadowVisual); // Ensure the size of shadow host and shadow visual always stay in sync ExpressionAnimation bindSizeAnimation = compositor.CreateExpressionAnimation(expression: "hostVisual.Size"); bindSizeAnimation.SetReferenceParameter(key: "hostVisual", compositionObject: hostVisual); shadowVisual.StartAnimation(propertyName: nameof(shadowVisual.Size), animation: bindSizeAnimation); }
public static void StartDropShadowBlurRadiusAnimation(this DropShadow shadow, UIElement shadowContainer, Color shadowColor, Vector3?shadowOffset = null, float shadowOpacity = 1.0f, float blurRadius = 16.0f, int duration = 800) { var compositor = shadow.Compositor; shadow.Color = shadowColor; if (shadowOffset == null) { shadowOffset = Vector3.Zero; } shadow.Opacity = shadowOpacity; var shadowBlurAnimation = compositor.CreateScalarKeyFrameAnimation(); shadowBlurAnimation.Duration = TimeSpan.FromMilliseconds(duration); shadowBlurAnimation.InsertKeyFrame(1.0f, blurRadius); shadow.StartAnimation("BlurRadius", shadowBlurAnimation); var shadowOffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); shadowOffsetAnimation.Duration = TimeSpan.FromMilliseconds(duration); shadowOffsetAnimation.InsertKeyFrame(1.0f, shadowOffset.Value); shadow.StartAnimation("Offset", shadowOffsetAnimation); var sprite = compositor.CreateSpriteVisual(); sprite.Size = shadowContainer.RenderSize.ToVector2(); sprite.Shadow = shadow; ElementCompositionPreview.SetElementChildVisual(shadowContainer, sprite); }
private void InitializeShadow() { if (_shadowDirectional != null) { DisposeShadow(); } var compositor = Window.Current.Compositor; _shadowContainer = compositor.CreateContainerVisual(); _shadowAmbientVisual = compositor.CreateSpriteVisual(); _shadowAmbient = compositor.CreateDropShadow(); _shadowAmbientVisual.Shadow = _shadowAmbient; _shadowDirectionalVisual = compositor.CreateSpriteVisual(); _shadowDirectional = compositor.CreateDropShadow(); _shadowDirectionalVisual.Shadow = _shadowDirectional; _shadowContainer.Children.InsertAtTop(_shadowAmbientVisual); _shadowContainer.Children.InsertAtTop(_shadowDirectionalVisual); ElementCompositionPreview.SetElementChildVisual(PlaceholderElement, _shadowContainer); UpdateShadowValues(); }
private void Uninitialize() { if (!IsInitialized) { return; } IsInitialized = false; Parent.OnElementContextUninitialized(this); if (SpriteVisual != null) { SpriteVisual.Shadow = null; SpriteVisual.Dispose(); } Shadow?.Dispose(); ElementCompositionPreview.SetElementChildVisual(Element, null); Element.SizeChanged -= OnElementSizeChanged; SpriteVisual = null; Shadow = null; ElementVisual = null; }
public void AnimateShadow(double depth, double opacity, double radius, Duration duration) { if (!ShadowEnabled) { DropShadow.Opacity = 0; ShadowOpacity = opacity; } else { DropShadow.BeginAnimation(DropShadowEffect.OpacityProperty, new DoubleAnimation() { From = DropShadow.Opacity, To = opacity, Duration = duration, EasingFunction = EasingFunction, }); } DropShadow.BeginAnimation(DropShadowEffect.ShadowDepthProperty, new DoubleAnimation() { From = DropShadow.ShadowDepth, To = depth, Duration = duration, EasingFunction = EasingFunction, }); DropShadow.BeginAnimation(DropShadowEffect.BlurRadiusProperty, new DoubleAnimation() { From = DropShadow.BlurRadius, To = radius, Duration = duration, EasingFunction = EasingFunction, }); }
static void SetShadowProperties(DropShadow dropShadow, IShadow?mauiShadow) { float blurRadius = 10f; float opacity = 1f; Graphics.Color?shadowColor = Colors.Black; Graphics.Point offset = Graphics.Point.Zero; if (mauiShadow != null) { blurRadius = mauiShadow.Radius * 2; opacity = mauiShadow.Opacity; shadowColor = mauiShadow.Paint.ToColor(); offset = mauiShadow.Offset; } dropShadow.BlurRadius = blurRadius; dropShadow.Opacity = opacity; if (shadowColor != null) { dropShadow.Color = shadowColor.ToWindowsColor(); } dropShadow.Offset = new Vector3((float)offset.X, (float)offset.Y, 0); }
public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (SkipRender(context)) { return; } var panel = new TagBuilder("div", "a2-tab-bar", IsInGrid); onRender?.Invoke(panel); MergeAttributes(panel, context); if (DropShadow != ShadowStyle.None) { panel.AddCssClass("drop-shadow"); panel.AddCssClass(DropShadow.ToString().ToLowerInvariant()); } if (Style != TabBarStyle.Default) { panel.AddCssClass($"tab-bar-{Style.ToString().ToKebabCase()}"); } panel.RenderStart(context); RenderButtons(context); if (HasDescription) { RenderDesription(context); } panel.RenderEnd(context); }
private void Initialize(bool forceIfNotLoaded = false) { if (IsInitialized || !_isConnected || (!Element.IsLoaded && !forceIfNotLoaded)) { return; } IsInitialized = true; ElementVisual = ElementCompositionPreview.GetElementVisual(Element); Compositor = ElementVisual.Compositor; Shadow = Compositor.CreateDropShadow(); SpriteVisual = Compositor.CreateSpriteVisual(); SpriteVisual.RelativeSizeAdjustment = Vector2.One; SpriteVisual.Shadow = Shadow; if (Parent.SupportsOnSizeChangedEvent) { Element.SizeChanged += OnElementSizeChanged; } Parent?.OnElementContextInitialized(this); }
public ManageAddresses(int someonesid, AddressOwner addressOwner) { SomeonesId = someonesid; AddressOwner = addressOwner; InitializeComponent(); DropShadow.DropShadowToWindow(this); }
private void InitializeDropShadow(UIElement shadowHost, Shape shadowTarget) { Visual hostVisual = ElementCompositionPreview.GetElementVisual(shadowHost); Compositor compositor = hostVisual.Compositor; // Create a drop shadow dropShadow = compositor.CreateDropShadow(); //dropShadow.Color = Color.FromArgb(255, 75, 75, 80); dropShadow.Color = Colors.Black; dropShadow.BlurRadius = 10; dropShadow.Offset = new Vector3(0, 0, 0); // Associate the shape of the shadow with the shape of the target element dropShadow.Mask = shadowTarget.GetAlphaMask(); CreateAnimation(compositor); // Create a Visual to hold the shadow var shadowVisual = compositor.CreateSpriteVisual(); shadowVisual.Shadow = dropShadow; // Add the shadow as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(shadowHost, shadowVisual); // Make sure size of shadow host and shadow visual always stay in sync var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); shadowVisual.StartAnimation("Size", bindSizeAnimation); }
public FenceWindow(FenceInfo fenceInfo) { InitializeComponent(); DropShadow.ApplyShadows(this); BlurUtil.EnableBlur(Handle); WindowUtil.HideFromAltTab(Handle); //DesktopUtil.GlueToDesktop(Handle); //DesktopUtil.PreventMinimize(Handle); this.titleHeight = fenceInfo.TitleHeight; this.MouseWheel += FenceWindow_MouseWheel; thumbnailProvider.IconThumbnailLoaded += ThumbnailProvider_IconThumbnailLoaded; if (titleHeight < 16 || titleHeight > 100) { titleHeight = 35; } ReloadFonts(); AllowDrop = true; this.fenceInfo = fenceInfo; Text = fenceInfo.Name; Location = new Point(fenceInfo.PosX, fenceInfo.PosY); Width = fenceInfo.Width; Height = fenceInfo.Height; prevHeight = Height; lockedToolStripMenuItem.Checked = fenceInfo.Locked; minifyToolStripMenuItem.Checked = fenceInfo.CanMinify; Minify(); }
private void BuildForeground() { _foregroundBrush = _compositor.CreateSurfaceBrush(_uriSurface.Surface); _foregroundBrush.Stretch = CompositionStretch.Uniform; ForegroundVisual.Brush = _foregroundBrush; // ensure the image size accounts for the margin ForegroundVisual.Size = new Vector2( (float)ActualWidth - (float)ImageMargin.Left - (float)ImageMargin.Right, (float)ActualHeight - (float)ImageMargin.Top - (float)ImageMargin.Bottom); HandleAlignments(); if (_foregroundVisualShadow == null) { _foregroundVisualShadow = _compositor.CreateDropShadow(); _foregroundVisualShadow.Color = Color.FromArgb(255, 75, 75, 80); _foregroundVisualShadow.BlurRadius = 15.0f; _foregroundVisualShadow.Offset = new Vector3(2.5f, 2.5f, 0.0f); ForegroundVisual.Shadow = _foregroundVisualShadow; } _foregroundVisualShadow.Mask = _foregroundBrush; var offsetAnimation = _compositor.CreateVector3KeyFrameAnimation(); offsetAnimation.Target = nameof(Visual.Offset); offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); offsetAnimation.Duration = TimeSpan.FromMilliseconds(1500); var foregroundVisualImplicitAnimations = _compositor.CreateImplicitAnimationCollection(); foregroundVisualImplicitAnimations[nameof(Visual.Offset)] = offsetAnimation; ForegroundVisual.ImplicitAnimations = foregroundVisualImplicitAnimations; }
/// <summary> /// 绘制矩形。可带圆角、阴影 /// </summary> /// <param name="g"></param> /// <param name="rectangle">矩形</param> /// <param name="brush">用于填充的画刷。为null则不填充</param> /// <param name="border">边框描述对象。对象无效则不描边</param> /// <param name="radius">圆角半径</param> /// <param name="shadowColor">阴影颜色</param> /// <param name="shadowRadius">阴影羽化半径</param> /// <param name="offsetX">阴影横向偏移</param> /// <param name="offsetY">阴影纵向偏移</param> public static void DrawRectangle(Graphics g, Rectangle rectangle, Brush brush, Border border, int radius, Color shadowColor, int shadowRadius = 0, int offsetX = 0, int offsetY = 0) { if (shadowColor.A == 0 || (shadowRadius == 0 && offsetX == 0 && offsetY == 0)) { DrawRectangle(g, rectangle, brush, border, radius); return; } GraphicsPath path = null; Bitmap shadow = null; try { path = GetRoundedRectangle(rectangle, radius); shadow = DropShadow.Create(path, shadowColor, shadowRadius); var shadowBounds = DropShadow.GetBounds(rectangle, shadowRadius); shadowBounds.Offset(offsetX, offsetY); g.DrawImageUnscaled(shadow, shadowBounds.Location); DrawPath(g, path, brush, border); } finally { if (path != null) { path.Dispose(); } if (shadow != null) { shadow.Dispose(); } } }
internal override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (SkipRender(context)) { return; } var grid = new TagBuilder("div", "grid", IsInGrid); onRender?.Invoke(grid); MergeAttributes(grid, context); if (Height != null) { grid.MergeStyle("height", Height.Value); } if (_rows != null) { grid.MergeStyle("grid-template-rows", _rows.ToAttribute()); } if (_columns != null) { grid.MergeStyle("grid-template-columns", _columns.ToAttribute()); } if (Background != BackgroundStyle.Default) { grid.AddCssClass("background-" + Background.ToString().ToKebabCase()); } if (DropShadow != ShadowStyle.None) { grid.AddCssClass("drop-shadow"); grid.AddCssClass(DropShadow.ToString().ToLowerInvariant()); } if (Gap != null) { grid.MergeStyle("grid-gap", Gap.ToString()); } if (AutoFlow != AutoFlowMode.Default) { grid.MergeStyle("grid-auto-flow", AutoFlow.ToString().ToKebabCase(delim: " ")); } if (AlignItems != AlignItem.Default) { String aiStyle = AlignItems.ToString().ToLowerInvariant(); if (AlignItems == AlignItem.Top) { aiStyle = "start"; } if (AlignItems == AlignItem.Bottom) { aiStyle = "end"; } grid.MergeStyle("align-items", aiStyle); } grid.RenderStart(context); RenderChildren(context); grid.RenderEnd(context); }
public MessageBox(string title, string message) { InitializeComponent(); DropShadow.DropShadowToWindow(this); TitleLabel.Content = title; MessageText.Text = message; }
internal Shadow() { DefaultStyleKey = typeof(Shadow); var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _shadowVisual = compositor.CreateSpriteVisual(); _dropShadow = compositor.CreateDropShadow(); _shadowVisual.Shadow = _dropShadow; }
public Shadow() { DefaultStyleKey = typeof(Shadow); var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _shadowVisual = compositor.CreateSpriteVisual(); _dropShadow = compositor.CreateDropShadow(); _shadowVisual.Shadow = _dropShadow; }
public fDelRoom() { InitializeComponent(); DropShadow dr = new DropShadow(); dr.ApplyShadows(this); LoadRoom(); }
private void layoutRoot_Unloaded(object sender, RoutedEventArgs e) { _compositor = null; _shadow?.Dispose(); _shadow = null; _shadowContainer?.Dispose(); _shadowContainer = null; }
/// <summary> /// 计算指定边界添加描边和阴影后的边界 /// </summary> public static Rectangle GetBounds(Rectangle rectangle, Border border = null, int shadowRadius = 0, int offsetX = 0, int offsetY = 0) { if (border != null) { rectangle = border.GetBounds(rectangle); } var boundsShadow = DropShadow.GetBounds(rectangle, shadowRadius); boundsShadow.Offset(offsetX, offsetY); return(Rectangle.Union(rectangle, boundsShadow)); }
public DropShadowPanel() : base() { DefaultStyleKey = typeof(DropShadowPanel); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _dropShadow = _compositor.CreateDropShadow(); //_dropShadow.BlurRadius = 4; //_dropShadow.Color = Colors.White; //_dropShadow.Opacity = 0.7f; Visual.Shadow = _dropShadow; //Visual.Scale = new System.Numerics.Vector3(0.91f); }
/// <summary> /// Creates a <see cref="DropShadow"/> from the given <see cref="FrameworkElement"/> /// </summary> /// <param name="element">The source <see cref="FrameworkElement"/> for the <see cref="DropShadow"/></param> /// <param name="target">The optional target <see cref="FrameworkElement"/> to apply the <see cref="DropShadow"/> to (it can be the same as the source <see cref="FrameworkElement"/>)</param> /// <param name="apply">Indicates whether or not to immediately add the <see cref="DropShadow"/> to the visual tree</param> /// <param name="width">The optional width of the <see cref="DropShadow"/> (if null, the element width will be used)</param> /// <param name="height">The optional height of the <see cref="DropShadow"/> (if null, the element height will be used)</param> /// <param name="color">The <see cref="DropShadow"/> color (the default is <see cref="Colors.Black"/></param> /// <param name="opacity">The opacity of the <see cref="DropShadow"/></param> /// <param name="offsetX">The optional horizontal offset of the <see cref="DropShadow"/></param> /// <param name="offsetY">The optional vertical offset of the <see cref="DropShadow"/></param> /// <param name="clipMargin">The optional margin of the clip area of the <see cref="DropShadow"/></param> /// <param name="clipOffsetX">The optional horizontal offset of the clip area of the <see cref="DropShadow"/></param> /// <param name="clipOffsetY">The optional vertical offset of the clip area of the <see cref="DropShadow"/></param> /// <param name="blurRadius">The optional explicit <see cref="DropShadow"/> blur radius</param> /// <param name="maskElement">The optional <see cref="UIElement"/> to use to create an alpha mask for the <see cref="DropShadow"/></param> /// <returns>The <see cref="SpriteVisual"/> that hosts the <see cref="DropShadow"/></returns> public static SpriteVisual AttachVisualShadow( this FrameworkElement element, UIElement target, bool apply, float?width, float?height, Color color, float opacity, float offsetX = 0, float offsetY = 0, Thickness?clipMargin = null, float clipOffsetX = 0, float clipOffsetY = 0, float?blurRadius = null, UIElement maskElement = null) { // Setup the shadow Visual elementVisual = ElementCompositionPreview.GetElementVisual(element); Compositor compositor = elementVisual.Compositor; SpriteVisual sprite = compositor.CreateSpriteVisual(); DropShadow shadow = compositor.CreateDropShadow(); shadow.Color = color; shadow.Opacity = opacity; shadow.Offset = new Vector3(offsetX, offsetY, 0); if (blurRadius != null) { shadow.BlurRadius = blurRadius.Value; } sprite.Shadow = shadow; sprite.Size = new Vector2(width ?? (float)element.Width, height ?? (float)element.Height); // Clip it (if needed) and add it to the visual tree if (clipMargin != null || clipOffsetX > 0 || clipOffsetY > 0) { InsetClip clip = compositor.CreateInsetClip( (float)(clipMargin?.Left ?? 0), (float)(clipMargin?.Top ?? 0), (float)(clipMargin?.Right ?? 0), (float)(clipMargin?.Bottom ?? 0)); clip.Offset = new Vector2(clipOffsetX, clipOffsetY); sprite.Clip = clip; } // Alpha mask switch (maskElement) { case null: break; case Shape shape: shadow.Mask = shape.GetAlphaMask(); break; case Image image: shadow.Mask = image.GetAlphaMask(); break; case TextBlock textBlock: shadow.Mask = textBlock.GetAlphaMask(); break; } if (apply) { ElementCompositionPreview.SetElementChildVisual(target, sprite); } return(sprite); }
public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (SkipRender(context)) { return; } var panel = new TagBuilder("a2-panel", null, IsInGrid); MergeBindingAttributeBool(panel, context, ":initial-collapsed", nameof(Collapsed), Collapsed); MergeBindingAttributeBool(panel, context, ":collapsible", nameof(Collapsible), Collapsible); if (!String.IsNullOrEmpty(TestId) && context.IsDebugConfiguration) { panel.MergeAttribute("test-id", TestId); } panel.AddCssClassBool(Compact, "compact"); if (!HasHeader) { panel.MergeAttribute(":no-header", "true"); } var sb = GetBinding(nameof(Style)); if (sb != null) { panel.MergeAttribute(":panel-style", sb.GetPathFormat(context)); } else if (Style != PaneStyle.Default) { panel.MergeAttribute("panel-style", Style.ToString().ToLowerInvariant()); } MergeAttributes(panel, context, MergeAttrMode.Visibility); if (Background != BackgroundStyle.Default) { panel.AddCssClass("background-" + Background.ToString().ToKebabCase()); } if (Height != null) { panel.MergeStyle("height", Height.Value); } if (DropShadow != ShadowStyle.None) { panel.AddCssClass("drop-shadow"); panel.AddCssClass(DropShadow.ToString().ToLowerInvariant()); } panel.RenderStart(context); RenderHeader(context); var content = new TagBuilder("div", "panel-content"); MergeAttributes(content, context, MergeAttrMode.Margin | MergeAttrMode.Wrap | MergeAttrMode.Tip); content.RenderStart(context); RenderChildren(context); content.RenderEnd(context); panel.RenderEnd(context); }
public Form1() { InitializeComponent(); this.DoubleBuffered = true; CheckForIllegalCrossThreadCalls = false; this.MouseDown += Form1_MouseDown; foreach (Control c in Controls) { c.MouseDown += Form1_MouseDown; } DropShadow.Shadow(this); }
protected override void OnRender(ISurface <ColorBgra> dstCropped, PointInt32 renderOffset) { RectInt32 num = this.Bounds <ColorBgra>(); using (RenderArgs args = new RenderArgs(dstCropped)) { args.Graphics.Clear(Color.Transparent); this.sourceOutset.Render(dstCropped, renderOffset); args.Graphics.TranslateTransform((float)-renderOffset.X, (float)-renderOffset.Y, MatrixOrder.Append); DropShadow.DrawInside(args.Graphics, new Rectangle(0, 0, base.Width, base.Height), this.shadowExtent); } }
/// <summary> /// Initializes a new instance of the <see cref="DropShadowPanel"/> class. /// </summary> public DropShadowPanel() { this.DefaultStyleKey = typeof(DropShadowPanel); if (IsSupported) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _shadowVisual = compositor.CreateSpriteVisual(); _dropShadow = compositor.CreateDropShadow(); _shadowVisual.Shadow = _dropShadow; } }
public override int GetHashCode() { unchecked { int hashCode = (int)Side; hashCode = (hashCode * 397) ^ Color.GetHashCode(); hashCode = (hashCode * 397) ^ Size.GetHashCode(); hashCode = (hashCode * 397) ^ (int)Style; hashCode = (hashCode * 397) ^ ShadowSize.GetHashCode(); hashCode = (hashCode * 397) ^ Topmost.GetHashCode(); hashCode = (hashCode * 397) ^ DropShadow.GetHashCode(); return(hashCode); } }
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Get backing visual from shadow container and interop compositor _shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer); _compositor = _shadowContainer.Compositor; // Get CompositionImage, its sprite visual _image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer); _imageVisual = _image.SpriteVisual; // Add drop shadow to image visual _shadow = _compositor.CreateDropShadow(); _imageVisual.Shadow = _shadow; // Initialize sliders to shadow defaults - with the exception of offset BlurRadiusSlider.Value = _shadow.BlurRadius; //defaults to 9.0f OffsetXSlider.Value = _shadow.Offset.X; //defaults to 0 OffsetYSlider.Value = _shadow.Offset.Y; //defaults to 0 RedSlider.Value = _shadow.Color.R; //defaults to 0 (black.R) GreenSlider.Value = _shadow.Color.G; //defaults to 0 (black.G) BlueSlider.Value = _shadow.Color.B; //defaults to 0 (black.B) // Load mask asset onto surface using helpers in SamplesCommon _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _imageMaskSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Assets/CircleMask.png")); // Create surface brush for mask CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush(); mask.Surface = _imageMaskSurface.Surface; // Get surface brush from composition image CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush; // Create mask brush for toggle mask functionality _maskBrush = _compositor.CreateMaskBrush(); _maskBrush.Mask = mask; _maskBrush.Source = source; // Initialize toggle mask and animation to false _isMaskEnabled = false; _isAnimationEnabled = false; }
/// <summary> /// Disposes the resources /// </summary> public void Dispose() { // Clean up resources _compositor = null; Source = null; DataContext = null; Foreground = null; Background = null; _scheduledObject = null; _currentObject = null; // Clean up Composition Objects _imageSurface?.Dispose(); _imageSurface = null; _nextImageSurface?.Dispose(); _nextImageSurface = null; _frameLayerMask?.Dispose(); _frameLayerMask = null; _placeholderContentMask?.Dispose(); _placeholderContentMask = null; _placeholderContentBrush?.Dispose(); _placeholderContentBrush = null; _nextSurfaceBrush?.Dispose(); _nextSurfaceBrush = null; _rootContainer?.Dispose(); _rootContainer = null; _shadowVisual?.Dispose(); _shadowVisual = null; _frameLayer?.Dispose(); _frameLayer = null; _frameBackgroundVisual?.Dispose(); _frameBackgroundVisual = null; _placeholderBackgroundVisual?.Dispose(); _placeholderBackgroundVisual = null; _placeholderContentVisual?.Dispose(); _placeholderContentVisual = null; _frameContentVisual?.Dispose(); _frameContentVisual = null; _nextVisualContent?.Dispose(); _nextVisualContent = null; _shadow?.Dispose(); _shadow = null; _layerEffectBrush?.Dispose(); _layerEffectBrush = null; _imageOptions = null; _zoomInAnimationGroup?.Dispose(); _zoomInAnimationGroup = null; _fadeOutAnimation?.Dispose(); _fadeOutAnimation = null; _fadeInAnimation?.Dispose(); _fadeInAnimation = null; _colorAnimation?.Dispose(); _colorAnimation = null; _alignXAnimation?.Dispose(); _alignXAnimation = null; _alignYAnimation?.Dispose(); _alignYAnimation = null; _offsetAnimation?.Dispose(); _offsetAnimation = null; _scaleAnimation?.Dispose(); _scaleAnimation = null; // Dispose the generator at the end to allow the // dependant composition objects to unsubscribe from // generator events _generator?.Dispose(); _generator = null; }
/// <summary> /// Handles the Arrange pass during Layout /// </summary> /// <param name="finalSize">Final Size of the control</param> /// <returns>Total size occupied by the Children</returns> protected override Size ArrangeOverride(Size finalSize) { // Taking into account the BorderThickness and Padding var borders = BorderThickness; var padding = Padding; var corners = CornerRadius; var borderSize = borders.CollapseThickness(); var paddingSize = padding.CollapseThickness(); // Calculate the Offset for the frameVisual var left = (borders.Left + padding.Left).Single(); var top = (borders.Top + padding.Top).Single(); // Calculate the Dimensions of the frameVisual var width = Math.Max(0, finalSize.Width - borderSize.Width - paddingSize.Width).Single(); var height = Math.Max(0, finalSize.Height - borderSize.Height - paddingSize.Height).Single(); // Set the Size and Offset of visuals in the ImageFrame var frameSize = new Vector2(width, height); _rootContainer.Size = frameSize; _frameLayer.Size = frameSize; _frameBackgroundVisual.Size = frameSize; _frameContentVisual.Size = frameSize; _placeholderContentVisual.Size = frameSize; _placeholderBackgroundVisual.Size = frameSize; _shadowVisual.Size = frameSize; _nextVisualContent.Size = frameSize; _rootContainer.Offset = new Vector3(left, top, 0); // Update the frameLayerMask in case the CornerRadius or // BorderThickness or Padding has changed var pathInfo = new CompositionPathInfo(corners, borders, padding, false); using (var geometry = CompositionGenerator.GenerateGeometry(_generator.Device, frameSize.ToSize(), pathInfo, Vector2.Zero)) { _frameLayerMask.Redraw(_frameLayer.Size.ToSize(), geometry); } // If the FrameBackground has changed since the last time it was // applied to the frameBackgroundVisual, then animate the brush's // color to the new color. var brush = _frameBackgroundVisual.Brush as CompositionColorBrush; if (brush != null) { if (!brush.Color.Equals(FrameBackground)) { // If we are rendering fast, then no need to animate. // Just set the final value. if (RenderFast) { brush.Color = FrameBackground; } else { _colorAnimation.InsertKeyFrame(1f, FrameBackground); brush.StartAnimation("Color", _colorAnimation); } } } // If the PlaceholderBackground has changed since the last time it was // applied to the _placeholderBackgroundVisual, then update the brush's // color to the new color. brush = _placeholderBackgroundVisual.Brush as CompositionColorBrush; if (brush != null) { if (!brush.Color.Equals(PlaceholderBackground)) { brush.Color = PlaceholderBackground; } } // Redraw the placeholder content with the latest placeholder color _placeholderContentMask.Redraw(PlaceholderColor, PlaceholderBackground); // Set the stretch property of placeholder content's brush according to its size if ((width > PlaceholderSize.Width) && (height > PlaceholderSize.Height)) { _placeholderContentBrush.Stretch = CompositionStretch.None; } else { _placeholderContentBrush.Stretch = CompositionStretch.Uniform; } // Update the imageOptions _imageOptions.Stretch = Stretch; _imageOptions.HorizontalAlignment = AlignX; _imageOptions.VerticalAlignment = AlignY; _imageOptions.Interpolation = Interpolation; _imageOptions.SurfaceBackgroundColor = Colors.Transparent; _imageOptions.AutoResize = !RenderOptimized; // If Source is valid then try loading/refreshing the ImageSurface if (Source != null) { if (_imageSurface != null) { // Resize the ImageSurface to the new size _imageSurface.Resize(frameSize.ToSize(), _imageOptions); // Update the surface brush based on the Stretch and Alignment options if (RenderFast) { // Use no animations to update alignment if we are rendering fast (_frameContentVisual.Brush as CompositionSurfaceBrush)?.UpdateSurfaceBrushOptions(Stretch, AlignX, AlignY); } else { // Update stretch and alignment using animation (_frameContentVisual.Brush as CompositionSurfaceBrush)?.UpdateSurfaceBrushOptions(Stretch, AlignX, AlignY, _alignXAnimation, _alignYAnimation); } } else { // Load the Source to the ImageSurface ScheduleNextLoad(); } } else { // If the frameContentVisual had any previous brush, fade it out if (_imageSurface == null) { // Make the frameVisualContent transparent _frameContentVisual.Brush = _compositor.CreateColorBrush(Colors.Transparent); DisplayPlaceHolder(); _engineState = ImageEngineState.Idle; } } // Handle shadow if (DisplayShadow) { // If OptimizeShadow is True then use the sharedShadow otherwise use the instance shadow var shadow = OptimizeShadow ? ShadowProvider.GetSharedShadow(_compositor) : (_shadow ?? (_shadow = _compositor.CreateDropShadow())); shadow.BlurRadius = ShadowBlurRadius.Single(); shadow.Color = ShadowColor; shadow.Offset = new Vector3(ShadowOffsetX.Single(), ShadowOffsetY.Single(), 0); shadow.Opacity = ShadowOpacity.Single(); shadow.Mask = _layerEffectBrush.GetSourceParameter("mask"); _shadowVisual.Shadow = shadow; } else { _shadowVisual.Shadow = null; } return base.ArrangeOverride(finalSize); }
private void InitShadow() { grdLowerLayer.UpdateLayout(); _shadowContainer = CompositionManager.GetVisual(grdLowerLayer); _shadowContainer.Size = new Vector2((float)grdLowerLayer.ActualWidth, (float)grdLowerLayer.ActualHeight); _shadowContainer.Offset = new Vector3(0, 0, 0); _compositor = CompositionManager.GetCompositor(_shadowContainer); _spriteVisual = _compositor.CreateSpriteVisual(); _spriteVisual.Size = new Vector2((float)grdLowerLayer.ActualWidth + 10, (float)grdLowerLayer.ActualHeight + 10); _spriteVisual.Offset = new Vector3(-5, -5, 0); // Add drop shadow to image visual _shadow = _compositor.CreateDropShadow(); _shadow.Offset = new System.Numerics.Vector3(0, 0, 0); _shadow.Color = Windows.UI.Colors.Black; _shadow.Opacity = 0.3f; _spriteVisual.Shadow = _shadow; _shadowContainer.Children.InsertAtBottom(_spriteVisual); }
private void layoutRoot_Unloaded(object sender, RoutedEventArgs e) { _compositor = null; _shadow?.Dispose(); _shadow = null; _shadowContainer?.Dispose(); _shadowContainer = null; }
/// <summary> /// Gets the instance of the shared DropShadow /// </summary> /// <param name="compositor">Compositor</param> /// <returns>DropShadow</returns> internal static DropShadow GetSharedShadow(Compositor compositor) { if (_sharedShadow == null) { lock (ShadowLock) { if (_sharedShadow == null) { _sharedShadow = compositor.CreateDropShadow(); } } } return _sharedShadow; }