+wxCursor::wxCursor( const wxImage &image )
+{
+ CreateFromImage( image ) ;
+}
+
+void wxCursor::CreateFromImage(const wxImage & image)
+{
+ m_refData = new wxCursorRefData;
+
+ wxImage image16 = image.Scale(16,16) ;
+ unsigned char * rgbBits = image16.GetData();
+
+
+ int w = image16.GetWidth() ;
+ int h = image16.GetHeight() ;
+ bool bHasMask = image16.HasMask() ;
+
+ int hotSpotX = image16.GetOptionInt(wxCUR_HOTSPOT_X);
+ int hotSpotY = image16.GetOptionInt(wxCUR_HOTSPOT_Y);
+ if (hotSpotX < 0 || hotSpotX >= w)
+ hotSpotX = 0;
+ if (hotSpotY < 0 || hotSpotY >= h)
+ hotSpotY = 0;
+
+ M_CURSORDATA->m_hCursor = NewHandle( sizeof( Cursor ) ) ;
+ M_CURSORDATA->m_disposeHandle = true ;
+ HLock( (Handle) M_CURSORDATA->m_hCursor ) ;
+ CursPtr cp = *(CursHandle)M_CURSORDATA->m_hCursor ;
+ memset( cp->data , 0 , sizeof( Bits16 ) ) ;
+ memset( cp->mask , 0 , sizeof( Bits16 ) ) ;
+
+ unsigned char mr = image16.GetMaskRed() ;
+ unsigned char mg = image16.GetMaskGreen() ;
+ unsigned char mb = image16.GetMaskBlue() ;
+ for ( int y = 0 ; y < h ; ++y )
+ {
+ short rowbits = 0 ;
+ short maskbits = 0 ;
+
+ for ( int x = 0 ; x < w ; ++x )
+ {
+ long pos = (y * w + x) * 3;
+
+ unsigned char r = rgbBits[pos] ;
+ unsigned char g = rgbBits[pos+1] ;
+ unsigned char b = rgbBits[pos+2] ;
+ if ( bHasMask && r==mr && g==mg && b==mb )
+ {
+ // masked area, does not appear anywhere
+ }
+ else
+ {
+ if ( (int)r + (int)g + (int)b < 0x60 )
+ {
+ rowbits |= ( 1 << (15-x) ) ;
+ }
+ maskbits |= ( 1 << (15-x) ) ;
+ }
+ }
+ cp->data[y] = rowbits ;
+ cp->mask[y] = maskbits ;
+ }
+ if ( !bHasMask )
+ {
+ memcpy( cp->mask , cp->data , sizeof( Bits16) ) ;
+ }
+
+ cp->hotSpot.h = hotSpotX ;
+ cp->hotSpot.v = hotSpotY ;
+ HUnlock( (Handle) M_CURSORDATA->m_hCursor ) ;
+}
+