mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 09:35:59 +02:00
customdrawn: Further merges scrollbar and trackbar
git-svn-id: trunk@33450 -
This commit is contained in:
parent
216d302be2
commit
52006f1e4f
@ -65,7 +65,7 @@ type
|
||||
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
|
||||
// TCDScrollBar
|
||||
procedure DrawScrollBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDScrollBarStateEx); override;
|
||||
AState: TCDControlState; AStateEx: TCDPositionedCStateEx); override;
|
||||
// TCDGroupBox
|
||||
procedure DrawGroupBox(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
|
||||
@ -79,7 +79,7 @@ type
|
||||
// ===================================
|
||||
// TCDTrackBar
|
||||
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override;
|
||||
AState: TCDControlState; AStateEx: TCDPositionedCStateEx); override;
|
||||
// TCDProgressBar
|
||||
procedure DrawProgressBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDProgressBarStateEx); override;
|
||||
@ -775,7 +775,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCDDrawerCommon.DrawScrollBar(ADest: TCanvas; ADestPos: TPoint;
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDScrollBarStateEx);
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx);
|
||||
var
|
||||
lPos: TPoint;
|
||||
lSize: TSize;
|
||||
@ -814,11 +814,23 @@ begin
|
||||
// The slider
|
||||
lPos := Point(0, 0);
|
||||
if csfHorizontal in AState then
|
||||
begin
|
||||
if AStateEx.FloatPageSize > 0 then lSize.cx := Round(
|
||||
AStateEx.FloatPageSize * (ASize.cx - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 2));
|
||||
if lSize.cx < 5 then lSize.cx := 5;
|
||||
|
||||
lPos.X := Round(GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH)
|
||||
+ AStateEx.Position * (ASize.cx - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 3))
|
||||
+ AStateEx.FloatPos * (ASize.cx - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 2 - lSize.cx));
|
||||
end
|
||||
else
|
||||
begin
|
||||
if AStateEx.FloatPageSize > 0 then lSize.cy := Round(
|
||||
AStateEx.FloatPageSize * (ASize.cy - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 2));
|
||||
if lSize.cy < 5 then lSize.cy := 5;
|
||||
|
||||
lPos.Y := Round(GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH)
|
||||
+ AStateEx.Position * (ASize.cy - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 3));
|
||||
+ AStateEx.FloatPos * (ASize.cy - GetMeasures(TCDSCROLLBAR_BUTTON_WIDTH) * 2 - lSize.cy));
|
||||
end;
|
||||
ADest.Brush.Color := Palette.BtnFace;
|
||||
ADest.Brush.Style := bsSolid;
|
||||
ADest.Rectangle(Bounds(lPos.X, lPos.Y, lSize.cx, lSize.cy));
|
||||
@ -884,7 +896,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCDDrawerCommon.DrawTrackBar(ADest: TCanvas; ADestPos: TPoint;
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDTrackBarStateEx);
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx);
|
||||
var
|
||||
StepsCount, i: Integer;
|
||||
lTickmarkLeft, lTickmarkTop: integer; // for drawing the decorative bars
|
||||
|
@ -23,7 +23,7 @@ type
|
||||
// Common Controls Tab
|
||||
// ===================================
|
||||
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); override;
|
||||
AState: TCDControlState; AStateEx: TCDPositionedCStateEx); override;
|
||||
end;
|
||||
{ TCDButtonDrawerGrad = class(TCDButtonDrawer)
|
||||
public
|
||||
@ -120,7 +120,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCDDrawerExtra1.DrawTrackBar(ADest: TCanvas; ADestPos: TPoint;
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDTrackBarStateEx);
|
||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDPositionedCStateEx);
|
||||
var
|
||||
lDrawingBottom, StepsCount, i: Integer;
|
||||
pStart, pEnd: integer; // for drawing the decorative bars
|
||||
|
@ -229,18 +229,23 @@ type
|
||||
FMax: Integer;
|
||||
FMin: Integer;
|
||||
FOnChange: TNotifyEvent;
|
||||
FPageSize: Integer;
|
||||
FPosition: Integer;
|
||||
procedure SetMax(AValue: Integer);
|
||||
procedure SetMin(AValue: Integer);
|
||||
procedure SetPageSize(AValue: Integer);
|
||||
procedure SetPosition(AValue: Integer);
|
||||
procedure DoClickButton(AButton: TCDControlState; ALargeChange: Boolean);
|
||||
procedure HandleBtnClickTimer(ASender: TObject);
|
||||
protected
|
||||
FSmallChange, FLargeChange: Integer;
|
||||
FPCState: TCDPositionedCStateEx;
|
||||
function GetPositionFromMousePosWithMargins(X, Y, ALeftMargin, ARightMargin: Integer;
|
||||
AIsHorizontal, AAcceptMouseOutsideStrictArea: Boolean): integer;
|
||||
function GetPositionFromMousePos(X, Y: Integer): integer; virtual; abstract;
|
||||
function GetButtonFromMousePos(X, Y: Integer): TCDControlState; virtual;
|
||||
procedure CreateControlStateEx; override;
|
||||
procedure PrepareControlStateEx; override;
|
||||
// keyboard
|
||||
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||
// mouse
|
||||
@ -248,6 +253,8 @@ type
|
||||
X, Y: integer); override;
|
||||
procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
|
||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
||||
//
|
||||
property PageSize: Integer read FPageSize write SetPageSize;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -265,18 +272,17 @@ type
|
||||
FKind: TScrollBarKind;
|
||||
procedure SetKind(AValue: TScrollBarKind);
|
||||
protected
|
||||
FSBState: TCDScrollBarStateEx;
|
||||
function GetPositionFromMousePos(X, Y: Integer): integer; override;
|
||||
function GetButtonFromMousePos(X, Y: Integer): TCDControlState; override;
|
||||
function GetControlId: TCDControlID; override;
|
||||
procedure CreateControlStateEx; override;
|
||||
procedure PrepareControlStateEx; override;
|
||||
procedure PrepareControlState; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property DrawStyle;
|
||||
property Kind: TScrollBarKind read FKind write SetKind;
|
||||
property PageSize;
|
||||
property TabStop default True;
|
||||
end;
|
||||
|
||||
@ -336,11 +342,9 @@ type
|
||||
FOrientation: TTrackBarOrientation;
|
||||
procedure SetOrientation(AValue: TTrackBarOrientation);
|
||||
protected
|
||||
FTBState: TCDTrackBarStateEx;
|
||||
function GetPositionFromMousePos(X, Y: Integer): integer; override;
|
||||
function GetControlId: TCDControlID; override;
|
||||
procedure CreateControlStateEx; override;
|
||||
procedure PrepareControlStateEx; override;
|
||||
procedure PrepareControlState; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -1249,6 +1253,13 @@ begin
|
||||
if not (csLoading in ComponentState) then Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCDPositionedControl.SetPageSize(AValue: Integer);
|
||||
begin
|
||||
if FPageSize=AValue then Exit;
|
||||
FPageSize:=AValue;
|
||||
if not (csLoading in ComponentState) then Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCDPositionedControl.SetPosition(AValue: Integer);
|
||||
begin
|
||||
if FPosition=AValue then Exit;
|
||||
@ -1325,6 +1336,27 @@ begin
|
||||
Result := [];
|
||||
end;
|
||||
|
||||
procedure TCDPositionedControl.CreateControlStateEx;
|
||||
begin
|
||||
inherited CreateControlStateEx;
|
||||
FPCState := TCDPositionedCStateEx.Create;
|
||||
FStateEx := FPCState;
|
||||
end;
|
||||
|
||||
procedure TCDPositionedControl.PrepareControlStateEx;
|
||||
begin
|
||||
inherited PrepareControlStateEx;
|
||||
|
||||
if FMin < FMax then FPCState.FloatPos := FPosition / (FMax - FMin)
|
||||
else FPCState.FloatPos := 0.0;
|
||||
|
||||
FPCState.PosCount := FMax - FMin + 1;
|
||||
FPCState.Position := FPosition - FMin;
|
||||
|
||||
if FMin < FMax then FPCState.FloatPageSize := FPageSize / (FMax - FMin)
|
||||
else FPCState.FloatPageSize := 1.0;
|
||||
end;
|
||||
|
||||
procedure TCDPositionedControl.KeyDown(var Key: word; Shift: TShiftState);
|
||||
var
|
||||
NewPosition: Integer;
|
||||
@ -1358,7 +1390,7 @@ begin
|
||||
SetFocus;
|
||||
NewPosition := GetPositionFromMousePos(X, Y);
|
||||
DragDropStarted := True;
|
||||
if NewPosition > 0 then Position := NewPosition;
|
||||
if NewPosition >= 0 then Position := NewPosition;
|
||||
|
||||
// Check if any buttons were clicked
|
||||
FButton := GetButtonFromMousePos(X, Y);
|
||||
@ -1465,18 +1497,9 @@ begin
|
||||
Result:= cidScrollBar;
|
||||
end;
|
||||
|
||||
procedure TCDScrollBar.CreateControlStateEx;
|
||||
procedure TCDScrollBar.PrepareControlState;
|
||||
begin
|
||||
FSBState := TCDScrollBarStateEx.Create;
|
||||
FStateEx := FSBState;
|
||||
end;
|
||||
|
||||
procedure TCDScrollBar.PrepareControlStateEx;
|
||||
begin
|
||||
inherited PrepareControlStateEx;
|
||||
|
||||
if FMin < FMax then FSBState.Position := Position / (FMax - FMin)
|
||||
else FSBState.Position := 1.0;
|
||||
inherited PrepareControlState;
|
||||
|
||||
if FKind = sbHorizontal then
|
||||
FState := FState + [csfHorizontal] - [csfVertical, csfRightToLeft, csfTopDown]
|
||||
@ -1573,7 +1596,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
function TCDTrackBar.GetPositionFromMousePos(X, Y: integer): integer;
|
||||
function TCDTrackBar.GetPositionFromMousePos(X, Y: Integer): integer;
|
||||
var
|
||||
lLeftBorder, lRightBorder: Integer;
|
||||
begin
|
||||
@ -1588,17 +1611,9 @@ begin
|
||||
Result := cidTrackBar;
|
||||
end;
|
||||
|
||||
procedure TCDTrackBar.CreateControlStateEx;
|
||||
procedure TCDTrackBar.PrepareControlState;
|
||||
begin
|
||||
FTBState := TCDTrackBarStateEx.Create;
|
||||
FStateEx := FTBState;
|
||||
end;
|
||||
|
||||
procedure TCDTrackBar.PrepareControlStateEx;
|
||||
begin
|
||||
inherited PrepareControlStateEx;
|
||||
FTBState.PosCount := FMax - FMin + 1;
|
||||
FTBState.Position := FPosition - FMin;
|
||||
inherited PrepareControlState;
|
||||
case FOrientation of
|
||||
trHorizontal: FState := FState + [csfHorizontal] - [csfVertical, csfRightToLeft, csfTopDown];
|
||||
trVertical: FState := FState + [csfVertical] - [csfHorizontal, csfRightToLeft, csfTopDown];
|
||||
|
@ -140,15 +140,12 @@ type
|
||||
EventArrived: Boolean; // Added by event handlers and used by the caret so that it stops blinking while events are incoming
|
||||
end;
|
||||
|
||||
TCDScrollBarStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
Position: Double; // between 0.0 and 1.0
|
||||
end;
|
||||
|
||||
TCDTrackBarStateEx = class(TCDControlStateEx)
|
||||
TCDPositionedCStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
PosCount: integer; // The number of positions, calculated as Max - Min + 1
|
||||
Position: integer; // A zero-based position, therefore it is = Position - Min
|
||||
FloatPos: Double; // The same position, but as a float between 0.0 and 1.0
|
||||
FloatPageSize: Double; // The page size as a float between 0.0 and 1.0
|
||||
end;
|
||||
|
||||
TCDProgressBarStateEx = class(TCDControlStateEx)
|
||||
@ -287,7 +284,7 @@ type
|
||||
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
|
||||
// TCDScrollBar
|
||||
procedure DrawScrollBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDScrollBarStateEx); virtual; abstract;
|
||||
AState: TCDControlState; AStateEx: TCDPositionedCStateEx); virtual; abstract;
|
||||
// TCDGroupBox
|
||||
procedure DrawGroupBoxSquare(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
|
||||
@ -303,7 +300,7 @@ type
|
||||
// ===================================
|
||||
// TCDTrackBar
|
||||
procedure DrawTrackBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDTrackBarStateEx); virtual; abstract;
|
||||
AState: TCDControlState; AStateEx: TCDPositionedCStateEx); virtual; abstract;
|
||||
// TCDProgressBar
|
||||
procedure DrawProgressBar(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||
AState: TCDControlState; AStateEx: TCDProgressBarStateEx); virtual; abstract;
|
||||
@ -522,12 +519,12 @@ begin
|
||||
cidEdit: DrawEdit(ADest, ADestPos, ASize, AState, TCDEditStateEx(AStateEx));
|
||||
cidCheckBox: DrawCheckBox(ADest, ADestPos, ASize, AState, AStateEx);
|
||||
cidRadioButton:DrawRadioButton(ADest, ADestPos, ASize, AState, AStateEx);
|
||||
cidScrollBar: DrawScrollBar(ADest, ADestPos, ASize, AState, TCDScrollBarStateEx(AStateEx));
|
||||
cidScrollBar: DrawScrollBar(ADest, ADestPos, ASize, AState, TCDPositionedCStateEx(AStateEx));
|
||||
cidGroupBox: DrawGroupBox(ADest, ADestPos, ASize, AState, AStateEx);
|
||||
//
|
||||
cidStaticText: DrawStaticText(ADest, ADestPos, ASize, AState, AStateEx);
|
||||
//
|
||||
cidTrackBar: DrawTrackBar(ADest, ADestPos, ASize, AState, TCDTrackBarStateEx(AStateEx));
|
||||
cidTrackBar: DrawTrackBar(ADest, ADestPos, ASize, AState, TCDPositionedCStateEx(AStateEx));
|
||||
cidProgressBar:DrawProgressBar(ADest, ADestPos, ASize, AState, TCDProgressBarStateEx(AStateEx));
|
||||
cidListView: DrawListView(ADest, ADestPos, ASize, AState, TCDListViewStateEx(AStateEx));
|
||||
cidCTabControl:DrawCTabControl(ADest, ADestPos, ASize, AState, TCDCTabControlStateEx(AStateEx));
|
||||
|
Loading…
Reference in New Issue
Block a user