wxcursora cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that might indicate the interpretation of a mouse click. as with icons, cursors in x and ms windows are created in a different manner. therefore, separate cursors will be created for the different environments. platform-specific methods for creating a wxcursor object are catered for, and this is an occasion where conditional compilation will probably be required (see wxicon for an example). a single cursor object may be used in many windows (any subwindow type). the wxwidgets convention is to set the cursor for a window, as in x, rather than to set it globally as in ms windows, although a global ::wxsetcursor is also available for ms windows use. derived from include files <wx/cursor.h> predefined objects objects: wxnullcursor pointers:
wxstandard_cursor see also wxbitmap, wxicon, wxwindow::setcursor, ::wxsetcursor members
wxcursor::wxcursor
wxcursor::wxcursorwxcursor() default constructor. wxcursor(const char bits[], int width, int height, int hotspotx=-1, int hotspoty=-1, const char maskbits[]=null, wxcolour* fg=null, wxcolour* bg=null) constructs a cursor by passing an array of bits (motif and gtk+ only). maskbits is used only under motif and gtk+. the parameters fg and bg are only present on gtk+, and force the cursor to use particular background and foreground colours. if either hotspotx or hotspoty is -1, the hotspot will be the centre of the cursor image (motif only). wxcursor(const wxstring& cursorname, long type, int hotspotx=0, int hotspoty=0) constructs a cursor by passing a string resource name or filename. on macos when specifying a string resource name, first the color cursors 'crsr' and then the black/white cursors 'curs' in the resource chain are scanned through. hotspotx and hotspoty are currently only used under windows when loading from an icon file, to specify the cursor hotspot relative to the top left of the image. wxcursor(int cursorid) constructs a cursor using a cursor identifier. wxcursor(const wximage& image) constructs a cursor from a wximage. the cursor is monochrome, colors with the rgb elements all greater than 127 will be foreground, colors less than this background. the mask (if any) will be used as transparent. in msw the foreground will be white and the background black. if the cursor is larger than 32x32 it is resized. in gtk, the two most frequent colors will be used for foreground and background. the cursor will be displayed at the size of the image. on macos if the cursor is larger than 16x16 it is resized and currently only shown as black/white (mask respected). wxcursor(const wxcursor& cursor) copy constructor, uses reference counting. parameters bits
maskbits
width
height
hotspotx
hotspoty
type
under x, the permitted cursor types are:
under windows, the permitted types are:
cursorid
note that not all cursors are available on all platforms. cursor
wxpython note: constructors supported by wxpython are:
wxperl note: constructors supported by wxperl are:
example the following is an example of creating a cursor from 32x32 bitmap data (down_bits) and a mask (down_mask) where 1 is black and 0 is white for the bits, and 1 is opaque and 0 is transparent for the mask. it works on windows and gtk+.
static char down_bits[] = { 255, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243, 255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254, 255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; static char down_mask[] = { 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255, 31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0, 240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #ifdef __wxmsw__ wxbitmap down_bitmap(down_bits, 32, 32); wxbitmap down_mask_bitmap(down_mask, 32, 32); down_bitmap.setmask(new wxmask(down_mask_bitmap)); wximage down_image = down_bitmap.converttoimage(); down_image.setoption(wximage_option_cur_hotspot_x, 6); down_image.setoption(wximage_option_cur_hotspot_y, 14); wxcursor down_cursor = wxcursor(down_image); #else wxcursor down_cursor = wxcursor(down_bits, 32, 32, 6, 14, down_mask, wxwhite, wxblack); #endif wxcursor::~wxcursor~wxcursor() destroys the cursor. see reference-counted object destruction for more info. a cursor can be reused for more than one window, and does not get destroyed when the window is destroyed. wxwidgets destroys all cursors on application exit, although it is best to clean them up explicitly.
wxcursor::isokbool isok() const returns true if cursor data is present.
wxcursor::operator =wxcursor& operator =(const wxcursor& cursor) assignment operator, using reference counting.
|