Пример #1
0
        private void ScoreBar_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var scoreBar    = (ScoreBar)sender;
            var hitTestInfo = scoreBar.HitTest(e.GetPosition(scoreBar));

            if (e.ChangedButton == MouseButton.Left)
            {
                if (hitTestInfo.IsValid)
                {
                    var scoreNote = AddScoreNote(scoreBar, hitTestInfo, null);
                    if (scoreNote != null)
                    {
                        var note = scoreNote.Note;
                        if (note.IsSync)
                        {
                            ScoreNote prevScoreNote = null;
                            ScoreNote nextScoreNote = null;
                            if (note.HasPrevSync)
                            {
                                var prevNote = note.PrevSyncTarget;
                                prevScoreNote = FindScoreNote(prevNote);
                                LineLayer.NoteRelations.Add(scoreNote, prevScoreNote, NoteRelation.Sync);
                            }
                            if (note.HasNextSync)
                            {
                                var nextNote = note.NextSyncTarget;
                                nextScoreNote = FindScoreNote(nextNote);
                                LineLayer.NoteRelations.Add(scoreNote, nextScoreNote, NoteRelation.Sync);
                            }
                            if (note.HasPrevSync && note.HasNextSync)
                            {
                                LineLayer.NoteRelations.Remove(prevScoreNote, nextScoreNote);
                            }
                            LineLayer.InvalidateVisual();
                        }
                    }
                }
                else
                {
                    UnselectAllScoreNotes();
                    SelectScoreBar(scoreBar);
                }
                e.Handled = true;
            }
            else
            {
                if (HasSelectedScoreNotes)
                {
                    UnselectAllScoreNotes();
                    e.Handled = true;
                }
            }
        }
Пример #2
0
 private void RepositionLineLayer()
 {
     LineLayer.Width  = NoteLayer.ActualWidth;
     LineLayer.Height = NoteLayer.ActualHeight;
     LineLayer.InvalidateVisual();
 }
Пример #3
0
        private void ScoreNote_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                UnselectAllScoreNotes();
                e.Handled = true;
                return;
            }
            DraggingEndNote = sender as ScoreNote;
            Debug.Assert(DraggingEndNote != null, "DraggingEndNote != null");
            if (DraggingStartNote != null && DraggingEndNote != null)
            {
                var mode  = EditMode;
                var start = DraggingStartNote;
                var end   = DraggingEndNote;
                var ns    = start.Note;
                var ne    = end.Note;
                if (mode == EditMode.ResetNote)
                {
                    ns.Reset();
                    LineLayer.NoteRelations.RemoveAll(start, NoteRelation.Hold);
                    LineLayer.NoteRelations.RemoveAll(start, NoteRelation.FlickOrSlide);
                    if (!start.Equals(end))
                    {
                        ne.Reset();
                        LineLayer.NoteRelations.RemoveAll(end, NoteRelation.Hold);
                        LineLayer.NoteRelations.RemoveAll(end, NoteRelation.FlickOrSlide);
                    }
                    LineLayer.InvalidateVisual();
                    Project.IsChanged = true;
                }
                else if (!start.Equals(end))
                {
                    if (LineLayer.NoteRelations.ContainsPair(start, end))
                    {
                        MessageBox.Show(Application.Current.FindResource <string>(App.ResourceKeys.NoteRelationAlreadyExistsPrompt), App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    if (mode != EditMode.CreateRelations)
                    {
                        throw new ArgumentOutOfRangeException(nameof(mode));
                    }
                    var first  = ns < ne ? ns : ne;
                    var second = first.Equals(ns) ? ne : ns;
                    if (ns.Bar == ne.Bar && ns.IndexInGrid == ne.IndexInGrid && !ns.IsSync && !ne.IsSync)
                    {
                        // sync
                        Note.ConnectSync(ns, ne);
                        LineLayer.NoteRelations.Add(start, end, NoteRelation.Sync);
                        LineLayer.InvalidateVisual();
                    }
                    else if (ns.FinishPosition != ne.FinishPosition && (ns.Bar != ne.Bar || ns.IndexInGrid != ne.IndexInGrid) && (!ns.IsHoldStart && !ne.IsHoldStart) && (first.IsSlide == second.IsSlide))
                    {
                        // flick
                        if (first.HasNextFlickOrSlide || second.HasPrevFlickOrSlide)
                        {
                            MessageBox.Show(Application.Current.FindResource <string>(App.ResourceKeys.FlickRelationIsFullPrompt), App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            return;
                        }
                        Note.ConnectFlick(first, second);
                        LineLayer.NoteRelations.Add(start, end, NoteRelation.FlickOrSlide);
                        LineLayer.InvalidateVisual();
                    }
                    else if (ns.FinishPosition == ne.FinishPosition && !ns.IsHold && !ne.IsHold && !first.IsFlick && !first.IsSlide && !second.IsSlide)
                    {
                        // hold
                        var anyObstacles = Score.Notes.AnyNoteBetween(ns, ne);
                        if (anyObstacles)
                        {
                            MessageBox.Show(Application.Current.FindResource <string>(App.ResourceKeys.InvalidHoldCreationPrompt), App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            return;
                        }
                        Note.ConnectHold(ns, ne);
                        LineLayer.NoteRelations.Add(start, end, NoteRelation.Hold);
                        LineLayer.InvalidateVisual();
                    }
                    else
                    {
                        DraggingStartNote = DraggingEndNote = null;
                        e.Handled         = true;
                        return;
                    }

                    Project.IsChanged = true;
                    end.IsSelected    = true;
                }
            }
            DraggingStartNote = DraggingEndNote = null;
            e.Handled         = true;
        }