Update to fix coordinate conversion between views.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3585 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-01-22 20:28:12 +00:00
parent d4f4617d09
commit 710675c693
2 changed files with 96 additions and 67 deletions

View file

@ -477,9 +477,10 @@ PSMatrix* matrix;
NSEventType eventType; NSEventType eventType;
NSRect knobRect = {{0,0},{0,0}}; NSRect knobRect = {{0,0},{0,0}};
int periodCount = 0; // allows a forced update int periodCount = 0; // allows a forced update
NSArray* path = [self _pathBetweenSubview:self NSMutableArray* path = [self _pathBetweenSubview:self
toSuperview:[window contentView]]; toSuperview:[window contentView]];
[path addObject: [window contentView]];
matrix = [self _concatenateMatricesInReverseOrderFromPath:path]; matrix = [self _concatenateMatricesInReverseOrderFromPath:path];
[matrix inverse]; [matrix inverse];

View file

@ -516,21 +516,40 @@ float sx, sy;
- (PSMatrix*) _concatenateMatricesInReverseOrderFromPath: (NSArray*)viewsPath - (PSMatrix*) _concatenateMatricesInReverseOrderFromPath: (NSArray*)viewsPath
{ {
int i, count = [viewsPath count]; unsigned i = [viewsPath count];
PSMatrix *matrix = [[PSMatrix new] autorelease]; PSMatrix *matrix = [[PSMatrix new] autorelease];
NSView *parent;
BOOL wasFlipped;
BOOL isFlipped;
for (i = count - 1; i >= 0; i--) if (i-- < 2)
return matrix;
parent = [viewsPath objectAtIndex: i];
wasFlipped = [parent isFlipped];
while (i-- > 0)
{ {
NSView *view = [viewsPath objectAtIndex: i]; NSView *view = [viewsPath objectAtIndex: i];
[matrix concatenateWith: view->frameMatrix]; [matrix concatenateWith: view->frameMatrix];
isFlipped = [view isFlipped];
if (isFlipped != wasFlipped)
{
PSMatrix *flip = nil;
float vals[6] = { 1, 0, 0, -1, 0, 1 };
vals[5] = parent->bounds.size.height;
flip = [PSMatrix matrixFrom: vals];
[matrix concatenateWith: flip];
}
[matrix concatenateWith: view->boundsMatrix]; [matrix concatenateWith: view->boundsMatrix];
parent = view;
wasFlipped = isFlipped;
} }
return matrix; return matrix;
} }
- (NSArray*)_pathBetweenSubview:(NSView*)subview - (NSMutableArray*) _pathBetweenSubview: (NSView*)subview
toSuperview: (NSView*)_superview toSuperview: (NSView*)_superview
{ {
NSMutableArray *array = [NSMutableArray array]; NSMutableArray *array = [NSMutableArray array];
@ -555,22 +574,25 @@ PSMatrix* matrix;
if ([self isDescendantOf: aView]) if ([self isDescendantOf: aView])
{ {
NSArray* path = [self _pathBetweenSubview:self toSuperview:aView]; NSMutableArray *path;
path = [self _pathBetweenSubview: self toSuperview: aView];
[path addObject: aView];
matrix = [self _concatenateMatricesInReverseOrderFromPath:path]; matrix = [self _concatenateMatricesInReverseOrderFromPath:path];
[matrix inverse]; [matrix inverse];
new = [matrix pointInMatrixSpace:aPoint]; new = [matrix pointInMatrixSpace:aPoint];
} }
else else if ([aView isDescendantOf: self])
if ([aView isDescendantOf:self])
{ {
NSArray* path = [self _pathBetweenSubview:aView toSuperview:self]; NSMutableArray *path;
path = [self _pathBetweenSubview: aView toSuperview: self];
[path addObject: self];
matrix = [self _concatenateMatricesInReverseOrderFromPath: path]; matrix = [self _concatenateMatricesInReverseOrderFromPath: path];
new = [matrix pointInMatrixSpace: aPoint]; new = [matrix pointInMatrixSpace: aPoint];
} // The views are not in the same hierarchy of views. }
else // Convert the point to window from the other's view else
{ // coordinates and then to our view coordinates. {
new = [aView convertPoint: aPoint toView: nil]; new = [aView convertPoint: aPoint toView: nil];
new = [self convertPoint: new fromView: nil]; new = [self convertPoint: new fromView: nil];
} }
@ -590,12 +612,15 @@ PSMatrix* matrix;
{ {
NSRect r; NSRect r;
if (aView && window != [aView window]) // Must belong to the /* Must belong to the same window */
return NSZeroRect; // same window if (aView && window != [aView window])
return NSZeroRect;
r = aRect; r = aRect;
r.origin = [self convertPoint: r.origin fromView: aView]; r.origin = [self convertPoint: r.origin fromView: aView];
r.size = [self convertSize: r.size fromView: aView]; r.size = [self convertSize: r.size fromView: aView];
if ([aView isFlipped] != [self isFlipped])
r.origin.y -= r.size.height;
return r; return r;
} }
@ -604,12 +629,15 @@ NSRect r;
{ {
NSRect r; NSRect r;
if (aView && window != [aView window]) // Must belong to the /* Must belong to the same window */
return NSZeroRect; // same window if (aView && window != [aView window])
return NSZeroRect;
r = aRect; r = aRect;
r.origin = [self convertPoint: r.origin toView: aView]; r.origin = [self convertPoint: r.origin toView: aView];
r.size = [self convertSize: r.size toView: aView]; r.size = [self convertSize: r.size toView: aView];
if ([aView isFlipped] != [self isFlipped])
r.origin.y -= r.size.height;
return r; return r;
} }