Esempio n. 1
0
void tglFillRect(const TRectD &rect)
{
	glBegin(GL_POLYGON);
	tglVertex(rect.getP00());
	tglVertex(rect.getP10());
	tglVertex(rect.getP11());
	tglVertex(rect.getP01());
	glEnd();
}
Esempio n. 2
0
void tglDrawRect(const TRectD &rect)
{
	glBegin(GL_LINE_LOOP);
	tglVertex(rect.getP00());
	tglVertex(rect.getP10());
	tglVertex(rect.getP11());
	tglVertex(rect.getP01());
	glEnd();
}
Esempio n. 3
0
TRectD TAffine::operator*(const TRectD &rect) const
{
	if (rect != TConsts::infiniteRectD) {
		TPointD p1 = *this * rect.getP00(),
				p2 = *this * rect.getP01(),
				p3 = *this * rect.getP10(),
				p4 = *this * rect.getP11();
		return TRectD(tmin(p1.x, p2.x, p3.x, p4.x), tmin(p1.y, p2.y, p3.y, p4.y),
					  tmax(p1.x, p2.x, p3.x, p4.x), tmax(p1.y, p2.y, p3.y, p4.y));
	} else
		return TConsts::infiniteRectD;
}
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();
}
/*-- Paste後のフローティング状態の画像の描画 --*/
void RasterSelectionTool::drawFloatingSelection()
{
	double pixelSize = TTool::getApplication()->getCurrentTool()->getTool()->getPixelSize();

	TAffine aff = m_rasterSelection.getTransformation();
	glPushMatrix();
	tglMultMatrix(aff);

	//draw m_floatingSelection
	if (isFloating()) {
		TRasterP floatingSelection = m_rasterSelection.getFloatingSelection();
		TImageP app;
		if (TRasterCM32P toonzRas = (TRasterCM32P)(floatingSelection))
			app = TToonzImageP(toonzRas, toonzRas->getBounds());
		if (TRaster32P fullColorRas = (TRaster32P)(floatingSelection))
			app = TRasterImageP(fullColorRas);
		if (TRasterGR8P grRas = (TRasterGR8P)(floatingSelection))
			app = TRasterImageP(grRas);
		app->setPalette(m_rasterSelection.getCurrentImage()->getPalette());
		FourPoints points = getBBox() * aff.inv();
		TRectD bbox = points.getBox();
		TPointD center((bbox.getP00() + bbox.getP11()) * 0.5);
		if (TToonzImageP ti = (TToonzImageP)app)
			GLRasterPainter::drawRaster(TTranslation(center), ti, false);
		if (TRasterImageP ri = (TRasterImageP)app)
			GLRasterPainter::drawRaster(TTranslation(center), ri, true);
	}

	std::vector<TStroke> strokes = m_rasterSelection.getStrokes();
	int i;
	for (i = 0; i < (int)strokes.size(); i++) {
		TStroke stroke = strokes[i];
		glEnable(GL_LINE_STIPPLE);
		glLineStipple(1, 0xF0F0);
		tglColor(TPixel32::Black);
		drawStrokeCenterline(stroke, pixelSize);
		glDisable(GL_LINE_STIPPLE);
	}

	glPopMatrix();
}
ShiftTraceTool::GadgetId ShiftTraceTool::getGadget(const TPointD &p) {
  std::vector<std::pair<TPointD, GadgetId>> gadgets;
  gadgets.push_back(std::make_pair(m_p0, CurveP0Gadget));
  gadgets.push_back(std::make_pair(m_p1, CurveP1Gadget));
  gadgets.push_back(std::make_pair(m_p2, CurvePmGadget));
  TAffine aff = getGhostAff();
  if (0 <= m_ghostIndex && m_ghostIndex < 2) {
    gadgets.push_back(std::make_pair(aff * m_box.getP00(), RotateGadget));
    gadgets.push_back(std::make_pair(aff * m_box.getP01(), RotateGadget));
    gadgets.push_back(std::make_pair(aff * m_box.getP10(), RotateGadget));
    gadgets.push_back(std::make_pair(aff * m_box.getP11(), RotateGadget));
    gadgets.push_back(
        std::make_pair(aff * m_center[m_ghostIndex], MoveCenterGadget));
  }
  int k           = -1;
  double minDist2 = pow(10 * getPixelSize(), 2);
  for (int i = 0; i < (int)gadgets.size(); i++) {
    double d2 = norm2(gadgets[i].first - p);
    if (d2 < minDist2) {
      minDist2 = d2;
      k        = i;
    }
  }
  if (k >= 0) return gadgets[k].second;

  // rect-point
  if (0 <= m_ghostIndex && m_ghostIndex < 2) {
    TPointD q = aff.inv() * p;

    double big = 1.0e6;
    double d = big, x = 0, y = 0;
    if (m_box.x0 < q.x && q.x < m_box.x1) {
      x         = q.x;
      double d0 = fabs(m_box.y0 - q.y);
      double d1 = fabs(m_box.y1 - q.y);
      if (d0 < d1) {
        d = d0;
        y = m_box.y0;
      } else {
        d = d1;
        y = m_box.y1;
      }
    }
    if (m_box.y0 < q.y && q.y < m_box.y1) {
      double d0 = fabs(m_box.x0 - q.y);
      double d1 = fabs(m_box.x1 - q.y);
      if (d0 < d) {
        d = d0;
        y = q.y;
        x = m_box.x0;
      }
      if (d1 < d) {
        d = d1;
        y = q.y;
        x = m_box.x1;
      }
    }
    if (d < big) {
      TPointD pp = aff * TPointD(x, y);
      double d   = norm(p - pp);
      if (d < 10 * getPixelSize()) {
        return TranslateGadget;
      }
    }
  }
  return NoGadget;
}