// // initialize the mover: allocate memory, get cells and column data // void CellsMover::start(int r0, int c0, int r1, int c1, int qualifiers) { m_rowCount = r1 - r0 + 1; m_colCount = c1 - c0 + 1; assert(m_rowCount > 0); assert(m_colCount > 0); m_startPos = m_pos = TPoint(c0, r0); m_qualifiers = qualifiers; m_cells.resize(m_rowCount * m_colCount, TXshCell()); m_oldCells.resize(m_rowCount * m_colCount, TXshCell()); getCells(m_cells, r0, c0); getColumnsData(c0, c1); }
void CellsMover::getCells(std::vector<TXshCell> &cells, int r, int c) const { for (int i = 0; i < (int)cells.size(); i++) cells[i] = TXshCell(); TXsheet *xsh = getXsheet(); for (int i = 0; i < m_colCount; i++) { TXshColumn *column = xsh->getColumn(c + i); if (column && column->isLocked()) continue; xsh->getCells(r, c + i, m_rowCount, &cells[m_rowCount * i]); } }
void redo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); xsh->insertColumn(m_columnIndex); int frameCount = m_childLevel->getXsheet()->getFrameCount(); if (frameCount < 1) frameCount = 1; for (int r = 0; r < frameCount; r++) xsh->setCell(r, m_columnIndex, TXshCell(m_childLevel.getPointer(), TFrameId(r + 1))); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
TXshZeraryFxColumn::TXshZeraryFxColumn(int frameCount) : m_zeraryColumnFx(new TZeraryColumnFx()), m_zeraryFxLevel(new TXshZeraryFxLevel()) { m_zeraryColumnFx->addRef(); m_zeraryColumnFx->setColumn(this); m_zeraryFxLevel->addRef(); m_zeraryFxLevel->setColumn(this); for (int i = 0; i < frameCount; i++) setCell(i, TXshCell(m_zeraryFxLevel, TFrameId(1))); }
void MeshifyPopup::hideEvent(QHideEvent *he) { Dialog::hideEvent(he); TFrameHandle *frameHandle = TApp::instance()->getCurrentFrame(); TColumnHandle *columnHandle = TApp::instance()->getCurrentColumn(); disconnect(frameHandle, SIGNAL(frameSwitched()), this, SLOT(onCellSwitched())); disconnect(columnHandle, SIGNAL(columnIndexSwitched()), this, SLOT(onCellSwitched())); m_viewer->clear(); m_r = -1, m_c = -1, m_cell = TXshCell(); }
bool TXshZeraryFxColumn::setCell(int row, const TXshCell &cell) { if (cell.isEmpty()) return false; TXshCell newCell = cell; //Sto settando delle celle in una colonna nuova, devo settare anche l'effetto. if (isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0) { newCell = TXshCell(m_zeraryFxLevel, cell.getFrameId()); TXshZeraryFxLevel *fxLevel = cell.m_level->getZeraryFxLevel(); TXshZeraryFxColumn *fxColumn = fxLevel->getColumn(); m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx()); } return TXshCellColumn::setCell(row, newCell); }
TXshZeraryFxColumn::TXshZeraryFxColumn(const TXshZeraryFxColumn &src) : m_zeraryColumnFx(new TZeraryColumnFx()), m_zeraryFxLevel(new TXshZeraryFxLevel()) { m_zeraryColumnFx->addRef(); m_zeraryColumnFx->setColumn(this); m_zeraryFxLevel->addRef(); m_zeraryFxLevel->setColumn(this); m_first = src.m_first; int i; for (i = 0; i < (int)src.m_cells.size(); i++) m_cells.push_back(TXshCell(m_zeraryFxLevel, src.m_cells[i].getFrameId())); assert((int)src.m_cells.size() == (int)m_cells.size()); TFx *fx = src.getZeraryColumnFx()->getZeraryFx(); if (fx) { wstring fxName = fx->getName(); fx = fx->clone(false); fx->setName(fxName); m_zeraryColumnFx->setZeraryFx(fx); } }
void TXshSoundTextColumn::createSoundTextLevel(int row, QList<QString> textList) { TXshSoundTextLevel *level = new TXshSoundTextLevel(); level->setType(SND_TXT_XSHLEVEL); int i = 0; TXshCell cell; for (i; i < textList.size(); i++, row++) { QString str = textList.at(i); QString precStr = (i > 0) ? level->getFrameText(i - 1) : QString(); if (str == QString("<none>")) { if (i > 0) { setCell(row, cell); continue; } else str = QString(); } level->setFrameText(i, str); TFrameId fid(i + 1); cell = TXshCell(level, fid); setCell(row, cell); } }
QScriptValue foo(QScriptContext *ctx, QScriptEngine *eng) { int r = ctx->argument(0).toInteger(); int c = ctx->argument(1).toInteger(); QScriptValue levelArg = ctx->argument(2); ScriptWrapper::Level *level = dynamic_cast<ScriptWrapper::Level *>(levelArg.toQObject()); if (level) { TXshSimpleLevel *sl = level->getLevel(); if (!sl) return QScriptValue(0); TFrameId fid(1); if (!sl->isFid(fid)) sl->setFrame(fid, sl->createEmptyFrame()); ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); scene->getXsheet()->setCell(r, c, TXshCell(sl, fid)); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); } return QScriptValue(1); }
bool TXshZeraryFxColumn::setCells(int row, int rowCount, const TXshCell cells[]) { std::vector<TXshCell> newCells; bool isEmptyColumn = isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0; int i; for (i = 0; i < rowCount; i++) { if (isEmptyColumn) newCells.push_back(TXshCell(m_zeraryFxLevel, cells[i].getFrameId())); else newCells.push_back(cells[i]); } //Sto settando delle celle in una colonna nuova, devo settare anche l'effetto. if (isEmptyColumn) { i = 0; while (i < rowCount && cells[i].isEmpty()) i++; if (i >= rowCount) return false; TXshZeraryFxLevel *fxLevel = dynamic_cast<TXshZeraryFxLevel *>(cells[i].m_level.getPointer()); TXshZeraryFxColumn *fxColumn = fxLevel->getColumn(); m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx()); } return TXshCellColumn::setCells(row, rowCount, &newCells[0]); }
TImage *TTool::touchImage() { if (!m_application) return 0; m_cellsData.clear(); m_isLevelCreated = false; m_isFrameCreated = false; Preferences *pref = Preferences::instance(); bool isAutoCreateEnabled = pref->isAutoCreateEnabled(); bool animationSheetEnabled = pref->isAnimationSheetEnabled(); bool isAutoStretchEnabled = pref->isAutoStretchEnabled(); TFrameHandle *currentFrame = m_application->getCurrentFrame(); TXshLevelHandle *currentLevel = m_application->getCurrentLevel(); if (currentFrame->isEditingLevel()) { // Editing level // no level => return 0 TXshLevel *xl = currentLevel->getLevel(); if (!xl) return 0; TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl || sl->isEmpty()) return 0; TFrameId fid = currentFrame->getFid(); TImageP img = sl->getFrame(fid, true); if (!img) { // no drawing found if (sl->isSubsequence() || sl->isReadOnly() || !isAutoCreateEnabled) return 0; // create a new drawing img = sl->createEmptyFrame(); sl->setFrame(fid, img); currentLevel->notifyLevelChange(); m_isFrameCreated = true; } return img.getPointer(); } else { // editing xsheet if (m_application->getCurrentObject()->isSpline()) return 0; TSceneHandle *currentScene = m_application->getCurrentScene(); ToonzScene *scene = currentScene->getScene(); int row = currentFrame->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); if (col < 0) return 0; TXsheetHandle *currentXsheet = m_application->getCurrentXsheet(); TXsheet *xsh = currentXsheet->getXsheet(); if (!xsh) return 0; TXshCell cell = xsh->getCell(row, col); TXshSimpleLevel *sl = cell.getSimpleLevel(); if (sl != 0) { // current cell is not empty if (isAutoCreateEnabled && animationSheetEnabled && row > 0 && xsh->getCell(row - 1, col) == xsh->getCell(row, col)) { // animationSheet is enabled and the current cell is a "hold". We must // create a new drawing. // measure the hold length (starting from the current row) : r0-r1 int r0 = row, r1 = row; if (isAutoStretchEnabled) while (xsh->getCell(r1 + 1, col) == cell) r1++; // find the proper frameid (possibly addisng suffix, in order to avoid a // fid already used) TFrameId fid = getNewFrameId(sl, row); // create the new drawing TImageP img = sl->createEmptyFrame(); m_isFrameCreated = true; // insert the drawing in the level sl->setFrame(fid, img); // update the cell cell = TXshCell(sl, fid); // update the xsheet (change the current cell and possibly all the // following "hold") for (int r = r0; r <= r1; r++) xsh->setCell(r, col, cell); // notify currentXsheet->notifyXsheetChanged(); currentScene->notifyCastChange(); currentLevel->notifyLevelChange(); m_cellsData.push_back(r0); m_cellsData.push_back(r1); m_cellsData.push_back(0); } // we've found the image. return it. return cell.getImage(true).getPointer(); } // current cell is empty. if (!isAutoCreateEnabled) return 0; // get the column range int r0, r1; xsh->getCellRange(col, r0, r1); if (animationSheetEnabled && r0 <= r1) { // animation sheet enabled and not empty column. We must create a new // drawing in the column level and possibly add "holds" // find the last not-empty cell before the current one (a) and the first // after (b) int a = row - 1, b = row + 1; while (a >= r0 && xsh->getCell(a, col).isEmpty()) a--; while (b <= r1 && xsh->getCell(b, col).isEmpty()) b++; // find the level we must attach to if (a >= r0) { // there is a not-emtpy cell before the current one sl = xsh->getCell(a, col).getSimpleLevel(); } else if (b <= r1) { sl = xsh->getCell(b, col).getSimpleLevel(); } if (sl) { // note: sl should be always !=0 (the column is not empty) // if - for some reason - it is ==0 then we skip to the standard (i.e. // !animationSheetEnabled) beahviour // create the drawing // find the proper frameid (possibly addisng suffix, in order to avoid a // fid already used) TFrameId fid = getNewFrameId(sl, row); // create the new drawing TImageP img = sl->createEmptyFrame(); m_isFrameCreated = true; // insert the drawing in the level sl->setFrame(fid, img); // update the cell cell = TXshCell(sl, fid); xsh->setCell(row, col, cell); // create holds if (!isAutoStretchEnabled) { m_cellsData.push_back(row); m_cellsData.push_back(row); m_cellsData.push_back(2); // vuoto => nuovo } else { if (a >= r0) { // create a hold before : [a+1, row-1] TXshCell aCell = xsh->getCell(a, col); for (int i = a + 1; i < row; i++) xsh->setCell(i, col, aCell); m_cellsData.push_back(a + 1); m_cellsData.push_back(row - 1); m_cellsData.push_back(1); // vuoto => vecchio if (b <= r1 && xsh->getCell(b, col).getSimpleLevel() == sl) { // create also a hold after for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell); m_cellsData.push_back(row); m_cellsData.push_back(b - 1); m_cellsData.push_back(2); // vuoto => nuovo } else { m_cellsData.push_back(row); m_cellsData.push_back(row); m_cellsData.push_back(2); // vuoto => nuovo } } else if (b <= r1) { // create a hold after for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell); m_cellsData.push_back(row); m_cellsData.push_back(b - 1); m_cellsData.push_back(2); // vuoto => nuovo } } } // notify & return currentXsheet->notifyXsheetChanged(); currentScene->notifyCastChange(); currentLevel->notifyLevelChange(); return cell.getImage(true).getPointer(); } if (row > 0 && xsh->getCell(row - 1, col).getSimpleLevel() != 0 && !animationSheetEnabled) { sl = xsh->getCell(row - 1, col).getSimpleLevel(); if (sl->getType() != OVL_XSHLEVEL || sl->getPath().getFrame() != TFrameId::NO_FRAME) { // la cella precedente contiene un drawing di un livello. animationSheet // e' disabilitato // creo un nuovo frame currentLevel->setLevel(sl); if (sl->isSubsequence() || sl->isReadOnly()) return 0; TFrameId fid = sl->index2fid(sl->getFrameCount()); TImageP img = sl->createEmptyFrame(); m_isFrameCreated = true; sl->setFrame(fid, img); cell = TXshCell(sl, fid); xsh->setCell(row, col, cell); currentXsheet->notifyXsheetChanged(); currentScene->notifyCastChange(); currentLevel->notifyLevelChange(); return img.getPointer(); } } // animation sheet disabled or empty column. autoCreate is enabled: we must // create a new level int levelType = pref->getDefLevelType(); TXshLevel *xl = scene->createNewLevel(levelType); sl = xl->getSimpleLevel(); m_isLevelCreated = true; // create the drawing TFrameId fid = animationSheetEnabled ? getNewFrameId(sl, row) : TFrameId(1); TImageP img = sl->createEmptyFrame(); m_isFrameCreated = true; sl->setFrame(fid, img); cell = TXshCell(sl, fid); xsh->setCell(row, col, cell); if (animationSheetEnabled) { m_cellsData.push_back(row); m_cellsData.push_back(row); m_cellsData.push_back(2); // vuoto => nuovo } currentXsheet->notifyXsheetChanged(); currentScene->notifyCastChange(); currentLevel->notifyLevelChange(); return img.getPointer(); } }