• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: need advice on subclassing NSScrollVIew
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need advice on subclassing NSScrollVIew


  • Subject: Re: need advice on subclassing NSScrollVIew
  • From: Rainer Brockerhoff <email@hidden>
  • Date: Fri, 20 Mar 2009 09:22:33 -0300

At 19:59 -0700 19/03/09, email@hidden wrote:
>From: John Reppy <email@hidden>
>Date: Thu, 19 Mar 2009 15:39:44 -0500
>Message-ID: <email@hidden>
>
>I'm building a viewer for event logs that needs to support a wide range
>of scales (say from seconds/inch to nanoseconds/inch).  I've got a custom
>subclass of NSView for displaying this information, which I want to embed
>in an NSScrollView.  The problem that I'm faced with is that the floating-point
>coordinates used by Cocoa do not have enough precision at full magnification.
>
>I'm guessing that the best solution is to subclass NSScrollView to track the
>visible rectangle's origin using doubles, but I'm not sure which NSScrollView
>methods I should be overriding.  Also, do I need to override NSClipView too?
>Any pointers or suggestions would be appreciated.

In a similar situation, I didn't subclass NSScrollView. I subclassed NSView and inserted an NSScroller directly as its subview. I tracked the position with a 64-bit variable which I converted to a range suitable for the NSScroller just for setting its thumb position and size. I set my view as the NSScroller's target to convert back to my 64-bit position.

In the subclass' -drawRect: method, I calculated the visible portion of the view, and simply drew that - no NSClipView required. For your case, you'd have an additional step involving the scale; be careful with loss of precision there.

Despite being somewhat more work to implement, this proved to be more efficient and also a good learning experience regarding the view drawing mechanism.

HTH,
--
Rainer Brockerhoff  <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
 In their own business even sages err."
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________

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

  • Follow-Ups:
    • Re: need advice on subclassing NSScrollVIew
      • From: Benjamin Stiglitz <email@hidden>
  • Prev by Date: Re: NSScrollView like iTunes
  • Next by Date: Re: Bug+Fix: NSController (and subclasses) have problems with custom KVO keys
  • Previous by thread: Re: need advice on subclassing NSScrollVIew
  • Next by thread: Re: need advice on subclassing NSScrollVIew
  • Index(es):
    • Date
    • Thread