umain.pas 4.2 KB

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