mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 13:20:59 +00:00
Minor efficiency hacks and tidying
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2969 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4247f4ca1a
commit
c7abca82c0
1 changed files with 86 additions and 79 deletions
|
@ -312,33 +312,37 @@ static NSButtonCell* knobCell = nil;
|
||||||
float position;
|
float position;
|
||||||
|
|
||||||
if (_isHorizontal) {
|
if (_isHorizontal) {
|
||||||
|
float halfKnobWidth = knobRect.size.width / 2;
|
||||||
|
|
||||||
/* Adjust the point to lie inside the knob slot */
|
/* Adjust the point to lie inside the knob slot */
|
||||||
if (point.x < slotRect.origin.x + knobRect.size.width / 2)
|
if (point.x < slotRect.origin.x + halfKnobWidth)
|
||||||
position = slotRect.origin.x + knobRect.size.width / 2;
|
position = slotRect.origin.x + halfKnobWidth;
|
||||||
else if (point.x > slotRect.origin.x + slotRect.size.width
|
else if (point.x > slotRect.origin.x + slotRect.size.width
|
||||||
- knobRect.size.width / 2)
|
- halfKnobWidth)
|
||||||
position = slotRect.origin.x + slotRect.size.width
|
position = slotRect.origin.x + slotRect.size.width
|
||||||
- knobRect.size.width / 2;
|
- halfKnobWidth;
|
||||||
else
|
else
|
||||||
position = point.x;
|
position = point.x;
|
||||||
|
|
||||||
/* Compute the float value considering the knob size */
|
/* Compute the float value considering the knob size */
|
||||||
floatValue = (position - (slotRect.origin.x + knobRect.size.width / 2))
|
floatValue = (position - (slotRect.origin.x + halfKnobWidth))
|
||||||
/ (slotRect.size.width - knobRect.size.width);
|
/ (slotRect.size.width - knobRect.size.width);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
float halfKnobHeight = knobRect.size.height / 2;
|
||||||
|
|
||||||
/* Adjust the point to lie inside the knob slot */
|
/* Adjust the point to lie inside the knob slot */
|
||||||
if (point.y < slotRect.origin.y + knobRect.size.height / 2)
|
if (point.y < slotRect.origin.y + halfKnobHeight)
|
||||||
position = slotRect.origin.y + knobRect.size.height / 2;
|
position = slotRect.origin.y + halfKnobHeight;
|
||||||
else if (point.y > slotRect.origin.y + slotRect.size.height
|
else if (point.y > slotRect.origin.y + slotRect.size.height
|
||||||
- knobRect.size.height / 2)
|
- halfKnobHeight)
|
||||||
position = slotRect.origin.y + slotRect.size.height
|
position = slotRect.origin.y + slotRect.size.height
|
||||||
- knobRect.size.height / 2;
|
- halfKnobHeight;
|
||||||
else
|
else
|
||||||
position = point.y;
|
position = point.y;
|
||||||
|
|
||||||
/* Compute the float value */
|
/* Compute the float value */
|
||||||
floatValue = (position - (slotRect.origin.y + knobRect.size.height/2))
|
floatValue = (position - (slotRect.origin.y + halfKnobHeight))
|
||||||
/ (slotRect.size.height - knobRect.size.height);
|
/ (slotRect.size.height - knobRect.size.height);
|
||||||
floatValue = 1 - floatValue;
|
floatValue = 1 - floatValue;
|
||||||
}
|
}
|
||||||
|
@ -398,13 +402,14 @@ static NSButtonCell* knobCell = nil;
|
||||||
NSRect knobRect = [self rectForPart:NSScrollerKnob];
|
NSRect knobRect = [self rectForPart:NSScrollerKnob];
|
||||||
NSEventType eventType = [theEvent type];
|
NSEventType eventType = [theEvent type];
|
||||||
float oldFloatValue = _floatValue;
|
float oldFloatValue = _floatValue;
|
||||||
|
NSApplication *theApp = [NSApplication sharedApplication];
|
||||||
|
|
||||||
_hitPart = NSScrollerKnob;
|
_hitPart = NSScrollerKnob;
|
||||||
[NSEvent startPeriodicEventsAfterDelay:0.05 withPeriod:0.05];
|
[NSEvent startPeriodicEventsAfterDelay:0.05 withPeriod:0.05];
|
||||||
[[NSRunLoop currentRunLoop] limitDateForMode:NSEventTrackingRunLoopMode];
|
[[NSRunLoop currentRunLoop] limitDateForMode:NSEventTrackingRunLoopMode];
|
||||||
|
|
||||||
while (eventType != NSLeftMouseUp) {
|
while (eventType != NSLeftMouseUp) {
|
||||||
theEvent = [[NSApplication sharedApplication]
|
theEvent = [theApp
|
||||||
nextEventMatchingMask:eventMask
|
nextEventMatchingMask:eventMask
|
||||||
untilDate:[NSDate distantFuture]
|
untilDate:[NSDate distantFuture]
|
||||||
inMode:NSEventTrackingRunLoopMode
|
inMode:NSEventTrackingRunLoopMode
|
||||||
|
@ -438,80 +443,82 @@ static NSButtonCell* knobCell = nil;
|
||||||
|
|
||||||
- (void)trackScrollButtons:(NSEvent*)theEvent
|
- (void)trackScrollButtons:(NSEvent*)theEvent
|
||||||
{
|
{
|
||||||
NSApplication *theApp = [NSApplication sharedApplication];
|
NSApplication *theApp = [NSApplication sharedApplication];
|
||||||
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
|
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
|
||||||
NSLeftMouseDraggedMask | NSMouseMovedMask;
|
NSLeftMouseDraggedMask | NSMouseMovedMask;
|
||||||
NSPoint location;
|
NSPoint location;
|
||||||
BOOL shouldReturn = NO;
|
BOOL shouldReturn = NO;
|
||||||
id theCell = nil;
|
id theCell = nil;
|
||||||
NSRect rect;
|
NSRect rect;
|
||||||
|
|
||||||
NSDebugLog (@"trackScrollButtons");
|
NSDebugLog (@"trackScrollButtons");
|
||||||
do {
|
do {
|
||||||
location = [self convertPoint:[theEvent locationInWindow]fromView:nil];
|
location = [self convertPoint:[theEvent locationInWindow]fromView:nil];
|
||||||
_hitPart = [self testPart:location];
|
_hitPart = [self testPart:location];
|
||||||
rect = [self rectForPart:_hitPart];
|
rect = [self rectForPart:_hitPart];
|
||||||
|
|
||||||
switch (_hitPart) // determine which cell
|
switch (_hitPart) {
|
||||||
{ // was hit
|
// determine which cell was hit
|
||||||
case NSScrollerIncrementLine:
|
|
||||||
case NSScrollerIncrementPage:
|
|
||||||
theCell = (_isHorizontal ? rightCell : upCell);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NSScrollerDecrementLine:
|
case NSScrollerIncrementLine:
|
||||||
case NSScrollerDecrementPage:
|
case NSScrollerIncrementPage:
|
||||||
theCell = (_isHorizontal ? leftCell : downCell);
|
theCell = (_isHorizontal ? rightCell : upCell);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case NSScrollerDecrementLine:
|
||||||
theCell = nil;
|
case NSScrollerDecrementPage:
|
||||||
break;
|
theCell = (_isHorizontal ? leftCell : downCell);
|
||||||
}
|
break;
|
||||||
|
|
||||||
if (theCell)
|
default:
|
||||||
{ // highlight the cell
|
theCell = nil;
|
||||||
[theCell highlight:YES withFrame:rect inView:self];
|
break;
|
||||||
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
}
|
||||||
[window flushWindow];
|
|
||||||
NSDebugLog (@"tracking cell %x", theCell);
|
|
||||||
// Track the mouse until mouse goes up
|
|
||||||
shouldReturn = [theCell trackMouse:theEvent
|
|
||||||
inRect:rect
|
|
||||||
ofView:self
|
|
||||||
untilMouseUp:YES];
|
|
||||||
// unhighlight the cell
|
|
||||||
[theCell highlight:NO withFrame:rect inView:self];
|
|
||||||
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
|
||||||
[window flushWindow];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldReturn)
|
if (theCell) {
|
||||||
break;
|
[theCell highlight:YES withFrame:rect inView:self];
|
||||||
|
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||||
|
[window flushWindow];
|
||||||
|
NSDebugLog (@"tracking cell %x", theCell);
|
||||||
|
// Track the mouse until mouse goes up
|
||||||
|
shouldReturn = [theCell trackMouse:theEvent
|
||||||
|
inRect:rect
|
||||||
|
ofView:self
|
||||||
|
untilMouseUp:YES];
|
||||||
|
|
||||||
theEvent = [theApp nextEventMatchingMask:eventMask
|
[theCell highlight:NO withFrame:rect inView:self];
|
||||||
untilDate:[NSDate distantFuture]
|
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||||
inMode:NSEventTrackingRunLoopMode
|
[window flushWindow];
|
||||||
dequeue:YES];
|
}
|
||||||
}
|
|
||||||
while ([theEvent type] != NSLeftMouseUp);
|
|
||||||
|
|
||||||
NSDebugLog (@"return from trackScrollButtons");
|
if (shouldReturn)
|
||||||
|
break;
|
||||||
|
|
||||||
|
theEvent = [theApp nextEventMatchingMask:eventMask
|
||||||
|
untilDate:[NSDate distantFuture]
|
||||||
|
inMode:NSEventTrackingRunLoopMode
|
||||||
|
dequeue:YES];
|
||||||
|
} while ([theEvent type] != NSLeftMouseUp);
|
||||||
|
|
||||||
|
NSDebugLog (@"return from trackScrollButtons");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
|
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
|
||||||
{ // send action to
|
{
|
||||||
BOOL ret = [super sendAction:theAction to:theTarget]; // the target on
|
BOOL ret;
|
||||||
// behalf of cell
|
|
||||||
[self drawKnobSlot]; // lockFocus set in mouseDown method is
|
|
||||||
[self drawKnob]; // active so we simply redraw the knob and
|
|
||||||
[window flushWindow]; // slot to reflect the hit scroll button
|
|
||||||
|
|
||||||
return ret;
|
// send action to the target on behalf of cell
|
||||||
|
ret = [super sendAction:theAction to:theTarget];
|
||||||
|
[self drawKnobSlot]; // lockFocus set in mouseDown method is
|
||||||
|
[self drawKnob]; // active so we simply redraw the knob and
|
||||||
|
[window flushWindow]; // slot to reflect the hit scroll button
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)encodeWithCoder:aCoder
|
- (void)encodeWithCoder:aCoder
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
- initWithCoder:aDecoder
|
- initWithCoder:aDecoder
|
||||||
{
|
{
|
||||||
|
@ -520,15 +527,14 @@ BOOL ret = [super sendAction:theAction to:theTarget]; // the target on
|
||||||
|
|
||||||
- (void)drawRect:(NSRect)rect
|
- (void)drawRect:(NSRect)rect
|
||||||
{
|
{
|
||||||
NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))",
|
NSDebugLog (@"NSScroller drawRect: ((%f, %f), (%f, %f))",
|
||||||
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||||
|
|
||||||
// Draw the scroller buttons
|
[self drawArrow:NSScrollerDecrementArrow highlight:NO];
|
||||||
[self drawArrow:NSScrollerDecrementArrow highlight:NO];
|
[self drawArrow:NSScrollerIncrementArrow highlight:NO];
|
||||||
[self drawArrow:NSScrollerIncrementArrow highlight:NO];
|
|
||||||
|
|
||||||
[self drawKnobSlot]; // Draw knob slot
|
[self drawKnobSlot];
|
||||||
[self drawKnob]; // Draw the knob
|
[self drawKnob];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawArrow:(NSScrollerArrow)whichButton
|
- (void)drawArrow:(NSScrollerArrow)whichButton
|
||||||
|
@ -557,7 +563,7 @@ BOOL ret = [super sendAction:theAction to:theTarget]; // the target on
|
||||||
|
|
||||||
- (void)drawKnob
|
- (void)drawKnob
|
||||||
{
|
{
|
||||||
[knobCell drawWithFrame:[self rectForPart:NSScrollerKnob] inView:self];
|
[knobCell drawWithFrame:[self rectForPart:NSScrollerKnob] inView:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The following methods should be implemented in the backend */
|
/* The following methods should be implemented in the backend */
|
||||||
|
@ -568,6 +574,7 @@ BOOL ret = [super sendAction:theAction to:theTarget]; // the target on
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawKnobSlot
|
- (void)drawKnobSlot
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue