Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved set pattern menu item

  • Loading branch information...
commit d6cf70ffd8e844e8894bcdd294495ed702e4393a 1 parent 9038968
@mattrajca mattrajca authored
View
20 English.lproj/MainMenu.xib
@@ -413,15 +413,6 @@
<reference key="NSOnImage" ref="130733852"/>
<reference key="NSMixedImage" ref="295545801"/>
</object>
- <object class="NSMenuItem" id="27874331">
- <reference key="NSMenu" ref="644071420"/>
- <string key="NSTitle">Set Pattern to Selection</string>
- <string key="NSKeyEquiv"/>
- <int key="NSKeyEquivModMask">1048576</int>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="130733852"/>
- <reference key="NSMixedImage" ref="295545801"/>
- </object>
<object class="NSMenuItem" id="351490431">
<reference key="NSMenu" ref="644071420"/>
<bool key="NSIsDisabled">YES</bool>
@@ -534,6 +525,15 @@
<reference key="NSOnImage" ref="130733852"/>
<reference key="NSMixedImage" ref="295545801"/>
</object>
+ <object class="NSMenuItem" id="27874331">
+ <reference key="NSMenu" ref="644071420"/>
+ <string key="NSTitle">Add Pattern from Selection</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSKeyEquivModMask">1048576</int>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="130733852"/>
+ <reference key="NSMixedImage" ref="295545801"/>
+ </object>
<object class="NSMenuItem" id="10140717">
<reference key="NSMenu" ref="644071420"/>
<string key="NSTitle">Crop to Selection</string>
@@ -2590,10 +2590,10 @@
<reference ref="458402486"/>
<reference ref="608961187"/>
<reference ref="10140717"/>
- <reference ref="27874331"/>
<reference ref="736307709"/>
<reference ref="588029433"/>
<reference ref="789941198"/>
+ <reference ref="27874331"/>
<reference ref="129644657"/>
</array>
<reference key="parent" ref="993977698"/>
View
32 Pixel Art Core/Canvas/PXCanvasController.m
@@ -27,6 +27,7 @@
#import "PXCanvasDocument.h"
#import "PXPattern.h"
#import "PXToolSwitcher.h"
+#import "PXPatternEditorController.h"
@implementation PXCanvasController
@@ -245,21 +246,22 @@ - (NSScrollView *)scrollView
- (void)setPatternToSelection
{
- if (![canvas hasSelection]) { return; }
- PXTool *currentTool = [[PXToolPaletteController sharedToolPaletteController] currentTool];
- if (![currentTool supportsPatterns]) { return; }
+ if (![canvas hasSelection])
+ return;
+
NSRect selectedRect = [canvas selectedRect];
NSRect patternRect = NSZeroRect;
- int i, j;
+
// on the first pass, figure out how big the pattern's going to be.
// we have to do this instead of just using selectedRect.size because
// if the outer pixels of the selection are < .5 opacity, they wouldn't
// be included in the pattern, and so it would be too big.
- for (i = NSMinX(selectedRect); i < NSMaxX(selectedRect); i++)
+ for (int i = NSMinX(selectedRect); i < NSMaxX(selectedRect); i++)
{
- for (j = NSMinY(selectedRect); j < NSMaxY(selectedRect); j++)
+ for (int j = NSMinY(selectedRect); j < NSMaxY(selectedRect); j++)
{
NSPoint point = NSMakePoint(i, j);
+
if ([canvas pointIsSelected:point] && [canvas colorAtPoint:point].a > 127)
{
NSRect newRect = NSMakeRect(i - NSMinX(selectedRect), j - NSMinY(selectedRect), 1, 1);
@@ -267,24 +269,34 @@ - (void)setPatternToSelection
}
}
}
-//FIXME: undo goes here?
+
PXPattern *pattern = [[PXPattern alloc] init];
[pattern setSize:patternRect.size];
+
// now we loop through again and actually set the points
- for (i = NSMinX(selectedRect); i < NSMaxX(selectedRect); i++)
+ for (int i = NSMinX(selectedRect); i < NSMaxX(selectedRect); i++)
{
- for (j = NSMinY(selectedRect); j < NSMaxY(selectedRect); j++)
+ for (int j = NSMinY(selectedRect); j < NSMaxY(selectedRect); j++)
{
NSPoint point = NSMakePoint(i, j);
+
if ([canvas pointIsSelected:point] && [canvas colorAtPoint:point].a > 127)
{
[pattern addPoint:NSMakePoint(i - NSMinX(selectedRect) - NSMinX(patternRect), j - NSMinY(selectedRect) - NSMinY(patternRect))];
}
}
}
+
[canvas deselect];
- [currentTool setPattern:pattern];
[canvas changedInRect:NSInsetRect([canvas selectedRect], -2, -2)];
+
+ [[PXPatternEditorController sharedController] addPattern:pattern];
+
+ PXTool *currentTool = [[PXToolPaletteController sharedToolPaletteController] currentTool];
+
+ if ([currentTool supportsPatterns]) {
+ [currentTool setPattern:pattern];
+ }
}
- (void)backgroundChanged:(id)changed
View
2  Pixen Application/Canvas/PXCanvasWindowController_IBActions.m
@@ -203,7 +203,7 @@ - (BOOL)validateMenuItem:(NSMenuItem *)anItem
return [[board types] containsObject:PXLayerPboardType];
}
else if ([anItem action] == @selector(setPatternToSelection:))
- return [[self canvas] hasSelection] && [[[PXToolPaletteController sharedToolPaletteController] currentTool] supportsPatterns];
+ return [[self canvas] hasSelection];
else if ([anItem action] == @selector(zoomOut:))
{
return ([[canvasController view] zoomPercentage] > 100);
Please sign in to comment.
Something went wrong with that request. Please try again.