|
| 1 | +// ----------------------------------------------------------------------- |
| 2 | +// ConsoleEx - A simple console window system for .NET Core |
| 3 | +// |
| 4 | +// Author: Nikolaos Protopapas |
| 5 | +// Email: nikolaos.protopapas@gmail.com |
| 6 | +// License: MIT |
| 7 | +// ----------------------------------------------------------------------- |
| 8 | + |
| 9 | +using SharpConsoleUI.Controls; |
| 10 | +using SharpConsoleUI.DataBinding; |
| 11 | +using SharpConsoleUI.Layout; |
| 12 | +using SharpConsoleUI.Video; |
| 13 | + |
| 14 | +namespace SharpConsoleUI.Builders; |
| 15 | + |
| 16 | +/// <summary> |
| 17 | +/// Fluent builder for <see cref="VideoControl"/>. |
| 18 | +/// </summary> |
| 19 | +public sealed class VideoControlBuilder : IControlBuilder<VideoControl> |
| 20 | +{ |
| 21 | + private readonly VideoControl _control = new(); |
| 22 | + |
| 23 | + /// <summary>Sets the video file path.</summary> |
| 24 | + public VideoControlBuilder WithFile(string filePath) |
| 25 | + { |
| 26 | + _control.FilePath = filePath; |
| 27 | + return this; |
| 28 | + } |
| 29 | + |
| 30 | + /// <summary>Sets the render mode.</summary> |
| 31 | + public VideoControlBuilder WithRenderMode(VideoRenderMode mode) |
| 32 | + { |
| 33 | + _control.RenderMode = mode; |
| 34 | + return this; |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary>Sets the target frames per second.</summary> |
| 38 | + public VideoControlBuilder WithTargetFps(int fps) |
| 39 | + { |
| 40 | + _control.TargetFps = fps; |
| 41 | + return this; |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary>Enables looping playback.</summary> |
| 45 | + public VideoControlBuilder WithLooping(bool loop = true) |
| 46 | + { |
| 47 | + _control.Looping = loop; |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary>Enables the bottom overlay status bar (auto-show on interaction, auto-hide after 3s).</summary> |
| 52 | + public VideoControlBuilder WithOverlay(bool enabled = true) |
| 53 | + { |
| 54 | + _control.OverlayEnabled = enabled; |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary>Sets horizontal alignment.</summary> |
| 59 | + public VideoControlBuilder WithAlignment(HorizontalAlignment alignment) |
| 60 | + { |
| 61 | + _control.HorizontalAlignment = alignment; |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary>Sets vertical alignment.</summary> |
| 66 | + public VideoControlBuilder WithVerticalAlignment(VerticalAlignment alignment) |
| 67 | + { |
| 68 | + _control.VerticalAlignment = alignment; |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + /// <summary>Stretch horizontally to fill.</summary> |
| 73 | + public VideoControlBuilder Stretch() |
| 74 | + { |
| 75 | + _control.HorizontalAlignment = HorizontalAlignment.Stretch; |
| 76 | + return this; |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary>Fill vertically and stretch horizontally.</summary> |
| 80 | + public VideoControlBuilder Fill() |
| 81 | + { |
| 82 | + _control.VerticalAlignment = VerticalAlignment.Fill; |
| 83 | + _control.HorizontalAlignment = HorizontalAlignment.Stretch; |
| 84 | + return this; |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary>Sets control margin.</summary> |
| 88 | + public VideoControlBuilder WithMargin(int left, int top, int right, int bottom) |
| 89 | + { |
| 90 | + _control.Margin = new Margin(left, top, right, bottom); |
| 91 | + return this; |
| 92 | + } |
| 93 | + |
| 94 | + /// <summary>Sets the control name.</summary> |
| 95 | + public VideoControlBuilder WithName(string name) |
| 96 | + { |
| 97 | + _control.Name = name; |
| 98 | + return this; |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary>Subscribes to playback state changes.</summary> |
| 102 | + public VideoControlBuilder OnPlaybackStateChanged(EventHandler<VideoPlaybackState> handler) |
| 103 | + { |
| 104 | + _control.PlaybackStateChanged += handler; |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + /// <summary>Subscribes to playback ended.</summary> |
| 109 | + public VideoControlBuilder OnPlaybackEnded(EventHandler handler) |
| 110 | + { |
| 111 | + _control.PlaybackEnded += handler; |
| 112 | + return this; |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary>Builds the VideoControl.</summary> |
| 116 | + public VideoControl Build() => _control; |
| 117 | +} |
0 commit comments