mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 18:11:06 +00:00
Fixes for flipped views
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3996 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8f47f76dc6
commit
a4144cabfd
5 changed files with 107 additions and 68 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Mar 30 14:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSCell.m: Position image correctly in flipped views.
|
||||
* Source/NSSplitView.m: Position dimple image correctly when flipped.
|
||||
* Source/NSImage.m: Tidied a little
|
||||
* Source/NSScrollView.m: Work when flipped - and make NSScrollView
|
||||
flipped unless a subclass dictates otherwise.
|
||||
|
||||
Tue Mar 30 05:26:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Headers/AppKit/NSScroller.h: Modified ([-setContentView:]) and
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
|
@ -603,6 +604,14 @@
|
|||
[title drawInRect: cellFrame withAttributes: dict];
|
||||
}
|
||||
|
||||
static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
|
||||
{
|
||||
NSPoint p;
|
||||
p.x = MAX(NSMidX(outerRect) - (innerSize.width/2.),0.);
|
||||
p.y = MAX(NSMidY(outerRect) - (innerSize.height/2.),0.);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Draw image centered in frame.
|
||||
- (void) _drawImage: (NSImage *) image inFrame: (NSRect) cellFrame
|
||||
{
|
||||
|
@ -613,8 +622,13 @@
|
|||
return;
|
||||
|
||||
size = [image size];
|
||||
position.x = NSMidX (cellFrame) - size.width / 2;
|
||||
position.y = NSMidY (cellFrame) - size.height / 2;
|
||||
position = centerSizeInRect(size, cellFrame);
|
||||
/*
|
||||
* Images are always drawn with their bottom-left corner at the origin
|
||||
* so we must adjust the position to take account of a flipped view.
|
||||
*/
|
||||
if ([control_view isFlipped])
|
||||
position.y -= size.height;
|
||||
[image compositeToPoint: position operation: NSCompositeCopy];
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
FIXME:
|
||||
[1] Filter services not implemented.
|
||||
[2] Should there be a place to look for system bitmaps?
|
||||
(findImageNamed:).
|
||||
(findImageNamed: ).
|
||||
[3] bestRepresentation is not complete.
|
||||
*/
|
||||
#include <gnustep/gui/config.h>
|
||||
|
@ -57,10 +57,12 @@ static NSString* NSImage_PATH = @"Images";
|
|||
/* Backend protocol - methods that must be implemented by the backend to
|
||||
complete the class */
|
||||
@protocol NSImageBackend
|
||||
- (void) compositeToPoint: (NSPoint)point fromRect: (NSRect)rect
|
||||
operation: (NSCompositingOperation)op;
|
||||
- (void) dissolveToPoint: (NSPoint)point fromRect: (NSRect)rect
|
||||
fraction: (float)aFloat;
|
||||
- (void) compositeToPoint: (NSPoint)point
|
||||
fromRect: (NSRect)rect
|
||||
operation: (NSCompositingOperation)op;
|
||||
- (void) dissolveToPoint: (NSPoint)point
|
||||
fromRect: (NSRect)rect
|
||||
fraction: (float)aFloat;
|
||||
@end
|
||||
|
||||
typedef struct _rep_data_t
|
||||
|
@ -107,7 +109,7 @@ set_repd_for_rep(NSMutableArray *_reps, NSImageRep *rep, rep_data_t *new_repd)
|
|||
[[_reps objectAtIndex: i] getValue: &repd];
|
||||
if (repd.rep == rep && !found)
|
||||
{
|
||||
[_reps replaceObjectAtIndex: i withObject:
|
||||
[_reps replaceObjectAtIndex: i withObject:
|
||||
[NSValue value: new_repd withObjCType: @encode(rep_data_t)]];
|
||||
found = YES;
|
||||
break;
|
||||
|
@ -138,17 +140,17 @@ static NSDictionary* nsmapping = nil;
|
|||
{
|
||||
if (self == [NSImage class])
|
||||
{
|
||||
NSBundle *system = [NSBundle bundleWithPath:gnustep_libdir];
|
||||
NSString* path = [system pathForResource:@"nsmapping"
|
||||
ofType:@"strings"
|
||||
inDirectory:NSImage_PATH];
|
||||
NSBundle *system = [NSBundle bundleWithPath: gnustep_libdir];
|
||||
NSString* path = [system pathForResource: @"nsmapping"
|
||||
ofType: @"strings"
|
||||
inDirectory: NSImage_PATH];
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
[self setVersion: 1];
|
||||
|
||||
// initialize the class variables
|
||||
nameDict = [[NSMutableDictionary alloc] initWithCapacity: 10];
|
||||
if (path)
|
||||
nsmapping = [[[NSString stringWithContentsOfFile:path]
|
||||
nsmapping = [[[NSString stringWithContentsOfFile: path]
|
||||
propertyListFromStringsFileFormat]
|
||||
retain];
|
||||
}
|
||||
|
@ -156,13 +158,13 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
+ imageNamed: (NSString *)aName
|
||||
{
|
||||
NSString* realName = [nsmapping objectForKey:aName];
|
||||
NSString* realName = [nsmapping objectForKey: aName];
|
||||
|
||||
if (realName)
|
||||
aName = realName;
|
||||
|
||||
/* If there is no image with that name, search in the main bundle */
|
||||
if (!nameDict || ![nameDict objectForKey:aName])
|
||||
if (!nameDict || ![nameDict objectForKey: aName])
|
||||
{
|
||||
NSString* ext;
|
||||
NSString* path = nil;
|
||||
|
@ -199,7 +201,7 @@ static NSDictionary* nsmapping = nil;
|
|||
while ((o = [e nextObject]))
|
||||
{
|
||||
NSDebugLog(@"extension %s\n", [o cString]);
|
||||
path = [main pathForResource:the_name
|
||||
path = [main pathForResource: the_name
|
||||
ofType: o];
|
||||
if ([path length] != 0)
|
||||
break;
|
||||
|
@ -250,7 +252,7 @@ static NSDictionary* nsmapping = nil;
|
|||
}
|
||||
}
|
||||
|
||||
return [nameDict objectForKey:aName];
|
||||
return [nameDict objectForKey: aName];
|
||||
}
|
||||
|
||||
// Designated initializer for nearly everything.
|
||||
|
@ -282,7 +284,7 @@ static NSDictionary* nsmapping = nil;
|
|||
if ((self = [self init]) == o)
|
||||
{
|
||||
_flags.dataRetained = NO;
|
||||
if (![self useFromFile:fileName])
|
||||
if (![self useFromFile: fileName])
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
|
@ -298,7 +300,7 @@ static NSDictionary* nsmapping = nil;
|
|||
if ((self = [self init]) == o)
|
||||
{
|
||||
_flags.dataRetained = YES;
|
||||
if (![self useFromFile:fileName])
|
||||
if (![self useFromFile: fileName])
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
|
@ -324,7 +326,7 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
- initWithPasteboard: (NSPasteboard *)pasteboard
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
[self notImplemented: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -352,7 +354,7 @@ static NSDictionary* nsmapping = nil;
|
|||
/* Make sure we don't remove name from the nameDict if we are just a copy
|
||||
of the named image, not the original image */
|
||||
if (name && self == [nameDict objectForKey: name])
|
||||
[nameDict removeObjectForKey:name];
|
||||
[nameDict removeObjectForKey: name];
|
||||
[name release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -571,7 +573,7 @@ static NSDictionary* nsmapping = nil;
|
|||
cached.original = rep;
|
||||
cached.validCache = YES;
|
||||
[_reps removeLastObject];
|
||||
[_reps addObject:
|
||||
[_reps addObject:
|
||||
[NSValue value: &cached withObjCType: @encode(rep_data_t)]];
|
||||
}
|
||||
#endif
|
||||
|
@ -599,16 +601,17 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
// Using the Image
|
||||
- (void) compositeToPoint: (NSPoint)aPoint
|
||||
operation: (NSCompositingOperation)op;
|
||||
operation: (NSCompositingOperation)op;
|
||||
{
|
||||
NSRect rect;
|
||||
[self size];
|
||||
rect = NSMakeRect(0, 0, _size.width, _size.height);
|
||||
[self compositeToPoint: aPoint fromRect:rect operation: op];
|
||||
[self compositeToPoint: aPoint fromRect: rect operation: op];
|
||||
}
|
||||
|
||||
- (void) compositeToPoint: (NSPoint)aPoint fromRect: (NSRect)aRect
|
||||
operation: (NSCompositingOperation)op;
|
||||
- (void) compositeToPoint: (NSPoint)aPoint
|
||||
fromRect: (NSRect)aRect
|
||||
operation: (NSCompositingOperation)op;
|
||||
{
|
||||
NSImageRep *rep;
|
||||
NSRect rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
|
||||
|
@ -630,8 +633,9 @@ static NSDictionary* nsmapping = nil;
|
|||
[self dissolveToPoint: aPoint fromRect: rect fraction: aFloat];
|
||||
}
|
||||
|
||||
- (void) dissolveToPoint: (NSPoint)aPoint fromRect: (NSRect)aRect
|
||||
fraction: (float)aFloat;
|
||||
- (void) dissolveToPoint: (NSPoint)aPoint
|
||||
fromRect: (NSRect)aRect
|
||||
fraction: (float)aFloat;
|
||||
{
|
||||
NSImageRep *rep;
|
||||
NSRect rect = NSMakeRect(aPoint.x, aPoint.y, _size.width, _size.height);
|
||||
|
@ -678,7 +682,7 @@ static NSDictionary* nsmapping = nil;
|
|||
return ok;
|
||||
}
|
||||
|
||||
- (BOOL)loadFromFile: (NSString *)fileName
|
||||
- (BOOL) loadFromFile: (NSString *)fileName
|
||||
{
|
||||
NSArray* array;
|
||||
|
||||
|
@ -750,12 +754,12 @@ static NSDictionary* nsmapping = nil;
|
|||
if (!imageSize.width || !imageSize.height)
|
||||
return NO;
|
||||
|
||||
// FIMXE: determine alpha? separate?
|
||||
// FIXME: determine alpha? separate?
|
||||
rep = [[NSCachedImageRep alloc] initWithSize: _size
|
||||
depth: depth
|
||||
separate: NO
|
||||
alpha: NO];
|
||||
[self addRepresentation:rep];
|
||||
[self addRepresentation: rep];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -840,8 +844,7 @@ static NSDictionary* nsmapping = nil;
|
|||
return [_repList lastObject];
|
||||
}
|
||||
|
||||
- (NSImageRep *) bestRepresentationForDevice:
|
||||
(NSDictionary *)deviceDescription;
|
||||
- (NSImageRep*) bestRepresentationForDevice: (NSDictionary*)deviceDescription
|
||||
{
|
||||
id o, e;
|
||||
NSImageRep *rep = nil;
|
||||
|
@ -877,7 +880,7 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
- (NSArray *) representations
|
||||
{
|
||||
int i, count;
|
||||
unsigned i, count;
|
||||
if (!_repList)
|
||||
_repList = [[NSMutableArray alloc] init];
|
||||
if (_syncLoad)
|
||||
|
@ -888,7 +891,7 @@ static NSDictionary* nsmapping = nil;
|
|||
{
|
||||
rep_data_t repd;
|
||||
[[_reps objectAtIndex: i] getValue: &repd];
|
||||
[_repList addObject:repd.rep];
|
||||
[_repList addObject: repd.rep];
|
||||
}
|
||||
return _repList;
|
||||
}
|
||||
|
@ -898,7 +901,7 @@ static NSDictionary* nsmapping = nil;
|
|||
delegate = anObject;
|
||||
}
|
||||
|
||||
- delegate
|
||||
- (id) delegate
|
||||
{
|
||||
return delegate;
|
||||
}
|
||||
|
@ -918,10 +921,10 @@ static NSDictionary* nsmapping = nil;
|
|||
}
|
||||
|
||||
// Methods Implemented by the Delegate
|
||||
- (NSImage *)imageDidNotDraw:(id)sender
|
||||
inRect:(NSRect)aRect
|
||||
- (NSImage *)imageDidNotDraw: (id)sender
|
||||
inRect: (NSRect)aRect
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(imageDidNotDraw:inRect:)])
|
||||
if ([delegate respondsToSelector: @selector(imageDidNotDraw:inRect:)])
|
||||
return [delegate imageDidNotDraw: sender inRect: aRect];
|
||||
else
|
||||
return self;
|
||||
|
@ -939,9 +942,9 @@ static NSDictionary* nsmapping = nil;
|
|||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
if (name && [nameDict objectForKey:name])
|
||||
if (name && [nameDict objectForKey: name])
|
||||
{
|
||||
return [nameDict objectForKey:name];
|
||||
return [nameDict objectForKey: name];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
|
@ -151,7 +151,7 @@ static Class rulerViewClass = nil;
|
|||
//
|
||||
// Instance methods
|
||||
//
|
||||
- initWithFrame: (NSRect)rect
|
||||
- (id) initWithFrame: (NSRect)rect
|
||||
{
|
||||
[super initWithFrame: rect];
|
||||
[self setContentView: [[NSClipView new] autorelease]];
|
||||
|
@ -164,7 +164,7 @@ static Class rulerViewClass = nil;
|
|||
return self;
|
||||
}
|
||||
|
||||
- init
|
||||
- (id) init
|
||||
{
|
||||
return [self initWithFrame: NSZeroRect];
|
||||
}
|
||||
|
@ -181,6 +181,11 @@ static Class rulerViewClass = nil;
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL) isFlipped
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) setContentView: (NSClipView*)aView
|
||||
{
|
||||
ASSIGN((id)_contentView, (id)aView);
|
||||
|
@ -479,7 +484,14 @@ static Class rulerViewClass = nil;
|
|||
horizScrollerRect.size.width = contentRect.size.width;
|
||||
horizScrollerRect.size.height = scrollerWidth;
|
||||
|
||||
contentRect.origin.y += scrollerWidth + 1;
|
||||
if ([self isFlipped])
|
||||
{
|
||||
horizScrollerRect.origin.y += contentRect.size.height + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
contentRect.origin.y += scrollerWidth + 1;
|
||||
}
|
||||
}
|
||||
|
||||
[_horizScroller setFrame: horizScrollerRect];
|
||||
|
@ -494,6 +506,7 @@ static Class rulerViewClass = nil;
|
|||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
NSGraphicsContext *ctxt = [NSGraphicsContext currentContext];
|
||||
float scrollerWidth = [NSScroller scrollerWidth];
|
||||
float horizLinePosition, horizLineLength = [self bounds].size.width;
|
||||
float borderThickness = 0;
|
||||
|
@ -503,7 +516,7 @@ static Class rulerViewClass = nil;
|
|||
// rect.origin.x, rect.origin.y,
|
||||
// rect.size.width, rect.size.height);
|
||||
|
||||
PSgsave ();
|
||||
DPSgsave(ctxt);
|
||||
switch ([self borderType])
|
||||
{
|
||||
case NSNoBorder:
|
||||
|
@ -511,41 +524,45 @@ static Class rulerViewClass = nil;
|
|||
|
||||
case NSLineBorder:
|
||||
borderThickness = 1;
|
||||
NSFrameRect (rect);
|
||||
NSFrameRect(rect);
|
||||
break;
|
||||
|
||||
case NSBezelBorder:
|
||||
borderThickness = 2;
|
||||
NSDrawGrayBezel (rect, rect);
|
||||
NSDrawGrayBezel(rect, rect);
|
||||
break;
|
||||
|
||||
case NSGrooveBorder:
|
||||
borderThickness = 2;
|
||||
NSDrawGroove (rect, rect);
|
||||
NSDrawGroove(rect, rect);
|
||||
break;
|
||||
}
|
||||
|
||||
horizLinePosition = borderThickness;
|
||||
|
||||
PSsetlinewidth (1);
|
||||
PSsetgray (0);
|
||||
DPSsetlinewidth(ctxt, 1);
|
||||
DPSsetgray(ctxt, 0);
|
||||
if (_hasVertScroller)
|
||||
{
|
||||
horizLinePosition = scrollerWidth + borderThickness;
|
||||
horizLineLength -= scrollerWidth + 2 * borderThickness;
|
||||
PSmoveto (horizLinePosition, borderThickness + 1);
|
||||
PSrlineto (0, [self bounds].size.height - 2 * borderThickness);
|
||||
PSstroke ();
|
||||
DPSmoveto(ctxt, horizLinePosition, borderThickness + 1);
|
||||
DPSrlineto(ctxt, 0, [self bounds].size.height - 2 * borderThickness - 1);
|
||||
DPSstroke(ctxt);
|
||||
}
|
||||
|
||||
if (_hasHorizScroller)
|
||||
{
|
||||
PSmoveto (horizLinePosition, scrollerWidth + borderThickness + 1);
|
||||
PSrlineto (horizLineLength - 1, 0);
|
||||
PSstroke ();
|
||||
float ypos = scrollerWidth + borderThickness + 1;
|
||||
|
||||
if ([self isFlipped])
|
||||
ypos = [self bounds].size.height - ypos;
|
||||
DPSmoveto(ctxt, horizLinePosition, ypos);
|
||||
DPSrlineto(ctxt, horizLineLength - 1, 0);
|
||||
DPSstroke(ctxt);
|
||||
}
|
||||
|
||||
PSgrestore ();
|
||||
DPSgrestore(ctxt);
|
||||
}
|
||||
|
||||
- (NSRect) documentVisibleRect
|
||||
|
|
|
@ -393,7 +393,7 @@ RETURN_LABEL:
|
|||
draggedBarWidth = newWidth;
|
||||
}
|
||||
|
||||
NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
|
||||
static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
|
||||
{
|
||||
NSPoint p;
|
||||
p.x = MAX(NSMidX(outerRect) - (innerSize.width/2.),0.);
|
||||
|
@ -401,11 +401,6 @@ NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect)
|
|||
return p;
|
||||
}
|
||||
|
||||
NSPoint centerRectInRect(NSRect innerRect, NSRect outerRect)
|
||||
{
|
||||
return centerSizeInRect(innerRect.size,outerRect);
|
||||
}
|
||||
|
||||
- (void) drawDividerInRect: (NSRect)aRect
|
||||
{
|
||||
NSPoint dimpleOrigin;
|
||||
|
@ -416,11 +411,13 @@ NSPoint centerRectInRect(NSRect innerRect, NSRect outerRect)
|
|||
return;
|
||||
dimpleSize = [dimpleImage size];
|
||||
|
||||
/* composite into the center of the given rect. Since NSImages
|
||||
are always flipped, we adjust for it here */
|
||||
dimpleOrigin = centerSizeInRect(dimpleSize,aRect);
|
||||
dimpleOrigin = centerSizeInRect(dimpleSize, aRect);
|
||||
/*
|
||||
* Images are always drawn with their bottom-left corner at the origin
|
||||
* so we must adjust the position to take account of a flipped view.
|
||||
*/
|
||||
if ([self isFlipped])
|
||||
dimpleOrigin.y += dimpleSize.height;
|
||||
dimpleOrigin.y -= dimpleSize.height;
|
||||
[dimpleImage compositeToPoint: dimpleOrigin operation: NSCompositeSourceOver];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue