JD2022-TU1/main/tools/framework/JD.Timeline/Karaoke/KaraokeTrackTreeItem.cs

133 lines
4.7 KiB
C#

using System.ComponentModel;
using System.Drawing;
using Divelements.SandGrid;
using JD.Timeline.View.ClipView;
using JetBrains.Annotations;
using JD.Serialization;
namespace JD.Timeline.View.TrackTreeView
{
public class KaraokeTrackTreeItem : ClipTrackTreeItem, INotifyPropertyChanged
{
private bool _isPressed;
private static readonly Font _textFont = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Bold);
private static readonly Color _textColor = Color.Orange;
private static readonly StringFormat _stringFormat = new StringFormat
{
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
public KaraokeTrackTreeItem(TapeTrackWidget track)
: base(track)
{
IsPressed = false;
if (KaraokeTrack.ContentType != KaraokeTrack.ContentType_Enum.KaraokeContent_Singing)
{
Track.Fixed = true;
}
this.AllowSorting = false;
this.AllowDragging = false;
}
public override void Dispose()
{
}
public KaraokeTrack KaraokeTrack
{
get { return (KaraokeTrack) (TrackView.Track); }
}
public override string Text
{
get { return KaraokeTrack.ContentType != KaraokeTrack.ContentType_Enum.KaraokeContent_Singing ? KaraokeTrack.Name : ""; }
}
public bool IsPressed
{
get { return _isPressed; }
set
{
if (_isPressed != value)
{
_isPressed = value;
if (Hierarchy != null)
{
Hierarchy.Grid.Invalidate();
}
OnPropertyChanged("IsPressed");
}
}
}
public override bool SelectItemsOnClick
{
get { return KaraokeTrack.ContentType != KaraokeTrack.ContentType_Enum.KaraokeContent_Singing; }
}
public override bool DrawRowForeground(Divelements.SandGrid.Rendering.RenderingContext context, Rectangle rectangle, GridColumn[] columns, Divelements.SandGrid.Rendering.TextFormattingInformation[] informations, Divelements.SandGrid.GridRow row)
{
if (KaraokeTrack.ContentType != KaraokeTrack.ContentType_Enum.KaraokeContent_Singing)
{
return base.DrawRowForeground(context, rectangle, columns, informations, row);
}
UpdateHeight();
bool isMidiNoteSharp = MidiUtils.IsMidiNoteSharp(KaraokeTrack.MidiNote);
if (isMidiNoteSharp)
{
context.Graphics.FillRectangle(StyleSheet.Brushes[Color.Ivory], rectangle);
var blackKeyrectangle = new Rectangle(rectangle.X, rectangle.Y, (int)(rectangle.Width*0.65), rectangle.Height);
context.Graphics.FillRectangle(StyleSheet.Brushes[IsPressed ? Color.Orange : Color.Black], blackKeyrectangle);
}
else
{
context.Graphics.FillRectangle(StyleSheet.Brushes[IsPressed ? Color.Orange : Color.Ivory], rectangle);
}
using (var pen = new Pen(StyleSheet.LineColor))
{
context.Graphics.DrawRectangle(pen, rectangle);
}
//If the track midi note is a C (Do)
if (KaraokeTrack.MidiNote%12 == 0)
{
var textlocation = new PointF(rectangle.Right - 5, rectangle.Top + rectangle.Height/2);
context.Graphics.DrawString(KaraokeTrack.Name, _textFont, StyleSheet.Brushes[_textColor], textlocation.X, textlocation.Y, _stringFormat);
}
return false;
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e, Point gridClickPosition)
{
IsPressed = true;
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e, Point gridClickPosition)
{
IsPressed = false;
}
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e, Point gridClickPosition)
{
//The proper behaviour would be to have a MouseEnter and MouseLeave event, and trigger
//note off when leaving the key
IsPressed = false;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}