Permalink
Browse files

Fixed command line build

  • Loading branch information...
1 parent 15543db commit 3ce175585819945a50c2ef403b27b54223ffadd7 psiroki committed Jun 22, 2010
Showing with 271 additions and 55 deletions.
  1. +72 −25 English.lproj/VertexDocument.xib
  2. +4 −0 VertexDocument.h
  3. +78 −14 VertexDocument.m
  4. +115 −4 VertexHelper.xcodeproj/project.pbxproj
  5. +0 −12 VertexScanner.cpp
  6. +2 −0 VertexScanner.h
@@ -21,7 +21,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="5"/>
+ <integer value="100095"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -199,6 +199,40 @@
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSTextField" id="634502060">
+ <reference key="NSNextResponder" ref="190226495"/>
+ <int key="NSvFlags">290</int>
+ <string key="NSFrame">{{236, 6}, {343, 22}}</string>
+ <reference key="NSSuperview" ref="190226495"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="122428049">
+ <int key="NSCellFlags">-2072904127</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="673925191"/>
+ <string key="NSPlaceholderString">VertexScanner command line</string>
+ <reference key="NSControlView" ref="634502060"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <object class="NSColor" key="NSBackgroundColor" id="655330197">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textBackgroundColor</string>
+ <object class="NSColor" key="NSColor" id="663680681">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor" id="428189095">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textColor</string>
+ <object class="NSColor" key="NSColor" id="7449600">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ </object>
+ </object>
+ </object>
+ </object>
<object class="NSButton" id="209450221">
<reference key="NSNextResponder" ref="190226495"/>
<int key="NSvFlags">268</int>
@@ -244,10 +278,7 @@
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">controlTextColor</string>
- <object class="NSColor" key="NSColor" id="7449600">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MAA</bytes>
- </object>
+ <reference key="NSColor" ref="7449600"/>
</object>
</object>
</object>
@@ -264,21 +295,8 @@
<reference key="NSSupport" ref="673925191"/>
<reference key="NSControlView" ref="525144916"/>
<bool key="NSDrawsBackground">YES</bool>
- <object class="NSColor" key="NSBackgroundColor" id="655330197">
- <int key="NSColorSpace">6</int>
- <string key="NSCatalogName">System</string>
- <string key="NSColorName">textBackgroundColor</string>
- <object class="NSColor" key="NSColor" id="663680681">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MQA</bytes>
- </object>
- </object>
- <object class="NSColor" key="NSTextColor" id="428189095">
- <int key="NSColorSpace">6</int>
- <string key="NSCatalogName">System</string>
- <string key="NSColorName">textColor</string>
- <reference key="NSColor" ref="7449600"/>
- </object>
+ <reference key="NSBackgroundColor" ref="655330197"/>
+ <reference key="NSTextColor" ref="428189095"/>
</object>
</object>
<object class="NSPopUpButton" id="741400065">
@@ -463,7 +481,7 @@
<string>public.url</string>
</object>
</object>
- <string key="NSFrame">{{0, 14}, {326, 14}}</string>
+ <string key="NSFrameSize">{326, 9}</string>
<reference key="NSSuperview" ref="246688413"/>
<object class="NSTextContainer" key="NSTextContainer" id="728819784">
<object class="NSLayoutManager" key="NSLayoutManager">
@@ -542,7 +560,7 @@
<nil key="NSDelegate"/>
</object>
</object>
- <string key="NSFrame">{{1, 1}, {326, 151}}</string>
+ <string key="NSFrame">{{1, 1}, {326, 119}}</string>
<reference key="NSSuperview" ref="351088152"/>
<reference key="NSNextKeyView" ref="456641845"/>
<reference key="NSDocView" ref="456641845"/>
@@ -556,7 +574,7 @@
<object class="NSScroller" id="736499354">
<reference key="NSNextResponder" ref="351088152"/>
<int key="NSvFlags">256</int>
- <string key="NSFrame">{{327, 1}, {15, 151}}</string>
+ <string key="NSFrame">{{327, 1}, {15, 119}}</string>
<reference key="NSSuperview" ref="351088152"/>
<reference key="NSTarget" ref="351088152"/>
<string key="NSAction">_doScroller:</string>
@@ -575,7 +593,7 @@
<double key="NSPercent">0.94565218687057495</double>
</object>
</object>
- <string key="NSFrame">{{236, 6}, {343, 153}}</string>
+ <string key="NSFrame">{{236, 38}, {343, 121}}</string>
<reference key="NSSuperview" ref="190226495"/>
<reference key="NSNextKeyView" ref="246688413"/>
<int key="NSsFlags">18</int>
@@ -867,6 +885,14 @@
</object>
<int key="connectionID">100094</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">commandLineField</string>
+ <reference key="source" ref="512844837"/>
+ <reference key="destination" ref="634502060"/>
+ </object>
+ <int key="connectionID">100097</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1015,6 +1041,7 @@
<reference ref="351088152"/>
<reference ref="148885797"/>
<reference ref="110730408"/>
+ <reference ref="634502060"/>
</object>
<reference key="parent" ref="958765573"/>
</object>
@@ -1252,6 +1279,20 @@
<reference key="object" ref="504448310"/>
<reference key="parent" ref="110730408"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">100095</int>
+ <reference key="object" ref="634502060"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="122428049"/>
+ </object>
+ <reference key="parent" ref="190226495"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">100096</int>
+ <reference key="object" ref="122428049"/>
+ <reference key="parent" ref="634502060"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -1306,6 +1347,8 @@
<string>100078.IBPluginDependency</string>
<string>100091.IBPluginDependency</string>
<string>100092.IBPluginDependency</string>
+ <string>100095.IBPluginDependency</string>
+ <string>100096.IBPluginDependency</string>
<string>5.IBEditorWindowLastContentRect</string>
<string>5.IBPluginDependency</string>
<string>5.IBWindowTemplateEditedContentRect</string>
@@ -1366,6 +1409,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{379, 243}, {599, 540}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{379, 243}, {599, 540}}</string>
@@ -1393,7 +1438,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">100094</int>
+ <int key="maxID">100097</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1423,6 +1468,7 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>colsTextField</string>
+ <string>commandLineField</string>
<string>imageView</string>
<string>resultTextView</string>
<string>rowsTextField</string>
@@ -1434,6 +1480,7 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSTextField</string>
+ <string>NSTextField</string>
<string>IKImageView</string>
<string>NSTextView</string>
<string>NSTextField</string>
View
@@ -23,10 +23,14 @@
IBOutlet NSPopUpButton *stylePopUpButton;
IBOutlet NSButton *scanButton;
+ IBOutlet NSTextField *commandLineField;
ImageViewGridLayer *gridLayer;
// each row has columns, each column has points
NSMutableArray *pointMatrix;
+ NSString *filePath;
+ BOOL gridOK;
+
}
- (IBAction)updateGrid:(id)sender;
View
@@ -8,6 +8,7 @@
#import "VertexDocument.h"
#import "VertexScanner.h"
+#import <AppKit/AppKit.h>
#define VHTYPE_PURE 0
#define VHTYPE_BOX2D 1
@@ -16,6 +17,12 @@
#define VHSTYLE_ASSIGN 0
#define VHSTYLE_INIT 1
+@interface VertexDocument(PrivateMethods)
+
+- (void)refreshScanParameters;
+
+@end
+
@implementation VertexDocument
@synthesize pointMatrix;
@@ -40,7 +47,7 @@ - (void)windowControllerDidLoadNib:(NSWindowController *) aController
[imageView setImageWithURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForImageResource:@"drop_sprite.png"]]];
[imageView setCurrentToolMode: IKToolModeMove];
- [imageView setDoubleClickOpensImageEditPanel:NO];
+ [imageView setDoubleClickOpensImageEditPanel:NO];
gridLayer = [ImageViewGridLayer layer];
gridLayer.owner = imageView;
@@ -49,7 +56,15 @@ - (void)windowControllerDidLoadNib:(NSWindowController *) aController
[gridLayer setNeedsDisplay];
[imageView setOverlay:gridLayer forType:IKOverlayTypeImage];
- [scanButton setEnabled:NO];
+ imageView.supportsDragAndDrop = NO;
+
+ NSWindow *window = [aController window];
+ [window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
+ [window setDelegate:self];
+
+ filePath = nil;
+ gridOK = NO;
+ [self refreshScanParameters];
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
@@ -80,14 +95,60 @@ - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError *
return YES;
}
+- (void)refreshScanParameters
+{
+ BOOL enabled = gridOK && filePath != nil;
+ [scanButton setEnabled:enabled];
+ if(enabled) {
+ int rows = [[rowsTextField stringValue] intValue];
+ int cols = [[colsTextField stringValue] intValue];
+ [commandLineField setStringValue:[NSString stringWithFormat:@"VertexScanner -r %d -c %d %@",
+ rows, cols, filePath]];
+ } else {
+ [commandLineField setStringValue:@""];
+ }
+
+}
+
+- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
+{
+ return NSDragOperationGeneric;
+}
+
+- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
+{
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ if([[pboard types] containsObject:NSFilenamesPboardType])
+ {
+ NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
+ return [files count] == 1;
+ }
+ return YES;
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ if([[pboard types] containsObject:NSFilenamesPboardType])
+ {
+ NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
+ if([files count] == 1)
+ {
+ filePath = [files objectAtIndex:0];
+ [imageView setImageWithURL:[NSURL fileURLWithPath:filePath]];
+ [self refreshScanParameters];
+ }
+ }
+ return YES;
+}
+
- (IBAction)updateGrid:(id)sender
{
int rows = [[rowsTextField stringValue] intValue];
int cols = [[colsTextField stringValue] intValue];
-
- BOOL enabled = (rows > 0 && cols > 0);
- NSLog(@"Matrix: %d %d", rows, cols);
- [scanButton setEnabled:enabled];
+
+ gridOK = rows > 0 && cols > 0;
+ [self refreshScanParameters];
if (rows <= 50 && cols <= 50 && (rows != gridLayer.rows || cols != gridLayer.cols)) {
@@ -107,21 +168,24 @@ - (IBAction)updateGrid:(id)sender
[self updateResultTextField];
}
}
+
- (IBAction)scanImage:(id)sender
{
- NSLog(@"Image properties: %@", [imageView imageProperties]);
[self updateGrid:sender];
CGImageRef img = [imageView image];
size_t width = CGImageGetWidth(img);
size_t height = CGImageGetHeight(img);
- size_t pitch = CGImageGetBytesPerRow(img);
+ size_t pitch = width*4;
UInt8 *bits = (UInt8*)malloc(width * height * 4);
- CGContextRef textureContext = CGBitmapContextCreate(bits, width, height, 8, width*4,
+ memset(bits, 0, width*height*4);
+ CGContextRef bitmapContext = CGBitmapContextCreate(bits, width, height, 8, pitch,
CGImageGetColorSpace(img), kCGImageAlphaPremultipliedLast);
- CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), img);
- CGContextRelease(textureContext);
+ CGContextTranslateCTM(bitmapContext, 0, height);
+ CGContextScaleCTM(bitmapContext, 1.0, -1.0);
+ CGContextDrawImage(bitmapContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), img);
+ CGContextRelease(bitmapContext);
const UInt8 *data = bits;
int cellWidth = (width / gridLayer.cols);
@@ -136,11 +200,11 @@ - (IBAction)scanImage:(id)sender
cell.width = cellWidth;
cell.height = cellHeight;
// the CGImage is a bottom-up image
- cell.pitch = -pitch;
+ cell.pitch = pitch;
// so data will point to the last row
- cell.data = data+(height-1)*pitch;
+ cell.data = data;
// also offset it by the coordinates of the cell
- cell.data += (cx*cellWidth*4)+(cy*cellHeight*(-pitch));
+ cell.data += (cx*cellWidth*4)+(cy*cellHeight*pitch);
Vec2Array points;
findPoints(&cell, &points);
if(points.count > 0)
Oops, something went wrong. Retry.

0 comments on commit 3ce1755

Please sign in to comment.