Esempio n. 1
0
void KDContext::drawLine(KDPoint p1, KDPoint p2, KDColor c) {
  // Find the largest gap
  KDPoint left = KDPointZero, right = KDPointZero;
  if (p2.x() > p1.x()) {
    left = p1;
    right = p2;
  } else {
    left = p2;
    right = p1;
  }
  KDPoint top = KDPointZero, bottom = KDPointZero;
  if (p2.y() > p1.y()) {
    top = p1;
    bottom = p2;
  } else {
    top = p2;
    bottom = p1;
  }
  assert(right.x() >= left.x());
  assert(bottom.y() >= top.y());

  KDCoordinate deltaX = 2*(right.x() - left.x());
  KDCoordinate deltaY = 2*(bottom.y() - top.y());

  KDPoint p = KDPointZero, alwaysTranslate = KDPointZero, conditionalTranslate = KDPointZero;
  KDCoordinate scanLength, error, minusError, plusError;

  if (deltaX >= deltaY) {
    p = left;
    scanLength = right.x() - left.x();
    error = right.x() - left.x();
    minusError = deltaY;
    plusError = deltaX;
    alwaysTranslate = KDPoint(1,0);
    conditionalTranslate = KDPoint(0, (right.y() >= left.y() ? 1 : -1));
  } else {
    p = top;
    scanLength = bottom.y() - top.y();
    error = bottom.y() - top.y();
    minusError = deltaX;
    plusError = deltaY;
    alwaysTranslate = KDPoint(0,1);
    conditionalTranslate = KDPoint((bottom.x() >= top.x() ? 1 : -1), 0);
  }

  KDCoordinate scanCounter = 0;
  while (scanCounter++ < scanLength) {
    setPixel(p, c);
    p = p.translatedBy(alwaysTranslate);
    error = error - minusError;
    if (error <= 0) {
      p = p.translatedBy(conditionalTranslate);
      error = error + plusError;
    }
  }
}
Esempio n. 2
0
void EditorView::GutterView::drawRect(KDContext * ctx, KDRect rect) const {
  KDColor textColor = KDColor::RGB24(0x919EA4);
  KDColor backgroundColor = KDColor::RGB24(0xE4E6E7);

  ctx->fillRect(rect, backgroundColor);

  KDSize charSize = KDText::charSize(m_fontSize);

  KDCoordinate firstLine = m_offset / charSize.height();
  KDCoordinate firstLinePixelOffset = m_offset - firstLine * charSize.height();

  char lineNumber[4];
  int numberOfLines = bounds().height() / charSize.height() + 1;
  for (int i=0; i<numberOfLines; i++) {
    Poincare::Integer line(i + firstLine + 1);
    line.writeTextInBuffer(lineNumber, 4);
    KDCoordinate leftPadding = (2 - strlen(lineNumber)) * charSize.width();
    ctx->drawString(
      lineNumber,
      KDPoint(k_margin + leftPadding, i*charSize.height() - firstLinePixelOffset),
      m_fontSize,
      textColor,
      backgroundColor
    );
  }
}
Esempio n. 3
0
KDPoint KDContext::writeString(const char * text, KDPoint p, KDText::FontSize size, KDColor textColor, KDColor backgroundColor, int maxLength, bool transparentBackground) {
  KDPoint position = p;
  int characterWidth = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_WIDTH : BITMAP_SmallFont_CHARACTER_WIDTH;
  int characterHeight = size == KDText::FontSize::Large ? BITMAP_LargeFont_CHARACTER_HEIGHT: BITMAP_SmallFont_CHARACTER_HEIGHT;
  KDPoint characterSize(characterWidth, 0);

  const char * end = text+maxLength;
  while(*text != 0 && text != end) {
    writeChar(*text, position, size, textColor, backgroundColor, transparentBackground);
    if (*text == '\n') {
      position = KDPoint(0, position.y()+characterHeight);
    } else if (*text == '\t') {
      position = position.translatedBy(KDPoint(KDText::k_tabCharacterWidth*characterWidth, 0));
    } else {
      position = position.translatedBy(characterSize);
    }
    text++;
  }
  return position;
}
Esempio n. 4
0
void TextArea::ContentView::drawStringAt(KDContext * ctx, int line, int column, const char * text, size_t length, KDColor textColor, KDColor backgroundColor) const {
  KDSize charSize = KDText::charSize(m_fontSize);
  ctx->drawString(
    text,
    KDPoint(column*charSize.width(), line*charSize.height()),
    m_fontSize,
    textColor,
    backgroundColor,
    length
  );
}
Esempio n. 5
0
KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) {
  KDCoordinate x = 0;
  KDCoordinate y = 0;
  int index = indexOfChild(child);
  if (index > 0) {
    ExpressionLayout * previousChild = editableChild(index-1);
    assert(previousChild != nullptr);
    x = previousChild->origin().x() + previousChild->size().width();
  }
  y = baseline() - child->baseline();
  return KDPoint(x, y);
}
Esempio n. 6
0
std::list<KDPoint> randomPointsInConcaveSphere(int numPoints, double innerRadius, double outerRadius)
{
	CGAL::Random_points_in_sphere_3<KDPoint, Pt_creator> sphereRnd(outerRadius - innerRadius);
	std::list<KDPoint> innerRandomPoints;
	CGAL::copy_n(sphereRnd, numPoints, std::back_inserter(innerRandomPoints));

	std::list<KDPoint> randomPoints;
	std::list<KDPoint>::iterator pointsIter;
	for(pointsIter = innerRandomPoints.begin(); pointsIter != innerRandomPoints.end(); ++pointsIter)
	{
		KDPoint point = *pointsIter;
		KDVector vPoint1 = KDVector(point.x(), point.y(), point.z());
		KDVector vPoint1Unit = vPoint1 / CGAL::sqrt(vPoint1.squared_length());
		KDVector vPoint2 = vPoint1Unit * innerRadius;
		KDVector vPoint = vPoint1 + vPoint2;
		randomPoints.push_back(KDPoint(vPoint.x(), vPoint.y(), vPoint.z()));
	}
	return randomPoints;
}
Esempio n. 7
0
std::list<KDPoint> randomPointsInSphereGaussianDistribution(int numPoints, double radius, double width)
{
	CGAL::Random_points_in_sphere_3<KDPoint, Pt_creator> sphereRnd(1.0);
	std::list<KDPoint> innerRandomPoints;
	CGAL::copy_n(sphereRnd, numPoints, std::back_inserter(innerRandomPoints));

	std::list<KDPoint> randomPoints;
	std::list<KDPoint>::iterator pointsIter;
	for(pointsIter = innerRandomPoints.begin(); pointsIter != innerRandomPoints.end(); ++pointsIter)
	{
		KDPoint point = *pointsIter;
		KDVector vPointR = KDVector(point.x(), point.y(), point.z());
		double r =  CGAL::sqrt(vPointR.squared_length());
		KDVector unitVector = vPointR / r;
		double gaussRadius = std::exp(-(width*r*r));
		KDTransformation scaleGauss(CGAL::SCALING, gaussRadius);
		KDTransformation scaleRadius(CGAL::SCALING, radius);
		KDPoint scaledPoint = scaleGauss(KDPoint(unitVector.x(), unitVector.y(), unitVector.z()));
		scaledPoint = scaleRadius(scaledPoint);
		randomPoints.push_back(scaledPoint);
	}
	return randomPoints;
}
Esempio n. 8
0
KDPoint KDPoint::opposite() const {
  return KDPoint(-m_x, -m_y);
}
Esempio n. 9
0
KDPoint KDPoint::translatedBy(KDPoint other) const {
  return KDPoint(m_x+other.x(), m_y+other.y());
}
Esempio n. 10
0
//TODO: use CGAL::Cartesian_converter<K1,K2> converter;
//K1::Point_3 p_k1(1,2,3);
//K2::Point_3 p_k2 = converter( p_k1 );
KDPoint converPointExactToInexact(PointCGAL point)
{
	return KDPoint(CGAL::to_double(point.x()), CGAL::to_double(point.y()), CGAL::to_double(point.z()));
}
Esempio n. 11
0
KDPoint BracketPairLayout::positionOfChild(ExpressionLayout * child) {
  const KDCoordinate k_widthMargin = widthMargin();
  const KDCoordinate k_externWidthMargin = externWidthMargin();
  return KDPoint(k_widthMargin+k_externWidthMargin+k_lineThickness, k_verticalMargin + verticalExternMargin());
}