Re: My Slider has spikes
Re: My Slider has spikes
- Subject: Re: My Slider has spikes
- From: Ron Fleckner <email@hidden>
- Date: Fri, 13 Apr 2007 11:23:14 +1000
On 13/04/2007, at 11:13 AM, Murat Konar wrote:
On Apr 12, 2007, at 6:01 PM, Ron Fleckner wrote:
I make a popup window for a slider in my app. My problem is
that the slider has strange little barbs or spikes near the ends
of it's 'track' and the ends of the track are squared off rather
than rounded. Here's the whole code I use to create the window...
[snip]
First of all, why not use Interface Builder to construct your
view hierarchy then pop that into your custom window?
Second, I'll bet what's going on is that the end caps of your
slider's groove are being drawn upside down, which suggests a
problem somewhere with coordinates not having the proper flipped-
ness.
Yes, yes, that's it! It's fixable. Flipped-ness is surely the
culprit. I've set my slider subclass to return NO as I wanted to
easily track the mouse position and move the slider as the mouse
moved so the user doesn't have to click and drag. However, if my
slider returns YES for -isFlipped, I get a comical situation where
the slider moves in the opposite direction to the mouse, but at
least the spikes have gone. Well spotted, Murat.
What I'm trying to do:
Have the slider move in concert with the mouse without having to
click and drag.
The slider reads -mouseMoved: events while it's on screen and sets
it's value (knob position) according to the mouse's position.
There probably is a way to get the mouse position and set the
slider's value in the -isFlipped YES situation, but my maths is
not good. By setting -isFlipped to NO, I can simply use the
location.y of the -mouseMoved: event.
Events (like mouse moved events) report their location in window
coordinates. You can convert from window coordinate system to any
subview coordinate system like this (typed in mail, etc):
NSPoint localEventCoord = [self convertPoint: [mouseMovedEvent
locationInWindow] fromView:nil];
This will account for any flippage. And you don't need any maths.
The reason I used code and not IB was because IB wouldn't let me
make the window narrow enough for my purposes. There probably is
a way to do it in IB, but rather than research the answer, it
seemed simpler and quicker to just write that fairly small bit of
code.
Build your view hierarchy in IB without putting it in a window.
Create your window in code then add the view from the nib to the
window's content view. Or just build the whole hierarchy in IB
(including the window) and resize it after loading it.
Hmm... seems like very good advice. Thanks for supplying an answer
to a question I wanted to ask but didn't: how to get over the problem
now that you've identified what the problem is.
Thanks very much for your help
Ron Fleckner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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