Need longer highlight w/ NSButton performClick:
-
I'm calling -performClick: on an NSButton subclass which works fine
except that the highlight doesn't last long enough. I'd like it to be
more obvious to the user which button was "pressed". How can I get it
to highlight for a set length of time, like .1 seconds?
Thanks,
Glen Simmons -
On Monday, March 28, 2005, at 12:09PM, Glen Simmons <gsimmons...> wrote:
> I'm calling -performClick: on an NSButton subclass which works fine
> except that the highlight doesn't last long enough. I'd like it to be
> more obvious to the user which button was "pressed". How can I get it
> to highlight for a set length of time, like .1 seconds?
In your NSButton subclass, override performClick: to basically do this:
[[self cell] setHighlighted:YES];
[self display];
NSDate* theDate = [[[NSDate alloc] initWithTimeIntervalSinceNow:myIntervalInSeconds] autorelease];
[NSThread sleepUntilDate:theDate];
[[self cell] setHighlighted:NO];
[self display];
--
Rick Sharp
instant Interactive(tm) -
On Mar 28, 2005, at 10:17 AM, Ricky Sharp wrote:
>
> NSDate* theDate = [[[NSDate alloc]
> initWithTimeIntervalSinceNow:myIntervalInSeconds] autorelease];
>
> [NSThread sleepUntilDate:theDate];
Don't forget about the class methods...
[NSThread sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:myIntervalInSeconds]];
-Shawn -
On Monday, March 28, 2005, at 12:27PM, Shawn Erickson <shawn...> wrote:
>
> On Mar 28, 2005, at 10:17 AM, Ricky Sharp wrote:
>>
>> NSDate* theDate = [[[NSDate alloc]
>> initWithTimeIntervalSinceNow:myIntervalInSeconds] autorelease];
>>
>> [NSThread sleepUntilDate:theDate];
>
> Don't forget about the class methods...
>
> [NSThread sleepUntilDate:[NSDate
> dateWithTimeIntervalSinceNow:myIntervalInSeconds]];
Thanks for pointing that out. You can clearly tell which code in my project was written a while back :) I've yet to go back to such initial code and see what can be modified/optimized.
--
Rick Sharp
Instant Interactive(tm) -
On 28 Mar, 2005, at 12:17 PM, Ricky Sharp wrote:
>
> On Monday, March 28, 2005, at 12:09PM, Glen Simmons
> <gsimmons...> wrote:
>
>> I'm calling -performClick: on an NSButton subclass which works fine
>> except that the highlight doesn't last long enough. I'd like it to be
>> more obvious to the user which button was "pressed". How can I get it
>> to highlight for a set length of time, like .1 seconds?
>
> In your NSButton subclass, override performClick: to basically do this:
>
> [[self cell] setHighlighted:YES];
> [self display];
>
> NSDate* theDate = [[[NSDate alloc]
> initWithTimeIntervalSinceNow:myIntervalInSeconds] autorelease];
>
> [NSThread sleepUntilDate:theDate];
>
> [[self cell] setHighlighted:NO];
> [self display];
>
Ricky, Shawn,
thanks for the input. Wouldn't I also need to call [super
performClick:] somewhere? Do you think before or after the sleep?
Glen -
On 28 Mar, 2005, at 2:07 PM, Glen Simmons wrote:
> On 28 Mar, 2005, at 12:17 PM, Ricky Sharp wrote:
>
>>
>> On Monday, March 28, 2005, at 12:09PM, Glen Simmons
>> <gsimmons...> wrote:
>>
>>> I'm calling -performClick: on an NSButton subclass which works fine
>>> except that the highlight doesn't last long enough. I'd like it to be
>>> more obvious to the user which button was "pressed". How can I get it
>>> to highlight for a set length of time, like .1 seconds?
>>
>> In your NSButton subclass, override performClick: to basically do
>> this:
>>
>> [[self cell] setHighlighted:YES];
>> [self display];
>>
>> NSDate* theDate = [[[NSDate alloc]
>> initWithTimeIntervalSinceNow:myIntervalInSeconds] autorelease];
>>
>> [NSThread sleepUntilDate:theDate];
>>
>> [[self cell] setHighlighted:NO];
>> [self display];
>>
>
> Ricky, Shawn,
>
> thanks for the input. Wouldn't I also need to call [super
> performClick:] somewhere? Do you think before or after the sleep?
>
Sorry, should've just tried it instead of being lazy and asking. Upon
trying, the above does the highlight, but doesn't perform the action. I
removed the last two lines and replaced them with [super performClick:]
and the highlight is turned off and the action is performed. So this
will do just what I want.
Does anyone see any problem with this? I always feel a little uneasy
about sleeping in the main thread, but it should be OK if it's low
enough (.1 sec or so), right?
Glen -
Glen,
On 28.3.2005, at 22:19, Glen Simmons wrote:
> Does anyone see any problem with this? I always feel a little uneasy
> about sleeping in the main thread, but it should be OK if it's low
> enough (.1 sec or so), right?
This small interval should not be a problem. Nevertheless, if you do
feel uneasy, of course you can replace the code by something like
-(void)lazyFinish { ...the original ending after sleep... }
-(void)performClick:sender {
...original beginnning before sleep...
[self performSelector:@selector(lazyFinish) withObject:nil
afterDelay:.1];
}
---
Ondra Èada
OCSoftware: <ocs...> http://www.ocs.cz
private <ondra...> http://www.ocs.cz/oc -
On 28 Mar, 2005, at 3:30 PM, Ondra Cada wrote:
> Glen,
>
> On 28.3.2005, at 22:19, Glen Simmons wrote:
>
>> Does anyone see any problem with this? I always feel a little uneasy
>> about sleeping in the main thread, but it should be OK if it's low
>> enough (.1 sec or so), right?
>
> This small interval should not be a problem. Nevertheless, if you do
> feel uneasy, of course you can replace the code by something like
>
> -(void)lazyFinish { ...the original ending after sleep... }
> -(void)performClick:sender {
> ...original beginnning before sleep...
> [self performSelector:@selector(lazyFinish) withObject:nil
> afterDelay:.1];
> }
Good point. Thanks. -
On Mar 28, 2005, at 2:19 PM, Glen Simmons wrote:
>> thanks for the input. Wouldn't I also need to call [super
>> performClick:] somewhere? Do you think before or after the sleep?
>>
>
> Sorry, should've just tried it instead of being lazy and asking. Upon
> trying, the above does the highlight, but doesn't perform the action.
> I removed the last two lines and replaced them with [super
> performClick:] and the highlight is turned off and the action is
> performed. So this will do just what I want.
Sorry about that; I was quite rushed when posting that message. It was
taken from a custom button class as well where the last line in the
function performed the action.
> Does anyone see any problem with this? I always feel a little uneasy
> about sleeping in the main thread, but it should be OK if it's low
> enough (.1 sec or so), right?
I do plan to revisit that code. Currently though, I don't have any
animations, etc. going on. Thus, sleeping the thread made the most
sense at the time. I basically wanted to guarantee that that user (or
other entity**) didn't inject any more events. I suppose I could have
flushed the event queue after the delay, but will leave that as an
exercise for myself later :)
** Other entity includes a timer that runs my automated test script
(basically simulates clicks).
___________________________________________________________
Ricky A. Sharp mailto:<rsharp...>
Instant Interactive(tm) http://www.instantinteractive.com



