Merge pull request #2884 from shun-iwasawa/g/fix_fold_column_slipping

Fix folded columns slipping
This commit is contained in:
Rodney 2019-11-19 16:47:07 -07:00 committed by GitHub
commit 29cf1142d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 17 deletions

View file

@ -93,6 +93,9 @@ of column identified by \b col.
void saveData(TOStream &os); void saveData(TOStream &os);
void loadData(TIStream &is); void loadData(TIStream &is);
void rollLeftFoldedState(int index, int count);
void rollRightFoldedState(int index, int count);
}; };
#endif #endif

View file

@ -49,6 +49,7 @@
#include "toonz/txshnoteset.h" #include "toonz/txshnoteset.h"
#include "toutputproperties.h" #include "toutputproperties.h"
#include "toonz/preferences.h" #include "toonz/preferences.h"
#include "toonz/columnfan.h"
// TnzBase includes // TnzBase includes
#include "tfx.h" #include "tfx.h"
@ -1222,8 +1223,9 @@ public:
XsheetGUI::DragTool *XsheetGUI::DragTool::makeKeyFrameHandleMoverTool( XsheetGUI::DragTool *XsheetGUI::DragTool::makeKeyFrameHandleMoverTool(
XsheetViewer *viewer, bool isEaseOut, int keyRow) { XsheetViewer *viewer, bool isEaseOut, int keyRow) {
return new KeyFrameHandleMoverTool( return new KeyFrameHandleMoverTool(viewer,
viewer, isEaseOut ? KeyFrameHandleMoverTool::EaseOut isEaseOut
? KeyFrameHandleMoverTool::EaseOut
: KeyFrameHandleMoverTool::EaseIn, : KeyFrameHandleMoverTool::EaseIn,
keyRow); keyRow);
} }
@ -1694,11 +1696,22 @@ public:
col = 0; col = 0;
else if (!getViewer()->orientation()->isVerticalTimeline() && col > currEnd) else if (!getViewer()->orientation()->isVerticalTimeline() && col > currEnd)
col = currEnd; col = currEnd;
int dCol = col - (m_lastCol - m_offset); int dCol = col - (m_lastCol - m_offset);
// ignore if the cursor moves in the drag-starting column // ignore if the cursor moves in the drag-starting column
if (dCol == 0) return; if (dCol == 0) return;
if (dCol < 0 &&
!xsh->getColumnFan(getViewer()->orientation())->isActive(col)) {
while (
col != 0 &&
!xsh->getColumnFan(getViewer()->orientation())->isActive(col - 1)) {
col--;
dCol--;
}
}
int newBegin = *indices.begin() + dCol; int newBegin = *indices.begin() + dCol;
int newEnd = *indices.rbegin() + dCol; int newEnd = *indices.rbegin() + dCol;

View file

@ -178,3 +178,58 @@ void ColumnFan::loadData(TIStream &is) {
for (j = 0; j < count; j++) deactivate(index + j); for (j = 0; j < count; j++) deactivate(index + j);
} }
} }
//-----------------------------------------------------------------------------
void ColumnFan::rollLeftFoldedState(int index, int count) {
assert(index >= 0);
assert(count > 1);
int columnCount = m_columns.size();
if (columnCount <= index) return;
if (index + count - 1 > columnCount) count = columnCount - index + 1;
if (count < 2) return;
int i = index, j = index + count - 1;
bool tmp = isActive(i);
for (int k = i; k < j; ++k) {
if (isActive(k) && !isActive(k + 1))
deactivate(k);
else if (!isActive(k) && isActive(k + 1))
activate(k);
}
if (isActive(j) && !tmp)
deactivate(j);
else if (!isActive(j) && tmp)
activate(j);
update();
}
//-----------------------------------------------------------------------------
void ColumnFan::rollRightFoldedState(int index, int count) {
assert(index >= 0);
assert(count > 1);
int columnCount = m_columns.size();
if (columnCount <= index) return;
if (index + count - 1 > columnCount) count = columnCount - index + 1;
if (count < 2) return;
int i = index, j = index + count - 1;
bool tmp = isActive(j);
for (int k = j; k > i; --k) {
if (isActive(k) && !isActive(k - 1))
deactivate(k);
else if (!isActive(k) && isActive(k - 1))
activate(k);
}
if (isActive(i) && !tmp)
deactivate(i);
else if (!isActive(i) && tmp)
activate(i);
update();
}

View file

@ -1318,6 +1318,11 @@ void TXsheet::insertColumn(int col, TXshColumn *column) {
TFx *fx = column->getFx(); TFx *fx = column->getFx();
if (fx) getFxDag()->addToXsheet(fx); if (fx) getFxDag()->addToXsheet(fx);
} }
for (ColumnFan &columnFan : m_imp->m_columnFans) {
columnFan.rollRightFoldedState(col,
m_imp->m_columnSet.getColumnCount() - col);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1336,6 +1341,11 @@ void TXsheet::removeColumn(int col) {
} }
m_imp->m_columnSet.removeColumn(col); m_imp->m_columnSet.removeColumn(col);
m_imp->m_pegTree->removeColumn(col); m_imp->m_pegTree->removeColumn(col);
for (ColumnFan &columnFan : m_imp->m_columnFans) {
columnFan.rollLeftFoldedState(col,
m_imp->m_columnSet.getColumnCount() - col);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1363,12 +1373,16 @@ void TXsheet::moveColumn(int srcIndex, int dstIndex) {
int c1 = dstIndex; int c1 = dstIndex;
assert(c0 < c1); assert(c0 < c1);
m_imp->m_columnSet.rollLeft(c0, c1 - c0 + 1); m_imp->m_columnSet.rollLeft(c0, c1 - c0 + 1);
for (ColumnFan &columnFan : m_imp->m_columnFans)
columnFan.rollLeftFoldedState(c0, c1 - c0 + 1);
for (int c = c0; c < c1; ++c) m_imp->m_pegTree->swapColumns(c, c + 1); for (int c = c0; c < c1; ++c) m_imp->m_pegTree->swapColumns(c, c + 1);
} else { } else {
int c0 = dstIndex; int c0 = dstIndex;
int c1 = srcIndex; int c1 = srcIndex;
assert(c0 < c1); assert(c0 < c1);
m_imp->m_columnSet.rollRight(c0, c1 - c0 + 1); m_imp->m_columnSet.rollRight(c0, c1 - c0 + 1);
for (ColumnFan &columnFan : m_imp->m_columnFans)
columnFan.rollRightFoldedState(c0, c1 - c0 + 1);
for (int c = c1 - 1; c >= c0; --c) m_imp->m_pegTree->swapColumns(c, c + 1); for (int c = c1 - 1; c >= c0; --c) m_imp->m_pegTree->swapColumns(c, c + 1);
} }
} }