Scaling CALayer produces blurry/distorted text

2011-06-30 Thread Ajay Sabhaney
Hello,

I have an application in which the user can continuously zoom and pan a canvas 
(kind of like Google Maps).  On the canvas, a user can have multiple text 
items.  Each text item is a Core Animation layer, and the text is drawn using 
NSLayoutManager's drawGlyphsForGlyphRange method.

When the canvas is zoomed in or out, the text item is scaled using 
CGContextScaleCTM. The text however, is blurry at certain zoom levels. If I set 
the magnification filter of the CALayer to kCAFilterNearest, it almost works, 
but at a few (seemingly random) zoom levels, there appear to be some artifacts. 

Here are four links, each one showing different scenarios:

1) Using kCAFilterNearest magnification filter, at a zoom level where no 
artifacts are produced.
http://mothercreative.com/ajay/text/perfect.png

2) Using kCAFilterNearest magnification filter, at a zoom level where some 
artifacts are produced (areas in red).
http://mothercreative.com/ajay/text/artifacts1.jpg
http://mothercreative.com/ajay/text/artifacts2.png

3) Using the default magnification filter, notice blurriness.
http://mothercreative.com/ajay/text/blurry.png

I've ensured already that the frame rect is integral (so that the layer isn't 
sitting on half pixels), font smoothing is off, and antialiasing is on.

Any suggestions as to why these artifacts are showing up, or how to produce 
more clear results without using the kCAFilterNearest magnification filter, 
would be much appreciated.

Thanks,

Ajay

___

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


FSEvents - handling kFSEventStreamEventFlagRootChanged flag

2011-06-16 Thread Ajay Sabhaney
Hello,

I have setup an FSEventStream so that I can monitor a directory for file 
changes. If the root directory that is being watched is moved/renamed, I want 
to be able to keep monitoring the directory.  I am able to get the new path of 
the root directory, however I am unsure of how to monitor the new path. If I 
try to stop monitoring the watched directory (so I can subsequently monitor the 
new root directory path), the following error message is logged to my console:

(CarbonCore.framework) process_dir_events: watch_path: error trying to add 
kqueue for fd 5 (/Users/path/to/orig/dir; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_path: error removing fd 6 from 
kqueue (Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error trying to 
add kqueue for fd 6 (/Users/path/to/orig; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error trying to 
add kqueue for fd 7 (/Users/path/to; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error trying to 
add kqueue for fd 8 (/Users/path; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error trying to 
add kqueue for fd 9 (/Users; Bad file descriptor)

I'd appreciate if someone can suggest a way to monitor the new directory path 
(and stop monitoring the original location) when receiving a 
kFSEventStreamEventFlagRootChanged flag.  If invalidating and stopping the 
stream (then restarting it) is the way to go, perhaps someone could shed some 
light as to why I'm receiving the error mentioned above.

A similar question has been asked (but not yet solved) in the following thread:
http://lists.apple.com/archives/filesystem-dev/2010/May/msg7.html

Ajay
___

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: Linearly Scaling Text

2011-05-30 Thread Ajay Sabhaney
 I hope that there are no issues scaling an NSTextView that is layer-backed 
 (either using NSView's scaleUnitSquareToSize method, or the bounds 
 manipulation approach that TextEdit uses).

Unfortunately, there seems to be issues with scaling an NSTextView in a 
layer-backed hierarchy as well - I am encountering the same, somewhat garbled 
drawing of the editor, as mentioned in my previous posts. I'll file a radar 
with Apple.

Any suggestions as to how to implement an editable text box in a zoomable, Core 
Animation layer-backed or layer-hosted hierarchy, would be much appreciated.


___

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: Linearly Scaling Text

2011-05-30 Thread Ajay Sabhaney
 Because it was mono-Font text, I resorted to scaling the font
 instead.

Actually I did try scaling the font instead of the text view, but I'm unable to 
get the text to scale linearly as our application should be able to handle most 
fonts.

 I never went back to view scaling, but I wonder
 if you could control the granularity of the involved CALayers such that a
 tiled view would produce a clean result when scaled up?  Just a thought.

Hmm, there seems to be an issue scaling any layer-backed NSTextView, but I'll 
definitely look in to using a tiled layer. 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: Linearly Scaling Text

2011-05-29 Thread Ajay Sabhaney

 Also, you should disable screen font substitution via -[NSLayoutManager 
 setUsesScreenFont:NO].
 
 This is the main source of glyph advancement differences you're seeing.

Thanks Aki, indeed this has removed the small horizontal offset that was there.

I am however unable to figure out where the small vertical offset comes from.  
Using NSLayoutManager's defaultBaselineOffsetForFont method, I have tried 
getting the default baseline offset for the text at the max zoom level, and the 
baseline offset for the text at the current zoom, then find the difference and 
set the NSBaselineOffsetAttributeName attribute accordingly. However, this 
approach works at certain zoom levels and not at others! 

I've also tried using the same approach for line height, where I interpolate 
what the line height should be given the line height at the max zoom level 
(with the help of NSLayoutManager's defaultLineHeightForFont method), then set 
the minimum and maximum line height of the paragraph style accordingly. At some 
zoom levels, this works, but at other zoom levels, this make the vertical 
offset even worse.

Could anyone shed some light as to what the issue might be here?

Ajay___

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: Linearly Scaling Text

2011-05-29 Thread Ajay Sabhaney

On 2011-05-25, at 3:41 PM, Douglas Davidson wrote:

 
 On May 25, 2011, at 2:37 PM, Ajay Sabhaney wrote:
 
 - Instead of trying to scale text linearly, use a transformation to scale 
 the NSTextView and image representation appropriately.  While this is easy 
 to do with an image, I am having some issues scaling an NSTextView.  I've 
 tried subclassing NSTextView, then in the drawRect method, I apply an affine 
 transformation, then call the super's drawRect.  This almost works, except 
 the caret acts as if no transformation was applied - it's size and position 
 are unchanged even though the text is not.  I've also tried using the NSView 
 method scaleUnitSquareToSize: - however this produces fuzzy text.
 
 Try taking a look at the source code for TextEdit--it's available as sample 
 code, and it gives an example of scaling for NSTextViews.

Thanks for the pointer Douglas, I had a look at TextEdit and tried to use the 
same approach - however, it results in the same issues as using the 
scaleUnitSquareToSize approach where there are some weird drawing artifacts 
in which seemingly random rectangular portions of the text view are not drawn 
properly.

I have a suspicion that the reason for this has something to do with the fact 
that the NSTextView instance is being added as a subview of a layer-hosting 
view. I recognize that this is generally not recommended, however, our 
application uses a Core Animation layer hierarchy to handle animation and 
interaction with hundreds of layers at any given time. Without the use of a 
layer hierarchy, much of our application would not be possible.  View-backed 
layers would be too heavy for our application.  At the same time, however, 
layer hosting makes text editing very 
difficult.___

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: Linearly Scaling Text

2011-05-29 Thread Ajay Sabhaney
 Also, you should disable screen font substitution via -[NSLayoutManager 
 setUsesScreenFont:NO].
 
 This is the main source of glyph advancement differences you're seeing.
 
 Thanks Aki, indeed this has removed the small horizontal offset that was 
 there.
 
 I am however unable to figure out where the small vertical offset comes from. 
  Using NSLayoutManager's defaultBaselineOffsetForFont method, I have tried 
 getting the default baseline offset for the text at the max zoom level, and 
 the baseline offset for the text at the current zoom, then find the 
 difference and set the NSBaselineOffsetAttributeName attribute accordingly. 
 However, this approach works at certain zoom levels and not at others! 

My apologies, I just realized I explained this incorrectly.  I'm basically just 
getting the default baseline offset for the font at the max zoom, then multiply 
it by (currentZoomFactor/maxZoomFactor), then finally subtracting the default 
baseline offset for the font at the current zoom.  So it looks something like 
this:

float baselineAtMaxZoom = [layoutManager 
defaultBaselineOffsetForFont:fontAtMaxZoom];
float interpolatedBaselineAtCurrentZoom = baselineAtMaxZoom * factor / 
kWorkspaceMaxZoomFactor;
float offset = baselineAtCurrentZoom - [layoutManager 
defaultBaselineOffsetForFont:fontAtCurrentZoom];


 I've also tried using the same approach for line height, where I interpolate 
 what the line height should be given the line height at the max zoom level 
 (with the help of NSLayoutManager's defaultLineHeightForFont method), then 
 set the minimum and maximum line height of the paragraph style accordingly. 
 At some zoom levels, this works, but at other zoom levels, this make the 
 vertical offset even worse.
 
 Could anyone shed some light as to what the issue might be here?

___

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: Linearly Scaling Text

2011-05-29 Thread Ajay Sabhaney
Thanks Kyle, that's quite helpful.

We were initially hesitant to add the NSTextView directly to the layer-hosted 
view, however the following thread consoled us a little, especially since we 
were able to get geometry working correctly:
http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg21959.html

I'm going to try implementing a hierarchy similar to yours as it seems cleaner. 
The biggest issue I foresee is zooming in our application. Because the user can 
continually zoom (kind of like Google Maps), re-rendering the text at each zoom 
level will not only be expensive in terms of performance, but also will be 
jumpy since it is difficult to scale text linearly (in both the CALayer and 
the field editor), which goes back to the issue I mentioned in my original 
post.  Instead, using a hierarchy similar to yours, I hope I will be able to 
accomplish the following:

- Use a CALayer that has a text representation image that is constrained to the 
bounds of the layer, so that zooming is smooth. (No problems here - we already 
do this)
- When the user requires editing of a text box, we will add/show a scales 
layer-backed NSTextView.  I hope that there are no issues scaling an NSTextView 
that is layer-backed (either using NSView's scaleUnitSquareToSize method, or 
the bounds manipulation approach that TextEdit uses).

I will try this out and post my results on this thread.

PS. The OmniPlan beta is looking 
good!___

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


Linearly Scaling Text

2011-05-25 Thread Ajay Sabhaney
Hello list,

I am working on an application in which a user may insert, resize, and edit 
text boxes in a workspace.  We anticipate that a single user will have many 
(possibly hundreds) of text items in a workspace.  The user is also able to pan 
and zoom in/out of a workspace.  Because of the performance implications of 
such workspace transformations, our application uses image representations of 
the text all the time except when the user is editing the text or resizing the 
text box (in which case, the word wrapping will change).  When a user double 
clicks a text box, the image representation is hidden, and an NSTextView takes 
it's place.  When the user is done editing, the NSTextView instance is hidden 
and the image representation is re-generated and displayed.

Currently, zooming modifies the font sizes in the attributed string.  I.e. if 
the text in a particular text box is 12pt at 100%, then zooming to 200% 
increases the font size to 24pt.  Image representations of text are generated 
by using NSLayoutManager's drawGlyphsForGlyphRange:atPoint: method to draw the 
text to an image.  All text box image representations are rendered as if the 
zoom level is the max zoom level, so that regardless of the zoom level, the 
quality of the text is always high.

Everything works great, except that the text in a text box while it is being 
edited does not always perfectly overlap with the text from the image 
representation. The reason for this seems to be that the glyph metrics 
(particularly glyph advancement, line height, and baseline offset) do not scale 
linearly.

I have tried two approaches to fix this:

- Force linear scaling of text by changing the baseline offset, line height, 
and glyph advancement at any given zoom level.  I've tried using 
NSLayoutManager's defaultLineHeightForFont: and defaultBaselineOffsetForFont: 
methods to determine what these two attributes would be at the max zoom level, 
then interpolate what they should be at the current zoom level.  This hasn't 
really helped, as there is still a small vertical offset between the image 
representation and the text at the current zoom level.  As for setting the 
glyph advance, I'm not entirely sure of where to start with this, though my 
hunch would be to subclass NSTypesetter and override 
setLocation:withAdvancements:forStartOfGlyphRange:

- Instead of trying to scale text linearly, use a transformation to scale the 
NSTextView and image representation appropriately.  While this is easy to do 
with an image, I am having some issues scaling an NSTextView.  I've tried 
subclassing NSTextView, then in the drawRect method, I apply an affine 
transformation, then call the super's drawRect.  This almost works, except the 
caret acts as if no transformation was applied - it's size and position are 
unchanged even though the text is not.  I've also tried using the NSView method 
scaleUnitSquareToSize: - however this produces fuzzy text.

I would like to know if any of these approaches are correct/viable, and if they 
are, how would I go about solving the aforementioned challenges? If these 
approaches are incorrect, what direction should I take?

Thank you in advance.

Ajay
___

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


Shadow on a Borderless Window

2010-10-31 Thread Ajay Sabhaney
Hello list,

I am creating a window with a borderless style mask applied.  Even though 
content is drawn, the shadow of the window is much less intense than normal 
windows.  I've tried the setHasShadow: setter and using the invalidateShadow 
method, however neither work.  I've found one similar post 
(http://lists.apple.com/archives/cocoa-dev/2009/Sep/msg00388.html) which 
suggests this is a known issue, but wondering if anyone has had any luck 
getting around this? Although I'd like to ideally stay away from a private API, 
I might make an exception in this case if such a solution is possible.

Thank you,

Ajay


___

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 and Managed Object Context Question

2010-09-08 Thread Ajay Sabhaney
Hello list,

I have a Core Data based application with a simple data model.  There is an 
entity 'ItemContainer' which has a to-many relationship with the entity 'Item'. 
 An item model entity corresponds to a Core Animation layer, so when a new Item 
managed object is added to the ItemContainer managed object, a CALayer should 
be added to the view.  Currently, I'm observing (using KVO) the ItemContainer 
managed object.  Each time an item is added to the item container set, I 
receive a notification (change type is NSKeyValueChangeInsertion), and add a 
correspondingly add a Core Animation layer to the layer-hosting view.  A 
similar sort of thing happens when an item is removed from the item container 
set as well.  This all works very nicely - including the free undo and redo 
functionality provided by Core Data and the managed object context.

The problem is I'm not sure the best way to go about implementing document 
loading. 

I know NSArrayController offers the ability to bind to the managed object 
context (which I obtain from my NSPersistentDocument), which makes loading + 
fetching very simple.  However, if I use NSArrayController, and observe the 
arrangedObjects key of the array controller (as opposed to the item container 
set), I cannot get the newly added object (instead of getting 
NSKeyValueChangeInsertion type changes, I would get NSKeyValueChangeSetting 
type changes), which seems to be a problem that others have experienced as 
well.  It is important to get only the newly added/removed items since we would 
like to be able easily and efficiently add/remove only the necessary CALayers 
from the root layer.

As an aside, it seems that if I bind the contentSet property of the 
NSArrayController to the ItemContainer's items set, the loading does not work 
anymore, and arrangedObjects is empty after loading a document (which makes 
sense since the source set is empty).

So I'd like some insights on either how I could completely skip using the 
NSArrayController and automatically do a fetch after a document is loaded so 
that the model items become populated and I get the proper KVO notifications, 
OR, how to make the NSArrayController work in this context.  Or perhaps I am 
missing something altogether?

If possible, I would like to avoid:
1) Using an NSArrayController and on every KVO notification, look at the items 
that existed before the notification, looking at the items that exist after the 
notification, and determine the newly added items given the difference.
2) Using NSArrayController for the sake of loading, then once the 
loading/fetching is complete, continue to observe the item container set and 
disregard the NSArrayController (although this probably would work okay).

Thank you in advance.

Ajay



___

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: NSArrayController + KVO + Core Data Question

2010-08-23 Thread Ajay Sabhaney

On 2010-08-22, at 11:54 PM, Jerry Krinock wrote:

 
 it was *necessary*
 
 [emphasis added]
 
 for me to receive a KVO notification when either a new item was added to the 
 array controller, or removed from the array controller
 
 I'd say that this assumption is the problem.  What you probably *really need* 
 is a notification when relationships change in your *data model*.  I believe 
 the conventional approach would be to *observe your data model* instead of 
 array controller contents.  In other words, go right to the source.

Jerry, thank you for your response.  

Your solution is actually what I am currently doing =)

Like I state in my e-mail, I'm observing the content array of the 
NSArrayController, and am getting notifications perfectly fine.  I'm just 
wondering if there's a better way to do all this since I'm losing some of the 
free functionality provided by NSArrayController + Core Data.  One of the 
biggest things I'm losing out on is the free loading of documents in to my 
application.  The NSArrayController does a fetch and populates arrangedObjects, 
but this brings me back to the original problem of not being able to access the 
objects that were added to the array controller.

Perhaps I should give up the free functionality that Core Data is providing me 
and implement this functionality 
manually?___

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: NSArrayController + KVO + Core Data Question

2010-08-23 Thread Ajay Sabhaney
 I'm guessing, but you seem to have a managed object with a to-many 
 relationship, and you want to be notified whenever anything is added to or 
 removed from that relationship property. So, observe that property of the 
 managed object, and you're done.
 
 If there's something more complicated going on in the data model, your 
 solution may be more complex, but throwing NSArrayController at the problem 
 is highly unlikely to help with the solution.

Quincey, thank you for the follow up.  I do not think I explained my situation 
clearly so I will try and explain this more clearly.

I have a very simple data model.  There is only one entity: Item.  Each time I 
add or remove an Item to the array controller source, I would like my UI view 
to take action based on the newly added/removed Item.  More specifically: I 
have a very custom view, and each Item entity in the data model corresponds to 
a Core Animation layer in the view.  So if a particular Item entity is removed 
from the array controller, I'd like to remove a corresponding CALayer from the 
layer-hosting view.  And if a particular Item entity is added to the array 
controller, I'd like to add a corresponding CALayer to the layer-hosting view.

Currently, my view is observing the arrangedObjects property of 
NSArrayController.  However, all KVO notifications that the view receives are 
NSKeyValueChangeSetting type changes (as opposed to NSKeyValueChangeInsertion 
type changes).  I would like them to be NSKeyValueChangeInsertion changes so 
that I may easily add a CALayer corresponding to the newly added Item model.

So to overcome this, I binded the contentArray property of the 
NSArrayController to a mutable array of mine.  So each time I add an Item to 
the mutable array, the NSArrayController notifies my view, which takes the 
appropriate action.

[ I am doing something somewhat similar to what you see on the LAST post in 
this thread to ensure I receive NSKeyValueChangeInsertion type changes:
http://stackoverflow.com/questions/1313709 ]

In case you're wondering why I'm using an NSArrayController and not just an 
array, it is because NSArrayController currently ties in nicely with file 
loading and saving, as well as undo and redo.  I'm also using some of the 
selection functionality that NSArrayController provides.

Thinking about this a little more carefully, I'm not sure that using an 
NSArrayController actually is the best solution in this situation, especially 
as the data model and the view become more complex

Comments and suggestions in relation to this as well as my original post are 
appreciated___

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: NSArrayController + KVO + Core Data Question

2010-08-23 Thread Ajay Sabhaney
 I'm guessing, but you seem to have a managed object with a to-many 
 relationship, and you want to be notified whenever anything is added to or 
 removed from that relationship property.

I think I understand the confusion now.  I do not actually have a managed 
object that has a to-many relationship with the managed object 'Item'.  This is 
why I am having woes with the NSArrayController...how silly of me!

Thank you Quincey.




___

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: NSArrayController + KVO + Core Data Question

2010-08-23 Thread Ajay Sabhaney
 Try using a technique similar to the Department/Employees Core Data tutorial 
 in the documentation. That is, you can have a singleton object of a new 
 entity, (say, ItemSet), which has a to-many relationship items to all of 
 the Item objects. Bind the NSArrayController's content to the items 
 property of the ItemSet object, and I think you'll find that arrangedObjects 
 will give you the insert/delete notifications you want.

Yeah, I just removed the array controller and used an array.  I observe the 
array and you're correct, it works well - I am able to get the insert/delete 
notifications intended.

Thank you very much indeed.

 NSArrayController has no functionality related to loading, saving, undo or 
 redo. It can fetch objects from the store for you, and it can sometimes 
 create managed objects for you. But NSArrayController is in no way *part of* 
 Core Data.

What I meant by this is how the managed object context ties in with 
NSArrayController quite easily...

___

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 + KVO + Core Data Question

2010-08-22 Thread Ajay Sabhaney
Hello all,

In my Core Data based application, I have an NSArrayController, and it was 
necessary for me to receive a KVO notification when either a new item was added 
to the array controller, or removed from the array controller.  By looking in 
to some forums, I found out that I cannot do this by observing the 
arrangedObjects property in NSArrayController - some say this is a bug.  So 
instead, I binded the contentArray to a mutable array that I used to add and 
removed objects to or from.  In addition, I added array accessors for the 
mutable array so that the KVO would work as expected.  This now works 
beautifully, and I receive KVO notifications for object insertion and removal, 
as well as have the ability to see which objects were added or removed when 
observeValueForKeyPath:ofObject:change:context: is invoked.

However, in doing this, I lost some of the functionality that came for free 
with Core Data: undo/redo, load/save, etc.  I suppose this is because Core Data 
makes the changes to arrangedObjects (and the mutable array binded to 
contentArray is not touched), and I am no longer observing arrangedObjects.  I 
manually added some undo/redo functionality in the array accessors, but now 
thinking about how to do loading documents.  I would like to stay away from 
observing arrangedObjects, as then I would receive two KVO notifications for 
adding and removing objects in to the NSArrayController (one through the 
contentArray observation and one through the arrangedObjects observation).

I also thought about subclassing NSArrayController so that addObject: performs 
a KVO notifications like so:

[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes 
forKey:@arrangedObjects];
[super addObject:object];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:indexes 
forKey:@arrangedObjects];

This would alleviate the need to use the contentArray property.  However, I am 
assuming this would generate two KVO events - the new insertion notification 
(NSKeyValueChangeInsertion), and the existing change notification 
(NSKeyValueChangeSetting).  I would like to avoid this.

So my question is, is there an easy and efficient way to achieve what I am 
trying to do?

Thank you in advance.

Ajay

___

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: Odd Behaviour with CALayer

2010-06-18 Thread Ajay Sabhaney
Well, the problem seems to have been fixed.

I tried replacing every instance of MRWorkspaceItemLayer with a regular CALayer 
instance, and it seemed to work fine, meaning my problem was actually in the 
MRWorkspaceItemLayer subclass.  Seemed everytime I would unselect then select 
an item, the MRWorkspaceItemLayer would be destroyed, and then the message 
expecting model layer not copy: MRWorkspaceItemLayer would come up in the 
console.  So I overrided -initWithLayer: and -hitTest: , and now it seems to be 
fine.

Thanks for your comments

-AJ

On 2010-06-17, at 7:35 PM, Kyle Sluder wrote:

 On Thu, Jun 17, 2010 at 5:09 PM, Ajay Sabhaney co...@mothercreative.com 
 wrote:
 -The initializer initWithLayer: of my subclass of CALayer, 
 MRWorkspaceItemLayer is being invoked, even though I never explicitly invoke 
 this
 
 The documentation for -[CALayer initWithLayer:] describes how this
 method is used to create the layers for the presentation tree.
 
 
 -For when I handle the mouse down event, I tried changing my code from:
 
 CALayer *layer = [_rootLayer hitTest: where];
 
 to
 
 CALayer *presLayer = [_rootLayer presentationLayer];
 CALayer *layer = [presLayer hitTest: where];
 
 but now [[_rootLayer sublayers] indexOfObject:layer] is returning 
 NSNotFound,but I'm still looking in to this part...
 
 Of course, if _rootLayer is a model layer, it can't contain a
 presentation layer as a sublayer.
 
 Have you tried breaking on NSLog or perhaps write, to get a backtrace
 for the specific line this message is coming from?
 
 --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


Odd Behaviour with CALayer

2010-06-17 Thread Ajay Sabhaney
Hello list,

In my application, there are several CALayers (actually subclasses of CALayers) 
that are sublayers of my root layer.  The user can then drag these layers 
around and select them, etc.  Dragging works fine.

When a user selects/deselects one of the layers, the following code snippet is 
executed:

for( int i = 0; i  [[_workspaceLayer sublayers] count]; i++ ) {
  MRWorkspaceItemLayer *ab = [[_workspaceLayer sublayers] objectAtIndex:i];
  if ( [[_workspaceItemsController selectionIndexes] containsIndex:i] ) {
ab.borderColor=CGColorCreateGenericRGB(1.0f,1.0f,1.0f,1.0f);
ab.borderWidth=1.0;
  }
  else {
ab.borderWidth=0.0;
  }
}

However, I keep getting this output in my console: 


2010-06-17 02:49:13.464 Revapp[4838:a0f] expecting model layer not copy: 
MRWorkspaceItemLayer[(125,125)]


I tried wrapping that code in try/catch blocks, and apparently no exception is 
thrown.

What's even more peculiar is that when I comment out 
  ab.borderColor = ...
  ab.borderWidth = ...
statements, the weird console output does not appear

Or, when I comment out the 
  if ( [[_workspaceItemsController selectionIndexes] containsIndex:i] ) {
statement, the weird console output also does not appear!

A google search for expecting model layer not copy did not help either.

Anyone have any ideas as to what might be going on?

Thanks!

-Ajay___

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: Odd Behaviour with CALayer

2010-06-17 Thread Ajay Sabhaney

On 2010-06-17, at 5:19 PM, David Duncan wrote:

 On Jun 17, 2010, at 2:04 AM, Ajay Sabhaney wrote:
 
   ab.borderColor=CGColorCreateGenericRGB(1.0f,1.0f,1.0f,1.0f);
 
 Be aware that you are actually leaking a color here. Core Animation retains 
 all CF-type data that it gets, but since the compiler didn't support making a 
 CF type as retain-able this couldn't be declared in the property itself.

Oops, forgot to release colour, thanks

 
 2010-06-17 02:49:13.464 Revapp[4838:a0f] expecting model layer not copy: 
 MRWorkspaceItemLayer[(125,125)]
 
 What version of Mac OS X are you on?

10.6.4, although this was happening yesterday as well when I was using 10.6.3

For some reason, that message isn't showing up anymore, and I can't seem to 
reproduce it.  Now I'm getting a different message:

attempting to modify read-only layer MRWorkspaceItemLayer[(0,0)]

I don't know a whole lot about how the presentation and model are handled, but 
here are a couple things I noticed:

-The initializer initWithLayer: of my subclass of CALayer, MRWorkspaceItemLayer 
is being invoked, even though I never explicitly invoke this

-For when I handle the mouse down event, I tried changing my code from:

CALayer *layer = [_rootLayer hitTest: where];

to

CALayer *presLayer = [_rootLayer presentationLayer];
CALayer *layer = [presLayer hitTest: where];

but now [[_rootLayer sublayers] indexOfObject:layer] is returning 
NSNotFound,but I'm still looking in to this part... 

Thanks

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

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