Exemplo n.º 1
0
        public IEnumerator <object> Task()
        {
            var g = Timeline.Instance.Globals;

            while (true)
            {
                var rq = g.Get <DragKeyframesRequest>();
                if (rq != null)
                {
                    Document.Current.History.DoTransaction(() => {
                        Operations.DragKeyframes.Perform(rq.Offset, rq.RemoveOriginals);
                        Operations.ShiftGridSelection.Perform(rq.Offset);
                        if (rq.Offset.Y != 0)
                        {
                            var selected = Document.Current.SelectedRows().Where(r => r.Selected).Select(r => r.Index).ToDictionary(x => x);
                            ClearRowSelection.Perform();
                            foreach (var row in Document.Current.Rows)
                            {
                                if (selected.ContainsKey(row.Index - rq.Offset.Y))
                                {
                                    SelectRow.Perform(row, select: true);
                                }
                            }
                        }
                        g.Remove <DragKeyframesRequest>();
                    });
                }
                yield return(null);
            }
        }
Exemplo n.º 2
0
        public IEnumerator <object> Task()
        {
            Probers.Add(new BoneRowProber());
            Probers.Add(new FolderRowProber());
            Probers.Add(new NodeRowProber());
            Probers.Add(new AnimationTrackRowProber());
            var roll  = Timeline.Instance.Roll;
            var input = roll.RootWidget.Input;

            var cg = new ClickGesture(0, () => {
                var row = RowUnderMouse(input.MousePosition);
                if (row == null)
                {
                    return;
                }
                if (input.IsKeyPressed(Key.Shift))
                {
                    if (Document.Current.SelectedRows().Any())
                    {
                        var firstRow = Document.Current.SelectedRows().FirstOrDefault();
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRowRange.Perform(firstRow, row);
                        });
                    }
                    else
                    {
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRow.Perform(row);
                        });
                    }
                }
                else if (input.IsKeyPressed(Key.Control))
                {
                    Document.Current.History.DoTransaction(() => {
                        SelectRow.Perform(row, !row.Selected);
                    });
                }
                else
                {
                    Document.Current.History.DoTransaction(() => {
                        ClearRowSelection.Perform();
                        SelectRow.Perform(row);
                    });
                    input.ConsumeKey(Key.Mouse0);
                }
            });

            var dg = new DragGesture(0);

            dg.Recognized += () => {
                var row = RowUnderMouse(dg.MousePressPosition);
                // Have to turn off PreviewAnimation manually in order
                // to provide the same behaviour whether widget is selected or not
                // (PreviewAnimation is turned off when performing operation)
                if (Document.Current.PreviewAnimation)
                {
                    Document.Current.TogglePreviewAnimation();
                }
                if (!row?.Selected ?? false)
                {
                    Document.Current.History.DoTransaction(() => {
                        ClearRowSelection.Perform();
                        SelectRow.Perform(row);
                    });
                }
                roll.OnRenderOverlay += OnRollRenderOverlay;
                dragLocation          = new RowLocation(Document.Current.RowTree, 0);
            };
            dg.Changed += () => {
                dragLocation = MouseToRowLocation(input.MousePosition);
                CommonWindow.Current.Invalidate();
            };
            dg.Ended += () => {
                if (!dg.IsRecognizing())
                {
                    roll.OnRenderOverlay -= OnRollRenderOverlay;
                    CommonWindow.Current.Invalidate();
                    if (dragLocation != null)
                    {
                        DragRows(dragLocation.Value);
                    }
                }
            };

            roll.RootWidget.Gestures.Add(dg);
            roll.RootWidget.Gestures.Add(cg);
            yield break;
        }
Exemplo n.º 3
0
        public IEnumerator <object> Task()
        {
            var roll  = Timeline.Instance.Roll;
            var input = roll.RootWidget.Input;

            input.AcceptMouseThroughDescendants = true;
            while (true)
            {
                yield return(null);

                if (!input.WasMousePressed() || input.WasKeyPressed(Key.Mouse0DoubleClick))
                {
                    continue;
                }
                var initialMousePosition = input.MousePosition;
                var row = RowUnderMouse(initialMousePosition);
                if (row == null)
                {
                    continue;
                }
                if (input.IsKeyPressed(Key.Shift))
                {
                    if (Document.Current.SelectedRows().Any())
                    {
                        var firstRow = Document.Current.SelectedRows().FirstOrDefault();
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRowRange.Perform(firstRow, row);
                        });
                    }
                    else
                    {
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRow.Perform(row);
                        });
                    }
                }
                else if (input.IsKeyPressed(Key.Control))
                {
                    Document.Current.History.DoTransaction(() => {
                        SelectRow.Perform(row, !row.Selected);
                    });
                }
                else
                {
                    if (!row.Selected)
                    {
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRow.Perform(row);
                        });
                    }
                    while (
                        input.IsMousePressed() &&
                        Math.Abs(initialMousePosition.Y - input.MousePosition.Y) < TimelineMetrics.DefaultRowHeight / 4
                        )
                    {
                        yield return(null);
                    }
                    if (input.IsMousePressed())
                    {
                        yield return(DragTask());
                    }
                    else
                    {
                        Document.Current.History.DoTransaction(() => {
                            ClearRowSelection.Perform();
                            SelectRow.Perform(row);
                        });
                    }
                }
            }
        }