Explorar o código

Added RadioButton

lainz %!s(int64=9) %!d(string=hai) anos
pai
achega
322f598168

+ 98 - 2
bgracustomdrawn.pas

@@ -39,6 +39,10 @@ type
 
   end;
 
+  TBCDRadioButton = class(TCDRadioButton)
+
+  end;
+
   { TBGRADrawer }
 
   TBGRADrawer = class(TCDDrawerCommon)
@@ -79,6 +83,11 @@ type
       ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); override;
     procedure DrawCheckBox(ADest: TCanvas; ASize: TSize;
       AState: TCDControlState; AStateEx: TCDControlStateEx); override;
+    { RadioButton }
+    procedure DrawRadioButtonCircle(ADest: TCanvas; ADestPos: TPoint;
+      ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); override;
+    procedure DrawRadioButton(ADest: TCanvas; ASize: TSize;
+      AState: TCDControlState; AStateEx: TCDControlStateEx); override;
   end;
 
 procedure Register;
@@ -88,7 +97,7 @@ implementation
 procedure Register;
 begin
   RegisterComponents('BGRA Custom Drawn', [TBCDButton, TBCDEdit,
-    TBCDStaticText, TBCDProgressBar, TBCDSpinEdit, TBCDCheckBox]);
+    TBCDStaticText, TBCDProgressBar, TBCDSpinEdit, TBCDCheckBox, TBCDRadioButton]);
 end;
 
 { TBCDProgressBar }
@@ -130,7 +139,7 @@ begin
 
     TCDCOMBOBOX_DEFAULT_HEIGHT: Result := 21;
 
-    TCDRADIOBUTTON_CIRCLE_HEIGHT: Result := 15;
+    TCDRADIOBUTTON_CIRCLE_HEIGHT: Result := DPIAdjustment(13);
 
     TCDSCROLLBAR_BUTTON_WIDTH: Result := 17;
     TCDSCROLLBAR_LEFT_SPACING: Result := 17;
@@ -684,6 +693,93 @@ begin
   ADest.TextOut(lSquareHeight + 5, lTextY, AStateEx.Caption);
 end;
 
+procedure TBGRADrawer.DrawRadioButtonCircle(ADest: TCanvas; ADestPos: TPoint;
+  ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
+var
+  lCircleHeight, lCircleMid: integer;
+  Bitmap: TBGRABitmap;
+  bColor: TBGRAPixel;
+begin
+  lCircleHeight := GetMeasures(TCDRADIOBUTTON_CIRCLE_HEIGHT);
+  lCircleMid := lCircleHeight div 2;
+
+  Bitmap := TBGRABitmap.Create(lCircleHeight, lCircleHeight);
+
+  if csfEnabled in AState then
+  begin
+    if csfSunken in AState then
+      bColor := BGRA(61, 61, 61)
+    else
+    begin
+      if csfMouseOver in AState then
+        bColor := BGRA(109, 109, 109)
+      else
+        bColor := BGRA(84, 84, 84);
+    end;
+  end
+  else
+    bColor := BGRA(71, 71, 71);
+
+  if csfOn in AState then
+  begin
+    if csfEnabled in AState then
+      Bitmap.EllipseAntialias(lCircleMid, lCircleMid, lCircleMid - 1,
+        lCircleMid - 1, BGRA(48, 48, 48), 1, BGRA(229, 229, 229))
+    else
+      Bitmap.EllipseAntialias(lCircleMid, lCircleMid, lCircleMid - 1,
+        lCircleMid - 1, BGRA(48, 48, 48), 1, BGRA(170, 170, 170));
+  end
+  else
+  begin
+    Bitmap.EllipseAntialias(lCircleMid, lCircleMid, lCircleMid - 1,
+      lCircleMid - 1, BGRA(48, 48, 48), 1, bColor);
+  end;
+
+  Bitmap.Draw(TCanvas(ADest), 0, (ADest.Font.GetTextHeight('a') - lCircleHeight) div
+    2, False);
+end;
+
+procedure TBGRADrawer.DrawRadioButton(ADest: TCanvas; ASize: TSize;
+  AState: TCDControlState; AStateEx: TCDControlStateEx);
+var
+  lColor: TColor;
+  lCircleHeight: integer;
+  lTextHeight, lTextY: integer;
+begin
+  lCircleHeight := GetMeasures(TCDRADIOBUTTON_CIRCLE_HEIGHT);
+
+  // Background
+  lColor := $00535353; //AStateEx.ParentRGBColor;
+  ADest.Brush.Color := lColor;
+  ADest.Brush.Style := bsSolid;
+  ADest.Pen.Style := psClear;
+  ADest.FillRect(0, 0, ASize.cx, ASize.cy);
+
+  // The radiobutton circle itself
+  DrawRadioButtonCircle(ADest, Point(0, 0), ASize, AState, AStateEx);
+
+  // The text selection
+  //if csfHasFocus in AState then
+  //  DrawFocusRect(ADest, Point(lCircleHeight+3, 0),
+  //    Size(ASize.cx-lCircleHeight-3, ASize.cy));
+
+  // Now the text
+  ADest.Brush.Style := bsClear;
+  ADest.Font.Assign(AStateEx.Font);
+  if csfEnabled in AState then
+    ADest.Font.Color := $00E5E5E5
+  else
+    ADest.Font.Color := $00AAAAAA;
+  lTextHeight := ADest.TextHeight(cddTestStr);
+  // put the text in the center
+  if lCircleHeight > lTextHeight then
+    lTextY := (lCircleHeight - ADest.TextHeight(cddTestStr)) div 2
+  else
+    lTextY := 0;
+  lTextY := Max(0, lTextY - 1);
+  ADest.TextOut(lCircleHeight + 5, lTextY, AStateEx.Caption);
+end;
+
 initialization
   RegisterDrawer(TBGRADrawer.Create, dsCommon);
 

+ 39 - 4
test/test_bgracustomdrawn/umain.lfm

@@ -162,7 +162,7 @@ object frmMain: TfrmMain
       Left = 8
       Height = 20
       Top = 152
-      Width = 122
+      Width = 123
       DrawStyle = dsDefault
       Caption = 'BCDCheckBox1'
     end
@@ -170,7 +170,7 @@ object frmMain: TfrmMain
       Left = 8
       Height = 20
       Top = 176
-      Width = 122
+      Width = 123
       AllowGrayed = True
       DrawStyle = dsDefault
       Caption = 'BCDCheckBox2'
@@ -179,7 +179,7 @@ object frmMain: TfrmMain
       Left = 136
       Height = 20
       Top = 152
-      Width = 122
+      Width = 123
       DrawStyle = dsDefault
       Caption = 'BCDCheckBox3'
       Enabled = False
@@ -188,7 +188,7 @@ object frmMain: TfrmMain
       Left = 136
       Height = 20
       Top = 176
-      Width = 122
+      Width = 123
       AllowGrayed = True
       DrawStyle = dsDefault
       Caption = 'BCDCheckBox4'
@@ -209,6 +209,41 @@ object frmMain: TfrmMain
       MaxValue = 100
       Value = 1
     end
+    object BCDRadioButton1: TBCDRadioButton
+      Left = 8
+      Height = 20
+      Top = 200
+      Width = 142
+      Caption = 'BCDRadioButton1'
+      Checked = True
+      DrawStyle = dsDefault
+    end
+    object BCDRadioButton2: TBCDRadioButton
+      Left = 8
+      Height = 20
+      Top = 224
+      Width = 142
+      Caption = 'BCDRadioButton2'
+      DrawStyle = dsDefault
+    end
+    object BCDRadioButton3: TBCDRadioButton
+      Left = 152
+      Height = 20
+      Top = 200
+      Width = 142
+      Caption = 'BCDRadioButton3'
+      DrawStyle = dsDefault
+      Enabled = False
+    end
+    object BCDRadioButton4: TBCDRadioButton
+      Left = 152
+      Height = 20
+      Top = 224
+      Width = 142
+      Caption = 'BCDRadioButton4'
+      DrawStyle = dsDefault
+      Enabled = False
+    end
   end
   object BCToolBar1: TBCToolBar
     Left = 0

+ 6 - 0
test/test_bgracustomdrawn/umain.pas

@@ -23,6 +23,10 @@ type
     BCDEdit1: TBCDEdit;
     BCDEdit2: TBCDEdit;
     BCDProgressBar1: TBCDProgressBar;
+    BCDRadioButton1: TBCDRadioButton;
+    BCDRadioButton2: TBCDRadioButton;
+    BCDRadioButton3: TBCDRadioButton;
+    BCDRadioButton4: TBCDRadioButton;
     BCDSpinEdit1: TBCDSpinEdit;
     BCDSpinEdit2: TBCDSpinEdit;
     BCDStaticText1: TBCDStaticText;
@@ -150,6 +154,8 @@ begin
   BCDStaticText2.Enabled := not BCDStaticText2.Enabled;
   BCDCheckBox3.Enabled := not BCDCheckBox3.Enabled;
   BCDCheckBox4.Enabled := not BCDCheckBox4.Enabled;
+  BCDRadioButton3.Enabled := not BCDRadioButton3.Enabled;
+  BCDRadioButton4.Enabled := not BCDRadioButton4.Enabled;
 end;
 
 procedure TfrmMain.Timer1Timer(Sender: TObject);