using System.Drawing; using JD.Audio.SoundPlayer; using JD.Kernel.Structs; using JD.Sequencers.Windowlesses; using TeaBox; using TeaBox.Core.Source.Gui; namespace JD.Application.View.WindowLess { /// /// Responsible of painting a loop indicator /// public class LoopWidget : WindowlessControl, IResizable { private readonly PlayerLoop _model; private readonly global::JD.Sequencers.Times.Timeline _timeline; private readonly Brush _boundsBrush = new SolidBrush(Color.FromArgb(75, Color.DodgerBlue)); public LoopWidget(PlayerLoop model, global::JD.Sequencers.Times.Timeline timeline) { _model = model; _timeline = timeline; _model.RangeChanged += updateBounds; _timeline.PixelsPerTimeChanged += updateBounds; _timeline.TimeOffsetChanged += updateBounds; updateBounds(null, null); } protected override void Dispose(bool disposing) { base.Dispose(disposing); _model.RangeChanged -= updateBounds; _timeline.PixelsPerTimeChanged -= updateBounds; _timeline.TimeOffsetChanged -= updateBounds; } void updateBounds(object sender, System.EventArgs e) { if (Parent != null && _model.Range.HasValue) { float min = _timeline.TimeToPixel(_model.Range.Value.Min); float max = _timeline.TimeToPixel(_model.Range.Value.Max); var bounds = Bounds; bounds.Y = Parent.Bounds.Y; bounds.Height = Parent.Bounds.Height; bounds.X = (int) min; bounds.Width = (int)(max - min); Bounds = bounds; IsVisible = true; } else if (IsVisible) { Invalidate(); IsVisible = false; } } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); if (IsVisible) { e.Graphics.FillRectangle(_boundsBrush, Bounds); } } #region Resize/Move public bool IsMoveAllowed { get { return true; } } public void Snap_Self(float originalDelta, ref float snappedDelta, ref float diff) { } public void Snap_Bounds(float originalDelta, ref float snappedDelta, ref float diff) { } public void Move(float delta) { if (_model.Range.HasValue) { _model.Range = new Range(_model.Range.Value.Min + delta, _model.Range.Value.Max + delta); } } public void Resize(Edge resizeEdge, float delta) { if (_model.Range.HasValue) { if (resizeEdge == Edge.Left) { _model.Range = new Range(_model.Range.Value.Min + delta, _model.Range.Value.Max); } else if (resizeEdge == Edge.Right) { _model.Range = new Range(_model.Range.Value.Min + delta, _model.Range.Value.Max); } } } public bool IsResizeAllowed { get { return true; } } public void ResizeByValue(Edge resizeEdge, float value) { } #endregion } }