public override void MouseDrag(object sender, PointF arg, PointF delta, int dragCall) { if (delta.X != 0) { var cmds = new CompoundCommand(); var x = Instance.XDeltaToTime(delta.X); var mouseX = Instance.XPosToTime(arg.X); //move start/end if ((FStart == null) || (FEnd == null)) { if ((FStart != null) && (mouseX < Instance.Model.LoopEnd.Value)) { cmds.Append(Command.Set(FStart, mouseX)); } if ((FEnd != null) && (mouseX > Instance.Model.LoopStart.Value)) { cmds.Append(Command.Set(FEnd, mouseX)); } } else //move region { cmds.Append(Command.Set(FStart, FStart.Value + x)); cmds.Append(Command.Set(FEnd, FEnd.Value + x)); } //execute changes immediately cmds.Execute(); //collect changes for history FMoveCommands.Append(cmds); Instance.Parent.UpdateScene(); } }
void SendValue(ref CompoundCommand cmds, TLModelBase model, string name, object newValue) { //from editor get editableproperty var property = model.GetType().GetProperty(name); if (property.PropertyType.GenericTypeArguments[0] == typeof(string)) { var prop = (EditableProperty <string>)property.GetValue(model); cmds.Append(Command.Set(prop, newValue)); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(float)) { var prop = (EditableProperty <float>)property.GetValue(model); cmds.Append(Command.Set(prop, newValue)); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(int)) { var prop = (EditableProperty <int>)property.GetValue(model); cmds.Append(Command.Set(prop, (int)((float)newValue))); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(bool)) { var prop = (EditableProperty <bool>)property.GetValue(model); cmds.Append(Command.Set(prop, (float)newValue >= 0.5)); } }
public override void MouseDrag(object sender, PointF arg, PointF delta, int callNr) { if (FMoveCommands != null) { var cmds = new CompoundCommand(); var rlr = Instance.Parent.Parent.Ruler; var dx = rlr.XDeltaToTime(delta.X); // in order to do snapping we need to seperate view- and model-time first // var closestKeyframe = Instance.Parent.Parent.Tracks.SelectMany(track => track.KeyframeViews).Except(Enumerable.Repeat(Instance, 1)).OrderBy(kf => kf.Model.Time.Value).Where(kf => Math.Abs(rlr.TimeToXPos(kf.Model.Time.Value) - rlr.TimeToXPos(Instance.Model.Time.Value)) < 3); // if (closestKeyframe.Any()) // dx = Instance.Model.Time.Value - closestKeyframe.First().Model.Time.Value; var i = 0; foreach (var kf in FSelectedKeyframes) { //set time cmds.Append(Command.Set(kf.Model.Time, kf.Model.Time.Value + dx)); //set value if value keyframe if (kf is ValueKeyframeView) { var vkf = kf as ValueKeyframeView; var dy = vkf.Parent.YDeltaToValue(delta.Y); var min = vkf.Parent.Model.Maximum.Value; var max = vkf.Parent.Model.Minimum.Value; FActualValues[i] += dy; if (!FAffectedTracks.Any(x => x.Collapsed)) { cmds.Append(Command.Set(vkf.Model.Value, Math.Min(min, Math.Max(max, FActualValues[i])))); } i++; } } //execute changes immediately cmds.Execute(); //collect changes for history FMoveCommands.Append(cmds); Instance.Parent.Parent.UpdateScene(); } }
public override void Click() { // Save SynchronizationContext var context = SynchronizationContext.Current; try { var dialog = new ReferenceDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var command = new CompoundCommand(); foreach (var reference in dialog.References) { if (!FReferences.Contains(reference)) { command.Append(Command.Add(FReferences, reference)); } } CommandHistory.Insert(command); } } finally { // Restore SynchronizationContext SynchronizationContext.SetSynchronizationContext(context); } }
public override IMouseEventHandler MouseDown(object sender, MouseArg arg) { if (arg.CtrlKey || arg.AltKey) { foreach (var track in Instance.Parent.Tracks) { foreach (var kf in track.KeyframeViews.Where(x => x.Model.Selected.Value)) { FPreviouslySelected.Add(kf); } } } else //deselect keyframes { var cmds = new CompoundCommand(); foreach (var track in Instance.Parent.Tracks) { foreach (var kf in track.KeyframeViews.Where(x => x.Model.Selected.Value)) { cmds.Append(Command.Set(kf.Model.Selected, false)); } } if (cmds.CommandCount > 0) { Instance.History.Insert(cmds); } } //start collecting movecommands in drag FSelectionCommands = new CompoundCommand(); return(base.MouseDown(sender, arg)); }
//delete on right click public override IMouseEventHandler MouseDown(object sender, MouseArg arg) { var ret = base.MouseDown(sender, arg); if ((arg.Button == 1) || (arg.Button == 3)) { FWasSelected = Instance.Model.Selected.Value; var cmd = new CompoundCommand(); if ((!FWasSelected) && (!arg.CtrlKey)) { //unselect all keyframes foreach (var track in Instance.Parent.Parent.Tracks) { foreach (var kf in track.KeyframeViews.Where(x => x.Model.Selected.Value)) { cmd.Append(Command.Set(kf.Model.Selected, false)); } } } //set keyframe selected cmd.Append(Command.Set(Instance.Model.Selected, true)); Instance.History.Insert(cmd); //start collecting movecommands in drag FMoveCommands = new CompoundCommand(); //store initial values to operate on for being able to drag beyond min/max foreach (var track in Instance.Parent.Parent.Tracks) { foreach (var kf in track.KeyframeViews.Where(x => x.Model.Selected.Value)) { if (!FAffectedTracks.Contains(track)) { FAffectedTracks.Add(track); } FSelectedKeyframes.Add(kf); if (kf is ValueKeyframeView) { FActualValues.Add((kf as ValueKeyframeView).Model.Value.Value); } } } } return(ret); }
public override void MouseSelection(object sender, MouseArg arg, RectangleF rect) { var cmds = new CompoundCommand(); foreach (var track in Instance.Parent.Tracks) { var trackRect = track.ToTrackRect(rect); foreach (var kf in track.KeyframeViews) { var wasSelected = kf.Model.Selected.Value; var isSelected = kf.IsSelectedBy(trackRect); if (arg.AltKey) { if (FPreviouslySelected.Contains(kf)) //only remove from previously selected { cmds.Append(Command.Set(kf.Model.Selected, !isSelected)); } } else if (arg.CtrlKey) { if (!FPreviouslySelected.Contains(kf)) //only add to previously selected { cmds.Append(Command.Set(kf.Model.Selected, isSelected)); } } else if (isSelected != wasSelected) //only send selection change { cmds.Append(Command.Set(kf.Model.Selected, isSelected)); } } } if (cmds.CommandCount > 0) { //execute changes immediately cmds.Execute(); //collect changes for history FSelectionCommands.Append(cmds); } rect = new RectangleF(rect.X, rect.Y - Instance.Parent.FTrackGroup.Transforms[0].Matrix.Elements[5], rect.Width, rect.Height); Instance.Parent.SetSelectionRect(rect); Instance.Parent.UpdateScene(); }
public virtual void Nudge(ref CompoundCommand cmds, NudgeDirection direction, float timeDelta, float valueDelta) { foreach (var kf in KeyframeViews) { if (kf.Model.Selected.Value) { switch (direction) { case NudgeDirection.Back: cmds.Append(Command.Set(kf.Model.Time, kf.Model.Time.Value - timeDelta)); break; case NudgeDirection.Forward: cmds.Append(Command.Set(kf.Model.Time, kf.Model.Time.Value + timeDelta)); break; } } } }
public void DropItems(Dictionary <string, object> items, Point pt) { if (FDroppable != null) { FDroppable.DropItems(items, pt); } if (FIdItem != null) { if (FIdItem is IEditableIDList) { IIDItem targetItem; var destination = FIdItem as IEditableIDList; var mapper = FIdItem.Mapper; var commandHistory = mapper.Map <ICommandHistory>(); foreach (var item in items.Values) { if (item is string[] && mapper.CanMap <IConverter>()) { var entries = item as string[]; var converter = mapper.Map <IConverter>(); var command = new CompoundCommand(); foreach (var entry in entries) { if (converter.Convert(entry, out targetItem)) { if (destination.CanAdd(targetItem)) { command.Append(CreateAddCommand(destination, targetItem)); } } } commandHistory.Insert(command); break; } else if (mapper.CanMap <IConverter>()) { var converter = mapper.Map <IConverter>(); if (converter.Convert(item, out targetItem)) { if (destination.CanAdd(targetItem)) { var command = CreateAddCommand(destination, targetItem); commandHistory.Insert(command); } } } } } } }
public override void Nudge(ref CompoundCommand cmds, NudgeDirection direction, float timeDelta, float valueDelta) { base.Nudge(ref cmds, direction, timeDelta, valueDelta); foreach (var kf in Keyframes.Where(x => x.Model.Selected.Value)) { switch (direction) { case NudgeDirection.Up: var newValue = (float)VMath.Clamp(kf.Model.Value.Value + valueDelta, Model.Minimum.Value, Model.Maximum.Value); cmds.Append(Command.Set(kf.Model.Value, newValue)); break; case NudgeDirection.Down: newValue = (float)VMath.Clamp(kf.Model.Value.Value - valueDelta, Model.Minimum.Value, Model.Maximum.Value); cmds.Append(Command.Set(kf.Model.Value, newValue)); break; } } }
void ChangeKeyframeText(SvgWidget widget, object newValue, object delta) { var cmds = new CompoundCommand(); foreach (var kf in Keyframes.Where(x => x.Model.Selected.Value)) { cmds.Append(Command.Set(kf.Model.Text, (string)newValue)); } History.Insert(cmds); }
public override IMouseEventHandler MouseUp(object sender, MouseArg arg) { Instance.SizeBarDragRect.Visible = false; Instance.Label.CustomAttributes["style"] = ""; if (arg.Button == 1) { var oldOrder = Instance.Model.Order.Value; //send a commmand to set the order of each trackview var cmds = new CompoundCommand(); if (FNewOrder > oldOrder) { foreach (var track in Instance.Parent.Tracks.Where(x => x != Instance)) { if ((track.Model.Order.Value > oldOrder) && (track.Model.Order.Value <= FNewOrder)) { cmds.Append(Command.Set(track.Model.Order, track.Model.Order.Value - 1)); } } } else { foreach (var track in Instance.Parent.Tracks.Where(x => x != Instance)) { if ((track.Model.Order.Value >= FNewOrder) && (track.Model.Order.Value < oldOrder)) { cmds.Append(Command.Set(track.Model.Order, track.Model.Order.Value + 1)); } } } cmds.Append(Command.Set(Instance.Model.Order, FNewOrder)); Instance.History.Insert(cmds); //resort tracks after order //Instance.Parent.Tracks.Sort((t1, t2) => t1.Model.Order.Value.CompareTo(t2.Model.Order.Value)); } return(base.MouseUp(sender, arg)); }
public override void Click() { var dialog = new ReferenceDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var command = new CompoundCommand(); foreach (var reference in dialog.References) { if (!FReferences.Contains(reference)) { command.Append(Command.Add(FReferences, reference)); } } CommandHistory.Insert(command); } }
public override void MouseDrag(object sender, PointF arg, PointF delta, int dragCall) { if (delta.Y != 0) { var h = Math.Max(Instance.Model.CollapsedHeight, Instance.Model.Height.Value + delta.Y); if ((delta.Y < 0) || (arg.Y > Instance.Top + Instance.Height)) { //scale this track var cmds = Command.Set(Instance.Model.Height, h); //execute changes immediately cmds.Execute(); //collect changes for history FMoveCommands.Append(cmds); } } Instance.Parent.UpdateScene(); }
void PoshServer_OnKeyDown(bool ctrl, bool shift, bool alt, int keyCode) { var cmds = new CompoundCommand(); switch (keyCode) { case (int)Keys.Space: Timeliner.Timer.Play(!Timeliner.Timer.IsRunning); Timeliner.TimelineView.UpdateScene(); break; case (int)Keys.Back: Timeliner.Timer.Stop(); Timeliner.TimelineView.UpdateScene(); break; case (int)Keys.Delete: foreach (var track in Timeliner.TimelineView.Tracks.OfType <ValueTrackView>()) { foreach (var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Remove(track.Model.Keyframes, kf.Model)); } } foreach (var track in Timeliner.TimelineView.Tracks.OfType <StringTrackView>()) { foreach (var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Remove(track.Model.Keyframes, kf.Model)); } } break; case (int)Keys.A: if (ctrl) { if (shift) { foreach (var track in Timeliner.TimelineView.Tracks) { foreach (var kf in track.KeyframeViews) { cmds.Append(Command.Set(kf.Model.Selected, true)); } } } else { foreach (var kf in Timeliner.TimelineView.ActiveTrack.KeyframeViews) { cmds.Append(Command.Set(kf.Model.Selected, true)); } } } break; case (int)Keys.Left: Nudge(NudgeDirection.Back, shift, ctrl, alt); break; case (int)Keys.Right: Nudge(NudgeDirection.Forward, shift, ctrl, alt); break; case (int)Keys.Up: Nudge(NudgeDirection.Up, shift, ctrl, alt); break; case (int)Keys.Down: Nudge(NudgeDirection.Down, shift, ctrl, alt); break; case (int)Keys.OemBackslash: Timeliner.TimelineView.ActiveTrack.CollapseTrack(null, null, null); break; case (int)Keys.E: if (!ctrl) { foreach (var track in Timeliner.TimelineView.Tracks.OfType <ValueTrackView>()) { foreach (var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Set(kf.Model.Ease, (kf.Model.Ease.Value + 1) % 4)); } } } break; case (int)Keys.I: if (!ctrl) { cmds.Append(Command.Set(Timeliner.TimelineView.Ruler.Model.LoopStart, Timeliner.Timer.Time)); } break; case (int)Keys.O: if (!ctrl) { cmds.Append(Command.Set(Timeliner.TimelineView.Ruler.Model.LoopEnd, Timeliner.Timer.Time)); } break; case (int)Keys.Z: if (ctrl) { if (shift) { Context.History.Redo(); } else { Context.History.Undo(); } } break; default: { if (keyCode <= 32) { break; } //this fails: // var kc = new KeysConverter(); // var keys = kc.ConvertToString(keyCode); // if (shift) // keys = "+" + keys; // if (ctrl) // keys = "^" + keys; // if (alt) // keys = "%" + keys; // SendKeys.Send(keys); //so we stupid workaround like so: var keys = keyCode; if (shift) { keys |= (int)Keys.Shift; } if (ctrl) { keys |= (int)Keys.Control; } if (alt) { keys |= (int)Keys.Alt; } Application.OpenForms[0].BeginInvoke(new MethodInvoker(() => Shortcut(keys))); break; } } if (cmds.CommandCount > 0) { Context.History.Insert(cmds); } }
public virtual void Nudge(ref CompoundCommand cmds, NudgeDirection direction, float timeDelta, float valueDelta) { foreach(var kf in KeyframeViews) { if (kf.Model.Selected.Value) switch (direction) { case NudgeDirection.Back: cmds.Append(Command.Set(kf.Model.Time, kf.Model.Time.Value - timeDelta)); break; case NudgeDirection.Forward: cmds.Append(Command.Set(kf.Model.Time, kf.Model.Time.Value + timeDelta)); break; } } }
public override void Nudge(ref CompoundCommand cmds, NudgeDirection direction, float timeDelta, float valueDelta) { base.Nudge(ref cmds, direction, timeDelta, valueDelta); foreach(var kf in Keyframes.Where(x => x.Model.Selected.Value)) { switch (direction) { case NudgeDirection.Up: var newValue = (float) VMath.Clamp(kf.Model.Value.Value + valueDelta, Model.Minimum.Value, Model.Maximum.Value); cmds.Append(Command.Set(kf.Model.Value, newValue)); break; case NudgeDirection.Down: newValue = (float) VMath.Clamp(kf.Model.Value.Value - valueDelta, Model.Minimum.Value, Model.Maximum.Value); cmds.Append(Command.Set(kf.Model.Value, newValue)); break; } } }
void SendValue(ref CompoundCommand cmds, TLModelBase model, string name, object newValue) { //from editor get editableproperty var property = model.GetType().GetProperty(name); if (property.PropertyType.GenericTypeArguments[0] == typeof(string)) { var prop = (EditableProperty<string>) property.GetValue(model); cmds.Append(Command.Set(prop, newValue)); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(float)) { var prop = (EditableProperty<float>) property.GetValue(model); cmds.Append(Command.Set(prop, newValue)); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(int)) { var prop = (EditableProperty<int>) property.GetValue(model); cmds.Append(Command.Set(prop, (int)((float)newValue))); } else if (property.PropertyType.GenericTypeArguments[0] == typeof(bool)) { var prop = (EditableProperty<bool>) property.GetValue(model); cmds.Append(Command.Set(prop, (float) newValue >= 0.5)); } }
void PoshServer_OnKeyDown(bool ctrl, bool shift, bool alt, int keyCode) { var cmds = new CompoundCommand(); switch(keyCode) { case (int) Keys.Space: Timeliner.Timer.Play(!Timeliner.Timer.IsRunning); Timeliner.TimelineView.UpdateScene(); break; case (int) Keys.Back: Timeliner.Timer.Stop(); Timeliner.TimelineView.UpdateScene(); break; case (int) Keys.Delete: foreach(var track in Timeliner.TimelineView.Tracks.OfType<ValueTrackView>()) foreach(var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Remove(track.Model.Keyframes, kf.Model)); } foreach(var track in Timeliner.TimelineView.Tracks.OfType<StringTrackView>()) foreach(var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Remove(track.Model.Keyframes, kf.Model)); } break; case (int) Keys.A: if (ctrl) { if (shift) { foreach(var track in Timeliner.TimelineView.Tracks) foreach(var kf in track.KeyframeViews) cmds.Append(Command.Set(kf.Model.Selected, true)); } else { foreach(var kf in Timeliner.TimelineView.ActiveTrack.KeyframeViews) cmds.Append(Command.Set(kf.Model.Selected, true)); } } break; case (int) Keys.Left: Nudge(NudgeDirection.Back, shift, ctrl, alt); break; case (int) Keys.Right: Nudge(NudgeDirection.Forward, shift, ctrl, alt); break; case (int) Keys.Up: Nudge(NudgeDirection.Up, shift, ctrl, alt); break; case (int) Keys.Down: Nudge(NudgeDirection.Down, shift, ctrl, alt); break; case (int) Keys.OemBackslash: Timeliner.TimelineView.ActiveTrack.CollapseTrack(null, null, null); break; case (int) Keys.E: if (!ctrl) foreach(var track in Timeliner.TimelineView.Tracks.OfType<ValueTrackView>()) foreach(var kf in track.Keyframes.Where(k => k.Model.Selected.Value)) { cmds.Append(Command.Set(kf.Model.Ease, (kf.Model.Ease.Value + 1) % 4)); } break; case (int) Keys.I: if (!ctrl) cmds.Append(Command.Set(Timeliner.TimelineView.Ruler.Model.LoopStart, Timeliner.Timer.Time)); break; case (int) Keys.O: if (!ctrl) cmds.Append(Command.Set(Timeliner.TimelineView.Ruler.Model.LoopEnd, Timeliner.Timer.Time)); break; case (int) Keys.Z: if (ctrl) { if (shift) { Context.History.Redo(); } else { Context.History.Undo(); } } break; default: { if (keyCode <= 32) break; //this fails: // var kc = new KeysConverter(); // var keys = kc.ConvertToString(keyCode); // if (shift) // keys = "+" + keys; // if (ctrl) // keys = "^" + keys; // if (alt) // keys = "%" + keys; // SendKeys.Send(keys); //so we stupid workaround like so: var keys = keyCode; if (shift) keys |= (int) Keys.Shift; if (ctrl) keys |= (int) Keys.Control; if (alt) keys |= (int) Keys.Alt; Application.OpenForms[0].BeginInvoke(new MethodInvoker(() => Shortcut(keys))); break; } } if (cmds.CommandCount > 0) Context.History.Insert(cmds); }
void ChangeKeyframeText(SvgWidget widget, object newValue, object delta) { var cmds = new CompoundCommand(); foreach(var kf in Keyframes.Where(x => x.Model.Selected.Value)) cmds.Append(Command.Set(kf.Model.Text, (string) newValue)); History.Insert(cmds); }