Skip to content

Commit

Permalink
One more NSCollectionView instead of IKImageBrowserView.
Browse files Browse the repository at this point in the history
  • Loading branch information
uliwitness committed Oct 28, 2018
1 parent 9297088 commit 71a42cb
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 127 deletions.
185 changes: 94 additions & 91 deletions Stacksmith/Platforms/Mac/WILDMediaListDataSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ -(void) setSelectedIconID: (ObjectID)theID
{
[self ensureIconListExists];

NSInteger x = 0;
NSUInteger x = 0;
for( WILDSimpleImageBrowserItem* sibi in mIcons )
{
if( sibi.pictureID == theID )
{
[mIconListView selectItemsAtIndexPaths: [NSIndexPath indexPathWithIndexes: x] scrollPosition: NSCollectionViewScrollPositionCenteredVertically];
NSUInteger objectPath[2] = { 0, x };
[mIconListView selectItemsAtIndexPaths: [NSSet setWithObject: [NSIndexPath indexPathWithIndexes: objectPath length: sizeof(objectPath) / sizeof(NSInteger)]] scrollPosition: NSCollectionViewScrollPositionCenteredVertically];
break;
}
x++;
Expand All @@ -241,7 +242,9 @@ -(NSInteger) collectionView: (NSCollectionView *)collectionView numberOfItemsInS

- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
[mIcons objectAtIndex: [indexPath indexAtPosition: 1]];
NSCollectionViewItem *theItem = [collectionView makeItemWithIdentifier: @"MediaItem" forIndexPath: indexPath];
theItem.representedObject = [mIcons objectAtIndex: [indexPath indexAtPosition: 1]];
return theItem;
}


Expand Down Expand Up @@ -316,93 +319,93 @@ -(IBAction) paste: (id)sender
//{
//
//}


- (NSDragOperation)draggingEntered: (id <NSDraggingInfo>)sender
{
return [self draggingUpdated: sender];
}


- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSPasteboard* pb = [sender draggingPasteboard];
if( [pb canReadObjectForClasses: [NSArray arrayWithObject: [NSURL class]] options: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], NSPasteboardURLReadingFileURLsOnlyKey, [NSArray arrayWithObject: @"public.image"], NSPasteboardURLReadingContentsConformToTypesKey, nil]] )
{
[mIconListView setDropIndex: -1 dropOperation: IKImageBrowserDropOn];
return NSDragOperationCopy;
}
else
return NSDragOperationNone;
}


- (BOOL)performDragOperation: (id <NSDraggingInfo>)sender
{
ObjectID iconToSelect = 0;
NSPasteboard* pb = [sender draggingPasteboard];
NSArray * urls = [pb readObjectsForClasses: [NSArray arrayWithObject: [NSURL class]] options: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], NSPasteboardURLReadingFileURLsOnlyKey, [NSArray arrayWithObject: @"public.image"], NSPasteboardURLReadingContentsConformToTypesKey, nil]];
if( urls.count > 0 )
{
for( NSURL* theImgFile in urls )
{
NSImage * theImg = [[[NSImage alloc] initWithContentsOfURL: theImgFile] autorelease];
NSString* pictureName = [[NSFileManager defaultManager] displayNameAtPath: [theImgFile path]];
ObjectID pictureID = mDocument->GetMediaCache().GetUniqueIDForMedia();
std::string filePath = mDocument->GetMediaCache().AddMediaWithIDTypeNameSuffixHotSpotIsBuiltInReturningURL( pictureID, mMediaType, [pictureName UTF8String], "png" );
NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()];
NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr];
CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil];
NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef];
NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}];
[pngData writeToURL: imgFileURL atomically: YES];
WILDSimpleImageBrowserItem *sibi = [[[WILDSimpleImageBrowserItem alloc] init] autorelease];
sibi.name = pictureName;
sibi.filename = imgFileURLStr;
sibi.pictureID = pictureID;
sibi.image = theImg;
sibi.owner = self;
[mIcons addObject: sibi];
iconToSelect = pictureID;
}
}
else
{
NSArray* images = [pb readObjectsForClasses: [NSArray arrayWithObject: [NSImage class]] options:[NSDictionary dictionary]];
for( NSImage* theImg in images )
{
NSString* pictureName = @"Dropped Image";
ObjectID pictureID = mDocument->GetMediaCache().GetUniqueIDForMedia();
std::string filePath = mDocument->GetMediaCache().AddMediaWithIDTypeNameSuffixHotSpotIsBuiltInReturningURL( pictureID, mMediaType, [pictureName UTF8String], "png" );
NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()];
NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr];
CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil];
NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef];
NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}];
[pngData writeToURL: imgFileURL atomically: YES];
WILDSimpleImageBrowserItem *sibi = [[[WILDSimpleImageBrowserItem alloc] init] autorelease];
sibi.name = pictureName;
sibi.filename = imgFileURLStr;
sibi.pictureID = pictureID;
sibi.image = theImg;
sibi.owner = self;
[mIcons addObject: sibi];
iconToSelect = pictureID;
}
}
[mIconListView reloadData];
if( iconToSelect != 0 )
[self setSelectedIconID: iconToSelect];
return( urls != 0 && [urls count] > 0 );
}
//
//
//- (NSDragOperation)draggingEntered: (id <NSDraggingInfo>)sender
//{
// return [self draggingUpdated: sender];
//}
//
//
//- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
//{
// NSPasteboard* pb = [sender draggingPasteboard];
// if( [pb canReadObjectForClasses: [NSArray arrayWithObject: [NSURL class]] options: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], NSPasteboardURLReadingFileURLsOnlyKey, [NSArray arrayWithObject: @"public.image"], NSPasteboardURLReadingContentsConformToTypesKey, nil]] )
// {
// [mIconListView setDropIndex: -1 dropOperation: IKImageBrowserDropOn];
//
// return NSDragOperationCopy;
// }
// else
// return NSDragOperationNone;
//}
//
//
//- (BOOL)performDragOperation: (id <NSDraggingInfo>)sender
//{
// ObjectID iconToSelect = 0;
// NSPasteboard* pb = [sender draggingPasteboard];
// NSArray * urls = [pb readObjectsForClasses: [NSArray arrayWithObject: [NSURL class]] options: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: YES], NSPasteboardURLReadingFileURLsOnlyKey, [NSArray arrayWithObject: @"public.image"], NSPasteboardURLReadingContentsConformToTypesKey, nil]];
//
// if( urls.count > 0 )
// {
// for( NSURL* theImgFile in urls )
// {
// NSImage * theImg = [[[NSImage alloc] initWithContentsOfURL: theImgFile] autorelease];
// NSString* pictureName = [[NSFileManager defaultManager] displayNameAtPath: [theImgFile path]];
// ObjectID pictureID = mDocument->GetMediaCache().GetUniqueIDForMedia();
//
// std::string filePath = mDocument->GetMediaCache().AddMediaWithIDTypeNameSuffixHotSpotIsBuiltInReturningURL( pictureID, mMediaType, [pictureName UTF8String], "png" );
// NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()];
// NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr];
//
// CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil];
// NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef];
// NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}];
// [pngData writeToURL: imgFileURL atomically: YES];
//
// WILDSimpleImageBrowserItem *sibi = [[[WILDSimpleImageBrowserItem alloc] init] autorelease];
// sibi.name = pictureName;
// sibi.filename = imgFileURLStr;
// sibi.pictureID = pictureID;
// sibi.image = theImg;
// sibi.owner = self;
// [mIcons addObject: sibi];
// iconToSelect = pictureID;
// }
// }
// else
// {
// NSArray* images = [pb readObjectsForClasses: [NSArray arrayWithObject: [NSImage class]] options:[NSDictionary dictionary]];
// for( NSImage* theImg in images )
// {
// NSString* pictureName = @"Dropped Image";
// ObjectID pictureID = mDocument->GetMediaCache().GetUniqueIDForMedia();
//
// std::string filePath = mDocument->GetMediaCache().AddMediaWithIDTypeNameSuffixHotSpotIsBuiltInReturningURL( pictureID, mMediaType, [pictureName UTF8String], "png" );
// NSString* imgFileURLStr = [NSString stringWithUTF8String: filePath.c_str()];
// NSURL* imgFileURL = [NSURL URLWithString: imgFileURLStr];
//
// CGImageRef imageRef = [theImg CGImageForProposedRect:NULL context:NULL hints:nil];
// NSBitmapImageRep *bir = [[NSBitmapImageRep alloc] initWithCGImage: imageRef];
// NSData * pngData = [bir representationUsingType: NSBitmapImageFileTypePNG properties: @{}];
// [pngData writeToURL: imgFileURL atomically: YES];
//
// WILDSimpleImageBrowserItem *sibi = [[[WILDSimpleImageBrowserItem alloc] init] autorelease];
// sibi.name = pictureName;
// sibi.filename = imgFileURLStr;
// sibi.pictureID = pictureID;
// sibi.image = theImg;
// sibi.owner = self;
// [mIcons addObject: sibi];
// iconToSelect = pictureID;
// }
// }
// [mIconListView reloadData];
// if( iconToSelect != 0 )
// [self setSelectedIconID: iconToSelect];
//
// return( urls != 0 && [urls count] > 0 );
//}

@end
98 changes: 62 additions & 36 deletions Stacksmith/Platforms/Mac/WILDMediaPickerViewController.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<plugIn identifier="com.apple.imagekit.ibplugin" version="11762"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -14,58 +12,86 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="1">
<rect key="frame" x="0.0" y="0.0" width="414" height="328"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="136.75" horizontalPageScroll="10" verticalLineScroll="140" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="3">
<rect key="frame" x="20" y="43" width="374" height="265"/>
<textField verticalHuggingPriority="750" id="4">
<rect key="frame" x="17" y="20" width="380" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" copiesOnScroll="NO" id="Kxb-0F-V87">
<rect key="frame" x="1" y="1" width="372" height="263"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Built-in" id="5">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<scrollView wantsLayer="YES" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="kY9-D8-S0k">
<rect key="frame" x="20" y="42" width="375" height="266"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" id="VFY-jQ-48s">
<rect key="frame" x="1" y="1" width="373" height="264"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<ikImageBrowserView autoresizesSubviews="NO" zoomValue="0.23635973036289215" constrainsToOriginalSize="YES" allowsMultipleSelection="NO" animates="YES" id="6">
<rect key="frame" x="0.0" y="0.0" width="372" height="263"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<ikCellsStyle key="cellsStyleMask" titled="YES"/>
<autoresizingMask key="contentResizingMask" heightSizable="YES"/>
<size key="cellSize" width="54" height="54"/>
<connections>
<outlet property="dataSource" destination="9" id="12"/>
<outlet property="delegate" destination="9" id="13"/>
<outlet property="dragDestinationDelegate" destination="9" id="14"/>
</connections>
</ikImageBrowserView>
<collectionView id="6f5-YX-a0M">
<rect key="frame" x="0.0" y="0.0" width="373" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="BF9-Z5-bRO">
<size key="itemSize" width="50" height="50"/>
</collectionViewFlowLayout>
<color key="primaryBackgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</collectionView>
</subviews>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="7">
<rect key="frame" x="-100" y="-100" width="451" height="15"/>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="tSm-Vo-fx0">
<rect key="frame" x="1" y="144" width="233" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="8">
<rect key="frame" x="452" y="1" width="15" height="232"/>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="5mw-P3-nSN">
<rect key="frame" x="234" y="1" width="15" height="143"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<textField verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" id="4">
<rect key="frame" x="17" y="20" width="380" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Built-in" id="5">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
<customObject id="9" customClass="WILDMediaListDataSource">
<connections>
<outlet property="iconListView" destination="6" id="10"/>
<outlet property="imagePathField" destination="4" id="11"/>
</connections>
</customObject>
<collectionViewItem id="kfs-UJ-hsM">
<connections>
<outlet property="imageView" destination="YEm-lt-UGn" id="rO7-30-ZMP"/>
<outlet property="textField" destination="zJD-5U-bqH" id="mxg-8J-yzp"/>
<outlet property="view" destination="0mn-H2-2Sx" id="deY-En-RMX"/>
</connections>
</collectionViewItem>
<customView id="0mn-H2-2Sx" userLabel="Collection View Item View">
<rect key="frame" x="0.0" y="0.0" width="163" height="96"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="YEm-lt-UGn">
<rect key="frame" x="9" y="20" width="145" height="67"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="nxa-VC-g8S"/>
<connections>
<binding destination="kfs-UJ-hsM" name="value" keyPath="representedObject.image" id="Mwc-nV-nES"/>
</connections>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="zJD-5U-bqH">
<rect key="frame" x="7" y="6" width="149" height="14"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" alignment="center" title="Label" id="tTL-2v-qIM">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="kfs-UJ-hsM" name="value" keyPath="representedObject.name" id="pG2-He-85l"/>
</connections>
</textField>
</subviews>
<point key="canvasLocation" x="101.5" y="-123"/>
</customView>
</objects>
</document>

0 comments on commit 71a42cb

Please sign in to comment.