give theme more control over drawing

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28839 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-10-18 16:23:34 +00:00
parent 2c3f0453ee
commit a49d3efb05
6 changed files with 132 additions and 41 deletions

View file

@ -1,3 +1,12 @@
2009-10-18 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTheme.m:
* Source/GSThemeTools.m:
* Source/GSThemeDrawing.m:
* Source/GSThemePrivate.h:
* Headers/Additions/GNUstepGUI/GSTheme.h:
Allow theme to control how interior of tiled rect is filled.
2009-10-18 Nicolas Roard <nicolas@roard.com>
* Source/GSTheme.m,

View file

@ -699,6 +699,22 @@ withRepeatedImage: (NSImage*)image
background: (NSColor*)color
fillStyle: (GSThemeFillStyle)style;
/**
* Method to tile a rectangle given a group of up to nine tile images.<br />
* The GSDrawTiles object encapsulates the tile images and information
* about what parts of each image are used for tiling.<br />
* This draws the left, right, top and bottom borders by tiling the
* images at left, right, top and bottom. It then draws the four corner
* images and finally deals with the remaining space in the middle according
* to the default style set for the GSDrawTiles object used.<br />
* The background color specified is used to fill the center where
* style is FillStyleNone.<br />
* The return value is the central rectangle (inside the border images).
*/
- (NSRect) fillRect: (NSRect)rect
withTiles: (GSDrawTiles*)tiles
background: (NSColor*)color;
/**
* Method to tile the supplied image to fill the vertical rectangle.<br />
* The rect argument is the rectangle to be filled.<br />

View file

@ -817,12 +817,38 @@ typedef struct {
info = [[info objectForKey: @"GSThemeTiles"] objectForKey: fullName];
if ([info isKindOfClass: [NSDictionary class]] == YES)
{
float x;
float y;
NSString *path;
NSString *file;
NSString *ext;
float x;
float y;
NSString *name;
NSString *path;
NSString *file;
NSString *ext;
GSThemeFillStyle style = GSThemeFillStyleNone;
name = [info objectForKey: @"FillStyle"];
if ([name length] > 0)
{
if ([name isEqualToString: @"Scale"])
{
style = GSThemeFillStyleScale;
}
else if ([name isEqualToString: @"Repeat"])
{
style = GSThemeFillStyleRepeat;
}
else if ([name isEqualToString: @"Center"])
{
style = GSThemeFillStyleCenter;
}
else if ([name isEqualToString: @"Matrix"])
{
style = GSThemeFillStyleMatrix;
}
else if ([name isEqualToString: @"ScaleAll"])
{
style = GSThemeFillStyleScaleAll;
}
}
x = [[info objectForKey: @"HorizontalDivision"] floatValue];
y = [[info objectForKey: @"VerticalDivision"] floatValue];
file = [info objectForKey: @"FileName"];
@ -844,6 +870,7 @@ typedef struct {
horizontal: x
vertical: y];
[tiles setFillStyle: style];
//TODO(rio) tiles = [[GSDrawTiles alloc] initWithNinePatchImage: image];
RELEASE(image);
}

View file

@ -135,8 +135,7 @@
*/
[self fillRect: frame
withTiles: tiles
background: color
fillStyle: GSThemeFillStyleNone];
background: color];
}
}

View file

@ -56,11 +56,13 @@ typedef enum {
NSImage *images[9]; /** The tile images */
NSRect rects[9]; /** The rectangles to use when drawing */
float scaleFactor;
GSThemeFillStyle style; /** The default style for filling a rect */
}
- (id) copyWithZone: (NSZone*)zone;
/* Initialise with a single image, using 'annotations' to determinate
* where the tiles are in the image, in the form of black pixels in a 1-pixel surrounding border.
* where the tiles are in the image, in the form of black pixels in a
* 1-pixel surrounding border.
* It is similar to http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
*/
- (id) initWithNinePatchImage: (NSImage*)image;
@ -87,8 +89,10 @@ typedef enum {
- (void) scaleTo: (float)multiple;
- (NSRect) fillRect: (NSRect)rect
background: (NSColor*) color
background: (NSColor*)color
fillStyle: (GSThemeFillStyle)style;
- (NSRect) fillRect: (NSRect)rect
background: (NSColor*)color;
- (NSSize) computeTotalTilesSize;
- (void) drawCornersRect: (NSRect)rect;
@ -104,6 +108,9 @@ typedef enum {
- (NSRect) matrixStyleFillRect: (NSRect)rect;
- (void) repeatFillRect: (NSRect)rect;
- (GSThemeFillStyle) fillStyle;
- (void) setFillStyle: (GSThemeFillStyle)aStyle;
@end
/** This is the panel used to select and inspect themes.

View file

@ -610,6 +610,16 @@ withRepeatedImage: (NSImage*)image
DPSgrestore (ctxt);
}
- (NSRect) fillRect: (NSRect)rect
withTiles: (GSDrawTiles*)tiles
background: (NSColor*)color
{
return [self fillRect: rect
withTiles: tiles
background: color
fillStyle: [tiles fillStyle]];
}
- (NSRect) fillRect: (NSRect)rect
withTiles: (GSDrawTiles*)tiles
background: (NSColor*)color
@ -746,6 +756,7 @@ withRepeatedImage: (NSImage*)image
c->images[i] = [images[i] copy];
}
}
c->style = style;
return c;
}
@ -798,10 +809,11 @@ withRepeatedImage: (NSImage*)image
NSSize s = [image size];
NSBitmapImageRep* rep = [[image representations] objectAtIndex: 0];
for (i=0; i<s.width; i++)
for (i = 0; i < s.width; i++)
{
NSColor *pixelColor = [rep colorAtX:i y:s.height-1];
[pixelColor getRed:&r green:&g blue:&b alpha:&a];
NSColor *pixelColor = [rep colorAtX: i y: s.height - 1];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (a > 0 && x1 == -1)
{
x1 = i;
@ -813,10 +825,11 @@ withRepeatedImage: (NSImage*)image
}
}
for (i=0; i<s.height; i++)
for (i = 0; i < s.height; i++)
{
NSColor *pixelColor = [rep colorAtX:0 y:i];
[pixelColor getRed:&r green:&g blue:&b alpha:&a];
NSColor *pixelColor = [rep colorAtX: 0 y: i];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (a > 0 && y1 == -1)
{
y1 = i;
@ -829,6 +842,7 @@ withRepeatedImage: (NSImage*)image
}
scaleFactor = 1.0f;
style = GSThemeFillStyleNone;
rects[TileTL] = NSMakeRect(1, s.height - y1 -1, x1, y1);
rects[TileTM] = NSMakeRect(x1, s.height - y1 -1, x2 - x1, y1);
@ -847,6 +861,7 @@ withRepeatedImage: (NSImage*)image
- (void) validateTilesSizeWithImage: (NSImage*)image
{
int i;
for (i = 0; i < 9; i++)
{
if (rects[i].origin.x < 0.0 || rects[i].origin.y < 0.0
@ -881,6 +896,8 @@ withRepeatedImage: (NSImage*)image
rects[TileBM] = NSMakeRect(x, 0.0, s.width - 2.0 * x, y);
rects[TileBR] = NSMakeRect(s.width - x, 0.0, x, y);
style = GSThemeFillStyleNone;
[self validateTilesSizeWithImage: image];
return self;
}
@ -931,8 +948,14 @@ withRepeatedImage: (NSImage*)image
}
- (NSRect) fillRect: (NSRect)rect
background: (NSColor*) color
fillStyle: (GSThemeFillStyle)style
background: (NSColor*)color
{
return [self fillRect: rect background: color fillStyle: style];
}
- (NSRect) fillRect: (NSRect)rect
background: (NSColor*)color
fillStyle: (GSThemeFillStyle)aStyle
{
if (color == nil)
{
@ -944,7 +967,7 @@ withRepeatedImage: (NSImage*)image
}
NSRectFill(rect);
switch (style)
switch (aStyle)
{
case GSThemeFillStyleNone:
return [self noneStyleFillRect: rect];
@ -964,14 +987,13 @@ withRepeatedImage: (NSImage*)image
- (NSSize) computeTotalTilesSize
{
NSSize tsz;
tsz.width = rects[TileTL].size.width
+ rects[TileTR].size.width;
tsz.width = rects[TileTL].size.width + rects[TileTR].size.width;
if (images[TileTM] != nil)
{
tsz.width += rects[TileTM].size.width;
}
tsz.height = rects[TileTL].size.height
+ rects[TileBL].size.height;
tsz.height = rects[TileTL].size.height + rects[TileBL].size.height;
if (images[TileCL] != nil)
{
tsz.height += rects[TileCL].size.height;
@ -985,11 +1007,11 @@ withRepeatedImage: (NSImage*)image
NSSize bms = rects[TileBM].size;
NSSize crs = rects[TileCR].size;
NSSize tms = rects[TileTM].size;
NSRect inFill = NSMakeRect (rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSRect inFill = NSMakeRect (
rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
[self repeatFillRect: rect];
[self drawCornersRect: rect];
@ -1004,11 +1026,11 @@ withRepeatedImage: (NSImage*)image
NSSize bms = rects[TileBM].size;
NSSize crs = rects[TileCR].size;
NSSize tms = rects[TileTM].size;
NSRect inFill = NSMakeRect (rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSRect inFill = NSMakeRect (
rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSRect r = rects[TileCM];
@ -1039,11 +1061,11 @@ withRepeatedImage: (NSImage*)image
NSSize bms = rects[TileBM].size;
NSSize crs = rects[TileCR].size;
NSSize tms = rects[TileTM].size;
NSRect inFill = NSMakeRect (rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSRect inFill = NSMakeRect (
rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
[[GSTheme theme] fillRect: inFill
withRepeatedImage: images[TileCM]
@ -1065,10 +1087,11 @@ withRepeatedImage: (NSImage*)image
NSSize crs = rects[TileCR].size;
NSSize tms = rects[TileTM].size;
NSRect inFill = NSMakeRect (rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSRect inFill = NSMakeRect (
rect.origin.x + cls.width,
rect.origin.y + bms.height,
rect.size.width - cls.width - crs.width,
rect.size.height - bms.height - tms.height);
NSImage *im = [images[TileCM] copy];
NSRect r = rects[TileCM];
@ -1375,5 +1398,15 @@ withRepeatedImage: (NSImage*)image
operation: NSCompositeSourceOver];
}
- (GSThemeFillStyle) fillStyle
{
return style;
}
- (void) setFillStyle: (GSThemeFillStyle)aStyle
{
style = aStyle;
}
@end