* Source/GSGuiPrivate.h: New rounding rounding function

GSRoundTowardsInfinity which is simply floor(x+0.5)
* Source/NSBrowser.m:
* Source/NSSliderCell.m:
* Source/NSButtonCell.m:
* Source/NSClipView.m:
* Source/NSOutlineView.m:
* Source/NSRulerView.m:
Switch rint[f] to GSRoundTowardsInfinity


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33539 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-07-12 21:12:22 +00:00
parent adca33937f
commit c7e05f2c7b
8 changed files with 45 additions and 19 deletions

View file

@ -1,3 +1,15 @@
2011-07-12 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSGuiPrivate.h: New rounding rounding function
GSRoundTowardsInfinity which is simply floor(x+0.5)
* Source/NSBrowser.m:
* Source/NSSliderCell.m:
* Source/NSButtonCell.m:
* Source/NSClipView.m:
* Source/NSOutlineView.m:
* Source/NSRulerView.m:
Switch rint[f] to GSRoundTowardsInfinity
2011-07-11 Eric Wasylishen <ewasylishen@gmail.com> 2011-07-11 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSGhostscriptImageRep.m: Only invoke 'which' once. * Source/GSGhostscriptImageRep.m: Only invoke 'which' once.

View file

@ -32,6 +32,7 @@
#import <Foundation/NSBundle.h> #import <Foundation/NSBundle.h>
#include "GNUstepBase/preface.h" #include "GNUstepBase/preface.h"
#include <math.h>
/* /*
* Return the gnustep-gui bundle used to load gnustep-gui resources. * Return the gnustep-gui bundle used to load gnustep-gui resources.
@ -71,5 +72,21 @@ static inline NSString *GSGuiLocalizedString (NSString *key, NSString *comment)
#endif #endif
#define NSLocalizedString(key,comment) GSGuiLocalizedString (key, comment) #define NSLocalizedString(key,comment) GSGuiLocalizedString (key, comment)
/**
* Rounds to the nearest integer, and in the case of ties, round to the
* larger integer. This is the recommended rounding function for rounding
* graphics points.
*
* For example:
* GSRoundTowardsInfinity(0.8) == 1.0
* GSRoundTowardsInfinity(0.5) == 1.0
* GSRoundTowardsInfinity(0.1) == 0.0
* GSRoundTowardsInfinity(-2.5) == -2.0
*/
static inline CGFloat GSRoundTowardsInfinity(CGFloat x)
{
return floor(x + 0.5);
}
#endif /* _GNUstep_H_GSGuiPrivate */ #endif /* _GNUstep_H_GSGuiPrivate */

View file

@ -56,7 +56,7 @@
#import "AppKit/NSBezierPath.h" #import "AppKit/NSBezierPath.h"
#import "GNUstepGUI/GSTheme.h" #import "GNUstepGUI/GSTheme.h"
DEFINE_RINT_IF_MISSING #import "GSGuiPrivate.h"
/* Cache */ /* Cache */
static float scrollerWidth; // == [NSScroller scrollerWidth] static float scrollerWidth; // == [NSScroller scrollerWidth]
@ -1667,7 +1667,7 @@ static NSTextFieldCell *titleCell;
{ {
float f = [sender floatValue]; float f = [sender floatValue];
[self scrollColumnToVisible: rintf(f * _lastColumnLoaded)]; [self scrollColumnToVisible: GSRoundTowardsInfinity(f * _lastColumnLoaded)];
} }
break; break;

View file

@ -59,8 +59,6 @@
#include <math.h> #include <math.h>
DEFINE_RINT_IF_MISSING
typedef struct _GSButtonCellFlags typedef struct _GSButtonCellFlags
{ {
#if GS_WORDS_BIGENDIAN == 1 #if GS_WORDS_BIGENDIAN == 1
@ -969,7 +967,7 @@ typedef struct _GSButtonCellFlags
{ {
position = [controlView convertPointToBase: position]; position = [controlView convertPointToBase: position];
} }
position = NSMakePoint(rint(position.x), rint(position.y)); position = NSMakePoint(GSRoundTowardsInfinity(position.x), GSRoundTowardsInfinity(position.y));
if (controlView) if (controlView)
{ {
position = [controlView convertPointFromBase: position]; position = [controlView convertPointFromBase: position];

View file

@ -44,8 +44,6 @@
#include <math.h> #include <math.h>
DEFINE_RINT_IF_MISSING
@interface NSClipView (Private) @interface NSClipView (Private)
- (void) _scrollToPoint: (NSPoint)aPoint; - (void) _scrollToPoint: (NSPoint)aPoint;
@end @end
@ -444,8 +442,8 @@ static inline NSRect integralRect (NSRect rect, NSView *view)
*/ */
if (_copiesOnScroll) if (_copiesOnScroll)
{ {
new.x = _bounds.origin.x + (rint(new.x - _bounds.origin.x)); new.x = _bounds.origin.x + (GSRoundTowardsInfinity(new.x - _bounds.origin.x));
new.y = _bounds.origin.y + (rint(new.y - _bounds.origin.y)); new.y = _bounds.origin.y + (GSRoundTowardsInfinity(new.y - _bounds.origin.y));
} }
return new; return new;

View file

@ -59,6 +59,7 @@
#import "AppKit/NSTextFieldCell.h" #import "AppKit/NSTextFieldCell.h"
#import "AppKit/NSWindow.h" #import "AppKit/NSWindow.h"
#import "GSGuiPrivate.h"
#include <math.h> #include <math.h>
static NSNotificationCenter *nc = nil; static NSNotificationCenter *nc = nil;
@ -1282,9 +1283,9 @@ Also returns the child index relative to this parent. */
/* _bounds.origin is (0, 0) when the outline view is not clipped. /* _bounds.origin is (0, 0) when the outline view is not clipped.
* When the view is scrolled, _bounds.origin.y returns the scrolled height. */ * When the view is scrolled, _bounds.origin.y returns the scrolled height. */
verticalQuarterPosition = verticalQuarterPosition =
rint(((p.y + _bounds.origin.y) / _rowHeight) * 4.); GSRoundTowardsInfinity(((p.y + _bounds.origin.y) / _rowHeight) * 4.);
horizontalHalfPosition = horizontalHalfPosition =
rint(((p.x + _bounds.origin.y) / _indentationPerLevel) * 2.); GSRoundTowardsInfinity(((p.x + _bounds.origin.y) / _indentationPerLevel) * 2.);
/* We add an extra quarter to shift the insertion row below the hovered row. */ /* We add an extra quarter to shift the insertion row below the hovered row. */
row = (verticalQuarterPosition + 1) / 4; row = (verticalQuarterPosition + 1) / 4;
@ -1323,7 +1324,7 @@ Also returns the child index relative to this parent. */
{ {
NSInteger minInsertionLevel = levelAfter; NSInteger minInsertionLevel = levelAfter;
NSInteger maxInsertionLevel = levelBefore; NSInteger maxInsertionLevel = levelBefore;
NSInteger pointerInsertionLevel = rint((float)horizontalHalfPosition / 2.); NSInteger pointerInsertionLevel = GSRoundTowardsInfinity((float)horizontalHalfPosition / 2.);
/* Save positions to avoid executing this code when the general /* Save positions to avoid executing this code when the general
* position of the mouse is unchanged. * position of the mouse is unchanged.

View file

@ -42,8 +42,7 @@
#import "AppKit/NSRulerView.h" #import "AppKit/NSRulerView.h"
#import "AppKit/NSScrollView.h" #import "AppKit/NSScrollView.h"
#import "AppKit/NSStringDrawing.h" #import "AppKit/NSStringDrawing.h"
#import "GSGuiPrivate.h"
DEFINE_RINT_IF_MISSING
#define MIN_LABEL_DISTANCE 40 #define MIN_LABEL_DISTANCE 40
#define MIN_MARK_DISTANCE 5 #define MIN_MARK_DISTANCE 5
@ -581,9 +580,9 @@ static NSMutableDictionary *units = nil;
} }
/* calculate number of small marks in each bigger mark */ /* calculate number of small marks in each bigger mark */
_marksToMidMark = rint([self _stepForIndex: convIndex + 1]); _marksToMidMark = GSRoundTowardsInfinity([self _stepForIndex: convIndex + 1]);
_marksToBigMark = _marksToMidMark _marksToBigMark = _marksToMidMark
* rint([self _stepForIndex: convIndex + 2]); * GSRoundTowardsInfinity([self _stepForIndex: convIndex + 2]);
/* Calculate distance between labels. /* Calculate distance between labels.
It must not be less than MIN_LABEL_DISTANCE. */ It must not be less than MIN_LABEL_DISTANCE. */
@ -595,7 +594,7 @@ static NSMutableDictionary *units = nil;
} }
/* number of small marks between two labels */ /* number of small marks between two labels */
_marksToLabel = rint(_labelDistance / _markDistance); _marksToLabel = GSRoundTowardsInfinity(_labelDistance / _markDistance);
/* format of labels */ /* format of labels */
if (_labelDistance / _unitToRuler >= 1) if (_labelDistance / _unitToRuler >= 1)

View file

@ -44,7 +44,8 @@
#import "AppKit/NSWindow.h" #import "AppKit/NSWindow.h"
#import <GNUstepGUI/GSTheme.h> #import <GNUstepGUI/GSTheme.h>
DEFINE_RINT_IF_MISSING #import "GSGuiPrivate.h"
#ifndef HAVE_ATAN2F #ifndef HAVE_ATAN2F
#define atan2f atan2 #define atan2f atan2
#endif #endif
@ -689,7 +690,7 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
d = _maxValue - _minValue; d = _maxValue - _minValue;
f = ((aValue - _minValue) * (effectiveTicks - 1)) / d; f = ((aValue - _minValue) * (effectiveTicks - 1)) / d;
f = ((rint(f) * d) / (effectiveTicks - 1)) + _minValue; f = ((GSRoundTowardsInfinity(f) * d) / (effectiveTicks - 1)) + _minValue;
/* never return the maximum value, tested on Apple */ /* never return the maximum value, tested on Apple */
if (_type == NSCircularSlider && (f >= _maxValue)) if (_type == NSCircularSlider && (f >= _maxValue))