Пример #1
0
        private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsSelectable)
            {
                return;
            }
            MainCanvas.CaptureMouse();              //Capture mouse to receive events even if the pointer is outside the control

            //Start dragging:
            _draggingState.StartDragging(CanvasScoreRenderer.ConvertPoint(e.GetPosition(MainCanvas)));

            //Check if element under cursor is staff element:
            FrameworkElement element = e.OriginalSource as FrameworkElement;

            if (element == null)
            {
                return;
            }
            if (!Renderer.OwnershipDictionary.ContainsKey(element))
            {
                return;
            }

            //Set selected element:
            Select(Renderer.OwnershipDictionary[element]);
        }
Пример #2
0
        private void RenderOnCanvas(Measure measure)
        {
            if (Renderer == null)
            {
                Renderer = new CanvasScoreRenderer(MainCanvas);
            }
            var beamGroupsForThisMeasure = measure.Staff.BeamGroups.Where(bg => bg.Members.Any(m => m.Measure == measure));

            foreach (var beamGroup in beamGroupsForThisMeasure)
            {
                var frameworkElements = Renderer.OwnershipDictionary.Where(d => d.Value == beamGroup).Select(d => d.Key).ToList();
                frameworkElements.RemoveAllFrom(Renderer.Canvas);
            }

            foreach (var element in measure.Elements.Where(e => !(e is Barline)))
            {
                var note = element as Note;
                if (note != null)
                {
                    foreach (var lyric in note.Lyrics)
                    {
                        var lyricsFrameworkElements = Renderer.OwnershipDictionary.Where(d => d.Value == lyric).Select(d => d.Key).ToList();
                        lyricsFrameworkElements.RemoveAllFrom(Renderer.Canvas);
                    }
                }
                var frameworkElements = Renderer.OwnershipDictionary.Where(d => d.Value == element).Select(d => d.Key).ToList();
                frameworkElements.RemoveAllFrom(Renderer.Canvas);
            }

            var brush = Foreground as SolidColorBrush;

            if (brush != null)
            {
                Renderer.Settings.DefaultColor = Renderer.ConvertColor(brush.Color);
            }

            Renderer.Render(measure);
            if (SelectedElement != null)
            {
                ColorElement(SelectedElement, Colors.Magenta);
            }
            InvalidateMeasure();
        }
Пример #3
0
        private void RenderOnCanvas(Score score)
        {
            _innerScore = score;
            if (score == null)
            {
                return;
            }

            score.MeasureInvalidated -= Score_MeasureInvalidated;
            score.ScoreInvalidated   -= Score_ScoreInvalidated;

            MainCanvas.Children.Clear();
            Renderer = new CanvasScoreRenderer(MainCanvas);
            Renderer.Settings.RenderingMode = RenderingMode;
            Renderer.Settings.CurrentPage   = CurrentPage;
            var brush = Foreground as SolidColorBrush;

            if (brush != null)
            {
                Renderer.Settings.DefaultColor = Renderer.ConvertColor(brush.Color);
            }
            if (score.Staves.Count > 0)
            {
                Renderer.Settings.PageWidth = score.Staves[0].Elements.Count * 26;
            }

            Renderer.Render(score);

            if (SelectedElement != null)
            {
                ColorElement(SelectedElement, Colors.Magenta);
            }
            InvalidateMeasure();

            score.MeasureInvalidated += Score_MeasureInvalidated;
            score.ScoreInvalidated   += Score_ScoreInvalidated;
        }
Пример #4
0
        private void MainCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (!IsSelectable)
            {
                return;
            }
            if (!_draggingState.IsDragging || _innerScore == null)
            {
                return;
            }

            Point currentPosition = e.GetPosition(MainCanvas);
            var   strategy        = DraggingStrategy.For(SelectedElement);

            if (strategy != null)
            {
                strategy.Drag(Renderer, SelectedElement, _draggingState, CanvasScoreRenderer.ConvertPoint(currentPosition));
            }

            if (InvalidatingMode == InvalidatingModes.RedrawAllScore)
            {
                RenderOnCanvas(_innerScore);
            }
        }