Pixel perfect drawing on magnified view
Hi, I have an NSScrollView and use the magnification property to zoom into my view. It's all layer backed and I'm redrawing on setNeedsDisplay: I think that it draws in to the layer at 100% scale and then applies a transform to the layer, which leaves it looking blurry at large scale values etc. I would like to be able to use the smooth magnification and then trigger a redraw which draws pixel perfect for the new scale factor when the magnification ends. Is this possible in the current scenario? Or will I need to take the magnification factor from the scroll view and resize the view to the new number of pixels (old size * magnification) and reset the magnification on the scroll view to 1.0? Or is there some other way of handling this? Thanks Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Converting views to use layer backing
Thanks Gideon. Turning on the layer backing for all those levels did fix the redrawing problem. I didn't find out how to fix the layer drawing when the bounds origin has been moved, but I did work out a workaround. I added an instance variable to my view (the scrollview's document view): @property (assign) NSPoint originOffset; I set that to the offset from the origin to where I want the bounds origin to be, then in drawRect, I do: CGContextRef currentContext = NSGraphicsContext.currentContext.graphicsPort; CGContextSaveGState(currentContext); CGContextTranslateCTM(currentContext, self.originOffset.x, self.originOffset.y); ...do all my drawing relative to where the bounds origin should be CGContextRestoreGState(currentContext); That gets my view drawing properly, but I still have the problem of positioning my subviews, so I created a view that I will never draw as follows: @implementation OffsetView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code here. self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever; } return self; } - (BOOL)isFlipped { return YES; } @end Then in my main view, I add the following: OffsetView *offsetView = [[OffsetView alloc] initWithFrame:self.bounds]; [offsetView setBoundsOrigin:NSMakePoint(-self.originOffset.x, -self.originOffset.y)]; [self addSubview:offsetView]; And now I just add my subviews to the offset view instead of the main view. This does seem like a nasty hack to get the result I want, but it works, and nobody else has suggested any alternative, so I'll just run with it. Thanks again for the help. Ken On Oct 18, 2013, at 03:20 PM, Gideon King gid...@novamind.com wrote: I knew I was going to want to do something like that myself so created a small test project. ... Can anyone else help with how to draw a layer backed view where the bounds origin has been shifted? ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Converting views to use layer backing
Hi, I have an NSScrollView with a document view which has subviews. All my views are flipped. I am using and targeting 10.8. I am not using autolayout (I tried it and got horribly confused by how it works with scrollviews, so just turned it off) I turned the magnification capabilities of the scrollview on, and I set my bounds origin to near the center of the view and added the subviews. All this works fine - the view zooms on pinch actions, the subviews resize and reposition themselves exactly as expected. I turned on layer backing for my content view, and everything stopped working. I found the following: - Setting the bounds origin caused the drawing of the document view and subviews to fail. - Even with the bounds origin set, the view still tries to display as if it is drawn with the origin at 0,0. - Resizing the window causes weird drawing glitches. - Zooming the view also causes drawing problems, but also I can see that the magnification is being ignored when drawing. - My subviews are not being resized when the magnification changes. Turning on setAutresizesSubviews:YES doesn't seem to help with this, but I may have the wrong resizing mask set. The background view seldom changes, and I want to animate zooming and panning. The subviews seldom change, but need to be animated around quite a bit. It seemed as though this would be an ideal use of layer backing and only refreshing the layer content when I explicitly say it needs redrawing. So how do I emulate the behavior that I get with the straight NSView implementation. In particular: 1. What settings do I need to use on my scrollview's document view to get it to draw with the drawing centered on the bounds center rather than the frame, and scaled according to the scrollview's magnification? 2. Do I just need the document view itself to be layer backed for this, or do I need the clip view and/or the scroll view to be layer backed too? 3. How do I get the subviews positioned relative to the bounds origin when using layer backed views? 4. How do I get the subviews to resize/reposition themselves when the magnification changes, as happened automatically when it was just NSViews? Thanks Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Getting the best frame rate for NSView drawing
I am trying out some different ideas for animating portions of a view, but am having problems with performance. Essentially I have an animation running using a CABasicAnimation, and when it calls back to my view, it invalidates the rect where the object was drawn, and the new place where it is going to be drawn. Then in my drawRect code, I ask each of my objects that overlap the dirty rect to redraw itself. For testing purposes, I have a view that is 5,000 x 5,000 and have 100 of my objects which are placed randomly and size 200 x 400. For each object, I save the graphics state, transform my coordinates, clip to the bounds of the object, draw it, and then restore the graphics state. At the moment, on my test machine (which is admittedly not the latest and greatest, but it probably representative of our typical customer), I have tried the following scenarios: Draw each object individually (admittedly it's just a simple oval in rect which is filled and stroked): 12fps Generate an NSImage of the object once and cache it, then just drawInRect...: 8fps Cache a CIImage and draw that: 8fps Cache a CGLayer and draw that: 8fps This sure does seem to be awfully slow. Instruments tell that the time is all being spent in drawing the object, no matter how I do the drawing. Is there some better way to get decent drawing performance from drawing into an NSView? Thanks Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Example implementation of NSAnimatablePropertyContainer?
I tried this, and it worked fine on 10.7, however I have a couple of things I am animating - an opacity float value, and an NSRect. Both animate fine on 10.7, but on 10.6, the NSRect (or CGRect - I've tried both) doen't get animated - it just goes to its final value. I have looked through the release notes, but didn't see any mention of a change like this in 10.7. I'd rather not have to hook into an animated progress value and do my own interpolation of the intermediate values for the rect if I don't have to. Was this a known issue in 10.6? Is there a workaround? Thanks Ken On Mar 28, 2012, at 08:35 AM, Gideon King gid...@novamind.com wrote: I'd be interested in this too. In the past, I have created a subclass of NSView and just used the animation capabilities without ever inserting it in a view hierarchy, and that worked, but that was just a quick and dirty hack project - I'd like to know how to do it properly… Regards Gideon On 28/03/2012, at 12:34 AM, Kenneth Baxter wrote: I have some objects that I want to use implicit animations for, but they are not views. I understand that I should be able to implement the NSAnimatablePropertyContainer protocol and it should just work from there. Unfortunately the documentation seems pretty light on how to implement the protocol yourself, what the animator should return, etc. I have not been able to find any example code to show how you would do this. Is there an example around somewhere? Thanks Ken ___ ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Getting the best frame rate for NSView drawing
Thanks for taking the time to put together these replies Graham and Uli. Yes, I know it's a heavy load in my test case, but it is something that could happen from time to time in the real application. The contents of about half the layers seldom change, so from that perspective, caching contents as either NSImages, CIImages, CGLayers or using CALayers would seem to be a good idea. The other half of the layers are simple, and just consist of some bezier curves, and change a bit more frequently. The other day I wrote asking about technology choices and outlined why layer backed views didn't seem to be an option (can't guarantee z order), and why a CALayer hosting view didn't seem to be an option (show stopper drawing bug during animation of large layers, inability to add subviews leading to problems with overlay windows, problems with CAShapeLayers etc). If I understand you correctly, you might be suggesting using CALayers purely for drawing and using my own animations for moving the layers around, and triggering layer redraws when necessary. That may avoid some of the bugs that I have run into with layer animations, but I would still have to use overlay windows instead of using subviews, and work out issues with the tiled background and zooming etc. If I could find a way to guarantee the z order of layer backed views, then I would love to go that route, but I believe that's impossible based on my own and others' findings. If I just can't get the performance I need by any means using an NSView, then it looks as if I will just have to tackle all the issues I have encountered trying to work with a layer hosting view and CALayers. From what both of you are saying, it very much sounds as if I am just not going to be able to get the performance I need for decent animations by redrawing parts of an NSView when dealing with a large number of objects, and that the only solution is going to be the user of a layer hosting view and making things work with CALayer. Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Getting the best frame rate for NSView drawing
Thanks Graham, Yes, fully aware that CGLayer and CALayer are completely different. Interesting to hear about the z position needing to be a large number - will keep that in mind. Cool visualizer. I'm going to have another go at a test project and see if I can work around the issues and do it using layer hosting. Regards Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Example implementation of NSAnimatablePropertyContainer?
I have some objects that I want to use implicit animations for, but they are not views. I understand that I should be able to implement the NSAnimatablePropertyContainer protocol and it should just work from there. Unfortunately the documentation seems pretty light on how to implement the protocol yourself, what the animator should return, etc. I have not been able to find any example code to show how you would do this. Is there an example around somewhere? Thanks Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Technology recommendations for animation/display
On Mar 24, 2012, at 06:54 PM, Evadne Wu e...@monoceroi.com wrote: Why not both. Create a common model and use Core Animation to back the on-screen view, but when you need to draw, tell the model objects to draw themselves using Quartz. -ev I am considering this approach, and also re-looking at all the core animation and ns animation options, and have a few follow up questions: 1. One of the problems with using NSViews for an application like mine where I want to display a whole lot of sibling subviews that have to be in a particular order, has been that even though you can use -addSubview:positioned:relativeTo:, that didn't actually guarantee the order that the views were drawn. Now when I am reading through the Choosing the Animation Technology for Your Application documentation, I see that it says Both layers and layer-backed views support overlapping of layers/views with other layers/views outside of the sublayer/subview. Does that mean that when you add subviews when using layer backed views, they are actually guaranteed to honor their order (i.e. addSubview will draw the new subview in front of its siblings, and addSubview:positioned:relativeTo: will actually always draw in that order, and if you ask for subviews of a view, the order of the subviews will be the order in which they are actually drawn)? If so, it appears that I may be able to use layer backed views instead of a layer hosting view, which would mean that I wouldn't have to use a separate overlay window for editing text etc, which would solve a lot of problems. I might need to do some testing with layer backed views... 2. If I use layer backed views instead of a single layer hosting view, will that mean that I will be able to print properly (e.g shadows on the views print properly)? 3. I have played around with layer hosting before, but very little with layer backed views. Using layer hosting, I would have tried to use CAShapeLayer for my connector curves (though I have had trouble with these drawing strange things in the past), but if I am using layer backed views, I would need to be able to redraw the view during the animation. How would I do this? Is there some way to tell core animation that this view needs to redraw itself during the animation? I don't see anything that calls back to the layer saying that it is at a certain animation proportion. I see there is a needsDisplayOnBoundsChange property, but in some cases the bounds don't change. Could I just add an animatable property to the view which goes from 0.0 to 1.0, and then query that to find out how far through the animation it is, and force the view to display? Are there any other gotcha's with layer backed views to achieve the things I need? Thanks Ken. On Mar 24, 2012, at 3:02 PM, Kenneth Baxter k.b.bax...@mac.com wrote: Hi, I am developing an application where I need to be able to handle the following requirements: - Deployment: MacOS X 10.6 and later. May want to develop an iPad version later. - Type of application: Display and manipulation of graphical objects on a canvas. - Number of graphical objects: up to about 2,000 - Canvas needs to display solid color, gradient, or tiled image - The entire canvas with all the graphical objects on it need to be able to smoothly zoom and pan - Many of the graphical objects need to display text on them this must be high resolution rendering to look good - The text on graphical objects needs to be editable (I'm ok with putting a view overlay over it in order to accomplish this if necessary) - The graphical objects need to be able to be displayed with shadows and reflections. - The entire canvas and all the displayed objects must be printable at high resolution (i.e. PDF). - We need to animate movement of quite a number of the objects at once. - The objects that are moving have curved connection lines drawn to other objects that stay stationary, and those curves need to animate as the connected objects move. I am looking for recommendations on the best technology to use for this. ... ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Technology recommendations for animation/display
OK, so it looks as if I have found the answer to whether I would be able to use layer backed views, and the answer is that even with layer backing turned on, you can not guarantee the drawing order of overlapping sibling views: http://stackoverflow.com/questions/466297/is-there-a-proper-way-to-handle-overlapping-nsview-siblings This is really annoying because it will require a lot of work to work around, and also since sibling view layering apparently works on IOS, it would have been nice to use that paradigm on OSX. So this means that I have to either: A) See whether having a single view and using the NS animation options and animation proxies will give me the performance and functionality I need, or B) Try to work out the issues with drawing a tiled background canvas layer seamlessly with animated scrolling, resizing and scaling; drawing high quality text; the bug with large layers causing flickering; the problems with CAShapeLayers not always animating paths correctly; smooth scaling and pixel alignment of all the sublayers; having to have completely separate overlay windows for things like text editing which need to react to scrolling and scaling and synchronize them with the main view etc. Option B sounds scary because it includes a couple of bugs that I am aware of but have don't have a workaround for, and lots of work, so even though conceptually it would be nice to use CALayer (or even better, layer backed views if there was some way to get them to order siblings properly), it seems that if the performance is acceptable, I may just have to go with option A. While core animation would be nice, and in the future, 3d transforms etc might be nice, at the moment, my objects just need scale, opacity, and position animations. I guess the next thing to do is some testing with a full screen test app with a few hundred virtual views animating around, and see what sort of performance I get... If there are any comments on these options, or suggestions for other approaches, I'm all ears... Ken ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Technology recommendations for animation/display
Yes, that works if you are using pure CALayers - no problem there, but if you are using layer backed views, it doesn't work - see e.g. http://www.cocoabuilder.com/archive/cocoa/294950-problem-using-zposition-on-layer-backed-views.html ...so it still looks as if layer backed views are out... Ken On Mar 27, 2012, at 01:05 PM, Graham Cox graham@bigpond.com wrote: On 27/03/2012, at 12:54 PM, Kenneth Baxter wrote: If there are any comments on these options, or suggestions for other approaches, I'm all ears... CALayer has a 'zPosition' property which should allow you to set the order for sibling layers. --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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Technology recommendations for animation/display
Hi, I am developing an application where I need to be able to handle the following requirements: - Deployment: MacOS X 10.6 and later. May want to develop an iPad version later. - Type of application: Display and manipulation of graphical objects on a canvas. - Number of graphical objects: up to about 2,000 - Canvas needs to display solid color, gradient, or tiled image - The entire canvas with all the graphical objects on it need to be able to smoothly zoom and pan - Many of the graphical objects need to display text on them this must be high resolution rendering to look good - The text on graphical objects needs to be editable (I'm ok with putting a view overlay over it in order to accomplish this if necessary) - The graphical objects need to be able to be displayed with shadows and reflections. - The entire canvas and all the displayed objects must be printable at high resolution (i.e. PDF). - We need to animate movement of quite a number of the objects at once. - The objects that are moving have curved connection lines drawn to other objects that stay stationary, and those curves need to animate as the connected objects move. I am looking for recommendations on the best technology to use for this. The following are my thoughts so far, based on trying a few things: 1. Using an NSView and just drawing on that, I can get scaling and printing for free, but I can't use subviews for each of the graphical objects because you can't set the z order of sibling subviews, so I would have to create my own layer system which just draws to the view that I am using - easy enough, and I've done that before. But of course with this system, I miss out on all the benefits of core animation, and have to create my own custom animation code (presumably with NSAnimation), and it's all just standard view drawing, which I presume isn't making use of much by way of GPU acceleration etc. 2. Using CALayers at initial sight may appear to be the obvious thing for something graphical like this, but I have observed a number of issues with it. For my background, using tiled layers seems to not work too well when you have large texture images being tiled, and you can see the tiles being drawn. Scaling seems to be an issue as everything gets scaled and then redrawn, and looks blurry in the middle, and I have to take the scale factor into account with every piece of drawing code, including scaling fonts and even inline images in text etc. Also, printing is a problem, though I have found some code that goes through and extracts CG drawing commands and sends them to a PDF context, which gets me most of the way there, except that it seems to have trouble with translucent colors in some circumstances (especially on gradients), and can't draw shadows. I can't add a subview for the text editing, so have to create an overlay invisible window and position it right, and pass on scroll and zoom events etc just to have an editable subview that I can use for text editing. Also, I've come across some issues where a graphical object is over 10,000 pixels in one dimension in certain circumstances and on older computers in particular, the entire graphics buffer seems to get screwed up, and it flickers while it redraws (and the redraw is slow). Apple have acknowledged this issue, and it may well have already been fixed in 10.7+, but is IMHO very unlikely to be fixed in 10.6, so I'd have to find a workaround for that. Also, no matter what I do, the text drawing seems to never be as crisp as it is when I draw straight on my view in the NSView case. And despite having CAShapeLayer now, it sometimes seems to draw my curves doing crazy things during animations. So quite a lot of debugging to do. So should I go with NSView based drawing, where I know that the drawing and printing is going to work just right, and I have to code my own animations for zooming, scrolling, and moving objects around? Would I be able to get good enough performance doing this to get smooth animations? Are there any other downsides to this? Or should I go with Core Animation, and sort out the issues with drawing the tiled background, zooming smoothly, printing with shadows, text quality, having to have overlay windows, drawing everything scaled, etc, in order to be using the latest technologies and get the advantages of core animation? Or is there some other or hybrid option that I am not thinking of? Which approach would be easiest to port later to iPad? Any advice on this would be great! Thanks, Ken. ___ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSTextView scaled using scaleUnitSquareToSize - alignment issue
HI, I have a subclass of NSTextView that I am showing on a window. I sometimes want to display it zoomed in, so have been using scaleUnitSquareToSize:, and this works fine so long as the text is left aligned. When I am zoomed in, and using either center alignment or right alignment the text appears too far to the right in the text field. The frame of the field is showing at the correct size and location - it's just that the text is positioned incorrectly within the frame Am I doing something wrong here? Is there something I can do to get it to position correctly? Thanks Ken___ 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
NSArrayController or NSTreeController?
Hi, I'm working on implementing a search capability in my application. Each result will have a category and subcategory associated with it, as well as the actual result data. Separate from this, I will know what order I want the categories and subcategories sorted in at the time, and can populate that to the search results. I would like to present the results in an outline view so that the top level items are the categories (in order), and the second level items are the sub-categories (in order), and the actual results are detail rows. Sort of like what XCode 3 does with the project search, except two levels of categories rather than just file names. Should I be implementing this using an NSArrayController and somehow getting it to do the sorting/grouping to produce the outline rows, or should I be looking at an NSTreeController and getting my results to generate a tree rather than a flat list? Any suggestions on implementation would be welcome. Thanks Ken ___ 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
Truncating start and end of attributed string to show desired range.
Hi, I'm displaying search results in an outine view, and want to show the portion of the text where the search term was found, by truncating both the start and end of the string (where necessary) so that the result is visible in the displayed portion of the string. I can see how to truncate at the head or tail or center using the built in truncation options, but nothing to give a range of characters I want visible and get it to truncate before and after where necessary. I know enough about the string measurement stuff to be able to come up with an algorithm myself, but it would probably take a lot of work, when it may well already be a solved problem. I tried searching for something that would do the trick, but didn't come up with anything. Is there something already available that would take an attributed string, and the range you want visible and a rectangle (or size) to fit it in, and return a modified attributed string which will fit in that size, with ellipses at the start and/or end as required so that the required range is visible? Thanks Ken ___ 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
Blocking while a save panel sheet is showing
Hi everyone, I am using a framework where I register as a delegate and when my delegate method is called, I should be able to save my data, and then the framework does different things based on whether the data has been saved or not. I need to ask the user for the file name to save as, and then save the file. I have tried both the beginSheetModalForWindow:completionHandler: method and the old 10.5 beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: method, but both of them return immediately, and the framework thinks I haven't saved the file. Is there some way that I can display the save panel in such a way that it actually blocks until the user has chosen the save or cancel button on the save panel, like what NSRunAlertPanel does? That way, I would be able to get the file name and save the file before the method returned to the framework. Thanks Ken ___ 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
Blocking while a save panel sheet is showing
Hi everyone, I am using a framework where I register as a delegate and when my delegate method is called, I should be able to save my data, and then the framework does different things based on whether the data has been saved or not. I need to ask the user for the file name to save as, and then save the file. I have tried both the beginSheetModalForWindow:completionHandler: method and the old 10.5 beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: method, but both of them return immediately, and the framework thinks I haven't saved the file. Is there some way that I can display the save panel in such a way that it actually blocks until the user has chosen the save or cancel button on the save panel, like what NSRunAlertPanel does? That way, I would be able to get the file name and save the file before the method returned to the framework. Thanks Ken ___ 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: Blocking while a save panel sheet is showing
Thanks for the reply Graham. It sounds as if I would have to have control over the framework to do as you suggest, but I don't have access to the framework source. My understanding of what the framework does is: [delegate saveData]; if (dataHasBeenSaved) { do stuff } else { do different stuff } So if my delegate method saveData uses the sheet to save, it will return from the saveData method immediately, no matter what I do. I do have the file saving code in the completion block of the sheet, but by then it's too late - the framework thinks the data wasn't saved. I'm afraid I can't see a way to refactor that so that saveData doesn't return until the save operation is complete, and I can't see how the framework could work properly without waiting for the completion of the save operation. Maybe I'm missing something obvious about the way this is supposed to work (I'm still rather new to all this), or some other option. I did try to have a look at the document saving system, since it seems to be able to wait for the open documents to be saved on quit before deciding if the application should quit, but I didn't fully understand that, and I think it may operate in a different way than what I need. Regards Ken PS sorry about the double posting before - I'm using the web version of mobile me at the moment, and it seems to screw up every time I use it :( On 14 Feb, 2011,at 10:12 PM, Graham Cox graham@bigpond.com wrote: You need to factor your code so that you don't require the sheets to block. That isn't how they work. Instead, while the sheet is displayed, the event loop is run normally and will run the sheet modally while running everything else (like other documents) as normal. The user can switch away from the document displaying the sheet and come back to it later if they want. The point is that when the sheet ends (the user clicks OK or Cancel) the completion method (or block) is run, and it is this code that does the actual file saving. The purpose of the sheet is not only to choose the file name and location but to trigger the save itself. Rearranging your code so that the file save is triggered in this way should be straightforward - just call the save method from the sheet's completion method. --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: Blocking while a save panel sheet is showing
Thanks Ken - don't know why I missed that when reading the documentation. It does what I need, thanks. On 15 Feb, 2011,at 02:34 AM, Ken Thomases k...@codeweavers.com wrote: Although Graham is right that document-modal sheets is the preferred user interface for saving, you can run the save panel as an application-modal dialog. See -[NSSavePanel runModal]. Regards, Ken ___ 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: Undo in conjunction with core data
On 23 Jan, 2011,at 12:45 PM, Dave Fernandes dave.fernan...@utoronto.ca wrote: Looking back at my code, I see that I just use the KVO message to know that something changed. I then re-traverse the data model to update the view. (Not the most scalable technique.) I thought I would try that same approach. There is something unusual though - if I add a child, it shows up in the array controller and the children, and if I manually delete it, it is deleted from the array controller and the children. However, if I add a child and then undo the addition, the array controller has the child removed, but it is still there in the children, and all its data has gone. It has not been turned into a fault, and is not marked as deleted. Seeing as I can't access the data, it makes it impossible for me to do any cleanup because I need to know some data from the node in order to clean up properly. The only thing I can think of to overcome this is to grab the object ID and refetch the object so I can tell what has been deleted. All this just seems as if I must be going about this totally the wrong way, but I don't know any other way of accomplishing it. I did have a look to see if I could work anything out from the managed object context change notification, but couldn't get anywhere there either, and also looked at what was registered with the undo manager, but it didn't seem that the undo manager was being told what the objects were in the undoInsertions etc. I assume it's all managed in the MOC behind the scenes. So...still stuck, and not sure where to look next. If your background thread can copy the necessary data, then it doesn't have to worry about it disappearing. My understanding is that accessing a potentially changing MOC from another thread is problematic at best. See Ben Trumbull's posts on this topic. Ex. March 16, 2007 Re: Core Data threads [re: Ping: Look for hints for nested transaction problem with Core Data] That's a scary discussion - I need to pass in my objects to the processing thread so it can read them - I had no idea there would be a problem with doing that. Yet another thing to learn about Core Data. So if I understand correctly, instead of just myObjectInMyThread.node = node; I would have to do something like: NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init]; [managedObjectContext setPersistentStoreCoordinator:pscFromMainThread]; myThreadController.managedObjectContext = managedObjectContext; ... // In my thread (with appropriate will/did change and memory management...), where n is the node from the main MOC - (void)setNode:(Node *)n { node = [myThreadController.managedObjectContext objectWithID:[n objectID]]; } Is that the right sort of approach? You know, I could have done this project in 1/10th the time or less if I had not used core data - hope it pays off in the long term... The usual pattern seems to be to have a separate MOC for the background thread and echo changes to it when the MOC in the main thread changes (NSManagedObjectContextObjectsDidChangeNotification). ___ 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: Undo in conjunction with core data
Thanks for the follow up Dave. Regarding the predicate, I understood that the fetch was entity based rather than object based, so thought that if parent != self, I would get the children of other parents too. Anyway, I can check that pretty easily. No, I'm not directly updating a view. What happens is that the nodes are in a tree formation with connections between them, and when I add a new one, there is a layout system that gets told that there is a new node, and how big it is etc, and it moves all the other nodes and their connections around to fit the new one in, and then creates the view objects for the new node and its connection back to its parent. Quite a lot going on. And in the deletion process, I need to send the notifications before the underlying data is removed to stop some animations and pending notifications in queues etc, and to remove some observers, so that when the nodes are deleted, there is nothing hanging around trying to access things that have disappeared. This way, the view part of the system can remove things nicely, and the layout part of the system knows that the objects have gone. From Kyle's post, it appears that I can't get the prior notification from array controller observing, which is one thing I was thinking about doing. Another thing I was thinking was about implementing the primitive set methods addChildrenObject, removeChildrenObject, addChildren, removeChildren, and calling my notifications from there, and then all the undo stuff could presumably happen automagically and the notifications would happen when I wanted them to (I'm assuming that the undo and redo mechanism would also use these methods if they are available). I'm not sure if there are any potential downsides to this, but it's another thing that I could check with relatively little work. I think I need to have a play around with some of these ideas and see what works best for my situation, but any further suggestions based on the additional information above would be welcomed. Thanks Ken On 22 Jan, 2011,at 04:52 PM, Dave Fernandes dave.fernan...@utoronto.ca wrote: The fetch predicate would be @parent != nil if you want all children. Now this is where I get a bit lost - so I presume that in my createChild method, I no longer need to post the ChildNodeAddedNotification, because I would be able to observe the change, and somehow know which object had been added? Can you say what it is your application does when it gets these notifications? Are you just updating a view? And for the deletion, I'm not really clear on how to get the message to all the descendants that they are going to be removed etc. Again, what do the descendants need to do when they get this message? Why not just traverse the relationships to get each of the descendants and send it a message directly? So I am guessing that there must be some way to be notified when an object is going to be added, so I can do the pre-processing, and when it has been added, so I can do the post-processing, and ditto for the deletion, but I really don't see how this can be possible since the changes are percolating up from the MOC to the ArrayController, and I don't see anything in the array controller that seems to support this level of functionality. It sounds like you may be using the notifications to modify the data model. If so, there is probably a better design pattern. Sorry for being dumb about this, but I think I must be missing the concept of what you are meaning in some fundamental way. On 22 Jan, 2011,at 10:28 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: One way to do this through the MVC paradigm is to bind an NSArrayController or NSTreeController to your managed object context (in Entity mode), and then have your view layer bind or use KVO with the selectedObjects or arrangedObjects attribute of the controller. ___ 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: Undo in conjunction with core data
I thought I would try to do the necessary pre and post-processing using the -willChangeValueForKey:withSetMutation:usingObjects: and -didChangeValueForKey:withSetMutation:usingObjects: methods, and sure enough they get called at the right times, and work just fine for undo, but then when I redo, my Node objects come back as blank empty objects instead of being populated with my data. Any ideas why this would be? Essentially the flow is: 1. Create the child, which populates a bunch of things in the awakeFromInsert using primitive set methods. 2. Make some other changes to the object 3. Add it to the children (which triggers my post-processing) 4. Make some more changes to the object (end of action) Undo, which removes the child and triggers my pre and post processing to remove related items Redo, which knows that there is an object to reinsert, but it has nothing populated - not even my initial values that were set originally in awakeFromInsert. Surely the data should be populated in the object by this stage? I tried willAccessValueForKey:nil in case it was a fault, and checked isFault and isDeleted, but nothing helped. Thanks Ken___ 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: Undo in conjunction with core data
Thanks Dave. I am now trying to use an array controller. I have set up the array controller and an observer on arrangedObjects, and that gets called during my addition and removal of children, but the change kind is always 1, and there is never anything in the old or new value arrays, so nothing beyond this knows whether it was an insertion or a deletion. I'm not sure exactly how much use that is in managing my other objects. On 23 Jan, 2011,at 03:54 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: Undo, which removes the child and triggers my pre and post processing to remove related items This is the part that doesn't make sense to me. While you certainly have to worry about making sure your view is in sync with you data model, you should not have to update the nodes in your data model. Core data will do that for you on undo and redo. The other things that need to remain in sync during undo and redo are not other nodes - they are some things that are managed at the view and controller layers of the application. I have some background threads that are processing data and need to know when a node is removed, and I have a mapping between the data and a number of front end objects and views, some of which may be animating at the time, as well as an intermediate model layer, and if any of those objects try to access the core data objects when they have been deleted, then all hell breaks loose. Therefore I have been sending notifications before the nodes are removed so that the processing thread can pick up on that and remove the node from the ones it is working on, and the animations can have their connections to the back end and other related objects cleaned up nicely. I don't know how else to accomplish a nice tidy up, since the animations and processing are using other threads, and may try to access the deleted node. I guess the idea of the array controller is that now instead of accessing the children relationship directly I should always go through the array controller's arranged objects, but I'm afraid I still don't get how that would help with managing the nodes disappearing during undo before I knew about it. I guess the core issue may well be at levels above the data layer, but I'm not sure how to get around this. To keep your view in sync, if you put a controller object between it and the data model, then the controller has to worry about when to stop observing the managed object, not your view (and the NS*Controller classes do this). Now your view just has to change state when it observes that the data has changed or gone away. I'm not sure how this relates to my situation. When a node is added, my layout system runs in a background thread, and when it has worked out where the new node is going to go and where the existing nodes need to move to, it moves the existing ones to their new locations, and at that point creates a number of view level objects for the node, and registers the mapping between the node and its view counterpart. So now I have an array controller which lets me know when *something* has already changed. The two issues I see with this are: 1. I have no idea what changed - KVO only tells me that something has changed with my children. 2. It only tells me after the event, and something in either an animation or background processing thread may have already tried to access the deleted node. It may be more efficient if the view simply notes that a change has occurred in observeValueForKeyPath:ofObject:change:context:, and then coalesces all updates in one place such as drawRect: (since observeValueForKeyPath: may get hit several times during the update of a single object). Your view seems to follow all the intermediate changes of the data model within a single event cycle. That seems a bit fragile to me. Sorry, I don't understand what you mean by that or what to do about it. Again, sorry for taking so much time to get this. I hope the curtains will soon part and I will see the light.. Ken.___ 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
Undo in conjunction with core data
I am trying to work out an issue with undo in a few places in my application, and think if I get it with one of the places, I should be able to apply the same theory elsewhere. I have a parent and children relationship, and need to have a few things happen during the process of adding and deleting a child so that the rest of the application stays in sync. The core data side of things manages the undoability of the data, but of course it doesn't know how to send the other messages at the right times, so I have tried to add the notification messages in the reverse order on the undo stack (prepareWithInvocationTarget), but then redo doesn't work properly All the undo and redo for the rest of my application is working fine (just fairly simple relationships and attributes), but I think there's a design pattern I'm missing here for the more complex case. It's probably best for me to just post the things that need to happen during a normal add of a child and deletion of a child, and hopefully someone will be able to give me guidance on how to make it undoable and redoable. - (MyNode *)createChild { MyNode *child = [NSEntityDescription insertNewObjectForEntityForName:@MyNodeEntity inManagedObjectContext:[self managedObjectContext]]; // Set a bunch of properties on the new child. ... [[self mutableSetValueForKey:@children] addObject:child]; // Set a bunch more properties on the new child and other core data managed objects ... // Let the front end of the application know about it [[NSNotificationCenter defaultCenter] postNotificationName:@ChildNodeAddedNotification object:... userInfo:...]; return child; } - (void)deleteChild:(MyNode *)aChild { NSArray *affectedChildren = [aChild selfAndAllDescendants]; [[NSNotificationCenter defaultCenter] postNotificationName:@NodesWillBeRemovedNotification object:self userInfo:[NSDictionarydictionaryWithObjectsAndKeys:affectedChildren, @affectedChildren, nil]]; [[self mutableSetValueForKey:@children] removeObject:aChild]; if (self.parent) { // Do some things that could affect some ancestor values ... } for (MyNode *tn in affectedChildren) { // Do some special processing to clean up things that might be pointing to the descendants ... // Set a non-persistent property on the tn node which will be picked up by KVO to show that the node will be removed, so we can kill observing etc. ... [[self managedObjectContext] deleteObject:tn]; } aChild.parent = nil; // Do some post-processing to make sure some other values are kept in sync. ... // Post a notification so the front end can be updated. [[NSNotificationCenter defaultCenter] postNotificationName:@NodeRemovedNotification object:self userInfo:[NSDictionarydictionaryWithObjectsAndKeys:aChild, @node, self, @parent, affectedChildren, @affectedChildren, nil]]; } I have looked at some of the previous posts on related things, but haven't seen an answer that would explain what to do for this kind of thing (and some posts were suggesting turning off core data's undo completely and doing your own etc, which would not be good for me since I have a *lot* of places where it is working just fine for me and only about 6 places where it's not). Thanks in advance for any advice on this. Ken ___ 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 data autosave
I need to autosave my documents in my core data document based application I must say I was surprised and disappointed when I found out that Core Data doesn't appear to have any autosave support built in and NSPersistentDocument doesn't support the superclass NSDocument autosave architecture. I see there has been some discussion previously about possible approaches to solving this issue. I need something that works on 10.5 and 106. In 2008, Ben Trumbull said You could fake it by migrating the store to the backup location, creating a second context, pulling all the deltas from the original, save, and then tossing the second context. Is this the current opinion on the best way to do autosave? It sounds like a very heavy approach, and I'm not sure on the actual implementation details of how to do what Ben says. If there is some common way of doing this, is there some sample code out there from Apple or someone else? Any feedback/suggestions would be very much appreciated. Thanks Ken___ 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: Undo in conjunction with core data
Thanks for that suggestion Dave. I'm trying to understand how this would work. While a tree controller would be able to represent the whole hierarchy, I think maybe for the things I am trying to achieve here, I would be easier to use an array controller on the children, and keep it at a manageable single level rather than affecting the architecture of the whole application. So, completely separate from the UI, I create an array controller in my Node managed object, and set its entity name, MOC etc, and set the fetch predicate to be @parent = SELF. It should then keep itself updated when the children get added or deleted in the MOC, right? (I have never used array controllers in this way before) Now this is where I get a bit lost - so I presume that in my createChild method, I no longer need to post the ChildNodeAddedNotification, because I would be able to observe the change, and somehow know which object had been added? And for the deletion, I'm not really clear on how to get the message to all the descendants that they are going to be removed etc. So I am guessing that there must be some way to be notified when an object is going to be added, so I can do the pre-processing, and when it has been added, so I can do the post-processing, and ditto for the deletion, but I really don't see how this can be possible since the changes are percolating up from the MOC to the ArrayController, and I don't see anything in the array controller that seems to support this level of functionality. Sorry for being dumb about this, but I think I must be missing the concept of what you are meaning in some fundamental way. On 22 Jan, 2011,at 10:28 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: One way to do this through the MVC paradigm is to bind an NSArrayController or NSTreeController to your managed object context (in Entity mode), and then have your view layer bind or use KVO with the selectedObjects or arrangedObjects attribute of the controller. ___ 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: Base SDK 10.6 deployment target 10.5 - symbol not found
Thanks for that link Kyle, from that reference it appears that it is not possible to weak link classes in MacOS X, so the only way to use my subclasses of CAShapeLayer would be to move them all to a separate bundle and only load that bundle when running on 10.6. Something I wondered about was, is it possible to create a dummy CAShapeLayer class and do something in the runtime to make sure it uses the dummy one when running on 10.5 and the framework one when running on 10.6? I tried out a little test and got an error saying Class CAShapeLayer is implemented in both (QuartzCore) and (my app). One of the two will be used. Which one is undefined., and then it proceeded to use the dummy one on 10.6. I'm not sure if it would be possible to get in early in the runtime and remove the dummy class or something on 10.6? So I also wondered if it would be possible to create that dummy class but only load it if running on 10.5, but my guess is that wouldn't be possible either, because I probably couldn't get to the process early enough to load the bundle before the linker had complained about it. I'm sure you guys would have thought of these possibilities before, but I just thought I'd ask, since it would be less work than splitting it out into a separate bundle etc etc, and it just seems as if I would be coding for 10.5 with 10.6 as the exception kind of thing, whereas 90% of the users will be on 10.6 and we just need to get it running for 6 months or so on 10.5 until the rest have moved over. I hope there is an easier way than creating a bundle that we only load on 10.6...any suggestions of other things to try would be very welcome. Thanks Ken On 12 Jan, 2011,at 05:00 AM, Kyle Sluder kyle.slu...@gmail.com wrote: On Tue, Jan 11, 2011 at 10:40 AM, Wim Lewis w...@omnigroup.com wrote: You might be able to weakly link the class, in which case dyld will not complain but messages to CAShapeLayer will return nil. I don't remember on which OS revs it became possible to weak link a class, though. (Weak linking C symbols has been possible since 10.2; see TN2064.) See Greg Parker's website for an explanation of weak-linking ObjC classes, which became available in iOS 3.1: http://www.sealiesoftware.com/blog/archive/2009/09/09/objc_explain_Weak-import_classes.html --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: Custom path animation for CAShapeLayer
Thanks for the feedback David. I'll try the keyframe approach. On 11 Jan, 2011,at 09:24 AM, David Duncan david.dun...@apple.com wrote: The closest thing you could do here is use a Keyframe animation, but I'm not certain this could be done cleanly or without using lots of intermediate paths for even short sequences. It is something to explore. -- David Duncan ___ 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
Base SDK 10.6 deployment target 10.5 - symbol not found
Hi, I have a project I'm working on which needs to run on 10.5 and 10.6. I have various things enabled or disabled using: if (floor(NSAppKitVersionNumber) NSAppKitVersionNumber10_5) ... but I also have some places in my code where I want to use a CAShapeLayer subclass in 10.6 and an alternate version based on NSViews in 10.5. My logic says it is not going to call the CAShapeLayer, but it appears that it has been linked in to the application anyway, so when I try to run the program on 10.5, it gives me the error: dyld: Symbol not found: _OBJC_CLASS_$_CAShapeLayer What is the proper way to handle situations where a whole class is missing in the earlier SDK like this? The documentation doesn't seem to address this scenario as far as I can see. Thanks Ken___ 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
Custom path animation for CAShapeLayer
Hi, I'm trying to use a CAShapeLayer for some paths in my application. For the most part this works fine, but in some circumstances the animation from one path to another looks really strange during the animation. I would be able to tell it what the path should be at any intermediate point in the animation, but I'm not sure how to get access to it to provide those paths. Is it possible to provide my own paths for the animation, or get some callback when it wants a new path or the animation advances? If not, what's my best approach for animating the layer? I have played around with the idea of creating a dummy key which I add an animation for and animate it between 0 and 1, and set setNeedsDisplayForKey: to return YES for that key, and then use the value to determine how far through the animation I am and draw the appropriate path, but this seems a really counter-intuitive (hackish) way of doing it, but it seems to work and I haven't yet found a better way... (target is Mac OS X 10.6) Thanks. Ken ___ 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
Text display consistency
Hi, I have an application that needs to display text on both Mac OS X and on iOS. I'm sticking to core technologies for my drawing and drawing all my stuff into cgcontexts for maximum portability. I sometimes need the user to edit the text, so am planning to add a subview (NSTextView / UITextView) when the user needs to edit the text. What is the best way to minimize the customization for the two versions of the application, and ensure that when I put the text view over the top, that it is exactly the same size and shape (kerning/wrapping etc) when drawn in the text view and when drawn directly in the cg context? Any gotcha's I should know about? TIA Ken. ___ 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
Text rendering/editing on OSX iOS
Hi, I have an application which I plan to roll out on both iOS and MacOS X, and it needs to display text in various places on a series of views. I am doing all the drawing using the Core technologies (CGContext drawing) to make the maximum reuse of code. I've done most of the graphical stuff and am just moving on to the text. Sometimes the user needs to edit the text, so I am planning to add a subview (NSTextView / UITextView) while they are editing, but I need to be sure that it's going to be exactly the same rendering size, position, wrapping etc. between the text views and the core drawing. Is there anything special I need to look out for to ensure that it's the same? Is this the best way for me to achieve my goal of maximum reuse and seamless switching between the drawn text and the text view for editing? TIA Ken. ___ 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: Text rendering/editing on OSX iOS
Thanks Ricky, this is a very drawing-heavy application, so I think it's probably worth a little pain to get it mostly drawing cross platform, and then wrap the platform specific UI around that. I'm mostly there with that approach. Being the same refers to the size, position, rendering between core graphics and the text view on a specific operating system/device - it does not need to be pixel perfect the same between a Mac and an iPad Regards Ken PS apologies to everyone for the double posting before - Firefox 4 beta + Me.com = crash and message not showing up as sent even though it was. On 22 Dec, 2010,at 12:29 AM, Ricky Sharp rsh...@mac.com wrote: I'm not sure what you mean by it's the same. Do you mean pixel for pixel accuracy between Mac OS X and iOS? I don't thing that may be possible (at least at a high level) as there may be different rendering techniques. Default fonts between the systems are different and perhaps there's also subtle anti-aliasing differences, etc. Also, iPhone 4 introduced the Retina display, so output on such screens will provide much higher-quality output. ___ 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
Need functionality of CAShapeLayer in 10.5
Hi all, I had gone through my initial design for a project I am working on and one part of it really needs to use CAShapeLayer, but I just realized that it's only available in 10.6+, and I have to support 10.5. Essentially I have two layers that have a bezier path drawn between them. The two layers at each end of the path are moved during animations, and the bezier path needs to be adjusted to stay connected with the layers at each end Seems to me that this would be easily done by CAShapeLayer, if I could use it. I presume people were probably doing this type of thing before CAShapeLayer came along, so I'm wondering if there is some sample code for an equivalent of CAShapeLayer or at least something that will allow me to easily update the path during the animation. I was thinking of using a startPoint and endPoint for the path which are animated, and have setNeedsDisplayForKey set, and just recalculate the path in the drawing method Is this a good approach, or is there a better way, or some existing code that may help out with this? It would be nice to be able to do something that has an API match with CAShapeLayer, so that when I can ditch 10.5 support (hopefully soon), I could just move straight to CAShapeLayer without having to change anything else, but that would presumably mean animating an arbitrary number of points in the bezier path and handling all sorts of situations like one path having more points than the other etc. Any suggestions would be most welcome. Thanks Ken ___ 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: Need functionality of CAShapeLayer in 10.5
OK, thanks for that David - I'll take that route then. On 22 Sep, 2010,at 10:32 AM, David Duncan david.dun...@apple.com wrote: On Sep 21, 2010, at 5:02 PM, Kenneth Baxter wrote: Any suggestions would be most welcome. With a requirement of 10.5, about all you can do is call -setNeedsDisplay from a timer to implement the animation yourself, unless your path can be animated well enough by just stretching/squeezing the layer. Either way your talking about drawing your path into a plain CALayer. -- David Duncan ___ 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: Need functionality of CAShapeLayer in 10.5
Just a quick question about this - I notice that you say to use a timer which I presume you say deliberately rather than using the automatic needsDisplay and recalculating during display. The way I was thinking of doing it would have resulted in the recalculation of the path during the drawing, which in turn would have meant that I would want to change the frame/bounds during the drawing, which presumably would not be a good thing, right? Is this why you would say to use a timer? So presumably that means I would get the timer to fire frequently and then ask the presentation layer for the values for my animating points, and if they have changed, I recalculate my path, and update the frame if necessary, using a transaction which disables animation, and then calls setNeedsDisplay. Sorry to need to bother you for the clarification, but I just need to make sure I understand correctly. On 22 Sep, 2010,at 10:32 AM, David Duncan david.dun...@apple.com wrote: On Sep 21, 2010, at 5:02 PM, Kenneth Baxter wrote: Any suggestions would be most welcome. With a requirement of 10.5, about all you can do is call -setNeedsDisplay from a timer to implement the animation yourself, unless your path can be animated well enough by just stretching/squeezing the layer. Either way your talking about drawing your path into a plain CALayer. -- David Duncan ___ 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
Animating a non-standard layer property
Hi, I have a layer where I want to animate a point, testPoint. For the moment, I want to animate the y value of the point. I have testPoint as a property of the layer. I want to get it to redisplay (and preferably also call the setTestPoint) on every frame of the animation, so I implement: + (BOOL)needsDisplayForKey:(NSString *)key { if ([key isEqualToString:@testPoint]) { return YES; } return [super needsDisplayForKey:key]; } To see the changes as they are made, in addition to the normal synthesize of the testPoint, I have implemented the setter as follows: - (void)setTestPoint:(CGPoint)p { NSLog(@Setting test point to %f, %f, p.x, p.y); [self willChangeValueForKey:@testPoint]; testPoint = p; [self didChangeValueForKey:@testPoint]; } When I create the layer, I initialize the testPoint as follows: layer.testPoint = CGPointMake(5.0f, 10.0f); I try to animate the move of the point using: CABasicAnimation *movePointAnimation = [CABasicAnimation animation]; movePointAnimation.keyPath = @testPoint.y; movePointAnimation.toValue = [NSNumber numberWithFloat:y]; movePointAnimation.duration = 5.0f; movePointAnimation.removedOnCompletion = YES; movePointAnimation.fillMode = kCAFillModeBoth; movePointAnimation.repeatCount = 0; movePointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [layer addAnimation:movePointAnimation forKey:@testPoint.y]; What I expected to happen is that I would get a bunch of calls to setTestPoint:, passing in the original x value of 5.0 and animating from the previous y point (initially 10.0) to the new point, and that my drawLayer:inContext: would have been called for each iteration. Here's a typical run (each call to the animation separated by a line gap): 2010-09-21 08:16:36.717 CADisplay[20048:a0f] Starting animation to 4383.00 2010-09-21 08:16:48.422 CADisplay[20048:a0f] Starting animation to 886.00 2010-09-21 08:16:48.424 CADisplay[20048:a0f] Setting test point to 0.00, 0.041937 2010-09-21 08:16:48.424 CADisplay[20048:a0f] Setting test point to 0.00, 0.042831 2010-09-21 08:16:48.425 CADisplay[20048:a0f] Setting test point to 0.00, 0.044800 2010-09-21 08:16:48.445 CADisplay[20048:a0f] Setting test point to 0.00, 0.140321 2010-09-21 08:16:48.456 CADisplay[20048:a0f] Setting test point to 0.00, 0.215275 2010-09-21 08:17:01.422 CADisplay[20048:a0f] Setting test point to 0.00, 886.00 2010-09-21 08:17:01.583 CADisplay[20048:a0f] Starting animation to 2777.00 2010-09-21 08:17:15.142 CADisplay[20048:a0f] Starting animation to 1915.00 2010-09-21 08:17:15.143 CADisplay[20048:a0f] Setting test point to 0.00, 0.090642 2010-09-21 08:17:15.144 CADisplay[20048:a0f] Setting test point to 0.00, 0.092054 2010-09-21 08:17:15.144 CADisplay[20048:a0f] Setting test point to 0.00, 0.095602 2010-09-21 08:17:15.160 CADisplay[20048:a0f] Setting test point to 0.00, 0.247579 2010-09-21 08:17:15.175 CADisplay[20048:a0f] Setting test point to 0.00, 0.464084 And when I clicked on XCode, it added: 2010-09-21 08:17:26.118 CADisplay[20048:a0f] Setting test point to 0.00, 1915.00 ...and my drawLayer:inContext: was not called at all during the animation. What am I missing here? Why is my layer not being drawn on every frame? Why is the setTestPoint getting called with a zero X value? Why am I just getting these strange values in setTestPoint, and why for only the first tiny bit of the animation? Also, if I wanted to animate the whole point rather than just the y value, what should I pass in? I don't see an NSValue valueWithCGPoint... Thanks in advance Ken___ 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: Animating a non-standard layer property
Brilliant! Works now, thanks David. Is there somewhere I can find out more about this? It is not mentioned in the Core Animation Programming Guide (2010-08-12), and I have got two e-books on core animation, and it is not mentioned in either of them. Thanks Ken On 21 Sep, 2010,at 09:07 AM, David Duncan david.dun...@apple.com wrote: On Sep 20, 2010, at 3:42 PM, Kenneth Baxter wrote: To see the changes as they are made, in addition to the normal synthesize of the testPoint, I have implemented the setter as follows: There's your problem. Your not supposed to @synthesize these properties. Unless you let Core Animation define them (by declaring them @dynamic) they cannot be animated and you will see the symptoms you see. In your -drawInContext: method you can then query the property to get the current value. -- David Duncan ___ 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
Animated scrolling of NSScrollView
I see that UIScrollView has the option to animate scrolling, but I don't see any equivalent for NSScrollView, and the scrolling methods don't seem to be supported by implicit animation. My document view is a layer hosting view, so I looked at the CA scrolling layer, but that seems to be something completely different. So simple question: what is the best way to animate scrolling (scrollRectToVisible:, scrollPoint:) of an NSScrollView? The only other posts about this I have found seem to be asking similar questions, without any definitive answers. Thanks Ken ___ 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
Design pattern for core data, document based, graphical application
Hi, I am working on an application that uses core data at the back end, and the NSPersistentDocument architecture at the front end. It is a graphics application which essentially displays a tree of objects, destined for 105+ deployment. I also want the functionality available by AppleScript. I have created a couple of applications in Cocoa, but that was about 5 years ago, and I need to work with the latest technologies now. I am familiar with the MVC model, but am finding it difficult to really tie down the controller layer in the architecture, and am not certain about how the messaging should work. How I'm thinking of it is that I have a view controller for my canvas view, which uses KVO to observe when children objects are added or removed in my tree structure in core data. In the old way of doing things I would have had one big canvas view with a controller for each graphical object as it was added, and have it responsible for drawing itself within the canvas view. This would also allow me to have overlapping objects, and keeps the number of views down below the recommended 100 max per window. I could still do that, and have each of those controllers register themselves for KVO notifications on anything that should change how the object looks on the screen, but that would seem to leave me out in the cold as far as animations go (apart from just using an NSAnimation as a timer to call back to the controller for each object). I understand that in 10.5, views became more lightweight, and also gained the ability to overlap, so maybe I could create a view controller and view for each graphical object. If I go this kind of route, I am not sure of the drawing classes I should be using. I want to use animation for moving and reshaping my graphical objects. It looks as if I can just use an NSView directly and use -animator, or can get the views to be layer-backed, or use CALayers. The dynamics of the application are that is would be very unusual for there to be more than 500 of my graphical objects on the screen at once, and typically a user action would make about a dozen objects change shape (not just a transform - they would have to redraw each time), and another 50 move. Sometimes one graphical object is partially or wholly on top of another. It is possible that I may want to make an iPad version of this app later, so would like to choose the best technology to minimize rework to do that (I guess that would mean drawing everything in CG rather than NS methods, but am not sure of the overall view class choices). Recommendations? Then we get to the user interaction... I can tie the values back directly to the core data counterparts (using bindings in IB), but that skips the controller layer in the middle, and as far as I can see, would mean that I would have nowhere to put an undo action name, and also when someone changes something on my objects, in some cases I want other things updated synchronously, and sometimes asynchronously, and a controller layer would seem the place to trigger that. What is the right way to go about this? Should I ignore bindings at the user interface layer, and have IBActions to my view controller, and have that use manually configured bindings to update the model? If I was exposing all this to AppleScript, would I be able to leverage my view controllers etc, or would I have to use a different architecture? Thanks, Ken.___ 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: Design pattern for core data, document based, graphical application
Thanks Fritz - I had a look at the Sketch example, and see how it implements the AppleScript. I see also that it uses the concept of a single canvas that has objects that can draw on it. I think I'll have to do some testing with the other scenarios to see how performance would go using views or layers. Things like the video wall application Apple made make me think that I should be able to get good performance using those technologies. On 18 Aug, 2010,at 01:00 AM, Fritz Anderson fri...@manoverboard.org wrote: On 16 Aug 2010, at 8:18 PM, Kenneth Baxter wrote: If I was exposing all this to AppleScript, would I be able to leverage my view controllers etc, or would I have to use a different architecture? I believe Apple's sample code for Sketch-112 will put you a long way into your quest. Search for Sketch in the Xcode documentation browser. — F ___ 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: Design pattern for core data, document based, graphical application
Thanks Erik Having the model doing the drawing directly like that is something I hadn't thought of. Definitely worth considering. I'll still have to observe changes in related attributes to trigger UI updates, and I have many ancillary objects that need to be involved in the process, so I may have to factor them in as supporting classes or something like that. Anyway, that gives me a good starting point, and gives me the flexibility to represent the objects on whatever view hierarchy works without having to change things. Time to start making a few prototypes to test out the different design options... On 18 Aug, 2010,at 01:33 AM, Erik Buck erik.b...@sbcglobal.net wrote: You have too many design options on the table. Try some of them in mini-prototypes to see how well they work and then drop some of the ideas. ___ 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