Re: Drawing same text and graphics in different CGContextRef

2023-09-22 Thread David Duncan via Cocoa-dev


> On Sep 22, 2023, at 12:44 PM, JPH  wrote:
> 
> Hi David,
> 
> Trying  to understand the mechanism  you suggest  ( I am not familiar with 
> the concept of context pushing - poping :(I   )
> 
> NSGraphicsContext  * newcontext= 
> [NSGraphicsContex  
> graphicsContextWithCGContext:theprintContext flipped:YES] // theprintContext 
> obtained from PMSessionGetCGGraphicsContext(printSession, )
> [newcontext saveGraphicsState]; //Saves the current graphics state and 
> creates a new graphics state on the top of the stack.
>myDrawMethod( newcontext.CGContext)
> [NSGraphicsContext  
> restoreGraphicsState;]
> 
> Is this correct ?

You want NSGraphicsContext.currentContext (I had expected API similar to UIKit 
without looking it up, but it looks like you just have to save the current 
context, set your current context, and restore it afterwards).

> 
> All the best
> JP
> 
> 
> 
> 
> 
> 
>  
>a  graphic context created by myself  ( hence not the supplied on  by the 
> printing framework ) 
> 
>> Le 22 sept. 2023 à 17:59, David Duncan > > a écrit :
>> 
>> 
>> 
>>> On Sep 22, 2023, at 11:12 AM, JPH via Cocoa-dev >> > wrote:
>>> 
>>> I am facing the following  problems  in drawing text  and graphics in  
>>> CGContextRef of an NSview and Printing framework:
>>> 
>>> 1) drawing text  using:  [finalString drawInRect:textBox 
>>> withAttributes:attributes];
>>> Works nicely in my sub-classed NSViews  in  a  CGContextRef obtained in  
>>> the drawRect :  method with   CGContextRef viewCtx= [[NSGraphicsContext 
>>> currentContext] CGContext];
>>> But draws nothing in a print context obtained  
>>> PMSessionGetCGGraphicsContext(printSession, ); //( geometry is 
>>> perfectly previewed,Pdf’ed and printed except texts .. )
>>> 
>>> 2) filling a bezier path with a pattern Color
>>> 
>>> NSImage* nsPatImage= [[NSImage alloc] initWithCGImage:cgPatImage 
>>> size:NSZeroSize];
>>> NSColor* patternColor= [NSColor colorWithPatternImage:nsPatImage];
>>> [patternColor setFill];
>>> [bezierPath fill];
>>> 
>>> Works like a charm in the graphic context of NSView  and print nothing in a 
>>> print context.
>>> 
>>> I suspect this has something to do with the notion of  « Current context » 
>>> , as the context in NSView is explicitly the « currentContext »
>>> But not sure if  the printing  context is the « current  one » in the usual 
>>> print sequence ;
>> 
>> Correct. The current context is an AppKit concept, and you are working below 
>> AppKit in this code sequence – so you need to ensure the context is made 
>> current yourself. So you need to create an NSGraphicsContext, push it, and 
>> pop it, around your drawing code that relies on the current context. Since 
>> you pass the CGContext to myDrawMethod:, you could do this inside that 
>> method.
>> 
>>> err=   PMSessionBeginPageNoDialog(printSession, format )
>>> ctx =  PMSessionGetCGGraphicsContext(printSession, )
>>> [myDrawMethode: ctx] // [finalString drawInRect:textBox 
>>> withAttributes:attributes]; draws nothing in the printing context 
>>> PMSessionEndPageNoDialog(printSession);
>>> 
>>> I would appreciate any advice or suggestion regarding these points
>>> King regards
>>> JP
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ___
>>> 
>>> 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/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Drawing same text and graphics in different CGContextRef

2023-09-22 Thread David Duncan via Cocoa-dev


> On Sep 22, 2023, at 11:12 AM, JPH via Cocoa-dev  
> wrote:
> 
> I am facing the following  problems  in drawing text  and graphics in  
> CGContextRef of an NSview and Printing framework:
> 
> 1) drawing text  using:  [finalString drawInRect:textBox 
> withAttributes:attributes];
> Works nicely in my sub-classed NSViews  in  a  CGContextRef obtained in  the 
> drawRect :  method with   CGContextRef viewCtx= [[NSGraphicsContext 
> currentContext] CGContext];
> But draws nothing in a print context obtained  
> PMSessionGetCGGraphicsContext(printSession, ); //( geometry is perfectly 
> previewed,Pdf’ed and printed except texts .. )
> 
> 2) filling a bezier path with a pattern Color
> 
> NSImage* nsPatImage= [[NSImage alloc] initWithCGImage:cgPatImage 
> size:NSZeroSize];
> NSColor* patternColor= [NSColor colorWithPatternImage:nsPatImage];
> [patternColor setFill];
> [bezierPath fill];
> 
> Works like a charm in the graphic context of NSView  and print nothing in a 
> print context.
> 
> I suspect this has something to do with the notion of  « Current context » , 
> as the context in NSView is explicitly the « currentContext »
> But not sure if  the printing  context is the « current  one » in the usual 
> print sequence ;

Correct. The current context is an AppKit concept, and you are working below 
AppKit in this code sequence – so you need to ensure the context is made 
current yourself. So you need to create an NSGraphicsContext, push it, and pop 
it, around your drawing code that relies on the current context. Since you pass 
the CGContext to myDrawMethod:, you could do this inside that method.

> err=   PMSessionBeginPageNoDialog(printSession, format )
> ctx =  PMSessionGetCGGraphicsContext(printSession, )
> [myDrawMethode: ctx] // [finalString drawInRect:textBox 
> withAttributes:attributes]; draws nothing in the printing context 
> PMSessionEndPageNoDialog(printSession);
> 
> I would appreciate any advice or suggestion regarding these points
> King regards
> JP
> 
> 
> 
> 
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: CALayer shadows and CGContext clip rect

2023-01-03 Thread David Duncan via Cocoa-dev
While you may have solved your problem, your general approach is not one that 
would be recommended – CALayers are not meant to be drawn into a context, but 
rather added to a layer tree to be rendered by the system. For what you are 
doing you would likely have less issue and better performance drawing your 
shadows with AppKit or CoreGraphics directly instead of using CoreAnimation as 
an intermediary.

> On Jan 1, 2023, at 7:23 PM, David Young via Cocoa-dev 
>  wrote:
> 
> On Thu, Dec 15, 2022 at 08:59:24PM -0600, David Young via Cocoa-dev wrote:
>> Is it possible that a CGContext clip path will clip a shadow cast inside
>> the clip path, if the CALayer whose content cast the shadow is fully
>> outside of the clip path?  Any ideas why?
> 
> Just in case it helps somebody in the future: the answer seems to be
> "yes."  If I enlarge the frame of my sublayer (the layer whose drawn
> content actually casts the shadow) to enclose the entire shadow, then
> the shadow will not be clipped, even though I have set the shadow offset
> & opacity & radius on the superlayer.
> 
> I tried leaving the frame of the inner CALayer alone while enlarging
> the frame of the superlayer so that it enclosed the whole shadow.  That
> didn't help: the shadow was still clipped.
> 
> Dave
> 
> -- 
> David Young
> dyo...@pobox.comUrbana, IL(217) 721-9981
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: iOS UINavigation background removal.

2022-01-28 Thread David Duncan via Cocoa-dev


> On Jan 28, 2022, at 11:50 AM, Alex Zavatone  wrote:
> 
> Awesome.  Thank you, David.  
> 
> 
> I stumbled across this too while going through Apple documentation.  What’s 
> scary is that I have no idea why it works.
> 
> self.navigationController!.navigationBar.barStyle = .default
> self.navigationController!.navigationBar.isTranslucent = false
> self.navigationController!.navigationBar.titleTextAttributes = 
> [.foregroundColor: UIColor.white]
>   self.navigationController?.navigationBar.backgroundImage(for: .default)
> navigationController?.navigationBar.setBackgroundImage(UIImage(), 
> for: .default)

This stuff is pre-iOS 13 appearance customization. Using the new stuff will 
disable it.

> 
> let navBar = self.navigationController!.navigationBar
> let standardAppearance = UINavigationBarAppearance()
> standardAppearance.configureWithOpaqueBackground()
> standardAppearance.backgroundImage = UIImage()
> 
> navBar.standardAppearance = standardAppearance
> navBar.scrollEdgeAppearance = standardAppearance

With iOS 13 the navigation bar now has multiple appearance states. The 
scrollEdgeAppearance is when your bar is at the edge of a scroll view (top for 
a navigation bar, bottom for tab & toolbar). This configures the bar to use the 
same appearance state (in this case, a solid color background, using 
UIColor.systemBackgroundColor). In context the setting of backgroundImage 
doesn’t do anything (it defaults to nil and empty images have identical 
behavior).

By setting standardAppearance == scrollEdgeAppearance it in turn disables the 
“bar becomes transparent at the top” behavior introduced for large titles in 
iOS 13 and extended to all bar in iOS 15.

> 
> 
> Thanks again David.  You’re on my Christmas list.
> 
> Alex Zavatone
> 
>> On Jan 28, 2022, at 1:30 PM, David Duncan > > wrote:
>> 
>> UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
>> [appearance configureWithTransparentBackground];
>> navigationItem.standardAppearance = appearance;
>> 
>> Thats the simplest per-item way to do it. This does imply you adopt the new 
>> appearance APIs introduced in iOS 13.
>> 
>>> On Jan 28, 2022, at 11:03 AM, Alex Zavatone via Cocoa-dev 
>>> mailto:cocoa-dev@lists.apple.com>> wrote:
>>> 
>>> Hi there.  I’m in the middle of trying to find out how the hell to remove a 
>>> background from a UINavigationBar and it’s not easy.  You’d think that you 
>>> could get a UInavigationBar.navigationitem.background and remove it from a 
>>> superview or set its alpha to 0, but it’s not that easy.
>>> 
>>> Does anyone have any clue how to get a reference to the background once it 
>>> has been set so that it can be set to 0 alpha or removed from the 
>>> superview?  
>>> 
>>> Thanks in advance and happy Friday.  Apple sure has ways to make things 
>>> that should be simple very obscure and extremely deifficult to handle.  
>>> 
>>> Cheers, 
>>> Alex Zavatone
>>> ___
>>> 
>>> 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/david.duncan%40apple.com 
>>> 
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: iOS UINavigation background removal.

2022-01-28 Thread David Duncan via Cocoa-dev
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
[appearance configureWithTransparentBackground];
navigationItem.standardAppearance = appearance;

Thats the simplest per-item way to do it. This does imply you adopt the new 
appearance APIs introduced in iOS 13.

> On Jan 28, 2022, at 11:03 AM, Alex Zavatone via Cocoa-dev 
>  wrote:
> 
> Hi there.  I’m in the middle of trying to find out how the hell to remove a 
> background from a UINavigationBar and it’s not easy.  You’d think that you 
> could get a UInavigationBar.navigationitem.background and remove it from a 
> superview or set its alpha to 0, but it’s not that easy.
> 
> Does anyone have any clue how to get a reference to the background once it 
> has been set so that it can be set to 0 alpha or removed from the superview?  
> 
> Thanks in advance and happy Friday.  Apple sure has ways to make things that 
> should be simple very obscure and extremely deifficult to handle.  
> 
> Cheers, 
> Alex Zavatone
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Accessibility UIContentSizeCategory or current accessibility font setting

2021-10-18 Thread David Duncan via Cocoa-dev


> On Oct 18, 2021, at 10:51 AM, Alex Zavatone  wrote:
> 
> 
> 
>> On Oct 18, 2021, at 11:31 AM, David Duncan  wrote:
>> 
>> In general it's also preferred that you look at the traitCollection of the 
>> most relevant view for this information – there are contexts for which the 
>> content size category may not match the global value (and there is API on 
>> UIView to restrict the overall range that you can apply as well). This also 
>> means you can just use traitCollectionDidChange as your notification.
> 
> Is that issued when the program or screen first starts up?  I was using that 
> a few weeks ago for other accessibility settings, but wasn’t sure if it’s 
> issued when the font first appears, because there is no change.

Generally trait collection values should be reasonably correct at 
initialization time, anytime they change after that will send a 
traitCollectionDidChange call.

> 
> Thanks
> Alex Zavatone
> 
> 

___

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: Accessibility UIContentSizeCategory or current accessibility font setting

2021-10-18 Thread David Duncan via Cocoa-dev
In general its also preferred that you look at the traitCollection of the most 
relevant view for this information – there are contexts for which the content 
size category may not match the global value (and there is API on UIView to 
restrict the overall range that you can apply as well). This also means you can 
just use traitCollectionDidChange as your notification.

> On Oct 17, 2021, at 12:50 PM, Matt Jacobson via Cocoa-dev 
>  wrote:
> 
> Hey Alex,
> 
>> On Oct 17, 2021, at 2:51 PM, Alex Zavatone via Cocoa-dev 
>>  wrote:
>> 
>> We’ve got a situation where we need to check the current accessibility font 
>> size enum and apply custom settings to some attributed fonts.  I’ve seen 
>> that there is a way to check the current dynamic text size using SwiftUI, 
>> but I haven’t seen how to do it using UIKit.
>> 
>> I’ve seen that UIContentSizeCategory exists, but no idea how to see what the 
>> current value is.
>> 
>> Is anyone aware how to do this?  TIA.
> 
> Have you tried this?
> 
>   [UIApp preferredContentSizeCategory]
> 
> (Don’t forget to observe changes: UIContentSizeCategoryDidChangeNotification.)
> 
> Matt
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Scaling a UIImage

2020-11-02 Thread David Duncan via Cocoa-dev


> On Nov 2, 2020, at 3:20 PM, Carl Hoefs  wrote:
> 
> Okay. It was my understanding that -TIFFRepresentation was the only way to 
> get serializable image data bytes... What is a more efficient way to do this?

If you want serializable data bytes, sure, but thats not what you appear to be 
doing in the code you sent – you appear to want a bitmap representation. 
Presumably you go on to do something other than serialize it (as I imagine you 
want to draw it in some way).

In general if you want something you can draw, you can get a 
-CGImageForProposedRect:context:hints, and if you need an NSBitmapRep you can 
use -bestRepresentationForRect:context:hints:. But assuming your trying to get 
that NSImage somewhere other than into (say) an NSImageView, there may be 
better APIs or pathways to that solution.

> -Carl
> 
> 
>> On Nov 2, 2020, at 3:09 PM, David Duncan > > wrote:
>> 
>> Also any code using -TIFFRepresentation for any reason other than to get 
>> actual TIFF data is likely suspect. There are absolutely more efficient ways 
>> to do 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: Scaling a UIImage

2020-11-02 Thread David Duncan via Cocoa-dev


> On Nov 2, 2020, at 2:59 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> How can I correctly scale a UIImage from 3264x2448 down to 640x480 pixels?
> 
> 
> I have an iOS app that interacts with a macOS server process. The iOS app 
> takes a 3264x2448 camera image, scales it to 640x480 pixels, and makes a JPEG 
> representation of it to send to the server:
> 
>  NSData *dataObj = UIImageJPEGRepresentation(origImage,0.5);
> 
> The server reads the bytes, and creates an NSImage:
> 
>  NSImage *theImage = [[NSImage alloc] initWithData:imageData];
>  NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] 
> initWithData:[theImage TIFFRepresentation]];

Do you specifically need an NSBitmapImageRep? What is your next step here.

Also any code using -TIFFRepresentation for any reason other than to get actual 
TIFF data is likely suspect. There are absolutely more efficient ways to do 
this.

But which way you should do depends on your next step...

> 
> But at this point, imageRep.pixelsWide=1280 and imageRep.pixelsHigh=960!

You got 1280x960 because your on a 2x device and your resizing code didn’t 
specify a scale for the image (you passed 0.0, which means to use “native” 
scale).

> 
> If I write theImage to disk and look at it with Preview, it displays onscreen 
> as 640x480 but Preview's Inspector Tool shows it to be 1280x960.
> 
> On the iOS app side, here's the UIImage category method I'm using to scale 
> the image:
> 
> + (UIImage *)imageWithImage:(UIImage *)image 
>   scaledToSize:(CGSize)newSize 
> {
>UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);

Explicitly pass 1 here.

>[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
>UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
>UIGraphicsEndImageContext();
>return newImage;
> }
> 
> Any suggestions?
> -Carl
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Throttling drawing to vertical refresh

2020-10-23 Thread David Duncan via Cocoa-dev

> On Oct 23, 2020, at 8:54 AM, Andreas Falkenhahn  
> wrote:
> 
> Thanks, but once again, I still need a throttle because I obviously don't 
> want to call -setNeedsDisplay as often as the CPU permits, thereby causing 
> 100% CPU load. I still need some timer mechanism that only calls 
> -setNeedsDisplay every once in a while. So should I setup a timer based on 
> the monitor's refresh frequency rate that calls -setNeedsDisplay in intervals 
> of the monitor's vertical refresh rate or how is that supposed to be 
> implemented?
> 
> On 19.10.2020 at 01:22 David Duncan wrote:
> 
>> On Oct 18, 2020, at 2:37 AM, Andreas Falkenhahn via Cocoa-dev
>>  wrote:
> 
>> Not quite. AppKit throttle view refresh to 60fps but it certainly
>> won't throttle code that changes the gfx more often than that, i.e. 
>> something like this
> 
>>   for(;;) view.layer.contents = (id) getNextFrame();
> 
>> will hog the CPU. So I need some external timing mechanism to set
>> layer.contents not more often than necessary. I need to see if CADisplayLink 
>> can do that…
> 

It isn’t likely that code like "for(;;) view.layer.contents = (id) 
getNextFrame()” will actually work in a typical GUI based application. In 
particular, this setup prevents Core Animation from doing its “commit” phase, 
and so nothing will appear on screen (or if it does, it will appear by side 
effect, such as by doing this on a background thread and the main thread going 
a commit at effectively random intervals relative to this).

So yes, you should run a timer. But at the same time I would expect your code 
to know what the appropriate timing for calling “getNextFrame()” should be. If 
that method can literally be called at any time to generate a newly advanced 
frame, then just pick an upper limit and call -setNeedsDisplay as mentioned 
previously. This will allow you to effectively match what the built in commit 
logic can handle.

If you have precise timing needs, you can use a CVDisplayLink[Ref] to manage 
the timing. If you don’t, a simple NSTimer running at some target frequency 
should be plenty.
___

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: Problem in the creation of Graphics context(NSGraphicsContext)

2020-03-04 Thread David Duncan via Cocoa-dev
You’ll need to explain how you are creating the NSBitmapImageRep (what methods 
your calling, what parameters your passing, etc) that you pass to this method 
before anyone can explain why this might be going wrong for you.

> On Mar 3, 2020, at 10:19 PM, Sravan Kumar Lakkimsetti via Cocoa-dev 
>  wrote:
> 
> Hi,
> 
> 
> 
> In our product we use
> https://developer.apple.com/documentation/appkit/nsgraphicscontext/1529827-graphicscontextwithbitmapimagere?language=objc
> to create Graphics Context for drawing on top of image.
> 
> 
> 
> This particular API returns null in some cases. One particular case is
> troubling us. Would like to know why this happens and how to resolve
> 
> 
> 
> Here is the problem.
> 
> There are two monitors attached to Mac. Main display is retina display and
> secondary display is non-retina display. The application is moved from main
> display(retina display) to secondary display(non-retina display). In this
> case our application redraws the GUI(to use higher resolution images) In
> this process we are creating graphics context using the above api. This api
> returns null if the main display is retina and secondary display is
> non-retina.
> 
> 
> 
> It would be helpful if anyone can suggest on how to identify why this api
> returns null
> 
> 
> 
> Thanks
> 
> Sravan
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: UIView block-based methods

2019-11-11 Thread David Duncan via Cocoa-dev


> On Nov 9, 2019, at 12:09 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> I'm trying to keep some older iOS code going, but I'm getting a deprecation 
> warning on many UIView class methods:
> 
> +beginAnimations:context:
> +setAnimationBeginsFromCurrentState:
> +setAnimationDuration:
> +commitAnimations
> etc.
> 
> Xcode 11.2.1 says: "'beginAnimations:context:' is deprecated: first 
> deprecated in iOS 13.0 - Use the block-based animation API instead"
> 
> What is this 'block-based animation API’?

+[UIView animateWithDuration:animations:] and the like. 

> -Carl
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Subclassing NSCollectionViewFlowLayout

2019-10-21 Thread David Duncan via Cocoa-dev


> On Oct 21, 2019, at 3:26 AM, Arved von Brasch via Cocoa-dev 
>  wrote:
> 
> Hello list,
> 
> Thanks to someone on the list who provided me with a clue, I found that if I 
> add this to my NSCollectionViewItem subclass:
> 
> override func viewWillAppear() {
>super.viewWillAppear()
>view.removeConstraints(view.constraints)

Don’t do this – you don’t know what constraints may be attached to the view 
that you don’t know about.

>view.addConstraint(NSLayoutConstraint.init(item: view, attribute: 
> .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: 
> .notAnAttribute, multiplier: 1, constant: view.frame.size.width))
>view.addConstraint(NSLayoutConstraint.init(item: view, attribute: 
> .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: 
> .notAnAttribute, multiplier: 1, constant: view.frame.size.height))

This doesn’t really make a whole lot of sense – this is basically saying 
“whatever frame you have at this point, you will never be smaller than” which 
kinda defeats the whole purpose.

>}
> 
> the Collection View loads as expected and all the items appear at the proper 
> size regardless of window resizes. However, I do end up with a large number 
> of NSAutoresizingMaskLayoutConstraint clash errors.  Not quite sure how I’m 
> going to resolve this yet, but I thought I’d post it in case anyone else 
> follows in my footsteps.

Not too surprising, since the constraints you made are in direct conflict with 
these auto resizing mask constraints (since the auto resizing mask constraints 
basically tell the auto layout engine what the frame size will be).

> 
> Cheers,
> Arved
> 
> 
>> On 2019-10-20, at 21:54, Arved von Brasch  wrote:
>> 
>> Hello Cocoa List,
>> 
>> I’m in the process of porting a hobby project to up-to-date Swift so it can 
>> be used on Catalina (and I can upgrade my work machine - still looking for a 
>> QuickTime 7 Pro replacement, though).  I’ve encountered a phenomenon 
>> subclassing NSCollectionViewFlowLayout that I haven’t been able to resolve.
>> 
>> I have a Core Data backed NSArrayController feeding data to a 
>> NSCollectionView (still using XIBs, as that made the porting easier). That 
>> all works fine, although was surprisingly tricky to get going.  I 
>> implemented a NSCollectionViewFlowLayout subclass to provide a left 
>> justified layout. I then implemented the NSCollectionViewDelegateFlowLayout 
>> function sizeForItemAt: to provide custom sizes for my items.  This all 
>> works as intended during testing when the collection view is first loaded.  
>> However, if I resize the enclosing window, all the items reduce in size to 
>> what appears to be a single pixel and I can’t work out where the tiny size 
>> is coming from. My output of sizeForItemAt always seems to have sensible 
>> values, and I can’t see an obvious place for where else the collection view 
>> would be getting sizes from.
>> 
>> I’m only implementing an init function, to set the estimatedItemSize, 
>> sectionInset and spacing values, and then overriding 
>> layoutAttributesForElements, as that seems to be all that’s required for my 
>> use case. I do not have any headers or footers or sections in my scenario, 
>> so the Array Controller is pretty simple too, although it acts as the Data 
>> Source and Delegate for the Collection View.
>> 
>> Can anyone give me pointers for what I am screwing up? My web searches for 
>> this only return a meagre set of results which don’t help much.
>> 
>> Kind regards,
>> Arved
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Alerts in Xcode 11

2019-09-30 Thread David Duncan via Cocoa-dev
Instead of creating a new window and a root view controller in order to present 
your alert, just use (assuming self is a UIViewController) self.present(, animated:  completion: …)

> On Sep 30, 2019, at 5:48 PM, Doug Hardie  wrote:
> 
> Not sure how to do that.  It's not in any view controller as it is used in 
> virtually all of the various view controllers.  That's why I wanted it as a 
> function.
> 
> -- Doug
> 
>> On 30 September 2019, at 14:44, David Duncan  wrote:
>> 
>> What happens if you present it over your normal view controller hierarchy 
>> instead of using another window?
>> 
>> Has your application adopted UIWindowScene?
>> 
>>> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>>>  wrote:
>>> 
>>> I have some code that presents an alert to the user with information they 
>>> need, and an OK button to clear it.  It works fine in the previous Xcode 
>>> versions.  However, after upgrading to 11, it now displays the alert and 
>>> then immediately clears it.  This happens both in the simulator and on a 
>>> real device.  I have played around with the code and can't figure out how 
>>> to make it leave the alert on the screen.  This is in Swift.  It is a 
>>> function that is called from numerous places in the app.
>>> 
>>> func NotificationAlert (_ msg1: String, _ msg2: String) {
>>>  let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
>>> preferredStyle: .alert)
>>>  let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>>>  ErrorAlert.addAction(dismiss)
>>>  ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
>>> }
>>> 
>>> extension UIAlertController {
>>>  func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>>>  let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>>>  alertWindow.rootViewController = UIViewController()
>>>  alertWindow.windowLevel = UIWindow.Level.alert + 1;
>>>  alertWindow.makeKeyAndVisible()
>>>  alertWindow.rootViewController?.present(self, animated: animated, 
>>> completion: completion)
>>>  }
>>> }
>>> 
>>> 
>>> -- Doug
>>> 
>>> ___
>>> 
>>> 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/david.duncan%40apple.com
>>> 
>>> This email sent to david.dun...@apple.com
>> 
> 

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Alerts in Xcode 11

2019-09-30 Thread David Duncan via Cocoa-dev
What happens if you present it over your normal view controller hierarchy 
instead of using another window?

Has your application adopted UIWindowScene?

> On Sep 30, 2019, at 5:36 PM, Doug Hardie via Cocoa-dev 
>  wrote:
> 
> I have some code that presents an alert to the user with information they 
> need, and an OK button to clear it.  It works fine in the previous Xcode 
> versions.  However, after upgrading to 11, it now displays the alert and then 
> immediately clears it.  This happens both in the simulator and on a real 
> device.  I have played around with the code and can't figure out how to make 
> it leave the alert on the screen.  This is in Swift.  It is a function that 
> is called from numerous places in the app.
> 
> func NotificationAlert (_ msg1: String, _ msg2: String) {
>let ErrorAlert = UIAlertController(title: msg1, message: msg2, 
> preferredStyle: .alert)
>let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
>ErrorAlert.addAction(dismiss)
>ErrorAlert.presentInOwnWindow(animated: true, completion: nil)
> }
> 
> extension UIAlertController {
>func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
>let alertWindow = UIWindow(frame: UIScreen.main.bounds)
>alertWindow.rootViewController = UIViewController()
>alertWindow.windowLevel = UIWindow.Level.alert + 1;
>alertWindow.makeKeyAndVisible()
>alertWindow.rootViewController?.present(self, animated: animated, 
> completion: completion)
>}
> }
> 
> 
> -- Doug
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Pausing an animation

2019-09-17 Thread David Duncan via Cocoa-dev


> On Sep 17, 2019, at 1:19 PM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> I have a layer with two animations.
> 
> I would like to pause this animation occasionally .
> To do so, I set layer.speed = 0.0;
> 
> In the past, this has worked (with slightly different animations).
> However, in this case, the layer seems to just disappear. 
> (the layer occupies the whole screen, and when I set speed-0, the screen is 
> black)
> 
> Does anyone have an idea what might be the reason why it doesn't work?
> Are there properties that do not work with speed = 0?

Setting just the speed will often return you to the “beginning of time” for 
your CAMediaTiming compliant object (CALayer and CAAnimation the most common 
compliant objects).

 = ( - beginTime) * speed + timeOffset

So if you want to pause a layer, you also need to set the timeOffset to a value 
that matches the current value of 

QA1673 has a proper implementation for doing this 
>

> 
> Thanks a lot in advance.
> Gabriel.
> 
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: CABasicAnimation does not animate bounds.origin of a layer

2019-09-16 Thread David Duncan via Cocoa-dev


> On Sep 14, 2019, at 6:25 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Maybe, I haven't understood how the animation of the bounds property works,
> or the bounds property of a CALayer itself ,
> or I am making a stupid mistake.
> 
> Here is my code:
> 
>CALayer * imgLayer = [CALayer layer];
>imgLayer.contents= (__bridge id) imageRef;
>imgLayer.delegate= nil;
>imgLayer.opacity = 1.0;  
>imgLayer.anchorPoint  = CGPointMake( 0.0, 0.0 );
>imgLayer.zPosition   = -1.0;   
> 
>CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath: 
> @"bounds"];
>anim.timingFunction = [CAMediaTimingFunction functionWithName: 
> kCAMediaTimingFunctionLinear];
>anim.duration  = 5;// sec
>anim.autoreverses  = YES;
>anim.repeatCount  = 100;  // = 
> forever
> 
>NSRect from_rect = NSMakeRect( 100.0, 100.0, 200.0, 200.0 );
>anim.fromValue= [NSValue valueWithRect: from_rect ];
>NSRect to_rect = NSMakeRect( 200.0, 200.0, 300.0, 300.0 );
>anim.toValue = [NSValue valueWithRect: to_rect ];
> 
>[imgLayer addAnimation: anim forKey: @"myBoundsAnim"];
> 
> 
> What I am seeing is that the image gets scaled (from  200 to 300 
> width/height) which is fine,
> but it always sits in the lower left corner of the screen (I am working under 
> macOS).
> 
> I want the lower left corner of the image to be animated , too.
> (Eventually, the animation will be a bit more complex, but for now I am just 
> trying to understand this.)
> 
> What am I missing? or going wrong?
> 
> I guess I could achieve the effect by animating the position property of the 
> layer,
> but I'd rather prefer to understand what is going on.
> I have also re-read the "Core Animation Basics" , but it doesn't explain the 
> meaning of bounds.origin.
> In the drawings, it's always (0,0).

The bounds origin is the origin of the coordinate system for sublayers of that 
layer, and thus changing the bounds origin moves sublayers around. However, 
contents are affected by the contentsGravity of a layer, and the default 
gravity is “Resize” and so the image will be scaled to fill the layer.

If you want the image to move, you should animate the position of the layer, 
not the bounds.origin.

> 
> Thanks a lot in advance for any insights.
> 
> Best regards, Gabriel
> 
> 
> 
> 
> 
> 
> ___
> 
> 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/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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