Find the Background Color used by GTK to render a window

Linux specific forum
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Find the Background Color used by GTK to render a window

Post by StarBootics »

Hello everyone,

OK this following code work fine with GTK 2 but don't work with GTK 3. Since I don't know what to think about it, I'm asking you ladies and gentleman.
Specially Fred and/or Freak who exactly what is going on under the PureBasic hood.

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : WindowBackgroundColor
; File Name : WindowBackgroundColor.pb
; File version: 1.0.0
; Programming : Unknow
; Programmed by : StarBootics
; Date : 25-09-2015
; Last Update : 25-09-2015
; PureBasic code : V5.40 LTS Beta 8
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; A dirty trick to get the color used by GTK to render a window. 
; The following code work fine with GTK 2 but don't work with GTK 3.
;
; Is there a bug with StartDrawing(WindowOutput(Window)) : Possible
; Is there a bug with Point(5, 5) : Possible
; Is there a bug with two commands used in conjunction : Possible
; Is there no bug at all, just impossible with GTK 3 : Possible
;
; Obtaining this color is usefull when you want to use a WebGadget 
; with a local html file. 
;
; With the window back color you just need to write a css file 
; telling the background color for the html file. The main 
; objective is to have a perfect match between the window back
; color and the background of the html file displayed by the 
; WebGadget().
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule WindowBackgroundColor
  
  Declare.l FindIt(Window)
  
EndDeclareModule

Module WindowBackgroundColor
  
  Procedure.l FindIt(Window)
    
    If StartDrawing(WindowOutput(Window))
      Color.l = Point(5, 5)
      StopDrawing()
    EndIf
    
    If Color = 0 
      Color = $ededed
      Debug "Generic grey Window Back color used !"
    EndIf
    
    ProcedureReturn Color
  EndProcedure
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  If OpenWindow(0,50,50,100,100, "")
    
    Color.l = WindowBackgroundColor::FindIt(0)
    
    Debug Red(Color)
    Debug Green(Color)
    Debug Blue(Color)
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    
  EndIf
  
CompilerEndIf

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Find the Background Color used by GTK to render a window

Post by StarBootics »

Almost 1 month and 200 views later and no reply so far !

Nobody else need to find the color being used by GTK 3 rendering engine according to the current theme. I will search for this when I will have plenty of time like next winter.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Post Reply