Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chumchum

macrumors newbie
Original poster
Nov 11, 2010
2
0
Hi everyone,

I am writing an application that displays a large graph. When I use an NSScrollView the application slows down as the graph is quite big and therefore slow to draw on a subclass of NSView. Instead I would like to draw only the part of the graph that is visible (the size of the window) but I would still need scrollbars to choose what part of the graph is supposed to be drawn. Does any body as any suggestions about how to implement this as I am new to cocoa. Should I subclass an NSScrollView, or use NSSlider (although they are not very nice)?

Thanks
M
 

chumchum

macrumors newbie
Original poster
Nov 11, 2010
2
0
Hi

Thanks for the reply but do you have any suggestions on how to extend NSScrollView?

Cheers,
M
 

chown33

Moderator
Staff member
Aug 9, 2009
10,745
8,418
A sea of green
There is no reason to subclass NSScrollView. Doing so won't solve anything.

If the problem is your BigGraphView, then nothing done by NSScrollView can make BigGraphView draw less. The problem lies in BigGraphView. You wrote:
Instead I would like to draw only the part of the graph that is visible ...
Well why are you drawing parts that aren't visible? And why would you think that NSScrollView could make your class draw less?

If you're drawing parts that lie outside the visible part of your view, then stop drawing those parts. You should only draw the parts that lie inside the bounds rect of your document view, which will be set by the content view of the NSScrollView.

If your view is drawing invisible parts, then nothing NSScrollView can do will cause your view to draw less. You have to change how your view draws. When you do that, then NSScrollView will be faster.

If that doesn't make sense, then you don't understand how NSScrollView works. Review the reference doc:
http://developer.apple.com/library/...asics.html#//apple_ref/doc/uid/TP40003461-SW1

From that reference doc:
The content view is responsible for managing the position of the document view, clipping the document view to the content view's frame, and handling the details of scrolling in an efficient manner. The content view scrolls the document view by altering its bounds rectangle, which determines where the document view’s frame lies.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
There is no reason to subclass NSScrollView. Doing so won't solve anything.

If the problem is your BigGraphView, then nothing done by NSScrollView can make BigGraphView draw less. The problem lies in BigGraphView. You wrote:

Well why are you drawing parts that aren't visible? And why would you think that NSScrollView could make your class draw less?

If you're drawing parts that lie outside the visible part of your view, then stop drawing those parts. You should only draw the parts that lie inside the bounds rect of your document view, which will be set by the content view of the NSScrollView.

If your view is drawing invisible parts, then nothing NSScrollView can do will cause your view to draw less. You have to change how your view draws. When you do that, then NSScrollView will be faster.

If that doesn't make sense, then you don't understand how NSScrollView works. Review the reference doc:
http://developer.apple.com/library/...asics.html#//apple_ref/doc/uid/TP40003461-SW1

From that reference doc:
The content view is responsible for managing the position of the document view, clipping the document view to the content view's frame, and handling the details of scrolling in an efficient manner. The content view scrolls the document view by altering its bounds rectangle, which determines where the document view’s frame lies.

You'd hope that drawRect: had some parameter telling the view which bits need to be redrawn. Wait a second...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.