You've already forked lazarus-ccr
mbColorLib: Add TmbDeskPickerAction for more flexible picking of colors from desktop.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5559 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -12,30 +12,32 @@ uses
|
|||||||
PalUtils;
|
PalUtils;
|
||||||
|
|
||||||
const
|
const
|
||||||
crPickerCursor = 13;
|
crPickerCursor = 13;
|
||||||
|
|
||||||
type
|
type
|
||||||
TScreenForm = class(TForm)
|
TScreenForm = class(TForm)
|
||||||
procedure FormShow(Sender: TObject);
|
procedure EndSelection(x, y: integer; ok: boolean);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure FormKeyDown(Sender: TObject; var Key: Word;
|
||||||
procedure EndSelection(x, y: integer; ok: boolean);
|
Shift: TShiftState);
|
||||||
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
|
procedure FormMouseMove(Sender: TObject;
|
||||||
Shift: TShiftState; X, Y: Integer);
|
Shift: TShiftState; X, Y: Integer);
|
||||||
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
|
||||||
|
Shift: TShiftState; X, Y: Integer);
|
||||||
|
procedure FormShow(Sender: TObject);
|
||||||
|
|
||||||
private
|
private
|
||||||
FOnSelColorChange: TNotifyEvent;
|
FOnSelColorChange: TNotifyEvent;
|
||||||
FOnKeyDown: TKeyEvent;
|
FOnKeyDown: TKeyEvent;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
|
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
|
||||||
|
|
||||||
public
|
public
|
||||||
FHintFormat: string;
|
FHintFormat: string;
|
||||||
SelectedColor: TColor;
|
SelectedColor: TColor;
|
||||||
property OnSelColorChange: TNotifyEvent read FOnSelColorChange write FOnSelColorChange;
|
property OnSelColorChange: TNotifyEvent read FOnSelColorChange write FOnSelColorChange;
|
||||||
property OnScreenKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;
|
property OnScreenKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -46,10 +48,8 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
{$R PickCursor.res}
|
{$R PickCursor.res}
|
||||||
|
|
||||||
function ColorToHex(Color: TColor): string;
|
uses
|
||||||
begin
|
HTMLColors;
|
||||||
Result := IntToHex(GetRValue(Color), 2) + IntToHex(GetGValue(Color), 2) + IntToHex(GetBValue(Color), 2);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GetDesktopColor(const X, Y: Integer): TColor;
|
function GetDesktopColor(const X, Y: Integer): TColor;
|
||||||
var
|
var
|
||||||
|
@ -43,9 +43,9 @@ object Form1: TForm1
|
|||||||
Height = 384
|
Height = 384
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 403
|
Width = 403
|
||||||
ActivePage = TabSheet7
|
ActivePage = TabSheet2
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
TabIndex = 7
|
TabIndex = 1
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
OnChange = PageControl1Change
|
OnChange = PageControl1Change
|
||||||
OnMouseMove = PageControl1MouseMove
|
OnMouseMove = PageControl1MouseMove
|
||||||
@ -90,7 +90,6 @@ object Form1: TForm1
|
|||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
HintFormat = 'RGB(%r, %g, %b)'#13'Hex: #%hex'
|
HintFormat = 'RGB(%r, %g, %b)'#13'Hex: #%hex'
|
||||||
IntensityText = 'Intensity'
|
IntensityText = 'Intensity'
|
||||||
SliderMarker = smRect
|
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Constraints.MinHeight = 85
|
Constraints.MinHeight = 85
|
||||||
Constraints.MinWidth = 93
|
Constraints.MinWidth = 93
|
||||||
@ -721,8 +720,8 @@ object Form1: TForm1
|
|||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
Hue = 0
|
Hue = 0
|
||||||
Saturation = 0
|
Saturation = 0
|
||||||
Luminance = 65
|
Luminance = 61
|
||||||
SelectedColor = 4276545
|
SelectedColor = 4013373
|
||||||
end
|
end
|
||||||
object VColorPicker1: TVColorPicker
|
object VColorPicker1: TVColorPicker
|
||||||
Left = 34
|
Left = 34
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
unit mbDeskPickerButton;
|
unit mbDeskPickerButton;
|
||||||
|
|
||||||
{$MODE DELPHI}
|
//{$MODE DELPHI}
|
||||||
|
{$MODE ObjFPC}{$H+}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LCLIntf, LCLType, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms, ScreenWin;
|
LCLIntf, LCLType, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms,
|
||||||
|
ActnList,
|
||||||
|
ScreenWin;
|
||||||
|
|
||||||
type
|
type
|
||||||
TmbDeskPickerButton = class(TButton)
|
TmbDeskPickerButton = class(TButton)
|
||||||
@ -38,6 +41,50 @@ type
|
|||||||
property OnSelMouseWheelUp: TMouseWheelUpDownEvent read FOnWheelUp write FOnWheelUp;
|
property OnSelMouseWheelUp: TMouseWheelUpDownEvent read FOnWheelUp write FOnWheelUp;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TmbDeskPickerAction = class(TCustomAction)
|
||||||
|
private
|
||||||
|
FHintFmt: String;
|
||||||
|
FSelColor: TColor;
|
||||||
|
FScreenFrm: TScreenForm;
|
||||||
|
FShowScreenHint: Boolean;
|
||||||
|
FOnWheelUp, FOnWheelDown: TMouseWheelUpdownEvent;
|
||||||
|
FOnColorPicked: TNotifyEvent;
|
||||||
|
FOnScreenKeyDown: TKeyEvent;
|
||||||
|
protected
|
||||||
|
procedure ColorPicked(Sender: TObject);
|
||||||
|
procedure ScreenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
|
procedure StartPicking;
|
||||||
|
procedure WheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint;
|
||||||
|
var Handled: Boolean);
|
||||||
|
procedure WheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint;
|
||||||
|
var Handled: Boolean);
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
procedure ExecuteTarget(Target: TObject); override;
|
||||||
|
function HandlesTarget(Target: TObject): Boolean; override;
|
||||||
|
// procedure UpdateTarget(Target: TObject); override;
|
||||||
|
published
|
||||||
|
property Caption;
|
||||||
|
property Enabled;
|
||||||
|
property HelpContext;
|
||||||
|
property HelpKeyword;
|
||||||
|
property HelpType;
|
||||||
|
property Hint;
|
||||||
|
property ImageIndex;
|
||||||
|
property ScreenHintFormat: string read FHintFmt write FHintFmt;
|
||||||
|
property SecondaryShortCuts;
|
||||||
|
property SelectedColor: TColor read FSelColor;
|
||||||
|
property ShortCut;
|
||||||
|
property ShowScreenHint: boolean read FShowScreenHint write FShowScreenHint default false;
|
||||||
|
property Visible;
|
||||||
|
property OnExecute;
|
||||||
|
property OnHint;
|
||||||
|
property OnScreenKeyDown: TKeyEvent read FOnScreenKeyDown write FOnScreenKeyDown;
|
||||||
|
property OnSelColorChange: TNotifyEvent read FOnColorPicked write FOnColorPicked;
|
||||||
|
property OnSelMouseWheelDown: TMouseWheelUpDownEvent read FOnWheelDown write FOnWheelDown;
|
||||||
|
property OnSelMouseWheelUp: TMouseWheelUpDownEvent read FOnWheelUp write FOnWheelUp;
|
||||||
|
property OnUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -63,14 +110,20 @@ begin
|
|||||||
FOnColorPicked(Self);
|
FOnColorPicked(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerButton.ScreenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnKeyDown) then
|
||||||
|
FOnKeyDown(Self, Key, Shift);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TmbDeskPickerButton.StartPicking;
|
procedure TmbDeskPickerButton.StartPicking;
|
||||||
begin
|
begin
|
||||||
FScreenFrm := TScreenForm.Create(Application);
|
FScreenFrm := TScreenForm.Create(Application);
|
||||||
try
|
try
|
||||||
FScreenFrm.OnSelColorChange := ColorPicked;
|
FScreenFrm.OnSelColorChange := @ColorPicked;
|
||||||
FScreenFrm.OnScreenKeyDown := ScreenKeyDown;
|
FScreenFrm.OnScreenKeyDown := @ScreenKeyDown;
|
||||||
FScreenFrm.OnMouseWheelDown := WheelDown;
|
FScreenFrm.OnMouseWheelDown := @WheelDown;
|
||||||
FScreenFrm.OnMouseWheelUp := WheelUp;
|
FScreenFrm.OnMouseWheelUp := @WheelUp;
|
||||||
FScreenFrm.ShowHint := FShowScreenHint;
|
FScreenFrm.ShowHint := FShowScreenHint;
|
||||||
FScreenFrm.FHintFormat := FHintFmt;
|
FScreenFrm.FHintFormat := FHintFmt;
|
||||||
FScreenFrm.ShowModal;
|
FScreenFrm.ShowModal;
|
||||||
@ -79,12 +132,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TmbDeskPickerButton.ScreenKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
||||||
begin
|
|
||||||
if Assigned(FOnKeyDown) then
|
|
||||||
FOnKeyDown(Self, Key, Shift);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TmbDeskPickerButton.WheelUp(Sender: TObject; Shift: TShiftState;
|
procedure TmbDeskPickerButton.WheelUp(Sender: TObject; Shift: TShiftState;
|
||||||
MousePos: TPoint; var Handled: Boolean);
|
MousePos: TPoint; var Handled: Boolean);
|
||||||
begin
|
begin
|
||||||
@ -99,4 +146,68 @@ begin
|
|||||||
FOnWheelDown(Self, Shift, MousePos, Handled);
|
FOnWheelDown(Self, Shift, MousePos, Handled);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TmbDeskPickerAction }
|
||||||
|
|
||||||
|
constructor TmbDeskPickerAction.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FHintFmt := 'RGB(%r, %g, %b)'#13'Hex: %h';
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.ExecuteTarget(Target: TObject);
|
||||||
|
begin
|
||||||
|
StartPicking;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TmbDeskPickerAction.HandlesTarget(Target: TObject): Boolean;
|
||||||
|
begin
|
||||||
|
Result := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.ScreenKeyDown(Sender: TObject; var Key: Word;
|
||||||
|
Shift: TShiftState);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnScreenKeyDown) then
|
||||||
|
FOnScreenKeyDown(Self, Key, Shift);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.ColorPicked(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FSelColor := FScreenFrm.SelectedColor;
|
||||||
|
if Assigned(FOnColorPicked) then
|
||||||
|
FOnColorPicked(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.StartPicking;
|
||||||
|
begin
|
||||||
|
FScreenFrm := TScreenForm.Create(Application);
|
||||||
|
try
|
||||||
|
FScreenFrm.OnSelColorChange := @ColorPicked;
|
||||||
|
FScreenFrm.OnScreenKeyDown := @ScreenKeyDown;
|
||||||
|
FScreenFrm.OnMouseWheelDown := @WheelDown;
|
||||||
|
FScreenFrm.OnMouseWheelUp := @WheelUp;
|
||||||
|
FScreenFrm.ShowHint := FShowScreenHint;
|
||||||
|
FScreenFrm.FHintFormat := FHintFmt;
|
||||||
|
FScreenFrm.ShowModal;
|
||||||
|
finally
|
||||||
|
FScreenFrm.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.WheelUp(Sender: TObject; Shift: TShiftState;
|
||||||
|
MousePos: TPoint; var Handled: Boolean);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnWheelUp) then
|
||||||
|
FOnWheelUp(Self, Shift, MousePos, Handled);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TmbDeskPickerAction.WheelDown(Sender: TObject; Shift: TShiftState;
|
||||||
|
MousePos: TPoint; var Handled: Boolean);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnWheelDown) then
|
||||||
|
FOnWheelDown(Self, Shift, MousePos, Handled);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -14,6 +14,7 @@ implementation
|
|||||||
//{$R mbReg.res}
|
//{$R mbReg.res}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
ActnList,
|
||||||
RColorPicker, GColorPicker, BColorPicker,
|
RColorPicker, GColorPicker, BColorPicker,
|
||||||
RAxisColorPicker, GAxisColorPicker, BAxisColorPicker,
|
RAxisColorPicker, GAxisColorPicker, BAxisColorPicker,
|
||||||
CColorPicker, YColorPicker, MColorPicker, KColorPicker,
|
CColorPicker, YColorPicker, MColorPicker, KColorPicker,
|
||||||
@ -37,8 +38,11 @@ begin
|
|||||||
THSColorPicker, THSVColorPicker, THSLColorPicker, THSLRingPicker,
|
THSColorPicker, THSVColorPicker, THSLColorPicker, THSLRingPicker,
|
||||||
TSLColorPicker, TSLHColorPicker,
|
TSLColorPicker, TSLHColorPicker,
|
||||||
TCIEAColorPicker, TCIEBColorPicker, TCIELColorPicker,
|
TCIEAColorPicker, TCIEBColorPicker, TCIELColorPicker,
|
||||||
THexaColorPicker, TmbColorPreview, TmbColorList, TmbColorTree, TmbColorPalette,
|
THexaColorPicker, TmbColorPreview, TmbColorList, TmbColorTree,
|
||||||
TmbOfficeColorDialog, TmbDeskPickerButton]);
|
TmbColorPalette, TmbOfficeColorDialog, TmbDeskPickerButton
|
||||||
|
]);
|
||||||
|
|
||||||
|
RegisterActions('mbColorLib', [TmbDeskPickerAction], nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user