@@ -808,7 +808,7 @@ - (NSRect)mapMCRectangleToNSRect: (MCRectangle)r
808808 [m_window_handle setContentView: m_view];
809809
810810 [m_window_handle setLevel: t_window_level];
811- [m_window_handle setOpaque: m_mask ! = nil ];
811+ [m_window_handle setOpaque: m_mask = = nil ];
812812 [m_window_handle setHasShadow: m_has_shadow];
813813 if (!m_has_zoom_widget)
814814 [[m_window_handle standardWindowButton: NSWindowZoomButton] setEnabled: NO ];
@@ -853,7 +853,7 @@ - (NSRect)mapMCRectangleToNSRect: (MCRectangle)r
853853
854854 if (m_changes . mask_changed)
855855 {
856- [m_window_handle setOpaque: m_mask ! = nil ];
856+ [m_window_handle setOpaque: m_mask = = nil ];
857857 if (m_has_shadow)
858858 m_shadow_changed = true ;
859859 }
@@ -1002,18 +1002,57 @@ - (NSRect)mapMCRectangleToNSRect: (MCRectangle)r
10021002
10031003// //////////////////////////////////////////////////////////////////////////////
10041004
1005- // COCOA-TODO: Implement window masks.
1005+ static bool MCAlphaToCGImage (uindex_t p_width, uindex_t p_height, uint8_t * p_data, uindex_t p_stride, CGImageRef &r_image)
1006+ {
1007+ bool t_success = true ;
1008+
1009+ CGImageRef t_image = nil ;
1010+ CGColorSpaceRef t_colorspace = nil ;
1011+ CFDataRef t_data = nil ;
1012+ CGDataProviderRef t_dp = nil ;
1013+
1014+ if (t_success)
1015+ t_success = nil != (t_data = CFDataCreate (kCFAllocatorDefault , (uint8_t *)p_data, p_stride * p_height));
1016+
1017+ if (t_success)
1018+ t_success = nil != (t_dp = CGDataProviderCreateWithCFData (t_data));
1019+
1020+ if (t_success)
1021+ t_success = nil != (t_colorspace = CGColorSpaceCreateDeviceGray ());
1022+
1023+ if (t_success)
1024+ t_success = nil != (t_image = CGImageCreate (p_width, p_height, 8 , 8 , p_stride, t_colorspace, kCGImageAlphaNone , t_dp, nil , false , kCGRenderingIntentDefault ));
1025+
1026+ CGColorSpaceRelease (t_colorspace);
1027+ CGDataProviderRelease (t_dp);
1028+ CFRelease (t_data);
1029+
1030+ if (t_success)
1031+ r_image = t_image;
1032+
1033+ return t_success;
1034+ }
1035+
10061036void MCPlatformWindowMaskCreate (int32_t p_width, int32_t p_height, int32_t p_stride, void *p_bits, MCPlatformWindowMaskRef& r_mask)
10071037{
1008- r_mask = nil ;
1038+ CGImageRef t_mask;
1039+ t_mask = nil ;
1040+ MCAlphaToCGImage (p_width, p_height, (uint8_t *)p_bits, p_stride, t_mask);
1041+ r_mask = (MCPlatformWindowMaskRef)t_mask;
10091042}
10101043
10111044void MCPlatformWindowMaskRetain (MCPlatformWindowMaskRef p_mask)
10121045{
1046+ CGImageRef t_mask;
1047+ t_mask = (CGImageRef)p_mask;
1048+ CGImageRetain (t_mask);
10131049}
10141050
10151051void MCPlatformWindowMaskRelease (MCPlatformWindowMaskRef p_mask)
10161052{
1053+ CGImageRef t_mask;
1054+ t_mask = (CGImageRef)p_mask;
1055+ CGImageRelease (t_mask);
10171056}
10181057
10191058// //////////////////////////////////////////////////////////////////////////////
0 commit comments