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

  if (dlg->directionOfStroke == CLICK_STROKE_DIRECTION)
    {
      int newX, newY;
      int size = pDoc->getSize ();
      int angle = pDoc->getAngle ();
      int disp;
	
      int thickness = pDoc->getThickness ();
      if (size < 5)
	disp = size * 2;
      else
	disp = size;
      if (!angle || (angle == 180))
	{
	  newY = target.y;
	  newX = target.x + disp;
	}
      else if (angle == 90)
	{
	  newY = target.y + disp;
	  newX = target.x;
	}
      else
	{
	  int tanAngle = (int) tan (angle);
	  int c = target.y - (tanAngle * target.x);
	    
	  newY = target.y + disp;
	  newX = (newY - c) / tanAngle;
	}
      printf ("Setting line thickness to %d\n", thickness);
      glLineWidth( (float) thickness );

	
      printf ("In LineBrush::BrushBegin with source (%d, %d) and Target (%d, %d)\n",
	      source.x, source.y, target.x, target.y);
	
      glBegin( GL_LINES );
      SetColor( source );

      glVertex2d( target.x, target.y);
      glVertex2d( newX, newY);
      glEnd();
    }
  else
    return ;
}
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 #3
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();
}
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;
	}

	int size = pDoc->getSize();
	int angle = pDoc->getAngle();
	double opacity = pDoc->getOpac();
	int strokeDirChoice = dlg->m_StrokeDirChoice->value();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	srand(time(0));
	glMatrixMode(GL_MODELVIEW);
	
	switch (strokeDirChoice){
	// Slider/Right mouse 
	case 0:
		// don't have to change size and angle value
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Gradient
	case 1:
		// change angle value according to 
		// the gradient at this point
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;
			double Gx;
			double Gy;
			GLubyte color[3][3][3];
			double intensity[3][3];
			for (int i = -1; i < 2; i++){
				for (int j = -1; j < 2; j++){
					memcpy(color[i + 1][j + 1], pDoc->GetOriginalPixel(Point(source.x + displacement + i, source.y + dist + j)), 3);
					intensity[i + 1][j + 1] = 0.299*color[i + 1][j + 1][0] + 0.587*color[i + 1][j + 1][1] + 0.144*color[i + 1][j + 1][2];
				}
			}
			Gx = intensity[0][0] * (-1) + intensity[0][1] * (-2) + intensity[0][2] * (-1)\
				+ intensity[2][0] * (1) + intensity[2][1] * (2) + intensity[2][2] * (1);
			Gy = intensity[0][0] * (-1) + intensity[1][0] * (-2) + intensity[2][0] * (-1)\
				+ intensity[0][2] * (1) + intensity[1][2] * (2) + intensity[2][2] * (1);
			angle = -(int)(atan2(Gy, Gx)*57.32) % 360;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Brush direction
	case 2:
		current.x = target.x;
		current.y = target.y;
		if (prev.x!=-1&&current.x!=-1&&(current.x != prev.x || current.y != prev.y)){
			int dx = current.x - prev.x;
			int dy = current.y - prev.y;
			angle = (int)(atan2(dy, dx)*57.32) % 360;

			
			
			for (int i = 0; i < 4; i++){
				float length = size;
				float dist = fRand(-size*0.3, size*0.3)*2.5;
				float displacement = fRand(-size*0.75, size*0.75);
				float x1 = target.x + displacement;
				float y1 = target.y + dist;

				glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
				SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
				glVertex2d(x1 - length*0.75, y1);
				glVertex2d(x1 + length*0.75, y1);
				glEnd();
				glPopMatrix();
			}
		}
		prev.x = current.x;
		prev.y = current.y;
		break;

	default:
		break;

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

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

    int half_size;
    glGetIntegerv(GL_POINT_SIZE, &half_size);
    half_size /= 2;

    // dirty patch
    if (brushsize > 0) {
        glPointSize(brushsize);
        half_size = brushsize / 2;
        if (half_size == 0) half_size = 1;
    } else {
        // then it's normal paint
        // should set color according to original
        SetColor( source );
    }

    int width = ceil(pDoc->getWidth() / 2.0); //make sure it works when width is 1
    int angle = pDoc->getAngle();

    float m_sin = sin(2.0f * M_PI * angle / 360);
    float m_cos = cos(2.0f * M_PI * angle / 360);

    float depth = dlg->m_paintView->current_depth;

    glBegin( GL_POLYGON );

    if (pDoc->m_pUI->m_EdgeClipButton->value())
    {
        int nLength;
        int pLength;
        for (nLength = 0; nLength <= half_size; nLength++)
        {
            if (pDoc->isEdge(target.x - (int)(nLength * m_cos), target.y - (int)(nLength * m_sin)))
            {
                break;
            }
        }

        for (pLength = 0; pLength <= half_size; pLength++)
        {
            if (pDoc->isEdge(target.x + (int)(pLength * m_cos), target.y + (int)(pLength * m_sin)))
            {
                break;
            }
        }

        glVertex2d( target.x - nLength * m_cos - width * m_sin, target.y - nLength * m_sin + width * m_cos);
        glVertex2d( target.x + pLength * m_cos - width * m_sin, target.y + pLength * m_sin + width * m_cos);
        glVertex2d( target.x + pLength * m_cos + width * m_sin, target.y + pLength * m_sin - width * m_cos);
        glVertex2d( target.x - nLength * m_cos + width * m_sin, target.y - nLength * m_sin - width * m_cos);
    }
    else
    {
        glVertex2d( target.x - half_size * m_cos - width * m_sin, target.y - half_size * m_sin + width * m_cos);
        glVertex2d( target.x + half_size * m_cos - width * m_sin, target.y + half_size * m_sin + width * m_cos);
        glVertex2d( target.x + half_size * m_cos + width * m_sin, target.y + half_size * m_sin - width * m_cos);
        glVertex2d( target.x - half_size * m_cos + width * m_sin, target.y - half_size * m_sin - width * m_cos);
    }

    glEnd();
}
void LineBrush::BrushMove( const Point source, const Point target )
{
  int newX, newY, sourceNewX, sourceNewY;
  ImpressionistDoc* pDoc = GetDocument();
  ImpressionistUI* dlg=pDoc->m_pUI;

  if ( pDoc == NULL ) {
    printf( "LineBrush::BrushMove:document is NULL\n" );
    return;
  }
#if DEBUG
  printf ("In LineBrush::BrushMove with Source (%d, %d) and Target (%d, %d)\n",
	  source.x, source.y, target.x, target.y);

#endif
  if (dlg->directionOfStroke == CLICK_STROKE_DIRECTION)
    {
      int size = pDoc->getSize ();
      int angle = pDoc->getAngle ();
      int disp;
      int thickness = pDoc->getThickness ();

      if (size < 5)
	disp = size * 2;
      else
	disp = size;

      if (!angle || (angle == 180))
	{
	  newY = target.y;
	  newX = target.x + disp;
	  // 	    sourceNewY = source.y;
	  // 	    sourceNewX = source.x + disp;
	    
	}
      else if (angle == 90)
	{
	  newY = target.y + disp;
	  newX = target.x;
	  // 	    sourceNewY = source.y + disp;
	  // 	    sourceNewX = source.x;

	}
      else
	{
	  int tanAngle = (int) tan (angle);
	  int c = target.y - (tanAngle * target.x);
	    
	  newY = target.y + disp;
	  newX = (newY - c) / tanAngle;
	  // 	    sourceNewY = source.y + disp;
	  // 	    sourceNewX = (sourceNewY - c) / tanAngle;

	}
      glLineWidth( (float)thickness );
	
#if DEBUG
      printf ("LineBrush::BrushMove: Drawing a line from (%d,%d) to (%d,%d) of angle %d\n", 
	      target.x, target.y, newX, newY, angle);
#endif	

      glBegin( GL_LINES );
      SetColor( source );
       
      glVertex2d( target.x, target.y);
      glVertex2d( newX, newY);
      glEnd();
    }
  else if (dlg->directionOfStroke == DRAG_STROKE_DIRECTION)
    {

      int size = pDoc->getSize ();
      int angle = pDoc->getAngle ();
      int thickness = pDoc->getThickness ();
      glLineWidth( (float)thickness );
	

      if (lastPointX != -1)
	{
#if DEBUG
	  printf ("LineBrush::BrushMove: Drawing a line from (%d,%d) to (%d,%d) of angle %d\n", 
		  target.x, target.y, newX, newY, angle);
#endif	

	  glBegin( GL_LINES );
	  SetColor( source );
	  glVertex2d (lastPointX, lastPointY);
	  glVertex2d( target.x, target.y);
	  glEnd();
	  lastPointX = target.x;
	  lastPointY = target.y;
	}
      else
	{
	  lastPointX = target.x;
	  lastPointY = target.y;
	}
    }
}