Vibrancy to a Canvas

Thank you Ulrich.

I noticed when you deactivate the window it become grey. Is there a workaround for this so it always keeps it vibrancy?

Should be possible in the open event, Christoph: Change

EffectView.state = EffectView.NSVisualEffectStateFollowsWindowActiveState
to StateActive or StateInactive.

He, I just wanted to demonstrate the window to my wife and the project crashed after reopening it. I tried to assign NSImages I didn’t load yet. Glad you could make it work :wink:

Yes it crashes here too. But I only tried the code for getting the window vibrancy to work. :slight_smile:

Although StateInactive isn’t known, EffectView.state = 1 does work. Thanks again.

… and if you want to see it in full beauty :D, change this in NSCustomButton class:

Sub ChangeImage() if CurrentImage <> nil then me.ImageView.image = CurrentImage End Sub

I am working with NSImageNamed and didn’t notice that they are installed for fast access on the first run (where I didn’t load the currentImage on open initially), so they were available until I closed the project fully. Lesson 1 programming school: Always check for NIL before progressing. :wink:

Interesting… I never thought to set the background color of the window to clear! I’ve been trying different APIs and stylemask combinations to recreate this as we used to in older OS versions with no success.

Clear color… So simple, thanks Ulrich.

I learned a lot of tricks from you, Sam. Feels good to give back a small bit in return.

And I’m getting more and more confused in the similarities and differences between iOS and OS X. There is no NSImage with Insets yet on OS X, right? So, if you want to make the mask perform halfway fast, change the paint event to only fire the first time (create a “isInited” boolean or something which you set to true during the initial paint) and do another mask trick in the Resizing event. In every paint event it will flicker and be too slow, but in the resize it’s fast enough for real-time changes.
Although: I wish there was a NSImageWithIndents constructor. Would get one rid of all the resize handling.

Happy to have helped.

After having done Zero with iOS, Im not familiar with what you mean. Had a quick look at UIImage and think what you mean is something like “resizableImageWithCapInsets:”? AFAIK, the OS X equivalent can only be done when manually drawing the image, NSDrawNinePartImage takes 9 images, but you must draw it to something; which I don’t think will help in this case.

Alternatively you can create a NSImage with a Block, so in theory you could include the round rectangle drawing code within your block. I’ve not tried it, but that’s kinda cool. A dynamic image that’s actually source code…

I have heard that UIImage is coming to OS X and will replace NSImage in the future, apparently Apple’s Photos uses UIKit. Which gives some benefits at the expense of vector images. UIImage only supports bitmap images, while NSImage supports vector.

In the experiments that I tried; I created the mask (using NS drawing functions) when the window opened and the size had been set, but before it was shown. I’ve not tried to use this on a resizable window.

Photos uses a private framework called UXKit, which sort of sits atop UIKit and AppKit to let apps like Photos share more code across platforms.

This is just making convenient a capability NSImage has had since its inception (it previously required subclassing NSImageRep). The drawback is that the code has to be thread-safe, since it has no way of knowing when or on what thread it will be invoked.

I don’t why they didn’t simple call it ‘makeEveryThingLikeiOSKit’… (Not that you can blame them as Apple is now basically a phone company that happens to make other things).

Would this not work in Xojo then?

Yes, that was what I meant. I thought OS X would have that too. That’s the confusion I was talking about - both systems are that similar but then there’s big differences.
I had made a similar Xojo project with resizable images right at the beginning but I doubt there would be any performance boost included. But again it’s fast enough with a new mask created in the resize event. Although I’ll surely try a resizable mask in - did Apple say when? OS X 10.12? :wink:

I made that for iOSLib: AppleImage.FromContext. The draw methods classes like NSImage have now that draw directly on the current context make the code really easy to read and write now.
I forgot its name but there’s a neat app available building controls live from code. Would like to have that in Xojo too.

Really replace? UIImage has a lot of neat features, but I would doubt Apple will cut NSImage’s PDF/vector capabilities. Too many projects use that.

It’s really fast enough with a new mask NSImage in the redraw event: https://dl.dropboxusercontent.com/u/21200221/Xojo/uPhonia%20UI.mov

Yeah no… Us Mac Developers are 3rd party citizens, iPhones and iPads are Apple’s area of focus. Mac gets the leftovers. Remember the Mac is just a tool used to create iOS applications.

Sorry I got it wrong, it’s the UXKit, the one to unite all of Apple’s platforms. The one that’s used in Apple’s Photos. Maybe they’ll support vector throughout all platforms.

The surprising thing is that iOS doesn’t support vector already, after all iOS is a derivative of OS X and, at OS X’s core is a vector based graphics system.