ColorPalette: Replace ShowSelection by SelectionKind. Add property SelectionColor.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4293 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-08-25 12:12:26 +00:00
parent 68424fab94
commit fc29a13688
3 changed files with 183 additions and 92 deletions

View File

@ -65,6 +65,8 @@ type
pkStandardAndSystemPalette, pkExtendedAndSystemPalette,
pkGradientPalette, pkHTMLPalette, pkWebSafePalette);
TPaletteSelectionKind = (pskNone, pskThin, pskThinInverted, pskThick, pskThickInverted);
TColorMouseEvent = procedure (Sender: TObject; AColor: TColor; Shift: TShiftState) of object;
TColorPaletteEvent = procedure (Sender: TObject; AColor: TColor) of object;
@ -94,7 +96,8 @@ type
FPrevMouseIndex: Integer;
FStoredShift: TShiftState;
FShowColorHint: Boolean;
FShowSelection: Boolean;
FSelectionColor: TColor;
FSelectionKind: TPaletteSelectionKind;
FSavedHint: String;
FPaletteKind: TPaletteKind;
FGradientSteps: Byte;
@ -115,7 +118,8 @@ type
procedure SetGradientSteps(AValue: Byte);
procedure SetPaletteKind(AValue: TPaletteKind);
procedure SetSelectedIndex(AValue: Integer);
procedure SetShowSelection(AValue: Boolean);
procedure SetSelectionColor(AValue: TColor);
procedure SetSelectionKind(AValue: TPaletteSelectionKind);
procedure SetUseSpacers(AValue: Boolean);
protected
@ -137,6 +141,7 @@ type
procedure MouseMove(Shift:TShiftState; X, Y:Integer); override;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X, Y:Integer); override;
procedure UpdateSize; virtual;
property ButtonBorderColor: TColor read FButtonBorderColor write SetButtonBorderColor default clBlack;
property ButtonDistance: Integer read FButtonDistance write SetButtonDistance default 0;
property ButtonWidth: Integer read FButtonWidth write SetButtonWidth;
@ -147,8 +152,9 @@ type
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 ShowSelection: Boolean read FShowSelection write SetShowSelection default false;
property UseSpacers: Boolean read FUseSpacers write SetUseSpacers default true;
property OnGetHintText: TColorPaletteHintEvent read FOnGetHintText write FOnGetHintText;
@ -192,8 +198,9 @@ type
property PickMode;
property PickShift;
property SelectedIndex;
property SelectionColor;
property SelectionKind;
property ShowColorHint;
property ShowSelection;
property UseSpacers;
property OnColorMouseMove;
@ -737,12 +744,31 @@ begin
end;
// Paint selection
if FShowSelection then
if FSelectionKind <> pskNone then
begin
Canvas.Pen.Color := InvertColor(GetColors(FSelectedIndex));
Canvas.Pen.Width := 3;
Canvas.Pen.Style := psSolid;
Canvas.Brush.Style := bsClear;
Canvas.Pen.Style := psSolid;
case FSelectionKind of
pskThin, pskThinInverted :
begin
Canvas.Pen.Width := 1;
if FButtonDistance > 2 then InflateRect(Rsel, 2, 2);
end;
pskThick, pskThickInverted:
begin
Canvas.Pen.Width := 3;
end;
end;
case FSelectionKind of
pskThin, pskThick:
Canvas.Pen.Color := FSelectionColor;
pskThinInverted, pskThickInverted:
begin
Canvas.Pen.Color := InvertColor(GetColors(FSelectedIndex));
if (FSelectionKind = pskThinInverted) and (Canvas.Pen.Color = FButtonBorderColor) then
Canvas.Pen.Color := FSelectionColor;
end;
end;
Canvas.Rectangle(Rsel);
end;
end;
@ -781,6 +807,7 @@ procedure TCustomColorPalette.SetButtonBorderColor(const AValue: TColor);
begin
if FButtonBorderColor = AValue then exit;
FButtonBorderColor := AValue;
UpdateSize;
Invalidate;
end;
@ -788,9 +815,6 @@ procedure TCustomColorPalette.SetButtonDistance(const AValue: Integer);
begin
if FButtonDistance = AValue then exit;
FButtonDistance := AValue;
if FButtonDistance = 0 then
FMargin := 1 else
FMargin := FButtonDistance div 2 + FButtonDistance mod 2;
UpdateSize;
Invalidate;
end;
@ -1267,10 +1291,18 @@ begin
DoSelectColor(GetColors(FSelectedIndex));
end;
procedure TCustomColorPalette.SetShowSelection(AValue: Boolean);
procedure TCustomColorPalette.SetSelectionColor(AValue: TColor);
begin
if FShowSelection = AValue then exit;
FShowSelection := AValue;
if FSelectionColor = AValue then exit;
FSelectionColor := AValue;
Invalidate;
end;
procedure TCustomColorPalette.SetSelectionKind(AValue: TPaletteSelectionKind);
begin
if FSelectionKind = AValue then exit;
FSelectionKind := AValue;
UpdateSize;
Invalidate;
end;
@ -1289,6 +1321,10 @@ begin
FRows := 0 else
FRows := Ceil(FColors.Count / FCols);
if FButtonDistance = 0 then
FMargin := 1 else
FMargin := FButtonDistance div 2 + FButtonDistance mod 2;
dx := GetCellWidth;
dy := GetCellHeight;
d := FButtonDistance;

View File

@ -1,22 +1,22 @@
object MainForm: TMainForm
Left = 394
Height = 551
Height = 555
Top = 287
Width = 625
Caption = 'MainForm'
ClientHeight = 551
ClientHeight = 555
ClientWidth = 625
OnCreate = FormCreate
ShowHint = True
LCLVersion = '1.5'
object Panel1: TPanel
object LeftPanel: TPanel
Left = 0
Height = 551
Height = 555
Top = 0
Width = 160
Align = alLeft
BevelOuter = bvNone
ClientHeight = 551
ClientHeight = 555
ClientWidth = 160
TabOrder = 0
object ColorSample: TShape
@ -108,6 +108,7 @@ object MainForm: TMainForm
Width = 116
Caption = 'Built-in gradient steps'
Enabled = False
FocusControl = EdGradientSteps
ParentColor = False
end
object EdGradientSteps: TSpinEdit
@ -123,12 +124,13 @@ object MainForm: TMainForm
TabOrder = 7
Value = 3
end
object LblPickMode2: TLabel
object LblBuiltinPalettes: TLabel
Left = 10
Height = 15
Top = 224
Width = 83
Caption = 'Built-in palettes'
FocusControl = CbBuiltinPalettes
ParentColor = False
end
object CbBuiltinPalettes: TComboBox
@ -177,7 +179,7 @@ object MainForm: TMainForm
end
object Bevel1: TBevel
Left = 160
Height = 535
Height = 539
Top = 8
Width = 3
Align = alLeft
@ -185,28 +187,29 @@ object MainForm: TMainForm
BorderSpacing.Bottom = 8
Shape = bsLeftLine
end
object Panel2: TPanel
object RightPanel: TPanel
Left = 465
Height = 551
Height = 555
Top = 0
Width = 160
Align = alRight
BevelOuter = bvNone
ClientHeight = 551
ClientHeight = 555
ClientWidth = 160
TabOrder = 1
object Label3: TLabel
object LblButtonDistance: TLabel
Left = 83
Height = 15
Top = 276
Top = 358
Width = 65
Caption = 'Btn distance'
FocusControl = EdButtonDistance
ParentColor = False
end
object EdButtonDistance: TSpinEdit
Left = 83
Height = 23
Top = 296
Top = 378
Width = 58
Alignment = taRightJustify
MaxValue = 16
@ -214,29 +217,30 @@ object MainForm: TMainForm
TabOrder = 0
Value = 1
end
object Label4: TLabel
object LblButtonSize: TLabel
Left = 10
Height = 15
Top = 276
Top = 358
Width = 40
Caption = 'Btn size'
FocusControl = EdButtonSize
ParentColor = False
end
object EdBoxSize: TSpinEdit
object EdButtonSize: TSpinEdit
Left = 10
Height = 23
Top = 296
Top = 378
Width = 59
Alignment = taRightJustify
MinValue = 1
OnChange = EdBoxSizeChange
OnChange = EdButtonSizeChange
TabOrder = 1
Value = 16
end
object LblButtonBorderColor: TLabel
Left = 10
Height = 15
Top = 176
Top = 258
Width = 89
Caption = 'Btn border color:'
FocusControl = CbButtonBorderColor
@ -245,7 +249,7 @@ object MainForm: TMainForm
object CbButtonBorderColor: TColorBox
Left = 10
Height = 22
Top = 196
Top = 278
Width = 138
NoneColorColor = clWindow
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
@ -277,91 +281,133 @@ object MainForm: TMainForm
Top = 13
Width = 56
Caption = 'Pick mode'
FocusControl = CbPickMode
ParentColor = False
end
object CbShowSelection: TCheckBox
Left = 10
Height = 19
Top = 73
Width = 99
Caption = 'Show selection'
OnChange = CbShowSelectionChange
TabOrder = 4
end
object CbShowColorHints: TCheckBox
Left = 10
Height = 19
Top = 94
Top = 176
Width = 108
Caption = 'Show color hints'
Checked = True
OnChange = CbShowColorHintsChange
State = cbChecked
TabOrder = 5
TabOrder = 4
end
object EdColCount: TSpinEdit
Left = 10
Height = 23
Top = 352
Top = 428
Width = 59
Alignment = taRightJustify
MinValue = 1
OnChange = EdColCountChange
TabOrder = 6
TabOrder = 5
Value = 8
end
object Label2: TLabel
object LblColCount: TLabel
Left = 10
Height = 15
Top = 332
Top = 408
Width = 48
Caption = 'Columns'
FocusControl = EdColCount
ParentColor = False
end
object CbCustomHintText: TCheckBox
Left = 10
Height = 19
Top = 117
Top = 199
Width = 108
Caption = 'Custom hint text'
OnChange = CbCustomHintTextChange
TabOrder = 7
TabOrder = 6
end
object CbUseSpacers: TCheckBox
Left = 10
Height = 19
Top = 142
Top = 224
Width = 131
Caption = 'Use clNone as spacer'
Checked = True
OnChange = CbUseSpacersChange
State = cbChecked
TabOrder = 8
TabOrder = 7
end
object LblButtonBorderColor1: TLabel
object LblBkColor: TLabel
Left = 10
Height = 15
Top = 224
Top = 306
Width = 94
Caption = 'Background color'
FocusControl = CbColor
FocusControl = CbBkColor
ParentColor = False
end
object CbColor: TColorBox
object CbBkColor: TColorBox
Left = 10
Height = 22
Top = 244
Top = 326
Width = 138
NoneColorColor = clWindow
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
ItemHeight = 16
OnSelect = CbColorSelect
OnSelect = CbBkColorSelect
TabOrder = 8
end
object LblSelKind: TLabel
Left = 10
Height = 15
Top = 67
Width = 74
Caption = 'Selection kind'
FocusControl = CbSelKind
ParentColor = False
end
object CbSelKind: TComboBox
Left = 10
Height = 23
Hint = 'Defines when the picked color is determined and when the OnPickColor event is generated:'#13#10#13#10'pmDefault: '#13#10' Color selection at mouse-down, OnPickColor event at mouse-up if at same location'#13#10#13#10'pmImmediate:'#13#10' Color selection and OnPickColor event at mouse-down'#13#10#13#10'pmContinuous:'#13#10' Color selection and OnPickColor event while mouse is down'
Top = 87
Width = 137
ItemHeight = 15
ItemIndex = 0
Items.Strings = (
'none'
'thin'
'thin (inverted color)'
'thick'
'thick (inverted color)'
)
OnSelect = CbSelKindSelect
Style = csDropDownList
TabOrder = 9
Text = 'none'
end
object LblSelColor: TLabel
Left = 10
Height = 15
Top = 119
Width = 119
Caption = 'Color of selection rect:'
FocusControl = CbSelColor
ParentColor = False
end
object CbSelColor: TColorBox
Left = 9
Height = 22
Top = 139
Width = 138
NoneColorColor = clWindow
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeNone]
ItemHeight = 16
OnSelect = CbSelColorSelect
TabOrder = 10
end
end
object Bevel2: TBevel
Left = 462
Height = 535
Height = 539
Top = 8
Width = 3
Align = alRight
@ -369,9 +415,9 @@ object MainForm: TMainForm
BorderSpacing.Bottom = 8
Shape = bsLeftLine
end
object ScrollBox1: TScrollBox
object ScrollBox: TScrollBox
Left = 168
Height = 535
Height = 539
Top = 8
Width = 287
HorzScrollBar.Increment = 15
@ -384,7 +430,7 @@ object MainForm: TMainForm
VertScrollBar.Tracking = True
Anchors = [akTop, akLeft, akRight, akBottom]
BorderStyle = bsNone
ClientHeight = 535
ClientHeight = 539
ClientWidth = 287
TabOrder = 2
object ColorPalette: TColorPalette
@ -396,7 +442,7 @@ object MainForm: TMainForm
ButtonHeight = 20
ButtonWidth = 20
ColumnCount = 8
PickShift = [ssLeft, ssMiddle]
PickShift = [ssLeft, ssRight]
OnGetHintText = ColorPaletteGetHintText
OnSelectColor = ColorPaletteSelectColor
ParentColor = False

View File

@ -23,8 +23,9 @@ type
BtnLoadDefaultPal: TButton;
BtnEditColor: TButton;
CbBuiltinPalettes: TComboBox;
CbColor: TColorBox;
CbShowSelection: TCheckBox;
CbSelColor: TColorBox;
CbBkColor: TColorBox;
CbSelKind: TComboBox;
CbShowColorHints: TCheckBox;
CbButtonBorderColor: TColorBox;
CbCustomHintText: TCheckBox;
@ -32,30 +33,32 @@ type
ColorDialog: TColorDialog;
ColorPalette: TColorPalette;
CbPickMode: TComboBox;
LblButtonBorderColor1: TLabel;
LblBkColor: TLabel;
LblSelColor: TLabel;
LblSelKind: TLabel;
MouseColorSample: TShape;
EdButtonDistance: TSpinEdit;
EdBoxSize: TSpinEdit;
EdButtonSize: TSpinEdit;
EdGradientSteps: TSpinEdit;
Label3: TLabel;
Label4: TLabel;
LblButtonDistance: TLabel;
LblButtonSize: TLabel;
LblMouseColorInfo: TLabel;
LblGradientSteps: TLabel;
LblPickMode: TLabel;
EdColCount: TSpinEdit;
Label2: TLabel;
LblColCount: TLabel;
LblColorInfo: TLabel;
LblButtonBorderColor: TLabel;
LblPickMode2: TLabel;
LblBuiltinPalettes: TLabel;
MnuEditPickedColor: TMenuItem;
MnuDeletePickedColor: TMenuItem;
OpenDialog: TOpenDialog;
PalettePopupMenu: TPopupMenu;
Panel1: TPanel;
Panel2: TPanel;
LeftPanel: TPanel;
RightPanel: TPanel;
SaveDialog: TSaveDialog;
ColorSample: TShape;
ScrollBox1: TScrollBox;
ScrollBox: TScrollBox;
procedure BtnAddColorClick(Sender: TObject);
procedure BtnCreateRndPaletteClick(Sender: TObject);
procedure BtnDeleteColorClick(Sender: TObject);
@ -63,11 +66,12 @@ type
procedure BtnLoadDefaultPalClick(Sender: TObject);
procedure BtnLoadRndPaletteClick(Sender: TObject);
procedure CbBuiltinPalettesSelect(Sender: TObject);
procedure CbColorSelect(Sender: TObject);
procedure CbBkColorSelect(Sender: TObject);
procedure CbCustomHintTextChange(Sender: TObject);
procedure CbPickModeSelect(Sender: TObject);
procedure CbSelColorSelect(Sender: TObject);
procedure CbSelKindSelect(Sender: TObject);
procedure CbShowColorHintsChange(Sender: TObject);
procedure CbShowSelectionChange(Sender: TObject);
procedure CbButtonBorderColorSelect(Sender: TObject);
procedure CbUseSpacersChange(Sender: TObject);
procedure ColorPaletteDblClick(Sender: TObject);
@ -79,7 +83,7 @@ type
Y: Integer);
procedure ColorPaletteSelectColor(Sender: TObject; AColor: TColor);
procedure EdButtonDistanceChange(Sender: TObject);
procedure EdBoxSizeChange(Sender: TObject);
procedure EdButtonSizeChange(Sender: TObject);
procedure EdColCountChange(Sender: TObject);
procedure EdGradientStepsChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
@ -201,9 +205,9 @@ begin
LblGradientSteps.Enabled := EdGradientSteps.Enabled;
end;
procedure TMainForm.CbColorSelect(Sender: TObject);
procedure TMainForm.CbBkColorSelect(Sender: TObject);
begin
ColorPalette.Color := CbColor.Selected;
ColorPalette.Color := CbBkColor.Selected;
end;
procedure TMainForm.CbCustomHintTextChange(Sender: TObject);
@ -219,16 +223,21 @@ begin
ColorPalette.PickMode := TPickMode(CbPickMode.ItemIndex);
end;
procedure TMainForm.CbSelColorSelect(Sender: TObject);
begin
ColorPalette.SelectionColor := CbSelColor.Selected;
end;
procedure TMainForm.CbSelKindSelect(Sender: TObject);
begin
ColorPalette.SelectionKind := TPaletteSelectionKind(CbSelKind.ItemIndex);
end;
procedure TMainForm.CbShowColorHintsChange(Sender: TObject);
begin
ColorPalette.ShowColorHint := CbShowColorHints.Checked;
end;
procedure TMainForm.CbShowSelectionChange(Sender: TObject);
begin
ColorPalette.ShowSelection := CbShowSelection.Checked;
end;
procedure TMainForm.CbUseSpacersChange(Sender: TObject);
begin
ColorPalette.UseSpacers := CbUseSpacers.Checked;
@ -300,10 +309,10 @@ begin
ColorPalette.ButtonDistance := EdButtonDistance.Value;
end;
procedure TMainForm.EdBoxSizeChange(Sender: TObject);
procedure TMainForm.EdButtonSizeChange(Sender: TObject);
begin
ColorPalette.ButtonWidth := EdBoxSize.Value;
ColorPalette.ButtonHeight := EdBoxSize.Value;
ColorPalette.ButtonWidth := EdButtonSize.Value;
ColorPalette.ButtonHeight := EdButtonSize.Value;
end;
procedure TMainForm.EdColCountChange(Sender: TObject);
@ -340,12 +349,12 @@ begin
EdColCount.Value := ColorPalette.ColumnCount;
EdGradientSteps.Value := ColorPalette.GradientSteps;
CbPickMode.ItemIndex := ord(ColorPalette.PickMode);
CbShowSelection.Checked := ColorPalette.ShowSelection;
CbSelKind.ItemIndex := ord(ColorPalette.SelectionKind);
CbShowColorHints.Checked := ColorPalette.ShowColorHint;
CbButtonBorderColor.Selected := ColorPalette.ButtonBorderColor;
CbColor.Selected := ColorPalette.Color;
CbBkColor.Selected := ColorPalette.Color;
EdButtonDistance.Value := ColorPalette.ButtonDistance;
EdBoxSize.Value := ColorPalette.ButtonWidth;
EdButtonSize.Value := ColorPalette.ButtonWidth;
ColorSample.Brush.Color := ColorPalette.SelectedColor;
SetColorInfo(LblColorInfo, 'Current', ColorPalette.SelectedIndex);
@ -353,7 +362,7 @@ begin
{ ColorPalette.PickShift must contain ssRight in order to be able to select
colors for the context menu. Use object inspector, or use this code: }
ColorPalette.PickShift := [ssLeft, ssRight];
//ColorPalette.PickShift := [ssLeft, ssRight];
ColorPalette.OnGetHintText := nil; // will be activated by CbCustomHintText
end;