merged in changes from trunk to work with moved NSAffineTransform

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@24134 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-11-19 11:39:27 +00:00
parent 3825d42113
commit f92292517e
7 changed files with 91 additions and 350 deletions

View file

@ -1,6 +1,22 @@
2006-11-17 Richard Frith-Macdoanld <rfm@gnu.org>
2006-11-19 Richard Frith-Macdoanld <rfm@gnu.org>
Sync with trunc at revision 24120.
* Merged in changes from trunk at revision 24133.
2006-11-19 Richard Frith-Macdoanld <rfm@gnu.org>
* Source/NSAffineTransform.m:
* Headers/AppKit/NSAffineTransform.h:
Remove basic implementation (now in base for MacOS-X compatibility)
retaining gui specific methods and GNUstep extensions (to deprecate?)
* Source/NSImage.m:
* Source/NSStringDrawing.m:
* Source/NSView.m:
Update to use transformStruct accessor method rather than trying to
work with the affine transform ivars directly.
2006-11-18 Richard Frith-Macdoanld <rfm@gnu.org>
* Source/NSScrollView.m: Adjust corner view when scroller is on right.
2006-11-17 Richard Frith-Macdoanld <rfm@gnu.org>

View file

@ -5,7 +5,7 @@
Author: Ovidiu Predescu <ovidiu@net-community.com>
Date: August 1997
Rewrite for macOS-X compatibility: Richard Frith-Macdonald, 1999
Rewrite for MacOS-X compatibility: Richard Frith-Macdonald, 1999
This file is part of the GNUstep GUI Library.
@ -29,43 +29,15 @@
#define _GNUstep_H_NSAffineTransform
#import <GNUstepBase/GSVersionMacros.h>
#include <Foundation/NSObject.h>
#include <Foundation/NSGeometry.h>
#import <Foundation/NSAffineTransform.h>
@class NSBezierPath;
typedef struct {
float m11;
float m12;
float m21;
float m22;
float tX;
float tY;
} NSAffineTransformStruct;
@interface NSAffineTransform (GUIAdditions)
@interface NSAffineTransform : NSObject <NSCopying, NSCoding>
{
@public
NSAffineTransformStruct matrix;
}
+ (NSAffineTransform*) transform;
- (void) appendTransform: (NSAffineTransform*)aTransform;
- (void) concat;
- (id) initWithTransform: (NSAffineTransform*)aTransform;
- (void) invert;
- (void) prependTransform: (NSAffineTransform*)aTransform;
- (void) rotateByDegrees: (float)angle;
- (void) rotateByRadians: (float)angleRad;
- (void) scaleBy: (float)scale;
- (void) scaleXBy: (float)scaleX yBy: (float)scaleY;
- (void) set;
- (void) setTransformStruct: (NSAffineTransformStruct)val;
- (NSBezierPath*) transformBezierPath: (NSBezierPath*)aPath;
- (NSPoint) transformPoint: (NSPoint)aPoint;
- (NSSize) transformSize: (NSSize)aSize;
- (NSAffineTransformStruct) transformStruct;
- (void) translateXBy: (float)tranX yBy: (float)tranY;
@end
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
@ -77,7 +49,7 @@ typedef struct {
- (void) setFrameOrigin: (NSPoint)point;
- (void) setFrameRotation: (float)angle;
/* Old Apple name for -invert */
/* Deprecated: use -invert */
- (void) inverse;
- (BOOL) isRotated;
@ -93,7 +65,9 @@ typedef struct {
- (NSSize) sizeInMatrixSpace: (NSSize)size;
- (NSRect) rectInMatrixSpace: (NSRect)rect;
/* Deprecated: use -setTransformStruct: */
- (void) setMatrix: (const float[6])replace;
/* Deprecated: use -transformStruct */
- (void) getMatrix: (float[6])replace;
- (void) takeMatrixFromTransform: (NSAffineTransform *)aTransform;

View file

@ -25,7 +25,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include "config.h"
@ -39,7 +40,13 @@
#include "AppKit/NSBezierPath.h"
#include "AppKit/PSOperators.h"
typedef struct internal
{
@defs(NSAffineTransform)
} *iptr;
/* Private definitions */
#define matrix (((iptr)self)->_matrix)
#define A matrix.m11
#define B matrix.m12
#define C matrix.m21
@ -71,46 +78,11 @@ matrix_multiply (NSAffineTransformStruct MA, NSAffineTransformStruct MB)
return MC;
}
@implementation NSAffineTransform
static NSAffineTransformStruct identityTransform = {
1.0, 0.0, 0.0, 1.0, 0.0, 0.0
};
/**
* Return an autoreleased instance of this class.
*/
+ (NSAffineTransform*) transform
{
NSAffineTransform *t;
t = (NSAffineTransform*)NSAllocateObject(self, 0, NSDefaultMallocZone());
t->matrix = identityTransform;
return AUTORELEASE(t);
}
/**
* Return an autoreleased instance of this class.
*/
+ (id) new
{
NSAffineTransform *t;
t = (NSAffineTransform*)NSAllocateObject(self, 0, NSDefaultMallocZone());
t->matrix = identityTransform;
return t;
}
/**
* Appends the transform matrix to the receiver. This is done by performing a
* matrix multiplication of the receiver with aTransform so that aTransform
* is the first transform applied to the user coordinate. The new
* matrix then replaces the receiver's matrix.
*/
- (void) appendTransform: (NSAffineTransform*)aTransform
{
matrix = matrix_multiply(matrix, aTransform->matrix);
}
@implementation NSAffineTransform (GUIAdditions)
/**
* Concatenates the receiver's matrix with the one in the current graphics
@ -128,142 +100,18 @@ static NSAffineTransformStruct identityTransform = {
PSconcat(m);
}
/**
* Initialize the transformation matrix instance to the identity matrix.
* The identity matrix transforms a point to itself.
*/
- (id) init
{
matrix = identityTransform;
return self;
}
/**
* Initialize the receiever's instance with the instance represented
* by aTransform.
*/
- (id) initWithTransform: (NSAffineTransform*)aTransform
{
matrix = aTransform->matrix;
return self;
}
/**
* Calculates the inverse of the receiver's matrix and replaces the
* receiever's matrix with it.
*/
- (void) invert
{
float newA, newB, newC, newD, newTX, newTY;
float det;
det = A * D - B * C;
if (det == 0)
{
NSLog (@"error: determinant of matrix is 0!");
return;
}
newA = D / det;
newB = -B / det;
newC = -C / det;
newD = A / det;
newTX = (-D * TX + C * TY) / det;
newTY = (B * TX - A * TY) / det;
NSDebugLLog(@"NSAffineTransform",
@"inverse of matrix ((%f, %f) (%f, %f) (%f, %f))\n"
@"is ((%f, %f) (%f, %f) (%f, %f))",
A, B, C, D, TX, TY,
newA, newB, newC, newD, newTX, newTY);
A = newA; B = newB;
C = newC; D = newD;
TX = newTX; TY = newTY;
}
/**
* Prepends the transform matrix to the receiver. This is done by performing a
* matrix multiplication of the receiver with aTransform so that aTransform
* is the last transform applied to the user coordinate. The new
* matrix then replaces the receiver's matrix.
*/
- (void) prependTransform: (NSAffineTransform*)aTransform
{
matrix = matrix_multiply(aTransform->matrix, matrix);
}
/**
* Applies the rotation specified by angle in degrees. Points transformed
* with the transformation matrix of the receiver are rotated counter-clockwise
* by the number of degrees specified by angle.
*/
- (void) rotateByDegrees: (float)angle
{
[self rotateByRadians: pi * angle / 180];
}
/**
* Applies the rotation specified by angle in radians. Points transformed
* with the transformation matrix of the receiver are rotated counter-clockwise
* by the number of radians specified by angle.
*/
- (void) rotateByRadians: (float)angleRad
{
float sine = sin (angleRad);
float cosine = cos (angleRad);
NSAffineTransformStruct rotm;
rotm.m11 = cosine; rotm.m12 = sine; rotm.m21 = -sine; rotm.m22 = cosine;
rotm.tX = rotm.tY = 0;
matrix = matrix_multiply(rotm, matrix);
}
/**
* Scales the transformation matrix of the reciever by the factor specified
* by scale.
*/
- (void) scaleBy: (float)scale
{
NSAffineTransformStruct scam = identityTransform;
scam.m11 = scale; scam.m22 = scale;
matrix = matrix_multiply(scam, matrix);
}
/**
* Scales the X axis of the receiver's transformation matrix
* by scaleX and the Y axis of the transformation matrix by scaleY.
*/
- (void) scaleXBy: (float)scaleX yBy: (float)scaleY
{
NSAffineTransformStruct scam = identityTransform;
scam.m11 = scaleX; scam.m22 = scaleY;
matrix = matrix_multiply(scam, matrix);
}
/**
* Get the currently active graphics context's transformation
* matrix and set it into the receiver.
*/
- (void) set
{
GSSetCTM(GSCurrentContext(), self);
}
/**
* <p>
* Sets the structure which represents the matrix of the reciever.
* The struct is of the form:</p>
* <p>{m11, m12, m21, m22, tX, tY}</p>
*/
- (void) setTransformStruct: (NSAffineTransformStruct)val
{
matrix = val;
}
/**
* <p>
* Applies the receiver's transformation matrix to each point in
* <p>Applies the receiver's transformation matrix to each point in
* the bezier path, then returns the result. The original bezier
* path is not modified.
* </p>
@ -276,104 +124,7 @@ static NSAffineTransformStruct identityTransform = {
return AUTORELEASE(path);
}
/**
* Transforms a single point based on the transformation matrix.
* Returns the resulting point.
*/
- (NSPoint) transformPoint: (NSPoint)aPoint
{
NSPoint new;
new.x = A * aPoint.x + C * aPoint.y + TX;
new.y = B * aPoint.x + D * aPoint.y + TY;
return new;
}
/**
* Transforms the NSSize represented by aSize using the reciever's
* transformation matrix. Returns the resulting NSSize.
*/
- (NSSize) transformSize: (NSSize)aSize
{
NSSize new;
new.width = A * aSize.width + C * aSize.height;
if (new.width < 0)
new.width = - new.width;
new.height = B * aSize.width + D * aSize.height;
if (new.height < 0)
new.height = - new.height;
return new;
}
/**
* <p>
* Returns the <code>NSAffineTransformStruct</code> structure
* which represents the matrix of the reciever.
* The struct is of the form:</p>
* <p>{m11, m12, m21, m22, tX, tY}</p>
*/
- (NSAffineTransformStruct) transformStruct
{
return matrix;
}
/**
* Applies the translation specified by tranX and tranY to the receiver's matrix.
* Points transformed by the reciever's matrix after this operation will
* be shifted in position based on the specified translation.
*/
- (void) translateXBy: (float)tranX yBy: (float)tranY
{
NSAffineTransformStruct tranm = identityTransform;
tranm.tX = tranX;
tranm.tY = tranY;
matrix = matrix_multiply(tranm, matrix);
}
- (id) copyWithZone: (NSZone*)zone
{
return NSCopyObject(self, 0, zone);
}
- (BOOL) isEqual: (id)anObject
{
if ([anObject class] == isa)
{
NSAffineTransform *o = anObject;
if (A == o->A && B == o->B && C == o->C
&& D == o->D && TX == o->TX && TY == o->TY)
return YES;
}
return NO;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
float replace[6];
[aCoder decodeArrayOfObjCType: @encode(float)
count: 6
at: replace];
[self setMatrix: replace];
return self;
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
float replace[6];
[self getMatrix: replace];
[aCoder encodeArrayOfObjCType: @encode(float)
count: 6
at: replace];
}
@end /* NSAffineTransform */
@end /* NSAffineTransform (GUIAdditions) */
@implementation NSAffineTransform (GNUstep)
@ -571,13 +322,6 @@ static NSAffineTransformStruct identityTransform = {
return new;
}
- (NSString*) description
{
return [NSString stringWithFormat:
@"NSAffineTransform ((%f, %f) (%f, %f) (%f, %f))",
A, B, C, D, TX, TY];
}
- (void) setMatrix: (const float[6])replace
{
matrix.m11 = replace[0];
@ -600,12 +344,7 @@ static NSAffineTransformStruct identityTransform = {
- (void) takeMatrixFromTransform: (NSAffineTransform *)aTransform
{
matrix.m11 = aTransform->matrix.m11;
matrix.m12 = aTransform->matrix.m12;
matrix.m21 = aTransform->matrix.m21;
matrix.m22 = aTransform->matrix.m22;
matrix.tX = aTransform->matrix.tX;
matrix.tY = aTransform->matrix.tY;
matrix = [aTransform transformStruct];
}

View file

@ -1005,7 +1005,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
NSAffineTransform *transform;
if (!dstRect.size.width || !dstRect.size.height
|| !srcRect.size.width || !srcRect.size.height)
|| !srcRect.size.width || !srcRect.size.height)
return;
if (![ctxt isDrawingToScreen])
@ -1046,16 +1046,19 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
/* If the effective transform is the identity transform and there's
no dissolve, we can composite from our cache. */
if (delta == 1.0
&& fabs(transform->matrix.m11 - 1.0) < 0.01
&& fabs(transform->matrix.m12) < 0.01
&& fabs(transform->matrix.m21) < 0.01
&& fabs(transform->matrix.m22 - 1.0) < 0.01)
if (delta == 1.0)
{
[self compositeToPoint: dstRect.origin
fromRect: srcRect
operation: op];
return;
NSAffineTransformStruct ts = [transform transformStruct];
if (fabs(ts.m11 - 1.0) < 0.01 && fabs(ts.m12) < 0.01
&& fabs(ts.m21) < 0.01 && fabs(ts.m22 - 1.0) < 0.01)
{
[self compositeToPoint: dstRect.origin
fromRect: srcRect
operation: op];
return;
}
}
/* We can't composite or dissolve directly from the image reps, so we
@ -1078,6 +1081,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
*/
{
NSCachedImageRep *cache;
NSAffineTransformStruct ts;
NSSize s;
NSPoint p;
double x0, y0, x1, y1, w, h;
@ -1134,8 +1138,10 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
/* Set up the effective transform. We also save a gState with this
transform to make it easier to do the final composite. */
transform->matrix.tX = p.x;
transform->matrix.tY = p.y;
ts = [transform transformStruct];
ts.tX = p.x;
ts.tY = p.y;
[transform setTransformStruct: ts];
[ctxt GSSetCTM: transform];
gState = [ctxt GSDefineGState];

View file

@ -832,6 +832,15 @@ static float scrollerWidth;
NSSize border = _sizeForBorderType(_borderType);
NSRectEdge bottomEdge, topEdge;
float headerViewHeight = 0;
NSRectEdge verticalScrollerEdge = NSMinXEdge;
NSInterfaceStyle style;
style = NSInterfaceStyleForKey(@"NSScrollViewInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle
|| style == NSWindows95InterfaceStyle)
{
verticalScrollerEdge = NSMaxXEdge;
}
/* Determine edge positions. */
if (_rFlags.flipped_view)
@ -880,24 +889,15 @@ static float scrollerWidth;
if (_hasVertScroller)
{
NSRect vertScrollerRect;
NSRectEdge edge = NSMinXEdge;
NSInterfaceStyle style;
style = NSInterfaceStyleForKey(@"NSScrollViewInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle
|| style == NSWindows95InterfaceStyle)
{
edge = NSMaxXEdge;
}
NSDivideRect (contentRect, &vertScrollerRect, &contentRect,
scrollerWidth, edge);
scrollerWidth, verticalScrollerEdge);
[_vertScroller setFrame: vertScrollerRect];
/* Substract 1 for the line that separates the vertical scroller
* from the clip view (and eventually the horizontal scroller). */
NSDivideRect (contentRect, NULL, &contentRect, 1, edge);
NSDivideRect (contentRect, NULL, &contentRect, 1, verticalScrollerEdge);
}
/* Prepare the horizontal scroller. */
@ -930,7 +930,13 @@ static float scrollerWidth;
/* Now place the corner view. */
if (_hasCornerView)
{
[_cornerView setFrameOrigin: headerRect.origin];
NSPoint p = headerRect.origin;
if (verticalScrollerEdge == NSMaxXEdge)
{
p.x += contentRect.size.width;
}
[_cornerView setFrameOrigin: p];
}
/* Now place the rulers. */
@ -1040,12 +1046,12 @@ static float scrollerWidth;
return [_contentView backgroundColor];
}
- (void)setDrawsBackground:(BOOL)flag
- (void) setDrawsBackground: (BOOL)flag
{
[_contentView setDrawsBackground: flag];
}
- (BOOL)drawsBackground
- (BOOL) drawsBackground
{
return [_contentView drawsBackground];
}
@ -1454,6 +1460,7 @@ static float scrollerWidth;
BOOL hadHeaderView = _hasHeaderView;
BOOL hadCornerView = _hasCornerView;
NSView *aView = nil;
_hasHeaderView = ([[self documentView]
respondsToSelector: @selector(headerView)]
&& (aView=[(NSTableView *)[self documentView] headerView]));
@ -1475,8 +1482,8 @@ static float scrollerWidth;
{
aView = nil;
_hasCornerView =
([[self documentView] respondsToSelector: @selector(cornerView)]
&& (aView=[(NSTableView *)[self documentView] cornerView]));
([[self documentView] respondsToSelector: @selector(cornerView)]
&& (aView=[(NSTableView *)[self documentView] cornerView]));
if (aView == _cornerView)
return;
@ -1484,7 +1491,7 @@ static float scrollerWidth;
{
if (hadCornerView == NO)
{
[self addSubview:aView];
[self addSubview: aView];
}
else
{

View file

@ -350,11 +350,11 @@ static int cache_lookup_attributed_string(NSAttributedString *string,
static int use_screen_fonts(void)
{
NSGraphicsContext *ctxt = GSCurrentContext();
NSAffineTransform *ctm = GSCurrentCTM(ctxt);
NSGraphicsContext *ctxt = GSCurrentContext();
NSAffineTransform *ctm = GSCurrentCTM(ctxt);
NSAffineTransformStruct ts = [ctm transformStruct];
if (ctm->matrix.m11 != 1.0 || ctm->matrix.m12 != 0.0 ||
ctm->matrix.m21 != 0.0 || fabs(ctm->matrix.m22) != 1.0)
if (ts.m11 != 1.0 || ts.m12 != 0.0 || ts.m21 != 0.0 || fabs(ts.m22) != 1.0)
{
return 0;
}

View file

@ -306,16 +306,12 @@ GSSetDragTypes(NSView* obj, NSArray *types)
NSRect superviewsVisibleRect;
BOOL wasFlipped = _super_view->_rFlags.flipped_view;
NSAffineTransform *pMatrix = [_super_view _matrixToWindow];
NSAffineTransform *tMatrix = nil;
[_matrixToWindow takeMatrixFromTransform: pMatrix];
NSAffineTransformStruct ts = [pMatrix transformStruct];
/* prepend translation */
tMatrix = _matrixToWindow;
tMatrix->matrix.tX = NSMinX(_frame) * tMatrix->matrix.m11 +
NSMinY(_frame) * tMatrix->matrix.m21 + tMatrix->matrix.tX;
tMatrix->matrix.tY = NSMinX(_frame) * tMatrix->matrix.m12 +
NSMinY(_frame) * tMatrix->matrix.m22 + tMatrix->matrix.tY;
ts.tX = NSMinX(_frame) * ts.m11 + NSMinY(_frame) * ts.m21 + ts.tX;
ts.tY = NSMinX(_frame) * ts.m12 + NSMinY(_frame) * ts.m22 + ts.tY;
[_matrixToWindow setTransformStruct: ts];
/* prepend rotation */
if (_frameMatrix != nil)
@ -330,11 +326,14 @@ GSSetDragTypes(NSView* obj, NSArray *types)
* exactly overlays the original. To do that, we must translate
* the origin by the height of the view.
*/
flip->matrix.tY = _frame.size.height;
ts = [flip transformStruct];
ts.tY = _frame.size.height;
[flip setTransformStruct: ts];
(*preImp)(_matrixToWindow, preSel, flip);
}
(*preImp)(_matrixToWindow, preSel, _boundsMatrix);
[_matrixFromWindow takeMatrixFromTransform: _matrixToWindow];
ts = [_matrixToWindow transformStruct];
[_matrixFromWindow setTransformStruct: ts];
[_matrixFromWindow invert];
superviewsVisibleRect = [self convertRect: [_super_view visibleRect]