void TApp::updateXshLevel() { TXshLevel *xl = 0; if (m_currentFrame->isEditingScene()) { int frame = m_currentFrame->getFrame(); int column = m_currentColumn->getColumnIndex(); TXsheet *xsheet = m_currentXsheet->getXsheet(); if (xsheet && column >= 0 && frame >= 0 && !xsheet->isColumnEmpty(column)) { TXshCell cell = xsheet->getCell(frame, column); xl = cell.m_level.getPointer(); // Se sono su una cella vuota successiva a celle di un certo livello // prendo questo come livello corrente. if (!xl && frame > 0) { TXshCell cell = xsheet->getCell(frame - 1, column); xl = cell.m_level.getPointer(); } } m_currentLevel->setLevel(xl); // level could be the same, but palette could have changed if (xl && xl->getSimpleLevel()) { TPalette *currentPalette = m_paletteController->getCurrentPalette()->getPalette(); int styleIndex = m_paletteController->getCurrentLevelPalette()->getStyleIndex(); m_paletteController->getCurrentLevelPalette()->setPalette( xl->getSimpleLevel()->getPalette(), styleIndex); // Se il nuovo livello selezionato e' un ovl, // la paletta corrente e' una cleanup palette // => setto come handle corrente quello della paletta di cleanup. if (xl->getType() == OVL_XSHLEVEL && currentPalette && currentPalette->isCleanupPalette()) m_paletteController->editCleanupPalette(); } else if (xl && xl->getPaletteLevel()) { int styleIndex = m_paletteController->getCurrentLevelPalette()->getStyleIndex(); m_paletteController->getCurrentLevelPalette()->setPalette( xl->getPaletteLevel()->getPalette(), styleIndex); } else m_paletteController->getCurrentLevelPalette()->setPalette(0); } }
void ShiftTraceTool::updateBox() { if (0 <= m_ghostIndex && m_ghostIndex < 2 && m_row[m_ghostIndex] >= 0) { int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); int row = m_row[m_ghostIndex]; TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); TXshSimpleLevel *sl = cell.getSimpleLevel(); if (sl) { m_dpiAff = getDpiAffine(sl, cell.m_frameId); TImageP img = cell.getImage(false); if (img) { if (TRasterImageP ri = img) { TRasterP ras = ri->getRaster(); m_box = (convert(ras->getBounds()) - ras->getCenterD()) * ri->getSubsampling(); } else if (TToonzImageP ti = img) { TRasterP ras = ti->getRaster(); m_box = (convert(ras->getBounds()) - ras->getCenterD()) * ti->getSubsampling(); } else if (TVectorImageP vi = img) { m_box = vi->getBBox(); } } } } }
bool CellsMover::canMoveCells(const TPoint &pos) { TXsheet *xsh = getXsheet(); if (pos.x < 0) return false; if (pos.x != m_startPos.x) { int count = 0; // controlla il tipo int i = 0; while (i < m_rowCount * m_colCount) { TXshColumn::ColumnType srcType = getColumnTypeFromCell(i); int dstIndex = pos.x + i; TXshColumn *dstColumn = xsh->getColumn(dstIndex); if (srcType == TXshColumn::eZeraryFxType) return false; if (dstColumn && !dstColumn->isEmpty() && dstColumn->getColumnType() != srcType) return false; if (!dstColumn || dstColumn->isLocked() == false) count++; i += m_rowCount; } if (count == 0) return false; } if ((m_qualifiers & CellsMover::eInsertCells) || (m_qualifiers & CellsMover::eOverwriteCells)) return true; int count = 0; for (int i = 0; i < m_colCount; i++) { for (int j = 0; j < m_rowCount; j++) { if (!xsh->getCell(pos.y + j, pos.x + i).isEmpty()) return false; count++; } } if (count == 0) return false; return true; }
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(); }
/*! Notify change of image in \b fid: update icon and notify level change. */ void TTool::notifyImageChanged(const TFrameId &fid) { onImageChanged(); if (!m_application) return; m_application->getCurrentScene()->setDirtyFlag(true); if (m_application->getCurrentFrame()->isEditingLevel()) { TXshLevel *xl = m_application->getCurrentLevel()->getLevel(); if (!xl) return; TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl) return; sl->setDirtyFlag(true); IconGenerator::instance()->invalidate(sl, fid); IconGenerator::instance()->invalidateSceneIcon(); } else { int row = m_application->getCurrentFrame()->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); if (col < 0) return; TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet(); if (!xsh) return; TXshCell cell = xsh->getCell(row, col); TXshSimpleLevel *sl = cell.getSimpleLevel(); if (sl) { IconGenerator::instance()->invalidate(sl, fid); IconGenerator::instance()->invalidateSceneIcon(); sl->setDirtyFlag(true); } } m_application->getCurrentLevel()->notifyLevelChange(); }
void execute() { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int row = TApp::instance()->getCurrentFrame()->getFrame(); int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); const TXshCell &cell = xsh->getCell(row, col); if (cell.isEmpty()) return; for (++row; xsh->getCell(row, col) == cell; ++row) ; if (!xsh->getCell(row, col).isEmpty()) TApp::instance()->getCurrentFrame()->setFrame(row); }
bool changeFrameSkippingHolds(QKeyEvent *e) { if ((e->modifiers() & Qt::ShiftModifier) == 0 || e->key() != Qt::Key_Down && e->key() != Qt::Key_Up) return false; TApp *app = TApp::instance(); TFrameHandle *fh = app->getCurrentFrame(); if (!fh->isEditingScene()) return false; int row = fh->getFrame(); int col = app->getCurrentColumn()->getColumnIndex(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (e->key() == Qt::Key_Down) { if (cell.isEmpty()) { int r0, r1; if (xsh->getCellRange(col, r0, r1)) { while (row <= r1 && xsh->getCell(row, col).isEmpty()) row++; if (xsh->getCell(row, col).isEmpty()) return false; } else return false; } else { while (xsh->getCell(row, col) == cell) row++; } } else { // Key_Up while (row >= 0 && xsh->getCell(row, col) == cell) row--; if (row < 0) return false; cell = xsh->getCell(row, col); while (row > 0 && xsh->getCell(row - 1, col) == cell) row--; } fh->setFrame(row); return true; }
ClearColumnCellsUndo(int col) : m_col(col), m_r0(0) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(col, r0, r1); m_r0 = r0; if (r0 > r1) return; for (int r = r0; r <= r1; r++) { m_oldFrames.push_back(xsh->getCell(r, col)); } }
void PaletteViewerPanel::onCurrentButtonToggled(bool isCurrent) { if (isActive() == isCurrent) return; TApp *app = TApp::instance(); TPaletteHandle *ph = app->getPaletteController()->getCurrentLevelPalette(); // Se sono sulla palette del livello corrente e le palette e' vuota non // consento di bloccare il pannello. if (isActive() && !ph->getPalette()) { m_isCurrentButton->setPressed(true); return; } setActive(isCurrent); m_paletteViewer->enableSaveAction(isCurrent); // Cambio il livello corrente if (isCurrent) { std::set<TXshSimpleLevel *> levels; TXsheet *xsheet = app->getCurrentXsheet()->getXsheet(); int row, column; findPaletteLevels(levels, row, column, m_paletteHandle->getPalette(), xsheet); // Se non trovo livelli riferiti alla palette setto il palette viewer alla // palette del livello corrente. if (levels.empty()) { m_paletteViewer->setPaletteHandle(ph); update(); return; } TXshSimpleLevel *level = *levels.begin(); // Se sto editando l'xsheet devo settare come corrente anche la colonna e il // frame. if (app->getCurrentFrame()->isEditingScene()) { int currentColumn = app->getCurrentColumn()->getColumnIndex(); if (currentColumn != column) app->getCurrentColumn()->setColumnIndex(column); int currentRow = app->getCurrentFrame()->getFrameIndex(); TXshCell cell = xsheet->getCell(currentRow, column); if (cell.isEmpty() || cell.getSimpleLevel() != level) app->getCurrentFrame()->setFrameIndex(row); TCellSelection *selection = dynamic_cast<TCellSelection *>( app->getCurrentSelection()->getSelection()); if (selection) selection->selectNone(); } app->getCurrentLevel()->setLevel(level); m_paletteViewer->setPaletteHandle(ph); } else { m_paletteHandle->setPalette(ph->getPalette()); m_paletteViewer->setPaletteHandle(m_paletteHandle); } update(); }
void ShiftTraceTool::drawControlRect() { if (m_ghostIndex < 0 || m_ghostIndex > 1) return; int row = m_row[m_ghostIndex]; if (row < 0) return; int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; TImageP img = cell.getImage(false); if (!img) return; TRectD box; if (TRasterImageP ri = img) { TRasterP ras = ri->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ri->getSubsampling(); } else if (TToonzImageP ti = img) { TRasterP ras = ti->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ti->getSubsampling(); } else if (TVectorImageP vi = img) { box = vi->getBBox(); } else { return; } glPushMatrix(); tglMultMatrix(getGhostAff()); TPixel32 color; color = m_highlightedGadget == TranslateGadget ? TPixel32(200, 100, 100) : TPixel32(120, 120, 120); tglColor(color); glBegin(GL_LINE_STRIP); glVertex2d(box.x0, box.y0); glVertex2d(box.x1, box.y0); glVertex2d(box.x1, box.y1); glVertex2d(box.x0, box.y1); glVertex2d(box.x0, box.y0); glEnd(); color = m_highlightedGadget == 2000 ? TPixel32(200, 100, 100) : TPixel32::White; double r = 4 * sqrt(tglGetPixelSize2()); drawDot(box.getP00(), r, color); drawDot(box.getP01(), r, color); drawDot(box.getP10(), r, color); drawDot(box.getP11(), r, color); if (m_curveStatus == NoCurve) { color = m_highlightedGadget == 2001 ? TPixel32(200, 100, 100) : TPixel32::White; TPointD c = m_center[m_ghostIndex]; drawDot(c, r, color); } glPopMatrix(); }
void execute() { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int row = TApp::instance()->getCurrentFrame()->getFrame(); int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; for (--row; row >= 0 && xsh->getCell(row, col) == cell; --row) // Get *last* cell in previous uniform ; // cell block if (row >= 0 && !xsh->getCell(row, col).isEmpty()) { cell = xsh->getCell(row, col); while (row > 0 && xsh->getCell(row - 1, col) == cell) // Get *first* cell in current uniform --row; // cell block TApp::instance()->getCurrentFrame()->setFrame(row); } }
ResequenceUndo(int col, int count) : m_index(col), m_r0(0), m_newFramesCount(count) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(col, r0, r1); m_r0 = r0; assert(r0 <= r1); if (r0 > r1) return; for (int r = r0; r <= r1; r++) { TXshCell cell = xsh->getCell(r, col); assert(cell.isEmpty() || cell.m_level->getChildLevel()); m_oldFrames.push_back(cell.m_frameId); } }
void redo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(m_index, r0, r1); assert(r0 <= r1); if (r0 > r1) return; TXshCell cell = xsh->getCell(r0, m_index); assert(!cell.isEmpty()); assert(cell.m_level->getChildLevel()); xsh->clearCells(r0, m_index, r1 - r0 + 1); for (int i = 0; i < m_newFramesCount; i++) { cell.m_frameId = TFrameId(i + 1); xsh->setCell(m_r0 + i, m_index, cell); } TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
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 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 MeshifyPopup::acquirePreview() { m_viewer->clear(); // Assign preview input to the viewer bool enabled = false; ::xshPos(m_r, m_c); m_cell = TApp::instance()->getCurrentXsheet()->getXsheet()->getCell(m_r, m_c); // Redirect mesh case to texture TXshSimpleLevel *sl = m_cell.getSimpleLevel(); if (sl && sl->getType() == MESH_XSHLEVEL) { // Mesh image case TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TStageObject *meshObj = xsh->getStageObject(TStageObjectId::ColumnId(m_c)); const TStageObjectId &childId = ::firstChildLevelColumn(*xsh, *meshObj); if (childId.isColumn()) // Retrieved the associated texture cell - redirect acquisition there m_cell = xsh->getCell(m_r, childId.getIndex()); } if ((sl = m_cell.getSimpleLevel())) { // Standard image case m_viewer->m_img = sl->getFullsampledFrame(m_cell.getFrameId(), ImageManager::dontPutInCache); enabled = true; } else if (TXshChildLevel *cl = m_cell.getChildLevel()) { // Sub-xsheet case TXsheet *xsh = cl->getXsheet(); int row = m_cell.getFrameId().getNumber() - 1; m_viewer->m_xsh = xsh, m_viewer->m_row = row; enabled = true; } m_okBtn->setEnabled(enabled); // Update the corresponding processed image in the viewer updateMeshPreview(); }
void undo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(m_index, r0, r1); assert(r0 <= r1); if (r0 > r1) return; TXshCell cell = xsh->getCell(r0, m_index); assert(!cell.isEmpty()); assert(cell.m_level->getChildLevel()); xsh->clearCells(r0, m_index, r1 - r0 + 1); for (int i = 0; i < (int)m_oldFrames.size(); i++) { TFrameId fid = m_oldFrames[i]; if (fid != TFrameId::EMPTY_FRAME) { cell.m_frameId = fid; xsh->setCell(m_r0 + i, m_index, cell); } } TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
/*! Notify change of current image: update icon and notify level change. If current object is a spline commit spline chenged. If current mode is EditingLevel touch current frame. */ void TTool::notifyImageChanged() { onImageChanged(); if (!m_application) return; m_application->getCurrentScene()->setDirtyFlag(true); if (m_application->getCurrentFrame()->isEditingLevel()) { TXshLevel *xl = m_application->getCurrentLevel()->getLevel(); if (!xl) return; TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl) return; TFrameId fid = m_application->getCurrentFrame()->getFid(); sl->touchFrame(fid); // sl->setDirtyFlag(true); IconGenerator::instance()->invalidate(sl, fid); IconGenerator::instance()->invalidateSceneIcon(); } else { TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet(); if (!xsh) return; TObjectHandle *currentObject = m_application->getCurrentObject(); if (currentObject->isSpline()) { m_application->getCurrentObject()->commitSplineChanges(); TStageObject *pegbar = xsh->getStageObject(currentObject->getObjectId()); IconGenerator::instance()->invalidate(pegbar->getSpline()); } else { int row = m_application->getCurrentFrame()->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); if (col < 0) return; TXshCell cell = xsh->getCell(row, col); TXshSimpleLevel *sl = cell.getSimpleLevel(); if (sl) { IconGenerator::instance()->invalidate(sl, cell.m_frameId); sl->touchFrame(cell.m_frameId); IconGenerator::instance()->invalidateSceneIcon(); } } } m_application->getCurrentLevel()->notifyLevelChange(); }
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(); } }
void ShiftTraceTool::updateData() { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int row = TApp::instance()->getCurrentFrame()->getFrame(); int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXshCell cell = xsh->getCell(row, col); m_box = TRectD(); for (int i = 0; i < 2; i++) m_row[i] = -1; m_dpiAff = TAffine(); // we must find the prev (m_row[0]) and next (m_row[1]) reference images // (either might not exist) // see also stage.cpp, StageBuilder::addCellWithOnionSkin if (cell.isEmpty()) { // current cell is empty. search for the prev ref img int r = row - 1; while (r >= 0 && xsh->getCell(r, col).getSimpleLevel() == 0) r--; if (r >= 0) m_row[0] = r; // else prev drawing doesn't exist : nothing to do } else { // current cell is not empty // search for prev ref img TXshSimpleLevel *sl = cell.getSimpleLevel(); int r = row - 1; if (r >= 0) { TXshCell otherCell = xsh->getCell(r, col); if (otherCell.getSimpleLevel() == sl) { // find the span start while (r - 1 >= 0 && xsh->getCell(r - 1, col) == otherCell) r--; m_row[0] = r; } } // search for next ref img r = row + 1; while (xsh->getCell(r, col) == cell) r++; // first cell after the current span has the same level if (xsh->getCell(r, col).getSimpleLevel() == sl) m_row[1] = r; } updateBox(); }
void AntialiasPopup::setCurrentSampleRaster() { TRasterP sampleRas; m_startRas = TRasterP(); TSelection *selection = TApp::instance()->getCurrentSelection()->getSelection(); TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection); TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection); TImageP image; if (cellSelection) { TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex()); TImageP aux = cell.getImage(true); if (aux) image = aux->cloneImage(); } else if (filmstripSelection) { TApp *app = TApp::instance(); TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { TImageP imageAux = simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true); if (imageAux) image = imageAux->cloneImage(); } } if (!image || !(sampleRas = image->raster())) { m_viewer->setImage(TImageP()); m_viewer->update(); m_okBtn->setEnabled(false); return; } m_okBtn->setEnabled(true); m_startRas = sampleRas->clone(); onChange(m_startRas, sampleRas, m_thresholdField->getValue(), m_softnessField->getValue()); m_viewer->setImage(image); m_viewer->update(); }
void AdjustLevelsPopup::acquireRaster() { //Retrieve current selection TApp *app = TApp::instance(); TSelection *selection = app->getCurrentSelection()->getSelection(); TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection); TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection); //Retrieve the input raster m_inputRas = TRasterP(); if (cellSelection) { TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex()); TRasterImageP rasImage = cell.getImage(true); if (rasImage && rasImage->getRaster()) m_inputRas = rasImage->getRaster(); } else if (filmstripSelection) { TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true); if (rasImage && rasImage->getRaster()) m_inputRas = rasImage->getRaster(); } } if (m_inputRas) { m_threshold = m_inputRas->getLx() * m_inputRas->getLy() * m_thresholdD; m_okBtn->setEnabled(true); } else { m_inputRas = TRasterP(); m_okBtn->setEnabled(false); } //Build histograms m_histogram->setRaster(m_inputRas); //Update the corresponding processed image in the viewer updateProcessedImage(); }
void BinarizePopup::fetchSample() { TApp *app = TApp::instance(); TImageP img; if (app->getCurrentFrame()->isEditingLevel()) { TXshLevel *xshLevel = app->getCurrentLevel()->getLevel(); if (xshLevel && xshLevel->getSimpleLevel()) { TXshSimpleLevel *sl = xshLevel->getSimpleLevel(); img = sl->getFrame(app->getCurrentFrame()->getFid(), false); } } else { TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrame(), app->getCurrentColumn()->getColumnIndex()); img = cell.getImage(false); } TRasterImageP ri = img; if (ri) { setSample(ri->getRaster()); } else { setSample(TRasterP()); } }
void BrightnessAndContrastPopup::setCurrentSampleRaster() { TRasterP sampleRas; m_startRas = TRasterP(); TSelection *selection = TApp::instance()->getCurrentSelection()->getSelection(); TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection); TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection); if (cellSelection) { TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex()); TRasterImageP rasImage = cell.getImage(true); if (rasImage && rasImage->getRaster()) sampleRas = rasImage->getRaster()->clone(); } else if (filmstripSelection) { TApp *app = TApp::instance(); TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel(); if (simpleLevel) { TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true); if (rasImage && rasImage->getRaster()) sampleRas = rasImage->getRaster()->clone(); } } if (!sampleRas) { m_viewer->raster() = TRasterP(); m_viewer->update(); m_okBtn->setEnabled(false); return; } m_okBtn->setEnabled(true); m_startRas = sampleRas->clone(); onChange(m_startRas, sampleRas, m_contrastField->getValue(), m_brightnessField->getValue()); m_viewer->raster() = sampleRas; m_viewer->update(); }
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(); }
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 ComboViewerPanel::changeWindowTitle() { TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); if (!scene) return; int frame = app->getCurrentFrame()->getFrame(); // put the titlebar texts in this string QString name; // if the frame type is "scene editing" if (app->getCurrentFrame()->isEditingScene()) { QString sceneName = QString::fromStdWString(scene->getSceneName()); if (sceneName.isEmpty()) sceneName = tr("Untitled"); if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString(" *"); name = tr("Scene: ") + sceneName; if (frame >= 0) name = name + tr(" :: Frame: ") + tr(std::to_string(frame + 1).c_str()); int col = app->getCurrentColumn()->getColumnIndex(); if (col < 0) { setWindowTitle(name); return; } TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(frame, col); if (cell.isEmpty()) { setWindowTitle(name); return; } assert(cell.m_level.getPointer()); TFilePath fp(cell.m_level->getName()); QString imageName = QString::fromStdWString(fp.withFrame(cell.m_frameId).getWideString()); name = name + tr(" :: Level: ") + imageName; if (m_sceneViewer->isPreviewEnabled()) { name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } // If the current level exists and some option is set in the preference, // set the zoom value to the current level's dpi else if (Preferences::instance() ->isActualPixelViewOnSceneEditingModeEnabled() && TApp::instance()->getCurrentLevel()->getSimpleLevel() && !CleanupPreviewCheck::instance() ->isEnabled() // cleanup preview must be OFF && !CameraTestCheck::instance() ->isEnabled()) // camera test mode must be OFF neither { name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } } // if the frame type is "level editing" else { TXshLevel *level = app->getCurrentLevel()->getLevel(); if (level) { TFilePath fp(level->getName()); QString imageName = QString::fromStdWString( fp.withFrame(app->getCurrentFrame()->getFid()).getWideString()); name = name + tr("Level: ") + imageName; name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } } setWindowTitle(name); }
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 LevelCreatePopup::apply() { TApp *app = TApp::instance(); int row = app->getCurrentFrame()->getFrame(); int col = app->getCurrentColumn()->getColumnIndex(); int i, j; ToonzScene *scene = app->getCurrentScene()->getScene(); TXsheet *xsh = scene->getXsheet(); bool validColumn = true; if (xsh->getColumn(col)) validColumn = xsh->getColumn(col)->getColumnType() == TXshColumn::eLevelType; int from = (int)m_fromFld->getValue(); int to = (int)m_toFld->getValue(); int inc = (int)m_incFld->getValue(); int step = (int)m_stepFld->getValue(); double w = m_widthFld->getValue(); double h = m_heightFld->getValue(); double dpi = m_dpiFld->getValue(); int xres = std::max(tround(w * dpi), 1); int yres = std::max(tround(h * dpi), 1); int lType = getLevelType(); std::wstring levelName = m_nameFld->text().toStdWString(); // tolgo i blanks prima e dopo i = levelName.find_first_not_of(L' '); if (i == (int)std::wstring::npos) levelName = L""; else { int j = levelName.find_last_not_of(L' '); assert(j != (int)std::wstring::npos); levelName = levelName.substr(i, j - i + 1); } if (levelName.empty()) { error(tr("No level name specified: please choose a valid level name")); return false; } if (from > to) { error(tr("Invalid frame range")); return false; } if (inc <= 0) { error(tr("Invalid increment value")); return false; } if (step <= 0) { error(tr("Invalid step value")); return false; } int numFrames = step * (((to - from) / inc) + 1); if (scene->getLevelSet()->getLevel(levelName)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } TFilePath parentDir(m_pathFld->getPath().toStdWString()); TFilePath fp = scene->getDefaultLevelPath(lType, levelName).withParentDir(parentDir); TFilePath actualFp = scene->decodeFilePath(fp); if (TSystem::doesExistFileOrLevel(actualFp)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } parentDir = scene->decodeFilePath(parentDir); if (!TFileStatus(parentDir).doesExist()) { QString question; /*question = "Folder " +toQString(parentDir) + " doesn't exist.\nDo you want to create it?";*/ question = tr("Folder %1 doesn't exist.\nDo you want to create it?") .arg(toQString(parentDir)); int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) return false; try { TSystem::mkDir(parentDir); DvDirModel::instance()->refreshFolder(parentDir.getParentDir()); } catch (...) { error(tr("Unable to create") + toQString(parentDir)); return false; } } TXshLevel *level = scene->createNewLevel(lType, levelName, TDimension(), 0, fp); TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level); assert(sl); sl->setPath(fp, true); if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->getProperties()->setDpiPolicy(LevelProperties::DP_ImageDpi); sl->getProperties()->setDpi(dpi); sl->getProperties()->setImageDpi(TPointD(dpi, dpi)); sl->getProperties()->setImageRes(TDimension(xres, yres)); } /*-- これからLevelを配置しようとしているセルが空いているかどうかのチェック * --*/ bool areColumnsShifted = false; TXshCell cell = xsh->getCell(row, col); bool isInRange = true; for (i = row; i < row + numFrames; i++) { if (!cell.isEmpty()) { isInRange = false; break; } cell = xsh->getCell(i, col); } if (!validColumn) { isInRange = false; } /*-- 別のLevelに占有されていた場合、Columnを1つ右に移動 --*/ if (!isInRange) { col += 1; TApp::instance()->getCurrentColumn()->setColumnIndex(col); areColumnsShifted = true; xsh->insertColumn(col); } CreateLevelUndo *undo = new CreateLevelUndo(row, col, numFrames, step, areColumnsShifted); TUndoManager::manager()->add(undo); for (i = from; i <= to; i += inc) { TFrameId fid(i); TXshCell cell(sl, fid); if (lType == PLI_XSHLEVEL) sl->setFrame(fid, new TVectorImage()); else if (lType == TZP_XSHLEVEL) { TRasterCM32P raster(xres, yres); raster->fill(TPixelCM32()); TToonzImageP ti(raster, TRect()); ti->setDpi(dpi, dpi); sl->setFrame(fid, ti); ti->setSavebox(TRect(0, 0, xres - 1, yres - 1)); } else if (lType == OVL_XSHLEVEL) { TRaster32P raster(xres, yres); raster->clear(); TRasterImageP ri(raster); ri->setDpi(dpi, dpi); sl->setFrame(fid, ri); } for (j = 0; j < step; j++) xsh->setCell(row++, col, cell); } if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->save(fp); DvDirModel::instance()->refreshFolder(fp.getParentDir()); } undo->onAdd(sl); app->getCurrentScene()->notifySceneChanged(); app->getCurrentScene()->notifyCastChange(); app->getCurrentXsheet()->notifyXsheetChanged(); // Cambia l'immagine corrente ma non cambiano ne' il frame ne' la colonna // corrente // (entrambi notificano il cambiamento dell'immagine al tool). // devo verfificare che sia settato il tool giusto. app->getCurrentTool()->onImageChanged( (TImage::Type)app->getCurrentImageType()); return true; }
void SkeletonTool::draw() { // parent object reference system //glColor3d(1,0,0); //tglDrawRect(0,0,100,100); if (m_label != "") ToolUtils::drawBalloon(m_labelPos, m_label, TPixel32::Red, TPoint(20, -20), false); bool ikEnabled = m_mode.getValue() == INVERSE_KINEMATICS; assert(glGetError() == GL_NO_ERROR); // l'xsheet, oggetto (e relativo placement), frame corrente TTool::Application *app = TTool::getApplication(); TXsheet *xsh = getXsheet(); assert(xsh); TStageObjectId objId = app->getCurrentObject()->getObjectId(); // se l'oggetto corrente non e' una colonna non disegno nulla if (!objId.isColumn()) return; TStageObject *pegbar = xsh->getStageObject(objId); int col = objId.getIndex(); int frame = app->getCurrentFrame()->getFrame(); if (m_currentFrame != frame) m_temporaryPinnedColumns.clear(); TAffine aff = getMatrix(); // puo' suggere che il placement degeneri (es.: c'e' uno h-scale = 0%) if (fabs(aff.det()) < 0.00001) return; // m_unit = getPixelSize() * sqrt(fabs(aff.det())); if (!ikEnabled) drawLevelBoundingBox(frame, col); glPushMatrix(); tglMultMatrix(aff.inv()); // camera stand reference system //glColor3d(0,1,0); //tglDrawRect(0,0,100,100); bool changingParent = dynamic_cast<ParentChangeTool *>(m_dragTool) != 0; // !changingParent && if (m_mode.getValue() == BUILD_SKELETON && !xsh->getStageObjectParent(objId).isColumn()) { if (!changingParent) drawHooks(); } Skeleton skeleton; buildSkeleton(skeleton, col); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); drawSkeleton(skeleton, frame); glDisable(GL_BLEND); TXshCell cell = xsh->getCell(frame, objId.getIndex()); Skeleton::Bone *rootBone = skeleton.getRootBone(); for (int i = 0; i < skeleton.getBoneCount(); i++) { Skeleton::Bone *bone = skeleton.getBone(i); TStageObjectId currentId = bone->getStageObject()->getId(); bool isCurrent = (currentId == objId); TPointD pos = bone->getCenter(); if (isCurrent && m_mode.getValue() != BUILD_SKELETON) { drawDrawingBrowser(cell, pos); } bool isActiveChain = bone->isSelected(); glColor3d(0, 1, 0); if (ikEnabled) { drawIKJoint(bone); } else { TPointD pos = bone->getCenter(); if (isCurrent && m_mode.getValue() == ANIMATE) { drawMainGadget(pos); } } } m_currentFrame = frame; if (m_dragTool) m_dragTool->draw(); glPopMatrix(); }