mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
* 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:
parent
0024ee69e2
commit
22bfbcc946
8 changed files with 45 additions and 19 deletions
12
ChangeLog
12
ChangeLog
|
@ -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>
|
||||
|
||||
* Source/GSGhostscriptImageRep.m: Only invoke 'which' once.
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#import <Foundation/NSBundle.h>
|
||||
#include "GNUstepBase/preface.h"
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* Return the gnustep-gui bundle used to load gnustep-gui resources.
|
||||
|
@ -71,5 +72,21 @@ static inline NSString *GSGuiLocalizedString (NSString *key, NSString *comment)
|
|||
#endif
|
||||
#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 */
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
#import "AppKit/NSBezierPath.h"
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
#import "GSGuiPrivate.h"
|
||||
|
||||
/* Cache */
|
||||
static float scrollerWidth; // == [NSScroller scrollerWidth]
|
||||
|
@ -1667,7 +1667,7 @@ static NSTextFieldCell *titleCell;
|
|||
{
|
||||
float f = [sender floatValue];
|
||||
|
||||
[self scrollColumnToVisible: rintf(f * _lastColumnLoaded)];
|
||||
[self scrollColumnToVisible: GSRoundTowardsInfinity(f * _lastColumnLoaded)];
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -59,8 +59,6 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
|
||||
typedef struct _GSButtonCellFlags
|
||||
{
|
||||
#if GS_WORDS_BIGENDIAN == 1
|
||||
|
@ -969,7 +967,7 @@ typedef struct _GSButtonCellFlags
|
|||
{
|
||||
position = [controlView convertPointToBase: position];
|
||||
}
|
||||
position = NSMakePoint(rint(position.x), rint(position.y));
|
||||
position = NSMakePoint(GSRoundTowardsInfinity(position.x), GSRoundTowardsInfinity(position.y));
|
||||
if (controlView)
|
||||
{
|
||||
position = [controlView convertPointFromBase: position];
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
|
||||
@interface NSClipView (Private)
|
||||
- (void) _scrollToPoint: (NSPoint)aPoint;
|
||||
@end
|
||||
|
@ -444,8 +442,8 @@ static inline NSRect integralRect (NSRect rect, NSView *view)
|
|||
*/
|
||||
if (_copiesOnScroll)
|
||||
{
|
||||
new.x = _bounds.origin.x + (rint(new.x - _bounds.origin.x));
|
||||
new.y = _bounds.origin.y + (rint(new.y - _bounds.origin.y));
|
||||
new.x = _bounds.origin.x + (GSRoundTowardsInfinity(new.x - _bounds.origin.x));
|
||||
new.y = _bounds.origin.y + (GSRoundTowardsInfinity(new.y - _bounds.origin.y));
|
||||
}
|
||||
|
||||
return new;
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#import "AppKit/NSTextFieldCell.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
|
||||
#import "GSGuiPrivate.h"
|
||||
#include <math.h>
|
||||
|
||||
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.
|
||||
* When the view is scrolled, _bounds.origin.y returns the scrolled height. */
|
||||
verticalQuarterPosition =
|
||||
rint(((p.y + _bounds.origin.y) / _rowHeight) * 4.);
|
||||
GSRoundTowardsInfinity(((p.y + _bounds.origin.y) / _rowHeight) * 4.);
|
||||
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. */
|
||||
row = (verticalQuarterPosition + 1) / 4;
|
||||
|
@ -1323,7 +1324,7 @@ Also returns the child index relative to this parent. */
|
|||
{
|
||||
NSInteger minInsertionLevel = levelAfter;
|
||||
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
|
||||
* position of the mouse is unchanged.
|
||||
|
|
|
@ -42,8 +42,7 @@
|
|||
#import "AppKit/NSRulerView.h"
|
||||
#import "AppKit/NSScrollView.h"
|
||||
#import "AppKit/NSStringDrawing.h"
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
#import "GSGuiPrivate.h"
|
||||
|
||||
#define MIN_LABEL_DISTANCE 40
|
||||
#define MIN_MARK_DISTANCE 5
|
||||
|
@ -581,9 +580,9 @@ static NSMutableDictionary *units = nil;
|
|||
}
|
||||
|
||||
/* calculate number of small marks in each bigger mark */
|
||||
_marksToMidMark = rint([self _stepForIndex: convIndex + 1]);
|
||||
_marksToMidMark = GSRoundTowardsInfinity([self _stepForIndex: convIndex + 1]);
|
||||
_marksToBigMark = _marksToMidMark
|
||||
* rint([self _stepForIndex: convIndex + 2]);
|
||||
* GSRoundTowardsInfinity([self _stepForIndex: convIndex + 2]);
|
||||
|
||||
/* Calculate distance between labels.
|
||||
It must not be less than MIN_LABEL_DISTANCE. */
|
||||
|
@ -595,7 +594,7 @@ static NSMutableDictionary *units = nil;
|
|||
}
|
||||
|
||||
/* number of small marks between two labels */
|
||||
_marksToLabel = rint(_labelDistance / _markDistance);
|
||||
_marksToLabel = GSRoundTowardsInfinity(_labelDistance / _markDistance);
|
||||
|
||||
/* format of labels */
|
||||
if (_labelDistance / _unitToRuler >= 1)
|
||||
|
|
|
@ -44,7 +44,8 @@
|
|||
#import "AppKit/NSWindow.h"
|
||||
#import <GNUstepGUI/GSTheme.h>
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
#import "GSGuiPrivate.h"
|
||||
|
||||
#ifndef HAVE_ATAN2F
|
||||
#define atan2f atan2
|
||||
#endif
|
||||
|
@ -689,7 +690,7 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
|
||||
d = _maxValue - _minValue;
|
||||
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 */
|
||||
if (_type == NSCircularSlider && (f >= _maxValue))
|
||||
|
|
Loading…
Reference in a new issue