203 lines
7 KiB
C#
203 lines
7 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using JD.Application.View;
|
|
using JD.Application.View.Timeline;
|
|
using JD.Application.View.WindowLess;
|
|
using JD.Collections.Extensions;
|
|
using JD.Sequencers.Windowlesses;
|
|
using JD.Timeline.View.Actions.Macros;
|
|
using JD.Timeline.View.Helpers;
|
|
using TeaBox;
|
|
using JD.Serialization;
|
|
using TeaBox.Core.Source.Gui;
|
|
|
|
namespace JD.Timeline.View.ClipView.Widgets
|
|
{
|
|
public class MotionClipWidget : DanceEditorClipWidget
|
|
{
|
|
#region Variables
|
|
|
|
private static readonly Bitmap _icon16X16ClipSettings = Properties.Resources.Icon_16x16_clip_settings;
|
|
private static readonly Bitmap _icon16X16GoldMedal = Properties.Resources.Icon_16x16_goldmedal;
|
|
private static readonly Font _motionClipFont = new Font(FontFamily.GenericSansSerif, 8);
|
|
private static readonly StringFormat _stringFormat = new StringFormat
|
|
{
|
|
Alignment = StringAlignment.Center,
|
|
LineAlignment = StringAlignment.Center
|
|
};
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public MotionClipWidget(MotionClip model)
|
|
: base(model)
|
|
{
|
|
ToolbarItems.Add(
|
|
new ToolbarItem
|
|
{
|
|
Bitmap = () => _icon16X16ClipSettings,
|
|
Priority = 1,
|
|
IsVisible = () => true,
|
|
OnClick = delegate
|
|
{
|
|
var wpfwindow = new MotionClipEditionHelper(Model);
|
|
wpfwindow.Show();
|
|
wpfwindow.Left = Cursor.Position.X;
|
|
wpfwindow.Top = Cursor.Position.Y - wpfwindow.ActualHeight;
|
|
wpfwindow.Closing += (s, e) =>
|
|
{
|
|
var control = (WindowlessRootControl) RootControl;
|
|
var position = control.PointToClient(Cursor.Position);
|
|
control.SimulateOnMouseDown(control, new MouseEventArgs(MouseButtons.Left, 1, position.X, position.Y, 0));
|
|
};
|
|
}
|
|
}
|
|
);
|
|
ToolbarItems.Add(
|
|
new ToolbarItem
|
|
{
|
|
Bitmap = () => _icon16X16GoldMedal,
|
|
Priority = 0,
|
|
IsVisible = () => Model != null && Model.GoldMove
|
|
}
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public new MotionClip Model
|
|
{
|
|
get { return (MotionClip)base.Model; }
|
|
}
|
|
|
|
public override string ToolTipText
|
|
{
|
|
get
|
|
{
|
|
return Model.Model.Name + "\n" + base.ToolTipText;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
protected override void SetupBounds()
|
|
{
|
|
if (Timeline != null)
|
|
{
|
|
int left = Timeline.PixelFromFrame(Model.StartFrame);
|
|
int right = Timeline.PixelFromFrame(Model.StopFrame);
|
|
int width = right - left;
|
|
Bounds = new Rectangle(left, Track.Bounds.Top, width, Track.Height);
|
|
}
|
|
}
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
SetupBounds();
|
|
|
|
var graphics = e.Graphics;
|
|
|
|
Color fillColor, textColor, borderColor;
|
|
Color? fillColor2 = null;
|
|
if (Selected)
|
|
{
|
|
fillColor = Model.Model.Color;
|
|
textColor = Color.FromArgb(85, 85, 85);
|
|
borderColor = SelectionBorderColor;
|
|
fillColor2 = Color.FromArgb(fillColor.IsBright() ? 130 : 170, SelectionBorderColor);
|
|
}
|
|
else if (Model.MasterClip == null)
|
|
{
|
|
fillColor = Model.Model.Color;
|
|
textColor = fillColor.IsBright() ? Color.FromArgb(50, 50, 50) : Color.FromArgb(210, 210, 210);
|
|
borderColor = fillColor.Add(fillColor.IsBright() ? -40 : 20);
|
|
}
|
|
else
|
|
{
|
|
fillColor = Model.Model.Color;
|
|
fillColor = Color.FromArgb(fillColor.A, (int)(fillColor.R * 0.2f), (int)(fillColor.G * 0.2f), (int)(fillColor.B * 0.2f));
|
|
textColor = fillColor.IsBright() ? Color.FromArgb(80, 80, 80) : Color.FromArgb(90, 90, 90);
|
|
borderColor = fillColor.Add(fillColor.IsBright() ? -40 : 20);
|
|
}
|
|
|
|
if (Model.CollisionsWithOther)
|
|
{
|
|
fillColor = WarningFillColor;
|
|
textColor = Color.FromArgb(85, 85, 85);
|
|
}
|
|
|
|
FillBackground(graphics, Bounds, fillColor);
|
|
if (fillColor2 != null)
|
|
{
|
|
FillBackground(graphics, Bounds, (Color)fillColor2);
|
|
}
|
|
|
|
DrawRectangle(graphics, Bounds, Selected ? SelectionBorderPen : StyleSheet.Pens[borderColor]);
|
|
|
|
if (Bounds.Width > 12)
|
|
{
|
|
graphics.DrawString(Model.Model.ToString(), _motionClipFont, StyleSheet.Brushes[textColor],
|
|
Bounds, _stringFormat);
|
|
}
|
|
|
|
if (Model.CollisionsWithOther)
|
|
{
|
|
DrawClipWithWarning(graphics);
|
|
}
|
|
|
|
DrawNotificationIcons(graphics);
|
|
|
|
OnPaintChildControls(e);
|
|
|
|
if (!Model.IsActive)
|
|
{
|
|
DrawAsInactive(graphics);
|
|
}
|
|
}
|
|
|
|
public override void OnDoubleClick()
|
|
{
|
|
TeaBox.ObjectModel.Application.Main.Dispatcher.DispatchAsync(
|
|
() => Track.TrackView.SelectAll<MotionClipWidget>(x => x.Model.Model == Model.Model),
|
|
forceAsync: true);
|
|
}
|
|
|
|
public override void Resize(Edge resizeEdge, float delta)
|
|
{
|
|
// The resize method of motion clips is overrided to handle resize when multiple items are selected
|
|
// and to resize from the left
|
|
var currentTool = Track.TrackView.ToolManager.CurrentTool;
|
|
if (currentTool is ResizeTool)
|
|
{
|
|
if (currentTool.Selection.OfType<MotionClipWidget>().Where(x => x.Model.Model == Model.Model).IndexOf(this) > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (resizeEdge == Edge.Left)
|
|
{
|
|
var frameDelta = (int)Math.Round(Timeline.FrameFromTime(delta));
|
|
int newDuration = Math.Max(1, Model.Duration - frameDelta);
|
|
foreach (var clip in Model.Model.Instances)
|
|
{
|
|
clip.StartFrame -= newDuration - Model.Duration;
|
|
}
|
|
Model.Resize(newDuration, resizeCurves: WaveControl.IsStretchKeyPress);
|
|
}
|
|
else
|
|
{
|
|
base.Resize(resizeEdge, delta);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|