* 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


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37219 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2013-10-12 18:24:33 +00:00
parent a92ca7df32
commit 4ee6d51fd0
3 changed files with 68 additions and 4 deletions

View file

@ -1,3 +1,13 @@
2013-10-12 Eric Wasylishen <ewasylishen@gmail.com>
* 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 <ewasylishen@gmail.com> 2013-10-11 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSColorWell.m (-drawRect:): Remove incorrect intersection * Source/NSColorWell.m (-drawRect:): Remove incorrect intersection

View file

@ -65,6 +65,7 @@ typedef enum {
NSRect contentRect; /** Rectangle in which content should be NSRect contentRect; /** Rectangle in which content should be
* drawn, normally rects[TileCM], but can * drawn, normally rects[TileCM], but can
* be customized in the nine-patch format */ * be customized in the nine-patch format */
NSRect layoutRect;
NSRect originalRectCM; /** Caches rects[TileCM] as it was before NSRect originalRectCM; /** Caches rects[TileCM] as it was before
* -validateTilesSizeWithImage clears the * -validateTilesSizeWithImage clears the
* origin. Used by -themeMargins */ * origin. Used by -themeMargins */

View file

@ -849,11 +849,11 @@ withRepeatedImage: (NSImage*)image
NSColor *pixelColor = [rep colorAtX: i y: s.height - 1]; NSColor *pixelColor = [rep colorAtX: i y: s.height - 1];
[pixelColor getRed: &r green: &g blue: &b alpha: &a]; [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; x1 = i;
} }
else if (a == 0 && x1 != -1) else if (!(a == 1 && r == 0 && g == 0 && b == 0) && x1 != -1)
{ {
x2 = i - 1; x2 = i - 1;
break; break;
@ -865,11 +865,11 @@ withRepeatedImage: (NSImage*)image
NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i]; NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i];
[pixelColor getRed: &r green: &g blue: &b alpha: &a]; [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; y1 = i;
} }
else if (a == 0 && y1 != -1) else if (!(a == 1 && r == 0 && g == 0 && b == 0) && y1 != -1)
{ {
y2 = i - 1; y2 = i - 1;
break; break;
@ -904,6 +904,59 @@ withRepeatedImage: (NSImage*)image
contentRect.size.height = 1 + y2 - y1; 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]; [self validateTilesSizeWithImage: image];
return self; return self;
} }