mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 17:22:10 +00:00
* Tests/gui/NSView/NSView_autoresize_and_rounding.m: Add tests
for centerScanRect: with flipped view. * Source/NSView.m (-centerScanRect:): Change to get the failed tests to pass. * Source/GSThemeTools.m (-drawRoundBezel:withColor:): Make round bezel look a bit nicer. * Source/NSButtonCell.m (-drawImage:withFrame:inView:): Use centerScanRect: instead of similar code. * Source/NSCell.m: Use imageRectForBounds: and titleRectForBounds: in drawInteriorWithFrame:inView:. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38929 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
80f7c762a3
commit
1f3a02d1e7
6 changed files with 98 additions and 64 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2015-08-25 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Tests/gui/NSView/NSView_autoresize_and_rounding.m: Add tests for
|
||||||
|
centerScanRect: with flipped view.
|
||||||
|
* Source/NSView.m (-centerScanRect:): Change to get the failed
|
||||||
|
tests to pass.
|
||||||
|
* Source/GSThemeTools.m (-drawRoundBezel:withColor:): Make round
|
||||||
|
bezel look a bit nicer.
|
||||||
|
* Source/NSButtonCell.m (-drawImage:withFrame:inView:): Use
|
||||||
|
centerScanRect: instead of similar code.
|
||||||
|
* Source/NSCell.m: Use imageRectForBounds: and titleRectForBounds:
|
||||||
|
in drawInteriorWithFrame:inView:.
|
||||||
|
|
||||||
2015-08-24 Riccardo Mottola <rm@gnu.org>
|
2015-08-24 Riccardo Mottola <rm@gnu.org>
|
||||||
|
|
||||||
* Headers/AppKit/NSWindow.h
|
* Headers/AppKit/NSWindow.h
|
||||||
|
|
|
@ -409,16 +409,16 @@
|
||||||
|
|
||||||
- (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
|
- (void) drawRoundBezel: (NSRect)cellFrame withColor: (NSColor*)backgroundColor
|
||||||
{
|
{
|
||||||
NSBezierPath *p = [NSBezierPath bezierPath];
|
NSBezierPath *p;
|
||||||
NSPoint point;
|
NSPoint point;
|
||||||
CGFloat radius;
|
CGFloat radius;
|
||||||
|
|
||||||
// make smaller than enclosing frame
|
// make smaller than enclosing frame
|
||||||
cellFrame = NSInsetRect(cellFrame, 4, floor(cellFrame.size.height * 0.1875));
|
cellFrame = NSInsetRect(cellFrame, 4, 4);
|
||||||
radius = cellFrame.size.height / 2.0;
|
radius = cellFrame.size.height / 2.0;
|
||||||
point = cellFrame.origin;
|
point = cellFrame.origin;
|
||||||
point.x += radius;
|
point.x += radius;
|
||||||
point.y += radius;
|
point.y += radius - 0.5;
|
||||||
|
|
||||||
// Draw initial path to enclose the button...
|
// Draw initial path to enclose the button...
|
||||||
// left half-circle
|
// left half-circle
|
||||||
|
@ -446,13 +446,13 @@
|
||||||
|
|
||||||
// Add highlights...
|
// Add highlights...
|
||||||
point = cellFrame.origin;
|
point = cellFrame.origin;
|
||||||
point.x += radius;
|
point.x += radius - 0.5;
|
||||||
point.y += radius;
|
point.y += radius - 0.5;
|
||||||
p = [NSBezierPath bezierPath];
|
p = [NSBezierPath bezierPath];
|
||||||
[p setLineWidth: 2.0];
|
[p setLineWidth: 1.0];
|
||||||
[p appendBezierPathWithArcWithCenter: point
|
[p appendBezierPathWithArcWithCenter: point
|
||||||
radius: radius
|
radius: radius
|
||||||
startAngle: 120.0
|
startAngle: 135.0
|
||||||
endAngle: 270.0];
|
endAngle: 270.0];
|
||||||
|
|
||||||
// line to first point and right halfcircle
|
// line to first point and right halfcircle
|
||||||
|
@ -460,7 +460,7 @@
|
||||||
[p appendBezierPathWithArcWithCenter: point
|
[p appendBezierPathWithArcWithCenter: point
|
||||||
radius: radius
|
radius: radius
|
||||||
startAngle: 270.0
|
startAngle: 270.0
|
||||||
endAngle: 270.0];
|
endAngle: 315.0];
|
||||||
[[NSColor controlLightHighlightColor] set];
|
[[NSColor controlLightHighlightColor] set];
|
||||||
[p stroke];
|
[p stroke];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1015,47 +1015,23 @@ typedef struct _GSButtonCellFlags
|
||||||
toFitInSize: cellFrame.size
|
toFitInSize: cellFrame.size
|
||||||
scalingType: _imageScaling];
|
scalingType: _imageScaling];
|
||||||
|
|
||||||
/* Pixel-align size */
|
|
||||||
|
|
||||||
if (controlView)
|
|
||||||
{
|
|
||||||
NSSize sizeInBase = [controlView convertSizeToBase: size];
|
|
||||||
sizeInBase.width = GSRoundTowardsInfinity(sizeInBase.width);
|
|
||||||
sizeInBase.height = GSRoundTowardsInfinity(sizeInBase.height);
|
|
||||||
size = [controlView convertSizeFromBase: sizeInBase];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate an offset from the cellFrame origin */
|
/* Calculate an offset from the cellFrame origin */
|
||||||
|
|
||||||
offset = NSMakePoint((NSWidth(cellFrame) - size.width) / 2.0,
|
offset = NSMakePoint((NSWidth(cellFrame) - size.width) / 2.0,
|
||||||
(NSHeight(cellFrame) - size.height) / 2.0);
|
(NSHeight(cellFrame) - size.height) / 2.0);
|
||||||
|
|
||||||
/* Pixel-align the offset */
|
|
||||||
|
|
||||||
if (controlView)
|
|
||||||
{
|
|
||||||
NSPoint inBase = [controlView convertPointToBase: offset];
|
|
||||||
|
|
||||||
// By convention we will round down and to the right.
|
|
||||||
// With the standard button design this looks good
|
|
||||||
// because the bottom and right edges of the button look 'heavier'
|
|
||||||
// so if the image's center must be offset from the button's geometric
|
|
||||||
// center, it looks beter if it's closer to the 'heavier' part
|
|
||||||
|
|
||||||
inBase.x = GSRoundTowardsInfinity(inBase.x);
|
|
||||||
inBase.y = [controlView isFlipped] ?
|
|
||||||
GSRoundTowardsInfinity(inBase.y) :
|
|
||||||
GSRoundTowardsNegativeInfinity(inBase.y);
|
|
||||||
|
|
||||||
offset = [controlView convertPointFromBase: inBase];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Draw the image */
|
|
||||||
|
|
||||||
rect = NSMakeRect(cellFrame.origin.x + offset.x,
|
rect = NSMakeRect(cellFrame.origin.x + offset.x,
|
||||||
cellFrame.origin.y + offset.y,
|
cellFrame.origin.y + offset.y,
|
||||||
size.width,
|
size.width,
|
||||||
size.height);
|
size.height);
|
||||||
|
|
||||||
|
/* Pixel-align */
|
||||||
|
if (nil != controlView)
|
||||||
|
{
|
||||||
|
rect = [controlView centerScanRect: rect];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Draw the image */
|
||||||
|
|
||||||
fraction = (![self isEnabled] &&
|
fraction = (![self isEnabled] &&
|
||||||
[self imageDimsWhenDisabled]) ? 0.5 : 1.0;
|
[self imageDimsWhenDisabled]) ? 0.5 : 1.0;
|
||||||
|
|
||||||
|
|
|
@ -1979,14 +1979,31 @@ static NSColor *dtxtCol;
|
||||||
return NSInsetRect(theRect, borderSize.width, borderSize.height);
|
return NSInsetRect(theRect, borderSize.width, borderSize.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**<p>The GNUstep implementation returns -drawingRectForBounds:</p>
|
/**<p>Frame the image gets drawn in</p>
|
||||||
*/
|
*/
|
||||||
- (NSRect) imageRectForBounds: (NSRect)theRect
|
- (NSRect) imageRectForBounds: (NSRect)theRect
|
||||||
{
|
{
|
||||||
return [self drawingRectForBounds: theRect];
|
if (_cell.type == NSImageCellType)
|
||||||
|
{
|
||||||
|
NSRect frame = [self drawingRectForBounds: theRect];
|
||||||
|
|
||||||
|
// Add spacing between border and inside
|
||||||
|
if (_cell.is_bordered || _cell.is_bezeled)
|
||||||
|
{
|
||||||
|
frame.origin.x += 3;
|
||||||
|
frame.size.width -= 6;
|
||||||
|
frame.origin.y += 1;
|
||||||
|
frame.size.height -= 2;
|
||||||
|
}
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return theRect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** <p>TODO</p>
|
/** <p>Frame the title gets drawn in</p>
|
||||||
*/
|
*/
|
||||||
- (NSRect) titleRectForBounds: (NSRect)theRect
|
- (NSRect) titleRectForBounds: (NSRect)theRect
|
||||||
{
|
{
|
||||||
|
@ -2050,18 +2067,6 @@ static NSColor *dtxtCol;
|
||||||
*/
|
*/
|
||||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
NSRect drawingRect = [self drawingRectForBounds: cellFrame];
|
|
||||||
|
|
||||||
//FIXME: Check if this is also neccessary for images,
|
|
||||||
// Add spacing between border and inside
|
|
||||||
if (_cell.is_bordered || _cell.is_bezeled)
|
|
||||||
{
|
|
||||||
drawingRect.origin.x += 3;
|
|
||||||
drawingRect.size.width -= 6;
|
|
||||||
drawingRect.origin.y += 1;
|
|
||||||
drawingRect.size.height -= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (_cell.type)
|
switch (_cell.type)
|
||||||
{
|
{
|
||||||
case NSTextCellType:
|
case NSTextCellType:
|
||||||
|
@ -2069,7 +2074,7 @@ static NSColor *dtxtCol;
|
||||||
[self _drawEditorWithFrame: cellFrame inView: controlView];
|
[self _drawEditorWithFrame: cellFrame inView: controlView];
|
||||||
else
|
else
|
||||||
[self _drawAttributedText: [self _drawAttributedString]
|
[self _drawAttributedText: [self _drawAttributedString]
|
||||||
inFrame: drawingRect];
|
inFrame: [self titleRectForBounds: cellFrame]];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageCellType:
|
case NSImageCellType:
|
||||||
|
@ -2077,12 +2082,20 @@ static NSColor *dtxtCol;
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
NSPoint position;
|
NSPoint position;
|
||||||
|
NSRect drawingRect = [self imageRectForBounds: cellFrame];
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
size = [_cell_image size];
|
size = [_cell_image size];
|
||||||
position.x = MAX(NSMidX(drawingRect) - (size.width/2.),0.);
|
position.x = MAX(NSMidX(drawingRect) - (size.width/2.),0.);
|
||||||
position.y = MAX(NSMidY(drawingRect) - (size.height/2.),0.);
|
position.y = MAX(NSMidY(drawingRect) - (size.height/2.),0.);
|
||||||
|
rect = NSMakeRect(position.x, position.y, size.width, size.height);
|
||||||
|
|
||||||
[_cell_image drawInRect: NSMakeRect(position.x, position.y, size.width, size.height)
|
if (nil != controlView)
|
||||||
|
{
|
||||||
|
rect = [controlView centerScanRect: rect];
|
||||||
|
}
|
||||||
|
|
||||||
|
[_cell_image drawInRect: rect
|
||||||
fromRect: NSZeroRect
|
fromRect: NSZeroRect
|
||||||
operation: NSCompositeSourceOver
|
operation: NSCompositeSourceOver
|
||||||
fraction: 1.0
|
fraction: 1.0
|
||||||
|
|
|
@ -1656,6 +1656,8 @@ static NSSize _computeScale(NSSize fs, NSSize bs)
|
||||||
- (NSRect) centerScanRect: (NSRect)aRect
|
- (NSRect) centerScanRect: (NSRect)aRect
|
||||||
{
|
{
|
||||||
NSAffineTransform *matrix;
|
NSAffineTransform *matrix;
|
||||||
|
CGFloat x_org;
|
||||||
|
CGFloat y_org;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hmm - we assume that the windows coordinate system is centered on the
|
* Hmm - we assume that the windows coordinate system is centered on the
|
||||||
|
@ -1670,10 +1672,12 @@ static NSSize _computeScale(NSSize fs, NSSize bs)
|
||||||
aRect.size.height = -aRect.size.height;
|
aRect.size.height = -aRect.size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x_org = aRect.origin.x;
|
||||||
|
y_org = aRect.origin.y;
|
||||||
aRect.origin.x = GSRoundTowardsInfinity(aRect.origin.x);
|
aRect.origin.x = GSRoundTowardsInfinity(aRect.origin.x);
|
||||||
aRect.origin.y = GSRoundTowardsInfinity(aRect.origin.y);
|
aRect.origin.y = [self isFlipped] ? GSRoundTowardsNegativeInfinity(aRect.origin.y) : GSRoundTowardsInfinity(aRect.origin.y);
|
||||||
aRect.size.width = GSRoundTowardsInfinity(aRect.size.width);
|
aRect.size.width = GSRoundTowardsInfinity(aRect.size.width + (x_org - aRect.origin.x) / 2.0);
|
||||||
aRect.size.height = GSRoundTowardsInfinity(aRect.size.height);
|
aRect.size.height = GSRoundTowardsInfinity(aRect.size.height + (y_org - aRect.origin.y) / 2.0);
|
||||||
|
|
||||||
matrix = [self _matrixFromWindow];
|
matrix = [self _matrixFromWindow];
|
||||||
aRect.origin = [matrix transformPoint: aRect.origin];
|
aRect.origin = [matrix transformPoint: aRect.origin];
|
||||||
|
|
|
@ -37,7 +37,14 @@ int CHECK(NSView *view, NSRect frame)
|
||||||
return rects_almost_equal(r, frame);
|
return rects_almost_equal(r, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface TestView : NSView
|
||||||
|
@end
|
||||||
|
@implementation TestView
|
||||||
|
-(BOOL) isFlipped
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -225,6 +232,27 @@ int main(int argc, char **argv)
|
||||||
[view2 release];
|
[view2 release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
NSView *view2 = [[TestView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
|
||||||
|
|
||||||
|
testHopeful = YES;
|
||||||
|
PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.5, 0.5, 100, 100)],
|
||||||
|
NSMakeRect(1, 0, 100, 100)),
|
||||||
|
"centerScanRect works 1");
|
||||||
|
PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.9, 0.9, 99.9, 99.9)],
|
||||||
|
NSMakeRect(1, 1, 100, 100)),
|
||||||
|
"centerScanRect works 2");
|
||||||
|
PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.9, 0.9, 99.4, 99.4)],
|
||||||
|
NSMakeRect(1, 1, 99, 99)),
|
||||||
|
"centerScanRect works 3");
|
||||||
|
PASS(rects_almost_equal([view2 centerScanRect: NSMakeRect(0.4, 0.4, 99.4, 99.4)],
|
||||||
|
NSMakeRect(0, 0, 100, 100)),
|
||||||
|
"centerScanRect works 4");
|
||||||
|
testHopeful = NO;
|
||||||
|
|
||||||
|
[view2 release];
|
||||||
|
}
|
||||||
|
|
||||||
DESTROY(arp);
|
DESTROY(arp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue