Re: Constraining a NSSlider to Certain Values
Re: Constraining a NSSlider to Certain Values
- Subject: Re: Constraining a NSSlider to Certain Values
- From: Peter Zegelin <email@hidden>
- Date: Tue, 8 Apr 2008 10:22:17 +1000
On 08/04/2008, at 12:41 AM, Jean-Daniel Dupas wrote:
Le 7 avr. 08 à 16:03, Peter Zegelin a écrit :
On 07/04/2008, at 10:46 PM, Jean-Daniel Dupas wrote:
Le 7 avr. 08 à 14:10, Peter Zegelin a écrit :
On 07/04/2008, at 9:07 PM, Jean-Daniel Dupas wrote:
Le 7 avr. 08 à 12:14, Peter Zegelin a écrit :
I'm trying to constrain the value of an NSSlider (while it is
being dragged) depending on the state of a modifier key and
being totally new to Cocoa am getting nowhere really fast! For
a start, I don't seem to be able to find a way to test for a
modifier key during the actual drag.
Can anyone help me here?
thanks!
Peter
To get the current modifier state during an event, -[NSEvent
modifierFlags];
And -[NSApplication currentEvent] or -[NSWindow currentEvent] to
get the current event (if you do not already have it).
OK but given, say, my own slidercell subclass, which event should
I check in and how do I get a ref to the sliders window? I'm
currently using 'continueTracking' which seems to be the right
event to override:
You can get the ref window by using the -[NSView window] method.
You can get the current event by using the NSApp global variable
(NSEvent *event = [NSApp currentEvent];)
And see also the link in the Ron's message.
Ah thanks - thats what I was after I think.
However it looks like I am going to have to think about this some
more because I've just noticed another problem. I now have the
following in my NSSliderCell subclass:
- (BOOL)continueTracking:(NSPoint)lastPoint at:
(NSPoint)currentPoint inView:(NSView *)controlView{
NSEvent *theEvent = [NSApp currentEvent];
if ([theEvent modifierFlags] & NSShiftKeyMask){
NSLog(@"shiftKey");
[self setFloatValue:0.0];
}
return YES;
}
which is more or less what I want. However now if I press the
shiftkey without moving the mouse then of course I never get this
message so the slider doesn't move to the new position until I move
the mouse. Same when I stop pressing the shift key. It looks like
I need to have a timer set to run in mousedown, continuously check
the status of the modifier keys and set the sliders modified
position as needed. Thoughts?
regards,
Peter
Using a timer will not help you, as currentEvent is not valid when a
timer fired.
When the modifier stats change, the -[NSResponder flagsChanged:
(NSEvent *)theEvent]
is call on the first responder that should be your NSSlider in this
case.
We had a discussion about catching flag changed event the last week (http://www.cocoabuilder.com/archive/message/cocoa/2008/4/1/202898
)
Maybe you can find something that may help you in this topics.
Yes - the timer also appears to block while dragging the slider - at
least judging by the lack of calls to NSLog from the timer - while the
mouse is down. Unfortunately the flagsChanged event also only fires
after the mouseup - not during the drag. A bit frustrating seeing this
is my first couple of days with Cocoa, but at least I'm learning quite
a bit! It looks increasingly like the best way will be to just
override the tracking completely and handle it myself using the
mousedragged event. I've actually done a few experiments and this
seems to work fine and I get the modifier keys just like any view
(flagsChanged works in this case).
Thanks for everyones help,
Peter_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden