MUIDrawManager Class Reference

This reference page is linked to from the following overview topics: Autodesk Maya 2014, 3.9 UI draw manager, 4.5 Handling custom renderables for object overrides.



Detailed Description

Main interface for drawing simple geometry in Viewport 2.0 and Maya Hardware Renderer 2.0.

Simple geometry includes things like lines and text.

All drawing operations, including setting state like color and font size, must occur between calls to beginDrawable() and endDrawable(). For example, to draw a pair of red lines you would do the following:

        MColor red(1.0f, 0.0f, 0.0f);

        painter.beginDrawable();
        painter.setColor( red );
        painter.line( MPoint(0, 0, 0), MPoint(1, 1, 1) );
        painter.line( MPoint(0, 0, 0), MPoint(-1, -1, 5) );
        painter.endDrawable();

The call to endDrawable() resets the draw state, so if you wanted to continue drawing in red later on you would have to repeat the call to setColor(). E.g:

        painter.beginDrawable();
        painter.setColor( red );
        painter.text( MPoint(0, 0, 4), "Hello, world!" );
        painter.endDrawable();

Note that draw operations may not take place immediately but instead be queued up for later execution.

Examples:

footPrintManip.cpp, footPrintNode.cpp, lineManip.cpp, lineManip.h, marqueeTool.cpp, and swissArmyManip.cpp.

#include <MUIDrawManager.h>

List of all members.

Public Types

enum  FontSize { kDefaultFontSize, kSmallFontSize }
 

Font size for drawing the text.

More...
enum  TextAlignment { kLeft, kCenter, kRight }
 

Text alignment.

More...
enum  LineStyle {
  kSolid, kShortDotted, kShortDashed, kDashed,
  kDotted
}
 

Line style.

More...
enum  PaintStyle { kFlat, kStippled }
 

Paint style.

More...
enum  Primitive {
  kPoints, kLines, kLineStrip, kClosedLine,
  kTriangles, kTriStrip
}
 

Primitive.

More...

Public Member Functions

void beginDrawable ()
 Resets all draw state, such as color and line style, to defaults and indicates the start of a sequence of drawing operations.
void endDrawable ()
 Indicates the end of a sequence of drawing operations.
void setColor (const MColor &color)
 Set the draw color.
void setColorIndex (const short index)
 Set the color index for the later primitive and text drawing.
void setPointSize (float value)
 Set the point size for the point drawing.
void setLineWidth (float value)
 Set the line width for the primitive drawing (line, rect, box...)
void setLineStyle (LineStyle style)
 Set the line style for the primitive drawing (line, rect, box...)
void setLineStyle (unsigned int factor, unsigned short pattern)
 Set the dashed line pattern for the primitive drawing (line, rect, box...)
void setPaintStyle (PaintStyle style)
 Set the paint style for filled primitive drawing.
void line (const MPoint &startPoint, const MPoint &endPoint)
 Draw a straight line between two points.
void line2d (const MPoint &startPoint, const MPoint &endPoint)
 Draw a straight line between two points.
void point (const MPoint &point)
 Draw a point.
void point2d (const MPoint &point)
 Draw a point.
void rect (const MPoint &center, const MVector &up, const MVector &normal, double scaleX, double scaleY, bool filled=false)
 Draw a rectangle.
void rect2d (const MPoint &center, const MVector &up, double scaleX, double scaleY, bool filled=false)
 Draw a 2D rectangle on the screen.
void sphere (const MPoint &center, double radius, bool filled=false)
 Draw a sphere.
void circle (const MPoint &center, const MVector &normal, double radius, bool filled=false)
 Draw a circle.
void circle2d (const MPoint &center, double radius, bool filled=false)
 Draw a 2D circle on the screen.
void arc (const MPoint &center, const MVector &start, const MVector &end, const MVector &normal, double radius, bool filled=false)
 Draw an arc.
void arc2d (const MPoint &center, const MVector &start, const MVector &end, double radius, bool filled=false)
 Draw a 2D arc on the screen.
void mesh (Primitive mode, const MPointArray &position, const MVectorArray *normal=NULL, const MColorArray *color=NULL, const MUintArray *index=NULL)
 Draw custom geometric shapes from an array of vertices.
void mesh2d (Primitive mode, const MPointArray &position, const MColorArray *color=NULL, const MUintArray *index=NULL)
 Draw custom 2d geometric shapes from an array of vertices.
void cone (const MPoint &base, const MVector &direction, double radius, double height, bool filled=false)
 Draw a cone.
void box (const MPoint &center, const MVector &up, const MVector &right, double scaleX=1.0, double scaleY=1.0, double scaleZ=1.0, bool filled=false)
 Draw a box.
void setFontSize (FontSize fontSize)
 Set the size of font to be used when drawing text.
void text (const MPoint &position, const MString &text, TextAlignment alignment=kLeft, const int *backgroundSize=NULL, const MColor *backgroundColor=NULL, bool dynamic=false)
 Draw a screen facing and horizontal aligned text in viewport 2.0.
void text2d (const MPoint &position, const MString &text, TextAlignment alignment=kLeft, const int *backgroundSize=NULL, const MColor *backgroundColor=NULL, bool dynamic=false)
 Draw a text on the screen.

Member Enumeration Documentation

enum FontSize

Font size for drawing the text.

Enumerator:
kDefaultFontSize 

 

kSmallFontSize 

 

enum PaintStyle

Paint style.

Enumerator:
kFlat 

 

kStippled 

 


Member Function Documentation

void beginDrawable ( )

Resets all draw state, such as color and line style, to defaults and indicates the start of a sequence of drawing operations.

All drawing operations must take place between calls to beginDrawable() and endDrawable().

            painter.beginDrawable();
            painter.line( MPoint(0,0,0), MPoint(1,1,1) );
            painter.line( MPoint(0,0,0), MPoint( -1, -1, 11) );
            painter.endDrawable();
Examples:
footPrintManip.cpp, footPrintNode.cpp, lineManip.cpp, marqueeTool.cpp, and swissArmyManip.cpp.
void endDrawable ( )

Indicates the end of a sequence of drawing operations.

All internal drawing state, such as color and line style, are reset to defaults.

Examples:
footPrintManip.cpp, footPrintNode.cpp, lineManip.cpp, marqueeTool.cpp, and swissArmyManip.cpp.
void setColor ( const MColor color)

Set the draw color.

This will remain in effect until the next call to setColor(), setColorIndex() or endDrawable().

For text this color will be used as the foreground color. Background color can be specified directly in the call to text().

Default: (0.7, 0.7, 0.7, 1)

Parameters:
[in]colorThe color which will affect the later drawing
Examples:
footPrintManip.cpp, footPrintNode.cpp, marqueeTool.cpp, and swissArmyManip.cpp.
void setColorIndex ( const short  index)

Set the color index for the later primitive and text drawing.

For default, it will use (0.7, 0.7, 0.7, 1) as default color.

Parameters:
[in]indexColor index
Examples:
lineManip.cpp.
void setPointSize ( float  value)

Set the point size for the point drawing.

Parameters:
[in]valuePoint size in pixels.
void setLineWidth ( float  value)

Set the line width for the primitive drawing (line, rect, box...)

Parameters:
[in]valueLine width in pixels.
void setLineStyle ( LineStyle  style)

Set the line style for the primitive drawing (line, rect, box...)

Parameters:
[in]styleLine style type.
void setLineStyle ( unsigned int  factor,
unsigned short  pattern 
)

Set the dashed line pattern for the primitive drawing (line, rect, box...)

Parameters:
[in]factora multiplier for each bit in the line stipple pattern.
[in]patterna pattern determines which fragments of a line will be drawn
void setPaintStyle ( PaintStyle  style)

Set the paint style for filled primitive drawing.

Parameters:
[in]stylePaint style type.
void line ( const MPoint startPoint,
const MPoint endPoint 
)

Draw a straight line between two points.

Parameters:
[in]startPointThe start point of the line.
[in]endPointThe end point of the line.
Examples:
lineManip.cpp, and marqueeTool.cpp.
void line2d ( const MPoint startPoint,
const MPoint endPoint 
)

Draw a straight line between two points.

Parameters:
[in]startPointThe start point of the line, only x-y components(in pixels) are used.
[in]endPointThe end point of the line, only x-y components(in pixels) are used.
void point ( const MPoint point)

Draw a point.

Parameters:
[in]pointPosition of the point.
void point2d ( const MPoint point)

Draw a point.

Parameters:
[in]pointPosition of the point, only x-y components(in pixels) are used.
void rect ( const MPoint center,
const MVector up,
const MVector normal,
double  scaleX,
double  scaleY,
bool  filled = false 
)

Draw a rectangle.

The rectangle is within the plane determined by a normal vector, and a up vector is given to determine the X-Y direction.

Parameters:
[in]centerCenter of the rectangle
[in]upUp vector of the rectangle
[in]normalNormal vector of the rectangle plane
[in]scaleXScale factor in X-direction
[in]scaleYScale factor in Y-direction
[in]filledIf true the rectangle will be filled otherwise it will just be drawn as an outline.
void rect2d ( const MPoint center,
const MVector up,
double  scaleX,
double  scaleY,
bool  filled = false 
)

Draw a 2D rectangle on the screen.

The rectangle is always facing the camera, and a up vector is given to determine the X-Y direction.

Parameters:
[in]centerCenter of the rectangle, only x-y components(in pixels) are used.
[in]upUp vector of the rectangle, only x-y components are used.
[in]scaleXScale factor in X-direction
[in]scaleYScale factor in Y-direction
[in]filledIf true the rectangle will be filled otherwise it will just be drawn as an outline.
void sphere ( const MPoint center,
double  radius,
bool  filled = false 
)

Draw a sphere.

Parameters:
[in]centerCenter of the sphere.
[in]radiusRadius of the sphere.
[in]filledIf true the sphere will be filled otherwise it will just be drawn as a wireframe.
void circle ( const MPoint center,
const MVector normal,
double  radius,
bool  filled = false 
)

Draw a circle.

The circle is drawn within the plane determined by a normal vector.

Parameters:
[in]centerCenter of the circle
[in]normalNormal vector of the circle plane
[in]radiusRadius of the circle
[in]filledIf true the circle will be filled otherwise it will just be drawn as an outline.
void circle2d ( const MPoint center,
double  radius,
bool  filled = false 
)

Draw a 2D circle on the screen.

The circle is always facing the camera.

Parameters:
[in]centerCenter of the circle, only x-y components(in pixels) are used.
[in]radiusRadius(in pixels) of the circle
[in]filledIf true the circle will be filled otherwise it will just be drawn as an outline.
void arc ( const MPoint center,
const MVector start,
const MVector end,
const MVector normal,
double  radius,
bool  filled = false 
)

Draw an arc.

The arc is within the plane determined by a normal vector. The arc sweeps in CCW from the vector that is the projection of the given start vector onto the arc plane, and ends at the vector that is the projection of the given end vector onto the arc plane.

Parameters:
[in]centerCenter of the arc
[in]startStart vector, its projection onto the arc plane is the start of the arc.
[in]endEnd vector, its projection onto the arc plane is the end of the arc.
[in]normalNormal vector of the arc plane.
[in]radiusRadius of the arc.
[in]filledIf true the arc will be filled otherwise it will just be drawn as an outline.
void arc2d ( const MPoint center,
const MVector start,
const MVector end,
double  radius,
bool  filled = false 
)

Draw a 2D arc on the screen.

The arc is always facing the camera. The arc sweeps in CCW from the start vector and ends at the end vector.

Parameters:
[in]centerCenter of the arc, only x-y components(in pixels) are used
[in]startStart vector, only x-y components are used.
[in]endEnd vector, only x-y components are used.
[in]radiusRadius(in pixels) of the arc.
[in]filledIf true the arc will be filled otherwise it will just be drawn as an outline.
void mesh ( Primitive  mode,
const MPointArray position,
const MVectorArray normal = NULL,
const MColorArray color = NULL,
const MUintArray index = NULL 
)

Draw custom geometric shapes from an array of vertices.

If the optional normal or color arrays are provided they must contain a single value per element of the positions array (i.e. all three arrays must be the same length).

The optional index array specifies the order in which the vertex positions (and their corresponding normals and colors) should be drawn. Vertices can be reused by having their indices appear multiple times, so the index array may be longer (or shorter) than the other three arrays.

If the index array is not provided then the vertices will be drawn in the order in which they appear in the positions array.

Parameters:
[in]modePrimitive mode, e.g., point list, line list, etc.
[in]positionList of the vertex positions.
[in]normalList of the vertex normals.
[in]colorList of the vertex colors.
[in]indexList of the vertex indices.
void mesh2d ( Primitive  mode,
const MPointArray position,
const MColorArray color = NULL,
const MUintArray index = NULL 
)

Draw custom 2d geometric shapes from an array of vertices.

If the optional color arrays are provided they must contain a single value per element of the positions array (i.e. both arrays must be the same length).

The optional index array specifies the order in which the vertex positions (and their corresponding colors) should be drawn. Vertices can be reused by having their indices appear multiple times, so the index array may be longer (or shorter) than the other two arrays.

If the index array is not provided then the vertices will be drawn in the order in which they appear in the positions array.

Parameters:
[in]modePrimitive mode, e.g., point list, line list, etc.
[in]positionList of the vertex positions, only x-y components of the point are used.
[in]colorList of the vertex colors.
[in]indexList of the vertex indices.
void cone ( const MPoint base,
const MVector direction,
double  radius,
double  height,
bool  filled = false 
)

Draw a cone.

Parameters:
[in]baseBase position for the cone
[in]directionThe cone's tip will point in this direction.
[in]radiusRadius of the cone
[in]heightHeight of the cone
[in]filledIf true the cone will be filled otherwise it will just be drawn as an outline.
void box ( const MPoint center,
const MVector up,
const MVector right,
double  scaleX = 1.0,
double  scaleY = 1.0,
double  scaleZ = 1.0,
bool  filled = false 
)

Draw a box.

Parameters:
[in]centerCenter position for the box
[in]upThe top of the box will be facing this direction.
[in]rightThe side of the box will be facing this direction.
[in]scaleXX size of the box
[in]scaleYY size of the box
[in]scaleZZ size of the box
[in]filledIf true the box will be filled otherwise it will just be drawn as an outline.
void setFontSize ( FontSize  fontSize)

Set the size of font to be used when drawing text.

Default: kDefaultFontSize

Parameters:
[in]fontSizeThe font size to use.
Examples:
footPrintNode.cpp.
void text ( const MPoint position,
const MString text,
TextAlignment  alignment = kLeft,
const int *  backgroundSize = NULL,
const MColor backgroundColor = NULL,
bool  dynamic = false 
)

Draw a screen facing and horizontal aligned text in viewport 2.0.

It has a fixed size in screen space.

Parameters:
[in]positionPosition of the text to be drawn, it is 3d object space.
[in]textContent of the text string.
[in]alignmentAlignment of the text. "kLeft", background box's left bottom will be located at "position". In width direction, text area will be aligned to the left side of background. In height direction, text are will be aligned in the middle of background.

"kCenter", background box' center bottom will be located at "position". text area's center and background box's center will be the same point.

"kRight", background box's right bottom will be located at "position". In width direction, text area will be aligned to the right side of background. In height direction, text are will be aligned in the middle of background.

Parameters:
[in]backgroundSizeThe background box size of the text. Default is NULL, in this case there will be no background, just shows the text. If it is specified with smaller size than text, the text will be clipped. It is a int array with size 2, like "int backgroundSize[] = { width, height } " Size unit is the screen pixel.
[in]backgroundColorThe color of the background, it can be transparent. If NULL is passed, background will be fully transparent.
[in]dynamicThis is mostly used for performance. If the text draw is not changed frequently, we can leave it as default value false. If the text draw is changing very often like it is showing some dynamic numbers, in this case making dynamic true will give better performance.
Examples:
footPrintManip.cpp, footPrintNode.cpp, lineManip.cpp, and swissArmyManip.cpp.
void text2d ( const MPoint position,
const MString text,
TextAlignment  alignment = kLeft,
const int *  backgroundSize = NULL,
const MColor backgroundColor = NULL,
bool  dynamic = false 
)

Draw a text on the screen.

Parameters:
[in]positionPosition of the text to be drawn, it is in screen space, only x-y components are used.
[in]textContent of the text string.
[in]alignmentAlignment of the text. "kLeft", background box's left bottom will be located at "position". In width direction, text area will be aligned to the left side of background. In height direction, text are will be aligned in the middle of background.

"kCenter", background box' center bottom will be located at "position". text area's center and background box's center will be the same point.

"kRight", background box's right bottom will be located at "position". In width direction, text area will be aligned to the right side of background. In height direction, text are will be aligned in the middle of background.

Parameters:
[in]backgroundSizeThe background box size(in pixels) of the text. Default is NULL, in this case there will be no background, just shows the text. If it is specified with smaller size than text, the text will be clipped. It is a int array with size 2, like "int backgroundSize[] = { width, height } " Size unit is the screen pixel.
[in]backgroundColorThe color of the background, it can be transparent. If NULL is passed, background will be fully transparent.
[in]dynamicThis is mostly used for performance. If the text draw is not changed frequently, we can leave it as default value false. If the text draw is changing very often like it is showing some dynamic numbers, in this case making dynamic true will give better performance.

MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager
MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager MUIDrawManager