diff --git a/ChangeLog b/ChangeLog index 8d631df19..2881b489f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-10-19 Richard Frith-Macdonald + + * Headers/Additions/GNUstepGUI/GSTheme.h: + * Source/GSTheme.m: + Have tile filling method return rect of central tile area. + * Source/NSView.m: Fixup indentation problems. + 2006-10-19 01:45-EDT Gregory John Casamento * Source/NSView.m: Applied patch from Banlu Kemiyatorn. Corrects diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index b39ff8c7f..31da00f3d 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -430,7 +430,12 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification; */ @interface GSTheme (LowLevelDrawing) /** - * Method to tile the supplied image to fill the horizontal rectangle. + * Method to tile the supplied image to fill the horizontal rectangle.
+ * The rect argument is the rectangle to be filled.
+ * The image argument is the data to fill with.
+ * The source argument is the rectangle within the image which is used.
+ * The flipped argument specifies what sort of coordinate system is in + * use in the view where we are drawing. */ - (void) fillHorizontalRect: (NSRect)rect withImage: (NSImage*)image @@ -449,20 +454,29 @@ withRepeatedImage: (NSImage*)image center: (BOOL)center; /** - * Method to tile a rectangle given an array of nine tile images.
+ * Method to tile a rectangle given a group of up to nine tile images.
+ * The GSDrawTiles object encapsulates the tile images and information + * about what parts of each image are used for tiling.
* This draws the left, right, top and bottom borders by tiling the - * images at TileCL, TileCR, TileTM and TileBM respectively. It then - * draws the four corner images and finally deals with the remaining - * space in the middle according to the specified style.
- * The background color specified is used where style is FillStyleNone. + * 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 specified style.
+ * The background color specified is used to fill the center where + * style is FillStyleNone.
+ * The return value is the central rectangle (inside the border images). */ -- (void) fillRect: (NSRect)rect - withTiles: (GSDrawTiles*)tiles - background: (NSColor*)color - fillStyle: (GSThemeFillStyle)style; +- (NSRect) fillRect: (NSRect)rect + withTiles: (GSDrawTiles*)tiles + background: (NSColor*)color + fillStyle: (GSThemeFillStyle)style; /** - * Method to tile the supplied image to fill the vertical rectangle. + * Method to tile the supplied image to fill the vertical rectangle.
+ * The rect argument is the rectangle to be filled.
+ * The image argument is the data to fill with.
+ * The source argument is the rectangle within the image which is used.
+ * The flipped argument specifies what sort of coordinate system is in + * use in the view where we are drawing. */ - (void) fillVerticalRect: (NSRect)rect withImage: (NSImage*)image diff --git a/Source/GSTheme.m b/Source/GSTheme.m index be17e3746..ac91b6c88 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -1050,10 +1050,10 @@ withRepeatedImage: (NSImage*)image DPSgrestore (ctxt); } -- (void) fillRect: (NSRect)rect - withTiles: (GSDrawTiles*)tiles - background: (NSColor*)color - fillStyle: (GSThemeFillStyle)style +- (NSRwect) fillRect: (NSRect)rect + withTiles: (GSDrawTiles*)tiles + background: (NSColor*)color + fillStyle: (GSThemeFillStyle)style { NSGraphicsContext *ctxt = GSCurrentContext(); NSSize tls = tiles->rects[TileTL].size; @@ -1085,6 +1085,7 @@ withRepeatedImage: (NSImage*)image float space = 3.0; float scale; + inFill = NSZeroRect; if (tiles->images[TileTM] == nil) { grid.size.width = (tiles->rects[TileTL].size.width @@ -1289,16 +1290,22 @@ withRepeatedImage: (NSImage*)image fromRect: tiles->rects[TileBR] operation: NSCompositeSourceOver]; - inFill = NSMakeRect (rect.origin.x +cls.width, + 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); if (style == GSThemeFillStyleCenter) { - [self fillRect: inFill - withRepeatedImage: tiles->images[TileCM] - fromRect: tiles->rects[TileCM] - center: NO]; + NSRect r = tiles->rects[TileCM]; + + r.origin.x + = inFill.origin.x + (inFill.size.width - r.size.width) / 2; + r.origin.y + = inFill.origin.y + (inFill.size.height - r.size.height) / 2; + r.origin.y += r.size.height; // Allow for flip of image rectangle + [tiles->images[TileCM] compositeToPoint: r.origin + fromRect: tiles->rects[TileCM] + operation: NSCompositeSourceOver]; } else if (style == GSThemeFillStyleRepeat) { @@ -1309,11 +1316,27 @@ withRepeatedImage: (NSImage*)image } else if (style == GSThemeFillStyleScale) { - [tiles->images[TileCM] setScalesWhenResized: YES]; - [tiles->images[TileCM] setSize: inFill.size]; - [tiles->images[TileCM] compositeToPoint: inFill.origin - fromRect: tiles->rects[TileCM] - operation: NSCompositeSourceOver]; + NSImage *im = [tiles->images[TileCM] copy]; + NSRect r = tiles->rects[TileCM]; + NSSize s = [tiles->images[TileCM] size]; + NSPoint p = inFill.origin; + float sx = inFill.size.width / r.size.width; + float sy = inFill.size.height / r.size.height; + + r.size.width = inFill.size.width; + r.size.height = inFill.size.height; + r.origin.x *= sx; + r.origin.y *= sy; + s.width *= sx; + s.height *= sy; + p.y += inFill.size.height; // In flipped view + + [im setScalesWhenResized: YES]; + [im setSize: s]; + [im compositeToPoint: p + fromRect: r + operation: NSCompositeSourceOver]; + RELEASE(im); } } else @@ -1387,10 +1410,15 @@ withRepeatedImage: (NSImage*)image if (style == GSThemeFillStyleCenter) { - [self fillRect: inFill - withRepeatedImage: tiles->images[TileCM] - fromRect: tiles->rects[TileCM] - center: NO]; + NSRect r = tiles->rects[TileCM]; + + r.origin.x + = inFill.origin.x + (inFill.size.width - r.size.width) / 2; + r.origin.y + = inFill.origin.y + (inFill.size.height - r.size.height) / 2; + [tiles->images[TileCM] compositeToPoint: r.origin + fromRect: tiles->rects[TileCM] + operation: NSCompositeSourceOver]; } else if (style == GSThemeFillStyleRepeat) { @@ -1402,15 +1430,29 @@ withRepeatedImage: (NSImage*)image else if (style == GSThemeFillStyleScale) { NSImage *im = [tiles->images[TileCM] copy]; + NSRect r = tiles->rects[TileCM]; + NSSize s = [tiles->images[TileCM] size]; + NSPoint p = inFill.origin; + float sx = inFill.size.width / r.size.width; + float sy = inFill.size.height / r.size.height; + + r.size.width = inFill.size.width; + r.size.height = inFill.size.height; + r.origin.x *= sx; + r.origin.y *= sy; + s.width *= sx; + s.height *= sy; + [im setScalesWhenResized: YES]; - [im setSize: inFill.size]; - [im compositeToPoint: inFill.origin - fromRect: tiles->rects[TileCM] + [im setSize: s]; + [im compositeToPoint: p + fromRect: r operation: NSCompositeSourceOver]; RELEASE(im); } } + return inFill; } - (void) fillVerticalRect: (NSRect)rect diff --git a/Source/NSView.m b/Source/NSView.m index d976f932d..134b0799d 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -302,8 +302,8 @@ GSSetDragTypes(NSView* obj, NSArray *types) } else { - NSRect superviewsVisibleRect; - BOOL wasFlipped = _super_view->_rFlags.flipped_view; + NSRect superviewsVisibleRect; + BOOL wasFlipped = _super_view->_rFlags.flipped_view; NSAffineTransform *pMatrix = [_super_view _matrixToWindow]; NSAffineTransform *tMatrix = nil; @@ -312,17 +312,15 @@ GSSetDragTypes(NSView* obj, NSArray *types) /* prepend translation */ tMatrix = _matrixToWindow; tMatrix->matrix.tX = NSMinX(_frame) * tMatrix->matrix.m11 + - NSMinY(_frame) * tMatrix->matrix.m21 + - tMatrix->matrix.tX; + NSMinY(_frame) * tMatrix->matrix.m21 + tMatrix->matrix.tX; tMatrix->matrix.tY = NSMinX(_frame) * tMatrix->matrix.m12 + - NSMinY(_frame) * tMatrix->matrix.m22 + - tMatrix->matrix.tY; + NSMinY(_frame) * tMatrix->matrix.m22 + tMatrix->matrix.tY; /* prepend rotation */ if (_frameMatrix != nil) - { - (*preImp)(_matrixToWindow, preSel, _frameMatrix); - } + { + (*preImp)(_matrixToWindow, preSel, _frameMatrix); + } if (_rFlags.flipped_view != wasFlipped) { @@ -1144,9 +1142,9 @@ GSSetDragTypes(NSView* obj, NSArray *types) { /* no frame matrix, create one since it is needed for rotation */ if (_frameMatrix == nil) - { - _frameMatrix = [NSAffineTransform new]; // Map fromsuperview to frame - } + { + _frameMatrix = [NSAffineTransform new]; // Map fromsuperview to frame + } if (_coordinates_valid) { @@ -2089,12 +2087,13 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri if (subview->_frameMatrix) // assume rotation { - NSRect r; - r.origin = NSZeroPoint; - r.size = subviewFrame.size; - [subview->_frameMatrix boundingRectFor: r - result: &r]; - subviewFrame = NSOffsetRect(r, NSMinX(subviewFrame), NSMinY(subviewFrame)); + NSRect r; + + r.origin = NSZeroPoint; + r.size = subviewFrame.size; + [subview->_frameMatrix boundingRectFor: r result: &r]; + subviewFrame = NSOffsetRect(r, NSMinX(subviewFrame), + NSMinY(subviewFrame)); } /* @@ -2221,14 +2220,15 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri BOOL intersectCalculated = NO; if (subview->_frameMatrix != nil) - { - NSRect r; - r.origin = NSZeroPoint; - r.size = subviewFrame.size; - [subview->_frameMatrix boundingRectFor: r - result: &r]; - subviewFrame = NSOffsetRect(r, NSMinX(subviewFrame), NSMinY(subviewFrame)); - } + { + NSRect r; + + r.origin = NSZeroPoint; + r.size = subviewFrame.size; + [subview->_frameMatrix boundingRectFor: r result: &r]; + subviewFrame = NSOffsetRect(r, NSMinX(subviewFrame), + NSMinY(subviewFrame)); + } /* * Having drawn ourself into the rect, we must make sure that @@ -2245,7 +2245,7 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri */ subview->_rFlags.needs_display = YES; subview->_invalidRect = NSUnionRect(subview->_invalidRect, - isect); + isect); } if (subview->_rFlags.needs_display == YES) @@ -2854,29 +2854,28 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) unsigned count; NSView *v = nil, *w; - /* - If not within our frame then it can't be a hit. + /* If not within our frame then it can't be a hit. As a special case, always assume that it's a hit if our _super_view is nil, ie. if we're the top-level view in a window. */ if (_is_rotated_or_scaled_from_base) - { - p = [self convertPoint: aPoint fromView: _super_view]; - if (!NSPointInRect (p, _bounds)) - { - return nil; - } - } - else if (_super_view && ![_super_view mouse: aPoint inRect: _frame]) - { + { + p = [self convertPoint: aPoint fromView: _super_view]; + if (!NSPointInRect (p, _bounds)) + { return nil; - } + } + } + else if (_super_view && ![_super_view mouse: aPoint inRect: _frame]) + { + return nil; + } else - { - p = [self convertPoint: aPoint fromView: _super_view]; - } + { + p = [self convertPoint: aPoint fromView: _super_view]; + } if (_rFlags.has_subviews) { @@ -4275,12 +4274,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) - (float) frameRotation { - if (_frameMatrix != nil) - { - return [_frameMatrix rotationAngle]; - } + if (_frameMatrix != nil) + { + return [_frameMatrix rotationAngle]; + } - return 0.0; + return 0.0; } - (BOOL) postsFrameChangedNotifications