public void TestSurroudingAnchor() { var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(100, 200, 300); var grid = new UniformGrid { Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center}; var child1 = new UniformGrid { Size = childSize1 }; var child2 = new UniformGrid { Size = childSize2 }; child2.DependencyProperties.Set(ColumnPropertyKey, 1); grid.Children.Add(child1); grid.Children.Add(child2); grid.Measure(1000 * Vector3.One); grid.Arrange(1000 * Vector3.One, false); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, -1)); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); Assert.AreEqual(new Vector2(-50, 50), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 50)); Assert.AreEqual(new Vector2(-80, 20), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 80)); Assert.AreEqual(new Vector2(0, 100), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 100)); Assert.AreEqual(new Vector2(-10, 90), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 110)); Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 200)); Assert.AreEqual(new Vector2(-100, 0), grid.GetSurroudingAnchorDistances(Orientation.Horizontal, 300)); Assert.AreEqual(new Vector2(0, 200), grid.GetSurroudingAnchorDistances(Orientation.Vertical, -1)); Assert.AreEqual(new Vector2(-100, 100), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.AreEqual(new Vector2(-200, 0), grid.GetSurroudingAnchorDistances(Orientation.Vertical, 500)); Assert.AreEqual(new Vector2(0, 300), grid.GetSurroudingAnchorDistances(Orientation.InDepth, -1)); Assert.AreEqual(new Vector2(-150, 150), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 150)); Assert.AreEqual(new Vector2(-300, 0), grid.GetSurroudingAnchorDistances(Orientation.InDepth, 500)); }
protected override async Task LoadContent() { await base.LoadContent(); var sprites = Asset.Load<SpriteSheet>("RotatedImages"); var img1 = new ImageElement { Source = sprites["NRNR"], StretchType = StretchType.Fill }; var img2 = new ImageElement { Source = sprites["RNR"], StretchType = StretchType.Fill }; var img3 = new ImageElement { Source = sprites["NRR"], StretchType = StretchType.Fill }; var img4 = new ImageElement { Source = sprites["RR"], StretchType = StretchType.Fill }; img1.SetGridColumnSpan(2); img2.SetGridColumnSpan(2); img2.SetGridRow(1); img3.SetGridRowSpan(2); img3.SetGridColumn(2); img4.SetGridRowSpan(2); img4.SetGridColumn(3); var grid = new UniformGrid { Rows = 2, Columns = 4, Children = { img1, img2, img3, img4 } }; UIComponent.RootElement = grid; }
protected override async Task LoadContent() { await base.LoadContent(); buttonLeftTop2 = new Button { Padding = new Thickness(50, 50, 0, 50) }; buttonLeftTop1 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop2 }; buttonLeftTop0 = new Button { Padding = new Thickness(50, 50, 0, 50), Content = buttonLeftTop1}; var bottomGrid = new UniformGrid { Rows = 1, Columns = 2 }; bottomButton = new Button { Content = bottomGrid }; bottomButton.DependencyProperties.Set(GridBase.RowPropertyKey, 1); bottomButton.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); buttonBottomLeft1 = new Button { Margin = new Thickness(50, 50, 0, 50) }; buttonBottomLeft0 = new Button { Margin = new Thickness(50, 0, 0, 100), Content = buttonBottomLeft1 }; bottonBottomRight1 = new Button { Margin = new Thickness(0, 0, 50, 100) }; buttomBottonRight0 = new Button { Margin = new Thickness(0, 0, 50, 50), Content = bottonBottomRight1 }; buttomBottonRight0.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); bottomGrid.Children.Add(buttonBottomLeft0); bottomGrid.Children.Add(buttomBottonRight0); var mainGrid = new UniformGrid { Rows = 2, Columns = 2 }; mainGrid.Children.Add(buttonLeftTop0); mainGrid.Children.Add(bottomButton); UIComponent.RootElement = mainGrid; }
protected override async Task LoadContent() { await base.LoadContent(); sliderImages = Asset.Load<SpriteSheet>("DebugSlider"); slider = new Slider { TrackStartingOffsets = new Vector2(10, 6), TickOffset = 10 }; SetSliderImages(isRotatedImages); grid = new UniformGrid { Children = { slider } }; UIComponent.RootElement = grid; }
public void TestBasicInvalidations() { var grid = new UniformGrid { Rows = 2, Columns = 2, Layers = 2 }; var child = new UniformGrid(); grid.Children.Add(child); // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(ColumnSpanPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(RowSpanPropertyKey, 2)); UIElementLayeringTests.TestMeasureInvalidation(grid, () => child.DependencyProperties.Set(LayerSpanPropertyKey, 2)); }
protected override async Task LoadContent() { await base.LoadContent(); var uiImages = Asset.Load<UIImageGroup>("RotatedImages"); var img1 = new ImageElement { Source = uiImages["NotRotated"], StretchType = StretchType.Fill }; var img2 = new ImageElement { Source = uiImages["Rotated90"], StretchType = StretchType.Fill }; img2.DependencyProperties.Set(GridBase.RowPropertyKey, 1); var grid = new UniformGrid { Rows = 2 }; grid.Children.Add(img1); grid.Children.Add(img2); UIComponent.RootElement = grid; }
protected override async Task LoadContent() { await base.LoadContent(); // build the randomStackPanel elements randomStackPanel = new StackPanel { Orientation = Orientation.Vertical }; for (int i = 0; i < 30; i++) randomStackPanel.Children.Add(CreateButton(0, i, 50, 1200, true)); // build the randomStackPanel elements virtualizedStackPanel = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; for (int i = 0; i < 30; i++) virtualizedStackPanel.Children.Add(CreateButton(0, i, 75, 1200)); // build the uniform grid uniformGrid = new UniformGrid { Columns = 15, Rows = 20 }; for (int c = 0; c < uniformGrid.Columns; ++c) { for (int r = 0; r < uniformGrid.Rows; ++r) uniformGrid.Children.Add(CreateButton(c,r, 175, 300)); } // build the grid const int gridColumns = 10; const int gridRows = 10; grid = new Grid(); grid.LayerDefinitions.Add(new StripDefinition(StripType.Auto)); for (int i = 0; i < gridColumns; i++) grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); for (int i = 0; i < gridRows; i++) grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); for (int c = 0; c < gridColumns; ++c) { for (int r = 0; r < gridRows; ++r) grid.Children.Add(CreateButton(c, r, 50 + r * 30, 100 + c * 40)); } // build the scroll viewer scrollViewer = new TestScrollViewer { Name = "sv", Content = randomStackPanel, ScrollMode = ScrollingMode.HorizontalVertical, SnapToAnchors = true }; // set the scroll viewer as the root UIComponent.RootElement = scrollViewer; }
public void NegativeValues () { UniformGrid g = new UniformGrid (); try { g.Columns = -1; Assert.Fail ("1"); } catch (ArgumentException ex) { Assert.AreEqual (ex.Message, "'-1' is not a valid value for property 'Columns'.", "2"); } try { g.FirstColumn = -1; Assert.Fail ("3"); } catch (ArgumentException ex) { Assert.AreEqual (ex.Message, "'-1' is not a valid value for property 'FirstColumn'.", "4"); } try { g.Rows = -1; Assert.Fail ("5"); } catch (ArgumentException ex) { Assert.AreEqual (ex.Message, "'-1' is not a valid value for property 'Rows'.", "6"); } }
protected override async Task LoadContent() { await base.LoadContent(); var uiImages = Asset.Load<UIImageGroup>("UIImages"); var img1 = new ImageElement { Name = "UV 1 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img2 = new ImageElement { Name = "UV 2 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; img3 = new ImageElement { Name = "UV 3 stack panel", Source = new UIImage(Asset.Load<Texture>("uv")) }; stackPanel = new StackPanel { Orientation = Orientation.Vertical }; stackPanel.Children.Add(img1); stackPanel.Children.Add(img2); stackPanel.Children.Add(img3); var img4 = new ImageElement { Name = "UV grid", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img5 = new ImageElement { Name = "UV grid 2", Source = new UIImage(Asset.Load<Texture>("uv")) }; var img6 = new ImageElement { Name = "Game screen grid", Source = uiImages["GameScreen"] }; img4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); img4.DependencyProperties.Set(GridBase.RowPropertyKey, 0); img5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); img5.DependencyProperties.Set(GridBase.RowPropertyKey, 0); img6.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); img6.DependencyProperties.Set(GridBase.RowPropertyKey, 1); img6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); grid = new UniformGrid { Columns = 2, Rows = 2 }; grid.Children.Add(img4); grid.Children.Add(img5); grid.Children.Add(img6); scrollViewer = new ScrollViewer { Content = grid, ScrollMode = ScrollingMode.HorizontalVertical}; contentDecorator = new ContentDecorator { Content = scrollViewer }; UIComponent.RootElement = contentDecorator; }
protected override async Task LoadContent() { await base.LoadContent(); var imgElt = new ImageElement { Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.Fill }; imgElt.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 2); imgElt.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); imgElt.DependencyProperties.Set(GridBase.RowPropertyKey, 1); imgElt.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); var button1 = new Button(); button1.DependencyProperties.Set(GridBase.RowPropertyKey, 3); button1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); var button2 = new Button(); button2.DependencyProperties.Set(GridBase.RowPropertyKey, 3); button2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 3); var text = new TextBlock { Text = "Test Uniform Grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; text.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); text.DependencyProperties.Set(GridBase.RowPropertyKey, 0); text.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); var grid = new UniformGrid { Rows = 4, Columns = 4}; grid.Children.Add(imgElt); grid.Children.Add(button1); grid.Children.Add(button2); grid.Children.Add(text); UIComponent.RootElement = grid; }
protected override async Task LoadContent() { await base.LoadContent(); var uiImages = Asset.Load<UIImageGroup>("UIImages"); var imgElt1 = new ImageElement { Source = uiImages["GameScreen"], StretchType = StretchType.Fill }; imgElt1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 0); imgElt1.DependencyProperties.Set(GridBase.RowSpanPropertyKey, 3); imgElt1.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3); imgElt1.DependencyProperties.Set(GridBase.RowPropertyKey, 0); imgElt1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); var imgElt2 = new ImageElement { Source = uiImages["Logo"], StretchType = StretchType.Fill }; imgElt2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); imgElt2.DependencyProperties.Set(GridBase.RowPropertyKey, 0); imgElt2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2); var imgElt3 = new ImageElement { Source = uiImages["Logo"], StretchType = StretchType.Fill }; imgElt3.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2); imgElt3.DependencyProperties.Set(GridBase.RowPropertyKey, 2); imgElt3.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); var imgElt4 = new ImageElement { Source = uiImages["BorderButton"], StretchType = StretchType.Fill }; imgElt4.DependencyProperties.Set(Panel.ZIndexPropertyKey, 3); imgElt4.DependencyProperties.Set(GridBase.RowPropertyKey, 1); imgElt4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); var grid = new UniformGrid { Rows = 3, Columns = 3 }; grid.Children.Add(imgElt1); grid.Children.Add(imgElt2); grid.Children.Add(imgElt3); grid.Children.Add(imgElt4); UIComponent.RootElement = grid; }
public void TestScrollOwner() { var grid = new UniformGrid(); Assert.AreEqual(null, grid.ScrollOwner); var scrollViewer = new ScrollViewer { Content = grid }; Assert.AreEqual(scrollViewer, grid.ScrollOwner); scrollViewer.Content = null; Assert.AreEqual(null, grid.ScrollOwner); var scrollViewer2 = new ScrollViewer { Content = grid }; Assert.AreEqual(scrollViewer2, grid.ScrollOwner); }
private UniformGrid CreateShipButtonElement(SpaceShip spaceShip) { // Put the stat text block in a vertical uniform grid var statusTextGrid = new UniformGrid { Rows = 3, Margin = new Thickness(5f, -6f, 0, 0)}; statusTextGrid.Children.Add(CreateShipStatusTextBlock("Power", 0)); statusTextGrid.Children.Add(CreateShipStatusTextBlock("Control", 1)); statusTextGrid.Children.Add(CreateShipStatusTextBlock("Speed", 2)); // Put the stat stars in a vertical uniform grid spaceShip.PowerImageElement = CreateShipStatusStar(0); spaceShip.ControlImageElement = CreateShipStatusStar(1); spaceShip.SpeedImageElement = CreateShipStatusStar(2); var starGrid = new UniformGrid { Rows = 3 }; starGrid.Children.Add(spaceShip.PowerImageElement); starGrid.Children.Add(spaceShip.ControlImageElement); starGrid.Children.Add(spaceShip.SpeedImageElement); starGrid.SetGridColumn(2); // Ship image var shipSprite = mainScreneImages[spaceShip.Name]; var shipImageElement = new ImageElement { Source = shipSprite }; shipImageElement.SetGridColumn(4); // Create the horizontal grid with two blank stretchable columns and add the text blocks, the starts and the ship image var shipContent = new Grid(); shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); shipContent.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); shipContent.RowDefinitions.Add(new StripDefinition()); shipContent.LayerDefinitions.Add(new StripDefinition()); shipContent.Children.Add(statusTextGrid); shipContent.Children.Add(starGrid); shipContent.Children.Add(shipImageElement); // var shipSelectFrameSprite = mainScreneImages["weapon_select_frame"]; var shipButton = new Button { Name = spaceShip.Name, Content = shipContent, PressedImage = shipSelectFrameSprite, NotPressedImage = shipSelectFrameSprite, MouseOverImage = shipSelectFrameSprite, Padding = new Thickness(60, 20, 20, 20) }; shipButton.Click += delegate { currentShipImage.Source = shipSprite; activeShipIndex = shipList.FindIndex(w => w.Name == spaceShip.Name); PowerStatus = spaceShip.Power; ControlStatus = spaceShip.Control; SpeedStatus = spaceShip.Speed; CloseShipSelectPopup(); }; shipButton.IsEnabled = !spaceShip.IsLocked; shipButton.SetCanvasRelativeSize(new Vector3(1f, 1f, 1f)); var buttonGrid = new UniformGrid { MaximumHeight = 100 }; buttonGrid.Children.Add(shipButton); if (spaceShip.IsLocked) { var lockIconImage = mainScreneImages["lock_icon"]; var lockIconElement = new ImageElement { Source = lockIconImage, StretchType = StretchType.Fill, }; lockIconElement.SetPanelZIndex(1); buttonGrid.Children.Add(lockIconElement); } return buttonGrid; }
public static IObservable <EventPattern <TextCompositionEventArgs> > TextInputObserver(this UniformGrid This) { return(Observable.FromEventPattern <TextCompositionEventHandler, TextCompositionEventArgs>(h => This.TextInput += h, h => This.TextInput -= h)); }
public static IObservable <EventPattern <KeyboardFocusChangedEventArgs> > LostKeyboardFocusObserver(this UniformGrid This) { return(Observable.FromEventPattern <KeyboardFocusChangedEventHandler, KeyboardFocusChangedEventArgs>(h => This.LostKeyboardFocus += h, h => This.LostKeyboardFocus -= h)); }
public static IObservable <EventPattern <KeyEventArgs> > PreviewKeyDownObserver(this UniformGrid This) { return(Observable.FromEventPattern <KeyEventHandler, KeyEventArgs>(h => This.PreviewKeyDown += h, h => This.PreviewKeyDown -= h)); }
public void Test_UniformGrid_SetupColumnDefinitions_FirstAndEndFixed() { var treeroot = XamlReader.Load(@"<Page xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""> <controls:UniformGrid x:Name=""UniformGrid"" Columns=""5""> <controls:UniformGrid.ColumnDefinitions> <ColumnDefinition Width=""48""/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition Width=""128""/> </controls:UniformGrid.ColumnDefinitions> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> </controls:UniformGrid> </Page>") as FrameworkElement; Assert.IsNotNull(treeroot, "Could not load XAML tree."); var grid = treeroot.FindChild("UniformGrid") as UniformGrid; Assert.IsNotNull(grid, "Could not find UniformGrid in tree."); // We should find our first definition Assert.AreEqual(5, grid.ColumnDefinitions.Count, "Expected to find two Column definitions."); Assert.AreEqual(48, grid.ColumnDefinitions[0].Width.Value); Assert.AreEqual(128, grid.ColumnDefinitions[4].Width.Value); Assert.AreEqual(5, grid.Columns, "Columns not set to 5"); // We'll have five Columns in this setup grid.SetupColumnDefinitions(5); // We should now have our Columns created Assert.AreEqual(5, grid.ColumnDefinitions.Count, "5 ColumnDefinitions weren't created."); // Our original definition should be at index 2 var rdo = grid.ColumnDefinitions[0]; // Did we mark that our Column is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo)); Assert.AreNotEqual(GridUnitType.Star, rdo.Width.GridUnitType); Assert.AreNotEqual(1.0, rdo.Width.Value); // Our 2nd original definition should be at index 4 var rdo2 = grid.ColumnDefinitions[4]; // Did we mark that our Column is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo2)); ////Assert.AreEqual(4, UniformGrid.GetColumn(rdo2)); Assert.AreNotEqual(GridUnitType.Star, rdo2.Width.GridUnitType); Assert.AreNotEqual(1.0, rdo2.Width.Value); // Check that we filled in the other two. for (int i = 1; i < grid.ColumnDefinitions.Count - 1; i++) { var rd = grid.ColumnDefinitions[i]; // Check if we've setup our Column to automatically layout Assert.AreEqual(false, UniformGrid.GetAutoLayout(rd)); // We need to be using '*' layout for all our Columns to be even. Assert.AreEqual(GridUnitType.Star, rd.Width.GridUnitType); Assert.AreEqual(1.0, rd.Width.Value); } //// DO IT AGAIN //// This is so we can check that it will behave the same again on another pass. // We'll have five Columns in this setup grid.SetupColumnDefinitions(5); // We should now have our Columns created Assert.AreEqual(5, grid.ColumnDefinitions.Count, "5 ColumnDefinitions weren't created."); // Our original definition should be at index 0 rdo = grid.ColumnDefinitions[0]; // Did we mark that our Column is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo)); Assert.AreNotEqual(GridUnitType.Star, rdo.Width.GridUnitType); Assert.AreNotEqual(1.0, rdo.Width.Value); // Our 2nd original definition should be at index 4 rdo2 = grid.ColumnDefinitions[4]; // Did we mark that our Column is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo2)); Assert.AreNotEqual(GridUnitType.Star, rdo2.Width.GridUnitType); Assert.AreNotEqual(1.0, rdo2.Width.Value); // Check that we filled in the other two. for (int i = 1; i < grid.ColumnDefinitions.Count - 1; i++) { var rd = grid.ColumnDefinitions[i]; // Check if we've setup our Column to automatically layout Assert.AreEqual(false, UniformGrid.GetAutoLayout(rd)); // We need to be using '*' layout for all our Columns to be even. Assert.AreEqual(GridUnitType.Star, rd.Width.GridUnitType); Assert.AreEqual(1.0, rd.Width.Value); } }
private void CreateAndInsertButton(UniformGrid grid, int c, int r) { var button = new Button(); button.DependencyProperties.Set(GridBase.RowPropertyKey, r); button.DependencyProperties.Set(GridBase.ColumnPropertyKey, c); grid.Children.Add(button); }
public static IObservable <EventPattern <MouseButtonEventArgs> > MouseRightButtonUpObserver(this UniformGrid This) { return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.MouseRightButtonUp += h, h => This.MouseRightButtonUp -= h)); }
public static IObservable <EventPattern <MouseButtonEventArgs> > PreviewMouseRightButtonDownObserver(this UniformGrid This) { return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.PreviewMouseRightButtonDown += h, h => This.PreviewMouseRightButtonDown -= h)); }
protected override async Task LoadContent() { await base.LoadContent(); // build the randomStackPanel elements randomStackPanel = new StackPanel { Orientation = Orientation.Vertical }; for (int i = 0; i < 30; i++) { randomStackPanel.Children.Add(CreateButton(0, i, 50, 1200, true)); } // build the randomStackPanel elements virtualizedStackPanel = new StackPanel { Orientation = Orientation.Vertical, ItemVirtualizationEnabled = true }; for (int i = 0; i < 30; i++) { virtualizedStackPanel.Children.Add(CreateButton(0, i, 75, 1200)); } // build the uniform grid uniformGrid = new UniformGrid { Columns = 15, Rows = 20 }; for (int c = 0; c < uniformGrid.Columns; ++c) { for (int r = 0; r < uniformGrid.Rows; ++r) { uniformGrid.Children.Add(CreateButton(c, r, 175, 300)); } } // build the grid const int gridColumns = 10; const int gridRows = 10; grid = new Grid(); grid.LayerDefinitions.Add(new StripDefinition(StripType.Auto)); for (int i = 0; i < gridColumns; i++) { grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); } for (int i = 0; i < gridRows; i++) { grid.RowDefinitions.Add(new StripDefinition(StripType.Auto)); } for (int c = 0; c < gridColumns; ++c) { for (int r = 0; r < gridRows; ++r) { grid.Children.Add(CreateButton(c, r, 50 + r * 30, 100 + c * 40)); } } // build the scroll viewer scrollViewer = new TestScrollViewer { Name = "sv", Content = randomStackPanel, ScrollMode = ScrollingMode.HorizontalVertical, SnapToAnchors = true }; // set the scroll viewer as the root UIComponent.Page = new Engine.UIPage { RootElement = scrollViewer }; }
protected override async Task LoadContent() { await base.LoadContent(); sprites = Content.Load <SpriteSheet>("UIImages"); // Also draw a texture during the clear renderer // TODO: Use a custom compositor as soon as we have visual scripting? var topChildRenderer = ((SceneCameraRenderer)SceneSystem.GraphicsCompositor.Game).Child; var forwardRenderer = (topChildRenderer as SceneRendererCollection)?.Children.OfType <ForwardRenderer>().FirstOrDefault() ?? (ForwardRenderer)topChildRenderer; forwardRenderer.Clear = new ClearAndDrawTextureRenderer { Color = forwardRenderer.Clear.Color, Texture = sprites["GameScreen"].Texture }; var lifeBar = new ImageElement { Source = SpriteFromSheet.Create(sprites, "Logo"), HorizontalAlignment = HorizontalAlignment.Center }; lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3); var quitText = new TextBlock { Text = "Quit Game", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15") }; ApplyTextBlockDefaultStyle(quitText); var quitGameButton = new Button { Content = quitText, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(10), }; ApplyButtonDefaultStyle(quitGameButton); quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2); quitGameButton.Click += (sender, args) => Exit(); modalButton1Text = new TextBlock { Text = "Close Modal window 1", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15") }; ApplyTextBlockDefaultStyle(modalButton1Text); var modalButton1 = new Button { Name = "Button Modal 1", Content = modalButton1Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; ApplyButtonDefaultStyle(modalButton1); modalButton1.Click += ModalButton1OnClick; modal1 = new ModalElement { Content = modalButton1, Name = "Modal 1" }; modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1); modal1.OutsideClick += Modal1OnOutsideClick; modalButton2Text = new TextBlock { Text = "Close Modal window 2", Font = Content.Load <SpriteFont>("MicrosoftSansSerif15") }; ApplyTextBlockDefaultStyle(modalButton2Text); var modalButton2 = new Button { Name = "Button Modal 2", Content = modalButton2Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; ApplyButtonDefaultStyle(modalButton2); modalButton2.Click += ModalButton2OnClick; modal2 = new ModalElement { Content = modalButton2, Name = "Modal 2" }; modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2); modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2); modal2.OutsideClick += Modal2OnOutsideClick; uniformGrid = new UniformGrid { Columns = 3, Rows = 3 }; uniformGrid.Children.Add(modal1); uniformGrid.Children.Add(modal2); uniformGrid.Children.Add(lifeBar); uniformGrid.Children.Add(quitGameButton); UIComponent.Page = new Engine.UIPage { RootElement = uniformGrid }; }
public PostureRecognizerStart(Window parent) { _PostureCollection = FindVisualChild <UniformGrid>(parent, "PostureCollection"); ReadDefinePosture("PosturesRecord\\record.txt"); }
public void RefreshMap() { if (!IsVisible) { _isMapDirty = true; return; } _isMapDirty = false; MapCanvas.Children.Clear(); lock (_bot) { if (_bot.Game == null || _bot.Game.Map == null) { return; } UniformGrid grid = new UniformGrid(); grid.Background = Brushes.White; grid.Columns = _bot.Game.Map.DimensionX; grid.Rows = _bot.Game.Map.DimensionY; grid.Width = grid.Columns * _cellWidth; grid.Height = grid.Rows * _cellWidth; for (int y = 0; y < grid.Rows; ++y) { for (int x = 0; x < grid.Columns; ++x) { Rectangle rect = new Rectangle(); int collider = _bot.Game.Map.GetCollider(x, y); if (_bot.Game.Map.HasLink(x, y)) { rect.Fill = Brushes.Gold; } else if (_colliderColors.ContainsKey(collider)) { rect.Fill = _colliderColors[collider]; } else { rect.Fill = Brushes.Black; } if (collider == 2) { rect.Height = _cellWidth / 4; } if (collider == 3 || collider == 4) { rect.Width = _cellWidth / 4; } if (collider == 14) { rect.Height = _cellWidth / 4; rect.VerticalAlignment = VerticalAlignment.Top; } grid.Children.Add(rect); } } _mapGrid = grid; MapCanvas.Children.Add(grid); _player = new Ellipse() { Fill = Brushes.Red, Width = _cellWidth, Height = _cellWidth }; MapCanvas.Children.Add(_player); UpdatePlayerPosition(); } }
public void Test_UniformGrid_SetupRowDefinitions_FirstFixed() { var treeroot = XamlReader.Load(@"<Page xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""> <controls:UniformGrid x:Name=""UniformGrid""> <controls:UniformGrid.RowDefinitions> <RowDefinition Height=""48""/> </controls:UniformGrid.RowDefinitions> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> </controls:UniformGrid> </Page>") as FrameworkElement; Assert.IsNotNull(treeroot, "Could not load XAML tree."); var grid = treeroot.FindChild("UniformGrid") as UniformGrid; Assert.IsNotNull(grid, "Could not find UniformGrid in tree."); // We should find our first definition Assert.AreEqual(1, grid.RowDefinitions.Count); Assert.AreEqual(48, grid.RowDefinitions[0].Height.Value); // We'll have three rows in this setup grid.SetupRowDefinitions(3); // We should now have our rows created Assert.AreEqual(3, grid.RowDefinitions.Count); var rdo = grid.RowDefinitions[0]; // Did we mark that our row is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo)); Assert.AreNotEqual(GridUnitType.Star, rdo.Height.GridUnitType); Assert.AreNotEqual(1.0, rdo.Height.Value); // Check that we filled in the other two. for (int i = 1; i < grid.RowDefinitions.Count; i++) { var rd = grid.RowDefinitions[i]; // Check if we've setup our row to automatically layout Assert.AreEqual(true, UniformGrid.GetAutoLayout(rd)); // We need to be using '*' layout for all our rows to be even. Assert.AreEqual(GridUnitType.Star, rd.Height.GridUnitType); Assert.AreEqual(1.0, rd.Height.Value); } //// DO IT AGAIN //// This is so we can check that it will behave the same again on another pass. // We'll have three rows in this setup grid.SetupRowDefinitions(3); // We should now have our rows created Assert.AreEqual(3, grid.RowDefinitions.Count); rdo = grid.RowDefinitions[0]; // Did we mark that our row is special? Assert.AreEqual(false, UniformGrid.GetAutoLayout(rdo)); Assert.AreNotEqual(GridUnitType.Star, rdo.Height.GridUnitType); Assert.AreNotEqual(1.0, rdo.Height.Value); // Check that we filled in the other two. for (int i = 1; i < grid.RowDefinitions.Count; i++) { var rd = grid.RowDefinitions[i]; // Check if we've setup our row to automatically layout Assert.AreEqual(true, UniformGrid.GetAutoLayout(rd)); // We need to be using '*' layout for all our rows to be even. Assert.AreEqual(GridUnitType.Star, rd.Height.GridUnitType); Assert.AreEqual(1.0, rd.Height.Value); } }
internal static UIElement GetUIElement(PropertyInfo propertyInfo, SettingsService settingsService, SettingsKey settingsKey, object defaultValue, SettingsPropertyAttribute attribute) { Brush fgBrush = Application.Current.Resources[EnvironmentColors.BrandedUITextBrushKey] as Brush; var labelName = attribute.Name ?? propertyInfo.Name; if (propertyInfo.PropertyType == typeof(bool)) { var isChecked = settingsService.Get(settingsKey, (bool?)defaultValue ?? false); var res = new CheckBox { Content = labelName, IsChecked = isChecked }; res.Checked += (sender, args) => settingsService.Set(settingsKey, res.IsChecked ?? false); res.Unchecked += (sender, args) => settingsService.Set(settingsKey, res.IsChecked ?? false); res.ToolTip = attribute.Description; return(res); } if (propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType == typeof(int)) { var editorAttribute = propertyInfo.GetCustomAttribute <EditorAttribute>(); var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); if (editorAttribute != null) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); } var textBox = CreateTextBox(propertyInfo, settingsService, settingsKey, defaultValue); Grid.SetColumn(textBox, 1); grid.ToolTip = attribute.Description; grid.Children.Add(new Label { Foreground = fgBrush, Content = labelName + ":", ToolTip = labelName }); grid.Children.Add(textBox); if (editorAttribute != null) { var uiTypeEditor = Activator.CreateInstance(Type.GetType(editorAttribute.EditorTypeName)) as UITypeEditor; var panel = new StackPanel(); Grid.SetColumn(panel, 2); grid.Children.Add(panel); if (editorAttribute.EditorTypeName.Contains(typeof(FileNameEditor).FullName)) { var btnSelect = new Button { Content = "...", Width = 22, Height = 21, Margin = new Thickness(-2, 2, 0, 0), MinHeight = 1, MinWidth = 1 }; btnSelect.Click += (sender, args) => { var res = uiTypeEditor.EditValue(textBox.Text); if (res != null) { textBox.Text = res; } }; panel.Children.Add(btnSelect); } } return(grid); } if (propertyInfo.PropertyType.IsEnum) { var value = settingsService.Get(settingsKey, propertyInfo.PropertyType, defaultValue); var grid = new UniformGrid { Columns = 2 }; var combo = new ComboBox() { Width = 180, Style = Application.Current.TryFindResource("COABComboBoxStyle") as Style, Margin = new Thickness(0, 2, 2, 2), SelectedValue = Enum.Parse(propertyInfo.PropertyType, value.ToString()), //value, ItemsSource = Enum.GetValues(propertyInfo.PropertyType) }; combo.SelectionChanged += (sender, args) => settingsService.Set(propertyInfo.PropertyType, settingsKey, combo.SelectedValue); grid.ToolTip = attribute.Description; grid.Children.Add(new Label { Foreground = fgBrush, Content = labelName + ":" }); grid.Children.Add(combo); return(grid); } if (propertyInfo.PropertyType.IsArray) { var grp = new GroupBox { Header = labelName, Margin = new Thickness(0, 5, 0, 5) }; var value = settingsService.Get(settingsKey, new string[0]); var itemSource = new ObservableCollection <Bindable <string> >(value.Select(s => new Bindable <string>(s))); var edit = new StringListEdit { Height = 150, DataContext = itemSource, BrowseMode = BrowseMode.Directories }; var dock = new DockPanel(); dock.Children.Add(edit); Label labelDes = new Label { Content = attribute.Description }; DockPanel.SetDock(labelDes, Dock.Bottom); dock.Children.Add(labelDes); grp.Content = dock; PropertyChangedEventHandler saveAction = (sender, args) => settingsService.Set(settingsKey, itemSource.Select(b => b.Value).ToArray()); itemSource.Apply(bindable => bindable.PropertyChanged += saveAction); itemSource.CollectionChanged += (sender, args) => { settingsService.Set(settingsKey, itemSource.Select(bindable => bindable.Value).ToArray()); args.NewItems?.OfType <Bindable <string> >().Apply(bindable => bindable.PropertyChanged += saveAction); args.OldItems?.OfType <Bindable <string> >().Apply(bindable => bindable.PropertyChanged -= saveAction); }; edit.LostFocus += (sender, args) => saveAction(sender, new PropertyChangedEventArgs("")); return(grp); } throw new NotSupportedException(propertyInfo.PropertyType + " is not supported"); }
protected override async Task LoadContent() { await base.LoadContent(); var resolution = (Vector3)UIComponent.VirtualResolution; var canvas = new Canvas(); var imgElt = new ImageElement { Name = "UV image", Source = new Sprite(Asset.Load<Texture>("uv")), Width = resolution.X / 5, Height = resolution.Y / 5, StretchType = StretchType.Fill }; imgElt.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); imgElt.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 10, resolution.Y / 10, 0)); imgElt.DependencyProperties.Set(Panel.ZIndexPropertyKey, -1); stackPanel = new StackPanel { Orientation = Orientation.Vertical }; scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.Vertical }; scrollViewer.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(resolution.X / 4, resolution.Y / 10, 0)); scrollViewer.Content = stackPanel; var button1 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5), LocalMatrix = Matrix.Scaling(2, 2, 2) }; var textOnly = new TextBlock { Text = "Text only button", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextColor = new Color(1f, 0, 0, 0.5f) }; button1.Content = textOnly; var button2 = new Button { Name = "Button2", Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var imageContent = new ImageElement { Name = "Image Button2", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 50 }; button2.Content = imageContent; var button3 = new Button { Margin = Thickness.UniformRectangle(5), Padding = Thickness.UniformRectangle(5) }; var stackContent = new StackPanel { Orientation = Orientation.Horizontal }; var stackImage = new ImageElement { Name = "Image stack panel", Source = new Sprite(Asset.Load<Texture>("uv")), MaximumHeight = 50 }; var stackText = new TextBlock { Text = "button text", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Margin = Thickness.UniformRectangle(5) }; stackContent.Children.Add(stackImage); stackContent.Children.Add(stackText); button3.Content = stackContent; var button4 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Right, Padding = Thickness.UniformRectangle(5) }; var imageContent2 = new ImageElement { Name = "button 4 uv image", Source = new Sprite(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch, MaximumHeight = 40, Opacity = 0.5f }; button4.Content = imageContent2; var button5 = new Button { Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(5) }; var textOnly2 = new TextBlock { Text = "Left aligned", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; button5.Content = textOnly2; var button6 = new ImageButton { Height = 50, Margin = Thickness.UniformRectangle(5), HorizontalAlignment = HorizontalAlignment.Center, PressedImage = new Sprite(Asset.Load<Texture>("ImageButtonPressed")), NotPressedImage = new Sprite(Asset.Load<Texture>("ImageButtonNotPressed")), }; toggle = new ToggleButton { Content = new TextBlock { Text = "Toggle button test", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }, IsThreeState = true }; scrollingText = new ScrollingText { Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), Text = "<<<--- Scrolling text in a button ", IsEnabled = IsUpdateAutomatic }; var button7 = new Button { Margin = Thickness.UniformRectangle(5), Content = scrollingText }; var uniformGrid = new UniformGrid { Rows = 2, Columns = 2 }; var gridText = new TextBlock { Text = "Uniform grid", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center}; gridText.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2); var buttonLeft = new Button { Content = new TextBlock { Text = "unif-grid left", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonLeft.DependencyProperties.Set(GridBase.RowPropertyKey, 1); var buttonRight = new Button { Content = new TextBlock { Text = "unif-grid right", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), TextAlignment = TextAlignment.Center } }; buttonRight.DependencyProperties.Set(GridBase.RowPropertyKey, 1); buttonRight.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); uniformGrid.Children.Add(gridText); uniformGrid.Children.Add(buttonLeft); uniformGrid.Children.Add(buttonRight); stackPanel.Children.Add(button1); stackPanel.Children.Add(button2); stackPanel.Children.Add(button3); stackPanel.Children.Add(button4); stackPanel.Children.Add(button5); stackPanel.Children.Add(button6); stackPanel.Children.Add(toggle); stackPanel.Children.Add(button7); stackPanel.Children.Add(uniformGrid); canvas.Children.Add(imgElt); canvas.Children.Add(scrollViewer); UIComponent.RootElement = canvas; }
public static IObservable <EventPattern <MouseWheelEventArgs> > PreviewMouseWheelObserver(this UniformGrid This) { return(Observable.FromEventPattern <MouseWheelEventHandler, MouseWheelEventArgs>(h => This.PreviewMouseWheel += h, h => This.PreviewMouseWheel -= h)); }
public static void ComputeJacobian(ref UniformGrid<Matrix3x3> jacobian, UniformGrid<Vector> vec) { Vector3 spacing = vec.GetCellSpacing(); // Avoid divide-by-zero when z size is effectively 0 (for 2D domains) Vector3 reciprocalSpacing = new Vector3(1.0f / spacing.x , 1.0f / spacing.y, spacing.z > float.Epsilon ? 1.0f / spacing.z : 0.0f ) ; Vector3 halfReciprocalSpacing = (0.5f * reciprocalSpacing) ; uint[] dims = { vec.GetNumPoints(0), vec.GetNumPoints(1), vec.GetNumPoints(2) }; uint[] dimsMinus1 = { vec.GetNumPoints(0) - 1, vec.GetNumPoints(1) - 1, vec.GetNumPoints(2) - 1 }; uint numXY = dims[0] * dims[1]; uint[] index = new uint[3]; // Compute derivatives for interior (i.e. away from boundaries). for (index[2] = 1; index[2] < dimsMinus1[2]; ++index[2]) { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); for (index[1] = 1; index[1] < dimsMinus1[1]; ++index[1]) { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; for (index[0] = 1; index[0] < dimsMinus1[0]; ++index[0]) { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; Matrix3x3 rMatrix = jacobian[offsetX0Y0Z0]; /* Compute d/dx */ rMatrix.x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; /* Compute d/dy */ rMatrix.y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; /* Compute d/dz */ rMatrix.z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } #region boundariesDerivatives // Compute derivatives for boundaries: 6 faces of box. ------------------------------------------------------------ // In some situations, these macros compute extraneous data. // A tiny bit more efficiency could be squeezed from this routine, // but it turns out to be well under 1% of the total expense. // Compute derivatives for -X boundary. index[0] = 0; for (index[2] = 0; index[2] < dims[2]; ++index[2]) { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); for (index[1] = 0; index[1] < dims[1]; ++index[1]) { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } } // Compute derivatives for -Y boundary. index[1] = 0; for (index[2] = 0; index[2] < dims[2]; ++index[2]) { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; for (index[0] = 0; index[0] < dims[0]; ++index[0]) { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } } // Compute derivatives for -Z boundary. index[2] = 0; { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); for (index[1] = 0; index[1] < dims[1]; ++index[1]) { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; for (index[0] = 0; index[0] < dims[0]; ++index[0]) { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } } // Compute derivatives for +X boundary. index[0] = dimsMinus1[0]; for (index[2] = 0; index[2] < dims[2]; ++index[2]) { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); for (index[1] = 0; index[1] < dims[1]; ++index[1]) { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } } // Compute derivatives for +Y boundary. index[1] = dimsMinus1[1]; for (index[2] = 0; index[2] < dims[2]; ++index[2]) { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; for (index[0] = 0; index[0] < dims[0]; ++index[0]) { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } } // Compute derivatives for +Z boundary. index[2] = dimsMinus1[2]; { //ASSIGN_Z_OFFSETS uint offsetZM = numXY * (index[2] - 1); uint offsetZ0 = numXY * index[2]; uint offsetZP = numXY * (index[2] + 1); for (index[1] = 0; index[1] < dims[1]; ++index[1]) { //ASSIGN_YZ_OFFSETS uint offsetYMZ0 = dims[0] * (index[1] - 1) + offsetZ0; uint offsetY0Z0 = dims[0] * index[1] + offsetZ0; uint offsetYPZ0 = dims[0] * (index[1] + 1) + offsetZ0; uint offsetY0ZM = dims[0] * index[1] + offsetZM; uint offsetY0ZP = dims[0] * index[1] + offsetZP; for (index[0] = 0; index[0] < dims[0]; ++index[0]) { //ASSIGN_XYZ_OFFSETS uint offsetX0Y0Z0 = index[0] + offsetY0Z0; uint offsetXMY0Z0 = index[0] - 1 + offsetY0Z0; uint offsetXPY0Z0 = index[0] + 1 + offsetY0Z0; uint offsetX0YMZ0 = index[0] + offsetYMZ0; uint offsetX0YPZ0 = index[0] + offsetYPZ0; uint offsetX0Y0ZM = index[0] + offsetY0ZM; uint offsetX0Y0ZP = index[0] + offsetY0ZP; //COMPUTE_FINITE_DIFF if (index[0] == 0) { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.x; } else if (index[0] == dimsMinus1[0]) { jacobian[offsetX0Y0Z0].x = (vec[offsetX0Y0Z0].v - vec[offsetXMY0Z0].v) * reciprocalSpacing.x; } else { jacobian[offsetX0Y0Z0].x = (vec[offsetXPY0Z0].v - vec[offsetXMY0Z0].v) * halfReciprocalSpacing.x; } if (index[1] == 0) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.y; } else if (index[1] == dimsMinus1[1]) { jacobian[offsetX0Y0Z0].y = (vec[offsetX0Y0Z0].v - vec[offsetX0YMZ0].v) * reciprocalSpacing.y; } else { jacobian[offsetX0Y0Z0].y = (vec[offsetX0YPZ0].v - vec[offsetX0YMZ0].v) * halfReciprocalSpacing.y; } if (index[2] == 0) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0Z0].v) * reciprocalSpacing.z; } else if (index[2] == dimsMinus1[2]) { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0Z0].v - vec[offsetX0Y0ZM].v) * reciprocalSpacing.z; } else { jacobian[offsetX0Y0Z0].z = (vec[offsetX0Y0ZP].v - vec[offsetX0Y0ZM].v) * halfReciprocalSpacing.z; } } } #endregion } }
public static IObservable <EventPattern <MouseEventArgs> > MouseEnterObserver(this UniformGrid This) { return(Observable.FromEventPattern <MouseEventHandler, MouseEventArgs>(h => This.MouseEnter += h, h => This.MouseEnter -= h)); }
public static IObservable <EventPattern <StylusButtonEventArgs> > PreviewStylusButtonUpObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusButtonEventHandler, StylusButtonEventArgs>(h => This.PreviewStylusButtonUp += h, h => This.PreviewStylusButtonUp -= h)); }
public static IObservable <EventPattern <MouseEventArgs> > GotMouseCaptureObserver(this UniformGrid This) { return(Observable.FromEventPattern <MouseEventHandler, MouseEventArgs>(h => This.GotMouseCapture += h, h => This.GotMouseCapture -= h)); }
public static IObservable <EventPattern <KeyEventArgs> > KeyUpObserver(this UniformGrid This) { return(Observable.FromEventPattern <KeyEventHandler, KeyEventArgs>(h => This.KeyUp += h, h => This.KeyUp -= h)); }
public static IObservable <EventPattern <QueryCursorEventArgs> > QueryCursorObserver(this UniformGrid This) { return(Observable.FromEventPattern <QueryCursorEventHandler, QueryCursorEventArgs>(h => This.QueryCursor += h, h => This.QueryCursor -= h)); }
public static IObservable <EventPattern <SizeChangedEventArgs> > SizeChangedObserver(this UniformGrid This) { return(Observable.FromEventPattern <SizeChangedEventHandler, SizeChangedEventArgs>(h => This.SizeChanged += h, h => This.SizeChanged -= h)); }
public static IObservable <EventPattern <DataTransferEventArgs> > SourceUpdatedObserver(this UniformGrid This) { return(Observable.FromEventPattern <EventHandler <DataTransferEventArgs>, DataTransferEventArgs>(h => This.SourceUpdated += h, h => This.SourceUpdated -= h)); }
protected override void LoadScene() { mainScreneImages = LoadAsset<SpriteSheet>("MainSceneImages"); westernFont = LoadAsset<SpriteFont>("WesternFont"); popupWindowImage = mainScreneImages["popup_window"]; // Preload stars starSprites.Add(mainScreneImages["star0"]); starSprites.Add(mainScreneImages["star1"]); starSprites.Add(mainScreneImages["star2"]); starSprites.Add(mainScreneImages["star3"]); borderStarImages.Add(mainScreneImages["bstar0"]); borderStarImages.Add(mainScreneImages["bstar1"]); borderStarImages.Add(mainScreneImages["bstar2"]); borderStarImages.Add(mainScreneImages["bstar3"]); // Create space ships var random = new Random(); for (var i = 0; i < ShipNameList.Count; i++) { shipList.Add(new SpaceShip { Name = ShipNameList[i], Power = random.Next(4), Control = random.Next(4), Speed = random.Next(4), IsLocked = (i % 3) == 2, }); } var mainStackPanel = CreateMainScene(); CreateWelcomePopup(); CreateShipSelectionPopup(); // Create the background var background = new ImageElement { Source = mainScreneImages["background_uiimage"], StretchType = StretchType.Fill }; background.SetPanelZIndex(-1); // Overlay pop-ups and the main screen var overlay = new UniformGrid(); overlay.Children.Add(background); overlay.Children.Add(mainStackPanel); overlay.Children.Add(welcomePopup); overlay.Children.Add(shipSelectPopup); // Set the root element to the overall overlay var uiComponent = Entity.Get<UIComponent>(); uiComponent.RootElement = overlay; Script.AddTask(FillLifeBar); }
public static IObservable <EventPattern <StylusEventArgs> > PreviewStylusInAirMoveObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.PreviewStylusInAirMove += h, h => This.PreviewStylusInAirMove -= h)); }
private UIElement CreateMainSceneShipStatusPanel() { // Status star bars {Power, Life, Speed} var powerStatusDecorator = CreateMainSceneShipStatusStars("power", powerStatusStar, 0); var controlStatusDecorator = CreateMainSceneShipStatusStars("control", controlStatusStar, 1); var speedStatusDecorator = CreateMainSceneShipStatusStars("speed", speedStatusStar, 2); PowerStatus = shipList[activeShipIndex].Power; ControlStatus = shipList[activeShipIndex].Control; SpeedStatus = shipList[activeShipIndex].Speed; // Put the stats (Stars) in 3x1 uniform grid var statusPanel = new UniformGrid { Rows = 3 }; statusPanel.Children.Add(powerStatusDecorator); statusPanel.Children.Add(controlStatusDecorator); statusPanel.Children.Add(speedStatusDecorator); statusPanel.SetGridColumn(1); // SpaceShip Button currentShipImage = new ImageElement { Source = mainScreneImages[shipList[activeShipIndex].Name], }; currentShipImage.SetGridRow(1); var shipImageSpacerGrid = new Grid { HorizontalAlignment = HorizontalAlignment.Center }; shipImageSpacerGrid.Children.Add(currentShipImage); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2)); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 6)); shipImageSpacerGrid.RowDefinitions.Add(new StripDefinition(StripType.Star, 2)); shipImageSpacerGrid.ColumnDefinitions.Add(new StripDefinition()); shipImageSpacerGrid.LayerDefinitions.Add(new StripDefinition()); var shipButtonDesign = mainScreneImages["display_element"]; var currentShipButton = new Button { NotPressedImage = shipButtonDesign, PressedImage = shipButtonDesign, MouseOverImage = shipButtonDesign, Content = shipImageSpacerGrid, Padding = new Thickness(45, 20, 10, 25), VerticalAlignment = VerticalAlignment.Center }; currentShipButton.Click += delegate { // Once click, update the SpaceShip status pop-up and show it. UpdateShipStatus(); ShowShipSelectionPopup(); }; currentShipButton.SetGridColumn(3); // Status upgrade buttons var powerUpgradeButton = CreateIncreaseStatusButton("P", 0, 0, 2, 0, () => PowerStatus, () => PowerStatus++); var controlUpgradeButton = CreateIncreaseStatusButton("C", 0, 1, 2, 0, () => ControlStatus, () => ControlStatus++); var speedUpgradeButton = CreateIncreaseStatusButton("S", 1, 0, 2, 0, () => SpeedStatus, () => SpeedStatus++); var lifeUpgradeButton = CreateIncreaseStatusButton("L", 1, 1, 1, 1, () => 0, () => LifeStatus++); // Arrange the status up buttons in a 2x2 Uniform grid. var statusUpgradeGridPanel = new UniformGrid { Rows = 2, Columns = 2, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; statusUpgradeGridPanel.Children.Add(powerUpgradeButton); statusUpgradeGridPanel.Children.Add(controlUpgradeButton); statusUpgradeGridPanel.Children.Add(speedUpgradeButton); statusUpgradeGridPanel.Children.Add(lifeUpgradeButton); statusUpgradeGridPanel.SetGridColumn(5); // Put together bottom region in horizontal Stack panel, arranging it from left to right var mainPanel = new Grid(); mainPanel.RowDefinitions.Add(new StripDefinition()); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 25)); // space mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 3)); mainPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10)); // space mainPanel.LayerDefinitions.Add(new StripDefinition()); mainPanel.Children.Add(statusPanel); mainPanel.Children.Add(currentShipButton); mainPanel.Children.Add(statusUpgradeGridPanel); return mainPanel; }
protected override async Task LoadContent() { await base.LoadContent(); const float relativeSize = 1 / 6f; var canvas = new Canvas(); canvas.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); // left/top var image1 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image1.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image1.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 0, 0)); image1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0, 0)); canvas.Children.Add(image1); // right/top var image2 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image2.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image2.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 0, 0)); image2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 0, 0)); canvas.Children.Add(image2); // left/bottom var image3 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image3.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image3.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 1, 0)); image3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 1, 0)); canvas.Children.Add(image3); // 1/3 right/bottom var image4 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image4.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image4.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 1, 0)); image4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 1, 0)); canvas.Children.Add(image4); // 1/3 left/top middle centered var image5 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image5.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image5.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1 / 3f, 1 / 3f, 0)); image5.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0)); canvas.Children.Add(image5); // 1/3 right/top right aligned var image6 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image6.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image6.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 1 / 3f, 0)); image6.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0.5f, 0)); canvas.Children.Add(image6); // 1/3 left/bottom bottom aligned var image7 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image7.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image7.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1 / 3f, 2 / 3f, 0)); image7.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0, 0)); canvas.Children.Add(image7); // 1/3 right/bottom top aligned var image8 = new ImageElement { Source = new Sprite(Asset.Load <Texture>("uv")), StretchType = StretchType.FillOnStretch }; image8.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image8.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 2 / 3f, 0)); image8.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 1, 0)); canvas.Children.Add(image8); var grid = new UniformGrid { Rows = 3, Columns = 3 }; for (int c = 0; c < 3; c++) { for (int r = 0; r < 3; r++) { CreateAndInsertButton(grid, c, r); } } var baseGrid = new UniformGrid(); baseGrid.Children.Add(grid); baseGrid.Children.Add(canvas); UIComponent.RootElement = baseGrid; }
protected override async Task LoadContent() { await base.LoadContent(); Sprites = Asset.Load<SpriteSheet>("UIImages"); var lifeBar = new ImageElement { Source = Sprites["Logo"], HorizontalAlignment = HorizontalAlignment.Center }; lifeBar.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3); var quitGameButton = new Button { Content = new TextBlock { Text = "Quit Game", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Padding = Thickness.UniformRectangle(10), }; quitGameButton.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0); quitGameButton.DependencyProperties.Set(GridBase.RowPropertyKey, 2); quitGameButton.Click += (sender, args) => Exit(); modalButton1Text = new TextBlock { Text = "Close Modal window 1", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; var modalButton1 = new Button { Name = "Button Modal 1", Content = modalButton1Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; modalButton1.Click += ModalButton1OnClick; modal1 = new ModalElement { Content = modalButton1, Name = "Modal 1"}; modal1.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal1.DependencyProperties.Set(GridBase.RowPropertyKey, 1); modal1.OutsideClick += Modal1OnOutsideClick; modalButton2Text = new TextBlock { Text = "Close Modal window 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15") }; var modalButton2 = new Button { Name = "Button Modal 2", Content = modalButton2Text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Padding = Thickness.UniformRectangle(10), }; modalButton2.Click += ModalButton2OnClick; modal2 = new ModalElement { Content = modalButton2, Name = "Modal 2" }; modal2.DependencyProperties.Set(Panel.ZIndexPropertyKey, 2); modal2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1); modal2.DependencyProperties.Set(GridBase.RowPropertyKey, 2); modal2.OutsideClick += Modal2OnOutsideClick; uniformGrid = new UniformGrid { Columns = 3, Rows = 3 }; uniformGrid.Children.Add(modal1); uniformGrid.Children.Add(modal2); uniformGrid.Children.Add(lifeBar); uniformGrid.Children.Add(quitGameButton); UIComponent.RootElement = uniformGrid; }
public static IObservable <EventPattern <StylusEventArgs> > StylusOutOfRangeObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.StylusOutOfRange += h, h => This.StylusOutOfRange -= h)); }
public DlgMethods() { Title = "About"; ShowInTaskbar = false; WindowStyle = WindowStyle.ToolWindow; WindowStartupLocation = WindowStartupLocation.CenterOwner; ResizeMode = ResizeMode.NoResize; SizeToContent = SizeToContent.WidthAndHeight; StackPanel stack = new StackPanel(); Content = stack; Grid grid = new Grid(); grid.Margin = new Thickness(6); stack.Children.Add(grid); RowDefinition rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; grid.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; grid.RowDefinitions.Add(rowdef); rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; grid.RowDefinitions.Add(rowdef); ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = GridLength.Auto; grid.ColumnDefinitions.Add(coldef); Label lblText = new Label(); lblText.Content = "Numerical Methods v9.00"; lblText.FontSize = 24; lblText.Foreground = Brushes.YellowGreen; //lblText.FontStyle grid.Children.Add(lblText); Grid.SetRow(lblText, 0); Grid.SetColumn(lblText, 0); /* Label lblText2 = new Label(); * lblText2.Content = "Author:"; * lblText2.FontSize = 12; * lblText2.Foreground = Brushes.Black; * lblText2.HorizontalAlignment = HorizontalAlignment.Center;*/ Border bord = new Border(); bord.Background = Brushes.SlateGray; grid.Children.Add(bord); Grid.SetRow(bord, 0); Grid.SetColumn(bord, 0); bord.BorderBrush = Brushes.Gray; bord.Background = Brushes.White; bord.BorderThickness = new Thickness(2); CornerRadius c = new CornerRadius(); c.BottomLeft = 20; c.BottomRight = 20; c.TopLeft = 20; c.TopRight = 20; bord.CornerRadius = c; Border bordIn = new Border(); bordIn.Background = Brushes.SlateGray; bordIn.BorderBrush = Brushes.YellowGreen; bord.Child = bordIn; bordIn.Background = Brushes.White; bordIn.BorderThickness = new Thickness(2); CornerRadius c2 = new CornerRadius(); c2.BottomLeft = 20; c2.BottomRight = 20; c2.TopLeft = 20; c2.TopRight = 20; bordIn.CornerRadius = c2; DockPanel dock = new DockPanel(); dock.Margin = new Thickness(10); bordIn.Child = dock; Expander expanderMenu; //*** "Approximate decision of \n equalization f(x)=0 *** expanderMenu = new Expander(); dock.Children.Add(expanderMenu); DockPanel.SetDock(expanderMenu, Dock.Top); expanderMenu.Header = "Approximate decision of \n equalization f(x)=0"; expanderMenu.Foreground = Brushes.White; expanderMenu.Margin = new Thickness(0, 0, 0, 10); expanderMenu.Background = Brushes.SlateGray; ListView ListApproximateDecision = new ListView(); ListViewItem BisectionMethodItem = new ListViewItem(); BisectionMethodItem.Content = "Bisection Method"; ListViewItem ChordMethodItem = new ListViewItem(); ChordMethodItem.Content = "Chord Method"; ListViewItem IterationMethodItem = new ListViewItem(); IterationMethodItem.Content = "Iteration Method"; ListViewItem NewtonMethodItem = new ListViewItem(); NewtonMethodItem.Content = "Newton Method"; ListApproximateDecision.Items.Add(BisectionMethodItem); ListApproximateDecision.Items.Add(ChordMethodItem); ListApproximateDecision.Items.Add(IterationMethodItem); ListApproximateDecision.Items.Add(NewtonMethodItem); expanderMenu.Content = ListApproximateDecision; expanderMenu = new Expander(); dock.Children.Add(expanderMenu); expanderMenu.Foreground = Brushes.White; expanderMenu.Header = "Numerical Methods"; expanderMenu.Margin = new Thickness(0, 0, 0, 10); expanderMenu.Background = Brushes.SlateGray; ListView list2 = new ListView(); ListViewItem listV12 = new ListViewItem(); listV12.Content = "Method1"; ListViewItem listV22 = new ListViewItem(); listV22.Content = "Method2"; list2.Items.Add(listV12); list2.Items.Add(listV22); expanderMenu.Content = list2; Grid.SetRow(bord, 1); Grid.SetColumn(bord, 0); /* grid.Children.Add(lblText3); * Grid.SetRow(lblText3, 2); * Grid.SetColumn(lblText3, 0);*/ // Создание элемента UniformGrid для кнопок OK и Cancel UniformGrid unigrid = new UniformGrid(); unigrid.Rows = 1; unigrid.Columns = 1; stack.Children.Add(unigrid); // Создание объекта Button btnOk = new Button(); // Назначение шаблона //btnOk.Template = DesignButton(); btnOk.IsDefault = true; btnOk.Padding = new Thickness(5); btnOk.Margin = new Thickness(12); btnOk.HorizontalAlignment = HorizontalAlignment.Center; btnOk.VerticalAlignment = VerticalAlignment.Center; btnOk.Content = "OK"; btnOk.Click += OkButtonOnClick; unigrid.Children.Add(btnOk); }
public static IObservable <EventPattern <StylusSystemGestureEventArgs> > StylusSystemGestureObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusSystemGestureEventHandler, StylusSystemGestureEventArgs>(h => This.StylusSystemGesture += h, h => This.StylusSystemGesture -= h)); }
public static IObservable <EventPattern <StylusEventArgs> > LostStylusCaptureObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.LostStylusCapture += h, h => This.LostStylusCapture -= h)); }
public static IObservable <EventPattern <StylusButtonEventArgs> > StylusButtonDownObserver(this UniformGrid This) { return(Observable.FromEventPattern <StylusButtonEventHandler, StylusButtonEventArgs>(h => This.StylusButtonDown += h, h => This.StylusButtonDown -= h)); }
protected override async Task LoadContent() { await base.LoadContent(); const float relativeSize = 1 / 6f; var canvas = new Canvas(); canvas.DependencyProperties.Set(Panel.ZIndexPropertyKey, 1); // left/top var image1 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image1.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image1.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 0, 0)); image1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0, 0)); canvas.Children.Add(image1); // right/top var image2 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image2.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image2.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 0, 0)); image2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 0, 0)); canvas.Children.Add(image2); // left/bottom var image3 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image3.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image3.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(0, 1, 0)); image3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 1, 0)); canvas.Children.Add(image3); // 1/3 right/bottom var image4 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image4.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image4.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1, 1, 0)); image4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(1, 1, 0)); canvas.Children.Add(image4); // 1/3 left/top middle centered var image5 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image5.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image5.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 1/3f, 0)); image5.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0)); canvas.Children.Add(image5); // 1/3 right/top right aligned var image6 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image6.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image6.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2 / 3f, 1 / 3f, 0)); image6.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0, 0.5f, 0)); canvas.Children.Add(image6); // 1/3 left/bottom bottom aligned var image7 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image7.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image7.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(1/3f, 2/3f, 0)); image7.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 0, 0)); canvas.Children.Add(image7); // 1/3 right/bottom top aligned var image8 = new ImageElement { Source = new UIImage(Asset.Load<Texture>("uv")), StretchType = StretchType.FillOnStretch }; image8.DependencyProperties.Set(Canvas.RelativeSizePropertyKey, relativeSize * Vector3.One); image8.DependencyProperties.Set(Canvas.RelativePositionPropertyKey, new Vector3(2/3f, 2/3f, 0)); image8.DependencyProperties.Set(Canvas.PinOriginPropertyKey, new Vector3(0.5f, 1, 0)); canvas.Children.Add(image8); var grid = new UniformGrid { Rows = 3, Columns = 3 }; for (int c = 0; c < 3; c++) for (int r = 0; r < 3; r++) CreateAndInsertButton(grid, c, r); var baseGrid = new UniformGrid(); baseGrid.Children.Add(grid); baseGrid.Children.Add(canvas); UIComponent.RootElement = baseGrid; }
public static IObservable <EventPattern <RequestBringIntoViewEventArgs> > RequestBringIntoViewObserver(this UniformGrid This) { return(Observable.FromEventPattern <RequestBringIntoViewEventHandler, RequestBringIntoViewEventArgs>(h => This.RequestBringIntoView += h, h => This.RequestBringIntoView -= h)); }
public static IObservable <EventPattern <DependencyPropertyChangedEventArgs> > DataContextChangedObserver(this UniformGrid This) { return(Observable.FromEventPattern <DependencyPropertyChangedEventHandler, DependencyPropertyChangedEventArgs>(h => This.DataContextChanged += h, h => This.DataContextChanged -= h)); }
public void Test_UniformGrid_SetupColumnDefinitions_AllAutomatic() { var treeroot = XamlReader.Load(@"<Page xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""> <controls:UniformGrid x:Name=""UniformGrid""> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> <Border/> </controls:UniformGrid> </Page>") as FrameworkElement; Assert.IsNotNull(treeroot, "Could not load XAML tree."); var grid = treeroot.FindChild("UniformGrid") as UniformGrid; Assert.IsNotNull(grid, "Could not find UniformGrid in tree."); // Normal Grid's don't have any definitions to start Assert.AreEqual(0, grid.ColumnDefinitions.Count); // We'll have three columns in this setup grid.SetupColumnDefinitions(3); // We should now have our columns created Assert.AreEqual(3, grid.ColumnDefinitions.Count); for (int i = 0; i < grid.ColumnDefinitions.Count; i++) { var cd = grid.ColumnDefinitions[i]; // Check if we've setup our row to automatically layout Assert.AreEqual(true, UniformGrid.GetAutoLayout(cd)); // We need to be using '*' layout for all our rows to be even. Assert.AreEqual(GridUnitType.Star, cd.Width.GridUnitType); Assert.AreEqual(1.0, cd.Width.Value); } //// DO IT AGAIN //// This is so we can check that it will behave the same again on another pass. // We'll have three columns in this setup grid.SetupColumnDefinitions(3); // We should now have our columns created Assert.AreEqual(3, grid.ColumnDefinitions.Count); for (int i = 0; i < grid.ColumnDefinitions.Count; i++) { var cd = grid.ColumnDefinitions[i]; // Check if we've setup our row to automatically layout Assert.AreEqual(true, UniformGrid.GetAutoLayout(cd)); // We need to be using '*' layout for all our rows to be even. Assert.AreEqual(GridUnitType.Star, cd.Width.GridUnitType); Assert.AreEqual(1.0, cd.Width.Value); } }