customdrawn: Fixes the drawing of multiple controls after the big rewrite

git-svn-id: trunk@33257 -
This commit is contained in:
sekelsenmat 2011-11-03 12:36:24 +00:00
parent 9a57549165
commit 3a4ec76f82
4 changed files with 145 additions and 108 deletions

View File

@ -26,6 +26,9 @@ type
function GetMeasures(AMeasureID: Integer): Integer; override; function GetMeasures(AMeasureID: Integer): Integer; override;
function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer; function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer;
AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; override; AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; override;
procedure CalculatePreferredSize(ADest: TCanvas; AControlId: TCDControlID;
AState: TCDControlState; AStateEx: TCDControlStateEx;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
function GetColor(AColorID: Integer): TColor; override; function GetColor(AColorID: Integer): TColor; override;
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); override; AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); override;
@ -41,9 +44,6 @@ type
procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDEditStateEx); override; AState: TCDControlState; AStateEx: TCDEditStateEx); override;
// TCDCheckBox // TCDCheckBox
procedure CalculateCheckBoxPreferredSize(ADest: TCanvas;
AState: TCDControlState; AStateEx: TCDControlStateEx;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); override; AState: TCDControlState; AStateEx: TCDControlStateEx); override;
// TCDGroupBox // TCDGroupBox
@ -52,6 +52,8 @@ type
// =================================== // ===================================
// Common Controls Tab // Common Controls Tab
// =================================== // ===================================
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override;
// TCDCustomTabControl // TCDCustomTabControl
procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
@ -104,6 +106,25 @@ begin
end; end;
end; end;
procedure TCDDrawerCommon.CalculatePreferredSize(ADest: TCanvas;
AControlId: TCDControlID; AState: TCDControlState;
AStateEx: TCDControlStateEx; var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean);
begin
PreferredWidth := 0;
PreferredHeight := 0;
case AControlId of
cidCheckBox:
begin
if AStateEx.AutoSize then
PreferredWidth := 21 + GetMeasuresEx(ADest, TCDCONTROL_CAPTION_WIDTH, AState, AStateEx);
PreferredHeight := GetMeasuresEx(ADest, TCDCONTROL_CAPTION_HEIGHT, AState, AStateEx);
end;
end;
end;
function TCDDrawerCommon.GetColor(AColorID: Integer): TColor; function TCDDrawerCommon.GetColor(AColorID: Integer): TColor;
begin begin
case AColorId of case AColorId of
@ -121,7 +142,12 @@ procedure TCDDrawerCommon.DrawControl(ADest: TCanvas; ADestPos: TPoint;
AStateEx: TCDControlStateEx); AStateEx: TCDControlStateEx);
begin begin
case AControl of case AControl of
cidButton: DrawButton(ADest, ADestPos, ASize, AState, AStateEx); cidButton: DrawButton(ADest, ADestPos, ASize, AState, AStateEx);
cidEdit: DrawEdit(ADest, ADestPos, ASize, AState, TCDEditStateEx(AStateEx));
cidCheckBox: DrawCheckBox(ADest, ADestPos, ASize, AState, AStateEx);
cidGroupBox: DrawGroupBox(ADest, ADestPos, ASize, AState, AStateEx);
cidTrackBar: DrawTrackBar(ADest, ADestPos, ASize, AState, TCDTrackBarStateEx(AStateEx));
cidCTabControl:DrawCTabControl(ADest, ADestPos, ASize, AState, TCDCTabControlStateEx(AStateEx));
end; end;
end; end;
@ -265,18 +291,6 @@ begin
end; end;
end; end;
procedure TCDDrawerCommon.CalculateCheckBoxPreferredSize(ADest: TCanvas;
AState: TCDControlState; AStateEx: TCDControlStateEx; var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
begin
PreferredWidth := 0;
if AStateEx.AutoSize then
PreferredWidth := 21 + GetMeasuresEx(ADest, TCDCONTROL_CAPTION_WIDTH, AState, AStateEx);
PreferredHeight := GetMeasuresEx(ADest, TCDCONTROL_CAPTION_HEIGHT, AState, AStateEx);
end;
procedure TCDDrawerCommon.DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; procedure TCDDrawerCommon.DrawCheckBox(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx); ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
const const
@ -370,6 +384,12 @@ begin
ADest.TextOut(FCaptionMiddle, 0, AStateEx.Caption); ADest.TextOut(FCaptionMiddle, 0, AStateEx.Caption);
end; end;
procedure TCDDrawerCommon.DrawTrackBar(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDTrackBarStateEx);
begin
end;
procedure TCDDrawerCommon.DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; procedure TCDDrawerCommon.DrawCTabControl(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
var var

View File

@ -6,16 +6,26 @@ interface
uses uses
// RTL // RTL
Classes, SysUtils, Classes, SysUtils, Types,
// fpimage
fpcanvas, fpimgcanv, fpimage,
// LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage // LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage
Graphics, Controls, LCLType, LCLIntf, IntfGraphics, Graphics, Controls, LCLType,
// //
customdrawncontrols, customdrawnutils; customdrawndrawers, customdrawn_common;
{type type
TCDButtonDrawerGrad = class(TCDButtonDrawer)
{ TCDDrawerExtra1 }
TCDDrawerExtra1 = class(TCDDrawerCommon)
public
function GetMeasures(AMeasureID: Integer): Integer; override;
// ===================================
// Common Controls Tab
// ===================================
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override;
end;
{ TCDButtonDrawerGrad = class(TCDButtonDrawer)
public public
procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override; procedure DrawToIntfImage(ADest: TFPImageCanvas; CDButton: TCDButton); override;
procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override; procedure DrawToCanvas(ADest: TCanvas; CDButton: TCDButton); override;
@ -87,6 +97,30 @@ end;
procedure TCDTrackBarDrawerGraph.DrawToIntfImage(ADest: TFPImageCanvas; procedure TCDTrackBarDrawerGraph.DrawToIntfImage(ADest: TFPImageCanvas;
FPImg: TLazIntfImage; CDTrackBar: TCDTrackBar); FPImg: TLazIntfImage; CDTrackBar: TCDTrackBar);
procedure TCDTrackBarDrawerGraph.GetGeometry(var ALeftBorder,
ARightBorder: Integer);
begin
ALeftBorder := 9;
ARightBorder := 9;
end;
RegisterTrackBarDrawer(TCDTrackBarDrawerGraph.Create, dsExtra1);}
{ TCDDrawerExtra1 }
function TCDDrawerExtra1.GetMeasures(AMeasureID: Integer): Integer;
begin
case AMeasureId of
TCDTRACKBAR_LEFT_SPACING: Result := 9;
TCDTRACKBAR_RIGHT_SPACING: Result := 9;
else
Result:=inherited GetMeasures(AMeasureID);
end;
end;
procedure TCDDrawerExtra1.DrawTrackBar(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDTrackBarStateEx);
const const
CDBarEdge = 18; CDBarEdge = 18;
var var
@ -96,43 +130,40 @@ var
pStepWidth, pHalfStepWidth: Integer; pStepWidth, pHalfStepWidth: Integer;
begin begin
// Sanity check // Sanity check
if CDTrackBar.Max - CDTrackBar.Min <= 0 then if AStateEx.Max - AStateEx.Min <= 0 then
raise Exception.Create('[TCDTrackBarDrawerGraph.DrawToIntfImage] Max-Min must be at least 1'); raise Exception.Create('[TCDTrackBarDrawerGraph.DrawToIntfImage] Max-Min must be at least 1');
// Preparations // Preparations
StepsCount := CDTrackBar.Max - CDTrackBar.Min + 1; StepsCount := AStateEx.Max - AStateEx.Min + 1;
pStepWidth := (CDTrackBar.Width - CDBarEdge) div StepsCount; pStepWidth := (ASize.cx - CDBarEdge) div StepsCount;
pHalfStepWidth := (CDTrackBar.Width - CDBarEdge) div (StepsCount * 2); pHalfStepWidth := (ASize.cx - CDBarEdge) div (StepsCount * 2);
// The bottom part of the drawing // The bottom part of the drawing
lDrawingBottom := CDTrackBar.Height - 10; lDrawingBottom := ASize.cy - 10;
// Background // Background
if CDTrackBar.Parent = nil then ADest.Brush.Color := AStateEx.ParentRGBColor;
ADest.Brush.FPColor := colLtGray
else
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB(CDTrackBar.Color));
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
ADest.Pen.Style := psClear; ADest.Pen.Style := psClear;
ADest.Rectangle(0, 0, CDTrackBar.Width, CDTrackBar.Height); ADest.Rectangle(0, 0, ASize.cx, ASize.cy);
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6)); ADest.Brush.Color := ColorToRGB($006BB6E6);
// Draws the double-sided arrow in the center of the slider // Draws the double-sided arrow in the center of the slider
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($006BB6E6)); ADest.Pen.Color := ColorToRGB($006BB6E6);
ADest.Line(0, lDrawingBottom, CDTrackBar.Width, lDrawingBottom); ADest.Line(0, lDrawingBottom, ASize.cx, lDrawingBottom);
ADest.Line(3, lDrawingBottom - 1, 6, lDrawingBottom - 1); ADest.Line(3, lDrawingBottom - 1, 6, lDrawingBottom - 1);
ADest.Line(5, lDrawingBottom - 2, 6, lDrawingBottom - 2); ADest.Line(5, lDrawingBottom - 2, 6, lDrawingBottom - 2);
ADest.Line(3, lDrawingBottom + 1, 6, lDrawingBottom + 1); ADest.Line(3, lDrawingBottom + 1, 6, lDrawingBottom + 1);
ADest.Line(5, lDrawingBottom + 2, 6, lDrawingBottom + 2); ADest.Line(5, lDrawingBottom + 2, 6, lDrawingBottom + 2);
ADest.Line(CDTrackBar.Width - 1 - 3, lDrawingBottom - 1, CDTrackBar.Width - 1 - 6, lDrawingBottom - 1); ADest.Line(ASize.cx - 1 - 3, lDrawingBottom - 1, ASize.cx - 1 - 6, lDrawingBottom - 1);
ADest.Line(CDTrackBar.Width - 1 - 5, lDrawingBottom - 2, CDTrackBar.Width - 1 - 6, lDrawingBottom - 2); ADest.Line(ASize.cx - 1 - 5, lDrawingBottom - 2, ASize.cx - 1 - 6, lDrawingBottom - 2);
ADest.Line(CDTrackBar.Width - 1 - 3, lDrawingBottom + 1, CDTrackBar.Width - 1 - 6, lDrawingBottom + 1); ADest.Line(ASize.cx - 1 - 3, lDrawingBottom + 1, ASize.cx - 1 - 6, lDrawingBottom + 1);
ADest.Line(CDTrackBar.Width - 1 - 5, lDrawingBottom + 2, CDTrackBar.Width - 1 - 6, lDrawingBottom + 2); ADest.Line(ASize.cx - 1 - 5, lDrawingBottom + 2, ASize.cx - 1 - 6, lDrawingBottom + 2);
ADest.Pen.FPColor := TColorToFPColor(ColorToRGB(clGray)); ADest.Pen.Color := ColorToRGB(clGray);
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($00F0F0F0)); ADest.Brush.Color := ColorToRGB($00F0F0F0);
// Draws the decorative bars and also the slider button // Draws the decorative bars and also the slider button
@ -148,17 +179,17 @@ begin
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
ADest.Pen.FPColor := colBlack; ADest.Pen.Color := clBlack;
if i + CDTrackBar.Min <= CDTrackBar.Position then if i + AStateEx.Min <= AStateEx.Position then
ADest.Brush.FPColor := colDkGray ADest.Brush.Color := clDkGray
else else
ADest.Brush.FPColor := colWhite; ADest.Brush.Color := clWhite;
ADest.Rectangle(dRect); ADest.Rectangle(dRect);
// Draw the slider // Draw the slider
if i + CDTrackBar.Min = CDTrackBar.Position then if i + AStateEx.Min = AStateEx.Position then
begin begin
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6)); ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6));
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
@ -172,31 +203,23 @@ begin
end; end;
ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($007BC6F6)); ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($007BC6F6));
ADest.Line(7, lDrawingBottom - 1, CDTrackBar.Width - 8, lDrawingBottom - 1); ADest.Line(7, lDrawingBottom - 1, ASize.cx - 8, lDrawingBottom - 1);
ADest.Line(7, lDrawingBottom + 1, CDTrackBar.Width - 8, lDrawingBottom + 1); ADest.Line(7, lDrawingBottom + 1, ASize.cx - 8, lDrawingBottom + 1);
ADest.Colors[2, lDrawingBottom - 1] := ADest.Pen.FPColor; ADest.Colors[2, lDrawingBottom - 1] := ADest.Pen.FPColor;
ADest.Colors[4, lDrawingBottom - 2] := ADest.Pen.FPColor; ADest.Colors[4, lDrawingBottom - 2] := ADest.Pen.FPColor;
ADest.Colors[2, lDrawingBottom + 1] := ADest.Pen.FPColor; ADest.Colors[2, lDrawingBottom + 1] := ADest.Pen.FPColor;
ADest.Colors[4, lDrawingBottom + 2] := ADest.Pen.FPColor; ADest.Colors[4, lDrawingBottom + 2] := ADest.Pen.FPColor;
ADest.Colors[6, lDrawingBottom - 3] := ADest.Pen.FPColor; ADest.Colors[6, lDrawingBottom - 3] := ADest.Pen.FPColor;
ADest.Colors[6, lDrawingBottom + 3] := ADest.Pen.FPColor; ADest.Colors[6, lDrawingBottom + 3] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 2, lDrawingBottom - 1] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 2, lDrawingBottom - 1] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 4, lDrawingBottom - 2] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 4, lDrawingBottom - 2] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 2, lDrawingBottom + 1] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 2, lDrawingBottom + 1] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 4, lDrawingBottom + 2] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 4, lDrawingBottom + 2] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 6, lDrawingBottom - 3] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 6, lDrawingBottom - 3] := ADest.Pen.FPColor;
ADest.Colors[CDTrackBar.Width - 1 - 6, lDrawingBottom + 3] := ADest.Pen.FPColor; ADest.Colors[ASize.cx - 1 - 6, lDrawingBottom + 3] := ADest.Pen.FPColor;
end;
procedure TCDTrackBarDrawerGraph.GetGeometry(var ALeftBorder,
ARightBorder: Integer);
begin
ALeftBorder := 9;
ARightBorder := 9;
end; end;
initialization initialization
RegisterButtonDrawer(TCDButtonDrawerGrad.Create, dsExtra1); RegisterDrawer(TCDDrawerExtra1.Create, dsExtra1);
RegisterTrackBarDrawer(TCDTrackBarDrawerGraph.Create, dsExtra1);}
end. end.

View File

@ -35,6 +35,8 @@ type
FDrawer: TCDDrawer; FDrawer: TCDDrawer;
FState: TCDControlState; FState: TCDControlState;
FStateEx: TCDControlStateEx; FStateEx: TCDControlStateEx;
procedure CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean); override;
procedure PrepareCurrentDrawer(); virtual; procedure PrepareCurrentDrawer(); virtual;
procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual; procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual;
function GetClientRect: TRect; override; function GetClientRect: TRect; override;
@ -193,8 +195,6 @@ type
FCheckedState: TCheckBoxState; FCheckedState: TCheckBoxState;
protected protected
procedure DoButtonUp(); override; procedure DoButtonUp(); override;
procedure CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean); override;
function GetControlId: TCDControlID; override; function GetControlId: TCDControlID; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -207,16 +207,6 @@ type
property State: TCheckBoxState read FCheckedState write FCheckedState default cbUnchecked; property State: TCheckBoxState read FCheckedState write FCheckedState default cbUnchecked;
end; end;
{ TCDCheckBoxDrawer }
TCDCheckBoxDrawer = class(TCDDrawer)
public
procedure CalculatePreferredSize(CDCheckBox: TCDCheckBox; var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean); virtual; abstract;
procedure DrawToIntfImage(ADest: TFPImageCanvas; CDCheckBox: TCDCheckBox); virtual; abstract;
procedure DrawToCanvas(ADest: TCanvas; CDCheckBox: TCDCheckBox); virtual; abstract;
end;
// =================================== // ===================================
// Common Controls Tab // Common Controls Tab
// =================================== // ===================================
@ -264,6 +254,7 @@ type
//procedure Paint; override; //procedure Paint; override;
published published
property Color; property Color;
property DrawStyle;
property Max: integer read FMax write SetMax default 10; property Max: integer read FMax write SetMax default 10;
property Min: integer read FMin write SetMin default 0; property Min: integer read FMin write SetMin default 0;
property OnChange: TNotifyEvent read FOnChange write FOnChange; property OnChange: TNotifyEvent read FOnChange write FOnChange;
@ -271,15 +262,6 @@ type
property TabStop default True; property TabStop default True;
end; end;
{ TCDTrackBarDrawer }
TCDTrackBarDrawer = class(TCDDrawer)
public
procedure DrawToIntfImage(ADest: TFPImageCanvas; FPImg: TLazIntfImage;
CDTrackBar: TCDTrackBar); virtual; abstract;
procedure GetGeometry(var ALeftBorder, ARightBorder: Integer); virtual; abstract;
end;
{ TCDListView } { TCDListView }
(* TCDListView = class(TCDControl) (* TCDListView = class(TCDControl)
@ -694,13 +676,6 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCDCheckBox.CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
begin
TCDCheckBoxDrawer(FDrawer).CalculatePreferredSize(
Self, PreferredWidth, PreferredHeight, WithThemeSpace)
end;
function TCDCheckBox.GetControlId: TCDControlID; function TCDCheckBox.GetControlId: TCDControlID;
begin begin
Result := cidCheckBox; Result := cidCheckBox;
@ -822,7 +797,7 @@ end;
function TCDCustomTabControl.GetControlId: TCDControlID; function TCDCustomTabControl.GetControlId: TCDControlID;
begin begin
Result := cidCustomTabControl; Result := cidCTabControl;
end; end;
procedure TCDCustomTabControl.CreateControlStateEx; procedure TCDCustomTabControl.CreateControlStateEx;
@ -878,6 +853,15 @@ end;
{ TCDControl } { TCDControl }
procedure TCDControl.CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer; WithThemeSpace: Boolean);
begin
PrepareControlState;
PrepareControlStateEx;
FDrawer.CalculatePreferredSize(Canvas, GetControlId(), FState, FStateEx,
PreferredWidth, PreferredHeight, WithThemeSpace);
end;
procedure TCDControl.PrepareCurrentDrawer; procedure TCDControl.PrepareCurrentDrawer;
begin begin
FDrawer := GetDrawer(FDrawStyle); FDrawer := GetDrawer(FDrawStyle);
@ -925,9 +909,12 @@ end;
procedure TCDControl.PrepareControlStateEx; procedure TCDControl.PrepareControlStateEx;
begin begin
if Parent <> nil then FStateEx.ParentRGBColor := Parent.GetRGBBackgroundColor; if Parent <> nil then FStateEx.ParentRGBColor := Parent.GetRGBBackgroundColor
else FStateEx.ParentRGBColor := clSilver;
if Color = clDefault then FStateEx.RGBColor := FDrawer.GetControlColor(GetControlId()) if Color = clDefault then FStateEx.RGBColor := FDrawer.GetControlColor(GetControlId())
else FStateEx.RGBColor := GetRGBBackgroundColor; else FStateEx.RGBColor := GetRGBBackgroundColor;
FStateEx.Caption := Caption; FStateEx.Caption := Caption;
FStateEx.Font := Font; FStateEx.Font := Font;
FStateEx.AutoSize := AutoSize; FStateEx.AutoSize := AutoSize;
@ -1151,7 +1138,9 @@ function TCDTrackBar.GetPositionFromMousePos(X, Y: integer): integer;
var var
lLeftBorder, lRightBorder: Integer; lLeftBorder, lRightBorder: Integer;
begin begin
TCDTrackBarDrawer(FDrawer).GetGeometry(lLeftBorder, lRightBorder); lLeftBorder := FDrawer.GetMeasures(TCDTRACKBAR_LEFT_SPACING);
lRightBorder := FDrawer.GetMeasures(TCDTRACKBAR_RIGHT_SPACING);
if X > Width - lRightBorder then Result := FMax if X > Width - lRightBorder then Result := FMax
else if X < lLeftBorder then Result := FMin else if X < lLeftBorder then Result := FMin
else Result := FMin + (X - lLeftBorder) * (FMax - FMin + 1) div (Width - lRightBorder - lLeftBorder); else Result := FMin + (X - lLeftBorder) * (FMax - FMin + 1) div (Width - lRightBorder - lLeftBorder);

View File

@ -15,13 +15,15 @@ const
// Measures // Measures
TCDEDIT_LEFT_TEXT_SPACING = $400; // The space between the start of the text and the left end of the control TCDEDIT_LEFT_TEXT_SPACING = $400; // The space between the start of the text and the left end of the control
TCDEDIT_RIGHT_TEXT_SPACING = $401; // The space between the end of the text and the right end of the control TCDEDIT_RIGHT_TEXT_SPACING = $401; // The space between the end of the text and the right end of the control
TCDTRACKBAR_LEFT_SPACING = $1000;
TCDTRACKBAR_RIGHT_SPACING = $1001;
// Measures Ex // Measures Ex
TCDCONTROL_CAPTION_WIDTH = $100; TCDCONTROL_CAPTION_WIDTH = $100;
TCDCONTROL_CAPTION_HEIGHT = $101; TCDCONTROL_CAPTION_HEIGHT = $101;
TCDCTABCONTROL_TAB_HEIGHT = $1000; TCDCTABCONTROL_TAB_HEIGHT = $1100;
TCDCTABCONTROL_TAB_WIDTH = $1001; TCDCTABCONTROL_TAB_WIDTH = $1101;
// Colors // Colors
TCDEDIT_BACKGROUND_COLOR = $400; TCDEDIT_BACKGROUND_COLOR = $400;
@ -128,7 +130,7 @@ type
cidCheckBox, cidCheckBox,
cidGroupBox, cidGroupBox,
cidTrackBar, cidTrackBar,
cidCustomTabControl cidCTabControl
); );
{ TCDDrawer } { TCDDrawer }
@ -144,6 +146,9 @@ type
function GetMeasures(AMeasureID: Integer): Integer; virtual; abstract; function GetMeasures(AMeasureID: Integer): Integer; virtual; abstract;
function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer; function GetMeasuresEx(ADest: TCanvas; AMeasureID: Integer;
AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; virtual; abstract; AState: TCDControlState; AStateEx: TCDControlStateEx): Integer; virtual; abstract;
procedure CalculatePreferredSize(ADest: TCanvas; AControlId: TCDControlID;
AState: TCDControlState; AStateEx: TCDControlStateEx;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); virtual; abstract;
function GetColor(AColorID: Integer): TColor; virtual; abstract; function GetColor(AColorID: Integer): TColor; virtual; abstract;
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; AControl: TCDControlID; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
@ -156,9 +161,6 @@ type
procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawEdit(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDEditStateEx); virtual; abstract; AState: TCDControlState; AStateEx: TCDEditStateEx); virtual; abstract;
// TCDCheckBox // TCDCheckBox
procedure CalculateCheckBoxPreferredSize(ADest: TCanvas;
AState: TCDControlState; AStateEx: TCDControlStateEx;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); virtual; abstract;
procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawCheckBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract; AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
// TCDGroupBox // TCDGroupBox
@ -167,6 +169,9 @@ type
// =================================== // ===================================
// Common Controls Tab // Common Controls Tab
// =================================== // ===================================
// TCDTrackBar
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); virtual; abstract;
// TCDCustomTabControl // TCDCustomTabControl
procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract; AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract;
@ -232,13 +237,13 @@ end;
function TCDDrawer.GetControlColor(AControlId: TCDControlID): TColor; function TCDDrawer.GetControlColor(AControlId: TCDControlID): TColor;
begin begin
case AControlId of case AControlId of
cidControl: Result := clSilver; cidControl: Result := clSilver;
cidButton: Result := clSilver; cidButton: Result := clSilver;
cidEdit: Result := clSilver; cidEdit: Result := clSilver;
cidCheckBox: Result := clSilver; cidCheckBox: Result := clSilver;
cidGroupBox: Result := clSilver; cidGroupBox: Result := clSilver;
cidTrackBar: Result := clSilver; cidTrackBar: Result := clSilver;
cidCustomTabControl: Result := clSilver; cidCTabControl: Result := clSilver;
else else
Result := clSilver; Result := clSilver;
end; end;