Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
void tglDraw(const TVectorRenderData &rd, const TStroke *s)
{
	assert(s);
	if (!s)
		return;

	const TStroke &stroke = *s;

	// initialize information for aaliasing
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glEnable(GL_LINE_SMOOTH);

	// it's necessary to do line function of pixel size ?
	glLineWidth((float)1.0);

	assert(rd.m_palette);
	TStrokeProp *prop = stroke.getProp(/*rd.m_palette*/);
	/////questo codice stava dentro tstroke::getprop/////////
	TColorStyle *style = rd.m_palette->getStyle(stroke->getStyle() /*m_imp->m_styleId*/);
	if (!style->isStrokeStyle() || style->isEnabled() == false) {
		prop = 0;
	} else {
		if (!prop || style != prop->getColorStyle()) {
			stroke->setProp(style->makeStrokeProp(stroke));
			prop = stroke->getProp();
		}
	}
	///
	//---------------------
	if (prop)
		prop->draw(rd);
	//---------------------

	tglColor(TPixel32::White);

	glDisable(GL_BLEND);
	glDisable(GL_LINE_SMOOTH);
}
Ejemplo n.º 3
0
 UndoPickRGBM(TPalette *palette, int styleId, const TPixel32 newValue,
              const TXshSimpleLevelP &level)
     : m_palette(palette)
     , m_styleId(styleId)
     , m_newValue(newValue)
     , m_level(level)
     , m_colorAutoApplyEnabled(true) {
   PaletteController *controller =
       TTool::getApplication()->getPaletteController();
   m_colorAutoApplyEnabled = controller->isColorAutoApplyEnabled();
   m_styleParamIndex = controller->getCurrentPalette()->getStyleParamIndex();
   if (m_colorAutoApplyEnabled) {
     TColorStyle *cs = m_palette->getStyle(m_styleId);
     if (0 <= m_styleParamIndex &&
         m_styleParamIndex < cs->getColorParamCount())
       m_oldValue = cs->getColorParamValue(m_styleParamIndex);
     else
       m_oldValue = cs->getMainColor();
   } else {
     m_oldValue = controller->getColorSample();
   }
 }
Ejemplo n.º 4
0
void TStyleSelection::blendStyles() {
  if (!m_palette || m_pageIndex < 0) return;
  int n = m_styleIndicesInPage.size();
  if (n < 2) return;

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

  std::vector<TColorStyle *> styles;
  std::vector<std::pair<int, TColorStyle *>> oldStyles;
  for (std::set<int>::iterator it = m_styleIndicesInPage.begin();
       it != m_styleIndicesInPage.end(); ++it) {
    TColorStyle *cs = page->getStyle(*it);
    assert(cs);
    styles.push_back(cs);
    oldStyles.push_back(std::pair<int, TColorStyle *>(*it, cs->clone()));
  }
  assert(styles.size() >= 2);

  TPixel32 c0 = styles.front()->getMainColor();
  TPixel32 c1 = styles.back()->getMainColor();

  bool areAllStyleLincked = true;
  int i;
  for (i = 1; i < n - 1; i++) {
    QString gname = QString::fromStdWString(styles[i]->getGlobalName());
    if (!gname.isEmpty() && gname[0] != L'-') continue;
    areAllStyleLincked = false;
    styles[i]->setMainColor(blend(c0, c1, (double)i / (double)(n - 1)));
    styles[i]->invalidateIcon();
  }
  if (areAllStyleLincked) return;
  TApp::instance()->getCurrentPalette()->notifyColorStyleChanged();

  UndoBlendColor *undo =
      new UndoBlendColor(m_palette, m_pageIndex, oldStyles, c0, c1);
  TUndoManager::manager()->add(undo);
}
Ejemplo n.º 5
0
void StrokeSelection::changeColorStyle(int styleIndex) {
  TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
  if (!tool) return;
  TVectorImageP img(tool->getImage(true));
  if (!img) return;
  TPalette *palette = img->getPalette();
  TColorStyle *cs   = palette->getStyle(styleIndex);
  if (!cs->isStrokeStyle()) return;
  if (m_indexes.empty()) return;

  UndoSetStrokeStyle *undo = new UndoSetStrokeStyle(img, styleIndex);
  std::set<int>::iterator it;
  for (it = m_indexes.begin(); it != m_indexes.end(); ++it) {
    int index = *it;
    assert(0 <= index && index < (int)img->getStrokeCount());
    TStroke *stroke = img->getStroke(index);
    undo->addStroke(stroke);
    stroke->setStyle(styleIndex);
  }

  tool->notifyImageChanged();
  TUndoManager::manager()->add(undo);
}
Ejemplo n.º 6
0
bool TColorStyle::operator==(const TColorStyle &cs) const {
  if (getTagId() != cs.getTagId()) return false;

  if (getMainColor() != cs.getMainColor()) return false;

  int paramCount = getParamCount();
  if (paramCount != cs.getParamCount()) return false;

  int colorParamCount = getColorParamCount();
  if (colorParamCount != cs.getColorParamCount()) return false;

  if (m_name != cs.getName()) return false;
  if (m_originalName != cs.getOriginalName()) return false;
  if (m_globalName != cs.getGlobalName()) return false;
  if (m_isEditedFromOriginal != cs.getIsEditedFlag()) return false;
  if (m_pickedPosition != cs.getPickedPosition()) return false;
  if (m_flags != cs.getFlags()) return false;

  for (int p = 0; p < colorParamCount; ++p)
    if (getColorParamValue(p) != cs.getColorParamValue(p)) return false;

  for (int p = 0; p < paramCount; ++p) {
    switch (getParamType(p)) {
    case BOOL:
      if (getParamValue(bool_tag(), p) != cs.getParamValue(bool_tag(), p))
        return false;
      break;
    case INT:
    case ENUM:
      if (getParamValue(int_tag(), p) != cs.getParamValue(int_tag(), p))
        return false;
      break;
    case DOUBLE:
      if (getParamValue(double_tag(), p) != cs.getParamValue(double_tag(), p))
        return false;
      break;
    case FILEPATH:
      if (getParamValue(TFilePath_tag(), p) !=
          cs.getParamValue(TFilePath_tag(), p))
        return false;
      break;
    default:
      assert(false);
    }
  }

  return true;
}
Ejemplo n.º 7
0
TToonzImageP Naa2TlvConverter::makeTlv(bool transparentSyntheticInks) {
  if (!m_valid || m_colors.empty() || m_regions.empty() || !m_regionRas)
    return TToonzImageP();
  int lx                = m_regionRas->getLx();
  int ly                = m_regionRas->getLy();
  TPalette *palette     = m_palette;
  if (!palette) palette = new TPalette();

  TRasterCM32P ras(lx, ly);

  QList<int> styleIds;

  for (int i = 0; i < m_colors.count() - 1; i++) {
    TPixel32 color  = m_colors.at(i);
    int styleId     = palette->getClosestStyle(color);
    TColorStyle *cs = styleId < 0 ? 0 : palette->getStyle(styleId);
    if (cs) {
      if (cs->getMainColor() != color) cs = 0;
    }
    if (cs == 0) {
      styleId = palette->getPage(0)->addStyle(color);
      cs      = palette->getStyle(styleId);
    }
    styleIds.append(styleId);
  }
  styleIds.append(0);  // syntetic ink

  // int synteticInkStyleId = palette->getPage(0)->addStyle(TPixel32(0,0,0,0));
  // styleIds.append(synteticInkStyleId);

  for (int y = 0; y < ly; y++) {
    unsigned short *workScanLine = m_regionRas->pixels(y);
    TPixelCM32 *outScanLine      = ras->pixels(y);
    for (int x = 0; x < lx; x++) {
      int c = workScanLine[x];
      Q_ASSERT(0 <= c && c < m_regions.count());

      int color = m_regions[c].colorIndex;
      Q_ASSERT(0 <= color && color < styleIds.count());

      int styleId = styleIds.at(color);

      RegionInfo::Type type = m_regions.at(c).type;
      if (type == RegionInfo::Background)
        outScanLine[x] = TPixelCM32();
      else if (type & RegionInfo::Ink)
        outScanLine[x] = TPixelCM32(styleId, 0, 0);
      else if (m_syntheticInkRas->pixels(y)[x] == 1)
        outScanLine[x] =
            TPixelCM32(transparentSyntheticInks ? 0 : styleId, styleId, 0);
      else
        outScanLine[x] = TPixelCM32(0, styleId, 255);
    }
  }

  TToonzImageP ti = new TToonzImage(ras, ras->getBounds());
  ti->setPalette(palette);
  ti->setDpi(72, 72);

  return ti;
}