From fcb62acc07d267b2b6f298b388323f6a5285c06d Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 13 Jan 2010 22:44:00 +0000 Subject: [PATCH] Enhance too bright NULL colors for grids. Fixes issue #1584. --- source/helpers.pas | 20 +++++++++----------- source/main.pas | 15 ++++++++++----- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/source/helpers.pas b/source/helpers.pas index aa317f51..34ad04cd 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -215,7 +215,7 @@ type function BinToWideHex(bin: AnsiString): String; procedure CheckHex(text: String; errorMessage: string); procedure FixVT(VT: TVirtualStringTree); - function ColorAdjustBrightness(Col: TColor; Shift: SmallInt; BestFit: Boolean): TColor; + function ColorAdjustBrightness(Col: TColor; Shift: SmallInt): TColor; function ComposeOrderClause(Cols: TOrderColArray): String; procedure OpenRegistry(Session: String = ''); function GetRegValue( valueName: String; defaultValue: Integer; Session: String = '' ) : Integer; Overload; @@ -2518,19 +2518,17 @@ begin end; -function ColorAdjustBrightness(Col: TColor; Shift: SmallInt; BestFit: Boolean): TColor; +function ColorAdjustBrightness(Col: TColor; Shift: SmallInt): TColor; var Lightness: Byte; begin - if BestFit then begin - // If base color is bright, make bg color darker (grey), and vice versa, so that - // colors work with high contrast mode for accessibility - Lightness := GetLightness(Col); - if (Lightness < 128) and (Shift < 0) then - Shift := Abs(Shift) - else if (Lightness > 128) and (Shift > 0) then - Shift := 0 - Abs(Shift); - end; + // If base color is bright, make bg color darker (grey), and vice versa, so that + // colors work with high contrast mode for accessibility + Lightness := GetLightness(Col); + if (Lightness < 128) and (Shift < 0) then + Shift := Abs(Shift) + else if (Lightness > 128) and (Shift > 0) then + Shift := 0 - Abs(Shift); Result := ColorAdjustLuma(Col, Shift, true); end; diff --git a/source/main.pas b/source/main.pas index da6a5629..0a3a8939 100644 --- a/source/main.pas +++ b/source/main.pas @@ -10,7 +10,7 @@ unit Main; interface uses - Windows, SysUtils, Classes, Graphics, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons, + Windows, SysUtils, Classes, Graphics, GraphUtil, Forms, Controls, Menus, StdCtrls, Dialogs, Buttons, Messages, ExtCtrls, ComCtrls, StdActns, ActnList, ImgList, ToolWin, Clipbrd, SynMemo, SynEdit, SynEditTypes, SynEditKeyCmds, VirtualTrees, DateUtils, PngImageList, Widestrings, ShlObj, SynEditMiscClasses, SynEditSearch, SynCompletionProposal, SynEditHighlighter, @@ -3218,7 +3218,7 @@ begin // Sorting color and title image for k:=0 to Length(FDataGridSort)-1 do begin if FDataGridSort[k].ColumnName = Column.Name then begin - col.Color := ColorAdjustBrightness(col.Color, COLORSHIFT_SORTCOLUMNS, True); + col.Color := ColorAdjustBrightness(col.Color, COLORSHIFT_SORTCOLUMNS); case FDataGridSort[k].SortDirection of ORDER_ASC: col.ImageIndex := 109; ORDER_DESC: col.ImageIndex := 110; @@ -5284,7 +5284,7 @@ begin for i:=0 to h.Columns.Count-1 do begin NewColor := clWindow; if h.SortColumn = i then - NewColor := ColorAdjustBrightness(NewColor, COLORSHIFT_SORTCOLUMNS, True); + NewColor := ColorAdjustBrightness(NewColor, COLORSHIFT_SORTCOLUMNS); h.Columns[i].Color := NewColor; end; end; @@ -6492,9 +6492,14 @@ end; procedure TMainForm.CalcNullColors; var i: Integer; + h, l, s: Word; begin - for i:=Low(DatatypeCategories) to High(DatatypeCategories) do - DatatypeCategories[i].NullColor := ColorAdjustBrightness(DatatypeCategories[i].Color, COLORSHIFT_NULLFIELDS, False); + for i:=Low(DatatypeCategories) to High(DatatypeCategories) do begin + ColorRGBToHLS(DatatypeCategories[i].Color, h, l, s); + Inc(l, COLORSHIFT_NULLFIELDS); + s := Max(0, s-2*COLORSHIFT_NULLFIELDS); + DatatypeCategories[i].NullColor := ColorHLSToRGB(h, l, s); + end; end;