You've already forked lazarus-ccr
Industrial: Add PictureON and PictureOFF properties to TOnOffSwitch.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8964 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
}
|
}
|
||||||
|
|
||||||
unit switches;
|
unit Switches;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ type
|
|||||||
FInverse: Boolean;
|
FInverse: Boolean;
|
||||||
FDragging: Boolean;
|
FDragging: Boolean;
|
||||||
FDraggedDistance: Integer;
|
FDraggedDistance: Integer;
|
||||||
|
FFlippedColors: Boolean;
|
||||||
FTogglePending: Boolean;
|
FTogglePending: Boolean;
|
||||||
FMousePt: TPoint;
|
FMousePt: TPoint;
|
||||||
FButtonRect: TRect;
|
FButtonRect: TRect;
|
||||||
@@ -50,16 +51,20 @@ type
|
|||||||
FShowFocusRect: Boolean;
|
FShowFocusRect: Boolean;
|
||||||
FOnChange: TNotifyEvent;
|
FOnChange: TNotifyEvent;
|
||||||
FDblClickTimer: TTimer;
|
FDblClickTimer: TTimer;
|
||||||
|
FPicture: array[0..1] of TPicture;
|
||||||
function GetBorderWidth: Integer;
|
function GetBorderWidth: Integer;
|
||||||
function GetCaptions(AIndex: Integer): String;
|
function GetCaptions(AIndex: Integer): String;
|
||||||
function GetColors(AIndex: Integer): TColor;
|
function GetColors(AIndex: Integer): TColor;
|
||||||
function GetOrientation: TSwitchOrientation;
|
function GetOrientation: TSwitchOrientation;
|
||||||
|
function GetPicture(AIndex: Integer): TPicture;
|
||||||
procedure SetBorderStyle(AValue: TSwitchBorderStyle); reintroduce;
|
procedure SetBorderStyle(AValue: TSwitchBorderStyle); reintroduce;
|
||||||
procedure SetButtonSize(AValue: Integer);
|
procedure SetButtonSize(AValue: Integer);
|
||||||
procedure SetCaptions(AIndex: Integer; AValue: string);
|
procedure SetCaptions(AIndex: Integer; AValue: string);
|
||||||
procedure SetChecked(AValue: Boolean);
|
procedure SetChecked(AValue: Boolean);
|
||||||
procedure SetColors(AIndex: Integer; AValue: TColor);
|
procedure SetColors(AIndex: Integer; AValue: TColor);
|
||||||
|
procedure SetFlippedColors(AValue: Boolean);
|
||||||
procedure SetInverse(AValue: Boolean);
|
procedure SetInverse(AValue: Boolean);
|
||||||
|
procedure SetPicture(AIndex: Integer; AValue: TPicture);
|
||||||
procedure SetShowButtonBorder(AValue: Boolean);
|
procedure SetShowButtonBorder(AValue: Boolean);
|
||||||
procedure SetShowCaption(AValue: Boolean);
|
procedure SetShowCaption(AValue: Boolean);
|
||||||
procedure SetShowFocusRect(AValue: Boolean);
|
procedure SetShowFocusRect(AValue: Boolean);
|
||||||
@@ -95,7 +100,10 @@ type
|
|||||||
property Color default clWindow;
|
property Color default clWindow;
|
||||||
property ColorOFF: TColor index 0 read GetColors write SetColors default clMaroon;
|
property ColorOFF: TColor index 0 read GetColors write SetColors default clMaroon;
|
||||||
property ColorON: TColor index 1 read GetColors write SetColors default clGreen;
|
property ColorON: TColor index 1 read GetColors write SetColors default clGreen;
|
||||||
|
property FlippedColors: Boolean read FFlippedColors write SetFlippedColors default false;
|
||||||
property Inverse: Boolean read FInverse write SetInverse default false;
|
property Inverse: Boolean read FInverse write SetInverse default false;
|
||||||
|
property PictureOFF: TPicture index 0 read GetPicture write SetPicture;
|
||||||
|
property PictureON: TPicture index 1 read GetPicture write SetPicture;
|
||||||
property ReadOnly: boolean read FReadOnly write FReadOnly default false;
|
property ReadOnly: boolean read FReadOnly write FReadOnly default false;
|
||||||
property ShowButtonBorder: Boolean read FShowButtonBorder write SetShowButtonBorder default true;
|
property ShowButtonBorder: Boolean read FShowButtonBorder write SetShowButtonBorder default true;
|
||||||
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default true;
|
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default true;
|
||||||
@@ -103,6 +111,7 @@ type
|
|||||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
property Orientation: TSwitchOrientation read GetOrientation;
|
property Orientation: TSwitchOrientation read GetOrientation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -118,7 +127,10 @@ type
|
|||||||
property ColorOFF;
|
property ColorOFF;
|
||||||
property ColorON;
|
property ColorON;
|
||||||
property Enabled;
|
property Enabled;
|
||||||
|
property FlippedColors;
|
||||||
property Inverse;
|
property Inverse;
|
||||||
|
property PictureOFF;
|
||||||
|
property PictureON;
|
||||||
property ReadOnly;
|
property ReadOnly;
|
||||||
property ShowButtonBorder;
|
property ShowButtonBorder;
|
||||||
property ShowCaption;
|
property ShowCaption;
|
||||||
@@ -197,6 +209,8 @@ begin
|
|||||||
FColors[2] := clGray; // Border color
|
FColors[2] := clGray; // Border color
|
||||||
FCaptions[0] := 'OFF';
|
FCaptions[0] := 'OFF';
|
||||||
FCaptions[1] := 'ON';
|
FCaptions[1] := 'ON';
|
||||||
|
FPicture[0] := TPicture.Create;
|
||||||
|
FPicture[1] := TPicture.Create;
|
||||||
FShowCaption := true;
|
FShowCaption := true;
|
||||||
FShowButtonBorder := true;
|
FShowButtonBorder := true;
|
||||||
FShowFocusRect := true;
|
FShowFocusRect := true;
|
||||||
@@ -208,6 +222,13 @@ begin
|
|||||||
SetInitialBounds(0, 0, CX, CY);
|
SetInitialBounds(0, 0, CX, CY);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
destructor TCustomOnOffSwitch.Destroy;
|
||||||
|
begin
|
||||||
|
FPicture[0].Free;
|
||||||
|
FPicture[1].Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomOnOffSwitch.CalcButtonRect(ADelta: Integer): TRect;
|
function TCustomOnOffSwitch.CalcButtonRect(ADelta: Integer): TRect;
|
||||||
|
|
||||||
function GetOffset(AMaxSize, ABtnSize: Integer): Integer;
|
function GetOffset(AMaxSize, ABtnSize: Integer): Integer;
|
||||||
@@ -329,6 +350,9 @@ begin
|
|||||||
Canvas.Brush.Color := clGrayText;
|
Canvas.Brush.Color := clGrayText;
|
||||||
Canvas.Pen.Color := clGrayText;
|
Canvas.Pen.Color := clGrayText;
|
||||||
end else begin
|
end else begin
|
||||||
|
if FFlippedColors then
|
||||||
|
Canvas.Brush.Color := Color
|
||||||
|
else
|
||||||
if FChecked then
|
if FChecked then
|
||||||
Canvas.Brush.Color := ColorON
|
Canvas.Brush.Color := ColorON
|
||||||
else
|
else
|
||||||
@@ -424,6 +448,11 @@ begin
|
|||||||
if Width > Height then Result := soHorizontal else Result := soVertical;
|
if Width > Height then Result := soHorizontal else Result := soVertical;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomOnOffSwitch.GetPicture(AIndex: Integer): TPicture;
|
||||||
|
begin
|
||||||
|
Result := FPicture[AIndex];
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomOnOffSwitch.KeyDown(var Key: Word; Shift: TShiftState);
|
procedure TCustomOnOffSwitch.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@@ -493,9 +522,25 @@ var
|
|||||||
margin: Integer;
|
margin: Integer;
|
||||||
diam: Integer;
|
diam: Integer;
|
||||||
newChecked: Boolean;
|
newChecked: Boolean;
|
||||||
|
picIdx: Integer;
|
||||||
begin
|
begin
|
||||||
|
R := Rect(0, 0, Width, Height);
|
||||||
|
|
||||||
|
picIdx := IfThen(FChecked, 1, 0);
|
||||||
|
if FPicture[picIdx].Width > 0 then
|
||||||
|
begin
|
||||||
|
Canvas.StretchDraw(R, FPicture[picIdx].Graphic);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
if Enabled then begin
|
if Enabled then begin
|
||||||
Canvas.Brush.Color := Color;
|
if FFlippedColors then begin
|
||||||
|
if FChecked then
|
||||||
|
Canvas.Brush.Color := ColorON
|
||||||
|
else
|
||||||
|
Canvas.Brush.Color := ColorOFF;
|
||||||
|
end else
|
||||||
|
Canvas.Brush.Color := Color;
|
||||||
Canvas.Pen.Color := BorderColor;
|
Canvas.Pen.Color := BorderColor;
|
||||||
end else begin
|
end else begin
|
||||||
Canvas.Brush.Color := clInactiveBorder;
|
Canvas.Brush.Color := clInactiveBorder;
|
||||||
@@ -504,7 +549,6 @@ begin
|
|||||||
Canvas.Brush.Style := bsSolid;
|
Canvas.Brush.Style := bsSolid;
|
||||||
Canvas.Pen.Style := psSolid;
|
Canvas.Pen.Style := psSolid;
|
||||||
Canvas.Pen.Width := GetBorderWidth;
|
Canvas.Pen.Width := GetBorderWidth;
|
||||||
R := Rect(0, 0, Width, Height);
|
|
||||||
case FBorderStyle of
|
case FBorderStyle of
|
||||||
bsNone:
|
bsNone:
|
||||||
begin
|
begin
|
||||||
@@ -640,6 +684,13 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomOnOffSwitch.SetFlippedColors(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if AValue = FFlippedColors then exit;
|
||||||
|
FFlippedColors := AValue;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomOnOffSwitch.SetInverse(AValue: boolean);
|
procedure TCustomOnOffSwitch.SetInverse(AValue: boolean);
|
||||||
begin
|
begin
|
||||||
if AValue = FInverse then exit;
|
if AValue = FInverse then exit;
|
||||||
@@ -647,6 +698,17 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomOnOffSwitch.SetPicture(AIndex: Integer; AValue: TPicture);
|
||||||
|
begin
|
||||||
|
if AValue = FPicture[AIndex] then
|
||||||
|
exit;
|
||||||
|
if AValue = nil then
|
||||||
|
FPicture[AIndex].Clear
|
||||||
|
else
|
||||||
|
FPicture[AIndex].Assign(AValue);
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomOnOffSwitch.SetShowButtonBorder(AValue: Boolean);
|
procedure TCustomOnOffSwitch.SetShowButtonBorder(AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
if AValue = FShowButtonBorder then exit;
|
if AValue = FShowButtonBorder then exit;
|
||||||
|
Reference in New Issue
Block a user