Re: Creating a radar sweep effect

2009-09-27 Thread Graham Cox

Hi John,

The difficulty with this kind of display is simulating the persistence  
of the old cathode-ray tubes in a realistic way. Just drawing a shadow  
is unlikely to work, though it might help get you some way by creating  
the glow caused by scattering.


One possibility is to use OpenGL. It has a history buffer mode (may  
not be called that - I forget exactly) that stores the previous image  
at a diminished brightness and that can be stacked for a series of  
frames, giving a fade or trail effect.


Alternatively you can model persistence yourself by buffering up  
several frames (for example, using a NSBitmapImageRep) and then  
drawing the stack for each frame followed by the latest content. I  
have used this approach to simulate an oscilloscope display and it  
works well in terms of realism, but performance can be an issue.  
You'll probably need to store at least 3 or 4 previous frames to get  
the effect you want - there's no really good way to do it in one pass  
and get realism. Fact is those old tubes literally stored the image in  
the phosphors which naturally faded in their own time after the beam  
passed - to simulate that realistically requires that you model the  
image storage.


--Graham


On 27/09/2009, at 11:19 AM, John Cebasek wrote:


Hi All:

I'm wondering what the best way to create a radar sweep effect is?  
(Like in old war movies?)


___

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


Re: Frameworks in red

2009-09-27 Thread Graham Cox

Files shown in red can't be found at the path given.

If you do a Get Info on the file you can correct the path. If it's a  
framework shared by several projects it's worth putting it in a  
location that won't move and can be reached by them all. You might  
also want to look into setting up a common build folder.


The crash is probably due to the framework being not found at run time  
(because it couldn't be found at compile time and so wasn't copied to  
the correct destination within the app). If the app can't be linked to  
its frameworks at launch time, launch is simply aborted, and the  
Finder displays no explanation (on the Mac - no idea what happens on  
the godPhone).


--Graham



On 27/09/2009, at 1:12 PM, Erg Consultant wrote:

When I drag a bunch of frameworks from one Xcode project to another,  
their names are listed in red in the destination project. I know  
they exist because the original project works fine and I can do a  
Reveal In Finder to verify that they exist? The project being  
dragged *to* however crashes on launch even though I've verified the  
frameworks also exist at the paths listed in that project. I am  
using iPhone SDK 3.1 and XCode 3.1.3.


___

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


Re: Frameworks in red

2009-09-27 Thread ERG Consultant
I should have mentioned that the Frameworks in question are the System 
frameworks. And they are Found Fine by The original App. (which Runs just Fine.)

Sent from my iPod

On Sep 26, 2009, at 11:54 PM, Graham Cox graham@bigpond.com wrote:

Files shown in red can't be found at the path given.

If you do a Get Info on the file you can correct the path. If it's a framework 
shared by several projects it's worth putting it in a location that won't move 
and can be reached by them all. You might also want to look into setting up a 
common build folder.

The crash is probably due to the framework being not found at run time (because 
it couldn't be found at compile time and so wasn't copied to the correct 
destination within the app). If the app can't be linked to its frameworks at 
launch time, launch is simply aborted, and the Finder displays no explanation 
(on the Mac - no idea what happens on the godPhone).

--Graham



On 27/09/2009, at 1:12 PM, Erg Consultant wrote:

When I drag a bunch of frameworks from one Xcode project to another, their 
names are listed in red in the destination project. I know they exist because 
the original project works fine and I can do a Reveal In Finder to verify 
that they exist? The project being dragged *to* however crashes on launch even 
though I've verified the frameworks also exist at the paths listed in that 
project. I am using iPhone SDK 3.1 and XCode 3.1.3.




  

___

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


Re: Creating a radar sweep effect

2009-09-27 Thread Graham Cox
John, the code below is similar to my oscilloscope view in principle -  
here though I just use an NSImage to buffer the history, as it's  
simplest, but for performance you might try something more  
sophisticated. Also, when drawing the history, this just uses a linear  
opacity ramp - it might work better with a curve of some sort but I'll  
leave that to you!  Hope it helps,


--Graham


@interface GCRadarView : NSView
{
NSMutableArray* mHistoryBuffer;
NSTimer*mTimer;
NSTimeInterval  mLastUpdateTime;
CGFloat mAngle;
}


- (void)drawHistoryBuffer;
- (void)updateHistoryBuffer;
- (void)drawContentIntoImage:(NSImage*) theImage;
- (void)animateWithTimer:(NSTimer*) timer;

- (IBAction)startSweep:(id) sender;
- (IBAction)stopSweep:(id) sender;

@end



#define MAX_HISTORY_BUFFER_SIZE 6
#define SWEEP_RATE  0.3 // radians per second

//

#import GCRadarView.h


@implementation GCRadarView

- (void)drawHistoryBuffer
{
	// draw the stack of images in the history buffer, each one with a  
different transparency


if([mHistoryBuffer count]  0 )
{
CGFloat opacityIncrement = 1.0 / [mHistoryBuffer count];
NSUInteger  i;
NSImage*image;

for( i = 0; i  [mHistoryBuffer count]; ++i )
{
image = [mHistoryBuffer objectAtIndex:i];   

			[image drawInRect:[self bounds] fromRect:NSZeroRect  
operation:NSCompositeSourceOver fraction:(CGFloat)i * opacityIncrement];

}
}
}


- (void)updateHistoryBuffer
{
	// this generates the images. The image list is limited to a maximum  
- if exceeded images are discarded
	// from the front of the list. New images are added to the end of the  
list.


while([mHistoryBuffer count]  MAX_HISTORY_BUFFER_SIZE )
[mHistoryBuffer removeObjectAtIndex:0];

NSImage* newImage = [[NSImage alloc] initWithSize:[self bounds].size];

[newImage lockFocus];
[self drawContentIntoImage:newImage];
[newImage unlockFocus];

[mHistoryBuffer addObject:newImage];
[newImage release];
}


- (void)drawContentIntoImage:(NSImage*) theImage
{
// draw view content to the image. Image is already focused.

NSTimeInterval  currentTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval  elapsedTime = currentTime - mLastUpdateTime;
mLastUpdateTime = currentTime;

	// sweep rate is SWEEP_RATE rad/sec - so how many radians since we  
last updated?


CGFloat angleIncrement = SWEEP_RATE * elapsedTime;
mAngle += angleIncrement;
mAngle = fmod( mAngle, 2 * pi );// not really needed

// set the transform to this angle rotated around the centre point

NSPoint centre;

centre.x = NSMidX([self bounds]);
centre.y = NSMidY([self bounds]);

[NSGraphicsContext saveGraphicsState];

NSAffineTransform* transform = [NSAffineTransform transform];
[transform translateXBy:centre.x yBy:centre.y];
[transform rotateByRadians:mAngle];
[transform translateXBy:-centre.x yBy:-centre.y];
[transform concat];

	// draw the sweep line from centre to edge. The transform is rotated  
so we simply draw at a fixed angle.
	// add a shadow to simulate the glow of backscatter and help hide the  
discrete nature of the sweep lines


NSShadow* shadow = [[NSShadow alloc] init];
	[shadow setShadowColor:[NSColor colorWithCalibratedRed:0.4 green:1.0  
blue:0.4 alpha:1.0]];

[shadow setShadowOffset:NSZeroSize];
[shadow setShadowBlurRadius:8.0];
[shadow set];

// beam line

[[NSColor greenColor] set];
[NSBezierPath setDefaultLineWidth:1.5];
	[NSBezierPath strokeLineFromPoint:centre toPoint:NSMakePoint( NSMaxX 
([self bounds]), 0 )];


[shadow release];

[NSGraphicsContext restoreGraphicsState];
}


- (void)animateWithTimer:(NSTimer*) timer
{
	// timer callback ends up here. It updates the history buffer and  
marks the display needed.


#pragma unused(timer)

[self updateHistoryBuffer];
[self setNeedsDisplay:YES];
}




- (IBAction)startSweep:(id) sender
{
#pragma unused(sender)

if( mTimer == nil )
{
		mTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0  
target:self selector:@selector(animateWithTimer:) userInfo:nil  
repeats:YES];

mLastUpdateTime = [NSDate 

Xcode3.2 build and analyze warning for NSString allocation

2009-09-27 Thread Nick Rogers

Hi,

When I alloc and init a NSString the following way, there is warning  
that:
Potential leak of an object allocated on line 526 and stored in  
sizeDisp.
		1. Method returns an Objective-C object with a +1 retain count  
(owning reference).
	2. Object returned to caller as an owning reference (single retain  
count transferred to caller).
	3. Object allocated on line 526 and stored into 'sizeDisp' is  
returned from a method whose name  
('tableView:objectValueForTableColumn:row:') does not contain 'copy'  
or otherwise starts with 'new' or 'alloc'.  This violates the naming  
convention rules given in the Memory Management Guide for Cocoa  
(object leaked).


The code is as follows:

if ([[tableColumn identifier] isEqual:@Size] == YES)
{
NSString *sizeDisp;// line 526
NSNumber *size = [data objectForKey:@kDeviceSize];
unsigned long long sizeInBytes = [size 
unsignedLongLongValue];
if (sizeInBytes  1000*1000)
{
sizeDisp = [[NSString alloc] initWithFormat:@%.2f KB, ((float) 
sizeInBytes/1000)];

}
else if (sizeInBytes  1000*1000*1000)
{
sizeDisp = [[NSString alloc] initWithFormat:@%.2f MB, ((float) 
sizeInBytes/(1000*1000))];// warning number 1 (as listed above)

}
else
{
sizeDisp= [[NSString alloc] initWithFormat:@%.2f GB, ((float) 
sizeInBytes/(1000*1000*1000))];

}
return sizeDisp;// warning 2  3 (as listed above)
}

When I do sizeDisp = [NSString stringWithFormat:@%.2f MB, ((float) 
sizeInBytes/(1000*1000))];

The warning disappears in the next build and analyze.

Can I hope for a small analysis of the above from anybody?

Thanks,
Nick


___

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


Re: Xcode3.2 build and analyze warning for NSString allocation

2009-09-27 Thread Roland King
I can't really give you a much better analysis than the static  
analyzer is giving you. If you read the Memory Management Guide for  
Cocoa you will see that only methods starting new or alloc or  
containing copy should return objects transferring a retain count (but  
please actually read the whole thing, there's more information there).


You have alloc/inited an NSString which you're then returning. alloc/ 
init needs a balancing release which you haven't given it before the  
method end.


When you change it to stringWithFormat: that object isnt retained, so  
you don't have the problem.


What you probably want to do here is autorelease the return value  
before returning it and if your caller wants to retain the object, it  
needs to do that. Although frankly the change to use stringWithFormat:  
really does that for you anyway.


So either pattern works.

NSString *retval = [ [ NSString alloc ] initWithSomeInitializer: .. ];
[ retval autorelease ]; // --- balances the alloc/init
return retval;

or

NSString *retval = [ NSString stringWithSomeInitializer: ... ];
	return retval;	// --- ok as stringWithSomeInitializer is not an  
alloc/copy type method.


If your second version of the code, with stringWithFormat: works and  
doesn't crash, your original version was probably leaking the NSString.


On 27-Sep-2009, at 5:03 PM, Nick Rogers wrote:


Hi,

When I alloc and init a NSString the following way, there is warning  
that:
Potential leak of an object allocated on line 526 and stored in  
sizeDisp.
		1. Method returns an Objective-C object with a +1 retain count  
(owning reference).
	2. Object returned to caller as an owning reference (single retain  
count transferred to caller).
	3. Object allocated on line 526 and stored into 'sizeDisp' is  
returned from a method whose name  
('tableView:objectValueForTableColumn:row:') does not contain 'copy'  
or otherwise starts with 'new' or 'alloc'.  This violates the naming  
convention rules given in the Memory Management Guide for Cocoa  
(object leaked).


The code is as follows:

if ([[tableColumn identifier] isEqual:@Size] == YES)
{
NSString *sizeDisp;// line 526
NSNumber *size = [data objectForKey:@kDeviceSize];
unsigned long long sizeInBytes = [size 
unsignedLongLongValue];
if (sizeInBytes  1000*1000)
{
sizeDisp = [[NSString alloc] initWithFormat:@%.2f KB, ((float) 
sizeInBytes/1000)];

}
else if (sizeInBytes  1000*1000*1000)
{
sizeDisp = [[NSString alloc] initWithFormat:@%.2f MB, ((float) 
sizeInBytes/(1000*1000))];// warning number 1 (as listed above)

}
else
{
sizeDisp= [[NSString alloc] initWithFormat:@%.2f GB, ((float) 
sizeInBytes/(1000*1000*1000))];

}
return sizeDisp;// warning 2  3 (as listed above)
}

When I do sizeDisp = [NSString stringWithFormat:@%.2f MB, ((float) 
sizeInBytes/(1000*1000))];

The warning disappears in the next build and analyze.

Can I hope for a small analysis of the above from anybody?

Thanks,
Nick


___

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/rols%40rols.org

This email sent to r...@rols.org


___

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


Re: NSURLConnection upload to iDisk works with iPhone OS 2.x but fails on 3.x

2009-09-27 Thread Sergey Shapovalov

Hello again.

It looks like I've got more info on the issue. I've performed some  
additional investigation and figured out that if you substitute the  
lines
	NSInputStream* stream = [NSInputStream inputStreamWithFileAtPath:  
filePath];

[request setHTTPBodyStream: stream];
with
NSData* outgoingData = [str dataUsingEncoding: NSUTF8StringEncoding];
[request setHTTPBody: outgoingData];
then the code works perfectly with both 2.2.1 and 3.0. However, the  
original code works on 2.2.1 but fails on 3.0 and 3.1.


This makes me think that chunked upload from stream via  
NSURLConnection has been broken in iPhone OS 3.x. Unfortunately, in  
real life I can't upload my file by using setHTTPBody instead of  
setHTTPBodyStream because it's too big to store in memory.


So, if anybody sees a mistake in what I'm doing, please tell me.  
Otherwise, I'll post a bug to radar... However, that won't help me  
much because this issue a stopper for the new version of my app which  
I'm preparing for the App Store now.


Best regards,
Sergey.

On Sep 27, 2009, at 12:28 AM, Sergey Shapovalov wrote:


Hello.

I'm using a very simple code snippet to upload a small file to my  
MobileMe iDisk. The problem is that it perfectly works with iPhone  
OS 2.2.1, but fails on 3.0. Now I'm trying to figure out whether  
that's a bug in iPhone OS 3.0, or I am doing something wrong and  
2.2.1 is just more tolerant to my mistakes than 3.0.


Here is my code.

static NSString* kMobileMeUserName = ...;
static NSString* kMobileMePassword = ...;

- (void)upload
{
	NSString* tmpFolderPath = [NSHomeDirectory()  
stringByAppendingPathComponent: @tmp];
	NSString* filePath = [tmpFolderPath stringByAppendingPathComponent:  
@test.txt];


NSString* str = @1234567890;
	[str writeToFile: filePath atomically: NO encoding:  
NSUTF8StringEncoding error: NULL];


	NSURL* url = [NSURL URLWithString: [NSString stringWithFormat: @https://idisk.me.com/ 
%@/Documents/test.txt, kMobileMeUserName]];
	NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:  
url];

[request setHTTPMethod: @PUT];

	NSDictionary* fileAttr = [[NSFileManager defaultManager]  
fileAttributesAtPath: filePath traverseLink: YES];

unsigned long long uploadSize = [fileAttr fileSize];

if ( uploadSize  0 )
{
NSNumber* num = [NSNumber numberWithUnsignedLongLong: 
uploadSize];
		[request setValue: [num stringValue] forHTTPHeaderField: @Content- 
Length];


		NSInputStream* stream = [NSInputStream inputStreamWithFileAtPath:  
filePath];

[request setHTTPBodyStream: stream];

[NSURLConnection connectionWithRequest: request delegate: self];
}
}

In my controller (which is registered as NSURLConnection delegate) I  
implement all of NSURLConnection  delegate methods and just call  
NSLog from them so that I can see in the log how the operation  
performs. I return YES for canAuthenticateAgainstProtectionSpace and  
from connectionShouldUseCredentialStorage. When I receive  
authentication challenge, I act like this:


- (void)connection:(NSURLConnection*)connection  
didReceiveAuthenticationChallenge: 
(NSURLAuthenticationChallenge*)challenge

{
NSLog(@didReceiveAuthenticationChallenge);

	NSURLCredential* cred = [NSURLCredential credentialWithUser:  
kMobileMeUserName


   password: kMobileMePassword

persistence: NSURLCredentialPersistenceNone];

	[challenge.sender useCredential: cred forAuthenticationChallenge:  
challenge];

}

Now, here is what I see in console when I run this code with 2.2.1:
willSendRequest
connectionShouldUseCredentialStorage
didSendBodyData
didReceiveAuthenticationChallenge
didSendBodyData
didReceiveResponse
connectionDidFinishLoading

Everything works all right, and I can find the test.txt file (10  
bytes in size) on my iDisk in the Documents folder.


And this is how the same code runs in 3.0:
willSendRequest
connectionShouldUseCredentialStorage
canAuthenticateAgainstProtectionSpace
didReceiveAuthenticationChallenge
didSendBodyData
canAuthenticateAgainstProtectionSpace
didReceiveAuthenticationChallenge

For some reason I receive authentication challenge for the second  
time, and after that no more delegate methods are called. And the  
test.txt file never appears on the iDisk. Moreover - I tried  
deriving MyURLConnection from NSURLConnection and overriding init...  
and dealloc in it; from there, I just call super methods and add  
NSLog. This way I could see that the URL connection deallocs after  
the second authentication challenge - without having called  
connectionDidFinishLoading: or connection:didFailWithError: on the  
delegate.


So, 

Re: Creating a radar sweep effect

2009-09-27 Thread Graham Cox

Hi again - you got me going now! ;-)

Occurs to me that there's no need to store more than one buffered  
image (actually really obvious once it dawned on me). Checking the  
OpenGL approach, this is what it does also - just one history  
buffered image, which is then drawn into the new image at each update,  
with a lower opacity such that over time it naturally fades away. This  
is much more efficient as there are only two bitblits per frame, and a  
maximum of two images in memory at once and then only briefly, no  
matter how much persistence you dial in or what the frame rate is,  
etc. It also looks a lot more realistic, so it's a winner all round.  
Here's my revised view which still uses NSImage, but even with this is  
working nice and smoothly. I also added a target to show how actual  
blips on the screen could be handled.



@interface GCRadarView : NSView
{
NSTimer*mTimer;
NSTimeInterval  mLastUpdateTime;
CGFloat mAngle;
NSImage*mHistoryImage;
}


- (void)drawHistoryBuffer;
- (void)updateHistoryBuffer;
- (void)drawContentIntoImage:(NSImage*) theImage;
- (void)animateWithTimer:(NSTimer*) timer;

- (IBAction)startSweep:(id) sender;
- (IBAction)stopSweep:(id) sender;

@end


#define SWEEP_RATE  0.5 // 
radians per second


//



#import GCRadarView.h


@implementation GCRadarView

- (void)drawHistoryBuffer
{
// draw the current buffered image to the view

	[mHistoryImage drawInRect:[self bounds] fromRect:NSZeroRect  
operation:NSCompositeSourceOver fraction:1.0];

}


- (void)updateHistoryBuffer
{
NSImage* newImage = [[NSImage alloc] initWithSize:[self bounds].size];

	// copy the current history into it at reduced opacity - dial in  
different opacity values to change the persistence
	// values closer to 1.0 give more persistence, closer to 0 give less.  
1.0 gives infinite persistence, so the image never fades.


[newImage lockFocus];

if( mHistoryImage )
		[mHistoryImage drawInRect:[self bounds] fromRect:NSZeroRect  
operation:NSCompositeSourceOver fraction:0.92];


// draw new content

[self drawContentIntoImage:newImage];
[newImage unlockFocus];

// this is now the history buffer:

[mHistoryImage release];
mHistoryImage = newImage;
}


- (void)drawContentIntoImage:(NSImage*) theImage
{
// draw view content to the image. Image is already focused.

NSTimeInterval  currentTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval  elapsedTime = currentTime - mLastUpdateTime;
mLastUpdateTime = currentTime;

	// sweep rate is 0.5 rad/sec - so how many radians since we last  
updated?


CGFloat angleIncrement = SWEEP_RATE * elapsedTime;
mAngle += angleIncrement;
mAngle = fmod( mAngle, 2 * pi );

// set the transform to this angle rotated around the centre point

NSPoint centre;

centre.x = NSMidX([self bounds]);
centre.y = NSMidY([self bounds]);

[NSGraphicsContext saveGraphicsState];

NSAffineTransform* transform = [NSAffineTransform transform];
[transform translateXBy:centre.x yBy:centre.y];
[transform rotateByRadians:mAngle];
[transform translateXBy:-centre.x yBy:-centre.y];
[transform concat];

// set a shadow to simulate the backscatter glow

NSShadow* shadow = [[NSShadow alloc] init];
	[shadow setShadowColor:[NSColor colorWithCalibratedRed:0.4 green:1.0  
blue:0.4 alpha:1.0]];

[shadow setShadowOffset:NSZeroSize];
[shadow setShadowBlurRadius:8.0];
[shadow set];

	// draw the sweep line from centre to edge. The transform is rotated  
so draw at a fixed angle.


[[NSColor greenColor] set];
[NSBezierPath setDefaultLineWidth:1.5];
	[NSBezierPath strokeLineFromPoint:centre toPoint:NSMakePoint( NSMaxX 
([self bounds]), NSMidY([self bounds]))];


	// draw the target on the screen when the beam sweeps across it to  
simulate a blip - here just a square
	// restore first so that effect of rotation is removed - target stays  
at a fixed place.


[NSGraphicsContext restoreGraphicsState];

if( fabs(mAngle)  0.1 )
{
		NSBezierPath* target = [NSBezierPath bezierPathWithRect:NSMakeRect 
(( centre.x + NSMaxX([self bounds])) / 2.0, NSMidY([self bounds]), 10,  
10 )];

[[NSColor greenColor] set];
[target fill];
}

[shadow release];
}


- (void)animateWithTimer:(NSTimer*) timer
{
	// timer callback ends up here. It updates the 

Re: Frameworks in red

2009-09-27 Thread Gregory Weston

ERG Consultant wrote:

I should have mentioned that the Frameworks in question are the  
System frameworks. And they are Found Fine by The original App.  
(which Runs just Fine.)


Nevertheless, Graham has correctly stated the reason that items show  
up in red: Xcode can't find them where it thinks they are. To me, that  
suggests that perhaps they're referenced in the project by relative  
paths instead of absolute, and that relative path isn't appropriate  
from the second project.

___

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


Re: OR compositing operation?

2009-09-27 Thread Oleg Krupnov
Paul, thanks for such an exhaustive answer!

Here are answers to your questions:
1. My case is the simple one -- I'm rendering all text layers at once.
2. Yes and no. As I said, I am implementing the cross-fade effect,
when one text fades out and another text fades in. The texts can be of
the same color (simplest case) or of different color (different shades
of gray), and their alphas change during the fading animation. The
problem is that the semi-transparent areas of text, when overlapping,
produce brighter pixels, the annoying flash effect, I'm trying to
get rid of.

My further research shows that kCGBlendModeLighten does not seem to
apply to the alpha channel. Namely, colors are indeed composited using
the lighten rule, but then the resulting color is alpha blended with
the background as usual, so that two overlapping semitransparent
pixels still produce a more opaque pixel, which is undesirable

Am I missing the clue how to make kCGBlendModeLighten apply to the
alpha channel as well?

I have come to the following workaround: I fill the text layers with
opaque black background. In this case the kCGBlendModeLighten works
perfectly, as expected.

Unfortunately, I am not fully satisfied with this solution, because I
need the background of the text layers to be half-transparent as well.
This returns me to the question of how to make kCGBlendModeLighten to
the alpha channel.

You said I could average the color components but max the alphas.
How can I do this? Thanks!


On Sun, Sep 27, 2009 at 3:45 AM, Paul M l...@no-tek.com wrote:
 This is a multi-pass operation - you wont find a single
 blend mode that will do this in any simple manner.

 First question: Are you doing this all in one hit, or sequentially,
 ie, rendering the first layer of text then adding subsequent
 layers later?
 Second question: is the text all the same colour and have the
 same alpha component?

 If you're rendering all the text layers at once, you need to first
 combine the text layers, then composite over the background. In the
 simple case you describe, I imagine you'll need to average the colour
 components but max the alphas. This should give you the results you
 asked for.

 If you need to comosite different layers at different times, it
 becomes a lot more complex.
 If your text is not all the same colour then you need access to all
 the previous layers so that they may be combined as above and the
 composite redone.
 If your text is all the same colour then you can write the alpha from
 the first layer into the composite so that this may be extracted and
 used later in the 2nd and subsequent composites. The process for
 these later composites gets pretty gnarley, and you're really better
 of keeping a reference to the preceeding layers if that's at all
 possible.


 paulm


 On 27/09/2009, at 12:17 AM, Oleg Krupnov wrote:

 Thanks!

 It seemed exactly what I need but I've found that it doesn't work as
 expected. The interpolated semi-transparent parts of the rendered text
 still appears brighter than it should.

 Namely, consider drawing white text on black background, and then
 drawing the same white text one more time over the first one.

 Suppose that when a letter is rasterized, one of the resulting
 interpolated pixels is semitransparent white, with alpha = 50%. After
 alpha blending with the black background, the pixel becomes a 50% gray
 pixel.

 Now when the second text is drawn on top, there will be also the same
 semitransparent white pixel with alpha = 50% at the same location.
 What result I'd like to achieve would be to have the same 50% gray
 pixel at this location. However, with kCGBlendModeLighten mode, what I
 think what's happening is that the system picks pure white as the
 lighter of two colors: 50% gray of the background and pure white
 (without taking into account the alpha of the new pixel), and then
 applies the usual alpha blending rule, which results in 75% gray.

 Is there a workaround? Or am I doing something wrong? Thanks!

 On Tue, Sep 22, 2009 at 7:23 PM, David Duncan david.dun...@apple.com
 wrote:

 On Sep 22, 2009, at 6:22 AM, Oleg Krupnov wrote:

 Hi,

 I'd like to draw in a graphics context in such a compositing mode:

 R = MAX(S, D)

 i.e. out of two colors (source and destination), the maximum color
 (channel-wise) was chosen. This is basically equivalent to ORing the
 colors.


 This is the Lighten blend mode (kCGBlendModeLighten). There doesn't
 appear
 to be a corresponding NS composting mode, and I'm not sure why, but you
 can
 easily get a CGContext from an NSGraphicsContext by asking it for its
 graphicsPort, so this shouldn't be hard to integrate.
 --
 David Duncan
 Apple DTS Animation and Printing


 ___

 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:
 

Snow Leopard, core data, read only and multiple threads

2009-09-27 Thread Chris Idou
I've got an app that worked on Leopard. I ported it to Snow Leopard SDK 10.6, 
and now it works on Snow Leopard, but it doesn't work correctly on Leopard 
anymore. I haven't changed anything that ought to affect this.

It's an app with a foreground gui that writes an XML coredata store. A 
background thread reads the repository and takes action. Both threads have the 
full core data stack with their own coordinators. As soon as I activate the 
background thread, the XML store gets set to zero bytes.

When I encountered the problem I read the doco and I added the 
NSReadOnlyPersistentStoreOption when calling addPersistentStoreWithType in the 
background thread, but that hasn't helped. It wasn't necessary before.

Has anyone got any thoughts?

And also, how am I going to debug this? Xcode 3.2 doesn't run on 10.5 does it? 
And is an Xcode 3.2 project now going to work with XCode 3.1?


  
__
Get more done like never before with Yahoo!7 Mail.
Learn more: http://au.overview.mail.yahoo.com/
___

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


redrawing a particular subview in non mainWindows.

2009-09-27 Thread jon

I've got a Document type program,

the windows are structured like this:

Window - ContentView - SplitView - two CustomViews - one of them  
is Bordered Scroll view (outlineView) -Outline View


i have one instance of Outline View  called myOutlineView,   so no  
matter how many documents are displayed on the screen,   there is only  
one myOutlineView instance,


the current mainWindow  updates the myOutlineView just fine when i  
make a change to this one instance,   but i want to redraw or update  
the Outline View of all the other open documents that can be seen so  
they also match (on screen) the one instance of myOutlineView.   in  
code they already do match.  so they just need updated.


so far i can find the chain of windows,  like this,  but i can't  
figure out how to go deeper into them to be able to udpate the custom  
view down deep   maybe i'm approaching it wrong too...


any help would be great,(the setHidden is just there as a test,   
it is there so i know i've found the correct window, and eventually  
the correct subview)

thanks,
Jon.

IBOutlet NSOutlineView  *myOutlineView;
--


NSArray *theWindowsArray = [NSApp orderedWindows];
NSWindow *theWindow = [theWindowsArray objectAtIndex:1];

theContentView = [theWindow contentView];

//-  i need to find the split view of theContentView  and  
then the outline view of that one side of the split view -//


[theContentView setHidden:YES];



___

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


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Graham Cox


On 28/09/2009, at 12:04 AM, jon wrote:

i have one instance of Outline View  called myOutlineView,   so no  
matter how many documents are displayed on the screen,   there is  
only one myOutlineView instance,



I'm pretty sure that is never going to work. If I read you correctly,  
you have a single view instance that is simultaneously a subview of  
any number of documents? If so, that's just not a valid setup. A view  
must have a distinct unique parent view and window, not multiple  
parent views. However, I'm not sure how you could even set this up, so  
I'm skeptical that your description is really accurate.


What you need here is a separate view instance in each document but  
possibly sharing the same data source or controller such that they all  
show the same data, or sanest of all, separate data sources/ 
controllers that all reference a common shared data model - that is  
after all what you've described as your needs. This last will just  
work as long as you strictly follow MVC and use a standard recognised  
method for notifying views, like KVO or bindings.


--Graham


___

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


Re: OR compositing operation?

2009-09-27 Thread Oleg Krupnov
With a second thought, I think it would do perfectly with simply
averaging ALL channels, R, G, B, and A, for this cross-fade effect.

So I am reformulating my questions as follows: How do I produce the
blending mode when the foreground and background colors are averaged
channel-wise, for all channels, including the alpha channel?

Thanks

On Sun, Sep 27, 2009 at 4:25 PM, Oleg Krupnov oleg.krup...@gmail.com wrote:
 Paul, thanks for such an exhaustive answer!

 Here are answers to your questions:
 1. My case is the simple one -- I'm rendering all text layers at once.
 2. Yes and no. As I said, I am implementing the cross-fade effect,
 when one text fades out and another text fades in. The texts can be of
 the same color (simplest case) or of different color (different shades
 of gray), and their alphas change during the fading animation. The
 problem is that the semi-transparent areas of text, when overlapping,
 produce brighter pixels, the annoying flash effect, I'm trying to
 get rid of.

 My further research shows that kCGBlendModeLighten does not seem to
 apply to the alpha channel. Namely, colors are indeed composited using
 the lighten rule, but then the resulting color is alpha blended with
 the background as usual, so that two overlapping semitransparent
 pixels still produce a more opaque pixel, which is undesirable

 Am I missing the clue how to make kCGBlendModeLighten apply to the
 alpha channel as well?

 I have come to the following workaround: I fill the text layers with
 opaque black background. In this case the kCGBlendModeLighten works
 perfectly, as expected.

 Unfortunately, I am not fully satisfied with this solution, because I
 need the background of the text layers to be half-transparent as well.
 This returns me to the question of how to make kCGBlendModeLighten to
 the alpha channel.

 You said I could average the color components but max the alphas.
 How can I do this? Thanks!


 On Sun, Sep 27, 2009 at 3:45 AM, Paul M l...@no-tek.com wrote:
 This is a multi-pass operation - you wont find a single
 blend mode that will do this in any simple manner.

 First question: Are you doing this all in one hit, or sequentially,
 ie, rendering the first layer of text then adding subsequent
 layers later?
 Second question: is the text all the same colour and have the
 same alpha component?

 If you're rendering all the text layers at once, you need to first
 combine the text layers, then composite over the background. In the
 simple case you describe, I imagine you'll need to average the colour
 components but max the alphas. This should give you the results you
 asked for.

 If you need to comosite different layers at different times, it
 becomes a lot more complex.
 If your text is not all the same colour then you need access to all
 the previous layers so that they may be combined as above and the
 composite redone.
 If your text is all the same colour then you can write the alpha from
 the first layer into the composite so that this may be extracted and
 used later in the 2nd and subsequent composites. The process for
 these later composites gets pretty gnarley, and you're really better
 of keeping a reference to the preceeding layers if that's at all
 possible.


 paulm


 On 27/09/2009, at 12:17 AM, Oleg Krupnov wrote:

 Thanks!

 It seemed exactly what I need but I've found that it doesn't work as
 expected. The interpolated semi-transparent parts of the rendered text
 still appears brighter than it should.

 Namely, consider drawing white text on black background, and then
 drawing the same white text one more time over the first one.

 Suppose that when a letter is rasterized, one of the resulting
 interpolated pixels is semitransparent white, with alpha = 50%. After
 alpha blending with the black background, the pixel becomes a 50% gray
 pixel.

 Now when the second text is drawn on top, there will be also the same
 semitransparent white pixel with alpha = 50% at the same location.
 What result I'd like to achieve would be to have the same 50% gray
 pixel at this location. However, with kCGBlendModeLighten mode, what I
 think what's happening is that the system picks pure white as the
 lighter of two colors: 50% gray of the background and pure white
 (without taking into account the alpha of the new pixel), and then
 applies the usual alpha blending rule, which results in 75% gray.

 Is there a workaround? Or am I doing something wrong? Thanks!

 On Tue, Sep 22, 2009 at 7:23 PM, David Duncan david.dun...@apple.com
 wrote:

 On Sep 22, 2009, at 6:22 AM, Oleg Krupnov wrote:

 Hi,

 I'd like to draw in a graphics context in such a compositing mode:

 R = MAX(S, D)

 i.e. out of two colors (source and destination), the maximum color
 (channel-wise) was chosen. This is basically equivalent to ORing the
 colors.


 This is the Lighten blend mode (kCGBlendModeLighten). There doesn't
 appear
 to be a corresponding NS composting mode, and I'm not sure why, but you
 can
 easily get a CGContext 

Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread jon
I am probably not describing it accurately,I'll try to understand  
and describe what is going on more accurately in a bit,   more likely,  
i have one set of data,   and each time a new window is open,  it is  
creating another instance of the outline view,   i have not found away  
to get at the old instances of this view...


thanks,
Jon.


On Sep 27, 2009, at 8:31 AM, Graham Cox wrote:


 so I'm skeptical that your description is really accurate.


___

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


Re: Getting glyphs for surrogate characters ??

2009-09-27 Thread Anders Lassen

Hi

I may have solved the problem described above.

The method glyphAtIndex returns two glyphs. The first one is actually  
the correct glyph for the surrogate character. The next one is zero.


If someone knows a better method to obtain glyphs, without using the  
LayoutManager, I am glad to know.


Anders Lassen


On Sep 26, 2009, at 7:17 PM, Anders Lassen wrote:


Hi,

I have a problem generating glyph for surrogate characters.

I have considered not to use glyphs directly, but since I need very  
fine control of the drawing of the glyph, this is a good solution  
for me. Having a glyph gives direct acces to both the boundingbox,  
the path and the advancement.


The documentation for the GlyphGenerator says that only one glyph is  
generated per character.


This is also what I see, if I use a LayoutManager to generate glyph.

If for instance NSTextStorage is set to @\U0001D400, the following  
call to:


 NSGlyph glyph = [layoutManager glyphAtIndex:i  
isValidIndex:hasGlyph];


generates two glyphs, and not one as I hoped.

I have tried using glyphnames instead, but this is not an option,  
because not all glyphs in a font is name encoded.  (I am not  
absolutely sure about this, but I can only retrieve glyphs with  
simple name like tau, delta, infinity).



Kind regards,

Anders Lassen


___

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/anders.lassen%40mac.com

This email sent to anders.las...@mac.com


___

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


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 7:04 AM, jon wrote:

so far i can find the chain of windows,  like this,  but i can't  
figure out how to go deeper into them to be able to udpate the  
custom view down deep   maybe i'm approaching it wrong too...


The best way to do this is to use NSNotification. Post a notification  
when the outline content changes, and have each object that manages  
one of the outline views (probably the NSDocument or  
NSWindowController subclass) observe that notification and update its  
outline view when it's received.


There are some times when you do need to tell every one of your  
windows something. The way I do this is to loop through the  
application's window list, then look at each visible window's delegate  
and check whether it's an instance of my window controller subclass;  
if so, I cast the pointer to that subclass and call a method on it.  
(Since you're using NSDocument, you could probably get the same effect  
by getting the list of open documents from the document-controller  
object.)


—Jens___

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


Re: NSURLConnection upload to iDisk works with iPhone OS 2.x but fails on 3.x

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 2:25 AM, Sergey Shapovalov wrote:

This makes me think that chunked upload from stream via  
NSURLConnection has been broken in iPhone OS 3.x. Unfortunately, in  
real life I can't upload my file by using setHTTPBody instead of  
setHTTPBodyStream because it's too big to store in memory.


That sounds plausible :( Is there a way you can capture the HTTP  
traffic to see exactly what's going on? Ordinarily I use the tcpflow  
utility for this, but it's not possible to install that on an iPhone.  
I think tcpdump can be used from a Mac/PC to capture packets from  
other devices on the LAN.


In any case, you should repost your questions on the macnetworkprog  
mailing list — this looks like a CFNetwork problem, and some of the  
engineers who work on that read that list.


Unfortunately, in real life I can't upload my file by using  
setHTTPBody instead of setHTTPBodyStream because it's too big to  
store in memory.


Have you tried memory-mapping? Use [NSData  
dataWithContentsOfMappedFile:].


—Jens___

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


Re: Xcode3.2 build and analyze warning for NSString allocation

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 2:03 AM, Nick Rogers wrote:

		1. Method returns an Objective-C object with a +1 retain count  
(owning reference).


It means exactly what it says. The string was created by -alloc, so  
you own a reference so it, so you need to call -autorelease on it  
before returning it.
No offense, but this is very basic Cocoa refcounting stuff, so it  
sounds like you should carefully read the memory management guidelines.


—Jens___

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


Best Design Advice

2009-09-27 Thread David Blanton
I need to create an app the is auto downloaded and installed from a  
web site when the user clicks a web page button.


The app needs to be installed so that it always runs when the user  
logs in.


The app needs to periodically (by user preference setting) connect to  
a web server.


The app needs to display a window with information gleaned from its  
last web server connect.


=
1. Where should the app be installed.

2. Are there any permission issues.

3. Is this a background service or status like item.

4. Is it's periodic web connect fired by a timer or some other means.

5. Any other general tips / tricks.
=


Thanks in advance!

db


___

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


Core Animation and Run Loops

2009-09-27 Thread Oleg Krupnov
Hi,

Today I read this in wikipedia: (http://en.wikipedia.org/wiki/Core_Animation)

Animated sequences execute in a thread independent from the main run
loop, allowing application processing to occur while the animation is
in progress.

However, in my experience, Core Animation animations do not run while
the main thread is blocked. For example, when the main thread is
running a usual blocking NSAnimation, the CA-animation is frozen and
resumed only when the NSAnimation ends.

Could someone clarify on this, please?
___

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


Re: Best Design Advice

2009-09-27 Thread Jens Alfke


On Nov 14, 2009, at 9:21 AM, David Blanton wrote:

I need to create an app the is auto downloaded and installed from a  
web site when the user clicks a web page button.


It can be downloaded when the user clicks a button, but of course it  
can't automatically run or be installed that way; that would be a  
security issue. The user needs to explicitly open the app after it's  
downloaded.



1. Where should the app be installed.


Wherever the user wants. You shouldn't need an installer for this,  
just package the app as a .zip or .dmg file.



2. Are there any permission issues.


No. But setting your app to launch at login without the user's consent  
would be a bad idea, unless of course you're writing malware ;).  
Please either put up an alert asking the user on first launch, or make  
it a checkbox in the prefs.



3. Is this a background service or status like item.


Only if you want it to be. Is there any UI? (If not, how does the user  
configure it or turn it off?)

Should it have a dock item? If not, how does the user access its UI?


4. Is it's periodic web connect fired by a timer or some other means.


Probably an NSTimer.

—Jens___

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


where to release a CF object thats retained by a cocoa object

2009-09-27 Thread Navneet Kumar

Hi,
From a method in my AppController class I'm calling a function in  
another file as follows:


In AppController in init method:-
[self initialDriveList];


In AppController in initialDriveList method:
//some code here
[self volumeList];
// rest of the code here

In AppController in volumeList method:
finalArrayForVolumes = [[NSMutableArray alloc] init];// an ivar in  
AppController class
// adding some objects of type NSMutableDictionary to the  
finalArrayForVolumes here

FindVolumeNames((CFMutableArrayRef)finalArrayForVolumes);
[finalArrayForVolumes retain];


In another file in FindVolumeNames() function:
void FindVolumeNames(CFMutableArrayRef response)
{
CFIndex count = CFArrayGetCount(response);
int i;
for (i = 0; i  count; i++)
{
		CFMutableDictionaryRef data = (CFMutableDictionaryRef) 
CFArrayGetValueAtIndex (response, i);

// some code here
		CFStringRef outputVolumeName = CFStringCreateWithSubstring  
(kCFAllocatorDefault, pathName, rangeResult);// line 176, Call to  
function 'CFStringCreateWithSubstring' returns a Core Foundation  
object with a +1 retain count (owning reference)


CFDictionaryAddValue(data, CFSTR(kVolumeName), 
outputVolumeName);
// Shall I do CFRelease(outputVolumeName); here?
//some code here
	}//Object allocated on line 176 and stored into 'outputVolumeName' is  
no longer referenced after this point and has a retain count of +1  
(object leaked)


//some code here
}

The warnings returned by static analyzer in Xcode3.2 are mentioned in  
the code above.
Main warning was: Potential leak of an object allocated on line 176  
and stored into 'outputVolumeName'
The problem is where to release this outputVolumeName, which is added  
to a dictionary which is added to an array allocated in AppController?

And will that lead to removal of this warning?
I gather there is no autorelease in CF.

Wishes,
Nick

___

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


Re: NSMenuItem NSRuleEditor

2009-09-27 Thread Frederick Bartram

There is very little documentation on NSRuleEditor. :(
First, you need to distinguish between a 'criterion' and a 'display  
value' although they may be the same kind of classes. The criterion is  
a kind of identifier and the display value is what is actually shown.


It is also helpful to think of the rule editor as displaying a tree of  
alternatives along each row.
The left-most criterion is the root, typically a NSPopupButton. The  
selected NSMenuItem presents a particular branch. So if a criterion is  
a NSPopupButton then 'child:' might be the 'target' of the NSMenuItem  
at the 'index' in the criterion's menu. (criterion)NSPopUpButton =  
NSMenuItem target = next NSControl (the child, perhaps another  
NSPopUpButton)


The 'child:' method  returns a criterion that can be a variety objects  
a NSControl, a NSMenuItem, a NSString, an NSView, or nil.
- (id) ruleEditor:(NSRuleEditor *)editor child:(NSInteger)index  
forCriterion:(id)criterion withRowType:(NSRuleEditorRowType)rowType;


How you chose to chain along the criteria depends on you. The sequence  
of criteria represent paths through the rule tree.


If the initial criterion is nil then you are at the root and your root  
criterion might be a function, perhaps, of the row-type.


The 'displayValue' is what actually populates the rule editor and is  
either a NSMenuItem, NSString, an NSView, or some kind of NSControl.  
In some cases if the criterion happens to be a NSMenuItem then the  
display value may just be a copy of the criterion, or a copy of the  
'title' string, but each 'display value' must be new. We cannot just  
return a pointer to the criterion. In any case, the 'display value' is  
derived from the particular criterion and must be a new value for each  
invocation of
- (id) ruleEditor:(NSRuleEditor *)editor displayValueForCriterion: 
(id)criterion inRow:(NSInteger)row;


Any how, what I've learned about NSRuleEditor is just the result of  
spending too much time building rule editors. I am sorry but I don't  
have a good example project to demonstrate this.


In summary, the criteria represent a model or prototype of the  
alternative paths through the selection tree and the display values  
represent an instantiation of the path.


Anyway, this is what I've learned just by treating a rule editor as a  
black box maybe someone else can provide an authoritative answer.


Good luck.
*-
* Stop spam before it gets to your mailbox! Support blocklists.
* I use http://www.spamcop.net/.
* my PGP key id: 0x63fa758 keyserver: http://keyserver1.pgp.com
*/

___

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


Re: Getting glyphs for surrogate characters ??

2009-09-27 Thread Alastair Houghton

On 27 Sep 2009, at 16:51, Anders Lassen wrote:


I may have solved the problem described above.

The method glyphAtIndex returns two glyphs. The first one is  
actually the correct glyph for the surrogate character. The next one  
is zero.


Indeed, the system generates a special NSNullGlyph in many of these  
cases, the reason presumably being that it keeps the character ranges  
and glyph ranges aligned.


*However*, I'm not sure that there is any guarantee that a single  
character won't map in general to multiple glyphs, or indeed that a  
given character will directly result in *any* glyphs of its own.


You really do need to cope with these cases in your code, because they  
come up in real use cases.  They may be more common in non-Latin  
languages (Arabic, Indic scripts and Hangul are particularly fun), but  
even if you only support Latin languages it's possible that some fonts  
will cause problems for you if you can't cope with an arbitrary number  
of glyphs per character.


FWIW, if you aren't using the text system for this task, doing it  
yourself is decidedly non-trivial.  I would strongly recommend using  
the text system, and actually, if you can I would *also* recommend  
letting the text system do the layout for you, because it is very much  
more sophisticated than just worrying about bounding boxes and glyph  
advances.


Kind regards,

Alastair.

--
http://alastairs-place.net




___

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


Re: where to release a CF object thats retained by a cocoa object

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 10:11 AM, Navneet Kumar wrote:


// Shall I do CFRelease(outputVolumeName); here?


Yes. You have to call CFRelease on any reference you got via a  
xxCopyxx or xxCreatexx function.


—Jens___

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


Re: Xcode3.2 build and analyze warning for NSString allocation

2009-09-27 Thread Jeremy Pereira


On 27 Sep 2009, at 10:03, Nick Rogers wrote:


Hi,

When I alloc and init a NSString the following way, there is warning  
that:
Potential leak of an object allocated on line 526 and stored in  
sizeDisp.
		1. Method returns an Objective-C object with a +1 retain count  
(owning reference).
	2. Object returned to caller as an owning reference (single retain  
count transferred to caller).
	3. Object allocated on line 526 and stored into 'sizeDisp' is  
returned from a method whose name  
('tableView:objectValueForTableColumn:row:') does not contain 'copy'  
or otherwise starts with 'new' or 'alloc'.  This violates the naming  
convention rules given in the Memory Management Guide for Cocoa  
(object leaked).



Can I hope for a small analysis of the above from anybody?


It's hard to see how item 3 above can be improved on as an analysis  
except by providing a link to the memory management guidelines.  So  
here they are.


http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/2994




Thanks,
Nick


___

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/adc%40jeremyp.net

This email sent to a...@jeremyp.net


___

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


Re: Core Animation and Run Loops

2009-09-27 Thread Shlok Datye

Take a look at this movie, which was taken on Leopard: 
http://shlok.s3.amazonaws.com/20090927-ca-problem.mov
The blue rectangle is a layer-backed NSView that is animated using  
Core Animation. The problem is that the animation halts while the main  
loop waits for the mouse to get released.


For your information, this was a bug that has been fixed in Snow  
Leopard. I'm therefore curious: Have you tried running a blocking  
NSAnimation along with a CA-animation in Snow Leopard?


Shlok Datye
Coding Turtle
http://codingturtle.com



Hi,

Today I read this in wikipedia: (http://en.wikipedia.org/wiki/Core_Animation 
)


Animated sequences execute in a thread independent from the main run
loop, allowing application processing to occur while the animation is
in progress.

However, in my experience, Core Animation animations do not run while
the main thread is blocked. For example, when the main thread is
running a usual blocking NSAnimation, the CA-animation is frozen and
resumed only when the NSAnimation ends.

Could someone clarify on this, please?



___

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


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread jon
ok,  after thinking and analyzing what was going on,  everytime i make  
a new document in the running app,   it created a new instance of the  
window and all related stuff in the window including myOutlineView.   
and then my dataSource in code remained the same that fills out these  
outline views...   (atleast this is my current understanding).


so my question now morphs into:

  as Jens says below,  he in some cases is looping through the apps  
window list...


in my case,   in my main document xib,  i have an outline Controller  
which is type NStreeController...  and i have this defined..


IBOutlet NSTreeController *treeController  which is the thing that is  
controlling the outline view,  and appears to be the thing i want to  
update...


the question it appears to me is:  that this treeController also is  
made into multiple instances with each new Document,   is there an  
already defined loop of these?  (a list of the open document's  
NSTreeController *treeController;)


or do i need to make an NSMutableArray,  and keep track of these  
myself?   and then update these instances myself by looping through  
them?


thanks,
Jon.

On Sep 27, 2009, at 9:54 AM, Jens Alfke wrote:


 The way I do this is to loop through the application's window list,


___

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


Re: Best Design Advice

2009-09-27 Thread David Blanton

Jens -

I am not sure from your response how the app will run when the user  
logs in.


Should not  the app be installed in a particular location so that it  
starts when the user logs in?


And, does this not imply that the user should not have the option of  
specifying where the app is installed.


And, if there is a particular location to be installed so that the app  
runs at login are there not permission issues?



Thanks.

db


On Sep 27, 2009, at 10:38 AM, Jens Alfke wrote:



On Nov 14, 2009, at 9:21 AM, David Blanton wrote:

I need to create an app the is auto downloaded and installed from a  
web site when the user clicks a web page button.


It can be downloaded when the user clicks a button, but of course it  
can't automatically run or be installed that way; that would be a  
security issue. The user needs to explicitly open the app after it's  
downloaded.



1. Where should the app be installed.


Wherever the user wants. You shouldn't need an installer for this,  
just package the app as a .zip or .dmg file.



2. Are there any permission issues.


No. But setting your app to launch at login without the user's  
consent would be a bad idea, unless of course you're writing  
malware ;). Please either put up an alert asking the user on first  
launch, or make it a checkbox in the prefs.



3. Is this a background service or status like item.


Only if you want it to be. Is there any UI? (If not, how does the  
user configure it or turn it off?)

Should it have a dock item? If not, how does the user access its UI?


4. Is it's periodic web connect fired by a timer or some other means.


Probably an NSTimer.

—Jens




___

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


Re: Best Design Advice

2009-09-27 Thread Volker in Lists

Hi,

Am 14.11.2009 um 22:25 schrieb David Blanton:

Should not  the app be installed in a particular location so that it  
starts when the user logs in?


You can add any app, located at any location (nearly at any) to the  
Startup Items of a user and the app gets started. No need to be in a  
special place for that. Just has to be available at user login time.




And, does this not imply that the user should not have the option of  
specifying where the app is installed.


The user should have free choice - let it be /Applications or ~/ 
Applications for example. Since nothing is implied from the first  
step, no problem.




And, if there is a particular location to be installed so that the  
app runs at login are there not permission issues?


The user can not install the app to locations where he doesn't have  
write access to or where he can't get temporary write access.


What have you looked into? Your current questions are rather vague and  
not Cocoa related so far.


? http://whathaveyoutried.com/



Volker


___

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


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Jens Alfke


On Sep 27, 2009, at 11:19 AM, jon wrote:

the question it appears to me is:  that this treeController also  
is made into multiple instances with each new Document,   is there  
an already defined loop of these?  (a list of the open document's  
NSTreeController *treeController;)


No. I think you're confused about now nibs work. In your example,  
'treeController' is an instance variable (or field) of your document  
class. That means every instance of the class has one.


What happen when creating a document is that the NSDocumentController  
creates a new instance of your document subclass, then loads a new  
copy of the nib with your document object as its 'owner'. This creates  
a new instance of every object contained in the nib; and the instance  
variables of the owner object (your document) get connected to those  
new objects as you specified. So in  your new document object, the  
treeController instance variable will point to the new tree controller.


So every open document has one tree controller. If you want to find  
the list of open documents, ask the NSDocumentController.


—Jens___

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


Re: Best Design Advice

2009-09-27 Thread Colin Howarth


On 14 Nov, 2009, at 22:25, David Blanton wrote:


Jens -

I am not sure from your response how the app will run when the user  
logs in.


Should not  the app be installed in a particular location so that it  
starts when the user logs in?


And, does this not imply that the user should not have the option of  
specifying where the app is installed.


And, if there is a particular location to be installed so that the  
app runs at login are there not permission issues?



A user can decide which apps to start automatically when logging in,  
by selecting System Preferences  Accounts  LoginItems and then  
clicking on +.


A finder type window opens and the user can select any program to have  
it start up automatically. So, no, the app doesn't have to be in a  
particular location and no, there aren't special permission issues.



Perhaps you could explain the need for the whole automation aspect.  
The first time I read your first post I also thought malware/spyware.


I need to create an app the is auto downloaded and installed from a  
web site when the user clicks a web page button.
The app needs to be installed so that it always runs when the user  
logs in.

___

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


Re: NSURLConnection upload to iDisk works with iPhone OS 2.x but fails on 3.x

2009-09-27 Thread Sergey Shapovalov

Jens, thank you for your answer.

On Sep 27, 2009, at 7:59 PM, Jens Alfke wrote:


On Sep 27, 2009, at 2:25 AM, Sergey Shapovalov wrote:

This makes me think that chunked upload from stream via  
NSURLConnection has been broken in iPhone OS 3.x. Unfortunately, in  
real life I can't upload my file by using setHTTPBody instead of  
setHTTPBodyStream because it's too big to store in memory.


That sounds plausible :( Is there a way you can capture the HTTP  
traffic to see exactly what's going on? Ordinarily I use the tcpflow  
utility for this, but it's not possible to install that on an  
iPhone. I think tcpdump can be used from a Mac/PC to capture packets  
from other devices on the LAN.


Yes, I can try running the code in iPhone Simulator and capturing the  
traffic, or run it on iPhone and use the Mac as wi-fi proxy... Well,  
I'll try and compare the traffic generated with 2.2.1 and 3.0  
executables.


In any case, you should repost your questions on the macnetworkprog  
mailing list — this looks like a CFNetwork problem, and some of the  
engineers who work on that read that list.


Thanks for the advice! Will try doing so.

Unfortunately, in real life I can't upload my file by using  
setHTTPBody instead of setHTTPBodyStream because it's too big to  
store in memory.


Have you tried memory-mapping? Use [NSData  
dataWithContentsOfMappedFile:].


No, I haven't... Well, that is definitely another option worth of  
trying. Thank you, this idea didn't come to my mind before!


Best regards,
Sergey.___

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


Looking for Sample code: WWDC2007 - Session 201 - Building Animated Cocoa User Interfaces

2009-09-27 Thread Michael A. Crawford
I believe the demos were called CocoaShuffle and Layer-Backed OpenGL  
View.  Can these be downloaded somewhere?


-Michael


___

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


re: Snow Leopard, core data, read only and multiple threads

2009-09-27 Thread Ben Trumbull
I've got an app that worked on Leopard. I ported it to Snow Leopard  
SDK 10.6, and now it works on Snow Leopard, but it doesn't work  
correctly on Leopard anymore. I haven't changed anything that ought  
to affect this.


What doesn't work ?

It's an app with a foreground gui that writes an XML coredata store.  
A background thread reads the repository and takes action. Both  
threads have the full core data stack with their own coordinators.  
As soon as I activate the background thread, the XML store gets set  
to zero bytes.


The XML store is an atomic store.  Everything is loaded at once, and  
everything is written out for each save.  Very NSDocument like.  Like  
TextEdit.  Two people open up Text Edit, pointed to the same path  
mounted over a shared volume.  What happens ?


You almost certainly want to use the SQLite store, or have the stacks  
work with different XML files.


When I encountered the problem I read the doco and I added the  
NSReadOnlyPersistentStoreOption when calling  
addPersistentStoreWithType in the background thread, but that hasn't  
helped. It wasn't necessary before.


NSReadOnlyPersistentStoreOption doesn't have anything to do with multi- 
threading.


You sure you're not saving a MOC ?

- Ben

___

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


Re: redrawing a particular subview in non mainWindows.

2009-09-27 Thread Graham Cox
While sometimes you simply have no choice but to loop through your  
windows, it isn't the first approach that comes to mind for this.


In the MVC design, you have separate views (one in each document) and  
separate controllers (each one referenced from each document 1:1) but  
what you do need is a single common data model that all of these  
controllers are referencing. Since this is common to all, it is a good  
choice for a singleton.


Then, when any view, via the controller, updates the model, all the  
other controllers get informed about the change (via KVO, bindings,  
notifications, whatever) and update their views accordingly. You  
should not need to loop through your windows and try and force an  
update, that's just trying to work around the MVC design instead of  
making proper use of it.


The singleton will have to be external to the nib since there is not  
one instance per doc, but one instance per app, and you'll have to  
make that connection as each nib is loaded. From then on, however the  
updates notifications are actually implemented, it will work correctly  
without further intervention on your part. If you find yourself  
thinking you need to manage collections of things yourself just to  
handle this sort of update notifications, chances are you've  
overlooked something obvious, since there are numerous built-in  
mechanisms available for handling just this, and very elegantly too.


--Graham



On 28/09/2009, at 4:19 AM, jon wrote:

ok,  after thinking and analyzing what was going on,  everytime i  
make a new document in the running app,   it created a new instance  
of the window and all related stuff in the window including  
myOutlineView.  and then my dataSource in code remained the same  
that fills out these outline views...   (atleast this is my current  
understanding).


so my question now morphs into:

  as Jens says below,  he in some cases is looping through the apps  
window list...


in my case,   in my main document xib,  i have an outline  
Controller which is type NStreeController...  and i have this  
defined..


IBOutlet NSTreeController *treeController  which is the thing that  
is controlling the outline view,  and appears to be the thing i want  
to update...


the question it appears to me is:  that this treeController also  
is made into multiple instances with each new Document,   is there  
an already defined loop of these?  (a list of the open document's  
NSTreeController *treeController;)


or do i need to make an NSMutableArray,  and keep track of these  
myself?   and then update these instances myself by looping through  
them?




___

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


NSView clicking through to superview

2009-09-27 Thread PCWiz

Hi,

I have a transparent black NSView that I layer over my window using  
NSView's addSubview method. This works fine, but I want to make it so  
that all clicks are captured by the NSView, because right now I can  
click through to the superview underneath. I've already tried  
returning NO for acceptsFirstMouse and it has no effect.


Thanks
___

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


Re: OR compositing operation?

2009-09-27 Thread Paul M

This simplifies things a lot.
Just do an animated mix (crossfade) of the 2 text layers, including the
alpha channels, then simply composite the result over your background.
I'm not sure exactly which blend mode you'd use, but it will be a simple
alpha composite/blend/mix.


paulm


On 28/09/2009, at 3:02 AM, Oleg Krupnov wrote:


With a second thought, I think it would do perfectly with simply
averaging ALL channels, R, G, B, and A, for this cross-fade effect.

So I am reformulating my questions as follows: How do I produce the
blending mode when the foreground and background colors are averaged
channel-wise, for all channels, including the alpha channel?

Thanks

On Sun, Sep 27, 2009 at 4:25 PM, Oleg Krupnov oleg.krup...@gmail.com 
wrote:

Paul, thanks for such an exhaustive answer!

Here are answers to your questions:
1. My case is the simple one -- I'm rendering all text layers at once.
2. Yes and no. As I said, I am implementing the cross-fade effect,
when one text fades out and another text fades in. The texts can be of
the same color (simplest case) or of different color (different shades
of gray), and their alphas change during the fading animation. The
problem is that the semi-transparent areas of text, when overlapping,
produce brighter pixels, the annoying flash effect, I'm trying to
get rid of.

My further research shows that kCGBlendModeLighten does not seem to
apply to the alpha channel. Namely, colors are indeed composited using
the lighten rule, but then the resulting color is alpha blended with
the background as usual, so that two overlapping semitransparent
pixels still produce a more opaque pixel, which is undesirable

Am I missing the clue how to make kCGBlendModeLighten apply to the
alpha channel as well?

I have come to the following workaround: I fill the text layers with
opaque black background. In this case the kCGBlendModeLighten works
perfectly, as expected.

Unfortunately, I am not fully satisfied with this solution, because I
need the background of the text layers to be half-transparent as well.
This returns me to the question of how to make kCGBlendModeLighten to
the alpha channel.

You said I could average the color components but max the alphas.
How can I do this? Thanks!


On Sun, Sep 27, 2009 at 3:45 AM, Paul M l...@no-tek.com wrote:

This is a multi-pass operation - you wont find a single
blend mode that will do this in any simple manner.

First question: Are you doing this all in one hit, or sequentially,
ie, rendering the first layer of text then adding subsequent
layers later?
Second question: is the text all the same colour and have the
same alpha component?

If you're rendering all the text layers at once, you need to first
combine the text layers, then composite over the background. In the
simple case you describe, I imagine you'll need to average the colour
components but max the alphas. This should give you the results you
asked for.

If you need to comosite different layers at different times, it
becomes a lot more complex.
If your text is not all the same colour then you need access to all
the previous layers so that they may be combined as above and the
composite redone.
If your text is all the same colour then you can write the alpha from
the first layer into the composite so that this may be extracted and
used later in the 2nd and subsequent composites. The process for
these later composites gets pretty gnarley, and you're really better
of keeping a reference to the preceeding layers if that's at all
possible.


paulm


On 27/09/2009, at 12:17 AM, Oleg Krupnov wrote:


Thanks!

It seemed exactly what I need but I've found that it doesn't work as
expected. The interpolated semi-transparent parts of the rendered 
text

still appears brighter than it should.

Namely, consider drawing white text on black background, and then
drawing the same white text one more time over the first one.

Suppose that when a letter is rasterized, one of the resulting
interpolated pixels is semitransparent white, with alpha = 50%. 
After
alpha blending with the black background, the pixel becomes a 50% 
gray

pixel.

Now when the second text is drawn on top, there will be also the 
same

semitransparent white pixel with alpha = 50% at the same location.
What result I'd like to achieve would be to have the same 50% gray
pixel at this location. However, with kCGBlendModeLighten mode, 
what I

think what's happening is that the system picks pure white as the
lighter of two colors: 50% gray of the background and pure white
(without taking into account the alpha of the new pixel), and then
applies the usual alpha blending rule, which results in 75% gray.

Is there a workaround? Or am I doing something wrong? Thanks!

On Tue, Sep 22, 2009 at 7:23 PM, David Duncan 
david.dun...@apple.com

wrote:


On Sep 22, 2009, at 6:22 AM, Oleg Krupnov wrote:


Hi,

I'd like to draw in a graphics context in such a compositing mode:

R = MAX(S, D)

i.e. out of two colors (source and destination), the 

Re: NSView clicking through to superview

2009-09-27 Thread Ron Fleckner


On 28/09/2009, at 12:36 PM, PCWiz wrote:


Hi,

I have a transparent black NSView that I layer over my window using  
NSView's addSubview method. This works fine, but I want to make it  
so that all clicks are captured by the NSView, because right now I  
can click through to the superview underneath. I've already tried  
returning NO for acceptsFirstMouse and it has no effect.


Thanks



Not sure if this will help, but NSWindow has a -setIgnoresMouseEvents:  
method which, if you give it NO as the parameter, will allow  
transparent areas of the window to get mouse downs.  What I'm not sure  
about is if this will allow your transparent subview to get those  
clicks.


If this doesn't work, you could put your transparent view into a child  
window of the first window.


HTH,
Ron
___

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


Can an app query the values in its own Info.plist?

2009-09-27 Thread Hippo Man
Is there a way for me to put my own, custom key into a Cocoa
application's Info.plist and have the application query that key's
setting?

I know that I can use the dictionaryWithContentsOfFile: method of an
NSDictionary to read an arbitrary, dictionary-like property list,
given its pathname. However, I'm wondering if there's a way to
automatically get one or more settings in the current Cocoa
application's Info.plist without knowing anything about its pathname.
In other words, I want to query settings from my Info.plist.

Is this possible? If so, could someone point me to some docs which
describe how to do this?

Thanks in advance.

-- 
 HippoMan apple.hippo...@gmail.com
___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kyle Sluder
On Sun, Sep 27, 2009 at 8:33 PM, Hippo Man apple.hippo...@gmail.com wrote:
 Is there a way for me to put my own, custom key into a Cocoa
 application's Info.plist and have the application query that key's
 setting?

Yes, using -[NSBundle infoDictionary].  And of course you can get the
app's bundle by using +[NSBundle mainBundle].
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/doc/uid/2214-BCICBHBA

--Kyle Sluder
___

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


NSBitmapImageRep caching behavior in Snow Leopard

2009-09-27 Thread John Horigan
I have a drawing program that creates an NSBitmapImageRep and an  
NSImage:


mImage = [[NSImage alloc] initWithSize: size];
mBitmap = [[NSBitmapImageRep alloc]
  initWithBitmapDataPlanes: NULL
  pixelsWide: (int)size.width
  pixelsHigh: (int)size.height
  bitsPerSample: 8 samplesPerPixel: 4
  hasAlpha: YES isPlanar: NO
  colorSpaceName: NSCalibratedRGBColorSpace
  bytesPerRow: 0 bitsPerPixel: 0];
[mImage addRepresentation: mBitmap];

later I get the pointer to the bitmap data using the bitmapData method  
and hand it over drawing code (AGG) running in another thread.  
Periodically the render thread will send a message to the main thread  
telling it to draw the current image state to my view:


[mView performSelectorOnMainThread: @selector(redisplayImage:)
withObject: [NSValue valueWithRect:
NSMakeRect(cropX(), cropY(), cropWidth(), cropHeight())]
waitUntilDone: YES];


The redisplayImage method in my view class calls the display method

- (void)redisplayImage:(NSValue*)rectObj
{
mRenderedRect = [rectObj rectValue];
[self display];
}

Note that the render thread is waiting for redisplayImage to complete  
and the redisplayImage method is calling the display method, not the  
setNeedsDisplay method. The views's drawRect method looks like so:


- (void)drawRect:(NSRect)rect
{
NSSize fSize = [self frame].size;
NSSize rSize = [mBitmap size];

float scale;
if (rSize.width = fSize.widthrSize.height = fSize.height) {
// rendered area fits within frame, center it
scale = 1.0f;
}
else {
float wScale = fSize.width / rSize.width;
float hScale = fSize.height / rSize.height;
scale = (hScale  wScale) ? hScale : wScale;
}

NSRect dRect;

// center scaled image rectangle
dRect.size.width = rSize.width * scale;
dRect.size.height = rSize.height * scale;
dRect.origin.x = floorf((fSize.width - dRect.size.width) / 2.0f);
dRect.origin.y = floorf((fSize.height - dRect.size.height) / 2.0f);

[[NSColor colorWithDeviceRed: backgroundColor.r
  green: backgroundColor.g
  blue: backgroundColor.b
  alpha: backgroundColor.a ] set];
[NSBezierPath fillRect: rect];

[mImage drawInRect: dRect fromRect: NSZeroRect
 operation: NSCompositeSourceAtop
 fraction: 1.0];
}

Prior to Snow Leopard this all worked fine. The images drawn onto the  
bitmap in the rendering thread would be drawn into the view. If the  
view was resized smaller then the NSImage would be shrunk and  
centered. If the view was resized larger the NSImage would be centered.


But with Snow Leopard [mImage drawInRect ...] draws from the bitmap  
only the first time it is called. All subsequent calls to the  
drawInRect method draw whatever was in the bitmap on the first call,  
not the current contents of the bitmap. It's as if the  
NSBitmapImageRep was being cached on the first draw and the cached  
copy was used from then on.


However, if I resize the window so that the drawing NSRect is smaller  
than the NSBitmapImageRep (i.e., the bitmap has to be scaled) then the  
current bitmap is drawn. And then if I expand the window to be larger  
then it goes back drawing the cached bitmap. Shrinking the window  
really small seems to reset something in the NSBitmapImageRep, then it  
draws from the current bitmap whether there is scaling or not.


It seems that under Snow Leopard the NSBitmapImageRep is being cached  
somewhere (video memory?) and as long as there is no scaling the  
cached version of the NSBitmapImageRep is being used by drawInRect  
instead of of the bitmap in system memory. For some reason making the  
view really small causes drawInRect to use the data in system memory.


Here are some things that I tried:
1) Calling the NSImage recache method: [mImage recache];
2) Getting rid of the NSImage and using the NSImageRep drawInRect  
method to draw in the view.
3)  Call the NSBitmapImageRep bitmapData method before writing to the  
bitmap data plane in the rendering thread


#1 and #2 has no effect. NSImage-level caching does not appear to be  
the problem. There appears to be caching by NSBitmapImageRep. #3 was  
an attempt to get Snow Leopard to invalidate the NSBitmapImageRep  
cache. It didn't work.


So this is what worked:
4) Keep the bitmap data plane as a separate data structure, owned by  
the view. The redisplayImage method creates a new NSBitmapImageRep and  
NSImage every time it is called, using the bitmap data structure that  
is owned by the view.


While creating new NSImages and 

Unable to Compile Simple Application (Errors)

2009-09-27 Thread Mick Walker

Hi,

I am currently working my way through Learn Objective C on the Mac,  
and have typed one of the code samples into Xcode (ver 3.2), however  
Xcode gives me a compile error, I think I have typed the code letter  
for letter, so I was just wondering if someone could tell me why the  
following code will not compile?


#import Foundation/Foundation.h

typedef enum {
kCircle,
kRectange,
kOblateSpheroid
} ShapeType;

typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;

typedef struct {
int x, y, width, height;
} ShapeRect;

typedef struct{
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
} Shape;


int main (int argc, const char * argv[]) {

Shape shapes[3];
ShapeRect rect0 = {0, 0, 10, 30};
shapes[0].type = kCircle;
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;

ShapeRect rect1 = {30, 40, 50, 60};
shapes[1].type = kRectange;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;

ShapeRect rect2 = {15, 18, 37, 29};
shapes[2].type = kOblateSpheroid;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;


drawShapes(shapes, 3);

return(0);

}// main

void drawShapes(Shape shapes[], int count){
int i;
for(i = 0; i count; i++){
switch(shapes[i].type){
case kCircle:
drawCircle(shapes[i].bounds, 
shapes[i].fillColor);
break;
case kRectange:
drawRectangle(shapes[i].bounds, 
shapes[i].fillColor);
break;
case kOblateSpheroid:
drawEgg(shapes[i].bounds, shapes[i].fillColor);
break;
}
}
} // drawShapes

void drawCircle (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a circle at (%d %d %d %d) int %@, bounds.x,  
bounds.y, bounds.width, bounds.height, colorName(fillColor));

} // drawCircle
void drawRectangle (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a rectangle at (%d %d %d %d) int %@, bounds.x,  
bounds.y, bounds.width, bounds.height, colorName(fillColor));

} // drawRectangle
void drawEgg (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a egg at (%d %d %d %d) int %@, bounds.x, bounds.y,  
bounds.width, bounds.height, colorName(fillColor));

} // drawEgg

NSString* colorName(ShapeColor colName){
switch (colName) {
case kRedColor:
return @red;
break;
case kGreenColor:
return @green;
break;
case kBlueColor:
return @blue;
break;
}
return @No clue;
}// colorName

The error i get is:
Conflicting types for 'colorName'

Kind Regards
Mick Walker

___

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


Re: Creating a radar sweep effect

2009-09-27 Thread Jon Gilkison
You can do this with a single accumulating bitmap.
1. Create a bitmap the size of your view filled with the background color
2. Fill the bitmap with the background color using an alpha = 1 / number of
steps
3. Draw the radar onto the bitmap
4. Draw the bitmap in the view
5. Go to step 2

(I have done this exact thing on Win32, but not Cocoa so buyer beware).
___

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


Formatter and error windows (sheet AND modal)

2009-09-27 Thread Alex
Hi,

I'm currently working on a projet and I would like to have a custom
formatter. So, I write it and it's work fine. But when I type a string not
well-formed, my application display two error windows: one sheet and one
modal. I try to figure out why but without success. Someone have an idea ?

Alex
___

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


Master addChildObject: not called when adding child from an array controller !

2009-09-27 Thread Eric Morand

Hi guys,

I'm trying to implement a rather simple functionality in my app.

I have a Core Data entity class that represents invoices (Invoice).  
This class has a to-many relationship with another Core Data entity  
class that represents invoice lines (InvoiceLine). My Invoice class  
also has a property named totalAmount and my InvoiceLine class has a  
property named lineAmount. I want the total amount  of the invoice  
to be re-computed when any of the invoice lines amount changes.


Searching this list, I found that I need to add the invoice instance  
as an observer to the lineAmount property of any invoice line added  
with the addInvoiceLineObject: method. It works.
But only when I explicitly use this method. When the invoice line is  
added using an array controller, the method is not called at all !!!


For example, I have an array controller named invoicesController  
that lists all the invoices of the database. Then I have an array  
controller named invoiceLinesController whose content is bound to  
invoicesController.selection.invoiceLines. It works :  
invoiceLinesController actually contains the invoice inlines of the  
selected invoice in invoicesController.


Now, when I add a saleLine using the following command...

	InvoiceLine * myNewInvoiceLine = [NSEntityDescription  
insertNewObjectForEntityForName:@InvoiceLine  
inManagedObjectContext:managedObjectContext];

[invoiceLinesController addObject:myNewInvoiceLine];

...the addInvoiceLineObject: method of the selected invoice is not  
called, even if the invoice line is actually added to the invoiceLines  
mutable set of the invoice !


How am I supposed to add the invoice as an observer of the added  
invoice line (myNewInvoiceLine) properties ?
Wy is the addInvoiceLineobject: method not called ? Is the array  
controller inserting the invoice line using primitive methods ? Is  
this the normal behavior ?



Thanks for your help,


Eric Morand.
___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kiel Gillard
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/infoDictionary 



Generally one does not put custom keys in the Info.plist. You might  
want to consider a separate plist resource for your target and use  
NSBundle's pathForResource:ofType: method to query the dictionary at  
the resulting path. For more information see: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/pathForResource:ofType: 



Kiel

On 28/09/2009, at 1:33 PM, Hippo Man wrote:


Is there a way for me to put my own, custom key into a Cocoa
application's Info.plist and have the application query that key's
setting?

I know that I can use the dictionaryWithContentsOfFile: method of an
NSDictionary to read an arbitrary, dictionary-like property list,
given its pathname. However, I'm wondering if there's a way to
automatically get one or more settings in the current Cocoa
application's Info.plist without knowing anything about its pathname.
In other words, I want to query settings from my Info.plist.

Is this possible? If so, could someone point me to some docs which
describe how to do this?

Thanks in advance.

--
HippoMan apple.hippo...@gmail.com
___

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/kiel.gillard%40gmail.com

This email sent to kiel.gill...@gmail.com


___

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


how do i make SecKeyRef object from NSData of publicKey value

2009-09-27 Thread bosco fdo
Hi

I need to do RSA encryption for that i need to have SecKeyRef object
for the public Key i have. Do i still need to add to the Keychain and
get from the Keychain as a SecKeyRef ?

Is there any way i can convert my publicKey value from NSData bytes to
SecKeyref ?

Please help with sample code

Thanks
Bose
___

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


Re: Master addChildObject: not called when adding child from an array controller !

2009-09-27 Thread Kyle Sluder
You named the method -addInvoiceLineObject:, but the property is
-invoiceLines?  That's not going to work.

Also, NSController is sadly not KVO-compliant for dependent keys,
meaning that you can't override
+keyPathsForValuesAffectingValueForKey: and return a key path that
goes through an NSController.

--Kyle Sluder

On 9/27/09, Eric Morand eric.mor...@me.com wrote:
 Hi guys,

 I'm trying to implement a rather simple functionality in my app.

 I have a Core Data entity class that represents invoices (Invoice).
 This class has a to-many relationship with another Core Data entity
 class that represents invoice lines (InvoiceLine). My Invoice class
 also has a property named totalAmount and my InvoiceLine class has a
 property named lineAmount. I want the total amount  of the invoice
 to be re-computed when any of the invoice lines amount changes.

 Searching this list, I found that I need to add the invoice instance
 as an observer to the lineAmount property of any invoice line added
 with the addInvoiceLineObject: method. It works.
 But only when I explicitly use this method. When the invoice line is
 added using an array controller, the method is not called at all !!!

 For example, I have an array controller named invoicesController
 that lists all the invoices of the database. Then I have an array
 controller named invoiceLinesController whose content is bound to
 invoicesController.selection.invoiceLines. It works :
 invoiceLinesController actually contains the invoice inlines of the
 selected invoice in invoicesController.

 Now, when I add a saleLine using the following command...

   InvoiceLine * myNewInvoiceLine = [NSEntityDescription
 insertNewObjectForEntityForName:@InvoiceLine
 inManagedObjectContext:managedObjectContext];
   [invoiceLinesController addObject:myNewInvoiceLine];

 ...the addInvoiceLineObject: method of the selected invoice is not
 called, even if the invoice line is actually added to the invoiceLines
 mutable set of the invoice !

 How am I supposed to add the invoice as an observer of the added
 invoice line (myNewInvoiceLine) properties ?
 Wy is the addInvoiceLineobject: method not called ? Is the array
 controller inserting the invoice line using primitive methods ? Is
 this the normal behavior ?


 Thanks for your help,


 Eric Morand.
 ___

 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/kyle.sluder%40gmail.com

 This email sent to kyle.slu...@gmail.com



-- 
--Kyle Sluder
___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kyle Sluder
On Sun, Sep 27, 2009 at 8:47 PM, Kiel Gillard kiel.gill...@gmail.com wrote:
 Generally one does not put custom keys in the Info.plist. You might want to
 consider a separate plist resource for your target and use NSBundle's
 pathForResource:ofType: method to query the dictionary at the resulting
 path. For more information see:

Come again?  Info.plist is a perfectly fine place to put this
information, and very many apps put custom information there.  That's
where Sparkle expects its configuration information.

--Kyle Sluder
___

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


Re: how do i make SecKeyRef object from NSData of publicKey value

2009-09-27 Thread Kyle Sluder
This is not a Cocoa question.  Try re-reading the documentation and
asking a more appropriate list.

--Kyle Sluder
___

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


Re: Unable to Compile Simple Application (Errors)

2009-09-27 Thread Graham Cox

Hi Mick,

The problem is that none of the functions here have prototypes, so the  
use of 'colorName' comes before the definition of the function  
'colorName', which then has not matched the compiler's assumptions.  
Also, as given, the code spits out many warning about missing  
prototypes, which are the cause of the problem. Don't ignore warnings.


I'm not sure what Learning Objective C on the Mac is (a book?) if  
so, this code contains no Objective-C at all, is not object-oriented  
and apart from using a Cocoa class (NSString) in a not very clever or  
useful way, serves no real purpose as far as learning Objective-C is  
concerned (that I can see anyway). Perhaps it's given as a counter- 
example - how coding was done before Objective-C? Otherwise this looks  
like a text I'd steer clear of, especially if its code examples  
continue to be as sloppy as this one.


--Graham




On 27/09/2009, at 5:41 AM, Mick Walker wrote:


Hi,

I am currently working my way through Learn Objective C on the Mac,  
and have typed one of the code samples into Xcode (ver 3.2), however  
Xcode gives me a compile error, I think I have typed the code letter  
for letter, so I was just wondering if someone could tell me why the  
following code will not compile?


#import Foundation/Foundation.h

typedef enum {
kCircle,
kRectange,
kOblateSpheroid
} ShapeType;

typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;

typedef struct {
int x, y, width, height;
} ShapeRect;

typedef struct{
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
} Shape;


int main (int argc, const char * argv[]) {

   Shape shapes[3];
ShapeRect rect0 = {0, 0, 10, 30};
shapes[0].type = kCircle;
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;

ShapeRect rect1 = {30, 40, 50, 60};
shapes[1].type = kRectange;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;

ShapeRect rect2 = {15, 18, 37, 29};
shapes[2].type = kOblateSpheroid;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;


drawShapes(shapes, 3);

return(0);

}// main

void drawShapes(Shape shapes[], int count){
int i;
for(i = 0; i count; i++){
switch(shapes[i].type){
case kCircle:
drawCircle(shapes[i].bounds, 
shapes[i].fillColor);
break;
case kRectange:
drawRectangle(shapes[i].bounds, 
shapes[i].fillColor);
break;
case kOblateSpheroid:
drawEgg(shapes[i].bounds, shapes[i].fillColor);
break;
}
}
} // drawShapes

void drawCircle (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a circle at (%d %d %d %d) int %@, bounds.x,  
bounds.y, bounds.width, bounds.height, colorName(fillColor));

} // drawCircle
void drawRectangle (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a rectangle at (%d %d %d %d) int %@, bounds.x,  
bounds.y, bounds.width, bounds.height, colorName(fillColor));

} // drawRectangle
void drawEgg (ShapeRect bounds, ShapeColor fillColor){
	NSLog(@drawing a egg at (%d %d %d %d) int %@, bounds.x, bounds.y,  
bounds.width, bounds.height, colorName(fillColor));

} // drawEgg

NSString* colorName(ShapeColor colName){
switch (colName) {
case kRedColor:
return @red;
break;
case kGreenColor:
return @green;
break;
case kBlueColor:
return @blue;
break;
}
return @No clue;
}// colorName

The error i get is:
Conflicting types for 'colorName'

Kind Regards
Mick Walker


___

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


Re: Unable to Compile Simple Application (Errors)

2009-09-27 Thread Kyle Sluder
There should be more than just that one line.

C requires that functions be declared before they are used; if they
are not, it assumes they take any number of parameters and return an
int.  At the points at which you call colorName, the compiler hasn't
seen a declaration for colorName yet, but can infer that it is a
function from the way you're using it.  So it assumes it's int
colorName() and continues on its merry way.  Then when it sees your
definition of colorName later on, it complains because the definition
NSString *colorName(ShapeColor) does not match the assumed int
colorName().

You have two options:

1. Provide a prototype of colorName somewhere before it is used.
Typically this is done in a header (.h) file which is #imported by the
source (.m) file.
2. Move the definition of colorName before it is used.

I also suggest you consult your favorite C language book for more.  I
have always been partial to KR.

--Kyle Sluder
___

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


Re: NSBitmapImageRep caching behavior in Snow Leopard

2009-09-27 Thread Kyle Sluder
Overall your approach seems backwards.  Why is your render thread
telling your view when to draw itself?  The view should be in control
of when it is drawn.  This fits in with your scenario, which appears
to be a clear-cut example of the producer-consumer model.

--Kyle Sluder
___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Graham Cox


On 28/09/2009, at 1:47 PM, Kiel Gillard wrote:


Generally one does not put custom keys in the Info.plist.



Why not? As long as you're careful to ensure no conflict now or in the  
future with Apple's defined keys, you'll be fine (so ensure you use a  
key that couldn't possibly be used by Apple, such as prefixed with  
your name, etc - same as for any Objective-C class you create yourself  
in other words). I've seen plenty of third party code add keys to  
Info.plist, e.g. Sparkle.


--Graham


___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kiel Gillard


On 28/09/2009, at 2:23 PM, Graham Cox wrote:



On 28/09/2009, at 1:47 PM, Kiel Gillard wrote:


Generally one does not put custom keys in the Info.plist.



Why not? As long as you're careful to ensure no conflict now or in  
the future with Apple's defined keys, you'll be fine (so ensure you  
use a key that couldn't possibly be used by Apple, such as prefixed  
with your name, etc - same as for any Objective-C class you create  
yourself in other words). I've seen plenty of third party code add  
keys to Info.plist, e.g. Sparkle.


--Graham


Duh. Not sure what I was thinking. Sorry, Hippo Man. Thanks for the  
heads up, Graham and Kyle.


Kiel
___

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


Re: NSBitmapImageRep caching behavior in Snow Leopard

2009-09-27 Thread John Horigan
It is a digital art program where the user writes a description of an  
image and the program creates it. Image creation can be a lengthy  
process so I have the rendering thread periodically send a snapshot of  
what it has done so far to the view. This is purely to entertain the  
user while they wait for their image to finish.


What really happens is that the main thread has an NSTimer that tells  
it when to request an new snapshot. When this timer event fires the  
main thread sets a flag. The render thread checks this flag when it is  
at a good stopping point. When the render thread sees that the flag is  
set it send a message back to the main thread and waits for the  
message to complete. So the view is in control, it just needs to  
quiesce the rendering thread before it takes the snapshot.


-- john

On Sep 27, 2009, at 9:18 PM, Kyle Sluder wrote:


Overall your approach seems backwards.  Why is your render thread
telling your view when to draw itself?  The view should be in control
of when it is drawn.  This fits in with your scenario, which appears
to be a clear-cut example of the producer-consumer model.

--Kyle Sluder


___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Scott Anguish

Better question...

Why do it? It's easy enough to add your own.

I don't see what the issue is with just adding another. not like  
they're hard to read and get access to the data.

On Sep 28, 2009, at 12:23 AM, Graham Cox wrote:



On 28/09/2009, at 1:47 PM, Kiel Gillard wrote:


Generally one does not put custom keys in the Info.plist.



Why not? As long as you're careful to ensure no conflict now or in  
the future with Apple's defined keys, you'll be fine (so ensure you  
use a key that couldn't possibly be used by Apple, such as prefixed  
with your name, etc - same as for any Objective-C class you create  
yourself in other words). I've seen plenty of third party code add  
keys to Info.plist, e.g. Sparkle.




___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Hippo Man
 Duh. Not sure what I was thinking. Sorry, Hippo Man. Thanks for the
 heads up, Graham and Kyle.
 
 Kiel

Well, many thanks and much appreciation to all of you.

This is exactly the information I was looking for, and it's good to know
that there's a consensus that I _can_ put app-specific info into the
Info.plist.


-- 
 Hippo Man
 apple.hippo...@gmail.com

|.-, 0__0
|   /   (  oo'---,
|  /oo\
| ,\  |
| | \,=__/
|\  /
|/  /--|  /|
||__|-'|__|'
___

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


Re: NSBitmapImageRep caching behavior in Snow Leopard

2009-09-27 Thread Scott Anguish
I strongly suggest reading the release notes on NSImage in the  
Application Kit release notes for Snow Leopard.


it has many, many, changes. These won't translate to the Cocoa Drawing  
Guide for a bit yet. Sadly.



On Sep 25, 2009, at 7:22 PM, John Horigan wrote:

I have a drawing program that creates an NSBitmapImageRep and an  
NSImage:


mImage = [[NSImage alloc] initWithSize: size];
mBitmap = [[NSBitmapImageRep alloc]
  initWithBitmapDataPlanes: NULL
 pixelsWide: (int)size.width
 pixelsHigh: (int)size.height
 bitsPerSample: 8 samplesPerPixel: 4
 hasAlpha: YES isPlanar: NO
 colorSpaceName: NSCalibratedRGBColorSpace
 bytesPerRow: 0 bitsPerPixel: 0];
[mImage addRepresentation: mBitmap];

later I get the pointer to the bitmap data using the bitmapData  
method and hand it over drawing code (AGG) running in another  
thread. Periodically the render thread will send a message to the  
main thread telling it to draw the current image state to my view:


   [mView performSelectorOnMainThread: @selector(redisplayImage:)
   withObject: [NSValue valueWithRect:
   NSMakeRect(cropX(), cropY(), cropWidth(), cropHeight())]
   waitUntilDone: YES];


The redisplayImage method in my view class calls the display method

- (void)redisplayImage:(NSValue*)rectObj
{
   mRenderedRect = [rectObj rectValue];
   [self display];
}

Note that the render thread is waiting for redisplayImage to  
complete and the redisplayImage method is calling the display  
method, not the setNeedsDisplay method. The views's drawRect method  
looks like so:


- (void)drawRect:(NSRect)rect
{
NSSize fSize = [self frame].size;
NSSize rSize = [mBitmap size];

float scale;
if (rSize.width = fSize.widthrSize.height = fSize.height) {
// rendered area fits within frame, center it
scale = 1.0f;
}
else {
float wScale = fSize.width / rSize.width;
float hScale = fSize.height / rSize.height;
scale = (hScale  wScale) ? hScale : wScale;
}

NSRect dRect;

// center scaled image rectangle
dRect.size.width = rSize.width * scale;
dRect.size.height = rSize.height * scale;
dRect.origin.x = floorf((fSize.width - dRect.size.width) / 2.0f);
dRect.origin.y = floorf((fSize.height - dRect.size.height) / 2.0f);

   [[NSColor colorWithDeviceRed: backgroundColor.r
 green: backgroundColor.g
 blue: backgroundColor.b
 alpha: backgroundColor.a ] set];
   [NSBezierPath fillRect: rect];

   [mImage drawInRect: dRect fromRect: NSZeroRect
operation: NSCompositeSourceAtop
fraction: 1.0];
}

Prior to Snow Leopard this all worked fine. The images drawn onto  
the bitmap in the rendering thread would be drawn into the view. If  
the view was resized smaller then the NSImage would be shrunk and  
centered. If the view was resized larger the NSImage would be  
centered.


But with Snow Leopard [mImage drawInRect ...] draws from the bitmap  
only the first time it is called. All subsequent calls to the  
drawInRect method draw whatever was in the bitmap on the first call,  
not the current contents of the bitmap. It's as if the  
NSBitmapImageRep was being cached on the first draw and the cached  
copy was used from then on.


However, if I resize the window so that the drawing NSRect is  
smaller than the NSBitmapImageRep (i.e., the bitmap has to be  
scaled) then the current bitmap is drawn. And then if I expand the  
window to be larger then it goes back drawing the cached bitmap.  
Shrinking the window really small seems to reset something in the  
NSBitmapImageRep, then it draws from the current bitmap whether  
there is scaling or not.


It seems that under Snow Leopard the NSBitmapImageRep is being  
cached somewhere (video memory?) and as long as there is no scaling  
the cached version of the NSBitmapImageRep is being used by  
drawInRect instead of of the bitmap in system memory. For some  
reason making the view really small causes drawInRect to use the  
data in system memory.


Here are some things that I tried:
1) Calling the NSImage recache method: [mImage recache];
2) Getting rid of the NSImage and using the NSImageRep drawInRect  
method to draw in the view.
3)  Call the NSBitmapImageRep bitmapData method before writing to  
the bitmap data plane in the rendering thread


#1 and #2 has no effect. NSImage-level caching does not appear to be  
the problem. There appears to be caching by NSBitmapImageRep. #3 was  
an attempt to get Snow Leopard to invalidate the NSBitmapImageRep  
cache. It didn't work.


So this is what worked:
4) Keep the bitmap data 

Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kyle Sluder
On Sun, Sep 27, 2009 at 10:02 PM, Scott Anguish sc...@cocoadoc.com wrote:
 Why do it? It's easy enough to add your own.

It's also easy to add them to Info.plist… it seems like an appropriate
place to do so.

Perhaps Apple should clarify whether adding custom keys to Info.plist
is condoned.

--Kyle Sluder
___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Scott Anguish


On Sep 28, 2009, at 1:16 AM, Kyle Sluder wrote:

On Sun, Sep 27, 2009 at 10:02 PM, Scott Anguish sc...@cocoadoc.com  
wrote:

Why do it? It's easy enough to add your own.


It's also easy to add them to Info.plist… it seems like an appropriate
place to do so.

Perhaps Apple should clarify whether adding custom keys to Info.plist
is condoned.


Perhaps. I honestly don't think we have a best-practices position on  
this.


I guess I'll point you to bugreporter.apple.com, you being a good  
citizen and all. :-)



___

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


Re: Can an app query the values in its own Info.plist?

2009-09-27 Thread Kyle Sluder
Done.  rdar://problem://7257097

Also notes that the same collision issue exists for user defaults,
where AppKit stores window and splitter autosave information.

--Kyle Sluder
___

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


Re: Core Animation and Run Loops

2009-09-27 Thread Oleg Krupnov
Thanks! You are right, I have tested it on Snow Leopard, and the CA
animation runs simultaneously with the blocking NSAnimation, as
claimed in the Wikipedia. What a revelation! I'd say, what an ANNOYING
revelation! It means that this ability of CA animation of running in a
separate thread is rendered useless by this bug. I cannot rely on this
ability until a sufficient number of users upgrades to Snow Leopard,
and the long tail of this process will never end, so it's practically
never.

Or is there a workaround, beside using non-blocking animation, which
is often too tedious and sometimes not smooth enough?

On Sun, Sep 27, 2009 at 8:56 PM, Shlok Datye li...@codingturtle.com wrote:
 Take a look at this movie, which was taken on Leopard:
 http://shlok.s3.amazonaws.com/20090927-ca-problem.mov
 The blue rectangle is a layer-backed NSView that is animated using Core
 Animation. The problem is that the animation halts while the main loop waits
 for the mouse to get released.
 For your information, this was a bug that has been fixed in Snow Leopard.
 I'm therefore curious: Have you tried running a blocking NSAnimation along
 with a CA-animation in Snow Leopard?
 Shlok Datye
 Coding Turtle
 http://codingturtle.com

 Hi,

 Today I read this in wikipedia:
 (http://en.wikipedia.org/wiki/Core_Animation)

 Animated sequences execute in a thread independent from the main run
 loop, allowing application processing to occur while the animation is
 in progress.

 However, in my experience, Core Animation animations do not run while
 the main thread is blocked. For example, when the main thread is
 running a usual blocking NSAnimation, the CA-animation is frozen and
 resumed only when the NSAnimation ends.

 Could someone clarify on this, please?



___

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