void TriangleBrush::BrushMove(const Point source, const Point target) {
	ImpressionistDoc* pDoc = GetDocument();
	if (pDoc == NULL) {
		printf("TriangleBrush::BrushMove  document is NULL\n");
		return;
	}

	int size = pDoc->getSize(); // get brush size
	float alphaValue = pDoc->getAlpha();

	glPushMatrix();
	glTranslatef(target.x, target.y, 0); // move (0, 0) to the tip of mouse cursor

	glBegin(GL_POLYGON);

	SetColor(source, alphaValue);
	for (int i = 0; i < 3; i++) {
		float theta = -M_PI / 6 + 2.0f * M_PI * float(i) / float(3); // get the current angle (start from -30 degree)
		float x = cosf(theta) * size / 2; // calculate the x component 
		float y = sinf(theta) * size / 2; // calculate the y component 

		glVertex2f(x, y); // output vertex 
	}

	glEnd();

	glPopMatrix();
}
Example #2
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();

	GLubyte color[4];
	
	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
	color[3] = (GLubyte)pDoc->getAlpha(); //Set the alpha channel to whatever the slider says

	glColor4ubv( color );

}
Example #3
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
    ImpressionistDoc* pDoc = GetDocument();
    float alpha = pDoc->getAlpha();
    float* colorBlend = pDoc->getColorBlend();


    GLubyte color[4];

    memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
    color[0] = static_cast<GLubyte> (color[0] * colorBlend[0]);
    color[1] = static_cast<GLubyte> (color[1] * colorBlend[1]);
    color[2] = static_cast<GLubyte> (color[2] * colorBlend[2]);
    color[3] = static_cast<GLubyte>(alpha * 255.f);
    glColor4ubv( color );

}
void ScatteredLineBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("LineBrush::BrushMove  document is NULL\n");
		return;
	}

	const int size = pDoc->getSize();
	const float half_size = size / 2.0f;
	const int width = pDoc->getWidth();
	const int angle = pDoc->getAngle();
	const float half_line_width = width / 2.0f;
	float alpha = pDoc->getAlpha();
	float x, y;

	//glBegin(GL_POINTS);
	for (int i = 0; i < 3; i++)
	{

		x = target.x - size / 2 + irand(size);
		y = target.y - size / 2 + irand(size);

		Point random = Point(x, y);
		glPushMatrix();
		glTranslatef(random.x, random.y, 0.0f);
		glRotatef(angle, 0, 0, 1.0f);

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

		glBegin(GL_LINES);
		SetColor(random, alpha);
		glVertex2f(-half_size, 0);
		glVertex2f(half_size, 0);
		glEnd();

		glPopMatrix();
		
	}
}
Example #5
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const ImpBrush::Point source)
{
    ImpressionistDoc* pDoc = GetDocument();
    GLfloat alpha = pDoc->getAlpha();

    GLubyte color[3];
    memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );

    //
    // Setup the alpha settings
    //
    GLfloat color_r = ((GLfloat)color[0]/255);
    GLfloat color_g = ((GLfloat)color[1]/255);
    GLfloat color_b = ((GLfloat)color[2]/255);

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

    glColor4f(color_r, color_g, color_b, alpha);
}
Example #6
0
void PointBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "PointBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBegin( GL_POINTS );
		SetColor( source, alpha );

		glVertex2d( target.x, target.y );

	glEnd();
}
Example #7
0
void CircleBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "CircleBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBegin( GL_POLYGON );
		SetColor( source, alpha );
		for (int i = 0;i<360;i++)
			glVertex2d( target.x +0.5*size*cos(6.28*i/360) , target.y+0.5*size*sin(6.28*i/360));

	glEnd();
}
Example #8
0
void ScatteredPointBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "PointBrush::BrushMove  document is NULL\n" );
		return;
	}

	int size = pDoc->getSize();
	float alpha = pDoc->getAlpha();
	int angle = pDoc->getAngle();
	if(dlg->getDirMode()==1)
		angle = pDoc->getDirAngle();

	float cos_angle,sin_angle;
	float rad_angle = (angle*PI)/180;
	
	cos_angle = cos(-rad_angle);
	sin_angle = sin(-rad_angle);

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

	float orig_x,orig_y,x,y;
	SetColor( source, alpha );
	glBegin( GL_POINTS );
		for(int i = 0;i<0.05*size*size;i++)
		while(true){
			orig_x=-(size/2)+size*frand();
			orig_y=-(size/2)+size*frand();
			x = orig_x*cos_angle-orig_y*sin_angle;
			y = orig_x*sin_angle+orig_y*cos_angle;
			glVertex2d( target.x+x, target.y+y );
			break;
		}
	glEnd();
}
Example #9
0
void CsprayBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "CsprayBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int density = pDoc->getDensity();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	SetColor( source , alpha);
	for (int i = 0;i<density;i++){
			float r = rand() %10 ;
			r = r*size/10;
			oneCircle(target.x+r*cos(6.28*i/density) , target.y+r*sin(6.28*i/density), rand()%3);
		}

}
void CircleBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	float radius = (float)pDoc->getSize();
	float alpha = pDoc->getAlpha();

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glBegin(GL_POLYGON);
	SetColor(source, alpha);
	for (double i = 0; i < 2 * PI; i += PI / INTERVAL) {
		glVertex2d(target.x + cos(i)*radius, target.y + sin(i)*radius);
	}
	glEnd();
	glFlush();
}
Example #11
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();
	int r, g, b;
	ucolor32 col = pDoc->getBlendColor();


	GLubyte color[4];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );

	// Blend the color
	UNPACK_COLOR(r, g, b, col);
	color[0] = (unsigned)((r * color[0]) / 255);
	color[1] = (unsigned)((g * color[1]) / 255);
	color[2] = (unsigned)((b * color[2]) / 255);

	//Alpha
	color[3] = (int)(pDoc->getAlpha() * 255);
 
	glColor4ubv( color );

}
Example #12
0
void LineBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "LineBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int ax,ay,bx,by;
	int alpha = pDoc->getAlpha(); 
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	double angle = pDoc->getStrokeAngle();
	glBegin( GL_LINES );
		SetColor( source, alpha );
		
		glVertex2d( target.x, target.y );
		glVertex2d( target.x + cos(angle)*size, target.y + sin(angle)*size );
		
	glEnd();
}
Example #13
0
void SprayBrush::BrushMove( const Point source, const Point target )
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg=pDoc->m_pUI;

	if ( pDoc == NULL ) {
		printf( "SprayBrush::BrushMove  document is NULL\n" );
		return;
	}
	
	int size = pDoc->getSize();
	int density = pDoc->getDensity();
	int alpha = pDoc->getAlpha();
	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for (int i = 0; i<density; i++)
		{
			glPointSize( rand()%5+1 );
			glBegin( GL_POINTS );
			SetColor( source , alpha );
			glVertex2d( target.x - size/2 + rand()%size, target.y -size/2 + rand()%size);
			glEnd();
		}
}
Example #14
0
void CurvedBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("PointBrush::BrushMove  document is NULL\n");
		return;
	}

	int width = pDoc->m_nWidth;
	int height = pDoc->m_nHeight;

	radius = pDoc->getSize();
	minStrokeLength = pDoc->m_pUI->getMinStrokeLength();
	maxStrokeLength = pDoc->m_pUI->getMaxStrokeLength();
	curvatureFilter = pDoc->m_pUI->getCurvatureFilter();

	unsigned char* imageSource = (pDoc->m_ucBitmapBlurred == NULL) ? pDoc->m_ucBitmap : pDoc->m_ucBitmapBlurred;

	if (target.x < 0 || target.x >= width || target.y < 0 || target.y >= height)
	{
		return;
	}
	vector<pair< pair<int, int>, tuple<unsigned char, unsigned char, unsigned char> > > centers = CurvedBrushHelper::getCurvedBrushPoints(imageSource, pDoc->m_iGradient, pDoc->m_ucPreservedPainting, width, height, target.x, target.y, radius, minStrokeLength, maxStrokeLength, curvatureFilter);
	
	GLubyte color[4];
	color[3] = pDoc->getAlpha() * 255;
	auto color3 = centers[0].second;
	color[0] = get<0>(color3) * pDoc->m_pUI->m_colorSelector->r();
	color[1] = get<1>(color3) * pDoc->m_pUI->m_colorSelector->g();
	color[2] = get<2>(color3) * pDoc->m_pUI->m_colorSelector->b();
	glColor4ubv(color);
	
	if (centers.size() >= 3)
	{
		//calculate curves tangent
		double* tangentX = new double[centers.size()];
		double* tangentY = new double[centers.size()];
		tangentX[0] = centers[1].first.first - centers[0].first.first;
		tangentY[0] = centers[1].first.second - centers[0].first.second;
		tangentX[centers.size() - 1] = centers[centers.size() - 1].first.first - centers[centers.size() - 2].first.first;
		tangentY[centers.size() - 1] = centers[centers.size() - 1].first.second - centers[centers.size() - 2].first.second;
		for (int i = 1; i < centers.size() - 1; ++i)
		{
			tangentX[i] = centers[i].first.first - centers[i - 1].first.first;
			tangentY[i] = centers[i].first.second - centers[i - 1].first.second;
		}
		//calculate normal directions
		double* normalX = new double[centers.size()];
		double* normalY = new double[centers.size()];
		for (int i = 0; i < centers.size(); ++i)
		{
			double unit = sqrt(pow(tangentX[i], 2) + pow(tangentY[i], 2));
			normalX[i] = tangentY[i] / unit;
			normalY[i] = -tangentX[i] / unit;
		}
		//calculate boundary points and draw

		for (int i = 1; i < centers.size(); ++i)
		{
			glBegin(GL_POLYGON);
			glVertex2d(centers[i - 1].first.first + radius*normalX[i], centers[i - 1].first.second + radius*normalY[i]);
			glVertex2d(centers[i].first.first + radius*normalX[i], centers[i].first.second + radius*normalY[i]);
			glVertex2d(centers[i].first.first - radius*normalX[i], centers[i].first.second - radius*normalY[i]);
			glVertex2d(centers[i - 1].first.first - radius*normalX[i], centers[i - 1].first.second - radius*normalY[i]);
			glEnd();
		}

		delete tangentX;
		delete tangentY;
		delete normalX;
		delete normalY;
	}
	for (auto c : centers)
	{
		auto point = c.first;
		auto color3 = c.second;
		color[0] = get<0>(color3) * pDoc->m_pUI->m_colorSelector->r();
		color[1] = get<1>(color3) * pDoc->m_pUI->m_colorSelector->g();
		color[2] = get<2>(color3) * pDoc->m_pUI->m_colorSelector->b();
		glColor4ubv(color);

		glBegin(GL_POLYGON);
		for (int i = 0; i < 36; ++i)
		{
			double theta = i * 10 * 3.14159 / 180;
			glVertex2d(point.first - radius * cos(theta), point.second - radius * sin(theta));
		}
		glEnd();
	}
	
}