Пример #1
0
/**
 * Updates the preview points (if necessary)
 *
 */
void EFX::updatePreview()
{
	if (m_previewPointArray == NULL)
		return;

	int stepCount = 128;
	int step = 0;
	float stepSize = (float)(1) / ((float)(stepCount) / (M_PI * 2.0));

	float i = 0;
	float *x = new float;
	float *y = new float;

	/* Resize the array to contain stepCount points */
	m_previewPointArray->resize(stepCount);

	if (m_algorithm == KCircleAlgorithmName)
	{
		/* Draw a preview of a circle */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			circlePoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else if (m_algorithm == KEightAlgorithmName)
	{
		/* Draw a preview of a eight */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			eightPoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else if (m_algorithm == KLineAlgorithmName)
	{
		/* Draw a preview of a line */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			linePoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else if (m_algorithm == KDiamondAlgorithmName)
	{
		/* Draw a preview of a diamond */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			diamondPoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else if (m_algorithm == KTriangleAlgorithmName)
	{
		/* Draw a preview of a triangle */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			trianglePoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else if (m_algorithm == KLissajousAlgorithmName)
	{
		/* Draw a preview of a lissajous */
		for (i = 0; i < (M_PI * 2.0); i += stepSize)
		{
			lissajousPoint(this, i, x, y);
			m_previewPointArray->setPoint(step++,
						      static_cast<int> (*x),
						      static_cast<int> (*y));
		}
	}
	else
	{
		m_previewPointArray->resize(0);
	}

	delete x;
	delete y;
}
Пример #2
0
bool EFX::preview(QVector <QPoint>& polygon)
{
	bool retval = true;
	int stepCount = 128;
	int step = 0;
	qreal stepSize = (qreal)(1) / ((qreal)(stepCount) / (M_PI * 2.0));

	qreal i = 0;
	qreal x = 0;
	qreal y = 0;

	/* Resize the array to contain stepCount points */
	polygon.resize(stepCount);

	/* Since algorithm is identified by a string, we don't want to do N
	   string comparisons on each for loop increment. So, it's a bit faster
	   to check the algorithm only once and then do the looping. */
	if (m_algorithm == KCircleAlgorithmName)
	{
		/* Draw a preview of a circle */
		for (step = 0; step < stepCount; step++)
		{
			circlePoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else if (m_algorithm == KEightAlgorithmName)
	{
		/* Draw a preview of a eight */
		for (step = 0; step < stepCount; step++)
		{
			eightPoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else if (m_algorithm == KLineAlgorithmName)
	{
		/* Draw a preview of a line */
		for (step = 0; step < stepCount; step++)
		{
			linePoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else if (m_algorithm == KDiamondAlgorithmName)
	{
		/* Draw a preview of a diamond */
		for (step = 0; step < stepCount; step++)
		{
			diamondPoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else if (m_algorithm == KTriangleAlgorithmName)
	{
		/* Draw a preview of a triangle */
		for (step = 0; step < stepCount; step++)
		{
			trianglePoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else if (m_algorithm == KLissajousAlgorithmName)
	{
		/* Draw a preview of a lissajous */
		for (step = 0; step < stepCount; step++)
		{
			lissajousPoint(this, i, &x, &y);
			polygon[step] = QPoint(int(x), int(y));
			i += stepSize;
		}
	}
	else
	{
		polygon.resize(0);
		retval = false;
	}

	return retval;
}