How to get default window background colour?

Linux specific forum
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to get default window background colour?

Post by Shardik »

remi_meier's example finds out the color of a gadget's current GTK style.
If you use SetWindowColor() to change the window's background color
this code won't detect the changed background color of a window or
gadget. You would have to define your own GTK style and apply it to
window and gadgets for this code to work.

I have tried a somewhat different approach by grabbing the window
background under the ImageGadget and combining it with a transparent
PNG image:

Code: Select all

ImportC "-lz" : EndImport

UsePNGImageDecoder()

Define Filename.S

InitNetwork()
ReceiveHTTPFile("http://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/300px-PNG_transparency_demonstration_1.png", GetCurrentDirectory() + "WikipediaTransparentTestImage.png")

If LoadImage(0, GetCurrentDirectory() + "WikipediaTransparentTestImage.png")
  OpenWindow(0, 100, 100, ImageWidth(0) + 25, ImageHeight(0) + 25, "Display transparent PNG image")
  SetWindowColor(0, RGBA(226, 199, 182, 255))

  ; ----- Wait until background color is applied

  Delay(20)
  While WindowEvent() : Wend

  ; ----- Grab background from window

  StartDrawing(WindowOutput(0))
    GrabDrawingImage(1, 10, 10, ImageWidth(0), ImageHeight(0))
  StopDrawing()

  ; ----- Draw transparent PNG image into background image

  StartDrawing(ImageOutput(1))
    DrawAlphaImage(ImageID(0), 0, 0, 255)
  StopDrawing()

  ImageGadget(0, 10, 10, ImageWidth(0), ImageHeight(0), ImageID(1), #PB_Image_Border)

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case  #PB_Event_Gadget
        If EventGadget() = 0
          If EventType() = #PB_EventType_LeftClick
            Debug "Left click onto image detected!"
          EndIf
        EndIf
    EndSelect
  ForEver
EndIf
This example was successfully tested in andLinux/Kubuntu 9.04, Ubuntu 11.10
and OpenSuSE 12.1.
Last edited by Shardik on Fri Dec 30, 2011 10:04 am, edited 1 time in total.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: How to get default window background colour?

Post by Kukulkan »

Thanks. I tested a little and remi's example never returned any color. It is, because gtk_style_lookup_color() allways fails. I don't know why and I checked some time and gave up.

The idea to create a window and get the default background from there is great. I will check this (maybe not every time but at the first start).

Thanks to both of you!

Best,

Kukulkan
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to get default window background colour?

Post by Shardik »

Kukulkan wrote:I tested a little and remi's example never returned any color. It is, because gtk_style_lookup_color() allways fails.
gtk_style_lookup_color() only seems to fail on distributions using KDE. All Gnome or
Xfce based distributions work:

Code: Select all

Linux distribution        Desktop manager   gtk_style_lookup_color()
---------------------     ---------------   ------------------------   
andLinux/Kubuntu 9.04          KDE 4                   -
Kubuntu 10.04 LTS              KDE 4                   -
Kubuntu 11.04                  KDE 4                   -
Linux Mint 12                 Gnome 3                  +
OpenSuSE 12.1                  KDE 4                   -
Ubuntu 11.10                  Gnome 3                  + 
Ubuntu 10.04 LTS              Gnome 2                  +
Xubuntu 11.04                  Xfce                    +
Post Reply