diff --git a/ChangeLog b/ChangeLog index d47c446b3..ee105717e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-10-03 Eric Wasylishen + + * Source/GSThemeDrawing.m: Use new -[GSDrawTiles themeMargins] + to get the margins for draw tiles. + * Source/GSThemePrivate.h: + * Source/GSThemeTools.m: Get the 9-patch content rect support + working from end-to-end. + 2013-10-03 Eric Wasylishen * Headers/Additions/GNUstepGUI/GSTheme.h: diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 8c407379f..0e0665ce1 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -288,12 +288,7 @@ } else { - // FIXME: Move this code to a method in GSDrawTiles? - // FIXME: Not correct, need to get the content area of the draw tiles - margins.left = tiles->rects[TileCL].size.width; - margins.top = tiles->rects[TileTM].size.height; - margins.right = tiles->rects[TileCR].size.width; - margins.bottom = tiles->rects[TileBM].size.height; + margins = [tiles themeMargins]; return margins; } } @@ -370,8 +365,9 @@ { // FIXME: We assume the button's top and right padding are the same as // its bottom and left. - return NSMakeSize(tiles->contentRect.origin.x, - tiles->contentRect.origin.y); + + GSThemeMargins margins = [tiles themeMargins]; + return NSMakeSize(margins.left, margins.bottom); } } diff --git a/Source/GSThemePrivate.h b/Source/GSThemePrivate.h index aeb55cac8..3d8c10900 100644 --- a/Source/GSThemePrivate.h +++ b/Source/GSThemePrivate.h @@ -64,6 +64,9 @@ typedef enum { NSRect contentRect; /** Rectangle in which content should be * drawn, normally rects[TileCM], but can * be customized in the nine-patch format */ + NSRect originalRectCM; /** Caches rects[TileCM] as it was before + * -validateTilesSizeWithImage clears the + * origin. Used by -themeMargins */ float scaleFactor; GSThemeFillStyle style; /** The default style for filling a rect */ } @@ -139,6 +142,8 @@ typedef enum { */ - (NSSize) size; +- (GSThemeMargins) themeMargins; + @end /** This is the panel used to select and inspect themes. diff --git a/Source/GSThemeTools.m b/Source/GSThemeTools.m index 48015012b..36fc50c5a 100644 --- a/Source/GSThemeTools.m +++ b/Source/GSThemeTools.m @@ -897,7 +897,7 @@ withRepeatedImage: (NSImage*)image } else { - contentRect.origin.y = s.height - y2 - 1; + contentRect.origin.y = y1; contentRect.size.height = 1 + y2 - y1; } @@ -923,6 +923,8 @@ withRepeatedImage: (NSImage*)image { int i; + originalRectCM = rects[TileCM]; + for (i = 0; i < 9; i++) { if (rects[i].origin.x < 0.0 || rects[i].origin.y < 0.0 @@ -935,6 +937,8 @@ withRepeatedImage: (NSImage*)image { images[i] = [[self extractImageFrom: image withRect: rects[i]] retain]; + // FIXME: This makes no sense to me, why not leave the + // rect origins at their original values? rects[i].origin.x = 0; rects[i].origin.y = 0; } @@ -1078,15 +1082,43 @@ withRepeatedImage: (NSImage*)image return tsz; } +- (GSThemeMargins) themeMargins +{ + NSRect cm = originalRectCM; + GSThemeMargins margins; + + margins.left = rects[TileCL].size.width; + margins.right = rects[TileCR].size.width; + margins.top = rects[TileTM].size.height; + margins.bottom = rects[TileBM].size.height; + + // Adjust for contentRect != cm + + margins.left += (contentRect.origin.x - cm.origin.x); + margins.bottom += (contentRect.origin.y - cm.origin.y); + + margins.right += (NSMaxX(cm) - NSMaxX(contentRect)); + margins.top += (NSMaxY(cm) - NSMaxY(contentRect)); + + return margins; +} + - (NSRect) contentRectForRect: (NSRect)rect { - NSSize total = [self computeTotalTilesSize]; - NSRect inFill = NSMakeRect( - rect.origin.x + contentRect.origin.x, - rect.origin.y + contentRect.origin.y, - rect.size.width - (total.width - contentRect.size.width), - rect.size.height - (total.height - contentRect.size.height)); - return inFill; + NSRect cm = originalRectCM; + NSRect result = NSMakeRect(rect.origin.x + rects[TileCL].size.width, + rect.origin.y + rects[TileBM].size.height, + rect.size.width - (rects[TileCL].size.width + rects[TileCR].size.width), + rect.size.height - (rects[TileTM].size.height + rects[TileBM].size.height)); + + + result.origin.x += (contentRect.origin.x - cm.origin.x); + result.size.width += (contentRect.size.width - cm.size.width); + + result.origin.y += (contentRect.origin.y - cm.origin.y); + result.size.height += (contentRect.size.height - cm.size.height); + + return result; } - (NSRect) noneStyleFillRect: (NSRect)rect