Recent

Author Topic: Changing TButton's color anyone? This should be easy!  (Read 9656 times)

lainz

  • Hero Member
  • *****
  • Posts: 4463
    • https://lainz.github.io/
Re: Changing TButton's color anyone? This should be easy!
« Reply #15 on: August 31, 2016, 07:49:41 pm »
Thank you everyone for your assistance. I haven't been in Delphi for a few years now, so I take it I wasn't using TButton then  :-\

1. Use TCustomButton from the Cutsom Drawn Controlhttp://wiki.freepascal.org/Lazarus_Custom_Drawn_Controls: Great start. Unfortunately, I couldn't find a way to customize the bevels and the edges.

2. Use fpGui or MSEGui. Both are great suggestions and are worth every consideration. Unfortunately, I've got too much invested already in this app to move over right now. Maybe later.

3. Use BCRA: It's a bit overkill for someone who just wanted to change the color of a button's face. On the other hand, its great for theming. I wasn't planning to theme my app but I'll be doing that now. I've toyed with it over the last few days and I'm getting the hang of it.

So, once more, thank you all for your support and your help. I would suggest though (and I'll add it as a suggestion) to turn the Color of a TButton int a read-only property, but come to think of it, the object inspector does not support read-only properties, does it now? But that's a question for another day.  :)

About Custom Drawn, you need to create a class that is:

Code: Pascal  [Select][+][-]
  1. TCDWin7 = class(TCDDrawerCommon)
  2.  
And override the method:

Code: Pascal  [Select][+][-]
  1. procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint;
  2.       ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override;
  3.  
And register the class:

Code: Pascal  [Select][+][-]
  1. initialization
  2. RegisterDrawer(TCDWin7.Create, dsWindows7);
  3.  
  4. finalization
  5.   win7.Free;

And assign the theme:

Code: Pascal  [Select][+][-]
  1. DefaultStyle := dsWindows7;

Check what units you need.

With fpGUI is the same, the class:
Code: Pascal  [Select][+][-]
  1. TMyStyle = class(TfpgStyle)

The method:
Code: Pascal  [Select][+][-]
  1. procedure DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord;
  2.       AFlags: TfpgButtonFlags); override;

The registration:
Code: Pascal  [Select][+][-]
  1. initialization
  2.   fpgStyleManager.RegisterClass('Demo Style', TMyStyle);

The switch of themes:
Code: Pascal  [Select][+][-]
  1. if fpgStyleManager.SetStyle('Demo Style') then
  2.       fpgStyle := fpgStyleManager.Style;

With MSEGui I have no idea.

With BGRA is just install and use, of course the way I use to set the styles is by code, is much easier:

Code: Pascal  [Select][+][-]
  1. procedure BCButtonWindows7(AButton: TBCButton);
  2. begin
  3.   AButton.Rounding.RoundX := 3;
  4.   AButton.Rounding.RoundY := 3;
  5.   AButton.RoundingDropDown.Assign(AButton.Rounding);
  6.  
  7.   with AButton.StateNormal do
  8.   begin
  9.     Background.Gradient1EndPercent := 50;
  10.     Background.Gradient2.Point1XPercent := 0;
  11.     Background.Gradient2.Point1YPercent := 0;
  12.     Background.Gradient2.Point2YPercent := 100;
  13.     Background.Gradient2.GradientType := gtLinear;
  14.     Border.Color := RGBToColor(112, 112, 112);
  15.     Border.LightWidth := 1;
  16.     Border.LightOpacity := 175;
  17.     Border.Style := bboSolid;
  18.     FontEx.Color := clBlack;
  19.     FontEx.Shadow := False;
  20.     FontEx.Style := [];
  21.   end;
  22.  
  23.   AButton.StateHover.Assign(AButton.StateNormal);
  24.   AButton.StateClicked.Assign(AButton.StateNormal);
  25.  
  26.   with AButton.StateNormal do
  27.   begin
  28.     Background.Gradient1.StartColor := RGBToColor(242, 242, 242);
  29.     Background.Gradient1.EndColor := RGBToColor(235, 235, 235);
  30.     Background.Gradient2.StartColor := RGBToColor(221, 221, 221);
  31.     Background.Gradient2.EndColor := RGBToColor(207, 207, 207);
  32.   end;
  33.  
  34.   with AButton.StateHover do
  35.   begin
  36.     Background.Gradient1.StartColor := RGBToColor(234, 246, 253);
  37.     Background.Gradient1.EndColor := RGBToColor(217, 240, 252);
  38.     Background.Gradient2.StartColor := RGBToColor(190, 230, 253);
  39.     Background.Gradient2.EndColor := RGBToColor(167, 217, 245);
  40.     Border.Color := RGBToColor(60, 127, 177);
  41.   end;
  42.  
  43.   with AButton.StateClicked do
  44.   begin
  45.     Background.Gradient1.StartColor := RGBToColor(229, 244, 252);
  46.     Background.Gradient1.EndColor := RGBToColor(196, 229, 246);
  47.     Background.Gradient2.StartColor := RGBToColor(152, 209, 239);
  48.     Background.Gradient2.EndColor := RGBToColor(104, 179, 219);
  49.     Background.Gradient1EndPercent := 55;
  50.     Border.Color := RGBToColor(44, 98, 139);
  51.     Border.LightOpacity := 100;
  52.     Border.LightColor := clBlack;
  53.   end;
  54. end;  

But as already said we don't have too much different controls, only Button (a lot of them, you choose), Label, ProgressBar, Panel, ToolBar, TrackBar, Knob, Shape, Animation, etc..

I think I can copy the source code of Custom Drawn and make new BGRA ones, or copy the code of fpGUI and make new BGRA ones :)

Or directly inherit from Custom Drawn ones and make a theme for them.

Edit: I'm working on it
http://forum.lazarus-ide.org/index.php/topic,33887.0.html
« Last Edit: August 31, 2016, 11:43:56 pm by lainz »

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Re: Changing TButton's color anyone? This should be easy!
« Reply #16 on: September 01, 2016, 07:44:41 am »
Hi Lainz,

I've been using BGRA for a few days now and I'm warming up to it. Yes, to your point, I've had to extend URibbon to add further configurations to make it work. It took me a few hours but at least now I can create a TFrame, slap a bunch of TBCButtons and know that they all follow the same style. That's a time saver.

I can see now how a style is powerful and very useful. Thanks for all of this.

Once I've got the visual side of my app working, I'll share back with you. I've got the FileMenu up and running, and I'm still working through some quirks.

Thanks for all your work! Much appreciated.

lainz

  • Hero Member
  • *****
  • Posts: 4463
    • https://lainz.github.io/
Re: Changing TButton's color anyone? This should be easy!
« Reply #17 on: September 01, 2016, 04:59:13 pm »
Hi Lainz,

I've been using BGRA for a few days now and I'm warming up to it. Yes, to your point, I've had to extend URibbon to add further configurations to make it work. It took me a few hours but at least now I can create a TFrame, slap a bunch of TBCButtons and know that they all follow the same style. That's a time saver.

I can see now how a style is powerful and very useful. Thanks for all of this.

Once I've got the visual side of my app working, I'll share back with you. I've got the FileMenu up and running, and I'm still working through some quirks.

Thanks for all your work! Much appreciated.

Thankyou!

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Changing TButton's color anyone? This should be easy!
« Reply #18 on: September 13, 2016, 10:49:17 am »
1. Use TCustomButton from the Cutsom Drawn Controlhttp://wiki.freepascal.org/Lazarus_Custom_Drawn_Controls: Great start. Unfortunately, I couldn't find a way to customize the bevels and the edges.

Yes, there is no out-of-the-box customization of bevel/edges with Lazarus Custom Drawn, the original question was about Colour which Laz Custom Drawn allows to change out-of-the-box easily by changing the "pallete", but you can write your own drawer to change the edges like you want.

 

TinyPortal © 2005-2018