mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 21:50:46 +00:00
added ruler view bugfixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16555 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
17d70ba091
commit
bf20107653
3 changed files with 64 additions and 31 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2003-04-25 Benhur Stein <benhur@inf.ufsm.br>
|
||||||
|
|
||||||
|
* Source/NSRulerView.m:
|
||||||
|
Removed unused macro BASE_LINE_LOCATION.
|
||||||
|
(setMeasurementUnits:, setClientView:, setOriginOffset:): Add call
|
||||||
|
to invalidateHashMarks, remove call to setNeedsDisplay:.
|
||||||
|
(invalidateHashMarks): Add call to setNeedsDisplay:.
|
||||||
|
(drawHashMarksAndLabelsInRect:): Changed calculation of location
|
||||||
|
of zero hash mark. Changed use of _zeroLocation ivar into
|
||||||
|
zeroLocation local variable. Limited display of hashs and
|
||||||
|
marks to baseline.
|
||||||
|
* Headers/gnustep/gui/NSRulerView.h: Renamed unused ivar
|
||||||
|
_zeroLocation to _UNUSED.
|
||||||
|
|
||||||
2003-03-26 Fred Kiefer <FredKiefer@gmx.de>
|
2003-03-26 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSControl.m
|
* Source/NSControl.m
|
||||||
|
|
|
@ -73,7 +73,7 @@ typedef enum {
|
||||||
int _marksToBigMark;
|
int _marksToBigMark;
|
||||||
int _marksToMidMark;
|
int _marksToMidMark;
|
||||||
int _marksToLabel;
|
int _marksToLabel;
|
||||||
float _zeroLocation;
|
float _UNUSED;
|
||||||
float _unitToRuler;
|
float _unitToRuler;
|
||||||
NSString *_labelFormat;
|
NSString *_labelFormat;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ DEFINE_RINT_IF_MISSING
|
||||||
#define BIG_MARK_SIZE 6
|
#define BIG_MARK_SIZE 6
|
||||||
#define LABEL_MARK_SIZE 11
|
#define LABEL_MARK_SIZE 11
|
||||||
|
|
||||||
#define BASE_LINE_LOCATION 0
|
|
||||||
#define RULER_THICKNESS 16
|
#define RULER_THICKNESS 16
|
||||||
#define MARKER_THICKNESS 15
|
#define MARKER_THICKNESS 15
|
||||||
|
|
||||||
|
@ -264,7 +263,7 @@ static NSMutableDictionary *units = nil;
|
||||||
format: @"Unknown measurement unit %@", uName];
|
format: @"Unknown measurement unit %@", uName];
|
||||||
}
|
}
|
||||||
ASSIGN(_unit, newUnit);
|
ASSIGN(_unit, newUnit);
|
||||||
[self setNeedsDisplay: YES];
|
[self invalidateHashMarks];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) measurementUnits
|
- (NSString *) measurementUnits
|
||||||
|
@ -286,7 +285,7 @@ static NSMutableDictionary *units = nil;
|
||||||
/* NB: We should not RETAIN the clientView. */
|
/* NB: We should not RETAIN the clientView. */
|
||||||
_clientView = aView;
|
_clientView = aView;
|
||||||
[self setMarkers: nil];
|
[self setMarkers: nil];
|
||||||
[self setNeedsDisplay: YES];
|
[self invalidateHashMarks];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isOpaque
|
- (BOOL) isOpaque
|
||||||
|
@ -314,7 +313,7 @@ static NSMutableDictionary *units = nil;
|
||||||
- (void) setOriginOffset: (float)offset
|
- (void) setOriginOffset: (float)offset
|
||||||
{
|
{
|
||||||
_originOffset = offset;
|
_originOffset = offset;
|
||||||
[self setNeedsDisplay: YES];
|
[self invalidateHashMarks];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) originOffset
|
- (float) originOffset
|
||||||
|
@ -615,17 +614,21 @@ static NSMutableDictionary *units = nil;
|
||||||
- (void) drawHashMarksAndLabelsInRect: (NSRect)aRect
|
- (void) drawHashMarksAndLabelsInRect: (NSRect)aRect
|
||||||
{
|
{
|
||||||
NSView *docView;
|
NSView *docView;
|
||||||
|
NSRect docBounds;
|
||||||
|
NSRect baselineRect;
|
||||||
|
NSRect visibleBaselineRect;
|
||||||
|
float firstBaselineLocation;
|
||||||
float firstVisibleLocation;
|
float firstVisibleLocation;
|
||||||
float visibleLength;
|
float lastVisibleLocation;
|
||||||
int firstVisibleMark;
|
int firstVisibleMark;
|
||||||
int lastVisibleMark;
|
int lastVisibleMark;
|
||||||
int mark;
|
int mark;
|
||||||
int firstVisibleLabel;
|
int firstVisibleLabel;
|
||||||
int lastVisibleLabel;
|
int lastVisibleLabel;
|
||||||
int label;
|
int label;
|
||||||
NSRect baseLineRect;
|
|
||||||
float baselineLocation = [self baselineLocation];
|
float baselineLocation = [self baselineLocation];
|
||||||
NSPoint zeroPoint;
|
NSPoint zeroPoint;
|
||||||
|
float zeroLocation;
|
||||||
NSBezierPath *path;
|
NSBezierPath *path;
|
||||||
NSFont *font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
|
NSFont *font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
|
||||||
NSDictionary *attr = [[NSDictionary alloc]
|
NSDictionary *attr = [[NSDictionary alloc]
|
||||||
|
@ -635,47 +638,53 @@ static NSMutableDictionary *units = nil;
|
||||||
nil];
|
nil];
|
||||||
|
|
||||||
docView = [_scrollView documentView];
|
docView = [_scrollView documentView];
|
||||||
|
docBounds = [docView bounds];
|
||||||
zeroPoint = [self convertPoint: NSMakePoint(_originOffset, _originOffset)
|
|
||||||
fromView: docView];
|
|
||||||
|
|
||||||
|
/* Calculate the location of 'zero' hash mark */
|
||||||
|
// _originOffset is an offset from document bounds origin, in doc coords
|
||||||
|
zeroPoint.x = docBounds.origin.x + _originOffset;
|
||||||
|
zeroPoint.y = docBounds.origin.y + _originOffset;
|
||||||
|
zeroPoint = [self convertPoint: zeroPoint fromView: docView];
|
||||||
if (_orientation == NSHorizontalRuler)
|
if (_orientation == NSHorizontalRuler)
|
||||||
{
|
{
|
||||||
_zeroLocation = zeroPoint.x;
|
zeroLocation = zeroPoint.x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_zeroLocation = zeroPoint.y;
|
zeroLocation = zeroPoint.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self _verifyCachedValues];
|
[self _verifyCachedValues];
|
||||||
baseLineRect = [self convertRect: [docView bounds] fromView: docView];
|
|
||||||
|
|
||||||
|
/* Calculate the base line (corresponds to the document bounds) */
|
||||||
|
baselineRect = [self convertRect: docBounds fromView: docView];
|
||||||
if (_orientation == NSHorizontalRuler)
|
if (_orientation == NSHorizontalRuler)
|
||||||
{
|
{
|
||||||
baseLineRect.origin.y = baselineLocation;
|
baselineRect.origin.y = baselineLocation;
|
||||||
baseLineRect.size.height = 1;
|
baselineRect.size.height = 1;
|
||||||
baseLineRect = NSIntersectionRect(baseLineRect, aRect);
|
firstBaselineLocation = NSMinX(baselineRect);
|
||||||
firstVisibleLocation = NSMinX(baseLineRect);
|
visibleBaselineRect = NSIntersectionRect(baselineRect, aRect);
|
||||||
visibleLength = NSWidth(baseLineRect);
|
firstVisibleLocation = NSMinX(visibleBaselineRect);
|
||||||
|
lastVisibleLocation = NSMaxX(visibleBaselineRect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
baseLineRect.origin.x = baselineLocation;
|
baselineRect.origin.x = baselineLocation;
|
||||||
baseLineRect.size.width = 1;
|
baselineRect.size.width = 1;
|
||||||
baseLineRect = NSIntersectionRect(baseLineRect, aRect);
|
firstBaselineLocation = NSMinY(baselineRect);
|
||||||
firstVisibleLocation = NSMinY(baseLineRect);
|
visibleBaselineRect = NSIntersectionRect(baselineRect, aRect);
|
||||||
visibleLength = NSHeight(baseLineRect);
|
firstVisibleLocation = NSMinY(visibleBaselineRect);
|
||||||
|
lastVisibleLocation = NSMaxY(visibleBaselineRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw the base line */
|
/* draw the base line */
|
||||||
[[NSColor blackColor] set];
|
[[NSColor blackColor] set];
|
||||||
NSRectFill(baseLineRect);
|
NSRectFill(visibleBaselineRect);
|
||||||
|
|
||||||
/* draw hash marks */
|
/* draw hash marks */
|
||||||
firstVisibleMark = floor((firstVisibleLocation - _zeroLocation)
|
firstVisibleMark = ceil((firstVisibleLocation - zeroLocation)
|
||||||
/ _markDistance);
|
/ _markDistance);
|
||||||
lastVisibleMark = floor((firstVisibleLocation + visibleLength - _zeroLocation)
|
lastVisibleMark = floor((lastVisibleLocation - zeroLocation)
|
||||||
/ _markDistance);
|
/ _markDistance);
|
||||||
path = [NSBezierPath new];
|
path = [NSBezierPath new];
|
||||||
|
|
||||||
|
@ -683,7 +692,7 @@ static NSMutableDictionary *units = nil;
|
||||||
{
|
{
|
||||||
float markLocation;
|
float markLocation;
|
||||||
|
|
||||||
markLocation = _zeroLocation + mark * _markDistance;
|
markLocation = zeroLocation + mark * _markDistance;
|
||||||
if (_orientation == NSHorizontalRuler)
|
if (_orientation == NSHorizontalRuler)
|
||||||
{
|
{
|
||||||
[path moveToPoint: NSMakePoint(markLocation, baselineLocation)];
|
[path moveToPoint: NSMakePoint(markLocation, baselineLocation)];
|
||||||
|
@ -715,15 +724,24 @@ static NSMutableDictionary *units = nil;
|
||||||
|
|
||||||
/* draw labels */
|
/* draw labels */
|
||||||
/* FIXME: shouldn't be using NSCell to draw labels? */
|
/* FIXME: shouldn't be using NSCell to draw labels? */
|
||||||
firstVisibleLabel = floor((firstVisibleLocation - _zeroLocation)
|
firstVisibleLabel = floor((firstVisibleLocation - zeroLocation)
|
||||||
/ (_marksToLabel * _markDistance));
|
/ (_marksToLabel * _markDistance));
|
||||||
lastVisibleLabel = floor((firstVisibleLocation + visibleLength - _zeroLocation)
|
lastVisibleLabel = floor((lastVisibleLocation - zeroLocation)
|
||||||
/ (_marksToLabel * _markDistance));
|
/ (_marksToLabel * _markDistance));
|
||||||
|
/* firstVisibleLabel can be to the left of the visible ruler area.
|
||||||
|
This is OK because just part of the label can be visible to the left
|
||||||
|
when scrolling. However, it should not be drawn if outside of the
|
||||||
|
baseline. */
|
||||||
|
if (zeroLocation + firstVisibleLabel * _marksToLabel * _markDistance
|
||||||
|
< firstBaselineLocation)
|
||||||
|
{
|
||||||
|
firstVisibleLabel++;
|
||||||
|
}
|
||||||
|
|
||||||
for (label = firstVisibleLabel; label <= lastVisibleLabel; label++)
|
for (label = firstVisibleLabel; label <= lastVisibleLabel; label++)
|
||||||
{
|
{
|
||||||
float labelLocation = _zeroLocation + label * _marksToLabel * _markDistance;
|
float labelLocation = zeroLocation + label * _marksToLabel * _markDistance;
|
||||||
float labelValue = (labelLocation - _zeroLocation) / _unitToRuler;
|
float labelValue = (labelLocation - zeroLocation) / _unitToRuler;
|
||||||
NSString *labelString = [NSString stringWithFormat: _labelFormat, labelValue];
|
NSString *labelString = [NSString stringWithFormat: _labelFormat, labelValue];
|
||||||
NSSize size = [labelString sizeWithAttributes: attr];
|
NSSize size = [labelString sizeWithAttributes: attr];
|
||||||
NSPoint labelPosition;
|
NSPoint labelPosition;
|
||||||
|
@ -759,6 +777,7 @@ static NSMutableDictionary *units = nil;
|
||||||
- (void) invalidateHashMarks
|
- (void) invalidateHashMarks
|
||||||
{
|
{
|
||||||
_cacheIsValid = NO;
|
_cacheIsValid = NO;
|
||||||
|
[self setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setScrollView: (NSScrollView *)scrollView
|
- (void) setScrollView: (NSScrollView *)scrollView
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue