Tool Contexts

The basic interfaces for tools context (MPxContext, and MPxTexContext) are as follows:

The Viewport 2.0 interfaces attempt to match the old interface signatures, but branch off to allow access to an MUIDrawManager and a frame context (MFrameContext):

Note that drawFeedback() exists to allow for scenarios where continuous update is required, such as to always draw a 3d cursor.

The marqueeTool plug-in example demonstrates the use of an instance of an MUIDrawManager to perform drawing. As with the Legacy Default Viewport, the input event can be used to drive what to draw.

Mstatus marqueeContext::doDrag (
    MEvent & event,
    MHWRender::MUIDrawManager& drawManager,
    const MHWRender::MFrameContext& context)

{
    // Get the marquee's new end position.
    event.getPosition( last_x, last_y );

    // Draw the marquee at its new position.
    // Always drawn last so no need for complicated XOR
    drawManager.beginDrawable();
    drawManager.setColor( MColor(1.0f, 1.0f, 0.0f) );
    drawManager.line2d( MPoint( start_x, start_y), MPoint(last_x, start_y) );
    drawManager.line2d( MPoint( last_x, start_y), MPoint(last_x, last_y) );
    drawManager.line2d( MPoint( last_x, last_y), MPoint(start_x, last_y) );
    drawManager.line2d( MPoint( start_x, last_y), MPoint(start_x, start_y) );
    drawManager.endDrawable();
    return MS::kSuccess;
}

For Viewport 2.0, extra draw code is not required to handle XOR drawing.

The reason is because all context drawing can be thought of as drawing an overlay. Thus, for each event, only the current draw needs to be performed and the previous draw does not need to be “erased” using XOR drawing.

NOTE:M3dView::beginXorDrawing()/endXorDrawing() should not be used for Viewport 2.0 drawing.

The example above demonstrates mouse drag code which simply draws the current 2D marquee.