Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / May 2005



Tip: Looking for answers? Try searching our database.

the scrolling map, resizing a custom view

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Belding - 25 May 2005 23:45 GMT
I sure could use some more explanation of how to scroll around with a
custom view and NSScrollView.

Here's what I've done so far. . . .

* I created a custom view with a drawRect method to render my graphic,
which is a sort of map.

* I put it into a NSScrollView and made the window resizeable.

It works, it displays -- but I've got a problem I'm trying to figure
out.  Maps come in various sizes, and they get clipped when they are
bigger than my custom view.  I need a way to change the size of my view
contents, meaning the rendering area (not visible area), to make room
for the whole map I'm displaying.  (Or conversely, make it smaller to
fit a small map.)

The first thing I tried was the "setBounds" method.  But that didn't do
it. . .  Instead of changing the size of my view, it ended up *scaling*
my map to fit the view's current size.  That's neat trick. . .   but
that's not what I need to do here.

Any explanations, tips, or even pointing me toward the documentation
for this will be much appreciated.

Signature

Tony Belding, Hamilton Texas

matt neuburg - 26 May 2005 00:02 GMT
> I sure could use some more explanation of how to scroll around with a
> custom view and NSScrollView.
[quoted text clipped - 17 lines]
> my map to fit the view's current size.  That's neat trick. . .   but
> that's not what I need to do here.

Set the frameSize of the custom view to match the contentSize of the
scroll view. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Tony Belding - 26 May 2005 02:08 GMT
> Set the frameSize of the custom view to match the contentSize of the
> scroll view. m.

Thank you!  That worked.

Actually. . .  What I did was set the frameSize equal to the calculated
size of my map.  The scrollview appears to take care of itself, as far
as I can see.

Next thing I'll try is figuring out how to scroll to a part of the map
programmatically.

Signature

Tony Belding, Hamilton Texas

matt neuburg - 26 May 2005 04:35 GMT
> > Set the frameSize of the custom view to match the contentSize of the
> > scroll view. m.
[quoted text clipped - 7 lines]
> Next thing I'll try is figuring out how to scroll to a part of the map
> programmatically.

Let me save you some trouble, because this part is *really* hard to
figure out from the online manual. You set the origin of the clip view -
this is the content view of your custom view. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

matt neuburg - 26 May 2005 13:54 GMT
> > > Set the frameSize of the custom view to match the contentSize of the
> > > scroll view. m.
[quoted text clipped - 11 lines]
> figure out from the online manual. You set the origin of the clip view -
> this is the content view of your custom view.

I mean it's the content view of the scroll view that contains your
custom view. See why this is hard to explain??? :) m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Tony Belding - 26 May 2005 14:30 GMT
> Let me save you some trouble, because this part is *really* hard to
> figure out from the online manual. You set the origin of the clip view -
> this is the content view of your custom view. m.

Thank you, that helped!  Here's what I did:

    NSClipView *clipper = [myScrollView contentView];
    NSPoint origin;
    origin.x = 100.0;
    origin.y = 100.0;
    [clipper scrollToPoint:origin];

So far, so good. . .   It scrolls to the specified point, but it
doesn't update the scroll bars to match.  I guess I'll need some
additional code to update those.

Signature

Tony Belding, Hamilton Texas

matt neuburg - 26 May 2005 15:20 GMT
> > Let me save you some trouble, because this part is *really* hard to
> > figure out from the online manual. You set the origin of the clip view -
[quoted text clipped - 11 lines]
> doesn't update the scroll bars to match.  I guess I'll need some
> additional code to update those.

Simply tell the scroll view to reflectScrolledClipView:. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Tony Belding - 26 May 2005 16:05 GMT
>> So far, so good. . .   It scrolls to the specified point, but it
>> doesn't update the scroll bars to match.  I guess I'll need some
>> additional code to update those.
>
> Simply tell the scroll view to reflectScrolledClipView:. m.

Oh, cool!  I thought I'd have to get to the actual scrollbar objects,
do my own calculations, and then explicitly set them to the new
positions.

I should have known better.  :)  Everything turns out to be so easy
with Cocoa, I love it.  I just need to get more familiar with it.

Thanks again for your help!

Signature

Tony Belding, Hamilton Texas

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.