To create a custom cursor when using MPxContext::SetCursor, a cursor requires two XBM images: one for the mask, which defines which bits are transparent and which opaque, and one for the color, which defines which bits are white and which are black.
If you look at an XBM image file you'll see that it's just a snippet of C code which defines macros giving the width and height of the image, and an array of unsigned char. E.g:
#define HtumbleCursorMask_width 16
#define HtumbleCursorMask_height 16
static unsigned char HtumbleCursorMask_bits[] = {
0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0xdf, 0xf8, 0xff, 0x3c, 0xf8, 0x1e, 0xf8,
0x1e, 0xfc, 0x00, 0xfc, 0x7e, 0x00, 0x7e, 0xf0, 0x3e, 0xf0, 0x3e, 0x78,
0xfe, 0x3f, 0xf6, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, };
So you can include the two XBM image files directly into the C++ source for your plug-in, and then pass the sizes and arrays to the MCursor constructor.
This will only work if the XBM image is known at compile time and doesn't change. If you want to dynamically create a cursor at runtime from an arbitrary pair of XBM files then you would have to either write some code to parse the information from the files or find a library routine to do it for you. It's probably possible to do it with the Qt's image classes (QImage, QBitmap, QPixmap) but I haven't tried it myself.
One suggestion I have heard is overriding an existing cursor by replacing the contents of the header files, however this will not work for these reasons:
1) The header files were only read when Maya was built, not at runTime. They're not even shipped to you.
2) Since the switch to Qt we no longer use those XBM files for cursors. Instead we use PNG files. There should be a constructor for MCursor which takes a PNG file, but we don't yet have that.
3) Even the PNG files which Maya now uses are only used when Maya is built and do not get shipped to you. Their contents are embedded into a Qt resource file. So overriding the PNGs won't work, either.
An example of a custom cursor is in the Devkit sample lassoTool.
Here is the required XBM information:
Files used for:
Cursors
File Format:
xbm
Requirements:
16x16
transparent background
Created with this application:
xpaint
Naming conventions:
H<name>Cursor.h
H<name>CursorMask.h
Where used:
Mouse pointer
Enjoy,
Kristine
Comments
You can follow this conversation by subscribing to the comment feed for this post.