diff --git a/bgracontrolsfx.lpk b/bgracontrolsfx.lpk
index 3eab138..6302bae 100644
--- a/bgracontrolsfx.lpk
+++ b/bgracontrolsfx.lpk
@@ -18,7 +18,7 @@
-
+
@@ -30,10 +30,15 @@
+
+
+
+
+
-
+
diff --git a/fxbutton.pas b/fxbutton.pas
index bce8a30..b74240a 100644
--- a/fxbutton.pas
+++ b/fxbutton.pas
@@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Types,
- FXContainer, BGRABitmap, BGRABitmapTypes, BGRAOpenGL;
+ FXContainer, BGRABitmap, BGRABitmapTypes, BGRAOpenGL, FXMaterialColors;
type
@@ -18,9 +18,21 @@ interface
TCustomFXButton = class(TGraphicControl, IFXDrawable)
private
FBGRA: TBGRABitmap;
+ FColorActive: TColor;
+ FColorDisabled: TColor;
+ FColorHover: TColor;
+ FColorKind: TMaterialColor;
+ FColorNormal: TColor;
+ FFontColorAutomatic: boolean;
FTexture: IBGLTexture;
FState: TFXButtonStates;
FNeedDraw: boolean;
+ procedure SetFColorActive(AValue: TColor);
+ procedure SetFColorDisabled(AValue: TColor);
+ procedure SetFColorHover(AValue: TColor);
+ procedure SetFColorKind(AValue: TMaterialColor);
+ procedure SetFColorNormal(AValue: TColor);
+ procedure SetFFontColorAutomatic(AValue: boolean);
protected
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
{%H-}WithThemeSpace: boolean); override;
@@ -38,9 +50,17 @@ TCustomFXButton = class(TGraphicControl, IFXDrawable)
procedure FXPreview(var aCanvas: TCanvas);
procedure Draw;
procedure Paint; override;
+ function GetFillColor: TColor;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
+ property FontColorAutomatic: boolean read FFontColorAutomatic
+ write SetFFontColorAutomatic;
+ property ColorKind: TMaterialColor read FColorKind write SetFColorKind;
+ property ColorNormal: TColor read FColorNormal write SetFColorNormal;
+ property ColorHover: TColor read FColorHover write SetFColorHover;
+ property ColorActive: TColor read FColorActive write SetFColorActive;
+ property ColorDisabled: TColor read FColorDisabled write SetFColorDisabled;
end;
TFXButton = class(TCustomFXButton)
@@ -93,6 +113,66 @@ procedure Register;
{ TCustomFXButton }
+procedure TCustomFXButton.SetFColorActive(AValue: TColor);
+begin
+ if FColorActive = AValue then
+ Exit;
+ FColorActive := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TCustomFXButton.SetFColorDisabled(AValue: TColor);
+begin
+ if FColorDisabled = AValue then
+ Exit;
+ FColorDisabled := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TCustomFXButton.SetFColorHover(AValue: TColor);
+begin
+ if FColorHover = AValue then
+ Exit;
+ FColorHover := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TCustomFXButton.SetFColorKind(AValue: TMaterialColor);
+begin
+ if FColorKind = AValue then
+ Exit;
+ FColorKind := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TCustomFXButton.SetFColorNormal(AValue: TColor);
+begin
+ if FColorNormal = AValue then
+ Exit;
+ FColorNormal := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TCustomFXButton.SetFFontColorAutomatic(AValue: boolean);
+begin
+ if FFontColorAutomatic = AValue then
+ Exit;
+ FFontColorAutomatic := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
procedure TCustomFXButton.CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
begin
@@ -157,10 +237,10 @@ procedure TCustomFXButton.FXInvalidate;
Invalidate;
if Parent is TFXContainer then
- begin
+ begin
if TFXContainer(Parent).ReceivePaintFrom = nil then
Parent.Invalidate;
- end
+ end
else
Invalidate;
end;
@@ -185,6 +265,7 @@ procedure TCustomFXButton.FXPreview(var aCanvas: TCanvas);
procedure TCustomFXButton.Draw;
var
style: TTextStyle;
+ fill_color: TColor;
begin
if (Width <> FBGRA.Width) and (Height <> FBGRA.Height) then
begin
@@ -196,57 +277,90 @@ procedure TCustomFXButton.Draw;
begin
FBGRA.FillTransparent;
+ style.Alignment := taCenter;
+ style.Layout := tlCenter;
+ FBGRA.FontHeight := Font.GetTextHeight(Caption);
+ FBGRA.FontAntialias := True;
+
+ fill_color := GetFillColor;
+ FBGRA.Fill(fill_color);
+
+ if FontColorAutomatic then
+ FBGRA.TextRect(Rect(0, 0, Width, Height), 0, 0, Caption, style,
+ GetContrastColor(fill_color))
+ else
+ FBGRA.TextRect(Rect(0, 0, Width, Height), 0, 0, Caption, style, Font.Color);
+
+ FNeedDraw := False;
+ FTexture := nil;
+ end;
+end;
+
+procedure TCustomFXButton.Paint;
+begin
+ if (Parent is TFXContainer) then
+ exit;
+ Draw;
+ FBGRA.Draw(Canvas, 0, 0, False);
+end;
+
+function TCustomFXButton.GetFillColor: TColor;
+begin
+ if ColorKind = mcDefault then
+ begin
if Enabled then
begin
{ Button Down }
if fxbActive in FState then
- begin
- FBGRA.Fill(BGRA(50, 50, 50, 255));
- end
+ Result := ColorActive
else
begin
{ Button Hovered }
if fxbHovered in FState then
- begin
- FBGRA.Fill(BGRA(200, 200, 200, 255));
- end
+ Result := ColorHover
{ Button Normal }
else
- begin
- FBGRA.Fill(BGRA(125, 125, 125, 255));
- end;
+ Result := ColorNormal;
end;
end
{ Button Disabled }
else
+ Result := ColorDisabled;
+ end
+ else
+ begin
+ if Enabled then
begin
- FBGRA.Fill(BGRA(25, 25, 25, 255));
- end;
-
- style.Alignment := taCenter;
- style.Layout := tlCenter;
-
- FBGRA.TextRect(Rect(0, 0, Width, Height), 0, 0, Caption, style, Font.Color);
-
- FNeedDraw := False;
- FTexture := nil;
+ { Button Down }
+ if fxbActive in FState then
+ Result := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M100
+ else
+ begin
+ { Button Hovered }
+ if fxbHovered in FState then
+ Result := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M300
+ { Button Normal }
+ else
+ Result := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M500;
+ end;
+ end
+ { Button Disabled }
+ else
+ Result := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M900;
end;
end;
-procedure TCustomFXButton.Paint;
-begin
- if (Parent is TFXContainer) then
- exit;
- Draw;
- FBGRA.Draw(Canvas, 0, 0, False);
-end;
-
constructor TCustomFXButton.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FBGRA := TBGRABitmap.Create;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
+ FColorNormal := clWhite;
+ FColorHover := clSilver;
+ FColorActive := clMedGray;
+ FColorDisabled := clGray;
+ FFontColorAutomatic := True;
end;
destructor TCustomFXButton.Destroy;
diff --git a/fxmaterialcolors.pas b/fxmaterialcolors.pas
new file mode 100644
index 0000000..7611ad3
--- /dev/null
+++ b/fxmaterialcolors.pas
@@ -0,0 +1,237 @@
+{
+ Material Design color pallete from
+ https://material.google.com/style/color.html#color-color-palette
+}
+
+unit FXMaterialColors;
+
+{$mode objfpc}{$H+}{$MODESWITCH ADVANCEDRECORDS}
+
+interface
+
+uses
+ Classes, SysUtils, Graphics, BGRABitmap, BGRABitmapTypes, FGL;
+
+type
+
+ TMaterialColor = (mcDefault, mcRed, mcPink, mcPurple, mcDeepPurple,
+ mcIndigo, mcBlue, mcLightBlue, mcCyan, mcTeal, mcGreen, mcLightGreen,
+ mcLime, mcYellow, mcAmber, mcOrange, mcDeepOrange, mcBrown, mcGrey,
+ mcBlueGrey);
+
+const
+
+ MaterialColorStr: array[TMaterialColor] of string =
+ ('Default', 'Red', 'Pink', 'Purple', 'Deep Purple',
+ 'Indigo', 'Blue', 'Light Blue', 'Cyan', 'Teal', 'Green', 'Light Green',
+ 'Lime', 'Yellow', 'Amber', 'Orange',
+ 'Deep Orange', 'Brown', 'Grey', 'Blue Grey');
+
+function StrToMaterialColor(str: string): TMaterialColor;
+procedure MaterialColorsListStr(AList: TStrings);
+function GetContrastColor(ABGColor: TColor): TColor;
+
+type
+
+ { TMaterialColors }
+
+ TMaterialColors = record
+ M50: TBGRAPixel;
+ M100: TBGRAPixel;
+ M200: TBGRAPixel;
+ M300: TBGRAPixel;
+ M400: TBGRAPixel;
+ M500: TBGRAPixel;
+ M600: TBGRAPixel;
+ M700: TBGRAPixel;
+ M800: TBGRAPixel;
+ M900: TBGRAPixel;
+ A100: TBGRAPixel;
+ A200: TBGRAPixel;
+ A400: TBGRAPixel;
+ A700: TBGRAPixel;
+ procedure Create(aM50, aM100, aM200, aM300, aM400, aM500, aM600,
+ aM700, aM800, aM900, aA100, aA200, aA400, aA700: string);
+ end;
+
+ TMaterialColorsList = specialize TFPGMap;
+
+var
+ MaterialBlack: TBGRAPixel;
+ MaterialWhite: TBGRAPixel;
+ MaterialRed, MaterialPink, MaterialPurple, MaterialDeepPurple,
+ MaterialIndigo, MaterialBlue, MaterialLightBlue, MaterialCyan,
+ MaterialTeal, MaterialGreen, MaterialLightGreen, MaterialLime,
+ MaterialYellow, MaterialAmber, MaterialOrange, MaterialDeepOrange,
+ MaterialBrown, MaterialGrey, MaterialBlueGrey: TMaterialColors;
+ MaterialColorsList: TMaterialColorsList;
+
+implementation
+
+function StrToMaterialColor(str: string): TMaterialColor;
+var
+ cl: TMaterialColor;
+begin
+ Result := mcDefault;
+ str := LowerCase(str);
+ for cl := low(TMaterialColor) to high(TMaterialColor) do
+ if str = LowerCase(MaterialColorStr[cl]) then
+ begin
+ Result := cl;
+ exit;
+ end;
+end;
+
+procedure MaterialColorsListStr(AList: TStrings);
+var
+ s: string;
+begin
+ for s in MaterialColorStr do
+ AList.Add(s);
+end;
+
+function GetContrastColor(ABGColor: TColor): TColor;
+var
+ ADouble: double;
+ R, G, B: byte;
+begin
+ if ABGColor <= 0 then
+ begin
+ Result := clWhite;
+ Exit; // *** EXIT RIGHT HERE ***
+ end;
+
+ if ABGColor = clWhite then
+ begin
+ Result := clBlack;
+ Exit; // *** EXIT RIGHT HERE ***
+ end;
+
+ // Get RGB from Color
+ R := Red(ABGColor);
+ G := Green(ABGColor);
+ B := Blue(ABGColor);
+
+ // Counting the perceptive luminance - human eye favors green color...
+ ADouble := 1 - (0.299 * R + 0.587 * G + 0.114 * B) / 255;
+
+ if (ADouble < 0.5) then
+ Result := clBlack // bright colors - black font
+ else
+ Result := clWhite; // dark colors - white font
+end;
+
+{ TMaterialColors }
+
+procedure TMaterialColors.Create(aM50, aM100, aM200, aM300, aM400,
+ aM500, aM600, aM700, aM800, aM900, aA100, aA200, aA400, aA700: string);
+begin
+ self.M50 := StrToBGRA(aM50);
+ self.M100 := StrToBGRA(aM100);
+ self.M200 := StrToBGRA(aM200);
+ self.M300 := StrToBGRA(aM300);
+ self.M400 := StrToBGRA(aM400);
+ self.M500 := StrToBGRA(aM500);
+ self.M600 := StrToBGRA(aM600);
+ self.M700 := StrToBGRA(aM700);
+ self.M800 := StrToBGRA(aM800);
+ self.M900 := StrToBGRA(aM900);
+ self.A100 := StrToBGRA(aA100);
+ self.A200 := StrToBGRA(aA200);
+ self.A400 := StrToBGRA(aA400);
+ self.A700 := StrToBGRA(aA700);
+end;
+
+initialization
+
+ MaterialBlack := BGRABlack;
+ MaterialWhite := BGRAWhite;
+
+ MaterialRed.Create('#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350',
+ '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C', '#FF8A80',
+ '#FF5252', '#FF1744', '#D50000');
+ MaterialPink.Create('#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292',
+ '#EC407A', '#E91E63', '#D81B60', '#C2185B', '#AD1457', '#880E4F',
+ '#FF80AB', '#FF4081', '#F50057', '#C51162');
+ MaterialPurple.Create('#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC',
+ '#9C27B0', '#8E24AA', '#7B1FA2', '#6A1B9A', '#4A148C',
+ '#EA80FC', '#E040FB', '#D500F9', '#AA00FF');
+ MaterialDeepPurple.Create('#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2',
+ '#673AB7', '#5E35B1', '#512DA8', '#4527A0',
+ '#311B92', '#B388FF', '#7C4DFF', '#651FFF', '#6200EA');
+ MaterialIndigo.Create('#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0',
+ '#3F51B5', '#3949AB', '#303F9F', '#283593', '#1A237E',
+ '#8C9EFF', '#536DFE', '#3D5AFE', '#304FFE');
+ MaterialBlue.Create('#E3F2FD', '#BBDEFB', '#90CAF9', '#64B5F6', '#42A5F5',
+ '#2196F3', '#1E88E5', '#1976D2', '#1565C0', '#0D47A1',
+ '#82B1FF', '#448AFF', '#2979FF', '#2962FF');
+ MaterialLightBlue.Create('#E1F5FE', '#B3E5FC', '#81D4FA', '#4FC3F7', '#29B6F6',
+ '#03A9F4', '#039BE5', '#0288D1', '#0277BD', '#01579B',
+ '#80D8FF', '#40C4FF', '#00B0FF', '#0091EA');
+ MaterialCyan.Create('#E0F7FA', '#B2EBF2', '#80DEEA', '#4DD0E1', '#26C6DA',
+ '#00BCD4', '#00ACC1', '#0097A7', '#00838F', '#006064',
+ '#84FFFF', '#18FFFF', '#00E5FF', '#00B8D4');
+ MaterialTeal.Create('#E0F2F1', '#B2DFDB', '#80CBC4', '#4DB6AC', '#26A69A',
+ '#009688', '#00897B', '#00796B', '#00695C', '#004D40',
+ '#A7FFEB', '#64FFDA', '#1DE9B6', '#00BFA5');
+ MaterialGreen.Create('#E8F5E9', '#C8E6C9', '#A5D6A7', '#81C784', '#66BB6A',
+ '#4CAF50', '#43A047', '#388E3C', '#2E7D32', '#1B5E20',
+ '#B9F6CA', '#69F0AE', '#00E676', '#00C853');
+ MaterialLightGreen.Create('#F1F8E9', '#DCEDC8', '#C5E1A5', '#AED581', '#9CCC65',
+ '#8BC34A', '#7CB342', '#689F38', '#558B2F', '#33691E',
+ '#CCFF90', '#B2FF59', '#76FF03', '#64DD17');
+ MaterialLime.Create('#F9FBE7', '#F0F4C3', '#E6EE9C', '#DCE775', '#D4E157',
+ '#CDDC39', '#C0CA33', '#AFB42B', '#9E9D24', '#827717',
+ '#F4FF81', '#EEFF41', '#C6FF00', '#AEEA00');
+ MaterialYellow.Create('#FFFDE7', '#FFF9C4', '#FFF59D', '#FFF176', '#FFEE58',
+ '#FFEB3B', '#FDD835', '#FBC02D', '#F9A825', '#F57F17',
+ '#FFFF8D', '#FFFF00', '#FFEA00', '#FFD600');
+ MaterialAmber.Create('#FFF8E1', '#FFECB3', '#FFE082', '#FFD54F', '#FFCA28',
+ '#FFC107', '#FFB300', '#FFA000', '#FF8F00', '#FF6F00',
+ '#FFE57F', '#FFD740', '#FFC400', '#FFAB00');
+ MaterialOrange.Create('#FFF3E0', '#FFE0B2', '#FFCC80', '#FFB74D', '#FFA726',
+ '#FF9800', '#FB8C00', '#F57C00', '#EF6C00', '#E65100',
+ '#FFD180', '#FFAB40', '#FF9100', '#FF6D00');
+ MaterialDeepOrange.Create('#FBE9E7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043',
+ '#FF5722', '#F4511E', '#E64A19', '#D84315', '#BF360C',
+ '#FF9E80', '#FF6E40', '#FF3D00', '#DD2C00');
+ MaterialBrown.Create('#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63',
+ '#795548', '#6D4C41', '#5D4037', '#4E342E', '#3E2723',
+ '', '', '', '');
+ MaterialGrey.Create('#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD',
+ '#9E9E9E', '#757575', '#616161', '#424242', '#212121',
+ '', '', '', '');
+ MaterialBlueGrey.Create('#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C',
+ '#607D8B', '#546E7A', '#455A64', '#37474F', '#263238',
+ '', '', '', '');
+
+ MaterialColorsList := TMaterialColorsList.Create;
+ with MaterialColorsList do
+ begin
+ Add('', MaterialGrey);
+ Add(MaterialColorStr[mcDefault], MaterialGrey);
+ Add(MaterialColorStr[mcRed], MaterialRed);
+ Add(MaterialColorStr[mcPink], MaterialPink);
+ Add(MaterialColorStr[mcPurple], MaterialPurple);
+ Add(MaterialColorStr[mcDeepPurple], MaterialDeepPurple);
+ Add(MaterialColorStr[mcIndigo], MaterialIndigo);
+ Add(MaterialColorStr[mcBlue], MaterialBlue);
+ Add(MaterialColorStr[mcLightBlue], MaterialLightBlue);
+ Add(MaterialColorStr[mcCyan], MaterialCyan);
+ Add(MaterialColorStr[mcTeal], MaterialTeal);
+ Add(MaterialColorStr[mcGreen], MaterialGreen);
+ Add(MaterialColorStr[mcLightGreen], MaterialLightGreen);
+ Add(MaterialColorStr[mcLime], MaterialLime);
+ Add(MaterialColorStr[mcYellow], MaterialYellow);
+ Add(MaterialColorStr[mcAmber], MaterialAmber);
+ Add(MaterialColorStr[mcOrange], MaterialOrange);
+ Add(MaterialColorStr[mcDeepOrange], MaterialDeepOrange);
+ Add(MaterialColorStr[mcBrown], MaterialBrown);
+ Add(MaterialColorStr[mcGrey], MaterialGrey);
+ Add(MaterialColorStr[mcBlueGrey], MaterialBlueGrey);
+ end;
+
+finalization
+ MaterialColorsList.Free;
+
+end.
diff --git a/fxmaterialdesignbutton.pas b/fxmaterialdesignbutton.pas
index 69de13e..745adf5 100644
--- a/fxmaterialdesignbutton.pas
+++ b/fxmaterialdesignbutton.pas
@@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, Types, LResources, Forms, Controls, Graphics, Dialogs,
- BGRABitmap, BGRABitmapTypes, BGRAOpenGL, FXContainer, ExtCtrls;
+ BGRABitmap, BGRABitmapTypes, BGRAOpenGL, FXContainer, ExtCtrls, FXMaterialColors;
type
@@ -14,6 +14,8 @@ interface
TFXMaterialDesignButton = class(TGraphicControl, IFXDrawable)
private
+ FColorKind: TMaterialColor;
+ FFontColorAutomatic: boolean;
FNormalColor: TColor;
FNormalColorEffect: TColor;
FRoundBorders: single;
@@ -38,6 +40,8 @@ TFXMaterialDesignButton = class(TGraphicControl, IFXDrawable)
FCircleAlpha: byte;
FTexture: IBGLTexture;
FNeedDraw: boolean;
+ procedure SetFColorKind(AValue: TMaterialColor);
+ procedure SetFFontColorAutomatic(AValue: boolean);
procedure SetFNormalColor(AValue: TColor);
procedure SetFNormalColorEffect(AValue: TColor);
procedure SetFRoundBorders(AValue: single);
@@ -64,7 +68,7 @@ TFXMaterialDesignButton = class(TGraphicControl, IFXDrawable)
class function GetControlClassDefaultSize: TSize; override;
procedure TextChanged; override;
procedure UpdateShadow;
- procedure DrawTextShadow(AHeight: integer);
+ procedure DrawTextShadow(AHeight: integer; ATextColor: TColor);
protected
procedure FXInvalidate;
procedure FXDraw;
@@ -76,6 +80,9 @@ TFXMaterialDesignButton = class(TGraphicControl, IFXDrawable)
destructor Destroy; override;
published
property RoundBorders: single read FRoundBorders write SetFRoundBorders default 5;
+ property ColorKind: TMaterialColor read FColorKind write SetFColorKind;
+ property FontColorAutomatic: boolean read FFontColorAutomatic
+ write SetFFontColorAutomatic;
property NormalColor: TColor read FNormalColor write SetFNormalColor default clWhite;
property NormalColorEffect: TColor read FNormalColorEffect
write SetFNormalColorEffect default clSilver;
@@ -343,6 +350,25 @@ procedure TFXMaterialDesignButton.SetFNormalColor(AValue: TColor);
FXInvalidate;
end;
+procedure TFXMaterialDesignButton.SetFColorKind(AValue: TMaterialColor);
+begin
+ if FColorKind = AValue then
+ Exit;
+ FColorKind := AValue;
+ FNeedDraw := True;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
+procedure TFXMaterialDesignButton.SetFFontColorAutomatic(AValue: boolean);
+begin
+ if FFontColorAutomatic = AValue then
+ Exit;
+ FFontColorAutomatic := AValue;
+ if not (csLoading in ComponentState) then
+ FXInvalidate;
+end;
+
procedure TFXMaterialDesignButton.SetFNormalColorEffect(AValue: TColor);
begin
if FNormalColorEffect = AValue then
@@ -409,13 +435,13 @@ procedure TFXMaterialDesignButton.UpdateShadow;
FBGRAShadow.RoundRectAntialias(FShadowSize, FShadowSize, Width - FShadowSize,
Height - FShadowSize, FRoundBorders, FRoundBorders,
FShadowColor, 1, FShadowColor, [rrDefault]);
- BGRAReplace(FBGRAShadow, FBGRAShadow.FilterBlurRadial(FShadowSize / sqrt(2),
- FShadowSize / sqrt(2), rbBox) as TBGRABitmap);
+ BGRAReplace(FBGRAShadow, FBGRAShadow.FilterBlurRadial(FShadowSize /
+ sqrt(2), FShadowSize / sqrt(2), rbBox) as TBGRABitmap);
end;
FNeedDraw := True;
end;
-procedure TFXMaterialDesignButton.DrawTextShadow(AHeight: integer);
+procedure TFXMaterialDesignButton.DrawTextShadow(AHeight: integer; ATextColor: TColor);
var
bmpSdw: TBGRABitmap;
OutTxtSize: TSize;
@@ -449,7 +475,7 @@ procedure TFXMaterialDesignButton.DrawTextShadow(AHeight: integer);
bmpSdw.Free;
end;
- FBGRA.TextOut(OutX, OutY, Caption, FTextColor);
+ FBGRA.TextOut(OutX, OutY, Caption, ATextColor);
end;
procedure TFXMaterialDesignButton.FXInvalidate;
@@ -490,6 +516,8 @@ procedure TFXMaterialDesignButton.Draw;
round_rect_width: integer;
round_rect_height: integer;
text_height: integer;
+ color_normal: TColor;
+ color_effect: TColor;
begin
if (Width - 1 > FRoundBorders * 2) and (Height - 1 > FRoundBorders * 2) then
begin
@@ -506,10 +534,21 @@ procedure TFXMaterialDesignButton.Draw;
if FShadow then
FBGRA.PutImage(0, 0, FBGRAShadow, dmDrawWithTransparency);
- temp := TBGRABitmap.Create(Width, Height, FNormalColor);
+ if ColorKind = mcDefault then
+ begin
+ color_normal := FNormalColor;
+ color_effect := FNormalColorEffect;
+ end
+ else
+ begin
+ color_normal := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M500;
+ color_effect := MaterialColorsList.KeyData[MaterialColorStr[ColorKind]].M50;
+ end;
+
+ temp := TBGRABitmap.Create(Width, Height, color_normal);
temp.EllipseAntialias(FMousePos.X, FMousePos.Y, FCircleSize, FCircleSize,
- ColorToBGRA(FNormalColorEffect, FCircleAlpha), 1,
- ColorToBGRA(FNormalColorEffect, FCircleAlpha));
+ ColorToBGRA(color_effect, FCircleAlpha), 1,
+ ColorToBGRA(color_effect, FCircleAlpha));
if FShadow then
begin
@@ -536,7 +575,10 @@ procedure TFXMaterialDesignButton.Draw;
text_height := Height - FShadowSize
else
text_height := Height;
- DrawTextShadow(text_height);
+ if FontColorAutomatic then
+ DrawTextShadow(text_height, GetContrastColor(color_normal))
+ else
+ DrawTextShadow(text_height, FTextColor);
end;
FNeedDraw := False;
@@ -544,7 +586,10 @@ procedure TFXMaterialDesignButton.Draw;
end;
end
else
+ begin
FBGRA.FillTransparent;
+ FTexture := nil;
+ end;
end;
procedure TFXMaterialDesignButton.Paint;
@@ -584,6 +629,7 @@ constructor TFXMaterialDesignButton.Create(AOwner: TComponent);
FTextStyle := [];
FTextFont := 'default';
FTextQuality := fqFineAntialiasing;
+ FFontColorAutomatic := True;
end;
destructor TFXMaterialDesignButton.Destroy;
diff --git a/test/test_panel/umain.lfm b/test/test_panel/umain.lfm
index 2b2431d..35475e2 100644
--- a/test/test_panel/umain.lfm
+++ b/test/test_panel/umain.lfm
@@ -1,19 +1,19 @@
object frmMain: TfrmMain
- Left = 37
- Height = 445
- Top = 109
- Width = 783
+ Left = 487
+ Height = 444
+ Top = 194
+ Width = 788
Caption = 'BGRA Controls FX'
- ClientHeight = 445
- ClientWidth = 783
- OnDestroy = FormDestroy
+ ClientHeight = 444
+ ClientWidth = 788
+ OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '1.7'
object FXContainer1: TFXContainer
Left = 0
- Height = 445
- Top = 0
- Width = 783
+ Height = 394
+ Top = 50
+ Width = 788
Align = alClient
AutoResizeViewport = True
Color = clWhite
@@ -42,24 +42,59 @@ object frmMain: TfrmMain
Caption = 'Third'
Enabled = False
end
- object FXMaterialDesignButton1: TFXMaterialDesignButton
- Left = 144
- Height = 272
- Top = 88
- Width = 472
- RoundBorders = 100
- NormalColor = clSilver
- NormalColorEffect = clWhite
- ShadowColor = clSkyBlue
- ShadowSize = 70
- TextColor = clWhite
- TextSize = 30
- TextShadowSize = 10
- TextStyle = [fsBold, fsItalic]
+ object FXMaterialDesignButton2: TFXMaterialDesignButton
+ Left = 160
+ Height = 72
+ Top = 152
+ Width = 491
+ ColorKind = mcDefault
+ FontColorAutomatic = True
+ ShadowColor = clBlack
+ TextSize = 40
+ TextShadow = False
TextFont = 'default'
Anchors = [akTop, akLeft, akRight, akBottom]
AutoSize = True
- Caption = 'Hello World'
+ Caption = 'FXMaterialDesignButton2'
+ end
+ object FXMaterialDesignButton3: TFXMaterialDesignButton
+ Left = 694
+ Height = 72
+ Top = 312
+ Width = 83
+ RoundBorders = 35
+ ColorKind = mcDefault
+ FontColorAutomatic = True
+ ShadowColor = clBlack
+ TextSize = 40
+ TextShadow = False
+ TextFont = 'default'
+ Anchors = []
+ Caption = 'FX'
+ end
+ end
+ object Panel1: TPanel
+ Left = 0
+ Height = 50
+ Top = 0
+ Width = 788
+ Align = alTop
+ BevelOuter = bvNone
+ ClientHeight = 50
+ ClientWidth = 788
+ Color = clWhite
+ ParentColor = False
+ TabOrder = 1
+ object ComboBox1: TComboBox
+ Left = 589
+ Height = 28
+ Top = 8
+ Width = 188
+ Anchors = [akTop, akRight]
+ ItemHeight = 20
+ OnChange = ComboBox1Change
+ Style = csDropDownList
+ TabOrder = 0
end
end
end
diff --git a/test/test_panel/umain.pas b/test/test_panel/umain.pas
index 8b7be1e..a6831d7 100644
--- a/test/test_panel/umain.pas
+++ b/test/test_panel/umain.pas
@@ -6,25 +6,28 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
- FXContainer, FXButton, FXMaterialDesignButton, BGRABitmap, BGRABitmapTypes,
- BGRAOpenGL;
+ StdCtrls, FXContainer, FXButton, FXMaterialDesignButton, BGRABitmap,
+ BGRABitmapTypes, BGRAOpenGL, FXMaterialColors, Math;
type
{ TfrmMain }
TfrmMain = class(TForm)
+ ComboBox1: TComboBox;
FXButton1: TFXButton;
FXButton2: TFXButton;
FXButton3: TFXButton;
FXContainer1: TFXContainer;
- FXMaterialDesignButton1: TFXMaterialDesignButton;
- procedure FormDestroy(Sender: TObject);
+ FXMaterialDesignButton2: TFXMaterialDesignButton;
+ FXMaterialDesignButton3: TFXMaterialDesignButton;
+ Panel1: TPanel;
+ procedure ComboBox1Change(Sender: TObject);
+ procedure FormCreate(Sender: TObject);
procedure FXButton1Click(Sender: TObject);
procedure FXButton2Click(Sender: TObject);
procedure FXContainer1Paint(Sender: TObject);
private
- bg: TBGLBitmap;
end;
var
@@ -45,15 +48,31 @@ procedure TfrmMain.FXButton2Click(Sender: TObject);
FXButton2.Caption := 'You did it.';
end;
-procedure TfrmMain.FormDestroy(Sender: TObject);
+procedure TfrmMain.FormCreate(Sender: TObject);
begin
- FreeAndNil(bg);
+ Randomize;
+ MaterialColorsListStr(ComboBox1.Items);
+ ComboBox1.ItemIndex := RandomRange(0, ComboBox1.Items.Count+1);
+ ComboBox1Change(Self);
+end;
+
+procedure TfrmMain.ComboBox1Change(Sender: TObject);
+var
+ i: integer;
+begin
+ for i:=0 to FXContainer1.ControlCount-1 do
+ begin
+ if FXContainer1.Controls[i] is TFXButton then
+ TFXButton(FXContainer1.Controls[i]).ColorKind := StrToMaterialColor(ComboBox1.Caption);
+ if FXContainer1.Controls[i] is TFXMaterialDesignButton then
+ TFXMaterialDesignButton(FXContainer1.Controls[i]).ColorKind := StrToMaterialColor(ComboBox1.Caption);
+ end;
end;
procedure TfrmMain.FXContainer1Paint(Sender: TObject);
begin
- BGLCanvas.FillRectLinearColor(0, 0, FXContainer1.Width, FXContainer1.Height,
- BGRABlack, BGRABlack, BGRAWhite, BGRAWhite);
+ Panel1.Color := MaterialColorsList.KeyData[ComboBox1.Caption].M900;
+ FXContainer1.Color := MaterialColorsList.KeyData[ComboBox1.Caption].M800;
end;
end.