The following lines of code in the Opening-Event of a DesktopCanvas create a simple NSVisualEffectView. Unfortunately, all code in the Paint-Event of the Canvas is now ignored and not drawn. How can this be fixed?
Declare Function Alloc Lib "/usr/lib/libobjc.dylib" Selector "alloc" (id As Ptr) As Ptr
Declare Sub AddSubview Lib "AppKit" Selector "addSubview:" (id As Ptr, subview As Ptr)
Declare Function GetBounds Lib "AppKit" Selector "bounds" (id As Ptr) As NSRect
Declare Function InitWithFrame Lib "AppKit" Selector "initWithFrame:" (id As Ptr, frame As NSRect) As Ptr
Declare Function NSClassFromString Lib "Foundation" (className As CFStringRef) As Ptr
Declare Sub SetAutoresizingMask Lib "AppKit" Selector "setAutoresizingMask:" (id As Ptr, value As UInteger)
Var oFrame As NSRect = GetBounds(Me.Handle)
Var oHandle As Ptr = InitWithFrame(Alloc(NSClassFromString("NSVisualEffectView")), oFrame)
SetAutoresizingMask(oHandle, 18)
AddSubview(Me.Handle, oHandle)
@Sam_Rowlands, you are probably right, however the drawings are not output. So, where is my error? I use the code from the first post in the Opening-Event and the following two lines in the Paint-Event:
Yes, I know your objection makes sense. So it seems to be about the order of views. So how can I put the main view of the DesktopCanvas above that of the NSVisualEffectView? Is that what you are trying to tell me?
Imma not be around forever, so what I’m trying to instill in you is not the solution, but how to find the solution. Google “NSView addSubView” to see what options are available, the solution is within Apple’s documentation. It will take some understanding to get there, but I’m sure you can do it with experimentation if you don’t first get how to use the alternative API.
I would also recommend as someone who’s being doing declare for a long time, including the classname in the declare as this will help you later when you need to double check Apple’s documentation, especially as they re-use API names. Try to use constants for the frameworks as every once in a bluemoon, Apple have changed the framework that certain API are nested in.
declare function NSView_bounds lib kLibAppKit selector "bounds" ( NSViewInstance as integer ) as NSRect
Declare Function GetFrame Lib "AppKit" Selector "frame" (id As Ptr) As NSRect
Declare Function InitWithFrame Lib "AppKit" Selector "initWithFrame:" (id As Ptr, frame As NSRect) As Ptr
Declare Function Alloc Lib "/usr/lib/libobjc.dylib" Selector "alloc" (id As Ptr) As Ptr
Declare Function NSClassFromString Lib "Foundation" (className As CFStringRef) As Ptr
Declare Sub SetAutoresizingMask Lib "AppKit" Selector "setAutoresizingMask:" (id As Ptr, value As UInteger)
Declare Function GetSuperview Lib "AppKit" Selector "superview" (id As Ptr) As Ptr
Declare Sub AddSubviewPositionedRelativeTo Lib "AppKit" Selector "addSubview:positioned:relativeTo:" (id As Ptr, aView As Ptr, place As Int8, otherView As Ptr)
Var oFrame As NSRect = GetFrame(Me.Handle)
Var oHandle As Ptr = InitWithFrame(Alloc(NSClassFromString("NSVisualEffectView")), oFrame)
SetAutoresizingMask(oHandle, 18)
Var oSuperview As Ptr = GetSuperview(Me.Handle)
AddSubviewPositionedRelativeTo(oSuperview, oHandle, -1, Me.Handle)