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

@ -514,104 +514,132 @@ float sx, sy;
return NSZeroRect; return NSZeroRect;
} }
- (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;
NSView* view = [viewsPath objectAtIndex:i]; parent = [viewsPath objectAtIndex: i];
wasFlipped = [parent isFlipped];
[matrix concatenateWith:view->frameMatrix]; while (i-- > 0)
[matrix concatenateWith:view->boundsMatrix]; {
} NSView *view = [viewsPath objectAtIndex: i];
return matrix; [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];
parent = view;
wasFlipped = isFlipped;
}
return matrix;
} }
- (NSArray*)_pathBetweenSubview:(NSView*)subview - (NSMutableArray*) _pathBetweenSubview: (NSView*)subview
toSuperview:(NSView*)_superview toSuperview: (NSView*)_superview
{ {
NSMutableArray* array = [NSMutableArray array]; NSMutableArray *array = [NSMutableArray array];
NSView* view = subview; NSView *view = subview;
while (view && view != _superview) while (view && view != _superview)
{ {
[array addObject:view]; [array addObject:view];
view = view->super_view; view = view->super_view;
} }
return array; return array;
} }
- (NSPoint)convertPoint:(NSPoint)aPoint fromView:(NSView*)aView - (NSPoint) convertPoint: (NSPoint)aPoint fromView: (NSView*)aView
{ {
NSPoint new; NSPoint new;
PSMatrix* matrix; PSMatrix *matrix;
if (!aView) if (!aView)
aView = [window contentView]; aView = [window contentView];
if ([self isDescendantOf:aView]) if ([self isDescendantOf: aView])
{ {
NSArray* path = [self _pathBetweenSubview:self toSuperview:aView]; NSMutableArray *path;
matrix = [self _concatenateMatricesInReverseOrderFromPath:path]; path = [self _pathBetweenSubview: self toSuperview: aView];
[matrix inverse]; [path addObject: aView];
new = [matrix pointInMatrixSpace:aPoint]; matrix = [self _concatenateMatricesInReverseOrderFromPath:path];
} [matrix inverse];
else new = [matrix pointInMatrixSpace:aPoint];
if ([aView isDescendantOf:self]) }
{ else if ([aView isDescendantOf: self])
NSArray* path = [self _pathBetweenSubview:aView toSuperview:self]; {
NSMutableArray *path;
matrix = [self _concatenateMatricesInReverseOrderFromPath:path]; path = [self _pathBetweenSubview: aView toSuperview: self];
new = [matrix pointInMatrixSpace:aPoint]; [path addObject: self];
} // The views are not in the same hierarchy of views. matrix = [self _concatenateMatricesInReverseOrderFromPath: path];
else // Convert the point to window from the other's view new = [matrix pointInMatrixSpace: aPoint];
{ // coordinates and then to our view coordinates. }
new = [aView convertPoint:aPoint toView:nil]; else
new = [self convertPoint:new fromView:nil]; {
} new = [aView convertPoint: aPoint toView: nil];
new = [self convertPoint: new fromView: nil];
}
return new; return new;
} }
- (NSPoint)convertPoint:(NSPoint)aPoint toView:(NSView *)aView - (NSPoint) convertPoint: (NSPoint)aPoint toView: (NSView*)aView
{ {
if (!aView) if (!aView)
aView = [window contentView]; aView = [window contentView];
return [aView convertPoint:aPoint fromView:self]; return [aView convertPoint: aPoint fromView: self];
} }
- (NSRect)convertRect:(NSRect)aRect fromView:(NSView *)aView - (NSRect) convertRect: (NSRect)aRect fromView: (NSView*)aView
{ {
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;
} }
- (NSRect)convertRect:(NSRect)aRect toView:(NSView *)aView - (NSRect) convertRect: (NSRect)aRect toView: (NSView*)aView
{ {
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;
} }
- (PSMatrix*)_concatenateBoundsMatricesInReverseOrderFromPath:(NSArray*)viewsPath - (PSMatrix*)_concatenateBoundsMatricesInReverseOrderFromPath:(NSArray*)viewsPath