public void Control_With_Animated_Opacity_And_No_Children_Should_Not_Start_New_Layer() { using (TestApplication()) { Decorator decorator; Border border; var tree = new TestRoot { Padding = new Thickness(10), Width = 100, Height = 120, Child = decorator = new Decorator { Padding = new Thickness(11), Child = border = new Border { Background = Brushes.Red, } } }; var layout = AvaloniaLocator.Current.GetService <ILayoutManager>(); layout.ExecuteInitialLayoutPass(tree); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); Assert.Single(scene.Layers); } }
public void Should_Draw_Transparent_Layer_With_Correct_Opacity() { Border border; var root = new TestRoot { Width = 100, Height = 100, Child = border = new Border { Background = Brushes.Red, Child = new Canvas(), } }; var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var target = CreateTargetAndRunFrame(root); var context = Mock.Get(target.RenderTarget.CreateDrawingContext(null)); var borderLayer = target.Layers[border].Bitmap; context.Verify(x => x.DrawImage(borderLayer, 0.5, It.IsAny <Rect>(), It.IsAny <Rect>(), BitmapInterpolationMode.Default)); }
public void Should_Not_Push_Opacity_For_Transparent_Layer_Root_Control() { Border border; var root = new TestRoot { Width = 100, Height = 100, Child = border = new Border { Background = Brushes.Red, Child = new Canvas(), } }; var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var target = CreateTargetAndRunFrame(root); var context = GetLayerContext(target, border); context.Verify(x => x.PushOpacity(0.5), Times.Never); context.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once); context.Verify(x => x.PopOpacity(), Times.Never); }
public void Should_Not_Create_Layer_For_Childless_Control_With_Animated_Opacity() { Border border; var root = new TestRoot { Width = 100, Height = 100, Child = new Border { Background = Brushes.Red, Child = border = new Border { Background = Brushes.Green, } } }; var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var timer = new Mock <IRenderTimer>(); var target = CreateTargetAndRunFrame(root, timer); Assert.Single(target.Layers); }
// adds a new simplified unit icon to a canvas public static void PlaceSimplifiedUnit(Canvas canvas, UnitStartInfo unit, bool isBlurred = false) { var border = new Border { BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(1), Height = 16, Width = 16 }; if (isBlurred) { border.Opacity = 0.2; } canvas.Children.Add(border); border.Bind(Border.BorderBrushProperty, unit, "Player.ColorBrush", BindingMode.OneWay); Canvas.SetLeft(border, unit.X - border.Width / 2); Canvas.SetTop(border, unit.Y - border.Height / 2); Panel.SetZIndex(border, -10); var image = new Image { Source = unit.UnitDef.BuildPic }; // make the icons have the correct size var mission = MainWindow.Instance.Mission; border.RenderTransform = new ScaleTransform { CenterX = 8, CenterY = 8, ScaleX = 1 / 16.0 * mission.FromIngameX(unit.UnitDef.FootprintX * 16), ScaleY = 1 / 16.0 * mission.FromIngameY(unit.UnitDef.FootprintY * 16) }; border.Child = image; }
public void Resizing_Scene_Should_Add_DirtyRects() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { Decorator decorator; Border border; Canvas canvas; var tree = new TestRoot { ClientSize = new Size(100, 100), Child = decorator = new Decorator { Margin = new Thickness(0, 10, 0, 0), Child = border = new Border { Background = Brushes.Red, Child = canvas = new Canvas(), } } }; var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); Assert.Equal(new Size(100, 100), scene.Size); tree.ClientSize = new Size(110, 120); scene = scene.CloneScene(); sceneBuilder.Update(scene, tree); Assert.Equal(new Size(110, 120), scene.Size); var expected = new[] { new Rect(100, 0, 10, 100), new Rect(0, 100, 110, 20), }; Assert.Equal(expected, scene.Layers[tree].Dirty.ToArray()); // Layers are disabled. See #2244 // Assert.Equal(expected, scene.Layers[border].Dirty.ToArray()); } }
public void Hiding_Transparent_Control_Should_Remove_Layers() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { Decorator decorator; Border border; Canvas canvas; var tree = new TestRoot { Padding = new Thickness(10), Width = 100, Height = 120, Child = decorator = new Decorator { Padding = new Thickness(11), Child = border = new Border { Background = Brushes.Red, Padding = new Thickness(12), Child = canvas = new Canvas { Children = { new TextBlock() }, } } } }; var layout = tree.LayoutManager; layout.ExecuteInitialLayoutPass(); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); canvas.Bind(Canvas.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); Assert.Equal(3, scene.Layers.Count); border.IsVisible = false; scene = scene.CloneScene(); sceneBuilder.Update(scene, border); Assert.Equal(1, scene.Layers.Count); } }
public void Removing_Control_With_Animated_Opacity_Should_Remove_Layers() { using (TestApplication()) { Decorator decorator; Border border; Canvas canvas; var tree = new TestRoot { Padding = new Thickness(10), Width = 100, Height = 120, Child = decorator = new Decorator { Padding = new Thickness(11), Child = border = new Border { Background = Brushes.Red, Padding = new Thickness(12), Child = canvas = new Canvas { Children = { new TextBlock() }, } } } }; var layout = AvaloniaLocator.Current.GetService <ILayoutManager>(); layout.ExecuteInitialLayoutPass(tree); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); canvas.Bind(Canvas.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); Assert.Equal(3, scene.Layers.Count); decorator.Child = null; scene = scene.CloneScene(); sceneBuilder.Update(scene, border); Assert.Equal(1, scene.Layers.Count); } }
void UpdateTemplate() { if (Node != null) { bindings.Add(expander.Bind(ToggleButton.IsVisibleProperty, new Binding("ShowExpander") { Source = Node })); bindings.Add(expander.Bind(ToggleButton.IsCheckedProperty, new Binding("IsExpanded") { Source = Node })); bindings.Add(icon.Bind(ContentPresenter.IsVisibleProperty, new Binding("ShowIcon") { Source = Node })); bindings.Add(checkBoxContainer.Bind(Border.IsVisibleProperty, new Binding("IsCheckable") { Source = Node })); bindings.Add(checkBox.Bind(CheckBox.IsCheckedProperty, new Binding("IsChecked") { Source = Node })); bindings.Add(textContainer.Bind(Border.IsVisibleProperty, new Binding("IsEditing") { Source = Node, Converter = BoolConverters.Inverse })); bindings.Add(textContent.Bind(ContentPresenter.ContentProperty, new Binding("Text") { Source = Node })); RaisePropertyChanged(IconProperty, null, Icon); } spacer.Width = CalculateIndent(); if (ParentTreeView.Root == Node && !ParentTreeView.ShowRootExpander) { expander.IsVisible = false; } else { expander.ClearValue(IsVisibleProperty); } }
public void Should_Create_And_Delete_Layers_For_Controls_With_Animated_Opacity() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { Border border; var root = new TestRoot { Width = 100, Height = 100, Child = new Border { Background = Brushes.Red, Child = border = new Border { Background = Brushes.Green, Child = new Canvas(), Opacity = 0.9, } } }; root.Measure(Size.Infinity); root.Arrange(new Rect(root.DesiredSize)); var timer = new Mock <IRenderTimer>(); var target = CreateTargetAndRunFrame(root, timer); Assert.Equal(new[] { root }, target.Layers.Select(x => x.LayerRoot)); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); RunFrame(target); Assert.Equal(new IVisual[] { root, border }, target.Layers.Select(x => x.LayerRoot)); animation.OnCompleted(); RunFrame(target); Assert.Equal(new[] { root }, target.Layers.Select(x => x.LayerRoot)); } }
public void GeometryClip_Should_Affect_Child_Layers() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { var clip = StreamGeometry.Parse("M100,0 L0,100 100,100"); Decorator decorator; Border border; var tree = new TestRoot { Child = decorator = new Decorator { Clip = clip, Margin = new Thickness(12, 16), Child = border = new Border { Opacity = 0.5, Child = new Canvas(), } } }; var layout = tree.LayoutManager; layout.ExecuteInitialLayoutPass(); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); var borderLayer = scene.Layers[border]; Assert.Equal( Matrix.CreateTranslation(12, 16), ((MockStreamGeometryImpl)borderLayer.GeometryClip).Transform); } }
private IElement CreateListBoxItem(GameViewModel content) { var textBlock = new TextBlock(FontManager[Fonts.Normal]) { Text = content.GameName, Foreground = new SolidColorBrush(Colors.White), Margin = new Thickness(0, 10, 0, 10), }; var border = new Border() { Child = textBlock }; var listBoxItem = new ListBoxItem() { Content = border }; textBlock.Bind(TextBlock.ForegroundProperty, listBoxItem.GetObservable <bool, ListBoxItem>(ListBoxItem.IsSelectedProperty) .Select( isSelected => (Brush) (isSelected ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.White)))); border.Bind(Border.BackgroundProperty, listBoxItem.GetObservable <bool, ListBoxItem>(ListBoxItem.IsSelectedProperty) .Select( isSelected => (Brush) (isSelected ? new SolidColorBrush(Colors.Gray) : new SolidColorBrush(Colors.Black)))); content.PropertyChanged += delegate { listBoxItem.IsSelected = content.IsSelected; }; listBoxItem.Bind(ListBoxItem.IsSelectedProperty, BindingFactory.CreateTwoWay(content, c => c.IsSelected)); return(listBoxItem); }
public void Control_With_Animated_Opacity_And_Children_Should_Start_New_Layer() { using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) { Decorator decorator; Border border; Canvas canvas; var tree = new TestRoot { Padding = new Thickness(10), Width = 100, Height = 120, Child = decorator = new Decorator { Padding = new Thickness(11), Child = border = new Border { Background = Brushes.Red, Padding = new Thickness(12), Child = canvas = new Canvas() } } }; var layout = tree.LayoutManager; layout.ExecuteInitialLayoutPass(); var animation = new BehaviorSubject <double>(0.5); border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation); var scene = new Scene(tree); var sceneBuilder = new SceneBuilder(); sceneBuilder.UpdateAll(scene); var rootNode = (VisualNode)scene.Root; var borderNode = (VisualNode)scene.FindNode(border); var canvasNode = (VisualNode)scene.FindNode(canvas); Assert.Same(tree, rootNode.LayerRoot); Assert.Same(border, borderNode.LayerRoot); Assert.Same(border, canvasNode.LayerRoot); Assert.Equal(0.5, scene.Layers[border].Opacity); Assert.Equal(2, scene.Layers.Count()); Assert.Empty(scene.Layers.Select(x => x.LayerRoot).Except(new IVisual[] { tree, border })); animation.OnCompleted(); scene = scene.CloneScene(); sceneBuilder.Update(scene, border); rootNode = (VisualNode)scene.Root; borderNode = (VisualNode)scene.FindNode(border); canvasNode = (VisualNode)scene.FindNode(canvas); Assert.Same(tree, rootNode.LayerRoot); Assert.Same(tree, borderNode.LayerRoot); Assert.Same(tree, canvasNode.LayerRoot); Assert.Single(scene.Layers); var rootDirty = scene.Layers[tree].Dirty; Assert.Single(rootDirty); Assert.Equal(new Rect(21, 21, 58, 78), rootDirty.Single()); } }