umain.pas 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. unit umain;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  6. BCButtonFocus, BCTypes;
  7. type
  8. { TaForm }
  9. TaForm = class(TForm)
  10. BCButtonFocus1: TBCButtonFocus;
  11. procedure FormCreate(Sender: TObject);
  12. private
  13. public
  14. end;
  15. var
  16. aForm: TaForm;
  17. implementation
  18. uses
  19. bcbrightandcontrast;
  20. {$R *.lfm}
  21. { TaForm }
  22. procedure BCButtonWindows8(AButton: TBCButtonFocus; cl1, cl2: TColor);
  23. begin
  24. AButton.Rounding.RoundX := 1;
  25. AButton.Rounding.RoundY := 1;
  26. AButton.RoundingDropDown.Assign(AButton.Rounding);
  27. with AButton.StateNormal do
  28. begin
  29. Background.Style := bbsColor;
  30. Background.Color := cl1;
  31. Border.Style := bboSolid;
  32. Border.Width := 1;
  33. Border.Color := cl1;
  34. Border.LightWidth := 0;
  35. Border.LightOpacity := 255;
  36. Border.Style := bboSolid;
  37. // This will be automatically set with the GetContrastColor function
  38. //FontEx.Color := clWhite;
  39. FontEx.Shadow := False;
  40. FontEx.Style := [];
  41. end;
  42. AButton.StateHover.Assign(AButton.StateNormal);
  43. AButton.StateClicked.Assign(AButton.StateNormal);
  44. with AButton.StateHover do
  45. begin
  46. Background.Color := cl2;
  47. Border.Color := cl2;
  48. end;
  49. with AButton.StateClicked do
  50. begin
  51. Background.Color := cl2;
  52. Border.Color := cl2;
  53. end;
  54. end;
  55. procedure TaForm.FormCreate(Sender: TObject);
  56. var
  57. i: integer;
  58. begin
  59. for i := 0 to aForm.ComponentCount - 1 do
  60. begin
  61. if aForm.Components[i] is TBCButtonFocus then
  62. begin
  63. { Default style, color for normal and pressed }
  64. BCButtonWindows8(TBCButtonFocus(aForm.Components[i]), clNavy, clGray);
  65. { Hover color based on normal color }
  66. TBCButtonFocus(aForm.Components[i]).StateHover.Background.Color :=
  67. Bright(TBCButtonFocus(aForm.Components[i]).StateNormal.Background.Color, 20);
  68. { Font color based on normal color }
  69. TBCButtonFocus(aForm.Components[i]).StateNormal.FontEx.Color :=
  70. GetContrastColor(TBCButtonFocus(aForm.Components[i]).StateNormal.Background.Color);
  71. TBCButtonFocus(aForm.Components[i]).StateHover.FontEx.Color :=
  72. GetContrastColor(TBCButtonFocus(aForm.Components[i]).StateNormal.Background.Color);
  73. TBCButtonFocus(aForm.Components[i]).StateClicked.FontEx.Color :=
  74. GetContrastColor(TBCButtonFocus(aForm.Components[i]).StateNormal.Background.Color);
  75. end;
  76. end;
  77. end;
  78. end.