GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 18, 2014 3:50 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 10:14 am 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Dear friends,
though this might be Fedora(or gnome shell theme Adwaita) specific problem, I cannot get color from

Code:
GdkColor colorRed2 = {0x0000, 65535, 29555, 24158};
gtk_widget_modify_bg(button, GTK_STATE_NORMAL, &colorRed2);


So, I am trying to use
Code:
gtk_widget_override_background_color (Hbutton, GTK_STATE_NORMAL, GdkRGBA(0,0,0,1.));

ofcourse, this is not the way to use RGBA.
What is the correct way of using it?


Top
 Profile  
 
 Post subject: Re: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 11:08 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

GdkRGBA is normal struct. Just create this struct and pass pointer to the function call.

Code:
GdkRGBA color = {.0, .0, .0, 1.0};
gtk_widget_override_background_color (Hbutton, GTK_STATE_NORMAL, &color);


Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 11:30 am 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Tadej,
Thanks for your reply.
So, I have edited my code as following:
Code:
    GtkWidget *Hbutton = gtk_button_new_with_label("H");
    gtk_widget_modify_fg(Hbutton, GTK_STATE_NORMAL, &colorBlue);
    gtk_widget_override_background_color(Hbutton, GTK_STATE_NORMAL, &colorRed);
    gtk_grid_attach(GTK_GRID(grid), Hbutton, 0, 1, 1, 1);

    /* Create second button */
    GtkWidget *Hebutton = gtk_button_new_with_label("He");
    gtk_widget_override_background_color(Hebutton, GTK_STATE_NORMAL, &colorRed2);
    gtk_grid_attach(GTK_GRID(grid), Hebutton, 1, 1, 1, 1);

But, as I had a elaborate discussion with zerohour here,
this is probably problem with the shell theme, as override don't solve the problem(buttons are showing color only when not in focus). This is a confirmed problem of the Adwaita theme, as I get the desired effect if I use other GTK+ themes(Like High(/Low)Contrast etc).
So, any advice please?


Top
 Profile  
 
 Post subject: Re: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 11:45 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
The only issue I see is that the type is const GdkRGBA* rather than the GdkRGBA I think you are setting up in which case you probably need a & out front or a * in the declaration.
Always done it more longhand myself as I guess I just feel an address should have a variable declaration on which to base itself rather than trying to inline it all. Something like the following should work:
Code:
GdkRGBA colour;

{colour.red=0; colour.green=0; colour.blue=0; colour.alpha=1;}
gtk_widget_override_background_color (Hbutton, GTK_STATE_NORMAL, &colour);


Ah I see tadej already beat me too it with a shorter one.
by the way, its the same when dealing with other _set_rgba functions such as gtk_color_selection_set_current_rgba. The gtk_widget_modify_bg function is also depreciated in gtk3 which is good because GdkColor was always a pain to use. GdkRGBA integrates naturally with cairo and will make things easier all round.


Top
 Profile  
 
 Post subject: Re: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 12:05 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
rudra wrote:
...as override don't solve the problem(buttons are showing color only when not in focus)...

I would think this would be the case no matter what the theme.
As you can see gtk_widget_override_background_color takes GtkStateFlags. One being GTK_STATE_FLAG_NORMAL, another being GTK_STATE_FLAG_FOCUSED etc. In order to have a certain colour when focused I imagine you would have to call this function again with each of the GtkStateFlags you want overridden.
It is possible that on certain distros the default settings may be linked so if you override one it will trickle over to others. Not too sure. I generally prefer not to touch styling /theming as this can stuff up the accessibility of a program if the user can't override it in turn.


Top
 Profile  
 
 Post subject: Re: how I can use gdkRGBA
PostPosted: Thu Oct 11, 2012 12:31 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Thanks Paul,
I tried
Code:
gtk_widget_override_background_color(Hbutton, GTK_STATE_FLAG_ACTIVE(/FOCUSED/NORMAL), &colorRed);

but nothing changed.
Few weeks back. I raised the issue in fedora forumas well.

So, does it sounds like I have to move to forbidden region of changing the theme as the only option?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group