From 629356469ad027baefb0612da73a67b2dc156cce Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 18 Nov 2016 16:57:35 +0000 Subject: [PATCH] SpkToolbar: Add new property "HotTrackBrightnessChange" to Pane.Appearance. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5365 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../SpkGraphTools/SpkGraphTools.pas | 20 +-- .../spktoolbar/SpkToolbar/spkt_Appearance.pas | 118 +++++++++++------- .../spktoolbar/SpkToolbar/spkt_Pane.pas | 26 ++-- .../designtime/spkte_AppearanceEditor.lfm | 80 +++++++++--- .../designtime/spkte_AppearanceEditor.pas | 15 ++- 5 files changed, 170 insertions(+), 89 deletions(-) diff --git a/components/spktoolbar/SpkGraphTools/SpkGraphTools.pas b/components/spktoolbar/SpkGraphTools/SpkGraphTools.pas index 0fb6f09e4..3e0e8fe49 100644 --- a/components/spktoolbar/SpkGraphTools/SpkGraphTools.pas +++ b/components/spktoolbar/SpkGraphTools/SpkGraphTools.pas @@ -46,8 +46,8 @@ type TColorTools = class public class function Darken(AColor: TColor; APercentage: byte): TColor; - class function Brighten(AColor: TColor; APercentage: byte): TColor; - class function Shade(AColor1, AColor2: TColor; APercentage: byte): TColor; overload; + class function Brighten(AColor: TColor; APercentage: Integer): TColor; + class function Shade(AColor1, AColor2: TColor; APercentage: Integer): TColor; overload; class function Shade(AColor1, AColor2: TColor; AStep: extended): TColor; overload; class function AddColors(AColor1, AColor2: TColor): TColor; class function MultiplyColors(AColor1, AColor2: TColor): TColor; @@ -111,7 +111,7 @@ begin ); end; -class function TColorTools.Brighten(AColor: TColor; APercentage: byte): TColor; +class function TColorTools.Brighten(AColor: TColor; APercentage: Integer): TColor; var c: TRgbColor; p: Extended; @@ -119,14 +119,14 @@ begin c := TRgbColor(ColorToRGB(AColor)); p := APercentage/100; result := rgb( - round(c.R + (255-c.R)*p), - round(c.G + (255-c.G)*p), - round(c.B + (255-c.B)*p) + EnsureRange(round(c.R + (255-c.R)*p), 0, 255), + EnsureRange(round(c.G + (255-c.G)*p), 0, 255), + EnsureRange(round(c.B + (255-c.B)*p), 0, 255) ); end; class function TColorTools.Shade(AColor1, AColor2: TColor; - APercentage: byte): TColor; + APercentage: Integer): TColor; var c1, c2: TRgbColor; Step: Extended; // percentage as floating point number @@ -135,9 +135,9 @@ begin c2 := TRGBColor(ColorToRGB(AColor2)); Step := APercentage / 100; result := rgb( - round(c1.R + (c2.R - c1.R) * Step), - round(c1.G + (c2.G - c1.G) * Step), - round(c1.B + (c2.B - c1.B) * Step) + EnsureRange(round(c1.R + (c2.R - c1.R) * Step), 0, 255), + EnsureRange(round(c1.G + (c2.G - c1.G) * Step), 0, 255), + EnsureRange(round(c1.B + (c2.B - c1.B) * Step), 0, 255) ); end; diff --git a/components/spktoolbar/SpkToolbar/spkt_Appearance.pas b/components/spktoolbar/SpkToolbar/spkt_Appearance.pas index 3c354fb36..e075ea4b9 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Appearance.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Appearance.pas @@ -76,6 +76,7 @@ type TSpkPaneAppearance = class(TPersistent) FGradientFromColor: TColor; FGradientToColor: TColor; FGradientType: TBackgroundKind; + FHotTrackBrightnessChange: Integer; FStyle: TSpkPaneStyle; procedure SetCaptionBgColor(const Value: TColor); procedure SetCaptionFont(const Value: TFont); @@ -84,6 +85,7 @@ type TSpkPaneAppearance = class(TPersistent) procedure SetGradientFromColor(const Value: TColor); procedure SetGradientToColor(const Value: TColor); procedure SetGradientType(const Value: TBackgroundKind); + procedure SetHotTrackBrightnessChange(const Value: Integer); procedure SetStyle(const Value: TSpkPaneStyle); public constructor Create(ADispatch: TSpkBaseAppearanceDispatch); @@ -101,10 +103,11 @@ type TSpkPaneAppearance = class(TPersistent) property GradientFromColor: TColor read FGradientFromColor write SetGradientFromColor; property GradientToColor: TColor read FGradientToColor write SetGradientToColor; property GradientType: TBackgroundKind read FGradientType write SetGradientType; + property HotTrackBrightnessChange: Integer read FHotTrackBrightnessChange write SetHotTrackBrightnessChange default 20; property Style: TSpkPaneStyle read FStyle write SetStyle default psRectangleEtched; end; -type TSpkElementAppearance = class(TPersistent) + TSpkElementAppearance = class(TPersistent) private FDispatch: TSpkBaseAppearanceDispatch; FCaptionFont: TFont; @@ -460,32 +463,34 @@ end; procedure TSpkPaneAppearance.Assign(Source: TPersistent); var - SrcAppearance : TSpkPaneAppearance; + SrcAppearance: TSpkPaneAppearance; begin if Source is TSpkPaneAppearance then begin - SrcAppearance:=TSpkPaneAppearance(Source); + SrcAppearance := TSpkPaneAppearance(Source); - FCaptionFont.assign(SrcAppearance.CaptionFont); - FBorderDarkColor := SrcAppearance.BorderDarkColor; - FBorderLightColor := SrcAppearance.BorderLightColor; - FCaptionBgColor := SrcAppearance.CaptionBgColor; - FGradientFromColor := SrcAppearance.GradientFromColor; - FGradientToColor := SrcAppearance.GradientToColor; - FGradientType := SrcAppearance.GradientType; - FStyle := SrcAppearance.Style; + FCaptionFont.Assign(SrcAppearance.CaptionFont); + FBorderDarkColor := SrcAppearance.BorderDarkColor; + FBorderLightColor := SrcAppearance.BorderLightColor; + FCaptionBgColor := SrcAppearance.CaptionBgColor; + FGradientFromColor := SrcAppearance.GradientFromColor; + FGradientToColor := SrcAppearance.GradientToColor; + FGradientType := SrcAppearance.GradientType; + FHotTrackBrightnessChange := SrcAppearance.HotTrackBrightnessChange; + FStyle := SrcAppearance.Style; - if FDispatch<>nil then - FDispatch.NotifyAppearanceChanged; - end else - raise AssignException.create('TSpkPaneAppearance.Assign: Nie mogê przypisaæ obiektu '+Source.ClassName+' do TSpkPaneAppearance!'); + if FDispatch <> nil then + FDispatch.NotifyAppearanceChanged; + end else + raise AssignException.create('TSpkPaneAppearance.Assign: Nie mogê przypisaæ obiektu '+Source.ClassName+' do TSpkPaneAppearance!'); end; constructor TSpkPaneAppearance.Create(ADispatch: TSpkBaseAppearanceDispatch); begin inherited Create; - FDispatch:=ADispatch; - FCaptionFont:=TFont.Create; + FDispatch := ADispatch; + FCaptionFont := TFont.Create; + FHotTrackBrightnessChange := 20; FStyle := psRectangleEtched; Reset; end; @@ -528,9 +533,13 @@ begin FGradientToColor := Subnode.TextAsColor; Subnode := Node['GradientType', false]; - if assigned(Subnode) then + if Assigned(Subnode) then FGradientType := TBackgroundKind(Subnode.TextAsInteger); + Subnode := Node['HotTrackBrightnessChange', false]; + if Assigned(Subnode) then + FHotTrackBrightnessChange := Subnode.TextAsInteger; + Subnode := Node['Style', false]; if Assigned(Subnode) then FStyle := TSpkPaneStyle(SubNode.TextAsInteger); @@ -551,6 +560,7 @@ begin FGradientFromColor := rgb(222, 232, 245); FGradientToColor := rgb(199, 216, 237); FGradientType := bkConcave; + FHotTrackBrightnessChange := 20; FStyle := psRectangleEtched; end; @@ -564,6 +574,7 @@ begin FGradientFromColor := $00F8F8F8; FGradientToColor := $00E9E9E9; FGradientType := bkConcave; + FHotTrackBrightnessChange := 20; FStyle := psRectangleEtched; end; @@ -577,6 +588,7 @@ begin FGradientFromColor := $00F1F1F1; FGradientToColor := $00F1F1F1; FGradientType := bkSolid; + FHotTrackBrightnessChange := 0; FStyle := psDividerFlat; end; @@ -590,6 +602,7 @@ begin FGradientFromColor := $00464646; FGradientToColor := $00F1F1F1; FGradientType := bkSolid; + FHotTrackBrightnessChange := 0; FStyle := psDividerFlat; end; end; @@ -606,6 +619,7 @@ begin Add(' GradientFromColor := $' + IntToHex(FGradientFromColor, 8) + ';'); Add(' GradientToColor := $' + IntToHex(FGradientToColor, 8) + ';'); Add(' GradientType := ' + GetEnumName(TypeInfo(TBackgroundKind), ord(FGradientType)) + ';'); + Add(' HotTrackBrightnessChange = ' + IntToStr(FHotTrackBrightnessChange) + ';'); Add(' Style := ' + GetEnumName(TypeInfo(TSpkPaneStyle), ord(FStyle)) +';'); Add(' end;'); end; @@ -639,56 +653,66 @@ begin Subnode := Node['GradientType',true]; Subnode.TextAsInteger := integer(FGradientType); + Subnode := Node['HotTrackBrightnessChange',true]; + Subnode.TextAsInteger := FHotTrackBrightnessChange; + Subnode := Node['Style', true]; Subnode.TextAsInteger := integer(FStyle); end; procedure TSpkPaneAppearance.SetBorderDarkColor(const Value: TColor); begin -FBorderDarkColor:=Value; -if assigned(FDispatch) then - FDispatch.NotifyAppearanceChanged; + FBorderDarkColor := Value; + if Assigned(FDispatch) then + FDispatch.NotifyAppearanceChanged; end; procedure TSpkPaneAppearance.SetBorderLightColor(const Value: TColor); begin - FBorderLightColor:=Value; - if FDispatch<>nil then + FBorderLightColor := Value; + if FDispatch <> nil then FDispatch.NotifyAppearanceChanged; end; procedure TSpkPaneAppearance.SetCaptionBgColor(const Value: TColor); begin FCaptionBgColor := Value; - if FDispatch<>nil then - FDispatch.NotifyAppearanceChanged; -end; - -procedure TSpkPaneAppearance.SetGradientFromColor(const Value: TColor); -begin - FGradientFromColor:=Value; - if FDispatch<>nil then - FDispatch.NotifyAppearanceChanged; -end; - -procedure TSpkPaneAppearance.SetGradientToColor(const Value: TColor); -begin - FGradientToColor:=Value; - if FDispatch<>nil then - FDispatch.NotifyAppearanceChanged; -end; - -procedure TSpkPaneAppearance.SetGradientType(const Value: TBackgroundKind); -begin - FGradientType:=Value; - if FDispatch<>nil then + if FDispatch <> nil then FDispatch.NotifyAppearanceChanged; end; procedure TSpkPaneAppearance.SetCaptionFont(const Value: TFont); begin - FCaptionFont.assign(Value); - if FDispatch<>nil then + FCaptionFont.Assign(Value); + if FDispatch <> nil then + FDispatch.NotifyAppearanceChanged; +end; + +procedure TSpkPaneAppearance.SetGradientFromColor(const Value: TColor); +begin + FGradientFromColor := Value; + if FDispatch <> nil then + FDispatch.NotifyAppearanceChanged; +end; + +procedure TSpkPaneAppearance.SetGradientToColor(const Value: TColor); +begin + FGradientToColor := Value; + if FDispatch <> nil then + FDispatch.NotifyAppearanceChanged; +end; + +procedure TSpkPaneAppearance.SetGradientType(const Value: TBackgroundKind); +begin + FGradientType := Value; + if FDispatch <> nil then + FDispatch.NotifyAppearanceChanged; +end; + +procedure TSpkPaneAppearance.SetHotTrackBrightnessChange(const Value: Integer); +begin + FHotTrackBrightnessChange := Value; + if FDispatch <> nil then FDispatch.NotifyAppearanceChanged; end; diff --git a/components/spktoolbar/SpkToolbar/spkt_Pane.pas b/components/spktoolbar/SpkToolbar/spkt_Pane.pas index 1da0711a3..e4ce375a5 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Pane.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Pane.pas @@ -231,6 +231,7 @@ var FontColor, BorderLightColor, BorderDarkColor, c: TColor; i: Integer; R: T2DIntRect; + delta: Integer; begin // W niektórych warunkach nie jesteœmy w stanie rysowaæ: // * Brak dyspozytora @@ -243,21 +244,22 @@ begin if FPaneState = psIdle then begin // psIdle - BgFromColor:=FAppearance.Pane.GradientFromColor; - BgToColor:=FAppearance.Pane.GradientToColor; - CaptionColor:=FAppearance.Pane.CaptionBgColor; - FontColor:=FAppearance.Pane.CaptionFont.Color; - BorderLightColor:=FAppearance.Pane.BorderLightColor; - BorderDarkColor:=FAppearance.Pane.BorderDarkColor; + BgFromColor := FAppearance.Pane.GradientFromColor; + BgToColor := FAppearance.Pane.GradientToColor; + CaptionColor := FAppearance.Pane.CaptionBgColor; + FontColor := FAppearance.Pane.CaptionFont.Color; + BorderLightColor := FAppearance.Pane.BorderLightColor; + BorderDarkColor := FAppearance.Pane.BorderDarkColor; end else begin // psHover - BgFromColor:=TColorTools.Brighten(FAppearance.Pane.GradientFromColor,20); - BgToColor:=TColorTools.Brighten(FAppearance.Pane.GradientToColor,20); - CaptionColor:=TColorTools.Brighten(FAppearance.Pane.CaptionBgColor,20); - FontColor:=TColorTools.Brighten(FAppearance.Pane.CaptionFont.Color,20); - BorderLightColor:=TColorTools.Brighten(FAppearance.Pane.BorderLightColor,20); - BorderDarkColor:=TColorTools.Brighten(FAppearance.Pane.BorderDarkColor,20); + delta := FAppearance.Pane.HotTrackBrightnessChange; + BgFromColor := TColorTools.Brighten(FAppearance.Pane.GradientFromColor, delta); + BgToColor := TColorTools.Brighten(FAppearance.Pane.GradientToColor, delta); + CaptionColor := TColorTools.Brighten(FAppearance.Pane.CaptionBgColor, delta); + FontColor := TColorTools.Brighten(FAppearance.Pane.CaptionFont.Color, delta); + BorderLightColor := TColorTools.Brighten(FAppearance.Pane.BorderLightColor, delta); + BorderDarkColor := TColorTools.Brighten(FAppearance.Pane.BorderDarkColor, delta); end; // T³o diff --git a/components/spktoolbar/designtime/spkte_AppearanceEditor.lfm b/components/spktoolbar/designtime/spkte_AppearanceEditor.lfm index 01ca9b169..62b362a96 100644 --- a/components/spktoolbar/designtime/spkte_AppearanceEditor.lfm +++ b/components/spktoolbar/designtime/spkte_AppearanceEditor.lfm @@ -1,10 +1,10 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow - Left = 617 - Height = 544 - Top = 138 + Left = 554 + Height = 568 + Top = 248 Width = 558 Caption = 'Toolbar appearance editor' - ClientHeight = 544 + ClientHeight = 568 ClientWidth = 558 Color = clBtnFace Font.Color = clWindowText @@ -321,12 +321,12 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow end object PageControl1: TPageControl Left = 0 - Height = 371 + Height = 395 Top = 132 Width = 558 - ActivePage = TabSheet5 + ActivePage = TabSheet2 Align = alClient - TabIndex = 4 + TabIndex = 1 TabOrder = 1 object TabSheet1: TTabSheet Caption = 'Tab' @@ -697,7 +697,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow end object TabSheet2: TTabSheet Caption = 'Pane' - ClientHeight = 343 + ClientHeight = 367 ClientWidth = 550 ImageIndex = 1 object Label8: TLabel @@ -784,7 +784,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideRight.Side = asrBottom Left = 27 Height = 15 - Top = 266 + Top = 295 Width = 94 Anchors = [akTop, akRight] Caption = 'Pane caption font' @@ -928,7 +928,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideRight.Side = asrBottom Left = 141 Height = 25 - Top = 261 + Top = 290 Width = 127 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -940,13 +940,13 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow end object pPaneCaptionFontColor: TPanel AnchorSideLeft.Control = pPaneCaptionBackground - AnchorSideTop.Control = pPaneCaptionBackground + AnchorSideTop.Control = ePaneHotTrackBrightnessChange AnchorSideTop.Side = asrBottom AnchorSideRight.Control = pPaneCaptionBackground AnchorSideRight.Side = asrBottom Left = 141 Height = 25 - Top = 230 + Top = 259 Width = 100 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -978,7 +978,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideRight.Side = asrBottom Left = 141 Height = 23 - Top = 292 + Top = 321 Width = 127 Anchors = [akTop, akLeft, akRight] BorderSpacing.Top = 6 @@ -1004,7 +1004,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideRight.Side = asrBottom Left = 68 Height = 15 - Top = 296 + Top = 325 Width = 53 Anchors = [akTop, akRight] Caption = 'Pane style' @@ -1087,7 +1087,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideRight.Side = asrBottom Left = 49 Height = 15 - Top = 235 + Top = 264 Width = 72 Anchors = [akTop, akRight] BorderSpacing.Left = 12 @@ -1120,7 +1120,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow AnchorSideBottom.Side = asrBottom Left = 243 Height = 25 - Top = 230 + Top = 259 Width = 25 AllowAllUp = True BorderSpacing.Left = 2 @@ -1137,10 +1137,54 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow Width = 8 Shape = bsSpacer end + object Label15: TLabel + AnchorSideTop.Control = ePaneHotTrackBrightnessChange + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = LblPaneCaptionBackground + AnchorSideRight.Side = asrBottom + Left = 16 + Height = 30 + Top = 226 + Width = 105 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + Caption = 'HotTrack brightness'#13#10'change' + ParentColor = False + end + object ePaneHotTrackBrightnessChange: TSpinEdit + AnchorSideLeft.Control = pPaneCaptionBackground + AnchorSideTop.Control = pPaneCaptionBackground + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = pPaneCaptionBackground + AnchorSideRight.Side = asrBottom + Left = 141 + Height = 23 + Top = 230 + Width = 100 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 6 + MinValue = -100 + OnChange = ePaneHotTrackBrightnessChangeChange + TabOrder = 10 + end + object Label16: TLabel + AnchorSideLeft.Control = ePaneHotTrackBrightnessChange + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ePaneHotTrackBrightnessChange + AnchorSideTop.Side = asrCenter + Left = 247 + Height = 15 + Top = 234 + Width = 10 + BorderSpacing.Left = 6 + Caption = '%' + ParentColor = False + end end object TabSheet3: TTabSheet Caption = 'Item' - ClientHeight = 343 + ClientHeight = 367 ClientWidth = 550 ImageIndex = 2 object sItemRectangle: TShape @@ -2261,7 +2305,7 @@ object frmAppearanceEditWindow: TfrmAppearanceEditWindow object ButtonPanel: TPanel Left = 8 Height = 25 - Top = 511 + Top = 535 Width = 542 Align = alBottom AutoSize = True diff --git a/components/spktoolbar/designtime/spkte_AppearanceEditor.pas b/components/spktoolbar/designtime/spkte_AppearanceEditor.pas index 789116cbe..6687a3b98 100644 --- a/components/spktoolbar/designtime/spkte_AppearanceEditor.pas +++ b/components/spktoolbar/designtime/spkte_AppearanceEditor.pas @@ -6,7 +6,7 @@ interface uses LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons, + Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons, Spin, SpkGUITools, SpkXMLParser, spkt_Buttons, spkt_BaseItem, spkt_Pane, spkt_Types, spkt_Tab, SpkToolbar, spkt_Appearance; @@ -17,8 +17,11 @@ type TfrmAppearanceEditWindow = class(TForm) CbAppearanceStyle: TComboBox; + Label15: TLabel; + Label16: TLabel; PaneHSpacer: TBevel; ItemHSpacer: TBevel; + ePaneHotTrackBrightnessChange: TSpinEdit; TabVSpacer: TBevel; bInactiveTabHeaderFontColor: TSpeedButton; bItemActiveInnerDarkColor: TSpeedButton; @@ -211,7 +214,7 @@ type procedure cbLinkItemClick(Sender: TObject); procedure cbLinkPaneClick(Sender: TObject); procedure cbLinkTabClick(Sender: TObject); - + procedure ePaneHotTrackBrightnessChangeChange(Sender: TObject); procedure FormActivate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure FormCreate(Sender: TObject); @@ -805,6 +808,14 @@ begin Result := false; end; +procedure TfrmAppearanceEditWindow.ePaneHotTrackBrightnessChangeChange( + Sender: TObject); +begin + with tbPreview.Appearance.Pane do + HotTrackBrightnessChange := (Sender as TSpinEdit).Value; + tbPreview.Invalidate; +end; + procedure TfrmAppearanceEditWindow.FormActivate(Sender: TObject); var w, h: Integer;