Esempio n. 1
0
        private void CommandPaste()
        {
            if (CommandCanPaste())
            {
                TileSelectionClipboard clip      = TileSelectionClipboard.CopyFromClipboard();
                TileSelection          selection = clip.GetAsTileSelection(Layer.Level.Project, Layer.TileWidth, Layer.TileHeight);
                if (selection == null)
                {
                    return;
                }

                if (_selection != null)
                {
                    CompoundCommand command = new CompoundCommand();
                    if (_selection.Floating)
                    {
                        command.AddCommand(new DefloatTileSelectionCommand(Layer as MultiTileGridLayer, this));
                    }
                    command.AddCommand(new DeleteTileSelectionCommand(this));

                    LayerContext.History.Execute(command);
                }

                Command pasteCommand = new PasteFloatingSelectionCommand(this, selection, GetCenterTileOffset());
                LayerContext.History.Execute(pasteCommand);

                if (!(_currentTool is TileSelectTool))
                {
                    CommandManager.Perform(CommandKey.TileToolSelect);
                }

                _selection.Activate();
            }
        }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
            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);
                }
            }
Esempio n. 5
0
        void ChangeTrackMenuEntry(SvgWidget editor, object newValue, object delta)
        {
            var cmds = new CompoundCommand();

            SendValue(ref cmds, TrackMenuDict[editor], editor.Name, delta);
            History.Insert(cmds);
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        public RulerMouseHandler(RulerView rv, EditableProperty <float> start, EditableProperty <float> end, string sessionID)
            : base(rv, sessionID)
        {
            FStart = start;
            FEnd   = end;

            //start collecting movecommands in drag
            FMoveCommands = new CompoundCommand();
        }
Esempio n. 8
0
        public void Execute(ICommand command)
        {
            _redoStack = new Stack <ICommand>();

            // execute command
            command.Execute();

            // raise event for this
            //var eventData = command.getEventData();
            //eventData.operation = DataModel.CORE.ENUM.COMMAND_OPERATION_TYPE.EXECUTE;
            //PubSub.publish(eventData.topic, eventData);

            // check if it is mergable with previous command
            // create compound if YES and in case it is not already a compount command
            if (_undoStack.Count > 0)
            {
                var lastCommand = _undoStack.Pop();
                // check das letzte Command ob es mit dem neuen Command gruppiert werden will
                if (lastCommand.CanBeCompoundedWith(command) && !_breakNextCompoundFlag)
                {
                    // Gruppierung !!!!
                    // Ist das letzte bereits ein Compound?
                    if (!lastCommand.IsCompound)
                    {
                        // Noch nicht ... erstmal in eines umwandeln
                        lastCommand = CompoundCommand.Create(lastCommand);
                    }
                    // Jetzt haben wir im letzten Command definitiv ein Compound ... das aktuelle Command nur noch adden
                    (lastCommand as CompoundCommand).Append(command);
                    _undoStack.Push(lastCommand);
                }
                else if (lastCommand.IsMergableWith(command) && !_breakNextMergeFlag)
                {
                    lastCommand.MergeWith(command);
                    _undoStack.Push(lastCommand);
                }
                else
                {
                    // Nein, keine Gruppierung und kein Merge ...
                    // letztes Command wieder in Liste und das aktuelle oben drauf
                    _undoStack.Push(lastCommand);
                    _undoStack.Push(command);
                }
            }
            else
            {
                _undoStack.Push(command);
            }
            _breakNextCompoundFlag = false;
            _breakNextMergeFlag    = false;

            if (typeof(ICommandEventing).IsAssignableFrom(command.GetType()))
            {
                ((ICommandEventing)command).OnCommandExecuted();
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        void ChangeKeyframeMenuEntry(SvgWidget editor, object newValue, object delta)
        {
            var cmds = new CompoundCommand();

            foreach (var track in Parent.Document.Tracks)
            {
                foreach (var kf in track.KeyframeModels.Where(x => x.Selected.Value))
                {
                    SendValue(ref cmds, kf, editor.Name, delta);
                }
            }
            History.Insert(cmds);
        }
Esempio n. 12
0
        private void ResetSelection(CompoundCommand command)
        {
            if (_selectLayer.HasSelection)
            {
                if (_selectLayer.TileSelection.Floating)
                {
                    command.AddCommand(new DefloatTileSelectionCommand(Layer, _selectLayer));
                }
                command.AddCommand(new DeleteTileSelectionCommand(_selectLayer));
            }

            command.AddCommand(new CreateTileSelectionCommand(_selectLayer));
        }
Esempio n. 13
0
        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();
            }
        }
Esempio n. 14
0
        public override IMouseEventHandler MouseDown(object sender, MouseArg arg)
        {
            if (arg.Button == 1)
            {
                var ret = base.MouseDown(sender, arg);

                //start collecting movecommands in drag
                FMoveCommands = new CompoundCommand();

                return(ret);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 15
0
        private void DefloatSelection()
        {
            if (_selectLayer == null || _selectLayer.TileSelection == null)
            {
                return;
            }

            CompoundCommand command = new CompoundCommand();

            if (_selectLayer.TileSelection.Floating)
            {
                command.AddCommand(new DefloatTileSelectionCommand(Layer, _selectLayer));
            }
            command.AddCommand(new DeleteTileSelectionCommand(_selectLayer));
            History.Execute(command);
        }
Esempio n. 16
0
        private void CommandDelete()
        {
            if (CommandCanDelete())
            {
                CompoundCommand command = new CompoundCommand();
                if (!_selection.Floating)
                {
                    command.AddCommand(new FloatTileSelectionCommand(Layer as MultiTileGridLayer, this));
                }
                command.AddCommand(new DeleteTileSelectionCommand(this));

                LayerContext.History.Execute(command);

                CommandManager.Invalidate(CommandKey.Paste);
            }
        }
Esempio n. 17
0
        //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);
        }
Esempio n. 18
0
        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();
        }
Esempio n. 19
0
            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);
                }
            }
Esempio n. 20
0
        private void CommandCut()
        {
            if (CommandCanCut())
            {
                TileSelectionClipboard clip = new TileSelectionClipboard(_selection.Tiles);
                clip.CopyToClipboard();

                CompoundCommand command = new CompoundCommand();
                if (!_selection.Floating)
                {
                    command.AddCommand(new FloatTileSelectionCommand(Layer as MultiTileGridLayer, this));
                }
                command.AddCommand(new DeleteTileSelectionCommand(this));

                LayerContext.History.Execute(command);

                CommandManager.Invalidate(CommandKey.Paste);
            }
        }
Esempio n. 21
0
        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;
                    }
                }
            }
        }
Esempio n. 22
0
        private void EndDrag(PointerEventInfo info, ILevelGeometry viewport)
        {
            Rectangle selection = ClampSelection(_band.Selection);

            CompoundCommand command = new CompoundCommand();

            if (_mergeAction == MergeAction.New || !_selectLayer.HasSelection || _selectLayer.TileSelection.Floating)
            {
                ResetSelection(command);
            }

            switch (_mergeAction)
            {
            case MergeAction.New:
                ModifyNewTileSelectionCommand newCommand = new ModifyNewTileSelectionCommand(_selectLayer);
                newCommand.AddLocations(TileCoordsFromRegion(selection));
                command.AddCommand(newCommand);
                break;

            case MergeAction.Add:
                ModifyAddTileSelectionCommand addCommand = new ModifyAddTileSelectionCommand(_selectLayer);
                addCommand.AddLocations(TileCoordsFromRegion(selection));
                command.AddCommand(addCommand);
                break;

            case MergeAction.Remove:
                ModifyRemoveTileSelectionCommand removeCommand = new ModifyRemoveTileSelectionCommand(_selectLayer);
                removeCommand.AddLocations(TileCoordsFromRegion(selection));
                command.AddCommand(removeCommand);
                break;
            }

            if (command.Count > 0)
            {
                History.Execute(command);
            }

            _annots.Remove(_selectionAnnot);
            _action = UpdateAction.None;

            EndAutoScroll(info, viewport);
        }
Esempio n. 23
0
        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;
                }
            }
        }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        private void CommandDefloat()
        {
            if (CommandCanDefloat())
            {
                CompoundCommand command = new CompoundCommand();
                if (TileSelection.Floating)
                {
                    command.AddCommand(new DefloatTileSelectionCommand(Layer as MultiTileGridLayer, this));
                }
                command.AddCommand(new DeleteTileSelectionCommand(this));

                if (LayerContext != null)
                {
                    LayerContext.History.Execute(command);
                }
                else
                {
                    DefloatSelection();
                }
            }
        }
Esempio n. 26
0
 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;
         }
     }
 }
Esempio n. 27
0
 void ChangeKeyframeMenuEntry(SvgWidget editor, object newValue, object delta)
 {
     var cmds = new CompoundCommand();
     foreach (var track in Parent.Document.Tracks)
         foreach (var kf in track.KeyframeModels.Where(x => x.Selected.Value))
             SendValue(ref cmds, kf, editor.Name, delta);
     History.Insert(cmds);
 }
Esempio n. 28
0
        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;
                }
            }
        }
Esempio n. 29
0
        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);
            }
        }
Esempio n. 30
0
        void Nudge(NudgeDirection direction, bool shift, bool ctrl, bool alt)
        {
            var timeDelta  = 1f / Timeliner.Timer.FPS;
            var valueDelta = 0.01f;

            if (shift)
            {
                timeDelta *= Timeliner.Timer.FPS; //to nudge a whole second
            }
            var step = alt ? 10f : 0.1f;

            if (shift)
            {
                valueDelta *= step;
            }
            if (ctrl)
            {
                valueDelta *= step;
            }

            var kfSelected = false;

            foreach (var track in Timeliner.TimelineView.Tracks)
            {
                kfSelected = track.KeyframeViews.Any(kf => kf.Model.Selected.Value);
                if (kfSelected)
                {
                    break;
                }
            }

            if (kfSelected)
            {
                var cmds = new CompoundCommand();
                foreach (var track in Timeliner.TimelineView.Tracks)
                {
                    track.Nudge(ref cmds, direction, timeDelta, valueDelta);
                }
                Context.History.Insert(cmds);
            }
            else
            {
                var currentTime = Timeliner.Timer.Time;
                switch (direction)
                {
                case NudgeDirection.Back:
                    Timeliner.Timer.Time -= timeDelta;
                    break;

                case NudgeDirection.Forward:
                    Timeliner.Timer.Time += timeDelta;
                    break;

                case NudgeDirection.Up:
                    //find next kf
                    var nextKeyframe = Timeliner.TimelineView.Tracks.SelectMany(track => track.KeyframeViews).OrderBy(kf => kf.Model.Time.Value).First(kf => kf.Model.Time.Value > currentTime);
                    if (nextKeyframe != null)
                    {
                        Timeliner.Timer.Time = nextKeyframe.Model.Time.Value;
                    }
                    break;

                case NudgeDirection.Down:
                    //find prev kf
                    var lastKeyframe = Timeliner.TimelineView.Tracks.SelectMany(track => track.KeyframeViews).OrderByDescending(kf => kf.Model.Time.Value).First(kf => kf.Model.Time.Value < currentTime);
                    if (lastKeyframe != null)
                    {
                        Timeliner.Timer.Time = lastKeyframe.Model.Time.Value;
                    }
                    break;
                }
            }
        }
Esempio n. 31
0
        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);
        }
Esempio n. 32
0
        void Nudge(NudgeDirection direction, bool shift, bool ctrl, bool alt)
        {
            var timeDelta = 1f/Timeliner.Timer.FPS;
            var valueDelta = 0.01f;

            if (shift)
                timeDelta *= Timeliner.Timer.FPS; //to nudge a whole second

            var step = alt ? 10f : 0.1f;
            if (shift)
                valueDelta *= step;
            if (ctrl)
                valueDelta *= step;

            var kfSelected = false;
            foreach(var track in Timeliner.TimelineView.Tracks)
            {
                kfSelected = track.KeyframeViews.Any(kf => kf.Model.Selected.Value);
                if (kfSelected)
                    break;
            }

            if (kfSelected)
            {
                var cmds = new CompoundCommand();
                foreach(var track in Timeliner.TimelineView.Tracks)
                    track.Nudge(ref cmds, direction, timeDelta, valueDelta);
                Context.History.Insert(cmds);
            }
            else
            {
                var currentTime = Timeliner.Timer.Time;
                switch (direction)
                {
                    case NudgeDirection.Back:
                        Timeliner.Timer.Time -= timeDelta;
                        break;
                    case NudgeDirection.Forward:
                        Timeliner.Timer.Time += timeDelta;
                        break;
                    case NudgeDirection.Up:
                        //find next kf
                        var nextKeyframe = Timeliner.TimelineView.Tracks.SelectMany(track => track.KeyframeViews).OrderBy(kf => kf.Model.Time.Value).First(kf => kf.Model.Time.Value > currentTime);
                        if (nextKeyframe != null)
                            Timeliner.Timer.Time = nextKeyframe.Model.Time.Value;
                        break;
                    case NudgeDirection.Down:
                        //find prev kf
                        var lastKeyframe = Timeliner.TimelineView.Tracks.SelectMany(track => track.KeyframeViews).OrderByDescending(kf => kf.Model.Time.Value).First(kf => kf.Model.Time.Value < currentTime);
                        if (lastKeyframe != null)
                            Timeliner.Timer.Time = lastKeyframe.Model.Time.Value;
                        break;
                }
            }
        }
Esempio n. 33
0
 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));
     }
 }
Esempio n. 34
0
 void ChangeTrackMenuEntry(SvgWidget editor, object newValue, object delta)
 {
     var cmds = new CompoundCommand();
     SendValue(ref cmds, TrackMenuDict[editor], editor.Name, newValue);
     History.Insert(cmds);
 }
Esempio n. 35
0
        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);
        }