#include <wx/cursor.h>
A 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() function is also available for MS Windows use.
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+.
Predefined objects/pointers:
Public Member Functions | |
wxCursor () | |
Default constructor. More... | |
wxCursor (const char bits[], int width, int height, int hotSpotX=-1, int hotSpotY=-1, const char maskBits[]=NULL) | |
Constructs a cursor by passing an array of bits (XBM data). More... | |
wxCursor (const wxString &cursorName, wxBitmapType type=wxCURSOR_DEFAULT_TYPE, int hotSpotX=0, int hotSpotY=0) | |
Constructs a cursor by passing a string resource name or filename. More... | |
wxCursor (wxStockCursor cursorId) | |
Constructs a cursor using a cursor identifier. More... | |
wxCursor (const wxImage &image) | |
Constructs a cursor from a wxImage. More... | |
wxCursor (const wxCursor &cursor) | |
Copy constructor, uses reference counting. More... | |
virtual | ~wxCursor () |
Destroys the cursor. More... | |
virtual bool | IsOk () const |
Returns true if cursor data is present. More... | |
wxCursor & | operator= (const wxCursor &cursor) |
Assignment operator, using reference counting. More... | |
Public Member Functions inherited from wxGDIObject | |
wxGDIObject () | |
Default constructor. More... | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. More... | |
wxObject (const wxObject &other) | |
Copy ctor. More... | |
virtual | ~wxObject () |
Destructor. More... | |
virtual wxClassInfo * | GetClassInfo () const |
This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More... | |
wxObjectRefData * | GetRefData () const |
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More... | |
bool | IsKindOf (const wxClassInfo *info) const |
Determines whether this class is a subclass of (or the same class as) the given class. More... | |
bool | IsSameAs (const wxObject &obj) const |
Returns true if this object has the same data pointer as obj. More... | |
void | Ref (const wxObject &clone) |
Makes this object refer to the data in clone. More... | |
void | SetRefData (wxObjectRefData *data) |
Sets the wxObject::m_refData pointer. More... | |
void | UnRef () |
Decrements the reference count in the associated data, and if it is zero, deletes the data. More... | |
void | UnShare () |
This is the same of AllocExclusive() but this method is public. More... | |
void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More... | |
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from wxObject | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. More... | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More... | |
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More... | |
Protected Attributes inherited from wxObject | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. More... | |
wxCursor::wxCursor | ( | ) |
Default constructor.
wxCursor::wxCursor | ( | const char | bits[], |
int | width, | ||
int | height, | ||
int | hotSpotX = -1 , |
||
int | hotSpotY = -1 , |
||
const char | maskBits[] = NULL |
||
) |
Constructs a cursor by passing an array of bits (XBM data).
The parameters fg and bg have an effect only 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).
bits | An array of XBM data bits. |
width | Cursor width. |
height | Cursor height. |
hotSpotX | Hotspot x coordinate (relative to the top left of the image). |
hotSpotY | Hotspot y coordinate (relative to the top left of the image). |
maskBits | Bits for a mask bitmap. |
wxPerl Note: In wxPerl use Wx::Cursor->newData(bits, width, height, hotSpotX = -1, hotSpotY = -1, maskBits = 0).
wxCursor::wxCursor | ( | const wxString & | cursorName, |
wxBitmapType | type = wxCURSOR_DEFAULT_TYPE , |
||
int | hotSpotX = 0 , |
||
int | hotSpotY = 0 |
||
) |
Constructs a cursor by passing a string resource name or filename.
The arguments hotSpotX and hotSpotY are only used when there's no hotspot info in the resource/image-file to load (e.g. when using wxBITMAP_TYPE_ICO
under wxMSW or wxBITMAP_TYPE_XPM
under wxGTK).
cursorName | The name of the resource or the image file to load. |
type | Icon type to load. It defaults to wxCURSOR_DEFAULT_TYPE , which is a #define associated to different values on different platforms:
|
hotSpotX | Hotspot x coordinate (relative to the top left of the image). |
hotSpotY | Hotspot y coordinate (relative to the top left of the image). |
wxCursor::wxCursor | ( | wxStockCursor | cursorId | ) |
Constructs a cursor using a cursor identifier.
cursorId | A stock cursor identifier. See wxStockCursor. |
wxCursor::wxCursor | ( | const wxImage & | image | ) |
Constructs a cursor from a wxImage.
If cursor are monochrome on the current platform, colors with the RGB elements all greater than 127 will be foreground, colors less than this background. The mask (if any) will be used to specify the transparent area.
In wxMSW the foreground will be white and the background black. If the cursor is larger than 32x32 it is resized.
In wxGTK, colour cursors and alpha channel are supported (starting from GTK+ 2.2). Otherwise the two most frequent colors will be used for foreground and background. In any case, the cursor will be displayed at the size of the image.
Under wxMac (Cocoa), large cursors are supported.
Notice that the image can define the cursor hot spot. To set it you need to use wxImage::SetOption() with wxIMAGE_OPTION_CUR_HOTSPOT_X
or wxIMAGE_OPTION_CUR_HOTSPOT_Y
, e.g.
wxCursor::wxCursor | ( | const wxCursor & | cursor | ) |
Copy constructor, uses reference counting.
cursor | Pointer or reference to a cursor to copy. |
|
virtual |
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.
|
virtual |
Returns true if cursor data is present.
Assignment operator, using reference counting.