updating cursor code from Dave's newer version, fixes #10798
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60761 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -307,40 +307,49 @@ static NSCursor* wxGetStockCursor( short sIndex )
|
|||||||
|
|
||||||
//NSCursor takes an NSImage takes a number of Representations - here
|
//NSCursor takes an NSImage takes a number of Representations - here
|
||||||
//we need only one for the raw data
|
//we need only one for the raw data
|
||||||
NSBitmapImageRep *theRep =
|
NSBitmapImageRep *theRep = [[NSBitmapImageRep alloc]
|
||||||
[[NSBitmapImageRep alloc]
|
initWithBitmapDataPlanes: NULL // Tell Cocoa to allocate the planes for us.
|
||||||
initWithBitmapDataPlanes:nil // Allocate the buffer for us :)
|
pixelsWide: 16 // All classic cursors are 16x16
|
||||||
pixelsWide:16
|
pixelsHigh: 16
|
||||||
pixelsHigh:16
|
bitsPerSample: 1 // All classic cursors are bitmaps with bitmasks
|
||||||
bitsPerSample:1
|
samplesPerPixel: 2 // Sample 0:image 1:mask
|
||||||
samplesPerPixel:2
|
hasAlpha: YES // Identify last sample as a mask
|
||||||
hasAlpha:YES // Well, more like a mask...
|
isPlanar: YES // Use a separate array for each sample
|
||||||
isPlanar:NO
|
colorSpaceName: NSCalibratedWhiteColorSpace // 0.0=black 1.0=white
|
||||||
colorSpaceName:NSCalibratedWhiteColorSpace // Normal B/W - 0 black 1 white
|
bytesPerRow: 2 // Rows in each plane are on 2-byte boundaries (no pad)
|
||||||
bytesPerRow:0 // I don't care - figure it out for me :)
|
bitsPerPixel: 1]; // same as bitsPerSample since data is planar
|
||||||
bitsPerPixel:2]; // bitsPerSample * samplesPerPixel
|
|
||||||
|
|
||||||
//unsigned int is better to put data in then a void*
|
// Ensure that Cocoa allocated 2 and only 2 of the 5 possible planes
|
||||||
//note that working with bitfields would be a lot better here -
|
unsigned char *planes[5];
|
||||||
//but since it breaks some compilers...
|
[theRep getBitmapDataPlanes:planes];
|
||||||
wxUint32 *data = (wxUint32 *)[theRep bitmapData];
|
wxASSERT(planes[0] != NULL);
|
||||||
|
wxASSERT(planes[1] != NULL);
|
||||||
|
wxASSERT(planes[2] == NULL);
|
||||||
|
wxASSERT(planes[3] == NULL);
|
||||||
|
wxASSERT(planes[4] == NULL);
|
||||||
|
|
||||||
//traverse through the bitmap data
|
// NOTE1: The Cursor's bits field is white=0 black=1.. thus the bitwise-not
|
||||||
for (int i = 0; i < 16; ++i)
|
// Why not use NSCalibratedBlackColorSpace? Because that reverses the
|
||||||
|
// sense of the alpha (mask) plane.
|
||||||
|
// NOTE2: The mask data is 0=off 1=on
|
||||||
|
// NOTE3: Cocoa asks for "premultiplied" color planes. Since we have a
|
||||||
|
// 1-bit color plane and a 1-bit alpha plane we can just do a bitwise-and
|
||||||
|
// on the two. The original cursor bitmaps have 0 (white actually) for
|
||||||
|
// any masked-off pixels. Therefore every masked-off pixel would be wrong
|
||||||
|
// since we bit-flip all of the picture bits. In practice, Cocoa doesn't
|
||||||
|
// seem to care, but we are following the documentation.
|
||||||
|
|
||||||
|
// Fill in the color (black/white) plane
|
||||||
|
for(int i=0; i<16; ++i)
|
||||||
{
|
{
|
||||||
//bit alpha bit alpha ... :D
|
planes[0][2*i ] = (~pCursor->bits[i] & pCursor->mask[i]) >> 8 & 0xff;
|
||||||
|
planes[0][2*i+1] = (~pCursor->bits[i] & pCursor->mask[i]) & 0xff;
|
||||||
//Notice the = instead of |= -
|
}
|
||||||
//this is to avoid doing a memset earlier
|
// Fill in the alpha (i.e. mask) plane
|
||||||
data[i] = 0;
|
for(int i=0; i<16; ++i)
|
||||||
|
{
|
||||||
//do the rest of those bits and alphas :)
|
planes[1][2*i ] = pCursor->mask[i] >> 8 & 0xff;
|
||||||
for (int shift = 0; shift < 32; ++shift)
|
planes[1][2*i+1] = pCursor->mask[i] & 0xff;
|
||||||
{
|
|
||||||
const int bit = 1 << (shift >> 1);
|
|
||||||
data[i] |= ( !!( (pCursor->mask[i] & bit) ) ) << shift;
|
|
||||||
data[i] |= ( !( (pCursor->bits[i] & bit) ) ) << ++shift;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the representation (data) to the image
|
//add the representation (data) to the image
|
||||||
|
Reference in New Issue
Block a user