public (IGameWindow, ISoundPlayer) Run(IGameFrame frame) { AvaloniaWindow window = null; ClassicDesktopStyleApplicationLifetime lifetime; if (Application.Current == null) { var builder = AppBuilder.Configure <Application>() .UsePlatformDetect() .With(new AvaloniaNativePlatformOptions { UseGpu = true }); lifetime = new ClassicDesktopStyleApplicationLifetime() { }; Task.Run(() => { builder.Start((app, args) => { window = CreateWindow(frame); lifetime.MainWindow = window; window.Show(); window.Closed += (o, e) => Environment.Exit(0); app.Run(System.Threading.CancellationToken.None); }, null); }); while (window == null) { } } else { AvaloniaWindow win = null; Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() => { win = CreateWindow(frame); win.Show(); }); while (win == null) { } return(win, soundPlayer); } soundPlayer = new AvaloniaSoundPlayer(); return(window, soundPlayer); }
public GamePanel(AvaloniaWindow window, int width, int height, double xScale, double yScale) { Panel = this; this.window = window; this.Name = "panel"; Drawing = false; this.ScaleX = xScale; this.ScaleY = yScale; this.Width = width * xScale; this.Height = height * yScale; WindowWidth = (int)this.Width; WindowHeight = (int)this.Height; }
private AvaloniaWindow CreateWindow(IGameFrame frame) { AvaloniaWindow window = new AvaloniaWindow(frame.Bounds.Width, frame.Bounds.Height); window.Title = title; GamePanel panel = new GamePanel(window, (int)(frame.Bounds.Width / frame.ScaleX), (int)(frame.Bounds.Height / frame.ScaleY), frame.ScaleX, frame.ScaleY); window.Add(panel); window.WindowStartupLocation = startupLocation; window.TransparencyLevelHint = transparency; window.SystemDecorations = decorations; window.Topmost = topMost; window.ShowInTaskbar = showInTaskBar; window.CanResize = canResize; return(window); }