using System; using System.Drawing; using System.Drawing.Drawing2D; using JD.Audio.SoundPlayer; using JD.Kernel.StaticHelpers; using JD.Sequencers.Windowlesses; using TeaBox; namespace JD.Application.View.WindowLess { internal class CheckpointWidget : WindowlessControl { private readonly Checkpoint _model; private readonly global::JD.Sequencers.Times.Timeline _timeline; private readonly Pen _pen = new Pen(Color.FromArgb(100, Color.WhiteSmoke), 1); public CheckpointWidget(Checkpoint model, global::JD.Sequencers.Times.Timeline timeline) { Throw.IfNull(model, "model"); Throw.IfNull(timeline, "timeline"); _pen.DashStyle = DashStyle.Dash; _model = model; _timeline = timeline; _model.Changed += updateBounds; _timeline.PixelsPerTimeChanged += updateBounds; _timeline.TimeOffsetChanged += updateBounds; updateBounds(null, null); } protected override void Dispose(bool disposing) { base.Dispose(disposing); _model.Changed -= updateBounds; _timeline.PixelsPerTimeChanged -= updateBounds; _timeline.TimeOffsetChanged -= updateBounds; } void updateBounds(object sender, System.EventArgs e) { if (_model.Time.HasValue && Parent != null) { float position = _timeline.TimeToPixel(_model.Time.Value); var bounds = Bounds; bounds.Y = Parent.Bounds.Y; bounds.Height = Parent.Bounds.Height; bounds.X = (int) position - 1; bounds.Width = (int)(position + 1); Bounds = bounds; IsVisible = true; } else if (IsVisible) { Invalidate(); IsVisible = false; } } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); if (IsVisible) { var bounds = Bounds; e.Graphics.DrawLine(_pen, bounds.X, bounds.Top, bounds.X, bounds.Bottom); } } } }