Пример #1
0
        public void MouseUp(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            // Check if the track bar was moving (mouse down)
            //ReleaseMouseCapture();
            if (!_isTrackBarMoving)
            {
                // The user clicked without dragging the mouse; we need to add or
                // substract a "step" depending on the mouse cursor position.
                if (y < _rectFader.Y)
                {
                    if (Value + StepSize > Maximum)
                        Value = Maximum;
                    else
                        Value += StepSize;
                }
                else if (y > _rectFader.Y + _rectFader.Height)
                {
                    if (Value - StepSize < Minimum)
                        Value = Minimum;
                    else
                        Value -= StepSize;
                }

                if (OnFaderValueChanged != null)
                    OnFaderValueChanged(this, new EventArgs());

                OnInvalidateVisual();
            }

            //Console.WriteLine("FaderControl - MouseDown - Mouse up; stopping track bar movement");
            _mouseButtonDown = false;
            _isTrackBarMoving = false;
        }
Пример #2
0
 public void MouseDoubleClick(float x, float y, MouseButtonType button, KeysHeld keysHeld)
 {
 }
Пример #3
0
        public void MouseUp(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            // Check if the track bar was moving (mouse down)
            //ReleaseMouseCapture();
            if (!_isTrackBarMoving)
            {
                // The user clicked without dragging the mouse; we need to add or
                // substract a "step" depending on the mouse cursor position.
                if (x < _rectFader.X)
                {
                    if (Value - StepSize < Minimum)
                        Value = Minimum;
                    else
                        Value -= StepSize;
                }
                else if (x > _rectFader.X + _rectFader.Width)
                {
                    if (Value + StepSize > Maximum)
                        Value = Maximum;
                    else
                        Value += StepSize;
                }

                if (OnTrackBarValueChanged != null)
                    OnTrackBarValueChanged();

                OnInvalidateVisual();
            }

            _mouseButtonDown = false;
            _isTrackBarMoving = false;
        }
Пример #4
0
 public void MouseDown(float x, float y, MouseButtonType button, KeysHeld keysHeld)
 {
     // Make sure the mouse button pressed was the left mouse button
     _mouseButtonDown = true;
     //CaptureMouse();
     if (button == MouseButtonType.Left)
     {
         // Check if the user clicked in the fader area
         if (x >= _rectFader.X &&
             x <= _rectFader.Width + _rectFader.X &&
             y >= _rectFader.Y &&
             y <= _rectFader.Height + _rectFader.Y)
         {
             //Console.WriteLine("FaderControl - MouseDown - Mouse down on track bar; track bar is now moving");
             _isTrackBarMoving = true;
         }
     }
 }
Пример #5
0
        public void MouseUp(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            _isMouseDown = false;
            if (AudioFile == null)
                return;

            if (_isDraggingScrollBar)
            {
                _isDraggingThumb = false;
                _isDraggingScrollBar = false;
            } 
            else
            {
                ShowSecondaryPosition = false;
                long position = (long)(((x + ContentOffset.X) / ContentSize.Width) * Length);
                float positionPercentage = (float)position / (float)Length;
                if (button == MouseButtonType.Left)
                {
                    Position = position;
                    OnChangePosition(positionPercentage);
                }
            }
        }
Пример #6
0
 public void MouseClick(float x, float y, MouseButtonType button, KeysHeld keysHeld)
 {
     float scrollUnit = ScrollBarHeight * Zoom;
     if (ShowScrollBar && y >= Frame.Height - ScrollBarHeight)
     {
         // Make sure we are outside the thumb/visible area
         float visibleAreaWidth = (1 / Zoom) * Frame.Width;
         float visibleAreaX = (1 / Zoom) * ContentOffset.X;
         if (x < visibleAreaX)
             OnContentOffsetChanged(new BasicPoint(ContentOffset.X - scrollUnit, 0));
         else if (x > visibleAreaX + visibleAreaWidth)
             OnContentOffsetChanged(new BasicPoint(ContentOffset.X + scrollUnit, 0));
     } 
 }
Пример #7
0
 public static KeysHeld GetKeysHeld(NSEvent theEvent)
 {
     var keysHeld = new KeysHeld();
     keysHeld.IsShiftKeyHeld = (theEvent.ModifierFlags & NSEventModifierMask.ShiftKeyMask) != 0;
     keysHeld.IsAltKeyHeld = (theEvent.ModifierFlags & NSEventModifierMask.AlternateKeyMask) != 0;
     keysHeld.IsCtrlKeyHeld = (theEvent.ModifierFlags & NSEventModifierMask.ControlKeyMask) != 0;
     return keysHeld;
 }
Пример #8
0
        public void MouseDown(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            _isMouseDown = true;
            if (AudioFile == null)
                return;

            if (ShowScrollBar && y >= Frame.Height - ScrollBarHeight)
            {
                // ScrollBar area
                _isDraggingScrollBar = true;
                float visibleAreaWidth = (1 / Zoom) * Frame.Width;
                float visibleAreaX = (1 / Zoom) * ContentOffset.X;
                if (x >= visibleAreaX && x <= visibleAreaX + visibleAreaWidth)
                {
                    // User is dragging the thumb
                    _isDraggingThumb = true;
                    _mouseDownX = x;
                    _thumbMouseDownX = visibleAreaX;
                    //Console.WriteLine("Dragging thumb - _thumbMouseDownX: {0}", _thumbMouseDownX);
                }
            } 
            else
            {
                // Wave form area
                ShowSecondaryPosition = true;
                long position = (long)(((x + ContentOffset.X) / ContentSize.Width) * Length);
                float positionPercentage = (float)position / (float)Length;
                //Console.WriteLine("positionPercentage: {0} x: {1} ContentSize.Width: {2}", positionPercentage, x, ContentSize.Width);
                SecondaryPosition = (long)(positionPercentage * Length);
            }
        }
Пример #9
0
 public static KeysHeld GetKeysHeld()
 {
     var keysHeld = new KeysHeld();
     if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
         keysHeld.IsShiftKeyHeld = true;
     if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
         keysHeld.IsAltKeyHeld = true;
     if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
         keysHeld.IsCtrlKeyHeld = true;
     return keysHeld;
 }
Пример #10
0
        /// <summary>
        /// Occurs when the user double-clicks on the control.
        /// Starts the playback of a new song.
        /// </summary>
        /// <param name="e">Event arguments</param>
        public void MouseDoubleClick(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            if (_columns == null || _songCache == null)
                return;

            var partialRect = new BasicRectangle();
            bool controlNeedsToBePartiallyInvalidated = false;
            int albumArtCoverWidth = _columns[0].Visible ? _columns[0].Width : 0;
            int scrollbarOffsetY = (_startLineNumber * _songCache.LineHeight) - VerticalScrollBar.Value;

            // Keep original songId in case the now playing value is set before invalidating the older value
            Guid originalId = Guid.Empty;

            // Set original id
            if (_mode == SongGridViewMode.AudioFile)
                originalId = _nowPlayingAudioFileId;
            else if (_mode == SongGridViewMode.Playlist)
                originalId = _nowPlayingPlaylistItemId;

            // Loop through visible lines
            for (int a = _startLineNumber; a < _startLineNumber + _numberOfLinesToDraw; a++)
            {
                if (_items[a].IsMouseOverItem)
                {
                    // Set this item as the new now playing
                    _nowPlayingAudioFileId = _items[a].AudioFile.Id;
                    _nowPlayingPlaylistItemId = _items[a].PlaylistItemId;

                    OnItemDoubleClick(_nowPlayingAudioFileId, a);
                    var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, ((a - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, _songCache.LineHeight);
                    partialRect.Merge(newPartialRect);
                    controlNeedsToBePartiallyInvalidated = true;
                }
                else if (_mode == SongGridViewMode.AudioFile && _items[a].AudioFile != null && _items[a].AudioFile.Id == originalId)
                {
                    var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, ((a - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, _songCache.LineHeight);
                    partialRect.Merge(newPartialRect);
                    controlNeedsToBePartiallyInvalidated = true;
                }
                else if (_mode == SongGridViewMode.Playlist && _items[a].PlaylistItemId == originalId)
                {
                    var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, ((a - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, _songCache.LineHeight);
                    partialRect.Merge(newPartialRect);
                    controlNeedsToBePartiallyInvalidated = true;
                }
            }
                
            if (controlNeedsToBePartiallyInvalidated)
                OnInvalidateVisualInRect(partialRect);
        }        
Пример #11
0
        public void MouseClick(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            bool controlNeedsToBeFullyInvalidated = false;
            bool controlNeedsToBePartiallyInvalidated = false;
            var partialRect = new BasicRectangle();

            if (_columns == null || _songCache == null)
                return;

            // Show context menu strip if the button click is right and not the album art column
            if (button == MouseButtonType.Right && x > _columns[0].Width && y > _songCache.LineHeight)
                OnDisplayContextMenu(ContextMenuType.Item, x, y);

            int albumArtCoverWidth = _columns[0].Visible ? _columns[0].Width : 0;
            var columnResizing = _columns.FirstOrDefault(col => col.IsUserResizingColumn == true);
            int scrollbarOffsetY = (_startLineNumber * _songCache.LineHeight) - VerticalScrollBar.Value;

            // Check if the user has clicked on the header (for orderBy)
            if (y >= 0 && y <= _songCache.LineHeight &&
                columnResizing == null && !IsColumnMoving)
            {
                // Check on what column the user has clicked
                int offsetX = 0;
                for (int a = 0; a < _songCache.ActiveColumns.Count; a++)
                {
                    var column = _songCache.ActiveColumns[a];
                    if (column.Visible)
                    {
                        // Check if the mouse pointer is over this column
                        if (x >= offsetX - HorizontalScrollBar.Value && x <= offsetX + column.Width - HorizontalScrollBar.Value)
                        {
                            if (button == MouseButtonType.Left && CanChangeOrderBy)
                            {
                                // Check if the column order was already set
                                if (_orderByFieldName == column.FieldName)
                                {
                                    // Reverse ascending/descending
                                    _orderByAscending = !_orderByAscending;
                                }
                                else
                                {
                                    // Set order by field name
                                    _orderByFieldName = column.FieldName;
                                    _orderByAscending = true;
                                }

                                //_items = null;
                                _songCache = null;

                                // Raise column click event (if an event is subscribed)
                                if (OnColumnClick != null)
                                {
                                    var data = new SongGridViewColumnClickData();
                                    data.ColumnIndex = a;
                                    OnColumnClick(data);
                                }

                                OnInvalidateVisual();
                                return;
                            }
                            else if (button == MouseButtonType.Right)
                            {
                                //// Refresh column visibility in menu before opening
                                //foreach (ToolStripMenuItem menuItem in _menuColumns.Items)
                                //{
                                //    SongGridViewColumn menuItemColumn = _columns.FirstOrDefault(x => x.Title == menuItem.Tag.ToString());
                                //    if (menuItemColumn != null)
                                //        menuItem.Checked = menuItemColumn.Visible;
                                //}

                                OnDisplayContextMenu(ContextMenuType.Header, x, y);
                            }
                        }

                        offsetX += column.Width;
                    }
                }
            }

            // Loop through visible lines to find the original selected items
            var tuple = GetStartIndexAndEndIndexOfSelectedRows();
            int startIndex = tuple.Item1;
            int endIndex = tuple.Item2;

            // Make sure the indexes are set
            if (startIndex > -1 && endIndex > -1)
            {
                // Invalidate the original selected lines
                int startY = ((startIndex - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY;
                int endY = ((endIndex - _startLineNumber + 2) * _songCache.LineHeight) + scrollbarOffsetY;
                var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, startY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, endY - startY);
                partialRect.Merge(newPartialRect);
                controlNeedsToBePartiallyInvalidated = true;
            }

            // Reset selection (make sure SHIFT or CTRL isn't held down)
            if (!keysHeld.IsShiftKeyHeld && !keysHeld.IsCtrlKeyHeld)
            {
                // Make sure the mouse is over at least one item
                var mouseOverItem = _items.FirstOrDefault(item => item.IsMouseOverItem == true);
                if (mouseOverItem != null)
                    ResetSelection();
            }

            // Loop through visible lines to update the new selected items
            bool invalidatedNewSelection = false;
            for (int a = _startLineNumber; a < _startLineNumber + _numberOfLinesToDraw; a++)
            {
                // Check if mouse is over this item
                if (_items[a].IsMouseOverItem)
                {
                    invalidatedNewSelection = true;

                    // Check if SHIFT is held
                    if (keysHeld.IsShiftKeyHeld)
                    {
                        // Find the start index of the selection
                        int startIndexSelection = _lastItemIndexClicked;
                        if (a < startIndexSelection)
                            startIndexSelection = a;
                        if (startIndexSelection < 0)
                            startIndexSelection = 0;

                        // Find the end index of the selection
                        int endIndexSelection = _lastItemIndexClicked;
                        if (a > endIndexSelection)
                            endIndexSelection = a + 1;

                        // Loop through items to selected
                        for (int b = startIndexSelection; b < endIndexSelection; b++)
                            _items [b].IsSelected = true;

                        controlNeedsToBeFullyInvalidated = true;
                    }                
                    // Check if CTRL is held
                    else if(keysHeld.IsCtrlKeyHeld)
                    {
                        // Invert selection
                        _items[a].IsSelected = !_items[a].IsSelected;
                        var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, ((a - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, _songCache.LineHeight);
                        partialRect.Merge(newPartialRect);
                        controlNeedsToBePartiallyInvalidated = true;
                    }
                    else
                    {
                        // Set this item as the new selected item
                        _items[a].IsSelected = true;
                        var newPartialRect = new BasicRectangle(albumArtCoverWidth - HorizontalScrollBar.Value, ((a - _startLineNumber + 1) * _songCache.LineHeight) + scrollbarOffsetY, Frame.Width - albumArtCoverWidth + HorizontalScrollBar.Value, _songCache.LineHeight);
                        partialRect.Merge(newPartialRect);
                        controlNeedsToBePartiallyInvalidated = true;
                    }

                    // Set the last item clicked index
                    _lastItemIndexClicked = a;
                    break;
                }
            }

            // Raise selected item changed event (if an event is subscribed)
            if (invalidatedNewSelection && OnSelectedIndexChanged != null)
            {
                var data = new SongGridViewSelectedIndexChangedData();
                OnSelectedIndexChanged(data);
            }

            if (controlNeedsToBeFullyInvalidated)
                OnInvalidateVisual();
            else if (controlNeedsToBePartiallyInvalidated)
                OnInvalidateVisualInRect(partialRect);
        }
Пример #12
0
        /// <summary>
        /// Occurs when the user releases a mouse button.        
        /// </summary>
        public void MouseUp(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            _dragStartX = -1;
            bool controlNeedsToBeFullyInvalidated = false;
            _isUserHoldingLeftMouseButton = false;

            if (_columns == null || _songCache == null)
                return;

            // Get reference to the moving column
            SongGridViewColumn columnMoving = null;
            foreach (var column in _songCache.ActiveColumns)
            {
                column.IsUserResizingColumn = false;
                if (column.IsUserMovingColumn)
                    columnMoving = column;
            }

            // Check if the user is moving a column
            if (columnMoving != null)
            {
                columnMoving.IsUserMovingColumn = false;
                controlNeedsToBeFullyInvalidated = true;

                // Find out on what column the mouse cursor is
                SongGridViewColumn columnOver = null;
                int currentX = 0;
                bool isPastCurrentlyMovingColumn = false;
                for (int a = 0; a < _songCache.ActiveColumns.Count; a++)
                {
                    var currentColumn = _songCache.ActiveColumns[a];
                    if (currentColumn.FieldName == columnMoving.FieldName)
                        isPastCurrentlyMovingColumn = true;

                    if (currentColumn.Visible)
                    {
                        // Check if the cursor is over the left part of the column
                        if (x >= currentX - HorizontalScrollBar.Value &&
                            x <= currentX + (currentColumn.Width/2) - HorizontalScrollBar.Value)
                        {
                            if (isPastCurrentlyMovingColumn && currentColumn.FieldName != columnMoving.FieldName)
                                columnOver = _songCache.ActiveColumns[a - 1];
                            else
                                columnOver = _songCache.ActiveColumns[a];
                            break;
                        }
                            // Check if the cursor is over the right part of the column
                        else if (x >= currentX + (currentColumn.Width/2) - HorizontalScrollBar.Value &&
                                 x <= currentX + currentColumn.Width - HorizontalScrollBar.Value)
                        {
                            // Check if there is a next item
                            if (a < _songCache.ActiveColumns.Count - 1)
                            {
                                if (isPastCurrentlyMovingColumn)
                                    columnOver = _songCache.ActiveColumns[a];
                                else
                                    columnOver = _songCache.ActiveColumns[a + 1];
                            }
                            break;
                        }

                        // Increment x
                        currentX += currentColumn.Width;
                    }
                }

                //// Check if the column was found (the cursor might be past the last column
                //if (columnOver == null)
                //{
                //    return;
                //}

                // Order columns by their current order
                var columnsOrdered = _columns.OrderBy(q => q.Order).ToList();

                // Move column
                int indexRemove = -1;
                int indexAdd = -1;
                for (int a = 0; a < columnsOrdered.Count; a++)
                {
                    // Find the moving column index
                    if (columnsOrdered[a].FieldName == columnMoving.FieldName)
                        indexRemove = a;

                    // Find the column index with the mouse over
                    if (columnOver != null && columnsOrdered[a].FieldName == columnOver.FieldName)
                        indexAdd = a;
                }

                // Remove column
                columnsOrdered.RemoveAt(indexRemove);

                // Check if the item needs to be inserted at the end
                if (indexAdd == -1)
                    columnsOrdered.Insert(columnsOrdered.Count, columnMoving);
                else
                    columnsOrdered.Insert(indexAdd, columnMoving);

                // Loop through columns to change the order of columnns
                for (int a = 0; a < columnsOrdered.Count; a++)
                    columnsOrdered[a].Order = a;
            }

            if (controlNeedsToBeFullyInvalidated)
            {
                InvalidateSongCache();
                OnInvalidateVisual();
            }
        }
Пример #13
0
        /// <summary>
        /// Occurs when the user is pressing down a mouse button.
        /// </summary>        
        public void MouseDown(float x, float y, MouseButtonType button, KeysHeld keysHeld)
        {
            _dragStartX = (int) x;
            if (_columns == null || _songCache == null)
                return;

            // Loop through columns
            foreach (SongGridViewColumn column in _songCache.ActiveColumns)
            {
                // Check for resizing column
                if (column.IsMouseCursorOverColumnLimit && column.CanBeResized && CanResizeColumns)
                {
                    column.IsUserResizingColumn = true;
                    _dragOriginalColumnWidth = column.Width;
                }
            }

            // Check if the left mouse button is held
            if(button == MouseButtonType.Left)
                _isUserHoldingLeftMouseButton = true;
        }