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(); }
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(); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); bool left = e.Button.HasFlag(MouseButtons.Left); bool middle = e.Button.HasFlag(MouseButtons.Middle) || (e.Button.HasFlag(MouseButtons.Left) && ModifierKeys.HasFlag(Keys.Alt)); bool right = e.Button.HasFlag(MouseButtons.Right); var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType); if (buttonIdx >= 0) { var button = buttons[buttonIdx]; if (left) { if (button.type == ButtonType.SongHeader) { if (subButtonType == SubButtonType.Add) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateSong(); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Song) { if (button.song != selectedSong) { selectedSong = button.song; SongSelected?.Invoke(selectedSong); ConditionalInvalidate(); } } else if (button.type == ButtonType.InstrumentHeader) { if (subButtonType == SubButtonType.Add) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateInstrument(); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } if (subButtonType == SubButtonType.LoadInstrument) { var filename = PlatformDialogs.ShowOpenFileDialog("Open File", "Fami Tracker Instrument (*.fti)|*.fti"); if (filename != null) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); var instrument = FamitrackerInstrumentFile.CreateFromFile(App.Project, filename); if (instrument == null) { App.UndoRedoManager.AbortTransaction(); } else { App.UndoRedoManager.EndTransaction(); } } RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Instrument) { selectedInstrument = button.instrument; if (selectedInstrument != null) { instrumentDrag = selectedInstrument; mouseDragY = e.Y; } if (subButtonType == SubButtonType.Volume) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Volume); envelopeDragIdx = Envelope.Volume; } else if (subButtonType == SubButtonType.Pitch) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Pitch); envelopeDragIdx = Envelope.Pitch; } else if (subButtonType == SubButtonType.Arpeggio) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Arpeggio); envelopeDragIdx = Envelope.Arpeggio; } else if (subButtonType == SubButtonType.DPCM) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Max); } else if (subButtonType >= SubButtonType.DutyCycle0 && subButtonType <= SubButtonType.DutyCycle3) { selectedInstrument.DutyCycle = (selectedInstrument.DutyCycle + 1) % 4; } InstrumentSelected?.Invoke(selectedInstrument); ConditionalInvalidate(); } } else if (right) { if (button.type == ButtonType.Song && App.Project.Songs.Count > 1) { var song = button.song; if (PlatformDialogs.MessageBox($"Are you sure you want to delete '{song.Name}' ?", "Delete song", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewSong = song == selectedSong; App.Stop(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteSong(song); if (selectNewSong) { selectedSong = App.Project.Songs[0]; } SongSelected?.Invoke(selectedSong); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Instrument && button.instrument != null) { var instrument = button.instrument; if (subButtonType == SubButtonType.Arpeggio || subButtonType == SubButtonType.Pitch || subButtonType == SubButtonType.Volume) { int envType = Envelope.Volume; switch (subButtonType) { case SubButtonType.Arpeggio: envType = Envelope.Arpeggio; break; case SubButtonType.Pitch: envType = Envelope.Pitch; break; } App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrument.Id); instrument.Envelopes[envType].Length = 0; App.UndoRedoManager.EndTransaction(); ConditionalInvalidate(); } else if (subButtonType == SubButtonType.Max) { if (PlatformDialogs.MessageBox($"Are you sure you want to delete '{instrument.Name}' ? All notes using this instrument will be deleted.", "Delete intrument", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewInstrument = instrument == selectedInstrument; App.StopInstrumentNoteAndWait(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteInstrument(instrument); if (selectNewInstrument) { selectedInstrument = App.Project.Instruments.Count > 0 ? App.Project.Instruments[0] : null; } SongSelected?.Invoke(selectedSong); InstrumentDeleted?.Invoke(instrument); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } } } } if (middle) { mouseLastY = e.Y; } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); bool left = e.Button.HasFlag(MouseButtons.Left); bool middle = e.Button.HasFlag(MouseButtons.Middle) || (e.Button.HasFlag(MouseButtons.Left) && ModifierKeys.HasFlag(Keys.Alt)); bool right = e.Button.HasFlag(MouseButtons.Right); var buttonIndex = (e.Y + scrollY) / ButtonSizeY; var songIndex = buttonIndex - 1; var instrumentIndex = buttonIndex - (App.Project.Songs.Count + 2); var shiftY = (buttonIndex * ButtonSizeY - scrollY); if (left) { if (songIndex == -1) { if (GetButtonRect(1, shiftY).Contains(e.X, e.Y)) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateSong(); App.UndoRedoManager.EndTransaction(); ConditionalInvalidate(); } } else if (instrumentIndex == -1) { if (GetButtonRect(1, shiftY).Contains(e.X, e.Y)) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateInstrument(); App.UndoRedoManager.EndTransaction(); ConditionalInvalidate(); } } else if (songIndex >= 0 && songIndex < App.Project.Songs.Count) { selectedSong = App.Project.Songs[songIndex]; SongSelected?.Invoke(selectedSong); ConditionalInvalidate(); return; } else if (instrumentIndex >= 0 && instrumentIndex <= App.Project.Instruments.Count) { selectedInstrument = instrumentIndex == 0 ? null : App.Project.Instruments[instrumentIndex - 1]; if (selectedInstrument != null) { instrumentDragIdx = instrumentIndex - 1; mouseDragY = e.Y; } if (selectedInstrument != null && GetButtonRect(4, shiftY).Contains(e.X, e.Y)) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Volume); envelopeDragIdx = Envelope.Volume; } else if (selectedInstrument != null && GetButtonRect(3, shiftY).Contains(e.X, e.Y)) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Pitch); envelopeDragIdx = Envelope.Pitch; } else if (selectedInstrument != null && GetButtonRect(2, shiftY).Contains(e.X, e.Y)) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Arpeggio); envelopeDragIdx = Envelope.Arpeggio; } else if (GetButtonRect(1, shiftY).Contains(e.X, e.Y)) { if (selectedInstrument == null) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Max); } else { selectedInstrument.DutyCycle = (selectedInstrument.DutyCycle + 1) % 4; ConditionalInvalidate(); } } InstrumentSelected?.Invoke(selectedInstrument); ConditionalInvalidate(); } } else if (right) { instrumentIndex--; if (songIndex >= 0 && songIndex < App.Project.Songs.Count && App.Project.Songs.Count > 1) { var song = App.Project.Songs[songIndex]; if (MessageBox.Show($"Are you sure you want to delete '{song.Name}' ?", "Delete song", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewSong = song == selectedSong; App.Stop(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteSong(song); App.UndoRedoManager.EndTransaction(); if (selectNewSong) { selectedSong = App.Project.Songs[0]; } SongSelected?.Invoke(selectedSong); ConditionalInvalidate(); return; } } else if (instrumentIndex >= 0 && instrumentIndex < App.Project.Instruments.Count) { var instrument = App.Project.Instruments[instrumentIndex]; if (MessageBox.Show($"Are you sure you want to delete '{instrument.Name}' ? All notes using this instrument will be deleted.", "Delete intrument", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewInstrument = instrument == selectedInstrument; App.StopInstrumentNoteAndWait(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteInstrument(instrument); App.UndoRedoManager.EndTransaction(); if (selectNewInstrument) { selectedInstrument = App.Project.Instruments.Count > 0 ? App.Project.Instruments[0] : null; } SongSelected?.Invoke(selectedSong); ConditionalInvalidate(); return; } } } if (middle) { mouseLastY = e.Y; } }