Exemplo n.º 1
0
MStatus grabUVContext::drawFeedback(MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context)
{
	// to draw the brush ring.
	drawMgr.beginDrawable();
	{
		drawMgr.setColor( MColor(1.f, 1.f, 1.f) ); 
		drawMgr.setLineWidth( 2.0f );
		drawMgr.circle2d(MPoint(fBrushCenterScreenPoint.x, fBrushCenterScreenPoint.y), fBrushConfig.size());
	}				
	drawMgr.endDrawable();

	return MS::kSuccess;
}
Exemplo n.º 2
0
void uiDrawManagerDrawOverride::addUIDrawables(
    const MDagPath& objPath,
    MHWRender::MUIDrawManager& drawManager,
    const MHWRender::MFrameContext& frameContext,
    const MUserData* data)
{
    const uiDrawManagerData* thisdata = dynamic_cast<const uiDrawManagerData*>(data);
    if (!thisdata) {
        return;
    }

    switch (thisdata->fUIType) 
    {
    case uiDrawManager::kText: 
        {
            // Draw a text "uiDrawManager"
            // All drawing operations must take place between calls to beginDrawable()
            // and endDrawable().
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setFontSize(thisdata->fTextFontSize);
            drawManager.setFontIncline(thisdata->fTextIncline);
            drawManager.setFontWeight(thisdata->fTextWeight);
            drawManager.setFontStretch(thisdata->fTextStretch);
            drawManager.setFontLine(thisdata->fTextLine);

            MString faceName = uiDrawManagerData::fFontList[thisdata->fFontFaceIndex];
            drawManager.setFontName(faceName);
            int boxSize[] = { thisdata->fTextBoxWidth, thisdata->fTextBoxHeight };
            if (thisdata->fDraw2D) {
                // uiDrawManagerData::fPosition gives a screen space position 
                // where 2D UI item is located.                
                drawManager.text2d(thisdata->fPosition, thisdata->fText, thisdata->fTextAlignment, 
                    boxSize[0]+boxSize[1] == 0 ? NULL : boxSize, &thisdata->fTextBoxColor, false);
            }
            else {
                // for 3D items, place it at the origin of the world space.
                drawManager.text(thisdata->fPosition, thisdata->fText, thisdata->fTextAlignment, 
                    boxSize[0]+boxSize[1] == 0 ? NULL : boxSize, &thisdata->fTextBoxColor, false);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kLine:
	case uiDrawManager::kLineList:
	case uiDrawManager::kLineStrip:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			if (thisdata->fUIType == uiDrawManager::kLineStrip)
				drawManager.lineStrip(thisdata->fLines, thisdata->fDraw2D);
            else
				drawManager.lineList(thisdata->fLines, thisdata->fDraw2D);
			drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kPoint:
    case uiDrawManager::kPointList:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setPointSize(thisdata->fPointSize);
            drawManager.points(thisdata->fPoints, thisdata->fDraw2D);
            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kRect:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // For 2d rectangle, an up vector in screen space is used to determine its X 
                // and Y directions. In addition, "fRectScaleX" and "fRectScaleY"(in pixels)
                // specify the half-lengths of the 2d rectangle.
                drawManager.rect2d(thisdata->fPosition, thisdata->fRectUp,
                    thisdata->fRectScaleX, thisdata->fRectScaleY, thisdata->fIsFilled);
            }
            else {
                // For 3d rectangle, the up vector should not be parallel with the normal vector.
				drawManager.rect(thisdata->fPosition, thisdata->fRectUp, thisdata->fRectNormal,
                    thisdata->fRectScaleX, thisdata->fRectScaleY, thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kQuad:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);

            // prepare primitive type
            MUIDrawManager::Primitive mode = 
                thisdata->fIsFilled ? MUIDrawManager::kTriStrip : MUIDrawManager::kClosedLine;
            // prepare position list
            MPointArray position;
            for (int i = 0; i < 4; ++i) {
                position.append(thisdata->fQuadVertex[i]);
            }
            // prepare index
            MUintArray index;
            index.append(0);
            index.append(1);
            index.append(3);
            index.append(2);

            // draw mesh
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                drawManager.mesh2d(mode, position, NULL, thisdata->fIsFilled ? &index : NULL);
            }
            else {
                drawManager.mesh(mode, position, NULL, NULL, thisdata->fIsFilled ? &index : NULL);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kSphere:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.sphere(thisdata->fPosition, thisdata->fRadius, thisdata->fIsFilled);

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kCircle:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // The radius in specified as pixel unit for 2d items.
				drawManager.circle2d(thisdata->fPosition, thisdata->fRadius, 
                    thisdata->fIsFilled);
            }
            else {
                drawManager.circle(thisdata->fPosition, thisdata->fCircleNormal, thisdata->fRadius, 
                    thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

    case uiDrawManager::kArc:
        {
            drawManager.beginDrawable();

            drawManager.setColor(thisdata->fColor);
            drawManager.setLineWidth(thisdata->fLineWidth);
            drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
            if (thisdata->fDraw2D) {
                // If 2d, the range of the arc is defined by the start and end vectors 
                // specified in screen space.
                drawManager.arc2d(thisdata->fPosition, thisdata->fArcStart, thisdata->fArcEnd, 
                    thisdata->fRadius, thisdata->fIsFilled);
            }
            else {
                // For 3d arc, the projections of the start and end vectors onto the arc plane(
                // determined by the normal vector) determine the range of the arc.
                drawManager.arc(thisdata->fPosition, thisdata->fArcStart, thisdata->fArcEnd, 
                    thisdata->fArcNormal, thisdata->fRadius, thisdata->fIsFilled);
            }

            drawManager.endDrawable();
        }
        break;

	case uiDrawManager::kIcon:
		{	
            MString iconName = uiDrawManagerData::fIconList[thisdata->fIconIndex];
			drawManager.beginDrawable();
			drawManager.setColor(thisdata->fColor);
			drawManager.icon(thisdata->fPosition, iconName, thisdata->fIconScale);
			drawManager.endDrawable();
		}
		break;

	case uiDrawManager::kCone:
		{
			drawManager.beginDrawable();

			drawManager.setColor(thisdata->fColor);
			drawManager.setLineWidth(thisdata->fLineWidth);
			drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.cone(thisdata->fPosition,
							thisdata->fConeDirection,
							thisdata->fRadius, 
							thisdata->fConeHeight,
							thisdata->fIsFilled);

			drawManager.endDrawable();
		}
		break;

	case uiDrawManager::kBox:
		{
			drawManager.beginDrawable();

			drawManager.setColor(thisdata->fColor);
			drawManager.setLineWidth(thisdata->fLineWidth);
			drawManager.setLineStyle(thisdata->fLineStyle);
			drawManager.setPaintStyle(thisdata->fShaded ? 
				MUIDrawManager::kShaded : MUIDrawManager::kFlat);
			drawManager.box(thisdata->fPosition, 
							thisdata->fBoxUp,
							thisdata->fBoxRight,
							thisdata->fBoxScale[0],
							thisdata->fBoxScale[1],
							thisdata->fBoxScale[2],
							thisdata->fIsFilled);

			drawManager.endDrawable();
		}
		break;
	
	default:
        perror("unhandled ui types.");
        break;
    }
    
}