Beispiel #1
0
 private void SelectedElement(T item)
 {
     if (!SelectedElements.Any(e => e.Equals(item)))
     {
         SelectedElements.Add(item);
     }
 }
Beispiel #2
0
        public override void SetupCustomUIElements(object ui)
        {
            var nodeUI = ui as dynNodeView;

            //add a button to the inputGrid on the dynElement
            _selectButton = new dynNodeButton
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Center
            };
            _selectButton.Click += selectButton_Click;

            _tb = new TextBlock
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Center,
                Background          = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)),
                TextWrapping        = TextWrapping.Wrap,
                TextTrimming        = TextTrimming.WordEllipsis,
                MaxWidth            = 200,
                MaxHeight           = 100
            };

            if (SelectedElements == null || !SelectedElements.Any() || !SelectionText.Any() || !SelectButtonContent.Any())
            {
                SelectionText       = "Nothing Selected";
                SelectButtonContent = "Select Instances";
            }


            nodeUI.inputGrid.RowDefinitions.Add(new RowDefinition());
            nodeUI.inputGrid.RowDefinitions.Add(new RowDefinition());

            nodeUI.inputGrid.Children.Add(_tb);
            nodeUI.inputGrid.Children.Add(_selectButton);

            System.Windows.Controls.Grid.SetRow(_selectButton, 0);
            System.Windows.Controls.Grid.SetRow(_tb, 1);

            _tb.DataContext           = this;
            _selectButton.DataContext = this;

            var selectTextBinding = new System.Windows.Data.Binding("SelectionText")
            {
                Mode = BindingMode.TwoWay,
            };

            _tb.SetBinding(TextBlock.TextProperty, selectTextBinding);

            var buttonTextBinding = new System.Windows.Data.Binding("SelectButtonContent")
            {
                Mode = BindingMode.TwoWay,
            };

            _selectButton.SetBinding(ContentControl.ContentProperty, buttonTextBinding);
        }
Beispiel #3
0
        //TODO: This has not been revisited yet.

        /*
         * private void MouseMove_DragMoving_OLD(MouseEventArgs e)
         * {
         * Point gridLocation = TranslateLocation(e.Location);
         *
         * // if we don't have anything selected, there's no point dragging anything...
         * if (SelectedElements.Count() == 0)
         * return;
         *
         * Point d = new Point(e.X - m_lastMouseLocation.X, e.Y - m_lastMouseLocation.Y);
         * m_lastMouseLocation = e.Location;
         *
         * // calculate the points at which we should start dragging; ie. account for any selected elements.
         * // (we subtract VisibleTimeStart to make it relative to the control, instead of the grid canvas.)
         * TimeSpan earliestTime = GetEarliestTimeForElements(SelectedElements);
         * TimeSpan latestTime = GetLatestTimeForElements(SelectedElements);
         * int leftBoundary = (int)timeToPixels(earliestTime - VisibleTimeStart + DragTimeLeftOver);
         * int rightBoundary = (int)timeToPixels(latestTime - VisibleTimeStart + DragTimeLeftOver);
         *
         * // if the mouse moved left, only add it to the scroll size if:
         * // 1) the elements are hard left (or more) in the viewport
         * // 2) the elements are hard right, and we are moving right. This provides deceleration.
         * //    Cap this value to 0.
         * if (d.X < 0)
         * {
         * if (leftBoundary <= 0)
         *  m_dragAutoscrollDistance.Width += d.X;
         * else if (rightBoundary >= ClientSize.Width && m_dragAutoscrollDistance.Width > 0)
         *  m_dragAutoscrollDistance.Width = Math.Max(0, m_dragAutoscrollDistance.Width + d.X);
         * }
         *
         * // if the mouse moved right, do the inverse of the above rules.
         * if (d.X > 0)
         * {
         * if (rightBoundary >= ClientSize.Width)
         *  m_dragAutoscrollDistance.Width += d.X;
         * else if (leftBoundary <= 0 && m_dragAutoscrollDistance.Width < 0)
         *  m_dragAutoscrollDistance.Width = Math.Min(0, m_dragAutoscrollDistance.Width + d.X);
         * }
         *
         * // if the left and right boundaries are within the viewport, then stop all
         * // horizontal scrolling. This can happen if the user scrolls, and mouse-wheels
         * // (to zoom out). the control is stuck scrolling, and can't be stopped.
         * if (leftBoundary > 0 && rightBoundary < ClientSize.Width)
         * m_dragAutoscrollDistance.Width = 0;
         *
         * m_dragAutoscrollDistance.Height = (e.Y < 0) ? e.Y : ((e.Y > ClientSize.Height) ? e.Y - ClientSize.Height : 0);
         *
         * // if we're scrolling, start the timer if needed. If not, vice-versa.
         * if (m_dragAutoscrollDistance.Width != 0 || m_dragAutoscrollDistance.Height != 0)
         * {
         * if (!ScrollTimer.Enabled)
         *  ScrollTimer.Start();
         * }
         * else
         * {
         * if (ScrollTimer.Enabled)
         *  ScrollTimer.Stop();
         * }
         *
         * // only move the elements here if we aren't going to be auto-dragging while scrolling in the timer events.
         * if (d.X != 0 && m_dragAutoscrollDistance.Width == 0)
         * {
         * TimeSpan desiredMoveTime = DragTimeLeftOver + pixelsToTime(d.X);
         * TimeSpan realMoveTime = OffsetElementsByTime(SelectedElements, desiredMoveTime);
         * DragTimeLeftOver = desiredMoveTime - realMoveTime;
         * }
         *
         * // if we've moved vertically, we may need to move elements between rows
         * if (d.Y != 0 && !ResizingElement)
         * {
         * MoveElementsVerticallyToLocation(SelectedElements, gridLocation);
         * }
         * }
         */


        /// <summary>
        /// Handles mouse move events while in the "Moving" state.
        /// </summary>
        /// <param name="gridLocation">Mouse location on the grid.</param>
        private void MouseMove_DragMoving(Point gridLocation)
        {
            // if we don't have anything selected, there's no point dragging anything...
            if (!SelectedElements.Any())
            {
                return;
            }

            TimeSpan dt = pixelsToTime(gridLocation.X - m_elemMoveInfo.InitialGridLocation.X);
            int      dy = gridLocation.Y - m_elemMoveInfo.InitialGridLocation.Y;

            // If we didn't move, get outta here.
            if (dt == TimeSpan.Zero && dy == 0)
            {
                return;
            }


            // Calculate what our actual dt value will be.
            TimeSpan earliest = m_elemMoveInfo.OriginalElements.Values.Min(x => x.StartTime);

            if ((earliest + dt) < TimeSpan.Zero)
            {
                dt = -earliest;
            }

            TimeSpan latest = m_elemMoveInfo.OriginalElements.Values.Max(x => x.EndTime);

            if ((latest + dt) > TimeInfo.TotalTime)
            {
                dt = TimeInfo.TotalTime - latest;
            }

            // modify the dt time based on snap points (ie. marks, and borders of other elements)
            dt = FindSnapTimeForElements(SelectedElements, dt, ResizeZone.None);

            foreach (var elem in SelectedElements)
            {
                // Get this elemenent's original times (before resize started)
                ElementTimeInfo orig = m_elemMoveInfo.OriginalElements[elem];
                elem.StartTime = orig.StartTime + dt;
                //Control when the time changed event happens.
                elem.UpdateNotifyTimeChanged();
            }

            // if we've moved vertically, we may need to move elements between rows
            if (dy != 0)
            {
                SuppressInvalidate = true;
                MoveElementsVerticallyToLocation(SelectedElements, gridLocation);
                SuppressInvalidate = false;
            }

            Invalidate();
        }
Beispiel #4
0
 public void Update(Command command)
 {
     if (command.CommandDefinition is DeleteCommandDefinition)
     {
         command.Enabled = SelectedElements.Any() || Connections.Any(x => x.IsSelected);
     }
     else if (command.CommandDefinition is DrawConnectLineCommandDefinition)
     {
         command.Enabled = true;
     }
 }
Beispiel #5
0
 private void beginDragSelect(Point gridLocation)
 {
     m_dragState = DragState.Selecting;
     if (!ShiftPressed && SelectedElements.Any())
     {
         ClearSelectedElements();
     }
     else
     {
         tempSelectedElements = SelectedElements.ToList();
     }
     ClearSelectedRows(m_mouseDownElementRow);
     ClearActiveRows(m_mouseDownElementRow);
     SelectionArea             = new Rectangle(gridLocation.X, gridLocation.Y, 0, 0);
     m_selectionRectangleStart = gridLocation;
 }