From 86dd2650d129fd4f082cb8c5f49dcc4c66333138 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 29 Aug 2015 16:40:01 +0000 Subject: [PATCH] Colorpalette: Deprecate OnColorMouseMove git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4306 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/colorpalette/colorpalette.pas | 20 ++++---- .../colorpalette/demo/GeneralDemo/unit1.pas | 2 +- .../demo/ToolbarDemo/project1.lpi | 2 +- .../demo/ToolbarDemo/project1.lpr | 2 +- .../colorpalette/demo/ToolbarDemo/unit1.lfm | 5 +- .../colorpalette/demo/ToolbarDemo/unit1.pas | 46 +++++++++++++++---- 6 files changed, 53 insertions(+), 24 deletions(-) diff --git a/components/colorpalette/colorpalette.pas b/components/colorpalette/colorpalette.pas index 26e9f99b3..767aa6c48 100644 --- a/components/colorpalette/colorpalette.pas +++ b/components/colorpalette/colorpalette.pas @@ -135,8 +135,8 @@ type protected procedure BlendWBColor(AColor: TColor; Steps: Integer); - procedure ColorPick(AIndex: Integer; Shift: TShiftState); dynamic; - procedure ColorMouseMove(AColor: TColor; Shift: TShiftState); dynamic; + procedure ColorPick(AIndex: Integer; Shift: TShiftState); virtual; + procedure ColorMouseMove(AColor: TColor; Shift: TShiftState); virtual; procedure DoAddColor(AColor: TColor; AColorName: String = ''); virtual; procedure DoColorPick(AColor: TColor; AShift: TShiftState); virtual; procedure DoDeleteColor(AIndex: Integer); virtual; @@ -168,7 +168,7 @@ type property UseSpacers: Boolean read FUseSpacers write SetUseSpacers default true; property OnColorPick: TColorMouseEvent read FOnColorPick write FOnColorPick; - property OnColorMouseMove: TColorMouseEvent read FOnColorMouseMove write FOnColorMouseMove; + property OnColorMouseMove: TColorMouseEvent read FOnColorMouseMove write FOnColorMouseMove; deprecated 'Use OnMouseMove() and MouseColor'; property OnGetHintText: TColorPaletteHintEvent read FOnGetHintText write FOnGetHintText; public @@ -434,9 +434,9 @@ begin Result := -1; if FFlipped then begin - if (Y < 0) or (Y > FSizeToLastCol) then exit; + if (Y < 0) or (Y >= FSizeToLastCol-1) then exit; end else - if (X < 0) or (X > FSizeToLastCol) then exit; + if (X < 0) or (X >= FSizeToLastCol-1) then exit; W := GetCellWidth; H := GetCellHeight; @@ -702,15 +702,15 @@ begin inherited; Hint := FSavedHint; FMouseIndex := -1; - ColorMouseMove(MouseColor, []); + if Assigned(OnMouseMove) then + OnMouseMove(self, GetKeyShiftState, FMousePt.X, FMousePt.Y); +// ColorMouseMove(MouseColor, []); end; procedure TCustomColorPalette.MouseMove(Shift: TShiftState; X, Y: Integer); var C: TColor; begin - inherited; - FMouseIndex := GetColorIndex(X, Y); C := GetColors(FMouseIndex); ColorMouseMove(C, Shift); @@ -731,6 +731,8 @@ begin ColorPick(FMouseIndex, Shift); FPrevMouseIndex := FMouseIndex; + + inherited; end; procedure TCustomColorPalette.MouseUp(Button: TMouseButton; @@ -1296,7 +1298,7 @@ begin begin dec(dx); dec(dy); - d := -1; // Needed to correct for button frame line width + d := 0; end; if FFlipped then // Rows and columns are interchanged here !!! diff --git a/components/colorpalette/demo/GeneralDemo/unit1.pas b/components/colorpalette/demo/GeneralDemo/unit1.pas index 86890df1c..5631672ff 100644 --- a/components/colorpalette/demo/GeneralDemo/unit1.pas +++ b/components/colorpalette/demo/GeneralDemo/unit1.pas @@ -315,7 +315,7 @@ begin MousecolorSample.Brush.Color := Colorpalette.MouseColor; if MouseColorSample.Brush.Color = clNone then MouseColorSample.Brush.Style := bsClear else - MouseColorSample.Brush.Style := bsSolid; + MouseColorSample.Brush.Style := bsSolid; SetColorInfo(LblMouseColorInfo, 'Mouse color', ColorPalette.MouseIndex); end; diff --git a/components/colorpalette/demo/ToolbarDemo/project1.lpi b/components/colorpalette/demo/ToolbarDemo/project1.lpi index 42a8cd9bc..2e2692698 100644 --- a/components/colorpalette/demo/ToolbarDemo/project1.lpi +++ b/components/colorpalette/demo/ToolbarDemo/project1.lpi @@ -44,7 +44,7 @@ - + diff --git a/components/colorpalette/demo/ToolbarDemo/project1.lpr b/components/colorpalette/demo/ToolbarDemo/project1.lpr index 11c56ab39..6b4af373b 100644 --- a/components/colorpalette/demo/ToolbarDemo/project1.lpr +++ b/components/colorpalette/demo/ToolbarDemo/project1.lpr @@ -15,7 +15,7 @@ uses begin RequireDerivedFormResource:=True; Application.Initialize; - Application.CreateForm(TForm1, Form1); + Application.CreateForm(TMainForm, MainForm); Application.Run; end. diff --git a/components/colorpalette/demo/ToolbarDemo/unit1.lfm b/components/colorpalette/demo/ToolbarDemo/unit1.lfm index 360332c27..59f5a949e 100644 --- a/components/colorpalette/demo/ToolbarDemo/unit1.lfm +++ b/components/colorpalette/demo/ToolbarDemo/unit1.lfm @@ -1,9 +1,9 @@ -object Form1: TForm1 +object MainForm: TMainForm Left = 290 Height = 491 Top = 160 Width = 633 - Caption = 'Form1' + Caption = 'MainForm' ClientHeight = 491 ClientWidth = 633 OnCreate = FormCreate @@ -161,6 +161,7 @@ object Form1: TForm1 ParentColor = False ParentShowHint = False ShowHint = True + OnMouseMove = ColorPaletteMouseMove end end object ImageList: TImageList diff --git a/components/colorpalette/demo/ToolbarDemo/unit1.pas b/components/colorpalette/demo/ToolbarDemo/unit1.pas index f395e2736..0aca5cfa0 100644 --- a/components/colorpalette/demo/ToolbarDemo/unit1.pas +++ b/components/colorpalette/demo/ToolbarDemo/unit1.pas @@ -10,9 +10,9 @@ uses type - { TForm1 } + { TMainForm } - TForm1 = class(TForm) + TMainForm = class(TForm) ColorPalette: TColorPalette; CoolBar: TCoolBar; ImageList: TImageList; @@ -30,6 +30,8 @@ type Shift: TShiftState); procedure ColorPaletteColorPick(Sender: TObject; AColor: TColor; Shift: TShiftState); + procedure ColorPaletteMouseMove(Sender: TObject; Shift: TShiftState; X, + Y: Integer); procedure FormCreate(Sender: TObject); procedure MainPanelPaint(Sender: TObject); procedure TbChangeOrientationClick(Sender: TObject); @@ -42,21 +44,22 @@ type end; var - Form1: TForm1; + MainForm: TMainForm; implementation {$R *.lfm} -{ TForm1 } +{ TMainForm } { OnColorMouseMove is called when the mouse enters a different color button, or when the ColorPalette is left. } -procedure TForm1.ColorPaletteColorMouseMove(Sender: TObject; AColor: TColor; +procedure TMainForm.ColorPaletteColorMouseMove(Sender: TObject; AColor: TColor; Shift: TShiftState); var clrName: String; begin + (* if ColorPalette.MouseColor = clNone then Shape2.Brush.Style := bsClear else begin @@ -68,12 +71,13 @@ begin else clrName := ColorPalette.ColorNames[ColorPalette.MouseIndex]; LblMouseColor.Caption := 'Mouse color:'#13 + clrName; + *) end; { OnColorPick is called whenever a color button is clicked. A left-click defines the start color of the gradient of the main panel, a right-click defines its end color. } -procedure TForm1.ColorPaletteColorPick(Sender: TObject; AColor: TColor; +procedure TMainForm.ColorPaletteColorPick(Sender: TObject; AColor: TColor; Shift: TShiftState); begin // Select gradient start color with left mouse button @@ -124,7 +128,29 @@ begin MainPanel.Invalidate; end; -procedure TForm1.FormCreate(Sender: TObject); +procedure TMainForm.ColorPaletteMouseMove(Sender: TObject; Shift: TShiftState; + X, Y: Integer); +var + clrName: String; +begin + if ColorPalette.MouseColor = clNone then + begin + Shape2.Brush.Style := bsClear; + Shape2.Pen.Style := psDot; + end else + begin + Shape2.Brush.Style := bsSolid; + Shape2.Brush.Color := ColorPalette.MouseColor; + Shape2.Pen.Style := psSolid; + end; + if ColorPalette.MouseIndex = -1 then + clrName := 'clNone' + else + clrName := ColorPalette.ColorNames[ColorPalette.MouseIndex]; + LblMouseColor.Caption := 'Mouse color:'#13 + clrName; +end; + +procedure TMainForm.FormCreate(Sender: TObject); begin Toolbar.BorderSpacing.Left := 0; Toolbar.AutoSize := true; @@ -133,7 +159,7 @@ begin // Paint the three color boxes ColorPaletteColorPick(self, ColorPalette.Colors[0], [ssLeft]); ColorPaletteColorPick(self, ColorPalette.Colors[ColorPalette.ColorCount-1], [ssRight]); - ColorPaletteColorMouseMove(self, ColorPalette.MouseColor, []); + ColorPaletteMouseMove(self, [], 0, 0); // For Laz 1.4.2 where TPanel.OnPaint is not published: MainPanel.OnPaint := @MainPanelPaint; @@ -142,7 +168,7 @@ end; { Paints a color gradient onto the main panel of the form. The gradient is defined by the FStartColor and FEndColor obtained by clicks into the ColorPalette. } -procedure TForm1.MainPanelPaint(Sender: TObject); +procedure TMainForm.MainPanelPaint(Sender: TObject); begin MainPanel.Canvas.GradientFill(MainPanel.ClientRect, FStartColor, @@ -152,7 +178,7 @@ begin end; { Fires when the "Flip" button is clicked } -procedure TForm1.TbChangeOrientationClick(Sender: TObject); +procedure TMainForm.TbChangeOrientationClick(Sender: TObject); var i: Integer; begin