-
-
Save w0wca7a/2fa3af77b0aa8aba06df207790e7c312 to your computer and use it in GitHub Desktop.
Xenko Window thingy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using SiliconStudio.Core.Mathematics; | |
| using SiliconStudio.Xenko.Engine; | |
| using SiliconStudio.Xenko.Graphics; | |
| using SiliconStudio.Xenko.UI; | |
| using SiliconStudio.Xenko.UI.Controls; | |
| using SiliconStudio.Xenko.UI.Panels; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace UIWindow | |
| { | |
| public class WindowManager : SyncScript | |
| { | |
| public SpriteFont UIFont; | |
| private Canvas uiRoot; | |
| public override void Start() | |
| { | |
| var uiComponent = Entity.Get<UIComponent>(); | |
| if(uiComponent != null) | |
| { | |
| uiComponent.RootElement = uiRoot = new Canvas(); | |
| var window = new ChildWindow(UIFont); | |
| window.CaptionTitle = "Hello Window"; | |
| window.Show(uiRoot); | |
| } | |
| } | |
| public override void Update() | |
| { | |
| } | |
| } | |
| internal class ChildWindow | |
| { | |
| private Canvas windowHost; | |
| private Border captionBar; | |
| private TextBlock captionBarTitle; | |
| private Border clientArea; | |
| private Grid windowRoot; | |
| public ChildWindow(SpriteFont font) | |
| { | |
| captionBar = new Border(); | |
| captionBar.Name = "CaptionBar"; | |
| captionBar.Padding = new Thickness(2, 2, 2, 2); | |
| captionBar.MinimumHeight = 30; | |
| captionBar.HorizontalAlignment = HorizontalAlignment.Stretch; | |
| captionBar.BackgroundColor = Color.Blue; | |
| captionBar.SetGridRow(0); | |
| captionBar.CanBeHitByUser = true; | |
| captionBar.TouchMove += CaptionBar_TouchMove; | |
| var captionBarContent = new Grid(); | |
| captionBarContent.RowDefinitions.Add(new StripDefinition()); | |
| captionBarContent.ColumnDefinitions.Add(new StripDefinition()); | |
| captionBarContent.ColumnDefinitions.Add(new StripDefinition() { Type = StripType.Auto }); | |
| captionBarTitle = new TextBlock() { Font = font, TextColor= Color.White, }; | |
| captionBarTitle.SetGridColumn(0); | |
| captionBarContent.Children.Add(captionBarTitle); | |
| captionBar.Content = captionBarContent; | |
| var closeButton = new Button() | |
| { | |
| Content = new TextBlock { Font = font, TextColor = Color.White, Text = "X" }, | |
| BackgroundColor = Color.Red, | |
| }; | |
| closeButton.SetGridColumn(1); | |
| captionBarContent.Children.Add(closeButton); | |
| closeButton.Click += CloseButton_Click; | |
| clientArea = new Border(); | |
| clientArea.Name = "ClientArea"; | |
| clientArea.SetGridRow(1); | |
| clientArea.MinimumWidth = 100; | |
| clientArea.MinimumHeight = 100; | |
| clientArea.BackgroundColor = Color.White; | |
| clientArea.BorderColor = Color.Blue; | |
| clientArea.BorderThickness = new Thickness(2, 0, 2, 2); | |
| windowRoot = new Grid(); | |
| windowRoot.RowDefinitions.Add(new StripDefinition() { Type = StripType.Auto }); | |
| windowRoot.RowDefinitions.Add(new StripDefinition()); | |
| windowRoot.ColumnDefinitions.Add(new StripDefinition()); | |
| windowRoot.Children.Add(captionBar); | |
| windowRoot.Children.Add(clientArea); | |
| } | |
| public string CaptionTitle | |
| { | |
| get { return captionBarTitle.Text ; } | |
| set { captionBarTitle.Text = value; } | |
| } | |
| public UIElement Content | |
| { | |
| get { return clientArea.Content; } | |
| set { clientArea.Content = value; } | |
| } | |
| public void Show(Canvas windowHost) | |
| { | |
| this.windowHost = windowHost; | |
| windowHost.Children.Add(windowRoot); | |
| } | |
| private void CloseButton_Click(object sender, SiliconStudio.Xenko.UI.Events.RoutedEventArgs e) | |
| { | |
| windowHost.Children.Remove(windowRoot); | |
| } | |
| private void CaptionBar_TouchMove(object sender, TouchEventArgs e) | |
| { | |
| var position = windowRoot.GetCanvasRelativePosition(); | |
| position += (Vector3)e.ScreenTranslation; | |
| windowRoot.SetCanvasRelativePosition(position); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment