Beispiel #1
0
void RGBPickerTool::pickRect() {
  TImageP image = TImageP(getImage(false));

  TTool::Application *app = TTool::getApplication();
  TPaletteHandle *ph      = app->getPaletteController()->getCurrentPalette();
  int styleId             = ph->getStyleIndex();
  TPalette *palette       = ph->getPalette();
  TRectD area             = m_selectingRect;
  if (!palette) return;
  if (m_selectingRect.x0 > m_selectingRect.x1) {
    area.x1 = m_selectingRect.x0;
    area.x0 = m_selectingRect.x1;
  }
  if (m_selectingRect.y0 > m_selectingRect.y1) {
    area.y1 = m_selectingRect.y0;
    area.y0 = m_selectingRect.y1;
  }
  m_selectingRect.empty();
  if (area.getLx() <= 1 || area.getLy() <= 1) return;
  StylePicker picker(image, palette);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->bindFBO();

  m_currentValue = picker.pickColor(area);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->releaseFBO();
}
Beispiel #2
0
void RGBPickerTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
  TTool::Application *app   = TTool::getApplication();
  TPaletteHandle *pltHandle = app->getPaletteController()->getCurrentPalette();
  m_currentStyleId          = pltHandle->getStyleIndex();
  if (m_currentStyleId == 0) return;

  TColorStyle *colorStyle = pltHandle->getStyle();

  if (colorStyle) m_oldValue = colorStyle->getMainColor();

  if (m_pickType.getValue() == RECT_PICK) {
    m_selectingRect.x0 = e.m_pos.x;
    m_selectingRect.y0 = e.m_pos.y;
    m_selectingRect.x1 = e.m_pos.x;
    m_selectingRect.y1 = e.m_pos.y;
    m_drawingRect.x0   = pos.x;
    m_drawingRect.y0   = pos.y;
    m_drawingRect.x1   = pos.x;
    m_drawingRect.y1   = pos.y;
    invalidate();
    return;
  } else if (m_pickType.getValue() == FREEHAND_PICK) {
    startFreehand(pos, convert(e.m_pos));
    return;
  } else if (m_pickType.getValue() == POLYLINE_PICK) {
    addPointPolyline(pos, convert(e.m_pos));
    return;
  } else {
    pick(e.m_pos);
  }
}
void TStyleSelection::pasteStylesValue()
{
	if (!m_palette || m_pageIndex < 0)
		return;
	if (m_pageIndex == 0 && isSelected(m_palette, 0, 0)) {
		MsgBox(CRITICAL, "Can't modify color #0");
		return;
	}

	TPalette::Page *page = m_palette->getPage(m_pageIndex);
	assert(page);
	const StyleData *data = dynamic_cast<const StyleData *>(QApplication::clipboard()->mimeData());
	if (!data)
		return;
	int i = 0;
	UndoPasteValues *undo = new UndoPasteValues(m_palette);
	std::set<int>::iterator it;
	for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end() && i < data->getStyleCount(); ++it, i++) {
		int styleId = page->getStyleId(*it);
		undo->addItem(styleId, m_palette->getStyle(styleId), data->getStyle(i));
		m_palette->setStyle(styleId, data->getStyle(i)->clone());
	}
	TUndoManager::manager()->add(undo);

	TPaletteHandle *ph = TApp::instance()->getCurrentPalette();
	ph->notifyColorStyleChanged();
	ph->updateColor();
}
Beispiel #4
0
void TApp::onLevelColorStyleSwitched() {
  TPaletteHandle *ph = m_paletteController->getCurrentLevelPalette();
  assert(ph);

  if (ToonzCheck::instance()->setColorIndex(ph->getStyleIndex())) {
    ToonzCheck *tc = ToonzCheck::instance();
    int mask       = tc->getChecks();

    if (mask & ToonzCheck::eInk || mask & ToonzCheck::ePaint) {
      IconGenerator::Settings s;
      s.m_blackBgCheck      = mask & ToonzCheck::eBlackBg;
      s.m_transparencyCheck = mask & ToonzCheck::eTransparency;
      s.m_inksOnly          = mask & ToonzCheck::eInksOnly;
      s.m_inkIndex   = mask & ToonzCheck::eInk ? tc->getColorIndex() : -1;
      s.m_paintIndex = mask & ToonzCheck::ePaint ? tc->getColorIndex() : -1;

      IconGenerator::instance()->setSettings(s);

      TXshLevel *sl = m_currentLevel->getLevel();
      if (!sl) return;

      std::vector<TFrameId> fids;
      sl->getFids(fids);

      for (int i = 0; i < (int)fids.size(); i++)
        IconGenerator::instance()->invalidate(sl, fids[i]);

      m_currentLevel->notifyLevelViewChange();
    }

    /*-- 表示オプションが切り替わっただけなので、DirtyFlagを立てない --*/
    m_currentScene->notifySceneChanged(false);
  }
}
Beispiel #5
0
/*! notify the color picked by rgb picker to palette controller
*/
void ImageViewer::setPickedColorToStyleEditor(const TPixel32 &color) {
  // do not modify the style #0
  TPaletteHandle *ph =
      TApp::instance()->getPaletteController()->getCurrentPalette();
  if (ph->getStyleIndex() == 0) return;

  TApp::instance()->getPaletteController()->setColorSample(color);
}
Beispiel #6
0
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 TStyleSelection::toggleLink()
{
	if (!m_palette || m_pageIndex < 0)
		return;
	int n = m_styleIndicesInPage.size();
	if (n <= 0)
		return;

	bool somethingHasBeenLinked = false;

	bool currentStyleIsInSelection = false;
	TApp *app = TApp::instance();
	TPaletteHandle *ph = app->getCurrentPalette();

	TPalette::Page *page = m_palette->getPage(m_pageIndex);
	assert(page);

	for (std::set<int>::iterator it = m_styleIndicesInPage.begin();
		 it != m_styleIndicesInPage.end(); ++it) {
		TColorStyle *cs = page->getStyle(*it);
		assert(cs);
		wstring name = cs->getGlobalName();
		if (name != L"" && (name[0] == L'-' || name[0] == L'+')) {
			name[0] = name[0] == L'-' ? L'+' : L'-';
			cs->setGlobalName(name);
			if (name[0] == L'+')
				somethingHasBeenLinked = true;
		}

		if (*it == m_palette->getPage(m_pageIndex)->search(ph->getStyleIndex()))
			currentStyleIsInSelection = true;
	}
	if (somethingHasBeenLinked)
		StudioPalette::instance()->updateLinkedColors(m_palette.getPointer());

	ph->notifyPaletteChanged();

	if (currentStyleIsInSelection)
		ph->notifyColorStyleSwitched();

	// DA FARE: e' giusto mettere la nofica del dirty flag a current scene
	// o e' meglio farlo al livello corrente!?
	app->getCurrentScene()->setDirtyFlag(true);
	//  extern void setPaletteDirtyFlag();
	//  setPaletteDirtyFlag();
}
Beispiel #8
0
void setCurrentColorWithUndo(const TPixel32 &color) {
  TTool::Application *app = TTool::getApplication();
  TPaletteHandle *ph      = app->getPaletteController()->getCurrentPalette();
  int styleId             = ph->getStyleIndex();
  TPalette *palette       = ph->getPalette();
  TXshSimpleLevel *level  = app->getCurrentLevel()->getSimpleLevel();
  if (palette)
    TUndoManager::manager()->add(
        new UndoPickRGBM(palette, styleId, color, level));

  setCurrentColor(color);

  if (level) {
    std::vector<TFrameId> fids;
    level->getFids(fids);
    invalidateIcons(level, fids);
  }
}
Beispiel #9
0
void RGBPickerTool::onImageChanged() {
  if (m_currentStyleId != 0 && m_makePick &&
      (m_pickType.getValue() == POLYLINE_PICK ||
       m_pickType.getValue() == RECT_PICK)) {
    TTool::Application *app = TTool::getApplication();
    TPaletteHandle *ph      = app->getPaletteController()->getCurrentPalette();
    int styleId             = ph->getStyleIndex();
    TPalette *palette       = ph->getPalette();
    TXshSimpleLevel *level  = app->getCurrentLevel()->getSimpleLevel();
    if (palette)
      TUndoManager::manager()->add(
          new UndoPickRGBM(palette, styleId, m_currentValue, level));
    setCurrentColor(m_currentValue);
    if (level) {
      std::vector<TFrameId> fids;
      level->getFids(fids);
      invalidateIcons(level, fids);
    }
  }
  m_makePick = false;
}
Beispiel #10
0
void setCurrentColor(const TPixel32 &color) {
  PaletteController *controller =
      TTool::getApplication()->getPaletteController();
  TPaletteHandle *ph = controller->getCurrentPalette();

  TColorStyle *cs = ph->getStyle();
  if (!cs) return;

  if (controller->isColorAutoApplyEnabled()) {
    TCleanupStyle *ccs = dynamic_cast<TCleanupStyle *>(cs);
    if (ccs) ccs->setCanUpdate(true);

    int index = ph->getStyleParamIndex();
    if (0 <= index && index < cs->getColorParamCount())
      cs->setColorParamValue(index, color);
    else
      cs->setMainColor(color);

    cs->invalidateIcon();
    ph->notifyColorStyleChanged();

    // per le palette animate
    int styleIndex    = ph->getStyleIndex();
    TPalette *palette = ph->getPalette();
    if (palette && palette->isKeyframe(styleIndex, palette->getFrame()))
      palette->setKeyframe(styleIndex, palette->getFrame());

    if (ccs) ccs->setCanUpdate(false);
  } else
    controller->setColorSample(color);
}
Beispiel #11
0
void RGBPickerTool::pick(TPoint pos) {
  TImageP image = TImageP(getImage(false));

  TTool::Application *app = TTool::getApplication();
  TPaletteHandle *ph      = app->getPaletteController()->getCurrentPalette();
  int styleId             = ph->getStyleIndex();
  TPalette *palette       = ph->getPalette();
  if (!palette) return;

  TRectD area = TRectD(pos.x - 1, pos.y - 1, pos.x + 1, pos.y + 1);
  StylePicker picker(image, palette);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->bindFBO();

  m_currentValue = picker.pickColor(area);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->releaseFBO();

  TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel();
  UndoPickRGBM *cmd = new UndoPickRGBM(palette, styleId, m_currentValue, level);
  TUndoManager::manager()->add(cmd);
  cmd->redo();
  /*
setCurrentColor(m_currentValue);
if(level)
{
vector<TFrameId> fids;
level->getFids(fids);
invalidateIcons(level,fids);
}
*/
}
Beispiel #12
0
void RGBPickerTool::pickStroke() {
  TImageP image = TImageP(getImage(false));

  TTool::Application *app = TTool::getApplication();
  TPaletteHandle *ph      = app->getPaletteController()->getCurrentPalette();
  int styleId             = ph->getStyleIndex();
  TPalette *palette       = ph->getPalette();
  if (!palette) return;

  StylePicker picker(image, palette);
  TStroke *stroke = new TStroke(*m_stroke);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->bindFBO();

  m_currentValue = picker.pickColor(stroke);

  // iwsw commented out temporarily
  // if (m_viewer->get3DLutUtil() &&
  // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())
  //	m_viewer->get3DLutUtil()->releaseFBO();

  if (!(m_pickType.getValue() == POLYLINE_PICK)) {
    TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel();
    TUndoManager::manager()->add(
        new UndoPickRGBM(palette, styleId, m_currentValue, level));
    setCurrentColor(m_currentValue);
    if (level) {
      std::vector<TFrameId> fids;
      level->getFids(fids);
      invalidateIcons(level, fids);
    }
  }
}
Beispiel #13
0
void mergeCmapped(int column, int mColumn, const QString &fullpath, bool isRedo)
{
	static int MergeCmappedSessionId = 0;
	MergeCmappedSessionId++;

	TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
	int start, end;
	int mStart, mEnd;
	xsh->getCellRange(column, start, end);
	xsh->getCellRange(mColumn, mStart, mEnd);

	if (start > end)
		return;
	vector<TXshCell> cell(max(end, mEnd) - min(start, mStart) + 1);
	vector<TXshCell> mCell(cell.size());

	xsh->getCells(min(start, mStart), column, cell.size(), &(cell[0]));

	if (mColumn != -1)
		xsh->getCells(min(start, mStart), mColumn, cell.size(), &(mCell[0]));

	TXshColumn *col = xsh->getColumn(column);
	TXshColumn *mcol = xsh->getColumn(mColumn);

	vector<MergeCmappedPair> matchingLevels;

	std::map<MergedPair, TFrameId> computedMergedMap;

	TXshSimpleLevel *level = 0, *mLevel = 0;
	TXshLevel *xl;

	std::map<TFrameId, QString> images;
	double dpix = 0, dpiy = 0;
	for (int i = 0; i < (int)cell.size(); i++) {
		if (!cell[i].isEmpty() && dpix == 0)
			((TToonzImageP)(cell[i].getImage(false)))->getDpi(dpix, dpiy);

		if (!level) {
			level = cell[i].getSimpleLevel();
			xl = cell[i].m_level.getPointer();
		}
		if (!mLevel)
			mLevel = mCell[i].getSimpleLevel();
	}

	if (!level || !mLevel)
		return;

	TFilePath fp(fullpath.toStdString());

	TXshLevel *txl = level->getScene()->createNewLevel(level->getType(), fp.getWideName(), level->getResolution());
	TXshSimpleLevel *newLevel = txl->getSimpleLevel();
	newLevel->setPalette(level->getPalette());
	newLevel->clonePropertiesFrom(level);
	newLevel->setPath(fp);

	TApp::instance()->getCurrentScene()->notifySceneChanged();
	TApp::instance()->getCurrentScene()->notifyCastChange();
	TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();

	int count = 0;
	for (int i = 0; i < (int)cell.size(); i++) {
		if (cell[i].isEmpty() && mCell[i].isEmpty())
			continue;

		TAffine imgAff, matchAff;

		getColumnPlacement(imgAff, xsh, min(start, mStart) + i, column, false);
		getColumnPlacement(matchAff, xsh, min(start, mStart) + i, mColumn, false);

		//std::map<TFrameId, TFrameId>::iterator it;
		MergedPair mp(cell[i].isEmpty() ? TFrameId() : cell[i].getFrameId(),
					  mCell[i].isEmpty() ? TFrameId() : mCell[i].getFrameId(),
					  imgAff.inv() * matchAff);

		std::map<MergedPair, TFrameId>::iterator computedMergedIt = computedMergedMap.find(mp);

		if (computedMergedIt != computedMergedMap.end()) {
			TXshCell newCell(newLevel, computedMergedIt->second);
			xsh->setCell(i, column, newCell);
			cell[i] = newCell;
			continue;
		}

		TFrameId newFid(++count); //level->getLastFid().getNumber()+1);
		TDimension dim = level->getResolution();
		TToonzImageP newImage;
		if (cell[i].isEmpty()) {
			newImage = TToonzImageP(TRasterCM32P(dim), TRect(0, 0, dim.lx - 1, dim.ly - 1));
			newImage->setDpi(dpix, dpiy);
		} else
			newImage = (TToonzImageP)(cell[i].getImage(false)->cloneImage());

		newImage->setPalette(level->getPalette());

		newLevel->setFrame(newFid, newImage);
		TXshCell newCell(newLevel, newFid);
		xsh->setCell(i, column, newCell);
		computedMergedMap[mp] = newCell.getFrameId();

		cell[i] = newCell;

		TImageP img = cell[i].getImage(true);
		TImageP match = mCell[i].getImage(true);
		TFrameId fid = cell[i].m_frameId;
		TFrameId mFid = mCell[i].m_frameId;

		if (!img || !match)
			continue;

		TToonzImageP timg = (TToonzImageP)img;
		TToonzImageP tmatch = (TToonzImageP)match;

		QString id = "MergeCmappedUndo" + QString::number(MergeCmappedSessionId) + "-" + QString::number(fid.getNumber());
		TImageCache::instance()->add(id, timg->clone());
		images[fid] = id;

		TAffine dpiAff = getDpiAffine(level, fid);
		TAffine mdpiAff = getDpiAffine(mLevel, mFid);
		matchingLevels.push_back(MergeCmappedPair(cell[i], imgAff * dpiAff, mCell[i], matchAff * mdpiAff));
	}

	if (!isRedo) {
		TPalette *plt = level->getPalette();

		TPaletteHandle *pltHandle = new TPaletteHandle();
		pltHandle->setPalette(plt);
		int styleCount = plt->getStyleCount();

		TUndoManager::manager()->add(new MergeCmappedUndo(txl, MergeCmappedSessionId,
														  column,
														  level, images,
														  mColumn,
														  plt));
	}

	removeLevel(xl);
	QApplication::setOverrideCursor(Qt::WaitCursor);
	mergeCmapped(matchingLevels);
	QApplication::restoreOverrideCursor();

	for (int i = 0; i < (int)cell.size(); i++) //the saveboxes must be updated
	{
		if (cell[i].isEmpty() || mCell[i].isEmpty())
			continue;

		if (!cell[i].getImage(false) || !mCell[i].getImage(false))
			continue;

		TXshSimpleLevel *sl = cell[i].getSimpleLevel();
		const TFrameId &fid = cell[i].m_frameId;

		ToolUtils::updateSaveBox(sl, fid);
		IconGenerator::instance()->invalidate(sl, fid);
		sl->setDirtyFlag(true);
	}

	newLevel->setDirtyFlag(true);
	TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}