Beispiel #1
0
        public override void Initialize()
        {
            Tab = new ThemedTab {
                Text = "Devices"
            };
            Content = new Widget {
                Layout = new VBoxLayout(),
                Nodes  =
                {
                    (mainToolbar                     = new RemoteScriptingWidgets.Toolbar()),
                    new Widget {
                        Layout = new HBoxLayout(),
                        Nodes  =
                        {
                            (devicesScrollView       = new ThemedScrollView {
                                MinMaxWidth          =                                   300,
                                TabTravesable        = new TabTraversable()
                            }),
                            (deviceWidgetPlaceholder = new Widget()
                            {
                                Layout               = new HBoxLayout()
                            })
                        }
                    }
                }
            };
            RefreshMainToolbar();
            Content.AddChangeWatcher(
                () => CompiledAssembly.Instance,
                _ => {
                RefreshMainToolbar();
            }
                );

            void SelectDeviceBasedOnMousePosition()
            {
                devicesScrollView.SetFocus();
                var index = (devicesScrollView.Content.LocalMousePosition().Y / rowHeight).Floor();

                if (index < devices.Count)
                {
                    SelectDevice(index);
                }
            }

            var mouseDownGesture = new ClickGesture(0);

            mouseDownGesture.Began += SelectDeviceBasedOnMousePosition;
            devicesScrollView.Gestures.Add(mouseDownGesture);
            devicesScrollView.Content.CompoundPresenter.Insert(0, new SyncDelegatePresenter <Widget>(w => {
                w.PrepareRendererState();
                Renderer.DrawRect(
                    0, rowHeight * selectedDeviceIndex,
                    w.Width, rowHeight * (selectedDeviceIndex + 1),
                    devicesScrollView.IsFocused() ? Theme.Colors.SelectedBackground : Theme.Colors.SelectedInactiveBackground
                    );
            }));
        }
Beispiel #2
0
        public AnimationsPanel(Widget panelWidget)
        {
            Instance         = this;
            this.panelWidget = panelWidget;
            scrollView       = new ThemedScrollView {
                TabTravesable = new TabTraversable()
            };
            this.rootWidget = new Frame {
                Id      = "AnimationsPanel",
                Padding = new Thickness(4),
                Layout  = new VBoxLayout {
                    Spacing = 4
                },
                Nodes = { scrollView }
            };
            scrollView.Content.CompoundPresenter.Insert(0, new SyncDelegatePresenter <Widget>(w => {
                w.PrepareRendererState();
                var selectedIndex = GetSelectedAnimationIndex();
                Renderer.DrawRect(
                    0, rowHeight * selectedIndex,
                    w.Width, rowHeight * (selectedIndex + 1),
                    scrollView.IsFocused() ? Theme.Colors.SelectedBackground : Theme.Colors.SelectedInactiveBackground);
            }));
            var dragGesture = new DragGesture(0);

            dragGesture.Recognized += () => {
                var index = (scrollView.Content.LocalMousePosition().Y / rowHeight).Floor();
                if (index >= 0 && index < GetAnimations().Count)
                {
                    var animation = GetAnimations()[index];
                    if (!animation.IsLegacy && animation != Document.Current.Animation)
                    {
                        // Dirty hack: using a file drag&drop mechanics for dropping animation clips on the timeline grid.
                        var encodedAnimationId = Convert.ToBase64String(Encoding.UTF8.GetBytes(animation.Id));
                        // DragFiles in Winforms blocks execution, call it on the next update
                        Application.InvokeOnNextUpdate(() => {
                            Window.Current.DragFiles(new[] { encodedAnimationId });
                        });
                    }
                }
            };
            var mouseDownGesture = new ClickGesture(0);

            mouseDownGesture.Recognized += SelectAnimationBasedOnMousePosition;
            scrollView.Gestures.Add(dragGesture);
            scrollView.Gestures.Add(new ClickGesture(1, ShowContextMenu));
            scrollView.Gestures.Add(mouseDownGesture);
            scrollView.Gestures.Add(new DoubleClickGesture(0, RenameAnimation));
            scrollView.LateTasks.Add(ProcessCommandsTask);
            scrollView.AddChangeWatcher(CalcAnimationsHashCode, _ => Refresh());
        }
Beispiel #3
0
    void InitInteractive()
    {
        _input       = new InputWrapper();
        _dragGesture = new DragGesture(_input);
        _dragGesture.DragBeginHandler = OnDragBegin;
        _dragGesture.DragHandler      = OnDrag;
        _dragGesture.DragEndHandler   = OnDragEnd;


        _pinchGesture = new PinchGesture(_input);
        _pinchGesture.PinchHandler      = OnPinch;
        _pinchGesture.PinchEndHandler   = OnPinchEnd;
        _pinchGesture.PinchBeginHandler = OnPinchBegin;

        _clickGesture = new ClickGesture(_input);
        _clickGesture.ClickHandler = OnClick;
    }
Beispiel #4
0
 public InputWrapper(System.Action <Vector2> ClickHandler, System.Action <Vector2, Vector2> DragingHandler
                     , System.Action <Vector2, Vector2, Vector2, Vector2> PinchingHandler)
 {
     mInput = new MouseInputDevice();
     if (null != ClickHandler)
     {
         mClickGesture = new ClickGesture(mInput);
         mClickGesture.clickHandler = ClickHandler;
     }
     if (null != DragingHandler)
     {
         mDragGesture = new DragGesture(mInput);
         mDragGesture.dragingHandler = DragingHandler;
     }
     if (null != PinchingHandler)
     {
         mPinchGesture = new PinchGesture(mInput);
         mPinchGesture.pinchHandler = PinchingHandler;
     }
 }
Beispiel #5
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;
        }