void FilmstripFrames::onFrameSwitched() { // no. interferische con lo shift-click per la selezione. // m_selection->selectNone(); TApp *app = TApp::instance(); TFrameHandle *fh = app->getCurrentFrame(); TFrameId fid; if (fh->isEditingLevel()) fid = fh->getFid(); else { TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); int col = app->getCurrentColumn()->getColumnIndex(); int row = fh->getFrame(); if (row < 0 || col < 0) return; TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; fid = cell.getFrameId(); } int index = fid2index(fid); if (index >= 0) { exponeFrame(index); // clear selection and select only the destination frame select(index, ONLY_SELECT); } update(); }
void undo() const { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsheet->getCell(m_r, m_c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) return; rasImage->setRaster(((TRasterImageP)TImageCache::instance()->get(m_rasId, true))->getRaster()->clone()); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(false); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); if (m_isLastInBlock) { TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); } }
void redo() const { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsheet->getCell(m_r, m_c); TImageP image = (TRasterImageP)cell.getImage(true); if (!image) return; TRasterP ras = image->raster(); if (!ras) return; onChange(ras, m_threshold, m_softness); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(false); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); if (m_isLastInBlock) { TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); } }
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); }
void AdjustLevelsUndo::redo() const { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsheet->getCell(m_r, m_c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) return; TRasterP ras = rasImage->getRaster(); if (!ras) return; TRop::rgbmAdjust(ras, ras, m_in0, m_in1, m_out0, m_out1); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); if (m_isLastInBlock) TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
TFrameId TTool::getCurrentFid() const { if (!m_application) return TFrameId(); TFrameHandle *fh = m_application->getCurrentFrame(); if (fh->isEditingLevel()) return fh->getFid(); int row = m_application->getCurrentFrame()->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); TXshCell cell = m_application->getCurrentXsheet()->getXsheet()->getCell(row, col); if (cell.isEmpty()) return TFrameId::NO_FRAME; return cell.getFrameId(); }
int BinarizePopup::getSelectedFrames() { m_frames.clear(); TSelection *selection = TSelection::getCurrent(); TCellSelection *cellSelection; TFilmstripSelection *filmstripSelection; int count = 0; if ((cellSelection = dynamic_cast<TCellSelection *>(selection))) { std::set<TRasterImage *> images; int r0, c0, r1, c1; cellSelection->getSelectedCells(r0, c0, r1, c1); TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); int c, r; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TRasterImageP rasImage = cell.getImage(false); if (!rasImage || !rasImage->getRaster()) continue; Frames::value_type item(cell.getSimpleLevel(), cell.getFrameId()); Frames::iterator it; it = std::lower_bound(m_frames.begin(), m_frames.end(), item); if (it == m_frames.end() || *it != item) { m_frames.insert(it, item); count++; } } } } else if ((filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection))) { TXshSimpleLevel *sl = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (sl) { std::set<TFrameId> fids = filmstripSelection->getSelectedFids(); std::set<TFrameId>::iterator it; for (it = fids.begin(); it != fids.end(); ++it) { TRasterImageP rasImage = sl->getFrame(*it, false); if (!!rasImage && !!rasImage->getRaster()) { m_frames.push_back(std::make_pair(sl, *it)); count++; } } } } else { } m_frameIndex = 0; return count; }
void AntialiasPopup::apply() { TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent()); int threshold = m_thresholdField->getValue(); int softness = m_softnessField->getValue(); if (cellSelection) { std::set<TImage *> images; int r0, c0, r1, c1; cellSelection->getSelectedCells(r0, c0, r1, c1); TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); bool oneImageChanged = false; int c, r; TUndoManager::manager()->beginBlock(); for (c = c0; c <= c1; c++) for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TImageP image = cell.getImage(true); if (!image) continue; if (images.find(image.getPointer()) != images.end()) continue; TRasterP ras = image->raster(); if (!ras) continue; images.insert(image.getPointer()); oneImageChanged = true; TUndoManager::manager()->add(new TRasterAntialiasUndo(threshold, softness, r, c, ras->clone())); onChange(ras, threshold, softness); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); } TUndoManager::manager()->endBlock(); if (oneImageChanged) { close(); return; } } TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent()); if (filmstripSelection) { TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { std::set<TFrameId> fids = filmstripSelection->getSelectedFids(); std::set<TFrameId>::iterator it = fids.begin(); bool oneImageChanged = false; for (it; it != fids.end(); it++) { TImageP image = simpleLevel->getFrame(*it, true); if (!image) continue; TRasterP ras = image->raster(); if (!ras) continue; oneImageChanged = true; onChange(ras, threshold, softness); simpleLevel->touchFrame(*it); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, *it); } if (oneImageChanged) { close(); return; } } } DVGui::error(QObject::tr("The current selection is invalid.")); return; }
bool VectorizerPopup::apply() { std::set<TXshLevel *> levels; ToonzScene *scene = m_sceneHandle->getScene(); if (!scene) { assert(scene); return false; } TSceneProperties *sceneProp = scene->getProperties(); if (!sceneProp) return false; VectorizerParameters *vectorizerParameters = sceneProp->getVectorizerParameters(); if (!vectorizerParameters) return false; int r0 = 0; int c0 = 0; int r1 = 0; int c1 = 0; bool isCellSelection = getSelectedLevels(levels, r0, c0, r1, c1); if (levels.empty()) { error(tr("The current selection is invalid.")); return false; } //Initialize Progress bar m_progressDialog = new DVGui::ProgressDialog("", "Cancel", 0, 1); m_progressDialog->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); //Don't show ? and X buttons m_progressDialog->setWindowTitle(QString("Convert To Vector...")); m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); m_progressDialog->setWindowModality(Qt::WindowModal); //No user interaction is allowed during vectorization m_progressDialog->setFixedSize(200, 100); //Initialize vectorizer m_vectorizer = new Vectorizer; m_vectorizer->setParameters(*vectorizerParameters); connect(m_vectorizer, SIGNAL(frameName(QString)), this, SLOT(onFrameName(QString)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(frameDone(int)), this, SLOT(onFrameDone(int)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(partialDone(int, int)), this, SLOT(onPartialDone(int, int)), Qt::QueuedConnection); //We DON'T want the progress bar to be hidden at cancel press - since its modal //behavior prevents the user to interfere with a possibly still active vectorization. disconnect(m_progressDialog, SIGNAL(canceled()), m_progressDialog, SLOT(onCancel())); //We first inform the vectorizer of a cancel press; bool ret = connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SLOT(cancel())); //which eventually transmits the command to vectorization core, allowing full-time cancels ret = ret && connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SIGNAL(transmitCancel())); //Only after the vectorizer has terminated its process - or got cancelled, we are allowed //to proceed here. ret = ret && connect(m_vectorizer, SIGNAL(finished()), this, SLOT(onFinished()), Qt::QueuedConnection); assert(ret); int newIndexColumn = c1 + 1; std::set<TXshLevel *>::iterator it = levels.begin(); for (it; it != levels.end(); it++) { TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(*it); if (!sl || !sl->getSimpleLevel() || !isLevelToConvert(sl)) { QString levelName = tr(toString(sl->getName()).c_str()); QString errorMsg = tr("Cannot convert to vector the current selection.") + levelName; error(errorMsg); continue; } std::vector<TFrameId> fids; if (isCellSelection) getSelectedFids(fids, sl, r0, c0, r1, c1); else sl->getFids(fids); assert(fids.size() > 0); close(); // Re-initialize progress Bar m_progressDialog->setMaximum(fids.size() * 100); m_progressDialog->setValue(0); m_currFrame = 0; // Re-initialize vectorizer m_vectorizer->setLevel(sl); m_vectorizer->setFids(fids); // Start vectorizing m_vectorizer->start(); m_progressDialog->show(); // Wait the vectorizer... while (!l_quitLoop) QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); l_quitLoop = false; // Assign output X-sheet cells TXshSimpleLevel *vl = m_vectorizer->getVectorizedLevel(); if (isCellSelection && vl) { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); xsheet->insertColumn(newIndexColumn); int r, c; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TXshSimpleLevel *level = (!cell.isEmpty()) ? cell.getSimpleLevel() : 0; if (level != sl) continue; TFrameId curFid = cell.getFrameId(); std::vector<TFrameId> newFids; vl->getFids(newFids); std::vector<TFrameId>::iterator it1 = newFids.begin(); for (it1; it1 != newFids.end(); it1++) { TFrameId id = *it1; if (id.getNumber() == curFid.getNumber() || // Hanno stesso numero di frame (id.getNumber() == 1 && curFid.getNumber() == -2)) // La vecchia cella non ha numero di frame xsheet->setCell(r, newIndexColumn, TXshCell(vl, id)); } } } newIndexColumn += 1; } else if (vl) { std::vector<TFrameId> gomi; scene->getXsheet()->exposeLevel(0, scene->getXsheet()->getFirstFreeColumnIndex(), vl, gomi); } if (m_vectorizer->isCanceled()) break; } m_progressDialog->close(); delete m_vectorizer; TApp::instance()->getCurrentScene()->notifyCastChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); return true; }
void StylePickerTool::pick(const TPointD &pos, const TMouseEvent &e) { // Area = 0, Line = 1, All = 2 int modeValue = m_colorType.getIndex(); //------------------------------------ // MultiLayerStylePicker /*--- PickしたStyleId = 0、かつ Preference で MultiLayerStylePickerが有効、かつ Scene編集モード、かつ 下のカラムから拾った色がTransparentでない場合、 → カレントLevelを移動する。 ---*/ if (Preferences::instance()->isMultiLayerStylePickerEnabled() && getApplication()->getCurrentFrame()->isEditingScene()) { int superPickedColumnId = getViewer()->posToColumnIndex( e.m_pos, getPixelSize() * getPixelSize(), false); if (superPickedColumnId >= 0 /*-- 何かColumnに当たった場合 --*/ && getApplication()->getCurrentColumn()->getColumnIndex() != superPickedColumnId) /*-- かつ、Current Columnでない場合 --*/ { /*-- そのColumnからPickを試みる --*/ int currentFrame = getApplication()->getCurrentFrame()->getFrame(); TXshCell pickedCell = getApplication()->getCurrentXsheet()->getXsheet()->getCell( currentFrame, superPickedColumnId); TImageP pickedImage = pickedCell.getImage(false).getPointer(); TToonzImageP picked_ti = pickedImage; TVectorImageP picked_vi = pickedImage; TXshSimpleLevel *picked_level = pickedCell.getSimpleLevel(); if ((picked_ti || picked_vi) && picked_level) { TPointD tmpMousePosition = getColumnMatrix(superPickedColumnId).inv() * getViewer()->winToWorld(e.m_pos); TPointD tmpDpiScale = getCurrentDpiScale(picked_level, getCurrentFid()); tmpMousePosition.x /= tmpDpiScale.x; tmpMousePosition.y /= tmpDpiScale.y; StylePicker superPicker(pickedImage); int picked_subsampling = picked_level->getImageSubsampling(pickedCell.getFrameId()); int superPicked_StyleId = superPicker.pickStyleId( TScale(1.0 / picked_subsampling) * tmpMousePosition + TPointD(-0.5, -0.5), getPixelSize() * getPixelSize(), modeValue); /*-- 何かStyleが拾えて、Transparentでない場合 --*/ if (superPicked_StyleId > 0) { /*-- Levelの移動 --*/ getApplication()->getCurrentLevel()->setLevel(picked_level); /*-- Columnの移動 --*/ getApplication()->getCurrentColumn()->setColumnIndex( superPickedColumnId); /*-- 選択の解除 --*/ if (getApplication()->getCurrentSelection()->getSelection()) getApplication() ->getCurrentSelection() ->getSelection() ->selectNone(); /*-- StyleIdの移動 --*/ getApplication()->setCurrentLevelStyleIndex(superPicked_StyleId); return; } } } } /*-- MultiLayerStylePicker ここまで --*/ //------------------------------------ TImageP image = getImage(false); TToonzImageP ti = image; TVectorImageP vi = image; TXshSimpleLevel *level = getApplication()->getCurrentLevel()->getSimpleLevel(); if ((!ti && !vi) || !level) return; /*-- 画面外をpickしても拾えないようにする --*/ if (!m_viewer->getGeometry().contains(pos)) return; int subsampling = level->getImageSubsampling(getCurrentFid()); StylePicker picker(image); int styleId = picker.pickStyleId(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5), getPixelSize() * getPixelSize(), modeValue); if (styleId < 0) return; if (modeValue == 1) // LINES { /*-- pickLineモードのとき、取得Styleが0の場合はカレントStyleを変えない。 * --*/ if (styleId == 0) return; /*-- * pickLineモードのとき、PurePaintの部分をクリックしてもカレントStyleを変えない * --*/ if (ti && picker.pickTone(TScale(1.0 / subsampling) * pos + TPointD(-0.5, -0.5)) == 255) return; } /*--- Styleを選択している場合は選択を解除する ---*/ TSelection *selection = TTool::getApplication()->getCurrentSelection()->getSelection(); if (selection) { TStyleSelection *styleSelection = dynamic_cast<TStyleSelection *>(selection); if (styleSelection) styleSelection->selectNone(); } getApplication()->setCurrentLevelStyleIndex(styleId); }
void LinesFadePopup::apply() { TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent()); TPixel32 color = m_linesColorField->getColor(); int intensity = m_intensity->getValue(); if (cellSelection) { std::set<TRasterImage *> images; int r0, c0, r1, c1; cellSelection->getSelectedCells(r0, c0, r1, c1); TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); bool oneImageChanged = false; int c, r; TUndoManager::manager()->beginBlock(); for (c = c0; c <= c1; c++) for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TRasterImageP rasImage = (TRasterImageP)cell.getImage(true); if (!rasImage) continue; if (images.find(rasImage.getPointer()) != images.end()) continue; TRaster32P ras = rasImage->getRaster(); if (!ras) continue; images.insert(rasImage.getPointer()); TUndoManager::manager()->add(new TLineFadeUndo(color, intensity, r, c, ras->clone())); oneImageChanged = true; onChange(ras, ras, color, intensity); TXshSimpleLevel *simpleLevel = cell.getSimpleLevel(); assert(simpleLevel); simpleLevel->touchFrame(cell.getFrameId()); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId()); } TUndoManager::manager()->endBlock(); images.clear(); if (oneImageChanged) { close(); return; } } TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent()); if (filmstripSelection) { TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { std::set<TFrameId> fids = filmstripSelection->getSelectedFids(); bool oneImageChanged = false; for (auto const& fid : fids) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(fid, true); ; if (!rasImage) continue; TRaster32P ras = rasImage->getRaster(); if (!ras) continue; oneImageChanged = true; onChange(ras, ras, color, intensity); simpleLevel->touchFrame(fid); simpleLevel->setDirtyFlag(true); IconGenerator::instance()->invalidate(simpleLevel, fid); } if (oneImageChanged) { close(); return; } } } DVGui::error(QObject::tr("The current selection is invalid.")); return; }