summaryrefslogtreecommitdiff
path: root/macosx/Pcsxr-QL
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-07-22 02:13:38 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-07-22 02:13:38 +0000
commitd801c00dc645ff2745e06958f0a0971700296424 (patch)
treeada4dbfd4cf26322953130ed975be72e7a25b789 /macosx/Pcsxr-QL
parentaf3fc7e2a047dff37690d041489db41e8cf02eee (diff)
OS X: Generate a thumbnail image for a memory card file.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@91028 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/Pcsxr-QL')
-rw-r--r--macosx/Pcsxr-QL/GenerateThumbnailForURL.m65
1 files changed, 64 insertions, 1 deletions
diff --git a/macosx/Pcsxr-QL/GenerateThumbnailForURL.m b/macosx/Pcsxr-QL/GenerateThumbnailForURL.m
index 2e84f4a6..3a61afb9 100644
--- a/macosx/Pcsxr-QL/GenerateThumbnailForURL.m
+++ b/macosx/Pcsxr-QL/GenerateThumbnailForURL.m
@@ -13,6 +13,8 @@
This function's job is to create thumbnail for designated file as fast as possible
----------------------------------------------------------------------------- */
+#define ImageDivider 16
+
static OSStatus GenerateThumbnailForFreeze(void *thisInterface, QLThumbnailRequestRef preview, NSURL *url, NSDictionary *options, CGSize maxSize);
static OSStatus GenerateThumbnailForMemCard(void *thisInterface, QLThumbnailRequestRef preview, NSURL *url, NSDictionary *options, CGSize maxSize);
@@ -92,8 +94,69 @@ OSStatus GenerateThumbnailForFreeze(void *thisInterface, QLThumbnailRequestRef t
#endif
}
+static NSImage *MemoryImageAtIndex(NSArray *memArray, NSInteger my)
+{
+ NSInteger i = 0;
+ for (PcsxrMemoryObject *obj in memArray) {
+ NSIndexSet *idxSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(i, obj.blockSize)];
+ if ([idxSet containsIndex:my]) {
+ return obj.firstMemImage;
+ }
+ i += obj.blockSize;
+ }
+
+ return nil;
+}
+
OSStatus GenerateThumbnailForMemCard(void *thisInterface, QLThumbnailRequestRef thumbnail, NSURL *url, NSDictionary *options, CGSize maxSize)
{
- //NSArray *memCards = CreateArrayByEnumeratingMemoryCardAtURL(url);
+ NSArray *memCards = CreateArrayByEnumeratingMemoryCardAtURL(url);
+ if (!memCards) {
+ return noErr;
+ }
+
+ NSBundle *Bundle;
+ {
+ CFBundleRef cfbundle = QLThumbnailRequestGetGeneratorBundle(thumbnail);
+ NSURL *bundURL = CFBridgingRelease(CFBundleCopyBundleURL(cfbundle));
+ Bundle = [[NSBundle alloc] initWithURL:bundURL];
+ }
+
+ NSRect imageRect = NSMakeRect(0, 0, ImageDivider, ImageDivider);
+ NSImage *blankImage = [[NSImage alloc] initWithSize:imageRect.size];
+ [blankImage lockFocus];
+ [[NSColor blackColor] set];
+ [NSBezierPath fillRect:imageRect];
+ [blankImage unlockFocus];
+
+ NSImage *memImages = [[NSImage alloc] initWithSize:NSMakeSize((4 * ImageDivider), (4 * ImageDivider))];
+
+ NSInteger allMems = 0;
+ for (PcsxrMemoryObject *obj in memCards) {
+ allMems += obj.blockSize;
+ }
+ [memImages lockFocus];
+ [[NSColor clearColor] set];
+ [NSBezierPath fillRect:NSMakeRect(0, 0, (4 * ImageDivider), (4 * ImageDivider))];
+ for (int i = 1; i < 16; i++) {
+ NSInteger x = (i % 4) * ImageDivider, y = (3 * ImageDivider) - ((i / 4) * ImageDivider);
+ NSImage *curImage;
+ if (i < allMems) {
+ curImage = MemoryImageAtIndex(memCards, i - 1);
+ } else {
+ curImage = blankImage;
+ }
+ [curImage drawInRect:NSMakeRect(x, y, ImageDivider, ImageDivider) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
+ }
+ NSURL *psxMemURL = [Bundle URLForResource:@"pcsxrmemcard" withExtension:@"icns"];
+ NSImage *psxMemIcon = [[NSImage alloc] initByReferencingURL:psxMemURL];
+ psxMemIcon.size = NSMakeSize(ImageDivider, ImageDivider);
+ [psxMemIcon drawInRect:NSMakeRect(0, 3 * ImageDivider, ImageDivider, ImageDivider) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
+
+ [memImages unlockFocus];
+
+ NSData *data = [memImages TIFFRepresentation];
+ QLThumbnailRequestSetImageWithData(thumbnail, (__bridge CFDataRef)(data), NULL);
+
return noErr;
}