1 unit umain; 2 3 {$mode objfpc}{$H+} 4 5 interface 6 7 uses 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Spin, BCNumericKeyboard, BCButton, BCTypes, BCPanel, BGRABitmapTypes; 10 11 type 12 13 { TForm1 } 14 15 TForm1 = class(TForm) 16 BCNumericKeyboard1: TBCNumericKeyboard; 17 BCPanel1: TBCPanel; 18 Button1: TBCButton; 19 Button2: TBCButton; 20 Edit1: TEdit; 21 FloatSpinEdit1: TFloatSpinEdit; 22 procedure BCNumericKeyboard1Change(Sender: TObject); 23 procedure Button1Click(Sender: TObject); 24 procedure FormClick(Sender: TObject); 25 procedure FormCreate(Sender: TObject); 26 private 27 NumericSender: TControl; 28 public 29 30 end; 31 32 var 33 Form1: TForm1; 34 35 implementation 36 37 {$R *.lfm} 38 39 { TForm1 } 40 41 { Button style } 42 procedure BCButtonWindows8(AButton: TBCButton; cl1, cl2: TColor); 43 begin 44 AButton.Rounding.RoundX := 1; 45 AButton.Rounding.RoundY := 1; 46 AButton.RoundingDropDown.Assign(AButton.Rounding); 47 48 with AButton.StateNormal do 49 begin 50 Background.Style := bbsColor; 51 Background.Color := cl1; 52 Border.Style := bboSolid; 53 Border.Width := 1; 54 Border.Color := cl1; 55 Border.LightWidth := 0; 56 Border.LightOpacity := 255; 57 Border.Style := bboSolid; 58 FontEx.Color := clWhite; 59 FontEx.Shadow := False; 60 FontEx.Style := []; 61 end; 62 63 AButton.StateHover.Assign(AButton.StateNormal); 64 AButton.StateClicked.Assign(AButton.StateNormal); 65 66 with AButton.StateHover do 67 begin 68 Background.Color := cl2; 69 Border.Color := cl2; 70 end; 71 72 with AButton.StateClicked do 73 begin 74 Background.Color := cl2; 75 Border.Color := cl2; 76 end; 77 end; 78 79 procedure TForm1.Button1Click(Sender: TObject); 80 begin 81 if (NumericSender <> nil) and (NumericSender.Name = TControl(Sender).Name) and 82 (BCNumericKeyboard1.Visible) then 83 begin 84 BCNumericKeyboard1.Hide(); 85 // Remove unnecessary comma for button caption 86 if Sender is TBCButton or Sender is TEdit then 87 if Pos(DefaultFormatSettings.DecimalSeparator, NumericSender.Caption) = 88 Length(NumericSender.Caption) then 89 NumericSender.Caption := 90 LeftStr(NumericSender.Caption, Length(NumericSender.Caption) - 1); 91 end 92 else 93 begin 94 NumericSender := Sender as TControl; 95 BCNumericKeyboard1.Value := ''; 96 BCNumericKeyboard1.Panel.Left := NumericSender.Left; 97 BCNumericKeyboard1.Panel.Top := NumericSender.Top + NumericSender.Height; 98 BCNumericKeyboard1.Show(); 99 end; 100 end; 101 102 procedure TForm1.FormClick(Sender: TObject); 103 begin 104 if NumericSender <> nil then 105 Button1Click(NumericSender); 106 end; 107 108 procedure TForm1.BCNumericKeyboard1Change(Sender: TObject); 109 var 110 d: double; 111 begin 112 // For buttons 113 if NumericSender is TBCButton or NumericSender is TEdit then 114 begin 115 if BCNumericKeyboard1.Value <> '' then 116 NumericSender.Caption := 117 DefaultFormatSettings.CurrencyString + ' ' + BCNumericKeyboard1.Value 118 else 119 NumericSender.Caption := 120 DefaultFormatSettings.CurrencyString + ' 0' + 121 DefaultFormatSettings.DecimalSeparator + '00'; 122 end; 123 // For spin edit 124 if NumericSender is TFloatSpinEdit then 125 begin 126 TryStrToFloat(BCNumericKeyboard1.Value, d); 127 TFloatSpinEdit(NumericSender).Value := d; 128 end; 129 end; 130 131 procedure TForm1.FormCreate(Sender: TObject); 132 begin 133 // Assign custom format settings 134 DefaultFormatSettings.CurrencyString := '$'; 135 // DefaultFormatSettings.DecimalSeparator := '.'; 136 137 // Assign a style 138 BCButtonWindows8(BCNumericKeyBoard1.ButtonStyle, clGray, clSkyBlue); 139 // Custom extra size inside the button 140 BCNumericKeyBoard1.ButtonStyle.SetSizeVariables(0, 0, 15, 25); 141 // Apply the style 142 BCNumericKeyboard1.UpdateButtonStyle; 143 144 with BCNumericKeyboard1.Panel do 145 begin 146 BevelInner := bvNone; 147 BevelOuter := bvNone; 148 Background.Gradient1.StartColor := clNavy; 149 Background.Gradient1.EndColor := clPurple; 150 Background.Gradient1.Point1XPercent := 0; 151 Background.Gradient1.Point1YPercent := 0; 152 Background.Gradient1.Point2XPercent := 0; 153 Background.Gradient1.Point2YPercent := 100; 154 Background.Gradient1EndPercent := 100; 155 Background.Style := bbsGradient; 156 // Spacing around 157 ChildSizing.TopBottomSpacing := 5; 158 ChildSizing.LeftRightSpacing := 5; 159 // Spacing between buttons 160 ChildSizing.VerticalSpacing := 10; 161 ChildSizing.HorizontalSpacing := 10; 162 end; 163 end; 164 165 end. 166