* 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
This commit is contained in:
fredkiefer 2011-06-28 20:59:24 +00:00
parent a22d96f145
commit 1a31d7e65a
8 changed files with 166 additions and 69 deletions

View file

@ -1,3 +1,14 @@
2011-06-28 Fred Kiefer <FredKiefer@gmx.de>
* 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 <ewasylishen@gmail.com> 2011-06-26 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSGhostscriptImageRep.m: * Source/GSGhostscriptImageRep.m:

View file

@ -45,11 +45,11 @@
#if GS_API_VERSION(GS_API_NONE, 011500) #if GS_API_VERSION(GS_API_NONE, 011500)
@interface NSAffineTransform (GNUstep) @interface NSAffineTransform (GNUstep)
- (void) translateToPoint: (NSPoint)point; - (void) translateToPoint: (NSPoint)point;
- (void) scaleTo: (float)sx : (float)sy; - (void) scaleTo: (CGFloat)sx : (CGFloat)sy;
- (void) makeIdentityMatrix; - (void) makeIdentityMatrix;
- (float) rotationAngle; - (CGFloat) rotationAngle;
- (void) setFrameOrigin: (NSPoint)point; - (void) setFrameOrigin: (NSPoint)point;
- (void) setFrameRotation: (float)angle; - (void) setFrameRotation: (CGFloat)angle;
/* Deprecated: use -invert */ /* Deprecated: use -invert */
- (void) inverse; - (void) inverse;

View file

@ -201,26 +201,26 @@ PACKAGE_SCOPE
/* /*
* Modifying the Frame Rectangle * Modifying the Frame Rectangle
*/ */
- (float) frameRotation; - (CGFloat) frameRotation;
- (NSRect) frame; - (NSRect) frame;
- (void) setFrame: (NSRect)frameRect; - (void) setFrame: (NSRect)frameRect;
- (void) setFrameOrigin: (NSPoint)newOrigin; - (void) setFrameOrigin: (NSPoint)newOrigin;
- (void) setFrameRotation: (float)angle; - (void) setFrameRotation: (CGFloat)angle;
- (void) setFrameSize: (NSSize)newSize; - (void) setFrameSize: (NSSize)newSize;
/* /*
* Modifying the Coordinate System * Modifying the Coordinate System
*/ */
- (float) boundsRotation; - (CGFloat) boundsRotation;
- (NSRect) bounds; - (NSRect) bounds;
- (void) setBounds: (NSRect)aRect; - (void) setBounds: (NSRect)aRect;
- (void) setBoundsOrigin: (NSPoint)newOrigin; - (void) setBoundsOrigin: (NSPoint)newOrigin;
- (void) setBoundsRotation: (float)angle; - (void) setBoundsRotation: (CGFloat)angle;
- (void) setBoundsSize: (NSSize)newSize; - (void) setBoundsSize: (NSSize)newSize;
- (void) translateOriginToPoint: (NSPoint)point; - (void) translateOriginToPoint: (NSPoint)point;
- (void) scaleUnitSquareToSize: (NSSize)newSize; - (void) scaleUnitSquareToSize: (NSSize)newSize;
- (void) rotateByAngle: (float)angle; - (void) rotateByAngle: (CGFloat)angle;
- (BOOL) isFlipped; - (BOOL) isFlipped;
- (BOOL) isRotatedFromBase; - (BOOL) isRotatedFromBase;
@ -520,15 +520,15 @@ PACKAGE_SCOPE
/* /*
* Pagination * Pagination
*/ */
- (void) adjustPageHeightNew: (float*)newBottom - (void) adjustPageHeightNew: (CGFloat*)newBottom
top: (float)oldTop top: (CGFloat)oldTop
bottom: (float)oldBottom bottom: (CGFloat)oldBottom
limit: (float)bottomLimit; limit: (CGFloat)bottomLimit;
- (void) adjustPageWidthNew: (float*)newRight - (void) adjustPageWidthNew: (CGFloat*)newRight
left: (float)oldLeft left: (CGFloat)oldLeft
right: (float)oldRight right: (CGFloat)oldRight
limit: (float)rightLimit; limit: (CGFloat)rightLimit;
- (float) heightAdjustLimit; - (CGFloat) heightAdjustLimit;
- (BOOL) knowsPagesFirst: (int*)firstPageNum - (BOOL) knowsPagesFirst: (int*)firstPageNum
last: (int*)lastPageNum; last: (int*)lastPageNum;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
@ -536,7 +536,7 @@ PACKAGE_SCOPE
#endif #endif
- (NSPoint) locationOfPrintRect: (NSRect)aRect; - (NSPoint) locationOfPrintRect: (NSRect)aRect;
- (NSRect) rectForPage: (int)page; - (NSRect) rectForPage: (int)page;
- (float) widthAdjustLimit; - (CGFloat) widthAdjustLimit;
/* /*
* Writing Conforming PostScript * Writing Conforming PostScript

View file

@ -151,6 +151,7 @@ static GSDragView *sharedDragView = nil;
[dragCell setBordered: NO]; [dragCell setBordered: NO];
[sharedDragWindow setContentView: self]; [sharedDragWindow setContentView: self];
[sharedDragWindow setBackgroundColor: [NSColor clearColor]];
// Kept alive by the window // Kept alive by the window
RELEASE(self); RELEASE(self);
} }

View file

@ -58,7 +58,7 @@
*/ */
static const float pi = 3.1415926535897932384626434; static const CGFloat pi = 3.1415926535897932384626434;
@implementation NSAffineTransform (GUIAdditions) @implementation NSAffineTransform (GUIAdditions)
@ -108,15 +108,15 @@ static const float pi = 3.1415926535897932384626434;
@implementation NSAffineTransform (GNUstep) @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 it's rotated. */
if (B != 0 || C != 0) if (B != 0 || C != 0)
{ {
// FIXME: This case does not handle shear. // FIXME: This case does not handle shear.
float angle = [self rotationAngle]; CGFloat angle = [self rotationAngle];
// Keep the translation and add scaling // Keep the translation and add scaling
A = sx; B = 0; A = sx; B = 0;
@ -146,22 +146,22 @@ static const float pi = 3.1415926535897932384626434;
- (void) setFrameOrigin: (NSPoint)point - (void) setFrameOrigin: (NSPoint)point
{ {
NSAffineTransformStruct matrix = [self transformStruct]; NSAffineTransformStruct matrix = [self transformStruct];
float dx = point.x - TX; CGFloat dx = point.x - TX;
float dy = point.y - TY; CGFloat dy = point.y - TY;
[self translateXBy: dx yBy: dy]; [self translateXBy: dx yBy: dy];
} }
- (void) setFrameRotation: (float)angle - (void) setFrameRotation: (CGFloat)angle
{ {
[self rotateByDegrees: angle - [self rotationAngle]]; [self rotateByDegrees: angle - [self rotationAngle]];
} }
- (float) rotationAngle - (CGFloat) rotationAngle
{ {
NSAffineTransformStruct matrix = [self transformStruct]; NSAffineTransformStruct matrix = [self transformStruct];
float rotationAngle = atan2(-C, A); CGFloat rotationAngle = atan2(-C, A);
rotationAngle *= 180.0 / pi; rotationAngle *= 180.0 / pi;
if (rotationAngle < 0.0) if (rotationAngle < 0.0)
@ -218,16 +218,16 @@ static const float pi = 3.1415926535897932384626434;
{ {
NSAffineTransformStruct matrix = [self transformStruct]; NSAffineTransformStruct matrix = [self transformStruct];
/* Shortcuts of the usual rect values */ /* Shortcuts of the usual rect values */
float x = rect.origin.x; CGFloat x = rect.origin.x;
float y = rect.origin.y; CGFloat y = rect.origin.y;
float width = rect.size.width; CGFloat width = rect.size.width;
float height = rect.size.height; CGFloat height = rect.size.height;
float xc[3]; CGFloat xc[3];
float yc[3]; CGFloat yc[3];
float min_x; CGFloat min_x;
float max_x; CGFloat max_x;
float min_y; CGFloat min_y;
float max_y; CGFloat max_y;
int i; int i;
max_x = A * x + C * y + TX; max_x = A * x + C * y + TX;

View file

@ -913,7 +913,7 @@ scaleRect(NSRect rect, double scale)
wlimit = [_view widthAdjustLimit]; wlimit = [_view widthAdjustLimit];
for (i = first; i <= last; i++) for (i = first; i <= last; i++)
{ {
float newVal, limitVal; CGFloat newVal, limitVal;
pageRect = [self _rectForPage: i info: info xpage: &xpage ypage: &ypage]; pageRect = [self _rectForPage: i info: info xpage: &xpage ypage: &ypage];
limitVal = NSMaxY(pageRect) - hlimit * NSHeight(pageRect); limitVal = NSMaxY(pageRect) - hlimit * NSHeight(pageRect);
[_view adjustPageHeightNew: &newVal [_view adjustPageHeightNew: &newVal

View file

@ -1265,8 +1265,8 @@ static NSSize _computeScale(NSSize fs, NSSize bs)
{ {
if (_boundsMatrix == nil) if (_boundsMatrix == nil)
{ {
float sx = _bounds.size.width / _frame.size.width; CGFloat sx = _bounds.size.width / _frame.size.width;
float sy = _bounds.size.height / _frame.size.height; CGFloat sy = _bounds.size.height / _frame.size.height;
_frame.size = newSize; _frame.size = newSize;
_bounds.size.width = _frame.size.width * sx; _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) if (oldAngle != angle)
{ {
@ -1525,7 +1525,7 @@ static NSSize _computeScale(NSSize fs, NSSize bs)
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
- (void) setBoundsRotation: (float)angle - (void) setBoundsRotation: (CGFloat)angle
{ {
[self rotateByAngle: angle - [self boundsRotation]]; [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) if (angle != 0.0)
{ {
@ -1962,8 +1962,8 @@ convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matrix1,
*/ */
if (options > 0) if (options > 0)
{ {
float change = superViewFrameSize.width - oldSize.width; CGFloat change = superViewFrameSize.width - oldSize.width;
float changePerOption = change / options; CGFloat changePerOption = change / options;
if (_autoresizingMask & NSViewWidthSizable) if (_autoresizingMask & NSViewWidthSizable)
{ {
@ -1993,8 +1993,8 @@ convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matrix1,
*/ */
if (options > 0) if (options > 0)
{ {
float change = superViewFrameSize.height - oldSize.height; CGFloat change = superViewFrameSize.height - oldSize.height;
float changePerOption = change / options; CGFloat changePerOption = change / options;
if (_autoresizingMask & NSViewHeightSizable) 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 // 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 // and goes to the top and right as it grows in size for the naming
// of these variables // of these variables
float ldiff, rdiff, tdiff, bdiff; CGFloat ldiff, rdiff, tdiff, bdiff;
if (vRect.size.width == 0 && vRect.size.height == 0) if (vRect.size.width == 0 && vRect.size.height == 0)
return NO; return NO;
@ -3988,12 +3988,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
/* /*
* Pagination * Pagination
*/ */
- (void) adjustPageHeightNew: (float*)newBottom - (void) adjustPageHeightNew: (CGFloat*)newBottom
top: (float)oldTop top: (CGFloat)oldTop
bottom: (float)oldBottom bottom: (CGFloat)oldBottom
limit: (float)bottomLimit limit: (CGFloat)bottomLimit
{ {
float bottom = oldBottom; CGFloat bottom = oldBottom;
if (_rFlags.has_subviews) 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 // 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 /* Don't ask me why, but gcc-2.91.66 crashes if we use
NSMakePoint in the following expressions. We avoid this NSMakePoint in the following expressions. We avoid this
compiler internal bug by using an auxiliary aPoint compiler internal bug by using an auxiliary aPoint
@ -4040,12 +4040,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
*newBottom = bottom; *newBottom = bottom;
} }
- (void) adjustPageWidthNew: (float*)newRight - (void) adjustPageWidthNew: (CGFloat*)newRight
left: (float)oldLeft left: (CGFloat)oldLeft
right: (float)oldRight right: (CGFloat)oldRight
limit: (float)rightLimit limit: (CGFloat)rightLimit
{ {
float right = oldRight; CGFloat right = oldRight;
if (_rFlags.has_subviews) if (_rFlags.has_subviews)
{ {
@ -4058,7 +4058,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
/* See comments in adjustPageHeightNew:top:bottom:limit: /* See comments in adjustPageHeightNew:top:bottom:limit:
about why code is structured in this funny way. */ 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 /* Don't ask me why, but gcc-2.91.66 crashes if we use
NSMakePoint in the following expressions. We avoid this NSMakePoint in the following expressions. We avoid this
compiler internal bug by using an auxiliary aPoint compiler internal bug by using an auxiliary aPoint
@ -4094,9 +4094,9 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
*newRight = right; *newRight = right;
} }
- (float) heightAdjustLimit - (CGFloat) heightAdjustLimit
{ {
return 0; return 0.0;
} }
- (BOOL) knowsPagesFirst: (int*)firstPageNum last: (int*)lastPageNum - (BOOL) knowsPagesFirst: (int*)firstPageNum last: (int*)lastPageNum
@ -4143,9 +4143,9 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
return NSZeroRect; 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; return _frame;
} }
- (float) boundsRotation - (CGFloat) boundsRotation
{ {
if (_boundsMatrix != nil) if (_boundsMatrix != nil)
{ {
@ -4806,7 +4806,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
return 0.0; return 0.0;
} }
- (float) frameRotation - (CGFloat) frameRotation
{ {
if (_frameMatrix != nil) if (_frameMatrix != nil)
{ {

View file

@ -0,0 +1,85 @@
/*
copyright 2011 HNS <hns@goldelico.com>
*/
#include "Testing.h"
#include <math.h>
#include <Foundation/NSAutoreleasePool.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.h>
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;
}