It is currently Sun May 19, 2013 1:39 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to get default window background colour?
PostPosted: Tue Dec 27, 2011 3:02 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 577
Location: germany
Hi,

I like to use runtime-generated buttons by using ImageGadgets. Sadly, I do not manage to use transparency on the ImageGadgets. Now, I like to fill the background at least with the current window background colour.

But GetWindowColor() does not return any value (-1) if I do not set it previously. :(

I found some GTK hints about getting the colour, but PB does not know the needed API functions. :| (http://developer.gnome.org/gtk/2.24/GtkStyle.html#gtk-style-get-style-property)

How to retrieve this colour?

Kukulkan

_________________
There is not nothing that not might happen.


Top
 Profile  
 
 Post subject: Re: How to get default window background colour?
PostPosted: Thu Dec 29, 2011 11:44 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
Hope this helps:
Code:
; fg_color
; bg_color
; base_color
; text_color
; selected_bg_color
; selected_fg_color
; tooltip_bg_color
; tooltip_fg_color
ImportC ""
  gtk_style_lookup_color.l(*style, color_name.p-utf8, *color)
  gdk_color_parse(name.p-utf8, *color_out)
EndImport
Procedure GetColor(*widget, color_name.s, *color_out.GdkColor)
  a.s = Space(Len(color_name))
  PokeS(@a, color_name, -1, #PB_Ascii)
 
  gtk_widget_realize_(*widget)
 
  *style.GtkStyle = gtk_rc_get_style_(*widget)
  If Not gtk_style_lookup_color(*style, a, *color_out)
    gdk_color_parse("black", @color)
  EndIf

EndProcedure


OpenWindow(0,0,0,0,0,"")
ButtonGadget(0, 0, 0, 0, 0, "")

color.GdkColor
GetColor(GadgetID(0), "fg_color", @color)

With color
  Debug (\red / 255) &$FF
  Debug (\green / 255) &$FF
  Debug (\blue / 255) &$FF
EndWith

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
 Post subject: Re: How to get default window background colour?
PostPosted: Fri Dec 30, 2011 9:57 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 813
Location: Germany
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:
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.

Top
 Profile  
 
 Post subject: Re: How to get default window background colour?
PostPosted: Fri Dec 30, 2011 10:02 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jun 06, 2005 2:35 pm
Posts: 577
Location: germany
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

_________________
There is not nothing that not might happen.


Top
 Profile  
 
 Post subject: Re: How to get default window background colour?
PostPosted: Fri Dec 30, 2011 10:51 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 813
Location: Germany
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:
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                    +


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

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