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 / July 2006



Tip: Looking for answers? Try searching our database.

Cocoa & custom view

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 28 Jul 2006 08:05 GMT
Hi,

In "myView" which is a custom view, drawRect is drawing a few objects at
100 pixels from the left edge of the view. When I click the mouse on one
of these objects the outline is displayed in a different colour but the
it's is being drawn 100 pixels from the left edge of the window not 100
pixels from the left edge of the view.

What am I doing wrong? Any help appreciated.

Paul
Just - 28 Jul 2006 09:17 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> What am I doing wrong? Any help appreciated.

Are you calling drawRect yourself?

It's impossible to say what you're doing wrong if you don't post any
code.

Just
Tom Harrington - 28 Jul 2006 16:40 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> What am I doing wrong? Any help appreciated.

Hard to say from just that description, but at a guess you're probably
forgetting to convert from the window's coordinates to the view's
coordinates at some point.  One of the -convertRect: or -convertPoint:
methods may be what you need.

Signature

Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 2.0:  Delocalize, Repair Permissions, lots more.
See http://www.atomicbird.com/

Paul - 29 Jul 2006 06:35 GMT
Maybe it's because I'm drawing the object outside the custom view's
drawRect so it's just drawing to the window not the view. I'm drawing it
in the view's mouseDown. I'll have a fiddle with the code.

Thanks,

Paul

> > Hi,
> >
[quoted text clipped - 10 lines]
> coordinates at some point.  One of the -convertRect: or -convertPoint:
> methods may be what you need.
John C. Randolph - 29 Jul 2006 09:06 GMT
> Maybe it's because I'm drawing the object outside the custom view's
> drawRect so it's just drawing to the window not the view. I'm drawing it
> in the view's mouseDown.

Don't do that, and don't send -drawRect: yourself.

In -mouseDown:, process the event.  If you determine upon doing so that
you want to change what you see in your view, then send
-setNeedsDisplay: or -setNeedsDisplayInRect: to the view in question.

You also appear to be confused when you refer to the "custom view's
drawRect".  A view has a bounds rect and a frame rect.  A view
implements -drawRect:. The rect passed to a view in a -drawRect:
message is dependent on what portion of the view needs to be redrawn;  
this might be the entire bounds of the view, or it might be less than
that.

I strongly recommend reading the concept docs on views and 2D drawing.  
It will save you a good deal of time.

-jcr
Michael Ash - 29 Jul 2006 12:15 GMT
> Maybe it's because I'm drawing the object outside the custom view's
> drawRect so it's just drawing to the window not the view. I'm drawing it
> in the view's mouseDown. I'll have a fiddle with the code.

"Hard to say from just that description" is a very polite and roundabout
way of asking you to *post your code*. It's impossible to to answer this
sort of question with any certainty without actually seeing the code
responsible for the behavior. The best we can do without code is give you
vague platitudes which may or may not apply, whereas if we have code then,
assuming the problem is clear in the code (usually but not always the
case) then we can both point out the the specific error and the conceptual
problem that caused you to write it.

Signature

Michael Ash
Rogue Amoeba Software

Simon Slavin - 30 Jul 2006 22:06 GMT
On 28/07/2006, Paul wrote in message
<1hj7325.1pvboanb8ealaN%paulfredlein@NOSPAMoptusnet.com.au>:

> In "myView" which is a custom view, drawRect is drawing a few objects at
> 100 pixels from the left edge of the view.

So what you're saying here is that when drawRect is called normally
(because your window has just appeared) the object you're drawing appears
in its expect place, right ?

> When I click the mouse on one
> of these objects

'one of these objects' being one of your custom views, right ?

> the outline is displayed in a different colour but the
> it's is being drawn 100 pixels from the left edge of the window not 100
> pixels from the left edge of the view.

The need to redraw the contents of the custom view must be something
you're doing in your code because there's not normally any need to redraw
something just because someone clicks on it.  So you must have some code
somewhere which responds to a mouse click by calling the drawRect method.

So what parameters are you passing to it as its (NSRect) argument when you
call it ?

Simon.
Signature

http://www.hearsay.demon.co.uk

Paul - 31 Jul 2006 05:31 GMT
Hi,

Found the problem.

When I clicked the mouse in my object the object called:
"NSFrameRectWithWidthUsingOperation" immediately and drew the rect which
is outside the view's drawRect function.

So I made the mouseDown change the preset colour of my object and then
called: [self setNeedsDisplay:YES] after the mouseDown and then the view
refreshed itself and drew the rect in the proper place in the view not
in the window.

Thanks,

Paul

> Hi,
>
[quoted text clipped - 7 lines]
>
> Paul
 
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.