Example #1
0
MStatus customAttrCtx::doRelease( MEvent & event )
//
// Description
//     This method is called when a mouse button is released while this context is
//    the current context.
//
{
	// Let the parent class handle the event.
	MStatus stat = MPxSelectionContext::doRelease( event );

	// If an object is selected, process the event if the middle mouse button
	// was lifted.
	if ( !isSelecting() ) {
		if (event.mouseButton() == MEvent::kMiddleMouse)
		{
			event.getPosition( endPos_x, endPos_y );

			// Delete the move command if we have moved less then 2 pixels
			// otherwise call finalize to set up the journal and add the
			// command to the undo queue.
			//
			if ( abs(startPos_x - endPos_x) < 2 ) {
				delete cmd;
				view.refresh( true );
			}
			else {
				stat = cmd->finalize();
				view.refresh( true );
			}
			setCursor(MCursor::defaultCursor);
		}
	}

	return stat;
}
Example #2
0
MStatus customAttrCtx::doDrag( MEvent & event )
//
// Description
//     This method is called when a mouse button is dragged while this context is
//    the current context.
//
{
	MStatus stat;

	// If an object has been selected, then process the drag.  Otherwise, pass the
    // event on up to the parent class.
	if ((!isSelecting()) && (event.mouseButton() == MEvent::kMiddleMouse)) {

		event.getPosition( endPos_x, endPos_y );

		// Undo the command to erase the previously set delta value from the
		// node, set a new delta value in the command and redo the command to
		// set the values in the node.
		cmd->undoIt();
		cmd->setDelta(endPos_x - startPos_x);
		stat = cmd->redoIt();
		view.refresh( true );
	}
	else
		stat = MPxSelectionContext::doDrag( event );

	return stat;
}
Example #3
0
MStatus moveContext::doRelease( MEvent & event )
{
	MStatus stat = MPxSelectionContext::doRelease( event );
	if ( !isSelecting() ) {
		event.getPosition( endPos_x, endPos_y );

		// Delete the move command if we have moved less then 2 pixels
		// otherwise call finalize to set up the journal and add the
		// command to the undo queue.
		//
		if ( abs(startPos_x - endPos_x) < 2 && abs(startPos_y - endPos_y) < 2 ) {
			delete cmd;
			view.refresh( true );
		}
		else {
			stat = cmd->finalize();
			view.refresh( true );
		}
	}
	return stat;
}
Example #4
0
MStatus viewCapture::doIt( const MArgList& args )
{
	MStatus status = MS::kSuccess;

	if ( args.length() != 1 ) {
		// Need the file name argument
		//
		return MS::kFailure;
	}

	MString fileName;
	args.get( 0, fileName );

	// Get the active 3D view
	//
	M3dView view = M3dView::active3dView();

	// Capture the current view
	//
	view.refresh();
	view.beginGL();
 
	// Set the target for our pixel read to be the front buffer.  First, the
	// current state is saved using the glPushAttrib call.  It is important
	// to leave the OpenGL in the same state that we found it.
	//
	glPushAttrib( GL_PIXEL_MODE_BIT ); 

	int width = view.portWidth();
	int height = view.portHeight(); 

	// Allocate buffers for the pixel data
	//
	GLfloat * red   = new GLfloat[width*height];
	GLfloat * green = new GLfloat[width*height];
	GLfloat * blue  = new GLfloat[width*height];

	// Read the values from the OpenGL frame buffer
	//
	glReadBuffer( GL_FRONT );
	glReadPixels( 0, 0, width, height, GL_RED, GL_FLOAT, red );
	glReadPixels( 0, 0, width, height, GL_GREEN, GL_FLOAT, green );
	glReadPixels( 0, 0, width, height, GL_BLUE, GL_FLOAT, blue );
	
	// Put the gl read target back
	//
	glPopAttrib(); 

	view.endGL();

	// Write file as a PPM
	//
	Pic_Pixel * line = PixelAlloc( width );
	int idx;

	Pic * file = PicOpen( fileName.asChar(), (short) width, (short) height );
	if ( NULL != file ) { 
		for ( int row = height - 1; row >= 0; row-- ) {
			// Covert the row of pixels into PPM format
			//
			for ( int col = 0; col < width; col++ ) {
				// Find the array elements for this pixel
				//
				idx = ( row * width ) + ( col );
				line[col].r = (Pic_byte)( red[idx]   * 255.0 );
				line[col].g = (Pic_byte)( green[idx] * 255.0 );
				line[col].b = (Pic_byte)( blue[idx] * 255.0 );
			}
			// Write the line
			//
			if ( !PicWriteLine( file, line ) ) {
				status = MS::kFailure; 
				return MS::kFailure;
			}
		}
		PicClose( file ); 
	}
 
	delete []red;
	delete []green;
	delete []blue;
	PixelFree( line );

	return status;
}
Example #5
0
MStatus moveContext::doDrag( MEvent & event )
{
	MStatus stat;
	stat = MPxSelectionContext::doDrag( event );

	// If we are not in selecting mode (i.e. an object has been selected)
	// then do the translation.
	//
	if ( !isSelecting() ) {
		event.getPosition( endPos_x, endPos_y );
		MPoint endW, startW;
		MVector vec;
		view.viewToWorld( startPos_x, startPos_y, startW, vec );
		view.viewToWorld( endPos_x, endPos_y, endW, vec );
		downButton = event.mouseButton();

		// We reset the the move vector each time a drag event occurs 
		// and then recalculate it based on the start position. 
		//
		cmd->undoIt();

		switch( currWin )
		{
			case TOP:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( endW.x - startW.x, 0.0, 0.0 );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( endW.x - startW.x, 0.0,
											   endW.z - startW.z );
						break;
				}
				break;	

			case FRONT:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( endW.x - startW.x, 0.0, 0.0 );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( endW.x - startW.x,
											   endW.y - startW.y, 0.0 );
						break;
				}
				break;	

			case SIDE:
				switch ( downButton )
				{
					case MEvent::kMiddleMouse :
						cmd->setVector( 0.0, 0.0, endW.z - startW.z );
						break;
					case MEvent::kLeftMouse :
					default:
						cmd->setVector( 0.0, endW.y - startW.y,
											   endW.z - startW.z );
						break;
				}
				break;	

			case PERSP:
				break;
		}

		stat = cmd->redoIt();
		view.refresh( true );
	}
	return stat;
}