ColorPalette: Remove properties related to "Selected" color, replace by "Picked" color etc. Reason: Color selection event handler must pass Shift state to calling routine for further evaluation --> Reactivate old OnColorPick (instead of OnSelectColor). Remove property PickShift.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4296 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-08-26 14:29:55 +00:00
parent 754d1f376e
commit 0e8bee25b6
5 changed files with 110 additions and 316 deletions

View File

@ -58,9 +58,6 @@ type
pmContinuous // Select color at mouse-down and mouse-move, ColorPick event at mouse-up
);
TPickShiftEnum = (ssLeft, ssRight, ssMiddle);
TPickShift = set of TPickShiftEnum;
TPaletteKind = (pkStandardPalette, pkExtendedPalette, pkSystemPalette,
pkStandardAndSystemPalette, pkExtendedAndSystemPalette,
pkGradientPalette, pkHTMLPalette, pkWebSafePalette);
@ -83,14 +80,11 @@ type
FCols: Integer;
FOnColorMouseMove: TColorMouseEvent;
FOnColorPick: TColorMouseEvent;
FOnSelectColor: TColorPaletteEvent;
FOnGetHintText: TColorPaletteHintEvent;
FRows: Integer;
FColors: TStringList;
FSelectedColor: TColor;
FSelectedIndex: Integer;
FPickedIndex: Integer;
FPickMode: TPickMode;
FPickShift: TPickShift;
FMousePt: TPoint;
FMouseIndex: Integer;
FPrevMouseIndex: Integer;
@ -118,7 +112,7 @@ type
procedure SetCols(AValue: Integer);
procedure SetGradientSteps(AValue: Byte);
procedure SetPaletteKind(AValue: TPaletteKind);
procedure SetSelectedIndex(AValue: Integer);
procedure SetPickedIndex(AValue: Integer);
procedure SetSelectionColor(AValue: TColor);
procedure SetSelectionKind(AValue: TPaletteSelectionKind);
procedure SetUseSpacers(AValue: Boolean);
@ -132,12 +126,10 @@ type
procedure DoColorPick(AColor: TColor; AShift: TShiftState); virtual;
procedure DoDeleteColor(AIndex: Integer); virtual;
procedure DoInsertColor(AIndex: Integer; AColor: TColor; AColorName: String = ''); virtual;
procedure DoSelectColor(AColor: TColor); virtual;
function GetCellHeight: Integer; inline;
function GetCellWidth: Integer; inline;
function GetColorIndex(X,Y: Integer): Integer;
function GetHintText(AIndex: Integer): String; virtual;
function IsCorrectShift(Shift: TShiftState): Boolean;
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X, Y:Integer); override;
procedure MouseEnter; override;
procedure MouseLeave; override;
@ -153,13 +145,15 @@ type
property Flipped: Boolean read FFlipped write SetFlipped default false;
property GradientSteps: Byte read FGradientSteps write SetGradientSteps default 3;
property PaletteKind: TPaletteKind read FPaletteKind write SetPaletteKind default pkStandardPalette;
property PickedIndex: Integer read FPickedIndex write SetPickedIndex default -1;
property PickMode: TPickMode read FPickMode write FPickMode default pmImmediate;
property PickShift: TPickShift read FPickShift write FPickShift default [ssLeft];
property SelectedIndex: Integer read FSelectedIndex write SetSelectedIndex default 0;
property SelectionColor: TColor read FSelectionColor write SetSelectionColor default clBlack;
property SelectionKind: TPaletteSelectionKind read FSelectionKind write SetSelectionKind default pskNone;
property ShowColorHint: Boolean read FShowColorHint write FShowColorHint default true;
property UseSpacers: Boolean read FUseSpacers write SetUseSpacers default true;
property OnColorPick: TColorMouseEvent read FOnColorPick write FOnColorPick;
property OnColorMouseMove: TColorMouseEvent read FOnColorMouseMove write FOnColorMouseMove;
property OnGetHintText: TColorPaletteHintEvent read FOnGetHintText write FOnGetHintText;
public
@ -179,13 +173,8 @@ type
property ColorCount: Integer read GetColorCount;
property MouseIndex: Integer read FMouseIndex;
property MouseColor: TColor read GetMouseColor;
property PickedColor: TColor read GetPickedColor; deprecated 'Use SelectedColor';
property SelectedColor: TColor read FSelectedColor;
property PickedColor: TColor read GetPickedColor;
property OnSelectColor: TColorPaletteEvent read FOnSelectColor write FOnSelectColor;
property OnColorPick: TColorMouseEvent read FOnColorPick write FOnColorPick;
property OnColorMouseMove: TColorMouseEvent read FOnColorMouseMove write FOnColorMouseMove;
property Height stored False;
property Width stored False;
end;
@ -201,9 +190,8 @@ type
property Flipped;
property GradientSteps;
property PaletteKind;
property PickedIndex;
property PickMode;
property PickShift;
property SelectedIndex;
property SelectionColor;
property SelectionKind;
property ShowColorHint;
@ -212,7 +200,6 @@ type
property OnColorMouseMove;
property OnColorPick;
property OnGetHintText;
property OnSelectColor;
// inherited from TCustomColorPalette's ancestors
property Align;
@ -272,7 +259,6 @@ begin
FButtonWidth := 12;
FPrevMouseIndex := -1;
FPickMode := pmImmediate;
FPickShift := [ssLeft];
FShowColorHint := true;
FGradientSteps := 3;
FUseSpacers := true;
@ -330,10 +316,10 @@ procedure TCustomColorPalette.ColorPick(AIndex: Integer; Shift: TShiftState);
var
c: TColor;
begin
FPickedIndex := AIndex;
c := GetColors(AIndex);
DoColorPick(c, Shift);
if IsCorrectShift(Shift) then
SelectedIndex := AIndex;
Invalidate;
end;
procedure TCustomColorPalette.ColorMouseMove(AColor: TColor; Shift: TShiftState);
@ -373,13 +359,6 @@ begin
FColors.InsertObject(AIndex, AColorName, TObject(PtrInt(AColor)));
end;
procedure TCustomColorPalette.DoSelectColor(AColor: TColor);
begin
FSelectedColor := AColor;
Invalidate;
if Assigned(FOnSelectColor) then FOnSelectColor(self, AColor);
end;
function TCustomColorPalette.GetColorCount: Integer;
begin
Result := FColors.Count;
@ -488,7 +467,7 @@ end;
function TCustomColorPalette.GetPickedColor: TColor;
begin
Result := GetColors(FMouseIndex);
Result := GetColors(FPickedIndex);
end;
procedure TCustomColorPalette.InsertColor(AIndex: Integer; AColor: TColor;
@ -497,15 +476,6 @@ begin
DoInsertColor(AIndex, AColor, AColorName);
end;
function TCustomColorPalette.IsCorrectShift(Shift: TShiftState): Boolean;
begin
Result := True;
if (ssLeft in FPickShift) and (Classes.ssLeft in Shift) then exit;
if (ssRight in FPickShift) and (Classes.ssRight in Shift) then exit;
if (ssMiddle in FPickShift) and (Classes.ssMiddle in Shift) then exit;
Result := false;
end;
procedure TCustomColorPalette.LoadPalette(const FileName: String);
var
F: TextFile;
@ -620,7 +590,7 @@ begin
end;
UpdateSize;
SelectedIndex := 0;
PickedIndex := -1;
end;
procedure TCustomColorPalette.MouseDown(Button: TMouseButton;
@ -665,7 +635,8 @@ begin
inherited;
FMouseIndex := GetColorIndex(X, Y);
if (FMouseIndex >= 0) and (FMouseIndex < FColors.Count) then
if (FMouseIndex >= 0) and (FMouseIndex < FColors.Count) and
([ssLeft, ssRight, ssMiddle] * Shift <> []) then
begin
C := GetColors(FMouseIndex);
if ShowHint and FShowColorHint then
@ -761,7 +732,7 @@ begin
for I := 0 to pred(FColors.Count) do
begin
if I = FSelectedIndex then // Selected rect of box with selected color
if I = FPickedIndex then // Selected rect of box with selected color
Rsel := Bounds(X, Y, FButtonWidth, FButtonHeight);
PaintBox(X, Y, X + FButtonWidth, Y + FButtonHeight, GetColors(I));
if FFlipped then
@ -808,7 +779,7 @@ begin
Canvas.Pen.Color := FSelectionColor;
pskThinInverted, pskThickInverted:
begin
Canvas.Pen.Color := InvertColor(GetColors(FSelectedIndex));
Canvas.Pen.Color := InvertColor(GetPickedColor);
if (FSelectionKind = pskThinInverted) and (Canvas.Pen.Color = FButtonBorderColor) then
Canvas.Pen.Color := FSelectionColor;
end;
@ -890,6 +861,9 @@ begin
Invalidate;
end;
{ Setter for the property ColumnCount.
WARNING: If Flipped is true then this property is reinterpreted as the number
of ROWS! }
procedure TCustomColorPalette.SetCols(AValue: Integer);
begin
if AValue = FCols then
@ -899,6 +873,9 @@ begin
Invalidate;
end;
{ Setter for the property Flipped.
WARNING: If Flipped is true then the property ColumnCount is reinterpreted
as the number of ROWS! }
procedure TCustomColorPalette.SetFlipped(AValue: Boolean);
begin
if FFlipped = AValue then exit;
@ -1171,152 +1148,6 @@ begin
DoAddColor(RGBToColor( 0, 0, 0), 'Black');
end;
{
if FPaletteKind = pkHTMLPalette then
begin
DoAddColor(RGBToColor(255,255,255), 'white');
DoAddColor(RGBToColor(255,255,240), 'ivory');
DoAddColor(RGBToColor(255,255,224), 'lightyellow');
DoAddColor(RGBToColor(255,255, 0), 'yellow');
DoAddColor(RGBToColor(255,250,250), 'snow');
DoAddColor(RGBToColor(255,250,240), 'floralwhite');
DoAddColor(RGBToColor(255,250,205), 'lemonchiffon');
DoAddColor(RGBToColor(255,248,220), 'cornsilk');
DoAddColor(RGBToColor(255,245,238), 'seashell');
DoAddColor(RGBToColor(255,240,245), 'lavenderblush');
DoAddColor(RGBToColor(255,239,213), 'papayawhip');
DoAddColor(RGBToColor(255,235,205), 'blanchedalmond');
DoAddColor(RGBToColor(255,228,225), 'mistyrose');
DoAddColor(RGBToColor(255,228,196), 'bisque');
DoAddColor(RGBToColor(255,228,181), 'moccasin');
DoAddColor(RGBToColor(255,222,173), 'navajowhite');
DoAddColor(RGBToColor(255,218,185), 'peachpuff');
DoAddColor(RGBToColor(255,215, 0), 'gold');
DoAddColor(RGBToColor(255,192,203), 'pink');
DoAddColor(RGBToColor(255,182,193), 'lightpink');
DoAddColor(RGBToColor(255,165, 0), 'orange');
DoAddColor(RGBToColor(255,160,122), 'lightsalmon');
DoAddColor(RGBToColor(255,140, 0), 'darkorange');
DoAddColor(RGBToColor(255,127, 80), 'coral');
DoAddColor(RGBToColor(255,105,180), 'hotpink');
DoAddColor(RGBToColor(255, 99, 71), 'tomato');
DoAddColor(RGBToColor(255, 69, 0), 'orangered');
DoAddColor(RGBToColor(255, 20,147), 'deeppink');
DoAddColor(RGBToColor(255, 0,255), 'fuchsia');
DoAddColor(RGBToColor(255, 0,255), 'fuchsia');
DoAddColor(RGBToColor(255, 0, 0), 'red');
DoAddColor(RGBToColor(253,245,230), 'oldlace');
DoAddColor(RGBToColor(250,250,210), 'lightgoldenrodyellow');
DoAddColor(RGBToColor(250,240,230), 'linen');
DoAddColor(RGBToColor(250,235,215), 'antiquewhite');
DoAddColor(RGBToColor(250,128,114), 'salmon');
DoAddColor(RGBToColor(248,248,255), 'ghostwhite');
DoAddColor(RGBToColor(245,255,250), 'mintcream');
DoAddColor(RGBToColor(245,245,245), 'whitesmoke');
DoAddColor(RGBToColor(245,245,220), 'beige');
DoAddColor(RGBToColor(245,222,179), 'wheat');
DoAddColor(RGBToColor(244,164, 96), 'sandybrown');
DoAddColor(RGBToColor(240,255,255), 'azure');
DoAddColor(RGBToColor(240,255,240), 'honeydew');
DoAddColor(RGBToColor(240,248,255), 'aliceblue');
DoAddColor(RGBToColor(240,230,140), 'khaki');
DoAddColor(RGBToColor(240,128,128), 'lightcoral');
DoAddColor(RGBToColor(238,232,170), 'palegoldenrod');
DoAddColor(RGBToColor(238,130,238), 'violet');
DoAddColor(RGBToColor(233,150,122), 'darksalmon');
DoAddColor(RGBToColor(230,230,250), 'lavender');
DoAddColor(RGBToColor(224,255,255), 'lightcyan');
DoAddColor(RGBToColor(222,184,135), 'burlywood');
DoAddColor(RGBToColor(221,160,221), 'plum');
DoAddColor(RGBToColor(220,220,220), 'gainsboro');
DoAddColor(RGBToColor(220, 20, 60), 'crimson');
DoAddColor(RGBToColor(219,112,147), 'palevioletred');
DoAddColor(RGBToColor(218,165, 32), 'goldenrod');
DoAddColor(RGBToColor(218,112,214), 'orchid');
DoAddColor(RGBToColor(216,191,216), 'thistle');
DoAddColor(RGBToColor(211,211,211), 'lightgrey');
DoAddColor(RGBToColor(210,180,140), 'tan');
DoAddColor(RGBToColor(210,105, 30), 'chocolate');
DoAddColor(RGBToColor(205,133, 63), 'peru');
DoAddColor(RGBToColor(205, 92, 92), 'indianred');
DoAddColor(RGBToColor(199, 21,133), 'mediumvioletred');
DoAddColor(RGBToColor(192,192,192), 'silver');
DoAddColor(RGBToColor(189,183,107), 'darkkhaki');
DoAddColor(RGBToColor(188,143,143), 'rosybrown');
DoAddColor(RGBToColor(186, 85,211), 'mediumorchid');
DoAddColor(RGBToColor(184,134, 11), 'darkgoldenrod');
DoAddColor(RGBToColor(178, 34, 34), 'firebrick');
DoAddColor(RGBToColor(176,224,230), 'powderblue');
DoAddColor(RGBToColor(176,196,222), 'lightsteelblue');
DoAddColor(RGBToColor(175,238,238), 'paleturquoise');
DoAddColor(RGBToColor(173,255, 47), 'greenyellow');
DoAddColor(RGBToColor(173,216,230), 'lightblue');
DoAddColor(RGBToColor(169,169,169), 'darkgray');
DoAddColor(RGBToColor(165, 42, 42), 'brown');
DoAddColor(RGBToColor(160, 82, 45), 'sienna');
DoAddColor(RGBToColor(154,205, 50), 'yellowgreen');
DoAddColor(RGBToColor(153, 50,204), 'darkorchid');
DoAddColor(RGBToColor(152,251,152), 'palegreen');
DoAddColor(RGBToColor(148, 0,211), 'darkviolet');
DoAddColor(RGBToColor(147,112,219), 'mediumpurple');
DoAddColor(RGBToColor(144,238,144), 'lightgreen');
DoAddColor(RGBToColor(143,188,143), 'darkseagreen');
DoAddColor(RGBToColor(139, 69, 19), 'saddlebrown');
DoAddColor(RGBToColor(139, 0,139), 'darkmagenta');
DoAddColor(RGBToColor(139, 0, 0), 'darkred');
DoAddColor(RGBToColor(138, 43,226), 'blueviolet');
DoAddColor(RGBToColor(135,206,250), 'lightskyblue');
DoAddColor(RGBToColor(135,206,235), 'skyblue');
DoAddColor(RGBToColor(128,128,128), 'gray');
DoAddColor(RGBToColor(128,128, 0), 'olive');
DoAddColor(RGBToColor(128, 0,128), 'purple');
DoAddColor(RGBToColor(128, 0, 0), 'maroon');
DoAddColor(RGBToColor(127,255,212), 'aquamarine');
DoAddColor(RGBToColor(127,255, 0), 'chartreuse');
DoAddColor(RGBToColor(124,252, 0), 'lawngreen');
DoAddColor(RGBToColor(123,104,238), 'mediumslateblue');
DoAddColor(RGBToColor(119,136,153), 'lightslategray');
DoAddColor(RGBToColor(112,128,144), 'slategray');
DoAddColor(RGBToColor(107,142, 35), 'olivedrab');
DoAddColor(RGBToColor(106, 90,205), 'slateblue');
DoAddColor(RGBToColor(105,105,105), 'dimgray');
DoAddColor(RGBToColor(102,205,170), 'mediumaquamarine');
DoAddColor(RGBToColor(100,149,237), 'cornflowerblue');
DoAddColor(RGBToColor( 95,158,160), 'cadetblue');
DoAddColor(RGBToColor( 85,107, 47), 'darkolivegreen');
DoAddColor(RGBToColor( 75, 0,130), 'indigo');
DoAddColor(RGBToColor( 72,209,204), 'mediumturquoise');
DoAddColor(RGBToColor( 72, 61,139), 'darkslateblue');
DoAddColor(RGBToColor( 70,130,180), 'steelblue');
DoAddColor(RGBToColor( 65,105,225), 'royalblue');
DoAddColor(RGBToColor( 64,224,208), 'turquoise');
DoAddColor(RGBToColor( 60,179,113), 'mediumseagreen');
DoAddColor(RGBToColor( 50,205, 50), 'limegreen');
DoAddColor(RGBToColor( 47, 79, 79), 'darkslategray');
DoAddColor(RGBToColor( 46,139, 87), 'seagreen');
DoAddColor(RGBToColor( 34,139, 34), 'forestgreen');
DoAddColor(RGBToColor( 32,178,170), 'lightseagreen');
DoAddColor(RGBToColor( 30,144,255), 'dodgerblue');
DoAddColor(RGBToColor( 25, 25,112), 'midnightblue');
DoAddColor(RGBToColor( 0,255,255), 'aqua');
DoAddColor(RGBToColor( 0,255,255), 'cyan');
DoAddColor(RGBToColor( 0,255,127), 'springgreen');
DoAddColor(RGBToColor( 0,255, 0), 'lime');
DoAddColor(RGBToColor( 0,250,154), 'mediumspringgreen');
DoAddColor(RGBToColor( 0,206,209), 'darkturquoise');
DoAddColor(RGBToColor( 0,191,255), 'deepskyblue');
DoAddColor(RGBToColor( 0,139,139), 'darkcyan');
DoAddColor(RGBToColor( 0,128,128), 'teal');
DoAddColor(RGBToColor( 0,128, 0), 'green');
DoAddColor(RGBToColor( 0,100, 0), 'darkgreen');
DoAddColor(RGBToColor( 0, 0,255), 'blue');
DoAddColor(RGBToColor( 0, 0,205), 'mediumblue');
DoAddColor(RGBToColor( 0, 0,139), 'darkblue');
DoAddColor(RGBToColor( 0, 0,128), 'navy');
DoAddColor(RGBToColor( 0, 0, 0), 'black');
end;
}
if FPaletteKind = pkWebSafePalette then
begin
// https://en.wikipedia.org/wiki/Web_colors
@ -1330,17 +1161,13 @@ begin
SetCols(COLCOUNT[FPaletteKind]);
end;
procedure TCustomColorPalette.SetSelectedIndex(AValue: Integer);
procedure TCustomColorPalette.SetPickedIndex(AValue: Integer);
begin
if FSelectedIndex = AValue then exit;
if AValue < 0 then
FSelectedIndex := 0
else
if AValue >= FColors.Count then
FSelectedIndex := FColors.Count-1
else
FSelectedIndex := AValue;
DoSelectColor(GetColors(FSelectedIndex));
if FPickedIndex = AValue then exit;
if (AValue >= 0) and (AValue < FColors.Count) then
FPickedIndex := AValue else
FPickedIndex := -1;
Invalidate;
end;
procedure TCustomColorPalette.SetSelectionColor(AValue: TColor);
@ -1384,7 +1211,7 @@ begin
begin
dec(dx);
dec(dy);
d := -1; // Correct for button frame line width
d := -1; // Needed to correct for button frame line width
end;
if FFlipped then // Rows and columns are interchanged here !!!

View File

@ -55,7 +55,7 @@ object MainForm: TMainForm
Caption = 'Load random palette'
Enabled = False
OnClick = BtnLoadRndPaletteClick
TabOrder = 1
TabOrder = 5
end
object BtnCreateRndPalette: TButton
Left = 10
@ -64,7 +64,7 @@ object MainForm: TMainForm
Width = 137
Caption = 'Create random palette'
OnClick = BtnCreateRndPaletteClick
TabOrder = 2
TabOrder = 4
end
object BtnAddColor: TButton
Left = 10
@ -73,16 +73,16 @@ object MainForm: TMainForm
Width = 137
Caption = 'Add color...'
OnClick = BtnAddColorClick
TabOrder = 3
TabOrder = 7
end
object BtnLoadDefaultPal: TButton
object BtnLoadPalette: TButton
Left = 10
Height = 25
Top = 339
Width = 137
Caption = 'Load palette...'
OnClick = BtnLoadDefaultPalClick
TabOrder = 4
OnClick = BtnLoadPaletteClick
TabOrder = 3
end
object BtnDeleteColor: TButton
Left = 10
@ -91,9 +91,9 @@ object MainForm: TMainForm
Width = 137
Caption = 'Delete color #0'
OnClick = BtnDeleteColorClick
TabOrder = 5
TabOrder = 8
end
object BtnLoadDefaultPal1: TButton
object BtnSavePalette: TButton
Left = 10
Height = 25
Top = 446
@ -119,9 +119,8 @@ object MainForm: TMainForm
Alignment = taRightJustify
Enabled = False
MaxValue = 10
MinValue = 1
OnChange = EdGradientStepsChange
TabOrder = 7
TabOrder = 2
Value = 3
end
object LblBuiltinPalettes: TLabel
@ -153,7 +152,7 @@ object MainForm: TMainForm
)
OnSelect = CbBuiltinPalettesSelect
Style = csDropDownList
TabOrder = 8
TabOrder = 1
Text = 'Standard palette'
end
object MouseColorSample: TShape
@ -214,7 +213,7 @@ object MainForm: TMainForm
Alignment = taRightJustify
MaxValue = 16
OnChange = EdButtonDistanceChange
TabOrder = 0
TabOrder = 9
Value = 1
end
object LblButtonSize: TLabel
@ -234,7 +233,7 @@ object MainForm: TMainForm
Alignment = taRightJustify
MinValue = 1
OnChange = EdButtonSizeChange
TabOrder = 1
TabOrder = 8
Value = 16
end
object LblButtonBorderColor: TLabel
@ -255,7 +254,7 @@ object MainForm: TMainForm
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
ItemHeight = 16
OnSelect = CbButtonBorderColorSelect
TabOrder = 2
TabOrder = 6
end
object CbPickMode: TComboBox
Left = 10
@ -272,7 +271,7 @@ object MainForm: TMainForm
)
OnSelect = CbPickModeSelect
Style = csDropDownList
TabOrder = 3
TabOrder = 0
Text = 'default'
end
object LblPickMode: TLabel
@ -293,7 +292,7 @@ object MainForm: TMainForm
Checked = True
OnChange = CbShowColorHintsChange
State = cbChecked
TabOrder = 4
TabOrder = 3
end
object EdColCount: TSpinEdit
Left = 10
@ -303,7 +302,7 @@ object MainForm: TMainForm
Alignment = taRightJustify
MinValue = 1
OnChange = EdColCountChange
TabOrder = 5
TabOrder = 10
Value = 8
end
object LblColCount: TLabel
@ -322,7 +321,7 @@ object MainForm: TMainForm
Width = 108
Caption = 'Custom hint text'
OnChange = CbCustomHintTextChange
TabOrder = 6
TabOrder = 4
end
object CbUseSpacers: TCheckBox
Left = 10
@ -333,7 +332,7 @@ object MainForm: TMainForm
Checked = True
OnChange = CbUseSpacersChange
State = cbChecked
TabOrder = 7
TabOrder = 5
end
object LblBkColor: TLabel
Left = 10
@ -353,7 +352,7 @@ object MainForm: TMainForm
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
ItemHeight = 16
OnSelect = CbBkColorSelect
TabOrder = 8
TabOrder = 7
end
object LblSelKind: TLabel
Left = 10
@ -381,7 +380,7 @@ object MainForm: TMainForm
)
OnSelect = CbSelKindSelect
Style = csDropDownList
TabOrder = 9
TabOrder = 1
Text = 'none'
end
object LblSelColor: TLabel
@ -402,7 +401,7 @@ object MainForm: TMainForm
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
ItemHeight = 16
OnSelect = CbSelColorSelect
TabOrder = 10
TabOrder = 2
end
object CbFlipped: TCheckBox
Left = 10
@ -451,9 +450,9 @@ object MainForm: TMainForm
ButtonHeight = 20
ButtonWidth = 20
ColumnCount = 8
PickShift = [ssLeft, ssRight]
PickedIndex = 0
OnColorPick = ColorPaletteColorPick
OnGetHintText = ColorPaletteGetHintText
OnSelectColor = ColorPaletteSelectColor
ParentColor = False
PopupMenu = PalettePopupMenu
OnDblClick = ColorPaletteDblClick

View File

@ -16,11 +16,11 @@ type
Bevel1: TBevel;
Bevel2: TBevel;
BtnDeleteColor: TButton;
BtnLoadDefaultPal1: TButton;
BtnSavePalette: TButton;
BtnLoadRndPalette: TButton;
BtnCreateRndPalette: TButton;
BtnAddColor: TButton;
BtnLoadDefaultPal: TButton;
BtnLoadPalette: TButton;
BtnEditColor: TButton;
CbBuiltinPalettes: TComboBox;
CbSelColor: TColorBox;
@ -64,7 +64,7 @@ type
procedure BtnCreateRndPaletteClick(Sender: TObject);
procedure BtnDeleteColorClick(Sender: TObject);
procedure BtnEditColorClick(Sender: TObject);
procedure BtnLoadDefaultPalClick(Sender: TObject);
procedure BtnLoadPaletteClick(Sender: TObject);
procedure BtnLoadRndPaletteClick(Sender: TObject);
procedure CbBuiltinPalettesSelect(Sender: TObject);
procedure CbBkColorSelect(Sender: TObject);
@ -76,6 +76,8 @@ type
procedure CbButtonBorderColorSelect(Sender: TObject);
procedure CbUseSpacersChange(Sender: TObject);
procedure CbFlippedChange(Sender: TObject);
procedure ColorPaletteColorPick(Sender: TObject; AColor: TColor;
Shift: TShiftState);
procedure ColorPaletteDblClick(Sender: TObject);
procedure ColorPaletteGetHintText(Sender: TObject; AColor: TColor;
var AText: String);
@ -83,7 +85,6 @@ type
procedure ColorPaletteMouseLeave(Sender: TObject);
procedure ColorPaletteMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure ColorPaletteSelectColor(Sender: TObject; AColor: TColor);
procedure EdButtonDistanceChange(Sender: TObject);
procedure EdButtonSizeChange(Sender: TObject);
procedure EdColCountChange(Sender: TObject);
@ -146,18 +147,18 @@ procedure TMainForm.BtnDeleteColorClick(Sender: TObject);
begin
with ColorPalette do
begin
DeleteColor(SelectedIndex);
if SelectedIndex = ColorCount then SelectedIndex := ColorCount-1;
ColorSample.Brush.Color := Colors[SelectedColor];
if Colors[SelectedColor] = clNone then
DeleteColor(PickedIndex);
if PickedIndex = ColorCount then PickedIndex := ColorCount-1;
ColorSample.Brush.Color := PickedColor;
if PickedColor = clNone then
ColorSample.Brush.Style := bsClear else
ColorSample.Brush.Style := bsSolid;
UpdateCaption;
SetColorInfo(LblColorInfo, 'Current', SelectedIndex);
SetColorInfo(LblColorInfo, 'Current', PickedIndex);
end;
end;
procedure TMainForm.BtnLoadDefaultPalClick(Sender: TObject);
procedure TMainForm.BtnLoadPaletteClick(Sender: TObject);
begin
with OpenDialog do
if Execute then
@ -250,17 +251,29 @@ begin
ColorPalette.Flipped := CbFlipped.Checked;
end;
procedure TMainForm.ColorPaletteColorPick(Sender: TObject; AColor: TColor;
Shift: TShiftState);
begin
ColorSample.Brush.Color := AColor;
if AColor = clNone then
ColorSample.Brush.Style := bsClear else
ColorSample.Brush.Style := bsSolid;
SetColorInfo(LblColorInfo, 'Picked color', ColorPalette.PickedIndex);
BtnDeleteColor.Caption := 'Delete color #' + IntToStr(ColorPalette.PickedIndex);
UpdateCaption;
end;
procedure TMainForm.ColorPaletteDblClick(Sender: TObject);
begin
with ColorDialog do
begin
Color := ColorPalette.Colors[ColorPalette.SelectedIndex];
Color := ColorPalette.PickedColor;
if Execute then
begin
ColorPalette.Colors[ColorPalette.SelectedIndex] := Color;
ColorPalette.Colors[ColorPalette.PickedIndex] := Color;
ColorSample.Brush.Color := Color;
ColorSample.Brush.Style := bsSolid;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.SelectedIndex);
SetColorInfo(LblColorInfo, 'Current', ColorPalette.PickedIndex);
with BtnEditColor do
begin
Caption := 'Edit';
@ -297,18 +310,7 @@ begin
if MouseColorSample.Brush.Color = clNone then
MouseColorSample.Brush.Style := bsClear else
MouseColorSample.Brush.Style := bsSolid;
SetColorInfo(LblMouseColorInfo, 'MouseColor', ColorPalette.MouseIndex);
end;
procedure TMainForm.ColorPaletteSelectColor(Sender: TObject; AColor: TColor);
begin
ColorSample.Brush.Color := AColor;
if AColor = clNone then
ColorSample.Brush.Style := bsClear else
ColorSample.Brush.Style := bsSolid;
SetColorInfo(LblColorInfo, 'SelectedColor', ColorPalette.SelectedIndex);
BtnDeleteColor.Caption := 'Delete color #' + IntToStr(ColorPalette.SelectedIndex);
UpdateCaption;
SetColorInfo(LblMouseColorInfo, 'Mouse color', ColorPalette.MouseIndex);
end;
procedure TMainForm.EdButtonDistanceChange(Sender: TObject);
@ -343,11 +345,11 @@ begin
ColorSample.Brush.Style := bsSolid;
end;
end;
if ColorSample.Brush.Color <> ColorPalette.SelectedColor then
if ColorSample.Brush.Color <> ColorPalette.PickedColor then
begin
BtnEditColor.caption := 'Update >';
BtnEditColor.hint := 'Update palette';
SetColorInfo(LblColorInfo, 'New color', ColorPalette.SelectedIndex);
SetColorInfo(LblColorInfo, 'New color', ColorPalette.PickedIndex);
end;
end;
@ -363,8 +365,8 @@ begin
EdButtonDistance.Value := ColorPalette.ButtonDistance;
EdButtonSize.Value := ColorPalette.ButtonWidth;
ColorSample.Brush.Color := ColorPalette.SelectedColor;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.SelectedIndex);
ColorSample.Brush.Color := ColorPalette.PickedColor;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.PickedIndex);
UpdateCaption;
{ ColorPalette.PickShift must contain ssRight in order to be able to select
@ -407,14 +409,14 @@ end;
procedure TMainForm.UpdateCaption;
begin
Caption := Format('ColorPalette demo - CurIndex: %d (%d colors available)',
[ColorPalette.SelectedIndex, ColorPalette.ColorCount]
[ColorPalette.PickedIndex, ColorPalette.ColorCount]
);
end;
procedure TMainForm.UpdatePalette;
begin
ColorPalette.Colors[ColorPalette.SelectedIndex] := ColorSample.Brush.Color;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.SelectedIndex);
ColorPalette.Colors[ColorPalette.PickedIndex] := ColorSample.Brush.Color;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.PickedIndex);
with BtnEditColor do
begin
Caption := 'Edit';

View File

@ -2,10 +2,10 @@ object Form1: TForm1
Left = 290
Height = 491
Top = 160
Width = 584
Width = 639
Caption = 'Form1'
ClientHeight = 491
ClientWidth = 584
ClientWidth = 639
OnCreate = FormCreate
ShowHint = True
LCLVersion = '1.5'
@ -13,37 +13,30 @@ object Form1: TForm1
Left = 0
Height = 436
Top = 55
Width = 584
Width = 639
Align = alClient
Anchors = []
AutoSize = True
BevelOuter = bvNone
ClientHeight = 436
ClientWidth = 584
ClientWidth = 639
TabOrder = 0
object Shape1: TShape
Left = 56
Left = 64
Height = 120
Top = 40
Width = 146
Anchors = []
BorderSpacing.Around = 8
Brush.Style = bsClear
end
object Shape2: TShape
Left = 216
Left = 224
Height = 120
Top = 40
Width = 146
Anchors = []
BorderSpacing.Around = 8
end
object Label1: TLabel
Left = 56
Left = 64
Height = 56
Top = 176
Width = 146
Anchors = []
AutoSize = False
Caption = 'Gradient start'#13#10#13#10'(Left click)'
Font.Color = clWhite
@ -51,11 +44,10 @@ object Form1: TForm1
ParentFont = False
end
object Label2: TLabel
Left = 216
Left = 224
Height = 56
Top = 176
Width = 146
Anchors = []
AutoSize = False
Caption = 'Mouse color:'
Font.Color = clWhite
@ -63,20 +55,17 @@ object Form1: TForm1
ParentFont = False
end
object Shape3: TShape
Left = 376
Left = 384
Height = 120
Top = 40
Width = 146
Anchors = []
BorderSpacing.Around = 8
Brush.Style = bsClear
end
object Label3: TLabel
Left = 376
Left = 384
Height = 56
Top = 176
Width = 146
Anchors = []
AutoSize = False
Caption = 'Gradient end'#13#10#13#10'(Right click)'
Font.Color = clWhite
@ -88,9 +77,10 @@ object Form1: TForm1
Left = 0
Height = 55
Top = 0
Width = 584
Width = 639
Bands = <
item
Break = False
Control = ToolBar
MinHeight = 45
MinWidth = 45
@ -127,8 +117,7 @@ object Form1: TForm1
Flipped = True
GradientSteps = 1
PaletteKind = pkGradientPalette
PickShift = [ssLeft, ssRight]
SelectionColor = clWhite
PickedIndex = 0
SelectionKind = pskThickInverted
ShowColorHint = False
UseSpacers = False

View File

@ -49,50 +49,22 @@ implementation
{$R *.lfm}
{ TForm1 }
(*
procedure TForm1.ColorPalettePickColorColor(Sender: TObject; AColor: TColor;
AShift: TShiftState);
begin
if ColorPalette.SelectedColor = clNone then
Shape1.Brush.Style := bsClear
else
begin
Shape1.Brush.Style := bsSolid;
Shape1.Brush.Color := ColorPalette.SelectedColor;
end;
Label1.Caption := Format('Selected color:'#13'%s', [
ColorPalette.ColorNames[ColorPalette.SelectedIndex]
]);
inc(counter);
if odd(counter) then
FStartColor := Colorpalette.SelectedColor else
FEndColor := ColorPalette.SelectedColor;
Panel1.Invalidate;
end;
*)
procedure TForm1.FormCreate(Sender: TObject);
begin
// ColorPalette.InsertColor(0, clNone);
//ColorPalette.ColumnCount := 3; //ColorPalette.ColorCount div 3;
// ColorPalette.Vertical := true;
//ColorPalette.ColumnCount := 3;
ColorPalette.SelectedIndex := -1;
colorPalette.SelectedIndex := 0;
Toolbar.BorderSpacing.Left := 0;
Toolbar.AutoSize := true;
Coolbar.AutoSize := true;
ColorPaletteColorPick(self, ColorPalette.SelectedColor, [Classes.ssLeft]);
ColorPaletteColorPick(self, ColorPalette.Colors[ColorPalette.ColorCount-1], [Classes.ssRight]);
ColorPaletteColorPick(self, ColorPalette.Colors[0], [ssLeft]);
ColorPaletteColorPick(self, ColorPalette.Colors[ColorPalette.ColorCount-1], [ssRight]);
// For Laz 1.4.2 where TPanel.OnPaint is not published:
Panel1.OnPaint := @Panel1Paint;
end;
procedure TForm1.Panel1Paint(Sender: TObject);
begin
// Panel1.Canvas.GradientFill(Panel1.ClientRect, clSkyBlue, clNavy, gdVertical);
Panel1.Canvas.GradientFill(Panel1.ClientRect,
FStartColor,
FEndColor,
@ -106,6 +78,7 @@ var
begin
// Vertical orientation
CoolBar.AutoSize := false;
Toolbar.AutoSize := false;
if TbChangeOrientation.Down then
begin
CoolBar.Vertical := true;
@ -113,7 +86,8 @@ begin
ToolBar.Align := alLeft;
ColorPalette.Flipped := not ColorPalette.Flipped;
ColorPalette.Top := 9999;
end else
end
else
// Horizontal orientation
begin
CoolBar.Vertical := false;
@ -122,6 +96,7 @@ begin
ColorPalette.Flipped := not ColorPalette.Flipped;
ColorPalette.Left := 9999;
end;
Toolbar.AutoSize := true;
CoolBar.AutoSize := true;
end;
@ -137,7 +112,8 @@ end;
procedure TForm1.ColorPaletteColorPick(Sender: TObject; AColor: TColor;
Shift: TShiftState);
begin
if (Shift * [Classes.ssLeft] <> []) then
// Select gradient start color with left mouse button
if (Shift * [ssLeft] <> []) then
begin
FStartColor := AColor;
if FStartColor = clNone then
@ -151,7 +127,8 @@ begin
#13'(Left click)';
end;
if (Shift * [Classes.ssRight] <> []) then
// Select gradient end color with right mouse button
if (Shift * [ssRight] <> []) then
begin
FEndColor := AColor;
if FEndColor = clNone then