Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-07

ColotToRGB in GTK apps

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Valdas Jankūnas

Hello,

i trying get R G B values of system color "clBackground" (and others). So i use ColorToRGB function (app compiled with gtk2 widget set), but I get values that differs from actual color of form face. I found that these values match to values defined in unit "GTKGlobals" in array "SysColorMap". Is this function not yet implemented or this is a bug?

Lazarus svn 15819; fpc 2.2.0 i386; Linux i386 Kubuntu 8.04

P.S.

I tried get rgb values with code:

function SpalvaToRGB(const color: TColor): TColor;
var
   drobe: TBitmap;
begin
     drobe:=TBitmap.Create;
     drobe.Height:=1;
     drobe.Width:=1;
     drobe.Canvas.Brush.Color:=color;
     drobe.Canvas.FillRect(0, 0, 1, 1);
     result:=drobe.Canvas.Pixels[0, 0];
     drobe.Free;
end;

but when I every time call this function passing clBackground, clForm or clColorDesktop as "color" i get random value. Why?

Valdas Jank?nas

Reply by email

Mattias Gaertner
to Valdas Jankūnas
Show quoted text 31 lines
Hello, i trying get R G B values of system color "clBackground" (and others). So i use ColorToRGB function (app compiled with gtk2 widget set), but I get values that differs from actual color of form face. I found that these values match to values defined in unit "GTKGlobals" in array "SysColorMap". Is this function not yet implemented or this is a bug? Lazarus svn 15819; fpc 2.2.0 i386; Linux i386 Kubuntu 8.04 P.S. I tried get rgb values with code: function SpalvaToRGB(const color: TColor): TColor; var drobe: TBitmap; begin drobe:=TBitmap.Create; drobe.Height:=1; drobe.Width:=1; drobe.Canvas.Brush.Color:=color; drobe.Canvas.FillRect(0, 0, 1, 1); result:=drobe.Canvas.Pixels[0, 0]; drobe.Free; end; but when I every time call this function passing clBackground, clForm or clColorDesktop as "color" i get random value. Why?

These constants depend on widget class and user theme. For example a button has a different background than a form. And many themes use images or gradients or transparency and do not define a default color. I don't know what you are trying to achieve, but maybe you can use the functions of the lcl themes unit.

Mattias

Reply by email

Valdas Jankūnas
to Mattias Gaertner

Mattias Gaertner ra??:

Show quoted text 19 lines
On Sat, 26 Jul 2008 21:55:03 +0300 Valdas Jank?nas wrote: > Hello, > > i trying get R G B values of system color "clBackground" (and > others). So i use ColorToRGB function (app compiled with gtk2 widget > set), but I get values that differs from actual color of form face. I > found that these values match to values defined in unit "GTKGlobals" > in array "SysColorMap". Is this function not yet implemented or this > is a bug? > > Lazarus svn 15819; fpc 2.2.0 i386; Linux i386 Kubuntu 8.04 These constants depend on widget class and user theme. For example a button has a different background than a form. And many themes use images or gradients or transparency and do not define a default color. I don't know what you are trying to achieve, but maybe you can use the functions of the lcl themes unit.

My goal is button with duotone glyph: i load grayscale glyph from resources, then change glyph colors from clBackground (white in source glyph) to clWindowText (black in source glyph), and then transfer modified image in to button glyph. So, if I want calculate color transition then I must have RGB values of clBackground and clWindowText. In Windoze this works well, but in Linux one day I noticed that colors are not correct.
I know only this way, but maybe is another (alpha channel?)?

Thanks, I take look at "themes.pas".

Valdas Jank?nas

Reply by email

Valdas Jankūnas
to Valdas Jankūnas

Hello,

I found solution: in unit GtkProc is procedure UpdateSysColorMap that updates SysColorMap array (from where ColorToRGB gets RGB values of system colors), but functionality of this procedure is disabled ("NewSysColors" is not defined). So i writed own procedure that based on code of mentioned procedure. Now this procedure I call in OnCreate and then ColorToRGB returns correct values.

Valdas Jank?nas

Reply by email

Mattias Gaertner
to Valdas Jankūnas
Show quoted text 8 lines
Hello, I found solution: in unit GtkProc is procedure UpdateSysColorMap that updates SysColorMap array (from where ColorToRGB gets RGB values of system colors), but functionality of this procedure is disabled ("NewSysColors" is not defined). So i writed own procedure that based on code of mentioned procedure. Now this procedure I call in OnCreate and then ColorToRGB returns correct values.

Thanks for the hint. I forgot that. I enabled it by default. This fixes the 'random' colors.
But remember that the rest of my mail still holds true: These values depend on theme and not every theme defines all values. So don't expect that your program will work on every machine.

Mattias

Reply by email

Valdas Jankūnas
to Mattias Gaertner

Mattias Gaertner ra??:

Show quoted text 14 lines
On Sun, 27 Jul 2008 15:26:34 +0300 Valdas Jank?nas wrote: > Hello, > > I found solution: in unit GtkProc is procedure UpdateSysColorMap > that updates SysColorMap array (from where ColorToRGB gets RGB values > of system colors), but functionality of this procedure is disabled > ("NewSysColors" is not defined). So i writed own procedure that based > on code of mentioned procedure. Now this procedure I call in OnCreate > and then ColorToRGB returns correct values. Thanks for the hint. I forgot that. I enabled it by default. This fixes the 'random' colors.

Thanks.

But remember that the rest of my mail still holds true: These values depend on theme and not every theme defines all values. So don't expect that your program will work on every machine.

Yes, I understand that.

Valdas Jank?nas

Reply by email