本文整理汇总了C#中Compositor.CreateColorBrush方法的典型用法代码示例。如果您正苦于以下问题:C# Compositor.CreateColorBrush方法的具体用法?C# Compositor.CreateColorBrush怎么用?C# Compositor.CreateColorBrush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compositor
的用法示例。
在下文中一共展示了Compositor.CreateColorBrush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupVisuals
public void SetupVisuals()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var blueSquareVisual = _compositor.CreateSpriteVisual();
blueSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
blueSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Create the Green Square with 20% opacity
var greenSquareVisual = _compositor.CreateSpriteVisual();
greenSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
greenSquareVisual.Offset = new Vector3(150.00f, 100.00f, 0.00f);
greenSquareVisual.Opacity = 0.20f;
// Add the Visuals to the tree
ContainerVisual mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, mainContainer);
mainContainer.Children.InsertAtTop(blueSquareVisual);
mainContainer.Children.InsertAtTop(greenSquareVisual);
_source = greenSquareVisual;
_target = blueSquareVisual;
}
示例2: Parallax_Expression
public void Parallax_Expression()
{
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var blueSquareVisual = _compositor.CreateSpriteVisual();
blueSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
blueSquareVisual.Size = new System.Numerics.Vector2(100.0f, 100.0f);
blueSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Create the Green Square
var greenSquareVisual = _compositor.CreateSpriteVisual();
greenSquareVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
greenSquareVisual.Size = new System.Numerics.Vector2(50.0f, 50.0f);
greenSquareVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Add the Blue and Green square visuals to the tree
ContainerVisual mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, mainContainer);
mainContainer.Children.InsertAtTop(blueSquareVisual);
mainContainer.Children.InsertAtTop(greenSquareVisual);
_foreground = greenSquareVisual;
_background = blueSquareVisual;
}
示例3: SamplePage_Loaded
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Acquire Compositor and set up basic visual tree structure
_xamlRoot = ElementCompositionPreview.GetElementVisual(MainGrid);
_compositor = _xamlRoot.Compositor;
_root = _compositor.CreateContainerVisual();
_mainImage = Image.SpriteVisual;
ElementCompositionPreview.SetElementChildVisual(ImageContainer, _root);
_root.Children.InsertAtTop(_mainImage);
// Add visual indicators to show the position of AnchorPoint and CenterPoint
_indicatorContainer = _compositor.CreateContainerVisual();
_apIndicator = _compositor.CreateSpriteVisual();
_apIndicator.Size = new Vector2(10, 10);
_apIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
_apIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Red);
_cpIndicator = _compositor.CreateSpriteVisual();
_cpIndicator.Size = new Vector2(10, 10);
_cpIndicator.AnchorPoint = new Vector2(0.5f, 0.5f);
_cpIndicator.Brush = _compositor.CreateColorBrush(Windows.UI.Colors.Green);
_root.Children.InsertAtTop(_indicatorContainer);
_indicatorContainer.Children.InsertAtTop(_cpIndicator);
_indicatorContainer.Children.InsertAtTop(_apIndicator);
// Specify a clip to prevent image from overflowing into the sliders list
Visual containerGrid = ElementCompositionPreview.GetElementVisual(ContentGrid);
containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
ContentGrid.SizeChanged += (s, a) =>
{
containerGrid.Size = new Vector2((float)ContentGrid.ActualWidth, (float)ContentGrid.ActualHeight);
};
containerGrid.Clip = _compositor.CreateInsetClip();
// Create list of properties to add as sliders
var list = new List<TransformPropertyModel>();
list.Add(new TransformPropertyModel(AnchorPointXAction) { PropertyName = "AnchorPoint - X (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.X });
list.Add(new TransformPropertyModel(AnchorPointYAction) { PropertyName = "AnchorPoint - Y (Red)", MinValue = -1, MaxValue = 2, StepFrequency = 0.01f, Value = _mainImage.AnchorPoint.Y });
list.Add(new TransformPropertyModel(CenterPointXAction) { PropertyName = "CenterPoint - X (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.X });
list.Add(new TransformPropertyModel(CenterPointYAction) { PropertyName = "CenterPoint - Y (Green)", MinValue = -600, MaxValue = 600, StepFrequency = 1f, Value = _mainImage.CenterPoint.Y });
list.Add(new TransformPropertyModel(RotationAction) { PropertyName = "Rotation (in Degrees)", MinValue = 0, MaxValue = 360, StepFrequency = 1f, Value = _mainImage.RotationAngleInDegrees });
list.Add(new TransformPropertyModel(ScaleXAction) { PropertyName = "Scale - X", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.X });
list.Add(new TransformPropertyModel(ScaleYAction) { PropertyName = "Scale - Y", MinValue = 0, MaxValue = 3, StepFrequency = 0.01f, Value = _mainImage.Scale.Y });
list.Add(new TransformPropertyModel(OffsetXAction) { PropertyName = "Offset - X", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.X });
list.Add(new TransformPropertyModel(OffsetYAction) { PropertyName = "Offset - Y", MinValue = -200, MaxValue = 200, StepFrequency = 1f, Value = _mainImage.Offset.Y });
XamlItemsControl.ItemsSource = list;
}
示例4: SetupVisual
// Define and setup the Green Square Visual that will be animated
public void SetupVisual()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = (ContainerVisual)ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
_linear = _compositor.CreateLinearEasingFunction();
// Create Green Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
colorVisual.Size = new Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(250.0f, 50.0f, 0.0f);
colorVisual.CenterPoint = new Vector3(75.0f, 75.0f, 0.0f);
_target = colorVisual;
// Create Blue Square
var colorVisual2 = _compositor.CreateSpriteVisual();
colorVisual2.Brush = _compositor.CreateColorBrush(Colors.Aqua);
colorVisual2.Size = new Vector2(200.0f, 150.0f);
colorVisual2.Offset = new Vector3(25.0f, 50.0f, 0.0f);
colorVisual2.IsVisible = false;
_target2 = colorVisual2;
// Add the Blue and Green square visuals to the tree
_mainContainer = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(Container, _mainContainer);
_mainContainer.Children.InsertAtTop(_target);
_mainContainer.Children.InsertAtTop(_target2);
// Create Scoped batch for animations
_batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
// Add Animation1 to the batch
Animation1(_target);
// Suspend the batch to exclude an animation
_batch.Suspend();
// Exluding Animation2 from batch
Animation2(_target);
// Resuming the batch to collect additional animations
_batch.Resume();
// Add Animation3 to the batch
Animation3(_target);
// Batch is ended an no objects can be added
_batch.End();
// Method triggered when batch completion event fires
_batch.Completed += OnBatchCompleted;
}
示例5: ShowVisual_Click
private void ShowVisual_Click(object sender, RoutedEventArgs e)
{
// Initialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(root);
_compositor = _root.Compositor;
// Generate the Green Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Green);
colorVisual.Size = new Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(50.0f, 50.0f, 0.0f);
// Add the image to the tree
ElementCompositionPreview.SetElementChildVisual(root, colorVisual);
_target = colorVisual;
}
示例6: SetupVisual
// Defines the Visual to be animated in this sample and adds it to the Visual Tree
public void SetupVisual()
{
// Intialize the Compositor
_compositor = new Compositor();
_root = ElementCompositionPreview.GetElementVisual(Container);
_compositor = _root.Compositor;
// Create the Blue Square
var colorVisual = _compositor.CreateSpriteVisual();
colorVisual.Brush = _compositor.CreateColorBrush(Colors.Blue);
colorVisual.Size = new System.Numerics.Vector2(150.0f, 150.0f);
colorVisual.Offset = new Vector3(100.00f, 50.00f, 0.00f);
// Add the Visual to the tree
ElementCompositionPreview.SetElementChildVisual(Container, colorVisual);
_target = colorVisual;
}
示例7: CompositionImage
public CompositionImage()
{
this.DefaultStyleKey = typeof(CompositionImage);
this.Background = new SolidColorBrush(Colors.Transparent);
this._stretchMode = CompositionStretch.Uniform;
this.Loading += CompImage_Loading;
this.Unloaded += CompImage_Unloaded;
this.SizeChanged += CompImage_SizeChanged;
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// Intialize the statics as needed
if (!_staticsInitialized)
{
_defaultPlaceholderBrush = _compositor.CreateColorBrush(Colors.DarkGray);
TimeSpan duration = TimeSpan.FromMilliseconds(1000);
_fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeOutAnimation.InsertKeyFrame(0, 1);
_fadeOutAnimation.InsertKeyFrame(1, 0);
_fadeOutAnimation.Duration = duration;
_scaleAnimation = _compositor.CreateVector2KeyFrameAnimation();
_scaleAnimation.InsertKeyFrame(0, new Vector2(1.25f, 1.25f));
_scaleAnimation.InsertKeyFrame(1, new Vector2(1, 1));
_scaleAnimation.Duration = duration;
_staticsInitialized = true;
}
// Initialize the surface loader if needed
if (!SurfaceLoader.IsInitialized)
{
SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
}
_placeholderDelay = TimeSpan.FromMilliseconds(50);
_surfaceBrush = _compositor.CreateSurfaceBrush(null);
}
示例8: Clock_Loaded
private void Clock_Loaded(object sender, RoutedEventArgs e)
{
_root = Container.GetVisual();
_compositor = _root.Compositor;
// Background
_background = _compositor.CreateSpriteVisual();
_background.Size = new Vector2(200.0f, 200.0f);
var _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);
CompositionImageOptions options = new CompositionImageOptions()
{
DecodeWidth = 400,
DecodeHeight = 400,
};
var _image = _imageFactory.CreateImageFromUri(FaceImage, options);
_background.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
_root.Children.InsertAtTop(_background);
// Hour Hand
options = new CompositionImageOptions()
{
DecodeWidth = 72,
DecodeHeight = 240,
};
_hourhand = _compositor.CreateSpriteVisual();
_hourhand.Size = new Vector2(24.0f, 80.0f);
_image = _imageFactory.CreateImageFromUri(HourHandImage, options);
_hourhand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
_hourhand.CenterPoint = new Vector3(12.0f, 70.0f, 0);
_hourhand.Offset = new Vector3(88.0f, 30.0f, 0);
_root.Children.InsertAtTop(_hourhand);
// Minute Hand
options = new CompositionImageOptions()
{
DecodeWidth = 48,
DecodeHeight = 270,
};
_image = _imageFactory.CreateImageFromUri(MinuteHandImage, options);
_minutehand = _compositor.CreateSpriteVisual();
_minutehand.Size = new Vector2(16.0f, 90.0f);
_minutehand.Brush = _compositor.CreateSurfaceBrush(_image.Surface);
_minutehand.CenterPoint = new Vector3(8.0f, 85.0f, 0);
_minutehand.Offset = new Vector3(92.0f, 15.0f, 0);
_root.Children.InsertAtTop(_minutehand);
SetHoursAndMinutes();
// Second Hand
_secondhand = _compositor.CreateSpriteVisual();
_secondhand.Size = new Vector2(1.0f, 90.0f);
_secondhand.Brush = _compositor.CreateColorBrush(Colors.Red);
_secondhand.CenterPoint = new Vector3(0.5f, 90.0f, 0);
_secondhand.Offset = new Vector3(99.5f, 10.0f, 0);
_root.Children.InsertAtTop(_secondhand);
_secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6;
_timer.Start();
}
示例9: OnApplyTemplate
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
_trackBackground = GetTemplateChild("PART_TrackBackground") as Rectangle;
_root = GetVisual(_trackBackground);
_compositor = _root.Compositor;
_track = _compositor.CreateSpriteVisual();
_track.Brush = _compositor.CreateColorBrush(Color.FromArgb(255, 0, 120, 215));
_root.Children.InsertAtTop(_track);
//_track.getV
//_trackBackground
//
//_thumb = GetTemplateChild("PART_Thumb") as ContentControl;
//if (_thumb != null)
//{
// _thumb.PointerPressed += (s, e) => { TouchSliderDragValueHandler.OnPointerPressed(s as UIElement, this, e); };
// _thumb.PointerMoved += (s, e) => { TouchSliderDragValueHandler.OnPointerMoved(this, e); };
// _thumb.PointerReleased += (s, e) => { TouchSliderDragValueHandler.OnPointerReleased(s as UIElement, this, e); };
//}
}
示例10: OnLoaded
private void OnLoaded(object sender, RoutedEventArgs e)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
_width = 300f;
_height = 300f;
// Create the combined geometry
var ellipse1 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.45f * _width, 0.225f * _height);
var ellipse2 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.225f * _width, 0.45f * _height);
_combinedGeometry = ellipse1.CombineWith(ellipse2, Matrix3x2.Identity, CanvasGeometryCombine.Union);
// Create custom shaped visual using CompositionMaskBrush
_visual1 = _compositor.CreateSpriteVisual();
_visual1.Size = new Vector2(_width, _height);
_visual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);
var visualChild = _compositor.CreateSpriteVisual();
visualChild.Size = new Vector2(_width * 0.75f, _height * 0.75f);
visualChild.Offset = new Vector3(_width*0.125f, _height*0.125f, 0);
_visual1.Children.InsertAtTop(visualChild);
// Create the CompositionMask
var compositionMask = _generator.CreateMaskSurface(_visual1.Size.ToSize(), _combinedGeometry);
// Create SurfaceBrush from CompositionMask
var mask = _compositor.CreateSurfaceBrush(compositionMask.Surface);
var source = _compositor.CreateColorBrush(Color.FromArgb(255, 0, 173, 239));
// Create mask brush
var maskBrush = _compositor.CreateMaskBrush();
maskBrush.Mask = mask;
maskBrush.Source = source;
_visual1.Brush = maskBrush;
ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, _visual1);
// Create custom shaped visual using CompositionMaskBrush
_visual2 = _compositor.CreateSpriteVisual();
_visual2.Size = new Vector2(_width, _height);
_visual2.Offset = new Vector3(((CompositionGrid2.ActualWidth - _width) / 2).Single(),
((CompositionGrid2.ActualHeight - _height) / 2).Single(), 0);
// Create the CompositionMask filled with color
var compositionMask2 =
_generator.CreateGeometrySurface(_visual2.Size.ToSize(), _combinedGeometry, Color.FromArgb(192, 192, 0, 0));
// Create SurfaceBrush from CompositionMask
var surfaceBrush = _compositor.CreateSurfaceBrush(compositionMask2.Surface);
_visual2.Brush = surfaceBrush;
ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, _visual2);
// Initialize the visuals for the Animated Canvas
// Create the container to host the visuals
var container = _compositor.CreateContainerVisual();
container.Size = new Vector2(CompositionGrid3.ActualWidth.Single(), CompositionGrid3.ActualHeight.Single());
// Background Visual
_bgVisual = _compositor.CreateSpriteVisual();
_bgVisual.Size = new Vector2(_width, _height);
_bgVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(),
((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0);
var radians = ((45f*Math.PI)/180).Single();
var bgGeometry = _combinedGeometry.Transform(Matrix3x2.CreateRotation(radians, new Vector2(_width/2, _height/2)));
var bgMask = _generator.CreateGeometrySurface(_bgVisual.Size.ToSize(), bgGeometry, Color.FromArgb(255, 0, 173, 239));
var bgBrush = _compositor.CreateSurfaceBrush(bgMask.Surface);
_bgVisual.Brush = bgBrush;
container.Children.InsertAtBottom(_bgVisual);
// Animated Visual
_animatedVisual = _compositor.CreateSpriteVisual();
_animatedVisual.Size = new Vector2(_width, _height);
_animatedVisual.Offset = new Vector3(((CompositionGrid3.ActualWidth - _width) / 2).Single(),
((CompositionGrid3.ActualHeight - _height) / 2).Single(), 0);
// Create the Excluded geometry
_outerGeometry = CanvasGeometry.CreateRectangle(_generator.Device, 0, 0, _width, _height);
var excludedGeometry = _outerGeometry.CombineWith(_combinedGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Exclude);
// Create the CompositionMask
_animatedMaskSurface = _generator.CreateGeometrySurface(_animatedVisual.Size.ToSize(), excludedGeometry, Color.FromArgb(192, 192, 0, 0));
var animBrush = _compositor.CreateSurfaceBrush(_animatedMaskSurface.Surface);
_animatedVisual.Brush = animBrush;
container.Children.InsertAtTop(_animatedVisual);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, container);
}
示例11: Clock_Loaded
private void Clock_Loaded(object sender, RoutedEventArgs e)
{
Face.Fill = FaceColor;
_root = Container.GetVisual();
_compositor = _root.Compositor;
// Hour Ticks
if (ShowTicks)
{
SpriteVisual tick;
for (int i = 0; i < 12; i++)
{
tick = _compositor.CreateSpriteVisual();
tick.Size = new Vector2(4.0f, 20.0f);
tick.Brush = _compositor.CreateColorBrush(Colors.Silver);
tick.Offset = new Vector3(98.0f, 0.0f, 0);
tick.CenterPoint = new Vector3(2.0f, 100.0f, 0);
tick.RotationAngleInDegrees = i * 30;
_root.Children.InsertAtTop(tick);
}
}
// Second Hand
_secondhand = _compositor.CreateSpriteVisual();
_secondhand.Size = new Vector2(2.0f, 120.0f);
_secondhand.Brush = _compositor.CreateColorBrush(Colors.Red);
_secondhand.CenterPoint = new Vector3(1.0f, 100.0f, 0);
_secondhand.Offset = new Vector3(99.0f, 0.0f, 0);
_root.Children.InsertAtTop(_secondhand);
_secondhand.RotationAngleInDegrees = (float)(int)DateTime.Now.TimeOfDay.TotalSeconds * 6;
// Hour Hand
_hourhand = _compositor.CreateSpriteVisual();
_hourhand.Size = new Vector2(4.0f, 100.0f);
_hourhand.Brush = _compositor.CreateColorBrush(Colors.Black);
_hourhand.CenterPoint = new Vector3(2.0f, 80.0f, 0);
_hourhand.Offset = new Vector3(98.0f, 20.0f, 0);
_root.Children.InsertAtTop(_hourhand);
// Minute Hand
_minutehand = _compositor.CreateSpriteVisual();
_minutehand.Size = new Vector2(4.0f, 120.0f);
_minutehand.Brush = _compositor.CreateColorBrush(Colors.Black);
_minutehand.CenterPoint = new Vector3(2.0f, 100.0f, 0);
_minutehand.Offset = new Vector3(98.0f, 0.0f, 0);
_root.Children.InsertAtTop(_minutehand);
SetHoursAndMinutes();
// Add XAML element.
if (BackgroundImage != null)
{
var xaml = new Image();
xaml.Source = BackgroundImage;
xaml.Height = 200;
xaml.Width = 200;
Container.Children.Add(xaml);
}
_timer.Start();
}
示例12: OnLoaded
private async void OnLoaded(object sender, RoutedEventArgs e)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
var distance = 4f;
var visualSize = new Vector2(225, 150);
var vRefHeight = visualSize.Y + (visualSize.Y * 0.7f) + distance;
var hRefWidth = visualSize.X + (visualSize.X * 0.7f) + distance;
var vRefLeft = (float)(CompositionGrid1.ActualWidth - visualSize.X) / 2f;
var vRefTop = (float)(CompositionGrid1.ActualHeight - vRefHeight) / 2f;
var hRefLeft = (float)(CompositionGrid1.ActualWidth - hRefWidth) / 2f;
var hRefTop = (float)(CompositionGrid1.ActualHeight - visualSize.Y) / 2f;
var surfaceImage = await _generator.CreateImageSurfaceAsync(new Uri("ms-appx:///Assets/Images/Car.jpg"),
visualSize.ToSize(), ImageSurfaceOptions.Default);
var surfaceBrush = _compositor.CreateSurfaceBrush(surfaceImage.Surface);
var visual1 = _compositor.CreateSpriteVisual();
visual1.Size = visualSize;
visual1.Offset = new Vector3(vRefLeft, vRefTop, 0);
visual1.Brush = surfaceBrush;
_generator.CreateReflection(visual1, distance);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, visual1);
var invertEffect = new InvertEffect()
{
Source = new CompositionEffectSourceParameter("source")
};
var invertEffectFactory = _compositor.CreateEffectFactory(invertEffect);
var invertBrush = invertEffectFactory.CreateBrush();
invertBrush.SetSourceParameter("source", surfaceBrush);
var visual2 = _compositor.CreateSpriteVisual();
visual2.Size = visualSize;
visual2.Offset = new Vector3(hRefLeft, hRefTop, 0);
visual2.Brush = invertBrush;
_generator.CreateReflection(visual2, distance, 0.7f, ReflectionLocation.Right);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, visual2);
var visual3 = _compositor.CreateSpriteVisual();
visual3.Size = visualSize;
visual3.Offset = new Vector3(vRefLeft, vRefTop, 0);
visual3.Brush = surfaceBrush;
var inVisual = _compositor.CreateSpriteVisual();
inVisual.Size = new Vector2(80, 80);
inVisual.Offset = new Vector3(20, 10, 0);
inVisual.Brush = _compositor.CreateColorBrush(Colors.Yellow);
var inVisual2 = _compositor.CreateSpriteVisual();
inVisual2.Size = new Vector2(80, 80);
inVisual2.Offset = new Vector3(60, 60, 0);
inVisual2.Brush = _compositor.CreateColorBrush(Colors.Blue);
visual3.Children.InsertAtTop(inVisual2);
visual3.Children.InsertAtTop(inVisual);
_generator.CreateReflection(visual3, distance, 0.7f, ReflectionLocation.Bottom);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, visual3);
var visual4 = _compositor.CreateSpriteVisual();
visual4.Size = visualSize;
visual4.Offset = new Vector3(hRefLeft, hRefTop, 0);
visual4.Brush = surfaceBrush;
var inVisual3 = _compositor.CreateSpriteVisual();
inVisual3.Size = new Vector2(80, 80);
inVisual3.Offset = new Vector3(20, 10, 0);
inVisual3.Brush = _compositor.CreateColorBrush(Colors.Yellow);
var inVisual4 = _compositor.CreateSpriteVisual();
inVisual4.Size = new Vector2(80, 80);
inVisual4.Offset = new Vector3(60, 40, 0);
inVisual4.Brush = _compositor.CreateColorBrush(Colors.Blue);
visual4.Children.InsertAtTop(inVisual3);
visual4.Children.InsertAtTop(inVisual4);
_generator.CreateReflection(visual4, distance, 0.7f, ReflectionLocation.Right);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid4, visual4);
}
示例13: OnApplyTemplate
protected override void OnApplyTemplate()
{
// Scale.
var scale = this.GetTemplateChild(ScalePartName) as Path;
if (scale != null)
{
var pg = new PathGeometry();
var pf = new PathFigure();
pf.IsClosed = false;
var middleOfScale = 100 - ScalePadding - this.ScaleWidth / 2;
pf.StartPoint = this.ScalePoint(MinAngle, middleOfScale);
var seg = new ArcSegment();
seg.SweepDirection = SweepDirection.Clockwise;
seg.IsLargeArc = true;
seg.Size = new Size(middleOfScale, middleOfScale);
seg.Point = this.ScalePoint(MaxAngle, middleOfScale);
pf.Segments.Add(seg);
pg.Figures.Add(pf);
scale.Data = pg;
}
var container = this.GetTemplateChild(ContainerPartName) as Grid;
_root = container.GetVisual();
_compositor = _root.Compositor;
// Ticks.
SpriteVisual tick;
for (double i = Minimum; i <= Maximum; i += TickSpacing)
{
tick = _compositor.CreateSpriteVisual();
tick.Size = new Vector2(TickWidth, TickHeight);
tick.Brush = _compositor.CreateColorBrush(TickBrush.Color);
tick.Offset = new Vector3(100 - TickWidth / 2, 0.0f, 0);
tick.CenterPoint = new Vector3(TickWidth / 2, 100.0f, 0);
tick.RotationAngleInDegrees = (float)ValueToAngle(i);
_root.Children.InsertAtTop(tick);
}
// Scale Ticks.
for (double i = Minimum; i <= Maximum; i += TickSpacing)
{
tick = _compositor.CreateSpriteVisual();
tick.Size = new Vector2(ScaleTickWidth, (float)ScaleWidth);
tick.Brush = _compositor.CreateColorBrush(ScaleTickBrush.Color);
tick.Offset = new Vector3(100 - ScaleTickWidth / 2, ScalePadding, 0);
tick.CenterPoint = new Vector3(ScaleTickWidth / 2, 100 - ScalePadding, 0);
tick.RotationAngleInDegrees = (float)ValueToAngle(i);
_root.Children.InsertAtTop(tick);
}
// Needle.
_needle = _compositor.CreateSpriteVisual();
_needle.Size = new Vector2(NeedleWidth, NeedleHeight);
_needle.Brush = _compositor.CreateColorBrush(NeedleBrush.Color);
_needle.CenterPoint = new Vector3(NeedleWidth / 2, NeedleHeight, 0);
_needle.Offset = new Vector3(100 - NeedleWidth / 2, 100 - NeedleHeight, 0);
_root.Children.InsertAtTop(_needle);
OnValueChanged(this);
base.OnApplyTemplate();
}
示例14: InitComposition
/// <summary>
/// Initializes the Composition elements
/// </summary>
private void InitComposition()
{
// Compositor
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// CompositionGenerator
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
// Fade Out Animation
_fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeOutAnimation.InsertKeyFrame(1f, 0);
_fadeOutAnimation.Duration = TransitionDuration;
// Fade In Animation
_fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation();
_fadeInAnimation.InsertKeyFrame(1f, 1);
_fadeInAnimation.Duration = TransitionDuration;
// Color Animation
_colorAnimation = _compositor.CreateColorKeyFrameAnimation();
_colorAnimation.Duration = TransitionDuration;
// Offset Animation
_offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
_offsetAnimation.Target = "Offset";
_offsetAnimation.Duration = TransitionDuration;
_offsetAnimation.InsertKeyFrame(1f, Vector3.Zero);
// Alignment animations
_alignXAnimation = _compositor.CreateScalarKeyFrameAnimation();
_alignXAnimation.Duration = AlignmentTransitionDuration;
_alignYAnimation = _compositor.CreateScalarKeyFrameAnimation();
_alignYAnimation.Duration = AlignmentTransitionDuration;
// ZoomIn Animation Group
_scaleAnimation = _compositor.CreateVector3KeyFrameAnimation();
_scaleAnimation.Target = "Scale";
_scaleAnimation.InsertKeyFrame(1f, Vector3.One);
_scaleAnimation.Duration = TransitionDuration;
_zoomInAnimationGroup = _compositor.CreateAnimationGroup();
_zoomInAnimationGroup.Add(_scaleAnimation);
_zoomInAnimationGroup.Add(_offsetAnimation);
// Visuals
_rootContainer = _compositor.CreateContainerVisual();
_frameLayer = _compositor.CreateLayerVisual();
_frameBackgroundVisual = _compositor.CreateSpriteVisual();
_frameContentVisual = _compositor.CreateSpriteVisual();
_placeholderContentVisual = _compositor.CreateSpriteVisual();
_placeholderBackgroundVisual = _compositor.CreateSpriteVisual();
_nextVisualContent = _compositor.CreateSpriteVisual();
_frameLayer.Children.InsertAtTop(_frameBackgroundVisual);
_frameLayer.Children.InsertAtTop(_frameContentVisual);
_frameLayer.Children.InsertAtTop(_placeholderBackgroundVisual);
_frameLayer.Children.InsertAtTop(_placeholderContentVisual);
_frameLayer.Children.InsertAtTop(_nextVisualContent);
// Placeholder content
_placeholderContentMask = _generator.CreateGeometrySurface(PlaceholderSize, GetPlaceHolderGeometry(),
PlaceholderColor, PlaceholderBackground);
_placeholderContentBrush = _compositor.CreateSurfaceBrush(_placeholderContentMask.Surface);
_placeholderContentVisual.Brush = _placeholderContentBrush;
// Placeholder background
_placeholderBackgroundVisual.Brush = _compositor.CreateColorBrush(PlaceholderBackground);
// By default placeholder visual will not be visible
HidePlaceholder();
// Shadow visual
_shadowVisual = _compositor.CreateSpriteVisual();
_rootContainer.Children.InsertAtBottom(_shadowVisual);
_rootContainer.Children.InsertAtTop(_frameLayer);
_frameBackgroundVisual.Brush = _compositor.CreateColorBrush(FrameBackground);
// Create the effect to create the opacity mask
var layerEffect = new CompositeEffect
{
// CanvasComposite.DestinationIn - Intersection of source and mask.
// Equation: O = MA * S
// where O - Output pixel, MA - Mask Alpha, S - Source pixel.
Mode = CanvasComposite.DestinationIn,
Sources =
{
new CompositionEffectSourceParameter("source"),
new CompositionEffectSourceParameter("mask")
}
};
var layerEffectFactory = _compositor.CreateEffectFactory(layerEffect);
_layerEffectBrush = layerEffectFactory.CreateBrush();
// The mask for the imageFrame
_frameLayerMask = _generator.CreateMaskSurface(new Size(0, 0), null);
_layerEffectBrush.SetSourceParameter("mask", _compositor.CreateSurfaceBrush(_frameLayerMask.Surface));
// Apply the mask effect to the frameLayer
_frameLayer.Effect = _layerEffectBrush;
ElementCompositionPreview.SetElementChildVisual(this, _rootContainer);
}
示例15: OnLoaded
private async void OnLoaded(object sender, RoutedEventArgs e)
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_generator = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);
_backdropBrush = _compositor.CreateBackdropBrush();
_width = 300f;
_height = 300f;
// Create the combined geometry
var ellipse1 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.45f * _width, 0.225f * _height);
var ellipse2 = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.225f * _width, 0.45f * _height);
_combinedGeometry = ellipse1.CombineWith(ellipse2, Matrix3x2.Identity, CanvasGeometryCombine.Union);
// Create the container to host the visuals
var container1 = _compositor.CreateContainerVisual();
container1.Size = new Vector2(CompositionGrid1.ActualWidth.Single(), CompositionGrid1.ActualHeight.Single());
// Background Visual
_bgVisual1 = _compositor.CreateSpriteVisual();
_bgVisual1.Size = new Vector2(_width * 0.45f, _height * 0.45f);
_bgVisual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);
_bgVisual1.Brush = _compositor.CreateColorBrush(Colors.DarkOrange);
container1.Children.InsertAtBottom(_bgVisual1);
// Create custom shaped visual using CompositionMaskBrush
_visual1 = _compositor.CreateSpriteVisual();
_visual1.Size = new Vector2(_width, _height);
_visual1.Offset = new Vector3(((CompositionGrid1.ActualWidth - _width) / 2).Single(),
((CompositionGrid1.ActualHeight - _height) / 2).Single(), 0);
// Create the CompositionMask
var ellipseGeometry = CanvasGeometry.CreateEllipse(_generator.Device, _width / 2, _height / 2, 0.4f * _width, 0.4f * _height);
var compositionMask = _generator.CreateMaskSurface(_visual1.Size.ToSize(), ellipseGeometry);
// Create Masked BackdropBrush from CompositionMask
_visual1.Brush = _compositor.CreateMaskedBackdropBrush(compositionMask, Colors.AntiqueWhite, 30f, _backdropBrush);
container1.Children.InsertAtTop(_visual1);
var visual = _compositor.CreateSpriteVisual();
visual.Size = new Vector2(400, 400);
visual.Offset = new Vector3(((3 * CompositionGrid1.ActualWidth / 4f) - (_width / 2)).Single(),
((3 * CompositionGrid1.ActualHeight / 4f) - (_height / 2)).Single(), 0);
var roundRectGeometry = CanvasGeometry.CreateRoundedRectangle(_generator.Device, 0, 0, _width, _height, 25, 25);
var maskSurface = _generator.CreateMaskSurface(visual.Size.ToSize(), roundRectGeometry);
var frostedBrush = _compositor.CreateFrostedGlassBrush(maskSurface, Colors.AntiqueWhite, 30f, _backdropBrush);
var shadow = _compositor.CreateDropShadow();
shadow.Opacity = 0.5f;
shadow.Color = Colors.Black;
shadow.Offset = new Vector3(10, 10, 0);
shadow.BlurRadius = 15;
shadow.Mask = frostedBrush.GetSourceParameter("mask");
visual.Brush = frostedBrush;
visual.Shadow = shadow;
container1.Children.InsertAtTop(visual);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, container1);
// Initialize the visuals for the Animated Canvas
// Create the container to host the visuals
var container2 = _compositor.CreateContainerVisual();
container2.Size = new Vector2(CompositionGrid2.ActualWidth.Single(), CompositionGrid2.ActualHeight.Single());
// Background Visual
_bgVisual2 = _compositor.CreateSpriteVisual();
_bgVisual2.Size = new Vector2(_width * Factor, _height * Factor);
_bgVisual2.Offset = new Vector3(((CompositionGrid2.ActualWidth - (_width * Factor)) / 2).Single(),
((CompositionGrid2.ActualHeight - (_height * Factor)) / 2).Single(), 0);
//var radians = ((45f * Math.PI) / 180).Single();
//var bgGeometry = _combinedGeometry.Transform(Matrix3x2.CreateRotation(radians, new Vector2(_width / 2, _height / 2)));
//var bgMask = await _generator.CreateMaskAsync(_bgVisual2.Size.ToSize(), bgGeometry, Colors.DarkRed);
//_bgVisual2.Brush = _compositor.CreateSurfaceBrush(bgMask.Surface);
_bgVisual2.Brush = _compositor.CreateColorBrush(Colors.LawnGreen);
container2.Children.InsertAtBottom(_bgVisual2);
// Animated Visual
_animatedVisual = _compositor.CreateSpriteVisual();
_animatedVisual.Size = new Vector2(_width, _height);
_animatedVisual.Offset = new Vector3(((CompositionGrid2.ActualWidth - _width) / 2).Single(),
((CompositionGrid2.ActualHeight - _height) / 2).Single(), 0);
// Create the Excluded geometry
_outerGeometry = CanvasGeometry.CreateRectangle(_generator.Device, 0, 0, _width, _height);
var excludedGeometry = _outerGeometry.CombineWith(_combinedGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Exclude);
// Create the CompositionMask
_animatedCompositionMask = _generator.CreateMaskSurface(_animatedVisual.Size.ToSize(), excludedGeometry);
var animBrush = _compositor.CreateMaskedBackdropBrush(_animatedCompositionMask, Colors.AntiqueWhite, 10f, _backdropBrush);
_animatedVisual.Brush = animBrush;
container2.Children.InsertAtTop(_animatedVisual);
ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, container2);
}