Don’t know how much you care for answers by our (maybe one day) technology overlords , but here’s what ChatGPT (GPT-4o) says about this…
The modern alternative to NSHUDWindowMask for creating HUD-style windows in macOS is to use the NSPanel class with specific configuration. Here’s how you can achieve a similar HUD-style effect in contemporary macOS development:
Use NSPanel:
An NSPanel is a subclass of NSWindow that is intended for utility or floating windows. It can be configured to look like a HUD.
Set Appearance to NSAppearanceNamedVibrantDark:
Assign the window’s appearance to the dark, vibrant style to give it the semi-transparent, HUD-like look.
Configure as Non-Closable or Non-Resizable:
To maintain the traditional HUD behavior, you can set the appropriate flags to disable resizing and other unnecessary functionality.
Use styleMask:
Add NSWindow.StyleMask.utilityWindow and NSWindow.StyleMask.fullSizeContentView for a utility-like appearance.
Add Your Custom Content:
Once you’ve created your custom NSPanel, you can add your content views as needed.
By doing this, you can replicate the HUD look and functionality in a way that aligns with modern macOS design principles. Using the vibrant dark appearance ensures compatibility with macOS’s system-wide light/dark mode settings.
So within Xojo, it’s probably just a matter of selecting the closest looking DesktopWidow.Type and then doing declares for the various look/feel and functional differences. But as it looks like you’re an MBS user, my guess is that NSPanelMBS will be your easiest go to.
Thank you Christian, that solves my initial problem, assuming HUD windows are not altogether deprecated.
If I try the following, I get what is pictured below:
// Window Type: Floating Window
// Has Close Button: True (all others False)
// in the Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titlebarAppearsTransparent = True
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
// HUD and other properties
w.isMovableByWindowBackground = True
Var NSWindowStyleMaskHUDWindow As UInt64 = Bitwise.ShiftLeft(1, 13) // 8192
w.styleMask = BitwiseOr(w.styleMask, NSWindowStyleMaskHUDWindow)
The HUD looks nice (including some vibrancy), but I don’t like how the TextField looks when it has focus.
Thank you Patrick, for your efforts. I’ve had my reservations about the AI overlords and so far I have not indulged, much, but I tried to replicate the overlord’s suggestion as best I could, with the following pictured results (which did not endear me to favour our future overlords…):
// Window Type: Floating Window
// Has Close Button: True (all others False)
// in the Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
w.titlebarAppearsTransparent = True
// other properties
w.isMovableByWindowBackground = True
Const NSWindowStyleMaskUtilityWindow As Integer = 16
w.styleMask = BitwiseOr(w.styleMask, w.NSFullSizeContentViewWindowMask + NSWindowStyleMaskUtilityWindow)
w.isOpaque = False
w.backgroundColor = NSColorMBS.clearColor
NSAppearanceMBS.setAppearance(Self, NSAppearanceMBS.appearanceNamed(NSAppearanceMBS.NSAppearanceNameVibrantDark))
Also note: NSUtilityWindowMask is also deprecated, but I’m assuming the replacement is NSWindowStyleMaskUtilityWindow with a value of 16 (same as the old constant?)
Because of the TextField focus problem with the HUD window, I’m going to think about this further. Maybe what I want is a hybrid?
As for my final implementation, I fiddled quite a bit to make the numbers in the TextField more readable, when the input has focus. But the HUD state appears to override the background and text colour assignments in strange ways. I was almost resigned to thinking that a custom control would be required, then I came up with the following in the Opening event of the DesktopTextField:
If Not Color.IsDarkMode Then
NSAppearanceMBS.setAppearance(Me, NSAppearanceMBS.appearanceNamed(NSAppearanceMBS.NSAppearanceNameAqua))
End If
It might be overkill, but it works nicely to revert the TextField back to its normal appearance. And fortunately in dark mode, the focus issue is not so much a problem.
The final code I’m using to create the HUD Window is the following:
// Window Type: Floating Window
// Has Close Button: True (all others False)
// in the DesktopWindow.Opening event
Var w As NSWindowMBS = Me.NSWindowMBS
// title bar appearance
w.titlebarAppearsTransparent = True
w.titleVisibility = NSWindowMBS.NSWindowTitleHidden
// other properties
w.isMovableByWindowBackground = True
Var NSWindowStyleMaskHUDWindow As UInt64 = Bitwise.ShiftLeft(1, 13) // 8192
w.styleMask = BitwiseOr(w.styleMask, NSWindowStyleMaskHUDWindow)