Debian Codegraph @

phoenix/cocoa/utility.cpp

raw
1 NSImage* NSMakeImage(nall::image image, unsigned width = 0, unsigned height = 0) {
2 if(image.empty()) return nil;
3 if(width && height) image.scale(width, height, Interpolation::Linear);
4 image.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16);
5 NSImage* cocoaImage = [[[NSImage alloc] initWithSize:NSMakeSize(image.width, image.height)] autorelease];
6 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc]
7 initWithBitmapDataPlanes:nil
8 pixelsWide:image.width pixelsHigh:image.height
9 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES
10 isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace
11 bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
12 bytesPerRow:image.pitch bitsPerPixel:32
13 ] autorelease];
14 memcpy([bitmap bitmapData], image.data, image.height * image.pitch);
15 [cocoaImage addRepresentation:bitmap];
16 return cocoaImage;
17 }
18
19 NSDragOperation DropPathsOperation(id<NSDraggingInfo> sender) {
20 NSPasteboard* pboard = [sender draggingPasteboard];
21 if([[pboard types] containsObject:NSFilenamesPboardType]) {
22 if([sender draggingSourceOperationMask] & NSDragOperationGeneric) {
23 return NSDragOperationGeneric;
24 }
25 }
26 return NSDragOperationNone;
27 }
28
29 lstring DropPaths(id<NSDraggingInfo> sender) {
30 lstring paths;
31 NSPasteboard* pboard = [sender draggingPasteboard];
32 if([[pboard types] containsObject:NSFilenamesPboardType]) {
33 NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
34 for(unsigned n = 0; n < [files count]; n++) {
35 string path = [[files objectAtIndex:n] UTF8String];
36 if(directory::exists(path) && !path.endsWith("/")) path.append("/");
37 paths.append(path);
38 }
39 }
40 return paths;
41 }