Hatte zu viel Zeit.
Aber Linux muss eine Macke haben, Unter Windows und macOS läuft es.
Code: Alles auswählen
;-TOP
; Comment : Workaround Darkmode CanvasGadget PB v5.7x
; Version : v1.02
; Create  : 19.04.2019
; Update  : 12.08.2019
; OS      : macOS
Procedure CanvasSetGadgetBackgoundColor(Gadget, BackColor = #PB_Ignore)
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    Protected sv, container, cnt, index, obj, NSBackColor
    Protected Alpha.CGFloat, Blue.CGFloat, Green.CGFloat, Red.CGFloat
    
    If BackColor <> #PB_Ignore
      Red = Red(BackColor) / 255
      Green = Green(BackColor) / 255
      Blue = Blue(BackColor) / 255
      Alpha = 1.0
      NSBackColor = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @Red, "green:@", @Green, "blue:@", @Blue, "alpha:@", @Alpha)
    Else
      NSBackColor = CocoaMessage(0, 0, "NSColor windowBackgroundColor")
    EndIf
    
    sv = CocoaMessage(0, GadgetID(Gadget), "subviews")
    If CocoaMessage(0, sv, "count")
      container = CocoaMessage(0, sv, "objectAtIndex:", 0)
      If container
        sv = CocoaMessage(0, container, "subviews")
        cnt = CocoaMessage(0, sv, "count") - 1
        For index = 0 To cnt
          obj = CocoaMessage(0, sv, "objectAtIndex:@", @index)
          CocoaMessage(0, obj, "setBackgroundColor:", NSBackColor)
        Next
      EndIf
    EndIf
  CompilerEndIf
EndProcedure
; ****
Enumeration Windows
  #Main
EndEnumeration
Enumeration Gadgets
  #MainScrollArea
  #MainCanvas
EndEnumeration
Enumeration Status
  #MainStatusBar
EndEnumeration
Global NewList listButtons()
Procedure DrawCanvas()
  Protected dx, dy, x, y, c0, c1, c2, toggle
  c1 = #Red
  c2 = #Yellow
  dx = GadgetWidth(#MainCanvas)
  dy = GadgetHeight(#MainCanvas)
  If StartDrawing(CanvasOutput(#MainCanvas))
    For x = 0 To dx Step 20
      For y = 0 To dy Step 20
        If toogle
          toogle = #False
          c0 = c2
        Else
          toogle = #True
          c0 = c1
        EndIf
        Box(x, y, 20, 20, c0)
      Next
    Next
    StopDrawing()
  EndIf
EndProcedure
Procedure AddCanvasButton()
  Protected x, y
  x = GetGadgetAttribute(#MainCanvas, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(#MainCanvas, #PB_Canvas_MouseY)
  Debug "New Button on " + x + "/" + y
  AddElement(listButtons())
  OpenGadgetList(#MainCanvas)
  listButtons() = ButtonGadget(#PB_Any, x - 1, y - 1, 40, 40, "X")
  CloseGadgetList()
  ; Fix macOS gadget backgoundcolor on canvas gadget container
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    CanvasSetGadgetBackgoundColor(#MainCanvas)
  CompilerEndIf
EndProcedure
  
Procedure DoEventSizeWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
  ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
Procedure Main()
  Protected dx, dy, dx2, dy2, gadget
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
    dx2 = 1600
    dy2 = 1600
    
    ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx2, dy2)
    CanvasGadget(#MainCanvas, 0, 0, dx2, dy2, #PB_Canvas_Container)
    CloseGadgetList() ; Canvas
    CloseGadgetList() ; ScrollArea
    
    DrawCanvas()
    
    BindEvent(#PB_Event_SizeWindow, @DoEventSizeWindow(), #Main)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainCanvas
              If EventType() = #PB_EventType_LeftClick
                AddCanvasButton()
              EndIf
              
            Default
              gadget = EventGadget()
              ForEach listButtons()
                If listButtons() = gadget
                  Debug "CanvasButton " + ListIndex(listButtons())
                  Break
                EndIf
              Next
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()