mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 23:06:54 +08:00
Use the [NSimage initWithCGImage:size:] message when possible.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9907 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+25
-19
@@ -2960,19 +2960,30 @@ void Fl_X::collapse() {
|
|||||||
static NSImage *CGBitmapContextToNSImage(CGContextRef c)
|
static NSImage *CGBitmapContextToNSImage(CGContextRef c)
|
||||||
// the returned NSImage is autoreleased
|
// the returned NSImage is autoreleased
|
||||||
{
|
{
|
||||||
unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c);
|
NSImage* image;
|
||||||
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
|
||||||
pixelsWide:CGBitmapContextGetWidth(c)
|
if (fl_mac_os_version >= 100600) {
|
||||||
pixelsHigh:CGBitmapContextGetHeight(c)
|
CGImageRef cgimg = CGBitmapContextCreateImage(c); // requires 10.4
|
||||||
bitsPerSample:8
|
image = [[NSImage alloc] initWithCGImage:cgimg size:NSZeroSize]; // requires 10.6
|
||||||
samplesPerPixel:4
|
CFRelease(cgimg);
|
||||||
hasAlpha:YES
|
}
|
||||||
isPlanar:NO
|
else
|
||||||
colorSpaceName:NSDeviceRGBColorSpace
|
#endif
|
||||||
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
{
|
||||||
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
unsigned char *pdata = (unsigned char *)CGBitmapContextGetData(c);
|
||||||
NSImage* image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]];
|
NSBitmapImageRep *imagerep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&pdata
|
||||||
[imagerep release];
|
pixelsWide:CGBitmapContextGetWidth(c)
|
||||||
|
pixelsHigh:CGBitmapContextGetHeight(c)
|
||||||
|
bitsPerSample:8
|
||||||
|
samplesPerPixel:4
|
||||||
|
hasAlpha:YES
|
||||||
|
isPlanar:NO
|
||||||
|
colorSpaceName:NSDeviceRGBColorSpace
|
||||||
|
bytesPerRow:CGBitmapContextGetBytesPerRow(c)
|
||||||
|
bitsPerPixel:CGBitmapContextGetBitsPerPixel(c)];
|
||||||
|
image = [[NSImage alloc] initWithData: [imagerep TIFFRepresentation]];
|
||||||
|
[imagerep release];
|
||||||
|
}
|
||||||
return [image autorelease];
|
return [image autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3275,12 +3286,7 @@ int Fl::dnd(void)
|
|||||||
[mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"];
|
[mypasteboard setData:(NSData*)text forType:@"public.utf8-plain-text"];
|
||||||
CFRelease(text);
|
CFRelease(text);
|
||||||
Fl_Widget *w = Fl::pushed();
|
Fl_Widget *w = Fl::pushed();
|
||||||
Fl_Window *win = w->window();
|
Fl_Window *win = w->top_window();
|
||||||
if (win == NULL) {
|
|
||||||
win = (Fl_Window*)w;
|
|
||||||
} else {
|
|
||||||
while(win->window()) win = win->window();
|
|
||||||
}
|
|
||||||
NSView *myview = [Fl_X::i(win)->xid contentView];
|
NSView *myview = [Fl_X::i(win)->xid contentView];
|
||||||
NSEvent *theEvent = [NSApp currentEvent];
|
NSEvent *theEvent = [NSApp currentEvent];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user