Skip to content

Commit

Permalink
Pull upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
MBeijer committed Jun 9, 2020
2 parents 907bb60 + 4630751 commit 40cd4d7
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 109 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ build/
resources/pictures/docicons/osx/MilkyTracker-*.icns
resources/pictures/docicons/osx/docerator/

# Editor config files
.vscode/

# Don't include objects
*.o
.deps
Expand Down
41 changes: 41 additions & 0 deletions src/ppui/GraphicsAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class PPGraphicsAbstract
*a = *b;
*b = h;
}
static pp_int32 modulo(pp_int32 a, pp_int32 b)
{
return ((a % b + b) % b);
}

pp_int32 width, height;

Expand Down Expand Up @@ -331,6 +335,43 @@ class PPGraphicsAbstract
{
fillVerticalShaded(currentClipRect, colSrc, colDst, invertShading);
}


void drawHLineDashed(pp_int32 x1, pp_int32 x2, pp_int32 y, pp_int32 dashLength, pp_int32 dashOffset = 0)
{
if (x2 < x1)
swap(&x1, &x2);

pp_int32 tail = x1;
pp_int32 head = x1 + dashLength - modulo(dashOffset, dashLength);

while (head-1 < x2)
{
drawHLine(tail, head-1, y);
tail = head;
head += dashLength;
}
if (tail < x2)
drawHLine(tail, x2, y);
}

void drawVLineDashed(pp_int32 y1, pp_int32 y2, pp_int32 x, pp_int32 dashLength, pp_int32 dashOffset = 0)
{
if (y2 < y1)
swap(&y1, &y2);

pp_int32 tail = y1;
pp_int32 head = y1 + dashLength - modulo(dashOffset, dashLength);

while (head-1 < y2)
{
drawVLine(tail, head-1, x);
tail = head;
head += dashLength;
}
if (tail < y2)
drawVLine(tail, y2, x);
}
};

#endif
5 changes: 5 additions & 0 deletions src/ppui/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,8 @@ bool PPTools::decodeByteArray(pp_uint8* array, pp_uint32 size, const PPString& s
return true;
}

pp_int32 PPTools::clamp(pp_int32 a, pp_int32 min, pp_int32 max)
{
return (a < min ? min : (a >= max ? max-1 : a));
}

2 changes: 2 additions & 0 deletions src/ppui/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class PPTools

static PPString encodeByteArray(const pp_uint8* array, pp_uint32 size);
static bool decodeByteArray(pp_uint8* array, pp_uint32 size, const PPString& str);

static pp_int32 clamp(pp_int32 a, pp_int32 min, pp_int32 max);
};

#endif
72 changes: 70 additions & 2 deletions src/tracker/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ bool PatternEditor::hasValidSelection()
return PatternEditorTools::hasValidSelection(pattern, selection.start, selection.end, getNumChannels());
}

bool PatternEditor::selectionContains(const PatternEditorTools::Position& pos)
{
return PatternEditorTools::selectionContains(pattern, selection.start, selection.end, pos);
}

bool PatternEditor::canMoveSelection(pp_int32 channels, pp_int32 rows)
{
PatternEditorTools::Position ss = selection.start;
PatternEditorTools::Position se = selection.end;
ss.channel += channels;
ss.row += rows;
se.channel += channels;
se.row += rows;
return PatternEditorTools::hasValidSelection(pattern, ss, se, getNumChannels());
}

void PatternEditor::selectChannel(pp_int32 channel)
{
if (pattern == NULL)
Expand Down Expand Up @@ -1241,7 +1257,7 @@ bool PatternEditor::writeEffect(pp_int32 effNum, pp_uint8 eff, pp_uint8 op,
patternTools.setPosition(pattern, cursor.channel, cursor.row);

// only write effect, when valid effect
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x30)
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x20)
if (eff)
patternTools.setEffect(effNum, eff, op);
else
Expand Down Expand Up @@ -1274,7 +1290,7 @@ void PatternEditor::writeDirectEffect(pp_int32 effNum, pp_uint8 eff, pp_uint8 op
patternTools.setPosition(pattern, track, row);

// only write effect, when valid effect
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x30)
// (0 is not a valid effect in my internal format, arpeggio is mapped to 0x20)
if (eff)
patternTools.setEffect(effNum, eff, op);
}
Expand Down Expand Up @@ -1815,3 +1831,55 @@ void PatternEditor::deleteLine(pp_int32 row)

finishUndo(LastChangeDeleteLine);
}


void PatternEditor::moveSelection(pp_int32 channels, pp_int32 rows)
{
PatternEditorTools::Position targetStart = selection.start;
PatternEditorTools::Position targetEnd = selection.end;
targetStart.row += rows;
targetStart.channel += channels;
targetEnd.row += rows;
targetEnd.channel += channels;

if (!PatternEditorTools::hasValidSelection(pattern, selection.start, selection.end))
return;
if (!PatternEditorTools::hasValidSelection(pattern, targetStart, targetEnd))
return;

prepareUndo();

PatternEditorTools tools(pattern);
tools.moveSelection(selection.start, selection.end, channels, rows, true);

selection.start = targetStart;
selection.end = targetEnd;

finishUndo(LastChangeMoveSelection);
}


void PatternEditor::cloneSelection(pp_int32 channels, pp_int32 rows)
{
PatternEditorTools::Position targetStart = selection.start;
PatternEditorTools::Position targetEnd = selection.end;
targetStart.row += rows;
targetStart.channel += channels;
targetEnd.row += rows;
targetEnd.channel += channels;

if (!PatternEditorTools::hasValidSelection(pattern, selection.start, selection.end))
return;
if (!PatternEditorTools::hasValidSelection(pattern, targetStart, targetEnd))
return;

prepareUndo();

PatternEditorTools tools(pattern);
tools.moveSelection(selection.start, selection.end, channels, rows, false); // don't erase source notes

selection.start = targetStart;
selection.end = targetEnd;

finishUndo(LastChangeCloneSelection);
}
8 changes: 8 additions & 0 deletions src/tracker/PatternEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class PatternEditor : public EditorBase
LastChangeCut,
LastChangePaste,
LastChangeDeleteSelection,
LastChangeMoveSelection,
LastChangeCloneSelection,

LastChangeExpandPattern,
LastChangeShrinkPattern,
Expand Down Expand Up @@ -263,6 +265,8 @@ class PatternEditor : public EditorBase
void setSelectionEnd(const PatternEditorTools::Position& pos) { selection.end = pos; }
void resetSelection() { selection.reset(); }
bool hasValidSelection();
bool canMoveSelection(pp_int32 channels, pp_int32 rows);
bool selectionContains(const PatternEditorTools::Position& pos);
void selectChannel(pp_int32 channel);
void selectAll();

Expand Down Expand Up @@ -414,6 +418,10 @@ class PatternEditor : public EditorBase
void deleteNote(pp_int32 channel, pp_int32 row);
void deleteLine(pp_int32 row);

// --- moving entire selection -------------------------------------------
void moveSelection(pp_int32 channels, pp_int32 rows);
void cloneSelection(pp_int32 channels, pp_int32 rows);

};

#endif
9 changes: 5 additions & 4 deletions src/tracker/PatternEditorClipBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ void PatternEditor::ClipBoard::makeCopy(TXMPattern& pattern, const PatternEditor
return;

// only entire instrument column is allowed
if (selectionStart.inner >= 1 && selectionStart.inner<=2)
if (selectionStart.inner >= 1 && selectionStart.inner <= 2)
selectionStart.inner = 1;
if (selectionEnd.inner >= 1 && selectionEnd.inner<=2)
if (selectionEnd.inner >= 1 && selectionEnd.inner <= 2)
selectionEnd.inner = 2;
// only entire volume column can be selected
if (selectionStart.inner >= 3 && selectionStart.inner<=4)
if (selectionStart.inner >= 3 && selectionStart.inner <= 4)
selectionStart.inner = 3;
if (selectionEnd.inner >= 3 && selectionEnd.inner<=4)
if (selectionEnd.inner >= 3 && selectionEnd.inner <= 4)
selectionEnd.inner = 4;

selectionWidth = selectionEnd.channel - selectionStart.channel + 1;
selectionHeight = selectionEnd.row - selectionStart.row + 1;

mp_sint32 slotSize = pattern.effnum * 2 + 2;

// sanity check: only operate on internal XM pattern data
ASSERT(slotSize == 6);

mp_sint32 rowSizeDst = slotSize*selectionWidth;
Expand Down
51 changes: 50 additions & 1 deletion src/tracker/PatternEditorControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "PatternEditorControl.h"
#include "GraphicsAbstract.h"
#include "Tools.h"
#include "Screen.h"
#include "Control.h"
#include "Font.h"
Expand Down Expand Up @@ -732,7 +733,7 @@ void PatternEditorControl::paint(PPGraphicsAbstract* g)
g->drawString(name,px, py);
}
}

for (j = startPos; j < numVisibleChannels; j++)
{

Expand Down Expand Up @@ -814,6 +815,54 @@ void PatternEditorControl::paint(PPGraphicsAbstract* g)
}
}

// --------------------- draw moved selection ---------------------

if (hasValidSelection() && moveSelection)
{
pp_int32 moveSelectionRows = moveSelectionFinalPos.row - moveSelectionInitialPos.row;
pp_int32 moveSelectionChannels = moveSelectionFinalPos.channel - moveSelectionInitialPos.channel;

pp_int32 i1 = selectionStart.row + moveSelectionRows;
pp_int32 j1 = selectionStart.channel + moveSelectionChannels;
pp_int32 i2 = selectionEnd.row + moveSelectionRows;
pp_int32 j2 = selectionEnd.channel + moveSelectionChannels;

if (i2 >= 0 && j2 >= 0 && i1 < pattern->rows && j1 < numVisibleChannels)
{
i1 = PPTools::clamp(i1, 0, pattern->rows);
i2 = PPTools::clamp(i2, 0, pattern->rows);
j1 = PPTools::clamp(j1, 0, numVisibleChannels);
j2 = PPTools::clamp(j2, 0, numVisibleChannels);

pp_int32 x1 = (location.x + (j1-startPos) * slotSize + SCROLLBARWIDTH) + cursorPositions[selectionStart.inner] + (getRowCountWidth() + 4);
pp_int32 y1 = (location.y + (i1-startIndex) * font->getCharHeight() + SCROLLBARWIDTH) + (font->getCharHeight() + 4);

pp_int32 x2 = (location.x + (j2-startPos) * slotSize + SCROLLBARWIDTH) + cursorPositions[selectionEnd.inner]+cursorSizes[selectionEnd.inner] + (getRowCountWidth() + 3);
pp_int32 y2 = (location.y + (i2-startIndex) * font->getCharHeight() + SCROLLBARWIDTH) + (font->getCharHeight()*2 + 2);

// use a different color for cloning the selection instead of moving it
if (::getKeyModifier() & selectionKeyModifier)
g->setColor(hiLightPrimary);
else
g->setColor(textColor);

const pp_int32 dashLen = 6;

// inner dashed lines
g->drawHLineDashed(x1, x2, y1, dashLen, 3);
g->drawHLineDashed(x1, x2, y2, dashLen, 3+y2-y1);
g->drawVLineDashed(y1, y2, x1, dashLen, 3);
g->drawVLineDashed(y1, y2+2, x2, dashLen, 3+x2-x1);

// outer dashed lines
g->drawHLineDashed(x1-1, x2+1, y1-1, dashLen, 1);
g->drawHLineDashed(x1-1, x2, y2+1, dashLen, 3+y2-y1);
g->drawVLineDashed(y1-1, y2+1, x1-1, dashLen, 1);
g->drawVLineDashed(y1-1, y2+2, x2+1, dashLen, 3+x2-x1);
}

}

// draw scrollbars
hTopScrollbar->paint(g);
hBottomScrollbar->paint(g);
Expand Down
7 changes: 7 additions & 0 deletions src/tracker/PatternEditorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class PatternEditorControl :
pp_int32 selectionTicker;

bool hasDragged;

bool moveSelection;
PatternEditorTools::Position moveSelectionInitialPos;
PatternEditorTools::Position moveSelectionFinalPos;

// edit menu
pp_int32 menuPosX;
Expand Down Expand Up @@ -377,6 +381,9 @@ class PatternEditorControl :
void handleKeyChar(pp_uint8 character);
void handleKeyDown(pp_uint16 keyCode, pp_uint16 scanCode, pp_uint16 character);

void selectionModifierKeyDown();
void selectionModifierKeyUp();

// mark channel
void markChannel(pp_int32 channel, bool invert = true);

Expand Down
Loading

0 comments on commit 40cd4d7

Please sign in to comment.