Code: Select all
EnableExplicit
#NSFullSizeContentViewWindowMask = 1 << 15
; --- Blending Modes ---
Enumeration
#NSVisualEffectBlendingModeBehindWindow
#NSVisualEffectBlendingModeWithinWindow
EndEnumeration
; --- Materials ---
Enumeration
#NSVisualEffectMaterialAppearanceBased
#NSVisualEffectMaterialLight
#NSVisualEffectMaterialDark
#NSVisualEffectMaterialTitlebar
EndEnumeration
; --- Visual Effect State ---
Enumeration
#NSVisualEffectStateFollowsWindowActiveState
#NSVisualEffectStateActive
#NSVisualEffectStateInactive
EndEnumeration
Enumeration
#NSWindowTitleVisible
#NSWindowTitleHidden
EndEnumeration
; --- PureBasic Glass Material Constants ---
#GlassWindow_Light = 1
#GlassWindow_Dark = 2
#GlassWindow_Lighter = 3
#GlassWindow_LiquidGlass = 20 ; macOS 15+ only
Global blurryView.i
; --- Helper to switch materials dynamically ---
Procedure SetGlassMaterial(materialType.i)
CocoaMessage(0, blurryView, "setMaterial:", materialType)
EndProcedure
; --- Build the demo window ---
If OpenWindow(0, 200, 200, 520, 500, "Glass UI Demo", #PB_Window_Invisible | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
Define Frame.NSRect
Frame\size\width = WindowWidth(0)
Frame\size\height = WindowHeight(0)
Define Window0_ID = WindowID(0)
Define styleMask = CocoaMessage(0, Window0_ID, "styleMask") | #NSFullSizeContentViewWindowMask
CocoaMessage(0, Window0_ID, "setStyleMask:", styleMask)
CocoaMessage(0, Window0_ID, "setTitleVisibility:", #NSWindowTitleHidden)
CocoaMessage(0, Window0_ID, "setTitlebarAppearsTransparent:", #YES)
; **Make the window background transparent**
CocoaMessage(0, Window0_ID, "setOpaque:", #NO)
CocoaMessage(0, Window0_ID, "setBackgroundColor:", CocoaMessage(0, 0, "NSColor clearColor"))
; --- Create blur view background ---
blurryView = CocoaMessage(0, CocoaMessage(0, 0, "NSVisualEffectView alloc"),
"initWithFrame:@", @Frame)
; CocoaMessage(0, blurryView, "setBlendingMode:", #NSVisualEffectBlendingModeWithinWindow)
; CocoaMessage(0, blurryView, "setMaterial:", #GlassWindow_Light)
; CocoaMessage(0, blurryView, "setState:", #NSVisualEffectStateActive)
CocoaMessage(0, CocoaMessage(0, Window0_ID, "contentView"), "addSubview:", blurryView)
; --- Popup to select material ---
TextGadget(10, 20, 10, 120, 20, "Select Material:")
ComboBoxGadget(11, 150, 10, 150, 25)
AddGadgetItem(11, -1, "Light")
AddGadgetItem(11, -1, "Dark")
AddGadgetItem(11, -1, "Lighter")
AddGadgetItem(11, -1, "LiquidGlass (macOS 15+)")
SetGadgetState(11, 0) ; Default to Light
; --- Add sample UI gadgets to test rendering ---
TextGadget(0, 20, 50, 280, 24, "Welcome to the Glass Demo")
StringGadget(1, 20, 80, 280, 26, "")
SetGadgetText(1, "Type here...")
ButtonGadget(2, 20, 120, 120, 30, "Click Me")
CheckBoxGadget(3, 20, 160, 200, 24, "Enable Fancy Mode")
TrackBarGadget(4, 20, 200, 280, 30, 0, 100)
SetGadgetState(4, 50)
TextGadget(5, 20, 240, 280, 20, "Move the slider above!")
EditorGadget(6,300,300,160,160)
SetGadgetColor(6,#PB_Gadget_BackColor,#Black)
HideWindow(0, #False)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 2
MessageRequester("Glass Demo", "Button clicked!")
Case 3
If GetGadgetState(3)
SetGadgetText(5, "Fancy Mode Enabled!")
Else
SetGadgetText(5, "Fancy Mode Disabled!")
EndIf
Case 4
SetGadgetText(5, "Slider at " + Str(GetGadgetState(4)) + "%")
Case 11 ; Material selector
Select GetGadgetState(11)
Case 0 : SetGlassMaterial(#GlassWindow_Light)
Case 1 : SetGlassMaterial(#GlassWindow_Dark)
Case 2 : SetGlassMaterial(#GlassWindow_Lighter)
Case 3 : SetGlassMaterial(#GlassWindow_LiquidGlass)
EndSelect
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf