From 1a31d7e65a44f45c02098fb7484f81b95680dbdb Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Tue, 28 Jun 2011 20:59:24 +0000 Subject: [PATCH] * Source/GSDragView.m (-init): Set the window background colour to clear. * Headers/AppKit/NSAffineTransform.h, * Headers/AppKit/NSView.h, * Source/NSAffineTransform.m, * Source/NSPrintOperation.m, * Source/NSView.m: Use CGFlaot instead of float. * Tests/gui/NSView/NSView_bounds_scale.m: New test file that currently fails. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33398 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 ++++ Headers/AppKit/NSAffineTransform.h | 6 +- Headers/AppKit/NSView.h | 30 ++++----- Source/GSDragView.m | 1 + Source/NSAffineTransform.m | 42 ++++++------- Source/NSPrintOperation.m | 2 +- Source/NSView.m | 58 +++++++++--------- Tests/gui/NSView/NSView_bounds_scale.m | 85 ++++++++++++++++++++++++++ 8 files changed, 166 insertions(+), 69 deletions(-) create mode 100644 Tests/gui/NSView/NSView_bounds_scale.m diff --git a/ChangeLog b/ChangeLog index 7dee37a67..22323acc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-06-28 Fred Kiefer + + * Source/GSDragView.m (-init): Set the window background colour to clear. + * Headers/AppKit/NSAffineTransform.h, + * Headers/AppKit/NSView.h, + * Source/NSAffineTransform.m, + * Source/NSPrintOperation.m, + * Source/NSView.m: Use CGFlaot instead of float. + * Tests/gui/NSView/NSView_bounds_scale.m: New test file that + currently fails. + 2011-06-26 Eric Wasylishen * Source/GSGhostscriptImageRep.m: diff --git a/Headers/AppKit/NSAffineTransform.h b/Headers/AppKit/NSAffineTransform.h index 252d0cf47..beef4ce22 100644 --- a/Headers/AppKit/NSAffineTransform.h +++ b/Headers/AppKit/NSAffineTransform.h @@ -45,11 +45,11 @@ #if GS_API_VERSION(GS_API_NONE, 011500) @interface NSAffineTransform (GNUstep) - (void) translateToPoint: (NSPoint)point; -- (void) scaleTo: (float)sx : (float)sy; +- (void) scaleTo: (CGFloat)sx : (CGFloat)sy; - (void) makeIdentityMatrix; -- (float) rotationAngle; +- (CGFloat) rotationAngle; - (void) setFrameOrigin: (NSPoint)point; -- (void) setFrameRotation: (float)angle; +- (void) setFrameRotation: (CGFloat)angle; /* Deprecated: use -invert */ - (void) inverse; diff --git a/Headers/AppKit/NSView.h b/Headers/AppKit/NSView.h index 4019773e4..db63a66f1 100644 --- a/Headers/AppKit/NSView.h +++ b/Headers/AppKit/NSView.h @@ -201,26 +201,26 @@ PACKAGE_SCOPE /* * Modifying the Frame Rectangle */ -- (float) frameRotation; +- (CGFloat) frameRotation; - (NSRect) frame; - (void) setFrame: (NSRect)frameRect; - (void) setFrameOrigin: (NSPoint)newOrigin; -- (void) setFrameRotation: (float)angle; +- (void) setFrameRotation: (CGFloat)angle; - (void) setFrameSize: (NSSize)newSize; /* * Modifying the Coordinate System */ -- (float) boundsRotation; +- (CGFloat) boundsRotation; - (NSRect) bounds; - (void) setBounds: (NSRect)aRect; - (void) setBoundsOrigin: (NSPoint)newOrigin; -- (void) setBoundsRotation: (float)angle; +- (void) setBoundsRotation: (CGFloat)angle; - (void) setBoundsSize: (NSSize)newSize; - (void) translateOriginToPoint: (NSPoint)point; - (void) scaleUnitSquareToSize: (NSSize)newSize; -- (void) rotateByAngle: (float)angle; +- (void) rotateByAngle: (CGFloat)angle; - (BOOL) isFlipped; - (BOOL) isRotatedFromBase; @@ -520,15 +520,15 @@ PACKAGE_SCOPE /* * Pagination */ -- (void) adjustPageHeightNew: (float*)newBottom - top: (float)oldTop - bottom: (float)oldBottom - limit: (float)bottomLimit; -- (void) adjustPageWidthNew: (float*)newRight - left: (float)oldLeft - right: (float)oldRight - limit: (float)rightLimit; -- (float) heightAdjustLimit; +- (void) adjustPageHeightNew: (CGFloat*)newBottom + top: (CGFloat)oldTop + bottom: (CGFloat)oldBottom + limit: (CGFloat)bottomLimit; +- (void) adjustPageWidthNew: (CGFloat*)newRight + left: (CGFloat)oldLeft + right: (CGFloat)oldRight + limit: (CGFloat)rightLimit; +- (CGFloat) heightAdjustLimit; - (BOOL) knowsPagesFirst: (int*)firstPageNum last: (int*)lastPageNum; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) @@ -536,7 +536,7 @@ PACKAGE_SCOPE #endif - (NSPoint) locationOfPrintRect: (NSRect)aRect; - (NSRect) rectForPage: (int)page; -- (float) widthAdjustLimit; +- (CGFloat) widthAdjustLimit; /* * Writing Conforming PostScript diff --git a/Source/GSDragView.m b/Source/GSDragView.m index c1c8ef85d..4b750bcfe 100644 --- a/Source/GSDragView.m +++ b/Source/GSDragView.m @@ -151,6 +151,7 @@ static GSDragView *sharedDragView = nil; [dragCell setBordered: NO]; [sharedDragWindow setContentView: self]; + [sharedDragWindow setBackgroundColor: [NSColor clearColor]]; // Kept alive by the window RELEASE(self); } diff --git a/Source/NSAffineTransform.m b/Source/NSAffineTransform.m index 4e7a064fc..2b9b06907 100644 --- a/Source/NSAffineTransform.m +++ b/Source/NSAffineTransform.m @@ -58,7 +58,7 @@ */ -static const float pi = 3.1415926535897932384626434; +static const CGFloat pi = 3.1415926535897932384626434; @implementation NSAffineTransform (GUIAdditions) @@ -108,15 +108,15 @@ static const float pi = 3.1415926535897932384626434; @implementation NSAffineTransform (GNUstep) -- (void) scaleTo: (float)sx : (float)sy +- (void) scaleTo: (CGFloat)sx : (CGFloat)sy { - NSAffineTransformStruct matrix = [self transformStruct]; + NSAffineTransformStruct matrix = [self transformStruct]; /* If it's rotated. */ if (B != 0 || C != 0) { // FIXME: This case does not handle shear. - float angle = [self rotationAngle]; + CGFloat angle = [self rotationAngle]; // Keep the translation and add scaling A = sx; B = 0; @@ -146,22 +146,22 @@ static const float pi = 3.1415926535897932384626434; - (void) setFrameOrigin: (NSPoint)point { - NSAffineTransformStruct matrix = [self transformStruct]; - float dx = point.x - TX; - float dy = point.y - TY; + NSAffineTransformStruct matrix = [self transformStruct]; + CGFloat dx = point.x - TX; + CGFloat dy = point.y - TY; [self translateXBy: dx yBy: dy]; } -- (void) setFrameRotation: (float)angle +- (void) setFrameRotation: (CGFloat)angle { [self rotateByDegrees: angle - [self rotationAngle]]; } -- (float) rotationAngle +- (CGFloat) rotationAngle { - NSAffineTransformStruct matrix = [self transformStruct]; - float rotationAngle = atan2(-C, A); + NSAffineTransformStruct matrix = [self transformStruct]; + CGFloat rotationAngle = atan2(-C, A); rotationAngle *= 180.0 / pi; if (rotationAngle < 0.0) @@ -218,16 +218,16 @@ static const float pi = 3.1415926535897932384626434; { NSAffineTransformStruct matrix = [self transformStruct]; /* Shortcuts of the usual rect values */ - float x = rect.origin.x; - float y = rect.origin.y; - float width = rect.size.width; - float height = rect.size.height; - float xc[3]; - float yc[3]; - float min_x; - float max_x; - float min_y; - float max_y; + CGFloat x = rect.origin.x; + CGFloat y = rect.origin.y; + CGFloat width = rect.size.width; + CGFloat height = rect.size.height; + CGFloat xc[3]; + CGFloat yc[3]; + CGFloat min_x; + CGFloat max_x; + CGFloat min_y; + CGFloat max_y; int i; max_x = A * x + C * y + TX; diff --git a/Source/NSPrintOperation.m b/Source/NSPrintOperation.m index 584250913..4938acbb1 100644 --- a/Source/NSPrintOperation.m +++ b/Source/NSPrintOperation.m @@ -913,7 +913,7 @@ scaleRect(NSRect rect, double scale) wlimit = [_view widthAdjustLimit]; for (i = first; i <= last; i++) { - float newVal, limitVal; + CGFloat newVal, limitVal; pageRect = [self _rectForPage: i info: info xpage: &xpage ypage: &ypage]; limitVal = NSMaxY(pageRect) - hlimit * NSHeight(pageRect); [_view adjustPageHeightNew: &newVal diff --git a/Source/NSView.m b/Source/NSView.m index 6b741e01a..1d0e9e460 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -1265,8 +1265,8 @@ static NSSize _computeScale(NSSize fs, NSSize bs) { if (_boundsMatrix == nil) { - float sx = _bounds.size.width / _frame.size.width; - float sy = _bounds.size.height / _frame.size.height; + CGFloat sx = _bounds.size.width / _frame.size.width; + CGFloat sy = _bounds.size.height / _frame.size.height; _frame.size = newSize; _bounds.size.width = _frame.size.width * sx; @@ -1305,9 +1305,9 @@ static NSSize _computeScale(NSSize fs, NSSize bs) } } -- (void) setFrameRotation: (float)angle +- (void) setFrameRotation: (CGFloat)angle { - float oldAngle = [self frameRotation]; + CGFloat oldAngle = [self frameRotation]; if (oldAngle != angle) { @@ -1525,7 +1525,7 @@ static NSSize _computeScale(NSSize fs, NSSize bs) [self setNeedsDisplay: YES]; } -- (void) setBoundsRotation: (float)angle +- (void) setBoundsRotation: (CGFloat)angle { [self rotateByAngle: angle - [self boundsRotation]]; } @@ -1600,7 +1600,7 @@ static NSSize _computeScale(NSSize fs, NSSize bs) } } -- (void) rotateByAngle: (float)angle +- (void) rotateByAngle: (CGFloat)angle { if (angle != 0.0) { @@ -1962,8 +1962,8 @@ convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matrix1, */ if (options > 0) { - float change = superViewFrameSize.width - oldSize.width; - float changePerOption = change / options; + CGFloat change = superViewFrameSize.width - oldSize.width; + CGFloat changePerOption = change / options; if (_autoresizingMask & NSViewWidthSizable) { @@ -1993,8 +1993,8 @@ convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matrix1, */ if (options > 0) { - float change = superViewFrameSize.height - oldSize.height; - float changePerOption = change / options; + CGFloat change = superViewFrameSize.height - oldSize.height; + CGFloat changePerOption = change / options; if (_autoresizingMask & NSViewHeightSizable) { @@ -3067,7 +3067,7 @@ Returns YES iff any scrolling was done. // Ok we assume that the rectangle is origined at the bottom left // and goes to the top and right as it grows in size for the naming // of these variables - float ldiff, rdiff, tdiff, bdiff; + CGFloat ldiff, rdiff, tdiff, bdiff; if (vRect.size.width == 0 && vRect.size.height == 0) return NO; @@ -3988,12 +3988,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) /* * Pagination */ -- (void) adjustPageHeightNew: (float*)newBottom - top: (float)oldTop - bottom: (float)oldBottom - limit: (float)bottomLimit +- (void) adjustPageHeightNew: (CGFloat*)newBottom + top: (CGFloat)oldTop + bottom: (CGFloat)oldBottom + limit: (CGFloat)bottomLimit { - float bottom = oldBottom; + CGFloat bottom = oldBottom; if (_rFlags.has_subviews) { @@ -4004,7 +4004,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) { // FIXME: We have to convert this values for the subclass - float oTop, oBottom, oLimit; + CGFloat oTop, oBottom, oLimit; /* Don't ask me why, but gcc-2.91.66 crashes if we use NSMakePoint in the following expressions. We avoid this compiler internal bug by using an auxiliary aPoint @@ -4040,12 +4040,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) *newBottom = bottom; } -- (void) adjustPageWidthNew: (float*)newRight - left: (float)oldLeft - right: (float)oldRight - limit: (float)rightLimit +- (void) adjustPageWidthNew: (CGFloat*)newRight + left: (CGFloat)oldLeft + right: (CGFloat)oldRight + limit: (CGFloat)rightLimit { - float right = oldRight; + CGFloat right = oldRight; if (_rFlags.has_subviews) { @@ -4058,7 +4058,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) /* See comments in adjustPageHeightNew:top:bottom:limit: about why code is structured in this funny way. */ - float oLeft, oRight, oLimit; + CGFloat oLeft, oRight, oLimit; /* Don't ask me why, but gcc-2.91.66 crashes if we use NSMakePoint in the following expressions. We avoid this compiler internal bug by using an auxiliary aPoint @@ -4094,9 +4094,9 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) *newRight = right; } -- (float) heightAdjustLimit +- (CGFloat) heightAdjustLimit { - return 0; + return 0.0; } - (BOOL) knowsPagesFirst: (int*)firstPageNum last: (int*)lastPageNum @@ -4143,9 +4143,9 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) return NSZeroRect; } -- (float) widthAdjustLimit +- (CGFloat) widthAdjustLimit { - return 0; + return 0.0; } /* @@ -4796,7 +4796,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) return _frame; } -- (float) boundsRotation +- (CGFloat) boundsRotation { if (_boundsMatrix != nil) { @@ -4806,7 +4806,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) return 0.0; } -- (float) frameRotation +- (CGFloat) frameRotation { if (_frameMatrix != nil) { diff --git a/Tests/gui/NSView/NSView_bounds_scale.m b/Tests/gui/NSView/NSView_bounds_scale.m new file mode 100644 index 000000000..e95b5efed --- /dev/null +++ b/Tests/gui/NSView/NSView_bounds_scale.m @@ -0,0 +1,85 @@ +/* +copyright 2011 HNS +*/ +#include "Testing.h" + +#include + +#include +#include +#include +#include + +int CHECK(NSView *view, NSRect frame, NSRect bounds) +{ + NSRect r; + + r = [view frame]; + if (fabs(r.origin.x - frame.origin.x)>0.001 + || fabs(r.origin.y - frame.origin.y)>0.001 + || fabs(r.size.width - frame.size.width)>0.001 + || fabs(r.size.height - frame.size.height)>0.001) + { + printf("(1) expected frame (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, + r.origin.x, r.origin.y, r.size.width, r.size.height); + + return 0; + } + + r = [view bounds]; + if (fabs(r.origin.x - bounds.origin.x)>0.001 + || fabs(r.origin.y - bounds.origin.y)>0.001 + || fabs(r.size.width - bounds.size.width)>0.001 + || fabs(r.size.height - bounds.size.height)>0.001) + { + printf("(2) expected bounds (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, + r.origin.x, r.origin.y, r.size.width, r.size.height); + + return 0; + } + + return 1; +} + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + NSWindow *window; + NSView *view1; + int passed = 1; + + [NSApplication sharedApplication]; + window = [[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,200,200) + styleMask: NSClosableWindowMask + backing: NSBackingStoreRetained + defer: YES]; + view1 = [[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)]; + + [[window contentView] addSubview: view1]; + + [view1 setBounds: NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(30.4657, 88.5895, 21.2439, 60.8716)) && passed; + [view1 setBoundsRotation: 30]; + passed = (fabs([view1 boundsRotation] - 30.0) <= 0.001) && passed; + // passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(70.5714, 50.9892, 48.8336, 63.3383)) && passed; + passed = CHECK(view1, NSMakeRect(20,20,100,100), NSMakeRect(70.6788, 50.866, 48.8336, 63.3383)) && passed; + [view1 setBounds:(NSRect){{30.4657, 88.5895}, {21.2439, 60.8716}}]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{30.4657, 77.9676}, {48.8336, 63.3383}}) && passed; + [view1 scaleUnitSquareToSize:(NSSize){0.720733, 0.747573}]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{42.2704, 104.294}, {67.7554, 84.7253}}) && passed; + [view1 setBoundsRotation: 30 - 1e-6]; + passed = (fabs([view1 boundsRotation] - 30.0 + 1e-6) <= 0.001) && passed; + passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{39.9801, 104.211}, {66.2393, 85.2544}}) && passed; + [view1 rotateByAngle: 1e-6]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),(NSRect) {{39.9801, 104.211}, {66.2393, 85.2544}}) && passed; + passed = (fabs([view1 boundsRotation] - 30.0) <= 0.001) && passed; + + pass(passed,"NSView -scaleUnitSquareToSize works"); + + DESTROY(arp); + return 0; +} +