It is currently Mon Oct 21, 2019 4:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Workaround Darkmode CanvasGadget
PostPosted: Fri Apr 19, 2019 1:12 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1969
Location: Germany
Workaround Darkmode CanvasGadget
Code:
;-TOP

; Comment : Workaround Darkmode CanvasGadget PB v5.7x
; Version : v1.01
; Create  : 19.04.2019
; Update  :


Procedure CanvasSetGadgetBackgoundColor(Gadget, Color, NSColor = 0)
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    Protected sv, container, cnt, index, obj
    Protected Alpha.CGFloat, Blue.CGFloat, Green.CGFloat, Red.CGFloat
   
    If NSColor = 0
      Red = Red(Color) / 255
      Green = Green(Color) / 255
      Blue = Blue(Color) / 255
      Alpha = 1.0
      NSColor = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@",
                 @Red, "green:@", @Green, "blue:@", @Blue, "alpha:@", @Alpha)
    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:@", @NSColor)
        Next
      EndIf
    EndIf
  CompilerEndIf
EndProcedure

; *******************************************************************************

CompilerIf #PB_Compiler_IsMainFile
 
  Procedure RedrawCanvas0()
    ResizeGadget(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
    StartDrawing(CanvasOutput(0))
    Box(0, 0, GadgetWidth(0), GadgetHeight(0), $FF0000)
    Box(2, 2, GadgetWidth(0) - 4, GadgetHeight(0) - 4, $B48246)
    StopDrawing()
  EndProcedure
 
  Procedure RedrawCanvas3()
    ResizeGadget(5, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  EndProcedure
 
  Procedure SizeWindow()
    ResizeGadget(4, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Define Event
 
  ; ---------------------------------------------------------------------------
 
  If OpenWindow(0, 0, 0, 220, 220, "Canvas Container Workaround", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
   
    Define NSColor = CocoaMessage(0, WindowID(Window), "backgroundColor", 0)
   
    CanvasGadget(0, 0, 0, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 10, 10, 80, 30, "Button 1")
    CloseGadgetList()
   
    ScrollAreaGadget(2, 0, 0, 400, 400, 400, 400); #PB_Container_BorderLess)
    CanvasGadget(3, 0, 0, 400, 400, #PB_Canvas_Container)
    ButtonGadget(5, 10, 10, 80, 30, "Button 5")
    StringGadget(6, 10, 50, 200, 25, "Texte")
    TextGadget(7, 10, 90, 200, 60, "Hello World!")
    CloseGadgetList()
    CloseGadgetList()
   
    CanvasSetGadgetBackgoundColor(3, 0, NSColor)
    CanvasSetGadgetBackgoundColor(0, #Red)
   
    StartDrawing(CanvasOutput(3))
    Define x, y
    y = 0
    For x = 0 To 195 Step 10
      Box(x, y, 400-2*x, 400-2*y, RGB(Random(255), Random(255), Random(255)))
      y + 10        ; the same as y = y + 10
    Next x
    StopDrawing()
   
    SplitterGadget(4, 10, 10, 200, 200, 2, 0);, #PB_Splitter_Separator)
   
    RedrawCanvas0()
   
    BindEvent(#PB_Event_SizeWindow, @SizeWindow(), 0)
   
    BindGadgetEvent(0, @RedrawCanvas0(), #PB_EventType_Resize)
    BindGadgetEvent(2, @RedrawCanvas3(), #PB_EventType_Resize)
   
    Repeat
      Event = WaitWindowEvent()
     
    Until Event = #PB_Event_CloseWindow
   
  EndIf
 
CompilerEndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye