Got it working, Part of my issue seemed to be my logic.

300 is the bounds of my target image, and I have planned it so images fit inside this, so x would end up being 300. In a stupid moment, I set the if statement to run if x>300, which initially it wouldn't be as it would actually equal 300. However, I didn't spot my mistake as the NSLog inside the if statement appeared in the debugger so I thought it was running the rest of the code inside the if statement. I changed it to > 299 and voila it worked. I did also have to (is the term cast?) the 299 to a float.

I'm googling Fast Enumeration, but I'm compiling for 10.5,

So I'm left with the following which works as intended:

//select all images for kit
NSArray* kitImages = [kit valueForKeyPath:@"kitItems.kitItemProduct.productImage"];
        
        //set coordinates to x,y -> 0,0 to start
        float x = 0;
        float y = 75;
        //for each image
        NSEnumerator *imageLoop = [kitImages objectEnumerator];
        NSString *imgPath;
        
        while ((imgPath = [imageLoop nextObject])) {
                NSImage *img = [[NSImage alloc]initWithContentsOfFile:imgPath];

                //apply image to view
                [targetImage lockFocus];

[img drawInRect:NSMakeRect(x,y,75,75) fromRect:NSMakeRect(20,20,150,150) operation:NSCompositeCopy fraction: 1];
                
                //set new coordinates
                x = x+75;
                
//if coordinates are too wide, start new row - if x>300, reset x to 0 and add 100 to y
                if( x > (float)299 ){
                        
                        x = x-300;
                        y = y+75;
                        NSLog(@"x is greater than 300");
                
                }
                
        }
.....
//cleanup
        [bmpImageRep release];
        [img release];
        [kitLogoImg release];
        [targetImage release];


Thanks for everyones help.

_______________________________________________

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