Пример #1
0
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();
}
Пример #2
0
void MorphTool::draw()
{
	m_pixelSize = sqrt(tglGetPixelSize2());
	if (m_vi2) {
		TVectorRenderData rd(TTranslation(10, 10), TRect(), 0, 0);
		tglDraw(rd, m_vi2.getPointer());
	}

	double u = m_pixelSize * 5;
	for (int i = 0; i < (int)deformation.m_controlPoints.size(); i++) {
		TPointD p = deformation.m_controlPoints[i];
		bool selected = deformation.m_selected == i;
		bool base = (i & 1) == 0;
		if (base)
			if (selected)
				glColor3d(0.8, 0.8, 0.1);
			else
				glColor3d(0.5, 0.5, 0.1);
		else if (selected)
			glColor3d(0.8, 0.3, 0.1);
		else
			glColor3d(0.5, 0.1, 0.1);

		double r = base ? u * 2 : u * 1;
		tglDrawDisk(p, r);
		glColor3d(0, 0, 0);
		tglDrawCircle(p, r);
	}
	glColor3f(0, 1, 0);
	for (int i = 0; i + 1 < (int)deformation.m_controlPoints.size(); i += 2) {
		TPointD a = deformation.m_controlPoints[i];
		TPointD b = deformation.m_controlPoints[i + 1];
		tglDrawSegment(a, b);
	}
	/*
  deformation.update();
  glBegin(GL_LINES);
  for(double x = -200; x<=200; x+=20)
  for(double y = -200; y<=200; y+=20)
  {
    TPointD p0(x,y);
    TPointD p1 = deformation.apply(p0);
    glColor3d(0,1,0);
    tglVertex(p0);
    glColor3d(1,0,0);
    tglVertex(p1);
  }
  glEnd();
  */
}
Пример #3
0
void ShiftTraceTool::drawCurve() {
  if (m_curveStatus == NoCurve) return;
  double r = 4 * sqrt(tglGetPixelSize2());
  double u = getPixelSize();
  if (m_curveStatus == TwoPointsCurve) {
    TPixel32 color =
        m_highlightedGadget == 1000 ? TPixel32(200, 100, 100) : TPixel32::White;
    drawDot(m_p0, r, color);
    glColor3d(0.2, 0.2, 0.2);
    tglDrawSegment(m_p0, m_p1);
    drawDot(m_p1, r, TPixel32::Red);
  } else if (m_curveStatus == ThreePointsCurve) {
    TPixel32 color =
        m_highlightedGadget == 1000 ? TPixel32(200, 100, 100) : TPixel32::White;
    drawDot(m_p0, r, color);
    color =
        m_highlightedGadget == 1001 ? TPixel32(200, 100, 100) : TPixel32::White;
    drawDot(m_p1, r, color);

    glColor3d(0.2, 0.2, 0.2);

    TPointD center;
    if (circumCenter(center, m_p0, m_p1, m_p2)) {
      double radius = norm(center - m_p1);
      glBegin(GL_LINE_STRIP);
      int n = 100;
      for (int i = 0; i < n; i++) {
        double t  = (double)i / n;
        TPointD p = (1 - t) * m_p0 + t * m_p2;
        p         = center + radius * normalize(p - center);
        tglVertex(p);
      }
      for (int i = 0; i < n; i++) {
        double t  = (double)i / n;
        TPointD p = (1 - t) * m_p2 + t * m_p1;
        p         = center + radius * normalize(p - center);
        tglVertex(p);
      }
      glEnd();
    } else {
      tglDrawSegment(m_p0, m_p1);
    }
    color =
        m_highlightedGadget == 1002 ? TPixel32(200, 100, 100) : TPixel32::White;
    drawDot(m_p2, r, color);
  }
}
Пример #4
0
void tglDraw(const TRectD &rect,
			 const std::vector<TRaster32P> &textures,
			 bool blending)
{
	double pixelSize2 = tglGetPixelSize2();
	// level e' la minore potenza di 2 maggiore di sqrt(pixelSize2)
	unsigned int level = 1;
	while (pixelSize2 * level * level <= 1.0)
		level <<= 1;

	unsigned int texturesCount = (int)textures.size();
	if (level > texturesCount)
		level = texturesCount;

	level = texturesCount - level;

	tglDraw(rect, textures[level], blending);
}
Пример #5
0
void OutlineStrokeProp::draw(const TVectorRenderData &rd) {
  if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
      !convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
    return;

  glPushMatrix();
  tglMultMatrix(rd.m_aff);

  double pixelSize = sqrt(tglGetPixelSize2());

#ifdef _DEBUG
  if (m_stroke->isCenterLine() && m_colorStyle->getTagId() != 99)
#else
  if (m_stroke->isCenterLine())
#endif
  {
    TCenterLineStrokeStyle *appStyle =
        new TCenterLineStrokeStyle(m_colorStyle->getAverageColor(), 0, 0);
    appStyle->drawStroke(rd.m_cf, m_stroke);
    delete appStyle;
  } else {
    if (!isAlmostZero(pixelSize - m_outlinePixelSize, 1e-5) ||
        m_strokeChanged ||
        m_styleVersionNumber != m_colorStyle->getVersionNumber()) {
      m_strokeChanged    = false;
      m_outlinePixelSize = pixelSize;
      TOutlineUtil::OutlineParameter param;

      m_outline.getArray().clear();
      m_colorStyle->computeOutline(m_stroke, m_outline, param);

      // TOutlineStyle::StrokeOutlineModifier *modifier =
      // m_colorStyle->getStrokeOutlineModifier();
      // if(modifier)
      //  modifier->modify(m_outline);

      m_styleVersionNumber = m_colorStyle->getVersionNumber();
    }

    m_colorStyle->drawStroke(rd.m_cf, &m_outline, m_stroke);
  }

  glPopMatrix();
}
Пример #6
0
void VectorBrushProp::draw(const TVectorRenderData &rd)
{
	//Ensure that the stroke overlaps our clipping rect
	if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
		!convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
		return;

	TPaletteP palette(m_brush->getPalette());
	if (!palette)
		return;

	static TOutlineUtil::OutlineParameter param; //unused, but requested

	//Build a solid color style to draw each m_vi's stroke with.
	TSolidColorStyle colorStyle;

	//Push the specified rd affine before drawing
	glPushMatrix();
	tglMultMatrix(rd.m_aff);

	//1. If necessary, build the outlines
	double currentPixelSize = sqrt(tglGetPixelSize2());
	bool differentPixelSize = !isAlmostZero(currentPixelSize - m_pixelSize, 1e-5);
	m_pixelSize = currentPixelSize;

	int i, viRegionsCount = m_brush->getRegionCount(), viStrokesCount = m_brush->getStrokeCount();
	if (differentPixelSize || m_strokeChanged) {
		m_strokeChanged = false;

		//1a. First, the regions
		m_regionOutlines.resize(viRegionsCount);

		for (i = 0; i < viRegionsCount; ++i) {
			TRegionOutline &outline = m_regionOutlines[i];
			const TRegion *brushRegion = m_brush->getRegion(i);

			//Build the outline
			outline.clear();
			TOutlineUtil::makeOutline(*getStroke(), *brushRegion, m_brushBox,
									  outline);
		}

		//1b. Then, the strokes
		m_strokeOutlines.resize(viStrokesCount);

		for (i = 0; i < viStrokesCount; ++i) {
			TStrokeOutline &outline = m_strokeOutlines[i];
			const TStroke *brushStroke = m_brush->getStroke(i);

			outline.getArray().clear();
			TOutlineUtil::makeOutline(*getStroke(), *brushStroke, m_brushBox,
									  outline, param);
		}
	}

	//2. Draw the outlines

	UINT s, t, r,
		strokesCount = m_brush->getStrokeCount(),
		regionCount = m_brush->getRegionCount();

	for (s = 0; s < strokesCount; s = t) //Each cycle draws a group
	{
		//A vector image stores group strokes with consecutive indices.

		//2a. First, draw regions in the strokeIdx-th stroke's group
		for (r = 0; r < regionCount; ++r) {
			if (m_brush->sameGroupStrokeAndRegion(s, r)) {
				const TRegion *brushRegion = m_brush->getRegion(r);
				const TColorStyle *brushStyle =
					palette->getStyle(brushRegion->getStyle());
				assert(brushStyle);

				//Draw the outline
				colorStyle.setMainColor(brushStyle->getMainColor());
				colorStyle.drawRegion(0, false, m_regionOutlines[r]);
			}
		}

		//2b. Then, draw all strokes in strokeIdx-th stroke's group
		for (t = s; t < strokesCount && m_brush->sameGroup(s, t); ++t) {
			const TStroke *brushStroke = m_brush->getStroke(t);
			const TColorStyle *brushStyle =
				palette->getStyle(brushStroke->getStyle());
			if (!brushStyle)
				continue;

			colorStyle.setMainColor(brushStyle->getMainColor());
			colorStyle.drawStroke(0, &m_strokeOutlines[t], brushStroke); //brushStroke unused but requested
		}
	}

	glPopMatrix();
}
Пример #7
0
double
ToonzExt::Designer::getPixelSize2() const
{
	return tglGetPixelSize2();
}