Пример #1
0
void TSimpleStrokeProp::draw(
    const TVectorRenderData
        &rd) /*assenza di const non e' una dimenticanza! Alcune sottoclassi
                devono ridefinire questo metodo e serve che non sia const*/
{
  if (rd.m_clippingRect != TRect() && !rd.m_is3dView &&
      !convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect))
    return;

  if (!rd.m_show0ThickStrokes) {
    // >:(  This is not an implementation detail of TCenterlineStrokeStyle
    // because the drawStroke()
    //      function does not have access to rd - should modify the interface...
    //      it would be best.

    const TCenterLineStrokeStyle *cs =
        dynamic_cast<const TCenterLineStrokeStyle *>(m_colorStyle);
    if (cs && cs->getParamValue(TColorStyle::double_tag(), 0) == 0) return;
  }

  glPushMatrix();
  tglMultMatrix(rd.m_aff);
  m_colorStyle->drawStroke(rd.m_cf, m_stroke);

  glPopMatrix();
}
Пример #2
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();
}
Пример #3
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();
}
Пример #4
0
	void paintGL() override
	{
		drawBackground();

		// Draw original
		if (m_img) {
			pushGLWorldCoordinates();

			glEnable(GL_BLEND);
			glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

			// Note GL_ONE instead of GL_SRC_ALPHA: it's needed since the input
			// image is supposedly premultiplied - and it works because the
			// viewer's background is opaque.
			// See tpixelutils.h's overPixT function for comparison.

			draw(m_img);

			glDisable(GL_BLEND);

			popGLCoordinates();
		} else if (m_xsh) {
			// Build reference change affines

			// EXPLANATION: RasterPainter receives an affine specifiying the reference change
			// from world coordinates to the OpenGL viewport, where (0,0) corresponds to the
			// viewport center.

			const TAffine &cameraAff = m_xsh->getPlacement(m_xsh->getStageObjectTree()->getCurrentCameraId(), m_row);

			TTranslation centeredWidgetToWidgetAff(0.5 * width(), 0.5 * height());
			const TAffine &worldToCenteredWigetAff = centeredWidgetToWidgetAff.inv() * viewAff() * cameraAff.inv();

			glPushMatrix();
			tglMultMatrix(centeredWidgetToWidgetAff);

			assert(m_row >= 0);

			ImagePainter::VisualSettings vs;

			TDimension viewerSize(width(), height());
			Stage::RasterPainter painter(viewerSize, worldToCenteredWigetAff, TRect(viewerSize), vs, false);

			ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
			Stage::visit(painter, scene, m_xsh.getPointer(), m_row);

			painter.flushRasterImages();
			glFlush();

			glPopMatrix();
		}

		// Draw mesh preview
		if (m_meshImg) {
			glEnable(GL_BLEND);
			glEnable(GL_LINE_SMOOTH);

			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			// Retrieve mesh dpi
			TPointD meshDpi;
			m_meshImg->getDpi(meshDpi.x, meshDpi.y);

			// Push mesh-to-world coordinates change
			pushGLWorldCoordinates();
			glScaled(Stage::inch / meshDpi.x, Stage::inch / meshDpi.y, 1.0);

			glColor4f(0.0, 1.0, 0.0, 0.7); // Translucent green
			tglDrawEdges(*m_meshImg);

			popGLCoordinates();

			glDisable(GL_LINE_SMOOTH);
			glDisable(GL_BLEND);
		}
	}
Пример #5
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();
}
Пример #6
0
void TglTessellator::tessellate(const TColorFunction *cf, const bool antiAliasing, TRegionOutline &outline, TRaster32P texture)
{
	//QMutexLocker sl(m_mutex);
	checkErrorsByGL;
	glEnable(GL_TEXTURE_2D);
	glColor4d(1, 1, 1, 1);
	checkErrorsByGL;
	TextureInfoForGL texInfo;

	int pow2Lx = tcg::numeric_ops::GE_2Power((unsigned int)texture->getLx());
	int pow2Ly = tcg::numeric_ops::GE_2Power((unsigned int)texture->getLy());

	TAffine aff;
	if (texture->getLx() != pow2Lx || texture->getLy() != pow2Ly) {
		TRaster32P r(pow2Lx, pow2Ly);
		aff = TScale((double)pow2Lx / texture->getLx(), (double)pow2Ly / texture->getLy());
		TRop::resample(r, texture, aff.place(texture->getCenterD(), r->getCenterD()));
		texture = r;
		glPushMatrix();
		tglMultMatrix(aff.inv());
	}

	// If GL_BRGA isn't present make a proper texture to use (... obsolete?)
	texture->lock();
	TRasterP texImage = prepareTexture(texture, texInfo);
	checkErrorsByGL;
	if (texImage != texture)
		texImage->lock();

	assert(texImage->getLx() == texImage->getWrap());

	GLuint texId;
	glGenTextures(1, &texId); // Generate a texture name
	checkErrorsByGL;
	glBindTexture(GL_TEXTURE_2D, texId); // Bind it 'active'
	checkErrorsByGL;
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	 // These must be invoked
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);	 // on a bound texture
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //
	checkErrorsByGL;
	glTexEnvf(GL_TEXTURE_ENV,	  // This too ?
			  GL_TEXTURE_ENV_MODE, // Better here anyway
			  GL_MODULATE);		   //
	checkErrorsByGL;
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
	checkErrorsByGL;
	glTexImage2D(GL_TEXTURE_2D,
				 0,						 // one level only
				 texInfo.internalformat, // pixel channels count
				 texInfo.width,			 // width
				 texInfo.height,		 // height
				 0,						 // border size
				 texInfo.type,			 // pixel format           // crappy names
				 texInfo.format,		 // pixel data type        // oh, SO much
				 texImage->getRawData());
	checkErrorsByGL;
	texture->unlock();
	if (texImage != texture)
		texImage->unlock();

	TglTessellator::GLTess glTess;
	gluTessCallback(glTess.m_tess, GLU_TESS_VERTEX, (GluCallback)tessellateTexture);
	checkErrorsByGL;

	//------------------------//
	if (aff != TAffine())
		doTessellate(glTess, cf, antiAliasing, outline, aff); // Tessellate & render
	else
		doTessellate(glTess, cf, antiAliasing, outline); // Tessellate & render
	checkErrorsByGL;
	//------------------------//
	if (aff != TAffine())
		glPopMatrix();
	glDeleteTextures(1, &texId); // Delete & unbind texture
	checkErrorsByGL;
	glDisable(GL_TEXTURE_2D);
	checkErrorsByGL;
}