MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / PerformDrop

Method PerformDrop

Source/PatternEditor.cpp:3674–3737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3672}
3673
3674bool CPatternEditor::PerformDrop(CPatternClipData ClipData, bool bCopy, bool bCopyMix) // // //
3675{
3676 // Drop selection onto pattern, returns true if drop was successful
3677
3678 const int Channels = GetChannelCount();
3679
3680 m_bDragging = false;
3681 m_bDragStart = false;
3682
3683 if (m_bSelecting && m_selection.IsSameStartPoint(m_selDrag)) {
3684 // Drop area is same as select area
3685 m_bSelectionInvalidated = true;
3686 return false;
3687 }
3688
3689 if (m_selDrag.GetChanStart() >= Channels || m_selDrag.GetChanEnd() < 0) { // // //
3690 // Completely outside of visible area
3691 CancelSelection();
3692 return false;
3693 }
3694
3695 if (m_selDrag.m_cpStart.Xpos.Track < 0/* || m_selDrag.m_cpStart.Ypos.Row < 0*/) {
3696 // Clip if selection is less than zero as this is not handled by the paste routine
3697 int ChannelOffset = (m_selDrag.m_cpStart.Xpos.Track < 0) ? -m_selDrag.m_cpStart.Xpos.Track : 0;
3698 int RowOffset = (m_selDrag.m_cpStart.Ypos.Row < 0) ? -m_selDrag.m_cpStart.Ypos.Row : 0;
3699
3700 int NewChannels = ClipData.ClipInfo.Channels - ChannelOffset;
3701 int NewRows = ClipData.ClipInfo.Rows - RowOffset;
3702
3703 auto Clipped = CPatternClipData {NewChannels, NewRows}; // // //
3704
3705 Clipped.ClipInfo = ClipData.ClipInfo;
3706 Clipped.ClipInfo.Channels = NewChannels;
3707 Clipped.ClipInfo.Rows = NewRows;
3708
3709 for (int c = 0; c < NewChannels; ++c)
3710 for (int r = 0; r < NewRows; ++r)
3711 *Clipped.GetPattern(c, r) = *ClipData.GetPattern(c + ChannelOffset, r + RowOffset);
3712
3713 if (m_selDrag.m_cpStart.Xpos.Track < 0)
3714 m_selDrag.m_cpStart.Xpos = {0, cursor_column_t::NOTE};
3715
3716 m_selDrag.m_cpStart.Ypos.Row = std::max(m_selDrag.m_cpStart.Ypos.Row, 0);
3717
3718 ClipData = std::move(Clipped); // // //
3719 }
3720
3721 if (m_selDrag.m_cpEnd.Xpos.Track > Channels - 1)
3722 m_selDrag.m_cpEnd.Xpos = {Channels - 1, GetChannelColumns(Channels)};
3723
3724 // // //
3725 m_selDrag.m_cpEnd.Xpos.Column = std::min(m_selDrag.m_cpEnd.Xpos.Column, cursor_column_t::EFF4_PARAM2); // TODO remove hardcoded number
3726
3727 // Paste
3728
3729 bool bDelete = !bCopy;
3730 bool bMix = IsShiftPressed();
3731

Callers 1

OnDropMethod · 0.80

Calls 5

IsSameStartPointMethod · 0.80
GetPatternMethod · 0.80
GetChanStartMethod · 0.45
GetChanEndMethod · 0.45
AddActionMethod · 0.45

Tested by

no test coverage detected