#include <maya/MIOStream.h>
#include <math.h>
#include <stdlib.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MGlobal.h>
#include <maya/M3dView.h>
#include <maya/MDagPath.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MPxContextCommand.h>
#include <maya/MPxContext.h>
#include <maya/MEvent.h>
#include <maya/MUIDrawManager.h>
#include <maya/MFrameContext.h>
#include <maya/MPoint.h>
#include <maya/MColor.h>
#define CUSTOM_XOR_DRAW 0
#if CUSTOM_XOR_DRAW
class xorDraw
{
public:
xorDraw(
M3dView *view) { fView = view; };
~xorDraw() {};
void beginXorDrawing();
void endXorDrawing();
protected:
xorDraw() { fView = NULL; }
GLboolean depthTest[1];
GLboolean colorLogicOp[1];
GLboolean lineStipple[1];
};
void xorDraw::beginXorDrawing()
{
glGetBooleanv (GL_DEPTH_TEST, depthTest);
glGetBooleanv (GL_COLOR_LOGIC_OP, colorLogicOp);
glGetBooleanv (GL_LINE_STIPPLE, lineStipple);
glDrawBuffer( GL_FRONT );
glLineStipple( 1, 0x5555 );
glLineWidth( 1.0 );
glEnable( GL_LINE_STIPPLE );
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D(
0.0, (GLdouble) fView->portWidth(),
0.0, (GLdouble) fView->portHeight()
);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef(0.375, 0.375, 0.0);
glColor3f(1.0f, 1.0f, 1.0f);
glDisable (GL_DEPTH_TEST);
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp (GL_XOR);
}
void xorDraw::endXorDrawing()
{
glFlush();
glDrawBuffer( GL_BACK );
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
if (colorLogicOp[0])
glEnable (GL_COLOR_LOGIC_OP);
else
glDisable (GL_COLOR_LOGIC_OP);
if (depthTest[0])
glEnable (GL_DEPTH_TEST);
else
glDisable (GL_DEPTH_TEST);
if (lineStipple[0])
glEnable( GL_LINE_STIPPLE );
else
glDisable( GL_LINE_STIPPLE );
}
#endif
const char helpString[] =
"Click with left button or drag with middle button to select";
{
public:
marqueeContext();
private:
void drawMarqueeGL();
void doPressCommon(
MEvent & event );
void doReleaseCommon(
MEvent & event );
short start_x, start_y;
short last_x, last_y;
bool fsDrawn;
};
marqueeContext::marqueeContext()
{
setTitleString ( "Marquee Tool" );
}
void marqueeContext::toolOnSetup (
MEvent & )
{
setHelpString( helpString );
}
void marqueeContext::doPressCommon(
MEvent & event )
{
} else {
}
}
} else {
}
event.getPosition( start_x, start_y );
}
void marqueeContext::doReleaseCommon(
MEvent & event )
{
event.getPosition( last_x, last_y );
if ( abs(start_x - last_x) < 2 && abs(start_y - last_y) < 2 ) {
} else {
}
}
{
doPressCommon( event );
fsDrawn = false;
}
{
#if CUSTOM_XOR_DRAW
xorDraw XORdraw(&view);
XORdraw.beginXorDrawing();
#else
view.beginXorDrawing();
#endif
if (fsDrawn) {
drawMarqueeGL();
}
fsDrawn = true;
event.getPosition( last_x, last_y );
drawMarqueeGL();
#if CUSTOM_XOR_DRAW
XORdraw.endXorDrawing();
#else
view.endXorDrawing();
#endif
}
{
if (fsDrawn) {
#if CUSTOM_XOR_DRAW
xorDraw XORdraw(&view);
XORdraw.beginXorDrawing();
#else
view.beginXorDrawing();
#endif
drawMarqueeGL();
#if CUSTOM_XOR_DRAW
XORdraw.endXorDrawing();
#else
view.endXorDrawing();
#endif
}
doReleaseCommon( event );
}
{
doPressCommon( event );
}
{
doReleaseCommon( event );
}
{
event.getPosition( last_x, last_y );
double len = (last_y - start_y) * (last_y - start_y) +
(last_x - start_x) * (last_x - start_x) * 0.01;
}
{
return setHelpString( helpString );
}
void marqueeContext::drawMarqueeGL()
{
glBegin( GL_LINE_LOOP );
glVertex2i( start_x, start_y );
glVertex2i( last_x, start_y );
glVertex2i( last_x, last_y );
glVertex2i( start_x, last_y );
glEnd();
}
{
public:
marqueeContextCmd();
static void* creator();
};
marqueeContextCmd::marqueeContextCmd() {}
{
return new marqueeContext();
}
void* marqueeContextCmd::creator()
{
return new marqueeContextCmd;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"12.0",
"Any");
status = plugin.registerContextCommand( "marqueeToolContext",
marqueeContextCmd::creator );
return status;
}
{
status = plugin.deregisterContextCommand( "marqueeToolContext" );
return status;
}