Example #1
0
void PaintView::draw()
{
	#ifndef MESA
	// To avoid flicker on some machines.
	glDrawBuffer(GL_BACK);
	#endif // !MESA

	if(!valid())
	{


		glClearColor(0.7f, 0.7f, 0.7f, 1.0);

		// We're only using 2-D, so turn off depth 
		glDisable( GL_DEPTH_TEST );

		ortho();

		int	cx	= m_nWindowWidth = w();
		int	cy	= m_nWindowHeight = h();



		// Tell openGL to read from the front buffer when capturing
		// out paint strokes 
		glReadBuffer( GL_FRONT );

		glViewport( 0, 0, cx, cy );

		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		gluOrtho2D( 0, cx, 0, cy );

		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();

		// This translation is needed to make the image pixels line up with
		// the screen's pixels.  For details, visit:
		// http://www.opengl.org/resources/faq/technical/transformations.htm#tran0030
		glTranslatef( 0.375, 0.375, 0.0 );


		glClear( GL_COLOR_BUFFER_BIT );
	}

	ImpBrush::Point scrollpos;// = GetScrollPosition();
	scrollpos.x = 0;
	scrollpos.y	= 0;

	m_nWindowWidth	= w();
	m_nWindowHeight	= h();

	int drawWidth, drawHeight;
	drawWidth = min( m_nWindowWidth, m_pDoc->m_nPaintWidth );
	drawHeight = min( m_nWindowHeight, m_pDoc->m_nPaintHeight );

	int startrow = m_pDoc->m_nPaintHeight - (scrollpos.y + drawHeight);
	if ( startrow < 0 ) startrow = 0;

	m_pPaintBitstart = m_pDoc->m_ucPainting + 
		3 * ((m_pDoc->m_nPaintWidth * startrow) + scrollpos.x);

	m_nDrawWidth	= drawWidth;
	m_nDrawHeight	= drawHeight;

	m_nStartRow		= startrow;
	m_nEndRow		= startrow + drawHeight;
	m_nStartCol		= scrollpos.x;
	m_nEndCol		= m_nStartCol + drawWidth;

	if ( m_pDoc->m_ucPainting && !isAnEvent) 
	{
		RestoreContent();

	}

	if ( m_pDoc->m_ucPainting && isAnEvent) 
	{

		// Clear it after processing.
		isAnEvent	= 0;	

		ImpBrush::Point source( coord.x + m_nStartCol, m_nEndRow - coord.y );
		ImpBrush::Point target( coord.x, m_nWindowHeight - coord.y );
		
		// This is the event handler
		switch (eventToDo) 
		{
		case LEFT_MOUSE_DOWN:
			m_pDoc->m_pCurrentBrush->BrushBegin( source, target );
			break;
		case LEFT_MOUSE_DRAG:
			m_pDoc->m_pCurrentBrush->BrushMove( source, target );
			break;
		case LEFT_MOUSE_UP:
			m_pDoc->m_pCurrentBrush->BrushEnd( source, target );

			SaveCurrentBackContent();
			RestoreContent();
			break;
		case RIGHT_MOUSE_DOWN:

			break;
		case RIGHT_MOUSE_DRAG:

			break;
		case RIGHT_MOUSE_UP:

			break;

		default:
			printf("Unknown event!!\n");		
			break;
		}
	}

	glFlush();

	#ifndef MESA
	// To avoid flicker on some machines.
	glDrawBuffer(GL_BACK);
	#endif // !MESA
}
void PaintView::draw()
{
	#ifndef MESA
	// To avoid flicker on some machines.
  //	glDrawBuffer(GL_FRONT_AND_BACK);
	#endif // !MESA

	if(!valid())
	{

		glClearColor(0.7f, 0.7f, 0.7f, 1.0);

		// We're only using 2-D, so turn off depth 
		glDisable( GL_DEPTH_TEST );

		ortho();

		glClear( GL_COLOR_BUFFER_BIT );
	}

	Point scrollpos;// = GetScrollPosition();
	scrollpos.x = 0;
	scrollpos.y	= 0;

	m_nWindowWidth	= w();
	m_nWindowHeight	= h();

	int drawWidth, drawHeight;
	drawWidth = min( m_nWindowWidth, m_pDoc->m_nPaintWidth );
	drawHeight = min( m_nWindowHeight, m_pDoc->m_nPaintHeight );

	int startrow = m_pDoc->m_nPaintHeight - (scrollpos.y + drawHeight);
	if ( startrow < 0 ) startrow = 0;

	m_pPaintBitstart = m_pDoc->m_ucPainting + 
		3 * ((m_pDoc->m_nPaintWidth * startrow) + scrollpos.x);

	m_nDrawWidth	= drawWidth;
	m_nDrawHeight	= drawHeight;

	m_nStartRow		= startrow;
	m_nEndRow		= startrow + drawHeight;
	m_nStartCol		= scrollpos.x;
	m_nEndCol		= m_nStartCol + drawWidth;

	if ( m_pDoc->m_ucPainting && !isAnEvent) 
	{
		RestoreContent();

	}

	if ( m_pDoc->m_ucPainting && isAnEvent) 
	{

		// Clear it after processing.
		isAnEvent	= 0;	

		Point source( coord.x + m_nStartCol, m_nEndRow - coord.y );
		Point target( coord.x, m_nWindowHeight - coord.y );
		
		// This is the event handler
		switch (eventToDo) 
		{
		case LEFT_MOUSE_DOWN:
			m_pDoc->m_pCurrentBrush->BrushBegin( source, target );
			break;
		case LEFT_MOUSE_DRAG:
			m_pDoc->m_pCurrentBrush->BrushMove( source, target );
			break;
		case LEFT_MOUSE_UP:
			m_pDoc->m_pCurrentBrush->BrushEnd( source, target );

			SaveCurrentContent();
			RestoreContent();
			break;
		case RIGHT_MOUSE_DOWN:
			m_pDoc->m_pCurrentBrush->RightBrushBegin( source, target );
			break;
		case RIGHT_MOUSE_DRAG:
			m_pDoc->m_pCurrentBrush->RightBrushMove( source, target );
			break;
		case RIGHT_MOUSE_UP:
			m_pDoc->m_pCurrentBrush->RightBrushEnd( source, target );
			break;

		default:
			printf("Unknown event!!\n");		
			break;
		}
	}

	glFlush();

	#ifndef MESA
	// To avoid flicker on some machines.
	glDrawBuffer(GL_BACK);
	#endif // !MESA
}
void PaintView::draw()
{
	initSetup();

	if ( m_pDoc->m_ucPainting && !isAnEvent) 
	{
		RestoreContent(); // restore content upon refresh
	}

	if (m_pDoc->m_ucPainting && isAnEvent)
	{
		// Clear it after processing.
		isAnEvent = 0;

		Point source(coord.x + m_nStartCol, m_nEndRow - coord.y);
		Point target(coord.x, m_nWindowHeight - coord.y);
		// This is the event handler
		switch (eventToDo)
		{
		case LEFT_MOUSE_DOWN:
			m_pDoc->m_pUI->m_SizeRandButton->value(0);
			m_pDoc->m_pUI->setSizeRand(FALSE);
			savePreviousStrokes(); // save previous strokes before creating new strokes
			RestoreContent(); // put the strokes to colour buffer (no background)

			m_pDoc->m_pCurrentBrush->BrushBegin(source, target); // place the strokes to the colour buffer

			SaveCurrentContent(); // save the strokes to the buffer
			break;
		case LEFT_MOUSE_DRAG:
			RestoreContent();

			m_pDoc->m_pCurrentBrush->BrushMove(source, target);

			SaveCurrentContent();
			break;
		case LEFT_MOUSE_UP:
			RestoreContent();

			m_pDoc->m_pCurrentBrush->BrushEnd(source, target);
			
			SaveCurrentContent(); // save current strokes
			break;
		case RIGHT_MOUSE_DOWN:
			firstCoord = target;

			// Implement the right mouse stroke direction here
			rightClickDirectionLine = new RightClickDirectionLine(m_pDoc, "Right Click Direction Line");
			rightClickDirectionLine->BrushBegin(source, target);
			break;
		case RIGHT_MOUSE_DRAG:

			// We need to release the current content because 
			// each mouse drag refers to a different angle
			RestoreContent();

			rightClickDirectionLine->BrushMove(source, target);
			break;
		case RIGHT_MOUSE_UP:
			RestoreContent();

			rightClickDirectionLine->BrushEnd(source, target);
			angle = LineBrush::DetermineAngle(firstCoord, target);
			m_pDoc->setLineAngle(angle);
			delete rightClickDirectionLine;
			rightClickDirectionLine = NULL;

			break;
		default:
			printf("Unknown event!!\n");
			break;
		}
	}

	// put the background on top of the stroke
	// it sounds stupid, but if we want to do the other way,
	// we need to make everything rbga rather than rbg
	if (m_pDoc->m_ucPainting) {
		displayBackground(); 
	}

	glFlush();

	#ifndef MESA
		// To avoid flicker on some machines.
		glDrawBuffer(GL_BACK);
	#endif // !MESA

}