mbColorLib: Refactor OnChange events. (NOTE: OfficeColorDialog may hang when switching pickers).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5578 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-01-02 00:05:26 +00:00
parent 176aff8ff1
commit 454f0baf7b
41 changed files with 1830 additions and 1837 deletions

View File

@@ -9,7 +9,6 @@
<Title Value="axispickers"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>

View File

@@ -10,35 +10,39 @@ object Form1: TForm1
LCLVersion = '1.7'
object PageControl1: TPageControl
Left = 4
Height = 442
Height = 420
Top = 4
Width = 508
ActivePage = PgRED
Align = alClient
BorderSpacing.Around = 4
BorderSpacing.Left = 4
BorderSpacing.Top = 4
BorderSpacing.Right = 4
TabIndex = 0
TabOrder = 0
OnChange = PageControl1Change
object PgRED: TTabSheet
Caption = 'Picker based on RED'
ClientHeight = 414
ClientHeight = 392
ClientWidth = 500
object PanelRED: TPanel
Left = 0
Height = 414
Height = 392
Top = 0
Width = 500
Align = alClient
BevelOuter = bvNone
ClientHeight = 414
ClientHeight = 392
ClientWidth = 500
TabOrder = 0
OnPaint = PanelREDPaint
object RColorPicker1: TRColorPicker
Left = 24
Height = 390
Height = 368
Top = 0
Width = 22
HintFormat = 'Red: %value (selected)'
SelectionIndicator = siRect
Align = alLeft
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
@@ -48,7 +52,7 @@ object Form1: TForm1
end
object RAxisColorPicker1: TRAxisColorPicker
Left = 76
Height = 378
Height = 356
Top = 6
Width = 418
HintFormat = 'G: %g B: %b'#13'Hex: %hex'
@@ -64,22 +68,22 @@ object Form1: TForm1
end
object PgGREEN: TTabSheet
Caption = 'Picker based on GREEN'
ClientHeight = 414
ClientHeight = 392
ClientWidth = 500
object PanelGREEN: TPanel
Left = 0
Height = 414
Height = 392
Top = 0
Width = 500
Align = alClient
BevelOuter = bvNone
ClientHeight = 414
ClientHeight = 392
ClientWidth = 500
TabOrder = 0
OnPaint = PanelGREENPaint
object GColorPicker1: TGColorPicker
Left = 24
Height = 390
Height = 368
Top = 0
Width = 22
HintFormat = 'Green: %value (selected)'
@@ -92,7 +96,7 @@ object Form1: TForm1
end
object GAxisColorPicker1: TGAxisColorPicker
Left = 76
Height = 378
Height = 356
Top = 6
Width = 418
HintFormat = 'R: %r B: %b'#13'Hex: %hex'
@@ -149,4 +153,42 @@ object Form1: TForm1
end
end
end
object Panel1: TPanel
Left = 0
Height = 26
Top = 424
Width = 516
Align = alBottom
BevelOuter = bvNone
ClientHeight = 26
ClientWidth = 516
TabOrder = 1
object Label1: TLabel
AnchorSideLeft.Control = mbColorPreview1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = mbColorPreview1
AnchorSideTop.Side = asrCenter
Left = 76
Height = 15
Top = 5
Width = 34
BorderSpacing.Left = 8
Caption = 'Label1'
ParentColor = False
end
object mbColorPreview1: TmbColorPreview
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 20
Top = 2
Width = 60
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Bottom = 4
end
end
end

View File

@@ -7,14 +7,17 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, ComCtrls, RAxisColorPicker, RColorPicker, GColorPicker,
GAxisColorPicker, BColorPicker, BAxisColorPicker;
GAxisColorPicker, BColorPicker, BAxisColorPicker, mbColorPreview;
type
{ TForm1 }
TForm1 = class(TForm)
Label1: TLabel;
mbColorPreview1: TmbColorPreview;
PageControl1: TPageControl;
Panel1: TPanel;
RAxisColorPicker1: TRAxisColorPicker;
BAxisColorPicker1: TBAxisColorPicker;
GAxisColorPicker1: TGAxisColorPicker;
@@ -32,11 +35,14 @@ type
procedure FormCreate(Sender: TObject);
procedure GAxisColorPicker1Change(Sender: TObject);
procedure GColorPicker1Change(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure PanelBLUEPaint(Sender: TObject);
procedure PanelGREENPaint(Sender: TObject);
procedure PanelREDPaint(Sender: TObject);
procedure RAxisColorPicker1Change(Sender: TObject);
procedure RColorPicker1Change(Sender: TObject);
private
procedure UpdatePreview;
public
end;
@@ -49,18 +55,20 @@ implementation
{$R *.lfm}
uses
Types, GraphUtil;
LclIntf, Types, GraphUtil, HTMLColors;
{ TForm1 }
procedure TForm1.BAxisColorPicker1Change(Sender: TObject);
begin
BColorPicker1.SelectedColor := BAxisColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.BColorPicker1Change(Sender: TObject);
begin
BAxisColorPicker1.SelectedColor := BColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.FormCreate(Sender: TObject);
@@ -68,16 +76,24 @@ begin
RAxisColorPicker1.SelectedColor := clRed;
GAxisColorPicker1.SelectedColor := clGreen;
BAxisColorPicker1.SelectedColor := clBlue;
UpdatePreview;
end;
procedure TForm1.GAxisColorPicker1Change(Sender: TObject);
begin
GColorPicker1.SelectedColor := GAxisColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.GColorPicker1Change(Sender: TObject);
begin
GAxisColorPicker1.SelectedColor := GColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.PageControl1Change(Sender: TObject);
begin
UpdatePreview;
end;
// On BlueAxisPicker, x is RED, y is GREEN
@@ -190,12 +206,28 @@ end;
procedure TForm1.RAxisColorPicker1Change(Sender: TObject);
begin
RColorPicker1.SelectedColor := RAxisColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.RColorPicker1Change(Sender: TObject);
begin
RAXisColorPicker1.SelectedColor := RColorPicker1.SelectedColor;
UpdatePreview;
end;
procedure TForm1.UpdatePreview;
begin
case PageControl1.ActivePageindex of
0: mbColorPreview1.Color := RColorPicker1.SelectedColor;
1: mbColorPreview1.Color := GColorPicker1.SelectedColor;
2: mbColorPreview1.Color := BColorPicker1.SelectedColor;
end;
Label1.Caption := Format('R=%d G=%d B=%d HTML=#%s', [
GetRValue(mbColorPreview1.Color),
GetGValue(mbColorPreview1.Color),
GetBValue(mbColorPreview1.Color),
ColorToHex(mbColorPreview1.Color)
]);
end;
end.