2013-03-15 13:11:33 +00:00
|
|
|
NSImage* NSMakeImage(nall::image image, unsigned width = 0, unsigned height = 0) {
|
|
|
|
if(image.empty()) return nil;
|
|
|
|
if(width && height) image.scale(width, height, Interpolation::Linear);
|
|
|
|
image.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16);
|
2013-05-02 11:25:45 +00:00
|
|
|
NSImage* cocoaImage = [[[NSImage alloc] initWithSize:NSMakeSize(image.width, image.height)] autorelease];
|
|
|
|
NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
|
2013-03-15 13:11:33 +00:00
|
|
|
initWithBitmapDataPlanes:nil
|
|
|
|
pixelsWide:image.width pixelsHigh:image.height
|
|
|
|
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES
|
|
|
|
isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace
|
|
|
|
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
|
|
|
|
bytesPerRow:image.pitch bitsPerPixel:32
|
|
|
|
] autorelease];
|
|
|
|
memcpy([bitmap bitmapData], image.data, image.height * image.pitch);
|
|
|
|
[cocoaImage addRepresentation:bitmap];
|
|
|
|
return cocoaImage;
|
|
|
|
}
|
2013-07-29 09:42:45 +00:00
|
|
|
|
|
|
|
NSDragOperation DropPathsOperation(id<NSDraggingInfo> sender) {
|
|
|
|
NSPasteboard* pboard = [sender draggingPasteboard];
|
|
|
|
if([[pboard types] containsObject:NSFilenamesPboardType]) {
|
|
|
|
if([sender draggingSourceOperationMask] & NSDragOperationGeneric) {
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstring DropPaths(id<NSDraggingInfo> sender) {
|
|
|
|
lstring paths;
|
|
|
|
NSPasteboard* pboard = [sender draggingPasteboard];
|
|
|
|
if([[pboard types] containsObject:NSFilenamesPboardType]) {
|
|
|
|
NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
for(unsigned n = 0; n < [files count]; n++) {
|
|
|
|
string path = [[files objectAtIndex:n] UTF8String];
|
2013-12-03 10:01:59 +00:00
|
|
|
if(directory::exists(path) && !path.endsWith("/")) path.append("/");
|
2013-07-29 09:42:45 +00:00
|
|
|
paths.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return paths;
|
|
|
|
}
|