Пример #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (isDraggingInstrument)
            {
                if (ClientRectangle.Contains(e.X, e.Y))
                {
                    var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType);

                    var instrumentSrc = instrumentDrag;
                    var instrumentDst = buttonIdx >= 0 && buttons[buttonIdx].type == ButtonType.Instrument ? buttons[buttonIdx].instrument : null;

                    if (instrumentSrc != instrumentDst && instrumentSrc != null && instrumentDst != null)
                    {
                        if (envelopeDragIdx == -1)
                        {
                            if (PlatformDialogs.MessageBox($"Are you sure you want to replace all notes of instrument '{instrumentDst.Name}' with '{instrumentSrc.Name}'?", "Replace intrument", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                                App.Project.ReplaceInstrument(instrumentDst, instrumentSrc);
                                App.UndoRedoManager.EndTransaction();

                                InstrumentReplaced?.Invoke(instrumentDst);
                            }
                        }
                        else
                        {
                            if (PlatformDialogs.MessageBox($"Are you sure you want to copy the {Envelope.EnvelopeStrings[envelopeDragIdx]} envelope of instrument '{instrumentSrc.Name}' to '{instrumentDst.Name}'?", "Copy Envelope", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrumentDst.Id);
                                instrumentDst.Envelopes[envelopeDragIdx] = instrumentSrc.Envelopes[envelopeDragIdx].Clone();
                                App.UndoRedoManager.EndTransaction();

                                InstrumentEdited?.Invoke(instrumentDst, envelopeDragIdx);
                                Invalidate();
                            }
                        }
                    }
                }
                else
                {
                    InstrumentDraggedOutside(instrumentDrag, PointToScreen(new Point(e.X, e.Y)));
                }

                Capture = false;
            }

            CancelDrag();
        }
Пример #2
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (isDraggingInstrument)
            {
                var instrumentSrcIdx = instrumentDragIdx;
                var instrumentDstIdx = ((e.Y + scrollY) / ButtonSizeY) - (App.Project.Songs.Count + 2) - 1;

                if (instrumentSrcIdx != instrumentDstIdx && instrumentDstIdx >= 0 && instrumentDstIdx < App.Project.Instruments.Count)
                {
                    var instrumentSrc = App.Project.Instruments[instrumentSrcIdx];
                    var instrumentDst = App.Project.Instruments[instrumentDstIdx];

                    if (envelopeDragIdx == -1)
                    {
                        if (MessageBox.Show($"Are you sure you want to replace all notes of instrument '{instrumentDst.Name}' with '{instrumentSrc.Name}'?", "Replace intrument", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            App.UndoRedoManager.BeginTransaction(TransactionScope.Project);
                            App.Project.ReplaceInstrument(instrumentDst, instrumentSrc);
                            App.UndoRedoManager.EndTransaction();

                            InstrumentReplaced?.Invoke(instrumentDst);
                        }
                    }
                    else
                    {
                        if (MessageBox.Show($"Are you sure you want to copy the {Envelope.EnvelopeStrings[envelopeDragIdx]} envelope of instrument '{instrumentSrc.Name}' to '{instrumentDst.Name}'?", "Copy Envelope", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrumentDst.Id);
                            instrumentDst.Envelopes[envelopeDragIdx] = instrumentSrc.Envelopes[envelopeDragIdx].Clone();
                            App.Project.ReplaceInstrument(instrumentDst, instrumentSrc);
                            App.UndoRedoManager.EndTransaction();

                            InstrumentEdited?.Invoke(instrumentDst, envelopeDragIdx);
                            Invalidate();
                        }
                    }
                }
            }

            CancelDrag();
        }