diff --git a/ChangeLog b/ChangeLog index ccf7085b6..f51bdde26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2013-10-12 Eric Wasylishen + + * Source/GSThemeTools.m (-initWithNinePatchImage:): Parse the + "optiacal bounds" metadata in 9-patch images. It's stored + in the layoutRect ivar but not used otherwise. + + See "Optical bounds layout" section of: + http://developer.android.com/about/versions/android-4.3.html + * Source/GSThemePrivate.h (GSDrawTiles): Add layoutRect ivar + 2013-10-11 Eric Wasylishen * Source/NSColorWell.m (-drawRect:): Remove incorrect intersection diff --git a/Source/GSThemePrivate.h b/Source/GSThemePrivate.h index f3a2a5b7e..28d46cbed 100644 --- a/Source/GSThemePrivate.h +++ b/Source/GSThemePrivate.h @@ -65,6 +65,7 @@ typedef enum { NSRect contentRect; /** Rectangle in which content should be * drawn, normally rects[TileCM], but can * be customized in the nine-patch format */ + NSRect layoutRect; NSRect originalRectCM; /** Caches rects[TileCM] as it was before * -validateTilesSizeWithImage clears the * origin. Used by -themeMargins */ diff --git a/Source/GSThemeTools.m b/Source/GSThemeTools.m index 3658942b1..6d30a9032 100644 --- a/Source/GSThemeTools.m +++ b/Source/GSThemeTools.m @@ -849,11 +849,11 @@ withRepeatedImage: (NSImage*)image NSColor *pixelColor = [rep colorAtX: i y: s.height - 1]; [pixelColor getRed: &r green: &g blue: &b alpha: &a]; - if (a > 0 && x1 == -1) + if ((a == 1 && r == 0 && g == 0 && b == 0) && x1 == -1) { x1 = i; } - else if (a == 0 && x1 != -1) + else if (!(a == 1 && r == 0 && g == 0 && b == 0) && x1 != -1) { x2 = i - 1; break; @@ -865,11 +865,11 @@ withRepeatedImage: (NSImage*)image NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i]; [pixelColor getRed: &r green: &g blue: &b alpha: &a]; - if (a > 0 && y1 == -1) + if ((a == 1 && r == 0 && g == 0 && b == 0) && y1 == -1) { y1 = i; } - else if (a == 0 && y1 != -1) + else if (!(a == 1 && r == 0 && g == 0 && b == 0) && y1 != -1) { y2 = i - 1; break; @@ -904,6 +904,59 @@ withRepeatedImage: (NSImage*)image contentRect.size.height = 1 + y2 - y1; } + // Measure the layout rect (the right and bottom edges of the nine-patch + // data which _isn't_ red pixels) + + x1 = -1; + x2 = -1; + y1 = -1; + y2 = -1; + + for (i = 1; i < (s.width - 1); i++) + { + NSColor *pixelColor = [rep colorAtX: i y: s.height - 1]; + + [pixelColor getRed: &r green: &g blue: &b alpha: &a]; + if (!(a == 1 && r == 1 && g == 0 && b == 0) && x1 == -1) + { + x1 = i; + } + else if ((a == 1 && r == 1 && g == 0 && b == 0) && x1 != -1) + { + x2 = i - 1; + break; + } + } + + for (i = 1; i < (s.height - 1); i++) + { + NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i]; + + [pixelColor getRed: &r green: &g blue: &b alpha: &a]; + if (!(a == 1 && r == 1 && g == 0 && b == 0) && y1 == -1) + { + y1 = i; + } + else if ((a == 1 && r == 1 && g == 0 && b == 0) && y1 != -1) + { + y2 = i - 1; + break; + } + } + + + if (x2 == -1) + { + x2 = s.width - 2; + } + + if (y2 == -1) + { + y2 = s.height - 2; + } + + layoutRect = NSMakeRect(x1, s.height - y2 - 1, 1 + x2 - x1, 1 + y2 - y1); + [self validateTilesSizeWithImage: image]; return self; }