macOS High Sierra transparency problem.

Mac OSX specific forum
HarrysLad
User
User
Posts: 57
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

macOS High Sierra transparency problem.

Post by HarrysLad »

I use the code below to display a splash-screen (a grey 'sphere' on a transparent background in this example). It all works as intended on Windows and OSX up to macOS Sierra but the transparency fails on macOS High Sierra.
Oddly, the square background appears black on the screen but white when I take a screen-shot.

This is the same for both retina and non-retina displays.

The sphere image (sphere.png):
Image

Sierra:10.12.6
Image

High Sierra:10.13.3
Image

Code: Select all

; sphere.pb
; display a sphere on a transparent background
;


Procedure PreMultiply(image)
  
  StartDrawing(ImageOutput(image))
    DrawingMode(#PB_2DDrawing_AllChannels)
    For j = 0 To ImageHeight(image)-1
      For i = 0 To ImageWidth(image)-1
        color = Point(i,j)
        Plot(i, j, RGBA(Red(color)   & $FF * Alpha(color) & $FF / $FF,
                       Green(color)  & $FF * Alpha(color) & $FF / $FF,
                       Blue(color)   & $FF * Alpha(color) & $FF / $FF,
                       Alpha(color)))
      Next
    Next
    StopDrawing()
    
EndProcedure

ExamineDesktops() 

Enumeration
  
  #WINDOW_SPLASH
  #SPLASH_MEMORY
  
EndEnumeration

UsePNGImageDecoder()
CatchImage(#SPLASH_MEMORY, ?Sphere)
size = ImageWidth(#SPLASH_MEMORY)

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  
  OpenWindow(#WINDOW_SPLASH, (DesktopWidth(0)-size)/2, (DesktopHeight(0)-size)/2, size, size, "", #PB_Window_BorderLess|#PB_Window_Invisible)
  CopyImage(#SPLASH_MEMORY, #WINDOW_SPLASH)
  CocoaMessage(0, WindowID(#WINDOW_SPLASH), "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(#WINDOW_SPLASH)))
  CocoaMessage(0,WindowID(#WINDOW_SPLASH),"setHasShadow:",#YES)
  HideWindow(#WINDOW_SPLASH, #False)
  
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
  
  PreMultiply(#SPLASH_MEMORY)
  OpenWindow(#WINDOW_SPLASH, (DesktopWidth(0)-size)/2, (DesktopHeight(0)-size)/2, size, size,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
  SetWindowLongPtr_(WindowID(#WINDOW_SPLASH), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(#WINDOW_SPLASH), #GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
  hDC = StartDrawing(ImageOutput(#SPLASH_MEMORY))
    With sz.SIZE
      \cx = ImageWidth(#SPLASH_MEMORY)
      \cy = ImageHeight(#SPLASH_MEMORY)
    EndWith
    With BlendMode.BLENDFUNCTION
      \SourceConstantAlpha = 255
      \AlphaFormat = 1
    EndWith
    UpdateLayeredWindow_(WindowID(#WINDOW_SPLASH),0,0,@sz,hDC,@ContextOffset.POINT,0,@BlendMode,2)
  StopDrawing()
    
CompilerEndIf

AddKeyboardShortcut(#WINDOW_SPLASH, #PB_Shortcut_Escape,2)
StartTime.q = ElapsedMilliseconds()

Repeat
  If WaitWindowEvent(1) = #PB_Event_Menu And EventMenu() = 2 
    Break
  EndIf
Until ElapsedMilliseconds() - StartTime > 10000 

CloseWindow(#WINDOW_SPLASH)
End

DataSection

  Sphere:
  IncludeBinary "sphere.png" 
  
EndDataSection

Any ideas what I need to do to get the High Sierra transparency back?
kmitko
New User
New User
Posts: 3
Joined: Sat Jan 13, 2018 12:13 pm
Location: Gliwice, Poland

Re: macOS High Sierra transparency problem.

Post by kmitko »

Works for me if I add setOpaque:NO after colorWithPatternImage.

Code: Select all

  CocoaMessage(0, WindowID(#WINDOW_SPLASH), "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(#WINDOW_SPLASH)))
  CocoaMessage(0,WindowID(#WINDOW_SPLASH),"setHasShadow:",#YES)
  CocoaMessage(0, WindowID(#WINDOW_SPLASH), "setOpaque:", #NO)
macOS High Sierra, PB 5.61 (x64)
HarrysLad
User
User
Posts: 57
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

Re: macOS High Sierra transparency problem.

Post by HarrysLad »

Thanks for that kmitko.
CocoaMessage(0, WindowID(#WINDOW_SPLASH), "setOpaque:", #NO) works for me too.
Is this just a change of the default settings between 10.12.6 and 10.13.3?
Are there any other changes that you know about?

Dave
kmitko
New User
New User
Posts: 3
Joined: Sat Jan 13, 2018 12:13 pm
Location: Gliwice, Poland

Re: macOS High Sierra transparency problem.

Post by kmitko »

I'm not sure what's changed, I've only switched to Pure Basic recently. I remember having to set this when I tried to learn Objective C.
macOS High Sierra, PB 5.61 (x64)
Post Reply