mbColorLib: Fix endless change loops between RGB ColorPicker and RGB AxisColorPicker. Add axispickers demo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5563 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-12-24 12:47:07 +00:00
parent 83f00a7a0b
commit 054fd3f9f6
21 changed files with 596 additions and 106 deletions

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="axispickers"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="mbColorLibLaz"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="axispickers.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="axispickers"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@@ -0,0 +1,21 @@
program axispickers;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, main
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,152 @@
object Form1: TForm1
Left = 280
Height = 450
Top = 130
Width = 516
Caption = 'AxisPickers'
ClientHeight = 450
ClientWidth = 516
OnCreate = FormCreate
LCLVersion = '1.7'
object PageControl1: TPageControl
Left = 4
Height = 442
Top = 4
Width = 508
ActivePage = PgRED
Align = alClient
BorderSpacing.Around = 4
TabIndex = 0
TabOrder = 0
object PgRED: TTabSheet
Caption = 'Picker based on RED'
ClientHeight = 414
ClientWidth = 500
object PanelRED: TPanel
Left = 0
Height = 414
Top = 0
Width = 500
Align = alClient
BevelOuter = bvNone
ClientHeight = 414
ClientWidth = 500
TabOrder = 0
OnPaint = PanelREDPaint
object RColorPicker1: TRColorPicker
Left = 24
Height = 390
Top = 0
Width = 22
HintFormat = 'Red: %value (selected)'
Align = alLeft
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
TabOrder = 0
OnChange = RColorPicker1Change
SelectedColor = 8421631
end
object RAxisColorPicker1: TRAxisColorPicker
Left = 76
Height = 378
Top = 6
Width = 418
HintFormat = 'G: %g B: %b'#13'Hex: %hex'
Anchors = [akTop, akLeft, akRight]
Align = alClient
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
BorderSpacing.Around = 6
TabOrder = 1
OnChange = RAxisColorPicker1Change
end
end
end
object PgGREEN: TTabSheet
Caption = 'Picker based on GREEN'
ClientHeight = 414
ClientWidth = 500
object PanelGREEN: TPanel
Left = 0
Height = 414
Top = 0
Width = 500
Align = alClient
BevelOuter = bvNone
ClientHeight = 414
ClientWidth = 500
TabOrder = 0
OnPaint = PanelGREENPaint
object GColorPicker1: TGColorPicker
Left = 24
Height = 390
Top = 0
Width = 22
HintFormat = 'Green: %value (selected)'
Align = alLeft
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
TabOrder = 0
OnChange = GColorPicker1Change
SelectedColor = 8454016
end
object GAxisColorPicker1: TGAxisColorPicker
Left = 76
Height = 378
Top = 6
Width = 418
HintFormat = 'R: %r B: %b'#13'Hex: %hex'
Align = alClient
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
BorderSpacing.Around = 6
TabOrder = 1
OnChange = GAxisColorPicker1Change
end
end
end
object PgBLUE: TTabSheet
Caption = 'Picker based on BLUE'
ClientHeight = 414
ClientWidth = 500
object PanelBLUE: TPanel
Left = 0
Height = 414
Top = 0
Width = 500
Align = alClient
BevelOuter = bvNone
ClientHeight = 414
ClientWidth = 500
TabOrder = 0
OnPaint = PanelBLUEPaint
object BColorPicker1: TBColorPicker
Left = 24
Height = 390
Top = 0
Width = 22
HintFormat = 'Blue: %value (selected)'
Align = alLeft
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
TabOrder = 0
OnChange = BColorPicker1Change
SelectedColor = 16744576
end
object BAxisColorPicker1: TBAxisColorPicker
Left = 76
Height = 378
Top = 6
Width = 418
HintFormat = 'R: %r G: %g'#13'Hex: %hex'
Align = alClient
BorderSpacing.Left = 24
BorderSpacing.Bottom = 24
BorderSpacing.Around = 6
TabOrder = 1
OnChange = BAxisColorPicker1Change
end
end
end
end
end

View File

@@ -0,0 +1,201 @@
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, ComCtrls, RAxisColorPicker, RColorPicker, GColorPicker,
GAxisColorPicker, BColorPicker, BAxisColorPicker;
type
{ TForm1 }
TForm1 = class(TForm)
PageControl1: TPageControl;
RAxisColorPicker1: TRAxisColorPicker;
BAxisColorPicker1: TBAxisColorPicker;
GAxisColorPicker1: TGAxisColorPicker;
RColorPicker1: TRColorPicker;
BColorPicker1: TBColorPicker;
GColorPicker1: TGColorPicker;
PanelBLUE: TPanel;
PanelGREEN: TPanel;
PanelRED: TPanel;
PgRED: TTabSheet;
PgGREEN: TTabSheet;
PgBLUE: TTabSheet;
procedure BAxisColorPicker1Change(Sender: TObject);
procedure BColorPicker1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure GAxisColorPicker1Change(Sender: TObject);
procedure GColorPicker1Change(Sender: TObject);
procedure PanelBLUEPaint(Sender: TObject);
procedure PanelGREENPaint(Sender: TObject);
procedure PanelREDPaint(Sender: TObject);
procedure RAxisColorPicker1Change(Sender: TObject);
procedure RColorPicker1Change(Sender: TObject);
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
Types, GraphUtil;
{ TForm1 }
procedure TForm1.BAxisColorPicker1Change(Sender: TObject);
begin
BColorPicker1.SelectedColor := BAxisColorPicker1.SelectedColor;
end;
procedure TForm1.BColorPicker1Change(Sender: TObject);
begin
BAxisColorPicker1.SelectedColor := BColorPicker1.SelectedColor;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RAxisColorPicker1.SelectedColor := clRed;
GAxisColorPicker1.SelectedColor := clGreen;
BAxisColorPicker1.SelectedColor := clBlue;
end;
procedure TForm1.GAxisColorPicker1Change(Sender: TObject);
begin
GColorPicker1.SelectedColor := GAxisColorPicker1.SelectedColor;
end;
procedure TForm1.GColorPicker1Change(Sender: TObject);
begin
GAxisColorPicker1.SelectedColor := GColorPicker1.SelectedColor;
end;
// On BlueAxisPicker, x is RED, y is GREEN
procedure TForm1.PanelBLUEPaint(Sender: TObject);
var
x, y: Integer;
Rr, Rg, Rb: TSize;
begin
PanelBLUE.Canvas.Font.Assign(PanelRED.Font);
Rr := PanelBLUE.Canvas.TextExtent('red');
Rg := PanelBLUE.Canvas.TextExtent('green');
Rb := PanelBLUE.Canvas.TextExtent('blue');
x := BAxisColorPicker1.Left + (BAxisColorPicker1.Width - Rr.CX) div 2;
y := BAxisColorPicker1.Top + BAxisColorPicker1.Height + 4;
PanelBLUE.Canvas.TextOut(x, y, 'red');
x := x + Rr.CX div 2;
y := y + Rr.CY div 2;
DrawArrow(PanelBLUE.Canvas, sdRight, Point(x + 16, y), 16, atArrows);
PanelBLUE.Canvas.Font.Orientation := 900;
x := BColorPicker1.Left - Rb.CY - 4;
y := BColorPicker1.Top + (BColorPicker1.Height + Rb.CX) div 2;
PanelBLUE.Canvas.TextOut(x, y, 'blue');
x := x + Rb.CY * 3 div 4;
y := y - Rb.CX - 16;
DrawArrow(PanelBLUE.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
x := BAxisColorPicker1.Left - Rg.CY - 4;
y := BAxisColorPicker1.Top + (BAxisColorPicker1.Height + Rg.CX) div 2;
PanelBLUE.Canvas.TextOut(x, y, 'green');
x := x + Rg.CY * 3 div 4;
y := y - Rg.CX - 16;
DrawArrow(PanelBLUE.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
end;
// on GreenAxisPicker, x is BLUE, y is RED
procedure TForm1.PanelGREENPaint(Sender: TObject);
var
x, y: Integer;
Rr, Rg, Rb: TSize;
begin
PanelGREEN.Canvas.Font.Assign(PanelGREEN.Font);
Rr := PanelGREEN.Canvas.TextExtent('red');
Rg := PanelGREEN.Canvas.TextExtent('green');
Rb := PanelGREEN.Canvas.TextExtent('blue');
x := GAxisColorPicker1.Left + (GAxisColorPicker1.Width - Rb.CX) div 2;
y := GAxisColorPicker1.Top + GAxisColorPicker1.Height + 4;
PanelGREEN.Canvas.TextOut(x, y, 'blue');
x := x + Rb.CX div 2;
y := y + Rb.CY div 2;
DrawArrow(PanelGREEN.Canvas, sdRight, Point(x + 16, y), 16, atArrows); //Solid);
PanelGREEN.Canvas.Font.Orientation := 900;
x := GColorPicker1.Left - Rg.CY - 4;
y := GColorPicker1.Top + (GColorPicker1.Height + Rg.CX) div 2;
PanelGREEN.Canvas.TextOut(x, y, 'green');
x := x + Rg.CY * 3 div 4;
y := y - Rg.CX - 16;
DrawArrow(PanelGREEN.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
x := GAxisColorPicker1.Left - Rr.CY - 4;
y := GAxisColorPicker1.Top + (GAxisColorPicker1.Height + Rr.CX) div 2;
PanelGREEN.Canvas.TextOut(x, y, 'red');
x := x + Rr.CY * 3 div 4;
y := y - Rr.CX - 16;
DrawArrow(PanelGREEN.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
end;
procedure TForm1.PanelREDPaint(Sender: TObject);
var
x, y: Integer;
Rr, Rg, Rb: TSize;
begin
PanelRED.Canvas.Font.Assign(PanelRED.Font);
Rr := PanelRED.Canvas.TextExtent('red');
Rg := PanelRED.Canvas.TextExtent('green');
Rb := PanelRED.Canvas.TextExtent('blue');
x := RAxisColorPicker1.Left + (RAxisColorPicker1.Width - Rb.CX) div 2;
y := RAxisColorPicker1.Top + RAxisColorPicker1.Height + 4;
PanelRED.Canvas.TextOut(x, y, 'blue');
x := x + Rb.CX div 2;
y := y + Rb.CY div 2;
DrawArrow(PanelRED.Canvas, sdRight, Point(x + 16, y), 16, atArrows); //Solid);
PanelRED.Canvas.Font.Orientation := 900;
x := RColorPicker1.Left - Rr.CY - 4;
y := RColorPicker1.Top + (RColorPicker1.Height + Rr.CX) div 2;
PanelRED.Canvas.TextOut(x, y, 'red');
x := x + Rr.CY * 3 div 4;
y := y - Rr.CX - 16;
DrawArrow(PanelRED.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
x := RAxisColorPicker1.Left - Rg.CY - 4;
y := RAxisColorPicker1.Top + (RAxisColorPicker1.Height + Rg.CX) div 2;
PanelRED.Canvas.TextOut(x, y, 'green');
x := x + Rg.CY * 3 div 4;
y := y - Rg.CX - 16;
DrawArrow(PanelRED.Canvas, sdUp, Point(x, y + 8), 16, atArrows);
end;
procedure TForm1.RAxisColorPicker1Change(Sender: TObject);
begin
RColorPicker1.SelectedColor := RAxisColorPicker1.SelectedColor;
end;
procedure TForm1.RColorPicker1Change(Sender: TObject);
begin
RAXisColorPicker1.SelectedColor := RColorPicker1.SelectedColor;
end;
end.