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+}
|
||||
|
||||
@ -41,6 +41,7 @@ type
|
||||
FInverse: Boolean;
|
||||
FDragging: Boolean;
|
||||
FDraggedDistance: Integer;
|
||||
FFlippedColors: Boolean;
|
||||
FTogglePending: Boolean;
|
||||
FMousePt: TPoint;
|
||||
FButtonRect: TRect;
|
||||
@ -50,16 +51,20 @@ type
|
||||
FShowFocusRect: Boolean;
|
||||
FOnChange: TNotifyEvent;
|
||||
FDblClickTimer: TTimer;
|
||||
FPicture: array[0..1] of TPicture;
|
||||
function GetBorderWidth: Integer;
|
||||
function GetCaptions(AIndex: Integer): String;
|
||||
function GetColors(AIndex: Integer): TColor;
|
||||
function GetOrientation: TSwitchOrientation;
|
||||
function GetPicture(AIndex: Integer): TPicture;
|
||||
procedure SetBorderStyle(AValue: TSwitchBorderStyle); reintroduce;
|
||||
procedure SetButtonSize(AValue: Integer);
|
||||
procedure SetCaptions(AIndex: Integer; AValue: string);
|
||||
procedure SetChecked(AValue: Boolean);
|
||||
procedure SetColors(AIndex: Integer; AValue: TColor);
|
||||
procedure SetFlippedColors(AValue: Boolean);
|
||||
procedure SetInverse(AValue: Boolean);
|
||||
procedure SetPicture(AIndex: Integer; AValue: TPicture);
|
||||
procedure SetShowButtonBorder(AValue: Boolean);
|
||||
procedure SetShowCaption(AValue: Boolean);
|
||||
procedure SetShowFocusRect(AValue: Boolean);
|
||||
@ -95,7 +100,10 @@ type
|
||||
property Color default clWindow;
|
||||
property ColorOFF: TColor index 0 read GetColors write SetColors default clMaroon;
|
||||
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 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 ShowButtonBorder: Boolean read FShowButtonBorder write SetShowButtonBorder default true;
|
||||
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default true;
|
||||
@ -103,6 +111,7 @@ type
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Orientation: TSwitchOrientation read GetOrientation;
|
||||
end;
|
||||
|
||||
@ -118,7 +127,10 @@ type
|
||||
property ColorOFF;
|
||||
property ColorON;
|
||||
property Enabled;
|
||||
property FlippedColors;
|
||||
property Inverse;
|
||||
property PictureOFF;
|
||||
property PictureON;
|
||||
property ReadOnly;
|
||||
property ShowButtonBorder;
|
||||
property ShowCaption;
|
||||
@ -197,6 +209,8 @@ begin
|
||||
FColors[2] := clGray; // Border color
|
||||
FCaptions[0] := 'OFF';
|
||||
FCaptions[1] := 'ON';
|
||||
FPicture[0] := TPicture.Create;
|
||||
FPicture[1] := TPicture.Create;
|
||||
FShowCaption := true;
|
||||
FShowButtonBorder := true;
|
||||
FShowFocusRect := true;
|
||||
@ -208,6 +222,13 @@ begin
|
||||
SetInitialBounds(0, 0, CX, CY);
|
||||
end;
|
||||
|
||||
destructor TCustomOnOffSwitch.Destroy;
|
||||
begin
|
||||
FPicture[0].Free;
|
||||
FPicture[1].Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TCustomOnOffSwitch.CalcButtonRect(ADelta: Integer): TRect;
|
||||
|
||||
function GetOffset(AMaxSize, ABtnSize: Integer): Integer;
|
||||
@ -329,6 +350,9 @@ begin
|
||||
Canvas.Brush.Color := clGrayText;
|
||||
Canvas.Pen.Color := clGrayText;
|
||||
end else begin
|
||||
if FFlippedColors then
|
||||
Canvas.Brush.Color := Color
|
||||
else
|
||||
if FChecked then
|
||||
Canvas.Brush.Color := ColorON
|
||||
else
|
||||
@ -424,6 +448,11 @@ begin
|
||||
if Width > Height then Result := soHorizontal else Result := soVertical;
|
||||
end;
|
||||
|
||||
function TCustomOnOffSwitch.GetPicture(AIndex: Integer): TPicture;
|
||||
begin
|
||||
Result := FPicture[AIndex];
|
||||
end;
|
||||
|
||||
procedure TCustomOnOffSwitch.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
inherited;
|
||||
@ -493,9 +522,25 @@ var
|
||||
margin: Integer;
|
||||
diam: Integer;
|
||||
newChecked: Boolean;
|
||||
picIdx: Integer;
|
||||
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
|
||||
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;
|
||||
end else begin
|
||||
Canvas.Brush.Color := clInactiveBorder;
|
||||
@ -504,7 +549,6 @@ begin
|
||||
Canvas.Brush.Style := bsSolid;
|
||||
Canvas.Pen.Style := psSolid;
|
||||
Canvas.Pen.Width := GetBorderWidth;
|
||||
R := Rect(0, 0, Width, Height);
|
||||
case FBorderStyle of
|
||||
bsNone:
|
||||
begin
|
||||
@ -640,6 +684,13 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCustomOnOffSwitch.SetFlippedColors(AValue: Boolean);
|
||||
begin
|
||||
if AValue = FFlippedColors then exit;
|
||||
FFlippedColors := AValue;
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCustomOnOffSwitch.SetInverse(AValue: boolean);
|
||||
begin
|
||||
if AValue = FInverse then exit;
|
||||
@ -647,6 +698,17 @@ begin
|
||||
Invalidate;
|
||||
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);
|
||||
begin
|
||||
if AValue = FShowButtonBorder then exit;
|
||||
|
Reference in New Issue
Block a user