📄 scolorselect.pas
字号:
unit sColorSelect;
{$I sDefs.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Buttons, sSpeedButton;
type
TsColorSelect = class(TsSpeedButton)
{$IFNDEF NOTFORHELP}
private
FColorValue : TColor;
FOnChange : TNotifyEvent;
FImgWidth: integer;
FImgHeight: integer;
procedure SetColorValue(const Value: TColor);
procedure SetImgHeight(const Value: integer);
procedure SetImgWidth(const Value: integer);
public
ColorDialog : TColorDialog;
constructor Create (AOwner: TComponent); override;
procedure Click; override;
procedure UpdateGlyph; override;
procedure Loaded; override;
procedure AfterConstruction; override;
published
property OnChange: TNotifyEvent read FOnChange write FOnChange;
{$ENDIF} // NOTFORHELP
property ColorValue : TColor read FColorValue write SetColorValue;
property ImgWidth : integer read FImgWidth write SetImgWidth default 15;
property ImgHeight : integer read FImgHeight write SetImgHeight default 15;
end;
implementation
uses sDialogs, sCommonData, sThirdParty, sGraphUtils;
{ TsColorSelect }
procedure TsColorSelect.AfterConstruction;
begin
inherited;
UpdateGlyph;
end;
procedure TsColorSelect.Click;
var
cd : TColorDialog;
begin
if ColorDialog = nil then begin
if not UseStdDialogs then cd := TsColorDialog.Create(Self) else cd := TColorDialog.Create(Self);
end
else cd := ColorDialog;
cd.Color := ColorValue;
if cd.Execute then begin
ColorValue := cd.Color;
if Assigned(FOnChange) then FOnChange(Self);
end;
if ColorDialog <> cd then FreeAndNil(cd);
inherited Click;
end;
constructor TsColorSelect.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FImgHeight := 15;
FImgWidth := 15;
end;
procedure TsColorSelect.Loaded;
begin
inherited;
UpdateGlyph;
end;
procedure TsColorSelect.SetColorValue(const Value: TColor);
begin
FColorValue := Value;
UpdateGlyph;
SkinData.Invalidate;
end;
procedure TsColorSelect.SetImgHeight(const Value: integer);
begin
if FImgHeight <> Value then begin
FImgHeight := Value;
SkinData.Invalidate;
end;
end;
procedure TsColorSelect.SetImgWidth(const Value: integer);
begin
if FImgWidth <> Value then begin
FImgWidth := Value;
SkinData.Invalidate;
end;
end;
procedure TsColorSelect.UpdateGlyph;
begin
if (FImgHeight <> 0) and (FImgWidth <> 0) and (Glyph.Canvas.Pixels[FImgWidth div 2, FImgHeight div 2] <> ColorValue) then begin
if SkinData.Skinned then Glyph.OnChange := nil;
Glyph.Width := FImgWidth;
Glyph.Height := FImgHeight;
Glyph.Canvas.Brush.Color := ColorValue;
Glyph.Canvas.FillRect(Rect(0, 0, FImgWidth, FImgHeight));
// Transparent pixels in corners
Glyph.Canvas.Pixels[0, FImgHeight - 1] := ColorToRGB(clFuchsia);
Glyph.Canvas.Pixels[0, 0] := ColorToRGB(clFuchsia);
Glyph.Canvas.Pixels[FImgWidth - 1, FImgHeight - 1] := ColorToRGB(clFuchsia);
Glyph.Canvas.Pixels[FImgWidth - 1, 0] := ColorToRGB(clFuchsia);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -