/// <summary> /// Creates a new console app given a set of boundaries /// </summary> /// <param name="w">The width of the app</param> /// <param name="h">The height of the app</param> public ConsoleApp(int w, int h) { this.Name = GetType().Name; this.console = ConsoleProvider.Current; consoleWriter = Console.Out; this.lastConsoleWidth = this.console.BufferWidth; this.lastConsoleHeight = this.console.WindowHeight; this.observable = new ObservableObject(this); cycleRateMeter = new FrameRateMeter(); this.EndOfCycle.SubscribeForLifetime(Cycle, this); SetFocusOnStart = true; LayoutRoot = new ConsolePanel(w, h); FocusManager = new FocusManager(); LayoutRoot.Application = this; isFullScreen = false; FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), () => RequestPaintAsync(), this); LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, this); LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, this); LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, this); LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, this); WindowResized.SubscribeForLifetime(HandleDebouncedResize, this); this.LoopStarted.SubscribeOnce(() => _current = this); this.EndOfCycle.SubscribeForLifetime(DrainPaints, this); }
/// <summary> /// Creates a new console app given a set of boundaries /// </summary> /// <param name="x">The left position on the target console to bound this app</param> /// <param name="y">The right position on the target console to bound this app</param> /// <param name="w">The width of the app</param> /// <param name="h">The height of the app</param> public ConsoleApp(int x, int y, int w, int h) : base(ConsoleProvider.Current) { SetFocusOnStart = true; Theme = new Theme(); Bitmap = new ConsoleBitmap(x, y, w, h); LayoutRoot = new ConsolePanel { Width = w, Height = h }; FocusManager = new FocusManager(); LayoutRoot.Application = this; AutoFillOnConsoleResize = false; FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), Paint, LifetimeManager); LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, LifetimeManager); LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, LifetimeManager); LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, LifetimeManager); LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, LifetimeManager); WindowResized.SubscribeForLifetime(HandleDebouncedResize, LifetimeManager); }
/// <summary> /// Creates a new console app given a set of boundaries /// </summary> /// <param name="x">The left position on the target console to bound this app</param> /// <param name="y">The right position on the target console to bound this app</param> /// <param name="w">The width of the app</param> /// <param name="h">The height of the app</param> public ConsoleApp(int x, int y, int w, int h) : base(ConsoleProvider.Current) { SetFocusOnStart = true; Bitmap = new ConsoleBitmap(x, y, w, h); LayoutRoot = new ConsolePanel { Width = w, Height = h }; FocusManager = new FocusManager(); LayoutRoot.Application = this; AutoFillOnConsoleResize = false; FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), () => Paint(), this); LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, this); LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, this); LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, this); LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, this); WindowResized.SubscribeForLifetime(HandleDebouncedResize, this); }
/// <summary> /// Creates a new console app given a set of boundaries /// </summary> /// <param name="x">The left position on the target console to bound this app</param> /// <param name="y">The right position on the target console to bound this app</param> /// <param name="w">The width of the app</param> /// <param name="h">The height of the app</param> public ConsoleApp(int x, int y, int w, int h) { SetFocusOnStart = true; Theme = new Theme(); Bitmap = new ConsoleBitmap(x, y, w, h); MessagePump = new CliMessagePump(Bitmap.Console, KeyPressed); LayoutRoot = new ConsolePanel { Width = w, Height = h }; FocusManager = new FocusManager(); LayoutRoot.Application = this; AutoFillOnConsoleResize = false; FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), Paint, LifetimeManager); LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, LifetimeManager); LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, LifetimeManager); LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, LifetimeManager); LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, LifetimeManager); MessagePump.WindowResized.SubscribeForLifetime(HandleDebouncedResize, LifetimeManager); }