Browse Source

Merge pull request #221 from melchiorrecaruso/dev-bgracontrols

Probable fix for issue "BCTrackbarUpdown control bug"
Leandro Oscar Ezequiel Diaz 10 months ago
parent
commit
35635cd8d1
2 changed files with 17 additions and 16 deletions
  1. 16 15
      bccombobox.pas
  2. 1 1
      bctrackbarupdown.pas

+ 16 - 15
bccombobox.pas

@@ -143,7 +143,7 @@ type
     property ArrowWidth: integer read GetArrowWidth write SetArrowWidth;
     property ArrowWidth: integer read GetArrowWidth write SetArrowWidth;
     property ArrowFlip: boolean read GetArrowFlip write SetArrowFlip default false;
     property ArrowFlip: boolean read GetArrowFlip write SetArrowFlip default false;
     property FocusBorderColor: TColor read FFocusBorderColor write FFocusBorderColor default clBlack;
     property FocusBorderColor: TColor read FFocusBorderColor write FFocusBorderColor default clBlack;
-    property FocusBorderOpacity: byte read FFocusBorderOpacity write FFocusBorderOpacity default 255;
+    property FocusBorderOpacity: byte read FFocusBorderOpacity write FFocusBorderOpacity default 0;
     property DropDownBorderColor: TColor read FDropDownBorderColor write FDropDownBorderColor default clWindowText;
     property DropDownBorderColor: TColor read FDropDownBorderColor write FDropDownBorderColor default clWindowText;
     property DropDownBorderSize: integer read FDropDownBorderSize write FDropDownBorderSize default 1;
     property DropDownBorderSize: integer read FDropDownBorderSize write FDropDownBorderSize default 1;
     property DropDownColor: TColor read GetDropDownColor write SetDropDownColor default clWindow;
     property DropDownColor: TColor read GetDropDownColor write SetDropDownColor default clWindow;
@@ -440,17 +440,22 @@ end;
 procedure TBCComboBox.OnAfterRenderButton(Sender: TObject;
 procedure TBCComboBox.OnAfterRenderButton(Sender: TObject;
   const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
   const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
 var
 var
-  focusMargin: integer;
+  FocusMargin: integer;
 begin
 begin
   if Assigned(FOnDrawSelectedItem) then
   if Assigned(FOnDrawSelectedItem) then
     FOnDrawSelectedItem(self, ABGRA, AState, ARect);
     FOnDrawSelectedItem(self, ABGRA, AState, ARect);
   if Focused then
   if Focused then
   begin
   begin
-    focusMargin := round(2 * Button.CanvasScale);
-    ABGRA.RectangleAntialias(ARect.Left + focusMargin, ARect.Top + focusMargin,
-      ARect.Right - focusMargin - 1, ARect.Bottom - focusMargin - 1,
-      ColorToBGRA(FocusBorderColor, FocusBorderOpacity),
-      Button.CanvasScale);
+    FocusMargin := round(2 * FButton.CanvasScale);
+    ABGRA.RoundRectAntialias(
+      ARect.Left + FocusMargin,
+      ARect.Top + FocusMargin,
+      ARect.Right - FocusMargin - 1,
+      ARect.Bottom - FocusMargin - 1,
+      Max(0, FButton.Rounding.RoundX - FocusMargin),
+      Max(0, FButton.Rounding.RoundY - FocusMargin),
+      ColorToBGRA(FFocusBorderColor, FFocusBorderOpacity),
+      FButton.CanvasScale);
   end;
   end;
 end;
 end;
 
 
@@ -676,11 +681,9 @@ end;
 procedure TBCComboBox.UpdateFocus(AFocused: boolean);
 procedure TBCComboBox.UpdateFocus(AFocused: boolean);
 var
 var
   lForm: TCustomForm;
   lForm: TCustomForm;
-  oldCaption: string;
 begin
 begin
   lForm := GetParentForm(Self);
   lForm := GetParentForm(Self);
-  if lForm = nil then
-    exit;
+  if lForm = nil then Exit;
 
 
   {$IFDEF FPC}//#
   {$IFDEF FPC}//#
   if AFocused then
   if AFocused then
@@ -688,11 +691,7 @@ begin
   else
   else
     ActiveDefaultControlChanged(nil);
     ActiveDefaultControlChanged(nil);
   {$ENDIF}
   {$ENDIF}
-
-  oldCaption := FButton.Caption;
-  FButton.Caption := FButton.Caption + '1';
-  FButton.Caption := oldCaption;
-
+  FButton.UpdateControl;
   Invalidate;
   Invalidate;
 end;
 end;
 
 
@@ -822,6 +821,8 @@ begin
   FButton.OnClick := ButtonClick;
   FButton.OnClick := ButtonClick;
   FButton.DropDownArrow := True;
   FButton.DropDownArrow := True;
   FButton.OnAfterRenderBCButton := OnAfterRenderButton;
   FButton.OnAfterRenderBCButton := OnAfterRenderButton;
+  FFocusBorderColor := clBlack;
+  FFocusBorderOpacity := 0;
   UpdateButtonCanvasScaleMode;
   UpdateButtonCanvasScaleMode;
 
 
   FItems := TStringList.Create;
   FItems := TStringList.Create;

+ 1 - 1
bctrackbarupdown.pas

@@ -296,7 +296,7 @@ begin
   FEmptyText:= false;
   FEmptyText:= false;
   DoSelectAll;
   DoSelectAll;
   Invalidate;
   Invalidate;
-  NotifyChange;
+  if not (csLoading in ComponentState) then NotifyChange;
 end;
 end;
 
 
 procedure TCustomBCTrackbarUpdown.SetArrowColor(AValue: TColor);
 procedure TCustomBCTrackbarUpdown.SetArrowColor(AValue: TColor);