customdrawn: Small fixes

git-svn-id: trunk@33268 -
This commit is contained in:
sekelsenmat 2011-11-03 16:34:16 +00:00
parent 7affaf002f
commit 4cb152f986
4 changed files with 189 additions and 43 deletions

View File

@ -50,6 +50,7 @@ type
// =================================== // ===================================
// Common Controls Tab // Common Controls Tab
// =================================== // ===================================
// TCDTrackBar
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override; AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override;
// TCDCustomTabControl // TCDCustomTabControl
@ -90,8 +91,8 @@ begin
TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight('ŹÇ')+3; TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight('ŹÇ')+3;
TCDCTABCONTROL_TAB_HEIGHT: TCDCTABCONTROL_TAB_HEIGHT:
begin begin
if AStateEx.Font.Size = 0 then Result := 32 if AStateEx.Font.Size = 0 then Result := 22
else Result := AStateEx.Font.Size + 22; else Result := AStateEx.Font.Size + 14;
end; end;
TCDCTABCONTROL_TAB_WIDTH: TCDCTABCONTROL_TAB_WIDTH:
begin begin
@ -411,27 +412,32 @@ begin
ADest.Brush.Color := AStateEx.ParentRGBColor; ADest.Brush.Color := AStateEx.ParentRGBColor;
ADest.Rectangle(ADestPos.X, ADestPos.Y, ADestPos.X+ASize.cx, ADestPos.Y+ASize.cy); ADest.Rectangle(ADestPos.X, ADestPos.Y, ADestPos.X+ASize.cx, ADestPos.Y+ASize.cy);
CaptionHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx);
// frame // frame
if AStateEx.TabCount = 0 then CaptionHeight := 0
else CaptionHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx);
// white lines in the left and top
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear; ADest.Brush.Style := bsClear;
ADest.Pen.Color := ColorToRGB($009C9B91); ADest.Pen.Color := clWhite;
ADest.Line(0, CaptionHeight, 0, ASize.cy-1);
if AStateEx.TabCount = 0 then ADest.Pixels[1,1] := clWhite;
ADest.Rectangle(0, 0, ASize.cx - 2, ASize.cy - 2) ADest.Line(2, CaptionHeight, ASize.cx-1, CaptionHeight);
else // Grey line on the inside left and top
ADest.Rectangle(0, CaptionHeight, ASize.cx - 2, ASize.cy - 2); ADest.Pen.Color := ColorToRGB($00E2EFF1);
ADest.Line(1, CaptionHeight, 1, ASize.cy-2);
ADest.Pen.Color := ColorToRGB($00BFCED0); ADest.Line(2, CaptionHeight+1, ASize.cx-2, CaptionHeight+1);
ADest.Line(ASize.cx - 1, CaptionHeight + 1, // Dark grey line on the right and bottom
ASize.cx - 1, ASize.cy - 1); ADest.Pen.Color := ColorToRGB($00646F71);
ADest.Line(ASize.cx - 1, ASize.cy - 1, 1, ADest.Line(0, ASize.cy, ASize.cx, ASize.cy);
ASize.cy - 1); ADest.Line(ASize.cx, ASize.cy, ASize.cx, CaptionHeight);
// Grey line on the inside right and bottom
ADest.Pen.Color := ColorToRGB($00646F71);
ADest.Line(1, ASize.cy-1, ASize.cx-1, ASize.cy-1);
ADest.Line(ASize.cx-1, ASize.cy-1, ASize.cx-1, CaptionHeight);
// Tabs // Tabs
ADest.Font.Name := AStateEx.Font.Name; ADest.Font.Assign(AStateEx.Font);
ADest.Font.Size := AStateEx.Font.Size;
DrawTabs(ADest, ADestPos, ASize, AState, AStateEx); DrawTabs(ADest, ADestPos, ASize, AState, AStateEx);
end; end;
@ -473,20 +479,14 @@ var
lTabWidth, lTabHeight, lTabTopPos: Integer; lTabWidth, lTabHeight, lTabTopPos: Integer;
Points: array of TPoint; Points: array of TPoint;
lCaption: String; lCaption: String;
lTabHeightCorrection: Integer = 0;
begin begin
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex; IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
if IsSelected then if not IsSelected then lTabHeightCorrection := 3;
begin
lTabTopPos := 0;
lTabHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx);
end
else
begin
lTabTopPos := 5;
lTabHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx)-5;
end;
lTabTopPos := lTabHeightCorrection;
lTabHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx)-lTabHeightCorrection;
lTabWidth := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx); lTabWidth := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx);
// Fill the area inside the outer border // Fill the area inside the outer border
@ -502,7 +502,6 @@ begin
ADest.Polygon(Points); ADest.Polygon(Points);
// Draw the outer border only in the top and right sides, // Draw the outer border only in the top and right sides,
// and bottom if unselected
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear; ADest.Brush.Style := bsClear;
ADest.Pen.Color := ColorToRGB($009C9B91); ADest.Pen.Color := ColorToRGB($009C9B91);
@ -511,16 +510,27 @@ begin
ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+5); ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+5);
ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight); ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight);
// If it is selected, add a selection frame
if IsSelected then if IsSelected then
begin begin
ADest.Pen.Color := ColorToRGB($00D6C731); // If it is selected, add a selection frame
ADest.Pen.Color := clWhite;
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear; ADest.Brush.Style := bsClear;
ADest.Rectangle( ADest.Rectangle(
AStateEx.CurStartLeftPos+3, lTabTopPos+3, AStateEx.CurStartLeftPos+3, lTabTopPos+3,
AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos+lTabHeight-5 AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos+lTabHeight-3);
); ADest.Pen.Color := clBlack;
ADest.Pen.Style := psDot;
ADest.Rectangle(
AStateEx.CurStartLeftPos+3, lTabTopPos+3,
AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos+lTabHeight-3);
// and Clear the bottom area if selected
ADest.Pen.Color := AStateEx.RGBColor;
ADest.Line(AStateEx.CurStartLeftPos, lTabTopPos+lTabHeight,
AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight);
ADest.Line(AStateEx.CurStartLeftPos, lTabTopPos+lTabHeight-1,
AStateEx.CurStartLeftPos+lTabWidth-2, lTabTopPos+lTabHeight-1);
end; end;
// Now the text // Now the text

View File

@ -23,6 +23,15 @@ type
// TCDButton // TCDButton
procedure DrawButton(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; procedure DrawButton(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); override; AState: TCDControlState; AStateEx: TCDControlStateEx); override;
// TCDCustomTabControl
procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
procedure DrawTabSheet(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
procedure DrawTabs(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
procedure DrawTab(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
end; end;
implementation implementation
@ -88,6 +97,129 @@ begin
(ASize.cy - ADest.TextHeight(Str)) div 2, Str); (ASize.cy - ADest.TextHeight(Str)) div 2, Str);
end; end;
procedure TCDDrawerWinCE.DrawCTabControl(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
var
CaptionHeight: Integer;
begin
// Background
ADest.Pen.Style := psSolid;
ADest.Pen.Color := AStateEx.ParentRGBColor;
ADest.Brush.Style := bsSolid;
ADest.Brush.Color := AStateEx.ParentRGBColor;
ADest.Rectangle(ADestPos.X, ADestPos.Y, ADestPos.X+ASize.cx, ADestPos.Y+ASize.cy);
CaptionHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx);
// frame
ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear;
ADest.Pen.Color := ColorToRGB($009C9B91);
if AStateEx.TabCount = 0 then
ADest.Rectangle(0, 0, ASize.cx - 2, ASize.cy - 2)
else
ADest.Rectangle(0, CaptionHeight, ASize.cx - 2, ASize.cy - 2);
ADest.Pen.Color := ColorToRGB($00BFCED0);
ADest.Line(ASize.cx - 1, CaptionHeight + 1,
ASize.cx - 1, ASize.cy - 1);
ADest.Line(ASize.cx - 1, ASize.cy - 1, 1,
ASize.cy - 1);
// Tabs
ADest.Font.Name := AStateEx.Font.Name;
ADest.Font.Size := AStateEx.Font.Size;
DrawTabs(ADest, ADestPos, ASize, AState, AStateEx);
end;
procedure TCDDrawerWinCE.DrawTabSheet(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
begin
ADest.Brush.Color := AStateEx.RGBColor;
ADest.Brush.Style := bsSolid;
ADest.Pen.Style := psSolid;
ADest.Pen.Color := AStateEx.RGBColor;
ADest.Rectangle(0, 0, ASize.cx, ASize.cy);
end;
procedure TCDDrawerWinCE.DrawTabs(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
var
IsPainting: Boolean = False;
i: Integer;
begin
AStateEx.CurStartLeftPos := 0;
for i := 0 to AStateEx.Tabs.Count - 1 do
begin
if i = AStateEx.LeftmostTabVisibleIndex then
IsPainting := True;
if IsPainting then
begin
AStateEx.CurTabIndex := i;
DrawTab(ADest, ADestPos, ASize, AState, AStateEx);
AStateEx.CurStartLeftPos := AStateEx.CurStartLeftPos + GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx);
end;
end;
end;
procedure TCDDrawerWinCE.DrawTab(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
var
IsSelected: Boolean;
lTabWidth, lTabHeight, lTabTopPos: Integer;
Points: array of TPoint;
lCaption: String;
lTabHeightCorrection: Integer = 0;
begin
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
if not IsSelected then lTabHeightCorrection := 3;
lTabTopPos := lTabHeightCorrection;
lTabHeight := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_HEIGHT, AState, AStateEx)-lTabHeightCorrection;
lTabWidth := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx);
// Fill the area inside the outer border
ADest.Pen.Style := psClear;
ADest.Brush.Style := bsSolid;
ADest.Brush.Color := clWhite;
SetLength(Points, 5);
Points[0] := Point(AStateEx.CurStartLeftPos, lTabTopPos);
Points[1] := Point(AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos);
Points[2] := Point(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+5);
Points[3] := Point(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight);
Points[4] := Point(AStateEx.CurStartLeftPos, lTabTopPos+lTabHeight);
ADest.Polygon(Points);
// Draw the outer border only in the top and right sides,
// and bottom if unselected
ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear;
ADest.Pen.Color := ColorToRGB($009C9B91);
ADest.MoveTo(AStateEx.CurStartLeftPos+1, lTabTopPos);
ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos);
ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+5);
ADest.LineTo(AStateEx.CurStartLeftPos+lTabWidth, lTabTopPos+lTabHeight);
// If it is selected, add a selection frame
if IsSelected then
begin
ADest.Pen.Color := ColorToRGB($00D6C731);
ADest.Pen.Style := psSolid;
ADest.Brush.Style := bsClear;
ADest.Rectangle(
AStateEx.CurStartLeftPos+3, lTabTopPos+3,
AStateEx.CurStartLeftPos+lTabWidth-5, lTabTopPos+lTabHeight-3
);
end;
// Now the text
lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
ADest.TextOut(AStateEx.CurStartLeftPos+5, lTabTopPos+5, lCaption);
end;
initialization initialization
RegisterDrawer(TCDDrawerWinCE.Create, dsWinCE); RegisterDrawer(TCDDrawerWinCE.Create, dsWinCE);
end. end.

View File

@ -325,6 +325,7 @@ type
FTabs: TStringList; FTabs: TStringList;
FOnChanging: TNotifyEvent; FOnChanging: TNotifyEvent;
FOnChange: TNotifyEvent; FOnChange: TNotifyEvent;
FOptions: TNoteBookOptions;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer); override; X, Y: integer); override;
//procedure MouseMove(Shift: TShiftState; X, Y: integer); override; //procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
@ -333,12 +334,14 @@ type
//procedure MouseLeave; override; //procedure MouseLeave; override;
procedure SetTabIndex(AValue: Integer); virtual; procedure SetTabIndex(AValue: Integer); virtual;
procedure SetTabs(AValue: TStringList); procedure SetTabs(AValue: TStringList);
procedure SetOptions(AValue: TNoteBookOptions);
protected protected
FTabCState: TCDCTabControlStateEx; FTabCState: TCDCTabControlStateEx;
function GetControlId: TCDControlID; override; function GetControlId: TCDControlID; override;
procedure CreateControlStateEx; override; procedure CreateControlStateEx; override;
procedure PrepareControlStateEx; override; procedure PrepareControlStateEx; override;
procedure CorrectTabIndex(); procedure CorrectTabIndex();
property Options: TNoteBookOptions read FOptions write SetOptions;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -366,12 +369,10 @@ type
TCDPageControl = class(TCDCustomTabControl) TCDPageControl = class(TCDCustomTabControl)
private private
FOptions: TNoteBookOptions;
function GetActivePage: TCDTabSheet; function GetActivePage: TCDTabSheet;
function GetPageCount: integer; function GetPageCount: integer;
function GetPageIndex: integer; function GetPageIndex: integer;
procedure SetActivePage(Value: TCDTabSheet); procedure SetActivePage(Value: TCDTabSheet);
procedure SetOptions(AValue: TNoteBookOptions);
procedure SetPageIndex(Value: integer); procedure SetPageIndex(Value: integer);
procedure UpdateAllDesignerFlags; procedure UpdateAllDesignerFlags;
procedure UpdateDesignerFlags(APageIndex: integer); procedure UpdateDesignerFlags(APageIndex: integer);
@ -396,7 +397,7 @@ type
property Color; property Color;
property Font; property Font;
property PageIndex: integer read GetPageIndex write SetPageIndex; property PageIndex: integer read GetPageIndex write SetPageIndex;
property Options: TNoteBookOptions read FOptions write SetOptions; property Options;
property ParentColor; property ParentColor;
property ParentFont; property ParentFont;
property TabStop default True; property TabStop default True;
@ -754,6 +755,13 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCDCustomTabControl.SetOptions(AValue: TNoteBookOptions);
begin
if FOptions=AValue then Exit;
FOptions:=AValue;
Invalidate;
end;
function TCDCustomTabControl.GetControlId: TCDControlID; function TCDCustomTabControl.GetControlId: TCDControlID;
begin begin
Result := cidCTabControl; Result := cidCTabControl;
@ -772,6 +780,7 @@ begin
FTabCState.Tabs := Tabs; FTabCState.Tabs := Tabs;
FTabCState.TabIndex := TabIndex; FTabCState.TabIndex := TabIndex;
FTabCState.TabCount := GetTabCount(); FTabCState.TabCount := GetTabCount();
FTabCState.Options := FOptions;
end; end;
constructor TCDCustomTabControl.Create(AOwner: TComponent); constructor TCDCustomTabControl.Create(AOwner: TComponent);
@ -1478,12 +1487,6 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCDPageControl.SetOptions(AValue: TNoteBookOptions);
begin
if FOptions=AValue then Exit;
FOptions:=AValue;
end;
procedure TCDPageControl.SetPageIndex(Value: integer); procedure TCDPageControl.SetPageIndex(Value: integer);
begin begin
if (Value > -1) and (Value < FTabs.Count) then if (Value > -1) and (Value < FTabs.Count) then

View File

@ -7,7 +7,7 @@ interface
uses uses
Classes, SysUtils, Types, Classes, SysUtils, Types,
// LCL for types // LCL for types
Graphics; Graphics, ComCtrls;
const const
CDDRAWSTYLE_COUNT = 19; CDDRAWSTYLE_COUNT = 19;
@ -118,6 +118,7 @@ type
Tabs: TStringList; // Just a reference, don't Free Tabs: TStringList; // Just a reference, don't Free
TabIndex: Integer; TabIndex: Integer;
TabCount: Integer; TabCount: Integer;
Options: TNoteBookOptions;
// Used internally by the drawers // Used internally by the drawers
CurTabIndex: Integer;// For Tab routines, obtain the index CurTabIndex: Integer;// For Tab routines, obtain the index
CurStartLeftPos: Integer; CurStartLeftPos: Integer;