Quincey, thank you. With your suggestion, and a private email, and lots of reading :-), I have made some progress.

On Sep 3, 2009, at 8:54 PM, Quincey Morris wrote:

On Sep 3, 2009, at 20:37, Michael de Haan wrote:

Now the part that does not work.

changeViewDelta as follows:

-(IBAction) changeViewDelta: (id) sender
{
        NSRect newBounds;
        newBounds.origin.x = newBounds.origin.x + 50.0;
        .................

}

If that's your actual code, it's likely not going to work, because you're failing to initialize newBounds. So you're offsetting newBounds 50 pixels from a trash origin.


good point...thanks.



I expected this to call drawRect,.............

You don't say explicitly what class this 'changeViewDelta:' method is in. If it's in the view, then of course 'self' is the correct receiver for the message.

Yes it is.






Well, I **think** I now know what the problem is, but really not sure **why** this occurs. (I have considerably modified the project to try and understand this more fully).

(For simplicity, I implement an "int state" ivar to which drawRect refers)


In init, this:

- (id)initWithFrame:(NSRect)frame {
    self = ........
                [self setCurrentColor:[NSColor yellowColor]];
                [self setState: 1];
          .........
}



Here is the relevant code in drawRect;

        static int status = 0;
        if (status == 0)
        [ [self currentColor] set];
        else if ( status % 2)
                [[NSColor blackColor]set];
        else
                [[NSColor blueColor]set];
        status +=1;


and in


-(IBAction) changeViewDelta: (id) sender
{
        //NSRect newBounds = [self bounds];
NSRect newBounds = [view bounds]; <<<<<------ Issue: self bounds...see below.
        
        newBounds.origin.x = newBounds.origin.x + 50.0;
        newBounds.origin.y = newBounds.origin.y + 50.0;
        newBounds.size.width = 50.0;
        newBounds.size.height = 75.0;
        
        [self setState:2];
        
//[view setNeedsDisplayInRect:newBounds]; <<<-----same Issue...see below.
        [self setNeedsDisplayInRect:newBounds];
        
}


With this code, the changes are as I would expect. The view is initially yellow. Subsequent changes via changeViewDelta show a small block in the window which changes color from black to blue.


Now, here is what is puzzling.

1) Even though, as Quincey alluded to, I would have expected the outlet "view" and self to be equivalent, they are not.It seems as if "self" to changeViewDelta is a different entity from the outlet "view". 2) The ivar set in the "init" method is used by drawRect during the "first pass" ( if that is the correct term ie when status is 0), but in subsequent calls, initiated by setNeedsDisplayInRect, ( and I do understand that setNeedsDisplayInRect "informs" the view of a need for a refresh), even thought drawRect gets passed the correct "dirtyRect" bounds, when , from within drawRect I try to access the "state" Ivar ( which should now be 2) , what drawRect sees is still 1...and that seems to be the problem. (Note: I have used an int for simplicity, but the same occurred if I tried to use a color directly from drawRect).


So, in summary, changeViewDelta **seems** to work as expected, but drawRect does not see these changes, even though both methods are in the same class.

I hope I have articulated this clearly.

:-)



        




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to