Enhance too bright NULL colors for grids. Fixes issue #1584.

This commit is contained in:
Ansgar Becker
2010-01-13 22:44:00 +00:00
parent 24b675cb25
commit fcb62acc07
2 changed files with 19 additions and 16 deletions

View File

@@ -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;

View File

@@ -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;