Redraw only the necessary parts; tiny other speedups.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7358 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2000-09-03 19:30:19 +00:00
parent 3437a1effc
commit 09f3dae3ac

View file

@ -60,6 +60,7 @@ static NSButtonCell* knobCell = nil;
static const float scrollerWidth = 18; static const float scrollerWidth = 18;
static const float buttonsWidth = 16; static const float buttonsWidth = 16;
static NSColor *scrollBarColor = nil;
/* /*
* Class methods * Class methods
@ -67,7 +68,10 @@ static const float buttonsWidth = 16;
+ (void) initialize + (void) initialize
{ {
if (self == [NSScroller class]) if (self == [NSScroller class])
{
[self setVersion: 1]; [self setVersion: 1];
ASSIGN (scrollBarColor, [NSColor scrollBarColor]);
}
} }
+ (float) scrollerWidth + (float) scrollerWidth
@ -280,6 +284,7 @@ static const float buttonsWidth = 16;
return; return;
_isEnabled = flag; _isEnabled = flag;
_cacheValid = NO;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
@ -289,6 +294,7 @@ static const float buttonsWidth = 16;
return; return;
_arrowsPosition = where; _arrowsPosition = where;
_cacheValid = NO;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
@ -340,6 +346,7 @@ static const float buttonsWidth = 16;
_arrowsPosition = NSScrollerArrowsMaxEnd; _arrowsPosition = NSScrollerArrowsMaxEnd;
_hitPart = NSScrollerNoPart; _hitPart = NSScrollerNoPart;
_cacheValid = NO;
[self checkSpaceForParts]; [self checkSpaceForParts];
} }
@ -347,6 +354,7 @@ static const float buttonsWidth = 16;
{ {
[super setFrameSize: size]; [super setFrameSize: size];
[self checkSpaceForParts]; [self checkSpaceForParts];
_cacheValid = NO;
[self setNeedsDisplay: YES]; [self setNeedsDisplay: YES];
} }
@ -645,17 +653,34 @@ static const float buttonsWidth = 16;
*/ */
- (void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))", static NSRect rectForPartIncrementLine;
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); static NSRect rectForPartDecrementLine;
static NSRect rectForPartKnobSlot;
if (_cacheValid == NO)
{
rectForPartIncrementLine = [self rectForPart: NSScrollerIncrementLine];
rectForPartDecrementLine = [self rectForPart: NSScrollerDecrementLine];
rectForPartKnobSlot = [self rectForPart: NSScrollerKnobSlot];
}
[[_window backgroundColor] set]; [[_window backgroundColor] set];
NSRectFill (_bounds); NSRectFill (rect);
if (NSIntersectsRect (rect, rectForPartKnobSlot) == YES)
{
[self drawKnobSlot]; [self drawKnobSlot];
[self drawKnob]; [self drawKnob];
}
if (NSIntersectsRect (rect, rectForPartDecrementLine) == YES)
{
[self drawArrow: NSScrollerDecrementArrow highlight: NO]; [self drawArrow: NSScrollerDecrementArrow highlight: NO];
}
if (NSIntersectsRect (rect, rectForPartIncrementLine) == YES)
{
[self drawArrow: NSScrollerIncrementArrow highlight: NO]; [self drawArrow: NSScrollerIncrementArrow highlight: NO];
}
} }
- (void) drawArrow: (NSScrollerArrow)whichButton highlight: (BOOL)flag - (void) drawArrow: (NSScrollerArrow)whichButton highlight: (BOOL)flag
@ -688,12 +713,15 @@ static const float buttonsWidth = 16;
- (void) drawKnobSlot - (void) drawKnobSlot
{ {
NSRect rect; static NSRect rect;
if (_cacheValid == NO)
{
rect = [self rectForPart: NSScrollerKnobSlot]; rect = [self rectForPart: NSScrollerKnobSlot];
}
[[NSColor scrollBarColor] set]; [scrollBarColor set];
NSRectFill(rect); NSRectFill (rect);
} }
- (void) highlight: (BOOL)flag - (void) highlight: (BOOL)flag