Browse Source

Updated checkbox and scaling

lainz 9 years ago
parent
commit
788d517e68
3 changed files with 155 additions and 8 deletions
  1. 105 6
      bgracustomdrawn.pas
  2. 35 0
      test/test_bgracustomdrawn/umain.lfm
  3. 15 2
      test/test_bgracustomdrawn/umain.pas

+ 105 - 6
bgracustomdrawn.pas

@@ -49,8 +49,10 @@ type
   public
     constructor Create; override;
     { General }
+    function GetMeasures(AMeasureID: integer): integer; override;
     procedure DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint;
       AState: TCDControlState); override;
+    function DPIAdjustment(const AValue: integer): integer;
     { Button }
     procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint;
       ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override;
@@ -114,6 +116,54 @@ begin
   FRandSeed := randseed;
 end;
 
+function TBGRADrawer.GetMeasures(AMeasureID: integer): integer;
+begin
+  case AMeasureID of
+    TCDEDIT_LEFT_TEXT_SPACING: Result := 6;
+    TCDEDIT_RIGHT_TEXT_SPACING: Result := 3;
+    TCDEDIT_TOP_TEXT_SPACING: Result := 3;
+    TCDEDIT_BOTTOM_TEXT_SPACING: Result := 3;
+
+    TCDCHECKBOX_SQUARE_HALF_HEIGHT: Result :=
+        Floor(GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT) / 2);
+    TCDCHECKBOX_SQUARE_HEIGHT: Result := DPIAdjustment(13);
+
+    TCDCOMBOBOX_DEFAULT_HEIGHT: Result := 21;
+
+    TCDRADIOBUTTON_CIRCLE_HEIGHT: Result := 15;
+
+    TCDSCROLLBAR_BUTTON_WIDTH: Result := 17;
+    TCDSCROLLBAR_LEFT_SPACING: Result := 17;
+    TCDSCROLLBAR_RIGHT_SPACING: Result := 17;
+    TCDSCROLLBAR_LEFT_BUTTON_POS: Result := 0;
+    TCDSCROLLBAR_RIGHT_BUTTON_POS: Result := -17;
+
+    TCDTRACKBAR_LEFT_SPACING: Result := 9;
+    TCDTRACKBAR_RIGHT_SPACING: Result := 9;
+    TCDTRACKBAR_TOP_SPACING: Result := 5;
+    TCDTRACKBAR_FRAME_HEIGHT: Result := DPIAdjustment(17);
+
+    TCDLISTVIEW_COLUMN_LEFT_SPACING: Result := 10;
+    TCDLISTVIEW_COLUMN_RIGHT_SPACING: Result := 10;
+    TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING: Result := 5;
+    TCDLISTVIEW_LINE_TOP_SPACING: Result := 3;
+    TCDLISTVIEW_LINE_BOTTOM_SPACING: Result := 3;
+
+    TCDTOOLBAR_ITEM_SPACING: Result := 2;
+    TCDTOOLBAR_ITEM_ARROW_WIDTH: Result := 7;
+    TCDTOOLBAR_ITEM_BUTTON_DEFAULT_WIDTH: Result := 23;
+    TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH: Result := 35 - 23;
+    TCDTOOLBAR_ITEM_SEPARATOR_DEFAULT_WIDTH: Result := 8;
+    TCDTOOLBAR_DEFAULT_HEIGHT: Result := 26;
+
+    TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH: Result := 10;
+    TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING: Result := 10;
+    else
+      Result := 0;
+  end;
+  ;
+end;
+
 procedure TBGRADrawer.DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint;
   AState: TCDControlState);
 var
@@ -130,10 +180,12 @@ begin
   begin
     // 4 lines going down and to the right
     for i := 0 to 3 do
-      ADest.Line(ADestPos.X + 1 + i, ADestPos.Y + 2 + i, ADestPos.X + 1 + i, ADestPos.Y + 5 + i);
+      ADest.Line(ADestPos.X + 1 + i, ADestPos.Y + 2 + i, ADestPos.X +
+        1 + i, ADestPos.Y + 5 + i);
     // Now 5 lines going up and to the right
     for i := 4 to 8 do
-      ADest.Line(ADestPos.X + 1 + i, ADestPos.Y + 2 + 6 - i, ADestPos.X + 1 + i, ADestPos.Y + 5 + 6 - i);
+      ADest.Line(ADestPos.X + 1 + i, ADestPos.Y + 2 + 6 - i, ADestPos.X +
+        1 + i, ADestPos.Y + 5 + 6 - i);
     Exit;
   end;
 
@@ -143,13 +195,20 @@ begin
 
   // 4 lines going down and to the right
   for i := 0 to lFirstLinesEnd do
-    ADest.Line(ADestPos.X + 2 + i, ADestPos.Y + 2 + i, ADestPos.X + 2 + i, ADestPos.Y + lSpacing5 + i);
+    ADest.Line(ADestPos.X + 2 + i, ADestPos.Y + 2 + i, ADestPos.X +
+      2 + i, ADestPos.Y + lSpacing5 + i);
   // Now 5 lines going up and to the right
   for i := lFirstLinesEnd + 1 to lSecondLinesEnd do
     ADest.Line(ADestPos.X + 2 + i, ADestPos.Y + 2 + lFirstLinesEnd * 2 - i,
       ADestPos.X + 2 + i, ADestPos.Y + 2 + lFirstLinesEnd * 2 + lSpacing5 - i);
 end;
 
+function TBGRADrawer.DPIAdjustment(const AValue: integer): integer;
+begin
+  { Adjustment that works under Windows }
+  Result := ScaleY(AValue, 96);
+end;
+
 procedure TBGRADrawer.DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint;
   ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx);
 var
@@ -529,9 +588,49 @@ begin
   lSquareHalf := GetMeasures(TCDCHECKBOX_SQUARE_HALF_HEIGHT);
   lSquareHeight := GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT);
   r := Bounds(1, lHalf - lSquareHalf, lSquareHeight, lSquareHeight);
-  Bitmap.Rectangle(r.Left, r.Top, r.Right, r.Bottom, BGRA(48, 48, 48),
-    BGRA(84, 84, 84), dmSet);
-  Bitmap.SetHorizLine(r.Left + 1, r.Top + 1, r.Right - 2, BGRA(130, 130, 130));
+
+  if csfEnabled in AState then
+  begin
+    if csfSunken in AState then
+    begin
+      { Down }
+      Bitmap.Rectangle(r.Left, r.Top, r.Right, r.Bottom - 1, BGRA(48, 48, 48),
+        BGRA(61, 61, 61), dmSet);
+      Bitmap.Rectangle(r.Left + 1, r.Top + 1, r.Right - 1, r.Bottom -
+        2, BGRA(55, 55, 55),
+        BGRA(61, 61, 61), dmSet);
+      Bitmap.SetHorizLine(r.Left, r.Bottom - 1, r.Right - 1, BGRA(115, 115, 115));
+    end
+    else
+    begin
+      if csfMouseOver in AState then
+      begin
+        { Hovered }
+        Bitmap.GradientFill(r.Left, r.Top, r.Right, r.Bottom, BGRA(132, 132, 132),
+          BGRA(109, 109, 109), gtLinear, PointF(0, 0), PointF(0, ASize.cy), dmSet);
+        Bitmap.Rectangle(r.Left, r.Top, r.Right, r.Bottom - 1, BGRA(48, 48, 48), dmSet);
+        Bitmap.SetHorizLine(r.Left + 1, r.Top + 1, r.Right - 2, BGRA(160, 160, 160));
+        Bitmap.SetHorizLine(r.Left, r.Bottom - 1, r.Right - 1, BGRA(115, 115, 115));
+      end
+      else
+      begin
+        { Normal }
+        Bitmap.GradientFill(r.Left, r.Top, r.Right, r.Bottom, BGRA(107, 107, 107),
+          BGRA(84, 84, 84), gtLinear, PointF(0, 0), PointF(0, r.Bottom), dmSet);
+        Bitmap.Rectangle(r.Left, r.Top, r.Right, r.Bottom - 1, BGRA(48, 48, 48), dmSet);
+        Bitmap.SetHorizLine(r.Left + 1, r.Top + 1, r.Right - 2, BGRA(130, 130, 130));
+        Bitmap.SetHorizLine(r.Left, r.Bottom - 1, r.Right - 1, BGRA(115, 115, 115));
+      end;
+    end;
+  end
+  else
+  begin
+    { Disabled }
+    Bitmap.Rectangle(r.Left, r.Top, r.Right, r.Bottom - 1, BGRA(66, 66, 66),
+      BGRA(71, 71, 71), dmSet);
+    Bitmap.SetHorizLine(r.Left, r.Bottom - 1, r.Right - 1, BGRA(94, 94, 94));
+  end;
+
   Bitmap.Draw(TCanvas(ADest), ADestPos.x, ADestPos.y, False);
   Bitmap.Free;
 end;

+ 35 - 0
test/test_bgracustomdrawn/umain.lfm

@@ -77,6 +77,7 @@ object frmMain: TfrmMain
       Width = 96
       Caption = 'BCDButton1'
       DrawStyle = dsDefault
+      OnClick = BCDButton1Click
       TabOrder = 0
       TabStop = True
     end
@@ -174,6 +175,40 @@ object frmMain: TfrmMain
       DrawStyle = dsDefault
       Caption = 'BCDCheckBox2'
     end
+    object BCDCheckBox3: TBCDCheckBox
+      Left = 136
+      Height = 20
+      Top = 152
+      Width = 122
+      DrawStyle = dsDefault
+      Caption = 'BCDCheckBox3'
+      Enabled = False
+    end
+    object BCDCheckBox4: TBCDCheckBox
+      Left = 136
+      Height = 20
+      Top = 176
+      Width = 122
+      AllowGrayed = True
+      DrawStyle = dsDefault
+      Caption = 'BCDCheckBox4'
+      Enabled = False
+    end
+    object BCDSpinEdit2: TBCDSpinEdit
+      Left = 200
+      Height = 25
+      Top = 40
+      Width = 80
+      DrawStyle = dsDefault
+      Enabled = False
+      Lines.Strings = (
+        '1'
+      )
+      Increment = 1
+      MinValue = 0
+      MaxValue = 100
+      Value = 1
+    end
   end
   object BCToolBar1: TBCToolBar
     Left = 0

+ 15 - 2
test/test_bgracustomdrawn/umain.pas

@@ -9,7 +9,7 @@ uses
   { BGRABitmap }
   BGRABitmap, BGRABitmapTypes,
   { BGRAControls }
-  BGRACustomDrawn, BCPanel, BCToolBar;
+  BGRACustomDrawn, BCPanel, BCToolBar, Classes;
 
 type
 
@@ -18,10 +18,13 @@ type
   TfrmMain = class(TForm)
     BCDButton1: TBCDButton;
     BCDButton2: TBCDButton;
+    BCDCheckBox3: TBCDCheckBox;
+    BCDCheckBox4: TBCDCheckBox;
     BCDEdit1: TBCDEdit;
     BCDEdit2: TBCDEdit;
     BCDProgressBar1: TBCDProgressBar;
     BCDSpinEdit1: TBCDSpinEdit;
+    BCDSpinEdit2: TBCDSpinEdit;
     BCDStaticText1: TBCDStaticText;
     BCDStaticText2: TBCDStaticText;
     BCPanel1: TBCPanel;
@@ -33,6 +36,7 @@ type
     ToolButton2: TToolButton;
     ToolButton3: TToolButton;
     ToolButton4: TToolButton;
+    procedure BCDButton1Click(Sender: TObject);
     procedure BCToolBar1PaintButton(Sender: TToolButton; State: integer);
     procedure BCToolBar1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
     procedure FormCreate(Sender: TObject);
@@ -58,7 +62,6 @@ procedure TfrmMain.FormCreate(Sender: TObject);
 begin
   Self.AutoAdjustLayout(lapAutoAdjustForDPI, Self.DesignTimeDPI,
     Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, Self.DesignTimeDPI));
-  BCToolBar1.Font.Color := clWhite;
 end;
 
 procedure TfrmMain.BCToolBar1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
@@ -139,6 +142,16 @@ begin
   Bitmap.Free;
 end;
 
+procedure TfrmMain.BCDButton1Click(Sender: TObject);
+begin
+  BCDButton2.Enabled := not BCDButton2.Enabled;
+  BCDEdit2.Enabled := not BCDEdit2.Enabled;
+  BCDSpinEdit2.Enabled := not BCDSpinEdit2.Enabled;
+  BCDStaticText2.Enabled := not BCDStaticText2.Enabled;
+  BCDCheckBox3.Enabled := not BCDCheckBox3.Enabled;
+  BCDCheckBox4.Enabled := not BCDCheckBox4.Enabled;
+end;
+
 procedure TfrmMain.Timer1Timer(Sender: TObject);
 begin
   if BCDProgressBar1.Position <> BCDProgressBar1.Max then