/// <summary> /// Creates a console bitmap player control with no video loaded /// </summary> public ConsoleBitmapPlayer(bool showButtonBar = true) { this.CanFocus = false; RewindAndFastForwardIncrement = TimeSpan.FromSeconds(10); pictureInTheFrame = new BitmapControl() { AutoSize = true, CanFocus = false }; pictureFrame = Add(new BorderPanel(pictureInTheFrame)).Fill(padding: new Thickness(0, 0, 0, 2)); pictureInTheFrame.CenterBoth(); pictureFrame.BorderColor = ConsoleColor.DarkGray; playerProgressBar = Add(new PlayerProgressBar() { ShowPlayCursor = false }).FillHorizontally(padding: new Thickness(0, 0, 0, 0)).DockToBottom(padding: 1); var buttonBar = Add(new StackPanel() { CanFocus = false, Height = 1, Orientation = Orientation.Horizontal }).FillHorizontally().DockToBottom(); seekToBeginningButton = buttonBar.Add(new Button() { Text = "<<".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.Home), CanFocus = false }); seekBack10SButton = buttonBar.Add(new Button() { Shortcut = new KeyboardShortcut(ConsoleKey.LeftArrow), CanFocus = false }); playButton = buttonBar.Add(new Button() { Text = "".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.P), CanFocus = false }); seekForward10SButton = buttonBar.Add(new Button() { Shortcut = new KeyboardShortcut(ConsoleKey.RightArrow), CanFocus = false }); seekToEndButton = buttonBar.Add(new Button() { Text = ">>".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.End), CanFocus = false }); if (showButtonBar) { seekToBeginningButton.Pressed.SubscribeForLifetime(SeekToBeginningButtonPressed, this); seekBack10SButton.Pressed.SubscribeForLifetime(Rewind, this); playButton.Pressed.SubscribeForLifetime(PlayPressed, this); seekForward10SButton.Pressed.SubscribeForLifetime(FastForward, this); seekToEndButton.Pressed.SubscribeForLifetime(SeekToEndButtonPressed, this); } else { buttonBar.IsVisible = false; } this.SubscribeForLifetime(nameof(State), StateChanged, this); this.SynchronizeForLifetime(nameof(RewindAndFastForwardIncrement), () => { seekBack10SButton.Text = $"< {RewindAndFastForwardIncrement.TotalSeconds}s".ToConsoleString(); seekForward10SButton.Text = $"{RewindAndFastForwardIncrement.TotalSeconds}s >".ToConsoleString(); }, this); State = PlayerState.NotLoaded; }
private void InitFramePanel() { // vertical divider framePanel.Add(new ConsolePanel() { Width = 1, Background = RGB.White }).DockToRight().FillVertically(); var options = new ListGridOptions <InMemoryConsoleBitmapFrame>() { DataSource = new SyncList <InMemoryConsoleBitmapFrame>(animation.Frames), Columns = new List <ListGridColumnDefinition <InMemoryConsoleBitmapFrame> >() { new ListGridColumnDefinition <InMemoryConsoleBitmapFrame>() { Width = framePanel.Width - 2, Type = GridValueType.Pixels, Formatter = f => new Label() { Text = $"Frame {animation.Frames.IndexOf(f)+1}".ToWhite() }, Header = "Frame".ToYellow(), } }, ShowColumnHeaders = false, ShowPager = false, EnablePagerKeyboardShortcuts = false, }; frameList = framePanel.Add(new ListGrid <InMemoryConsoleBitmapFrame>(options)).Fill(padding: new Thickness(1, 1, 0, 0)); refreshed.SubscribeForLifetime(() => { frameList.Refresh(); }, frameList); BorderPanel fakeDialog = null; Label fakeDialogLabel = null; frameList.SelectionChanged.SubscribeForLifetime(() => { CurrentFrameIndex = frameList.SelectedRowIndex; Refresh(); if (fakeDialog != null) { fakeDialog.X = frameList.AbsoluteX + frameList.Width - 2; fakeDialog.Y = frameList.Y + 1 + frameList.SelectedRowIndex; fakeDialogLabel.Text = FormatTimespanForFramePopup(CurrentFrame.FrameTime); } }, frameList); frameList.Focused.SubscribeForLifetime(() => { var fakeDialogContent = new ConsolePanel() { Background = TimespanPopupBGColor }; fakeDialog = ConsoleApp.Current.LayoutRoot.Add(new BorderPanel(fakeDialogContent)); fakeDialog.BorderColor = RGB.Blue; fakeDialog.Width = 30; fakeDialog.Height = 5; fakeDialog.X = frameList.AbsoluteX + frameList.Width - 2; fakeDialog.Y = frameList.Y + 1 + frameList.SelectedRowIndex; fakeDialogContent.Fill(); fakeDialogLabel = fakeDialogContent.Add(new Label() { Text = FormatTimespanForFramePopup(CurrentFrame.FrameTime) }).CenterBoth(); refreshed.SubscribeForLifetime(() => { fakeDialogLabel.Text = FormatTimespanForFramePopup(CurrentFrame.FrameTime); }, fakeDialogLabel); ConsoleApp.Current.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.OemPlus, null, () => { undoRedo.Do(new ShiftTimeStampForwardAction(this, CurrentFrameIndex, 50)); }, fakeDialog); ConsoleApp.Current.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.OemMinus, null, () => { undoRedo.Do(new ShiftTimeStampBackwardAction(this, CurrentFrameIndex, 50)); }, fakeDialog); ConsoleApp.Current.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.OemPlus, ConsoleModifiers.Shift, () => { undoRedo.Do(new ShiftTimeStampForwardAction(this, CurrentFrameIndex, 10)); }, fakeDialog); ConsoleApp.Current.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.OemMinus, ConsoleModifiers.Shift, () => { undoRedo.Do(new ShiftTimeStampBackwardAction(this, CurrentFrameIndex, 10)); }, fakeDialog); }, frameList); frameList.Unfocused.SubscribeForLifetime(() => { fakeDialog?.Dispose(); fakeDialogLabel = null; fakeDialog = null; }, frameList); }