CustomDrawn: Implements the grayed state for checkboxes

git-svn-id: trunk@36176 -
This commit is contained in:
sekelsenmat 2012-03-20 11:52:13 +00:00
parent b48cf43d34
commit a67c0254f9
4 changed files with 93 additions and 19 deletions

View File

@ -21,6 +21,8 @@ type
TCDDrawerAndroid = class(TCDDrawerCommon) TCDDrawerAndroid = class(TCDDrawerCommon)
private private
bmpCheckbox, bmpCheckboxChecked: TBitmap; bmpCheckbox, bmpCheckboxChecked: TBitmap;
// Alternative checkbox drawing, not currently utilized
procedure DrawCheckBoxBitmap;
// Draws a line alternating between two colors // Draws a line alternating between two colors
procedure DrawAndroidAlternatedHorzLine(ADest: TCanvas; X1, X2, procedure DrawAndroidAlternatedHorzLine(ADest: TCanvas; X1, X2,
Y: Integer; AColor1, AColor2: TColor); Y: Integer; AColor1, AColor2: TColor);
@ -50,7 +52,7 @@ type
procedure DrawRaisedFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawRaisedFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;} procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;}
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override; procedure DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState); override;
{procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override; {procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;} procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;}
// =================================== // ===================================
@ -120,6 +122,28 @@ const
ANDROID_BUTTON_SUNKEN_LAST_LINE_A = $0000D300; ANDROID_BUTTON_SUNKEN_LAST_LINE_A = $0000D300;
ANDROID_BUTTON_SUNKEN_LAST_LINE_B = $0000D700; ANDROID_BUTTON_SUNKEN_LAST_LINE_B = $0000D700;
// Checkbox
var
ANDROID_CHECKBOX_A: array[0..29] of TColor =
($F5F5F5, $EBF0EC, $EBF0EC, $EBEBEB, $EBEBEB,
$E1E6E2, $EBE6EA, $E1E1E1, $E1E1E1, $D6D0D7,
$E1DDE0, $CDCECD, $D6D3D5, $CDCECD, $CDCECD,
$C3C4C3, $CCC9CC, $C3C0C2, $C3C4C3, $BABFBB,
$C3C0C2, $BABFBB, $BABBBA, $AFB0AF, $AFACAF,
$AFACAF, $AFACAF, $AFB0AF, $BABDBA, $C3C4C3);
ANDROID_CHECKBOX_B: array[0..29] of TColor =
($EBF0EC, $F5F0F4, $EBEBEB, $EBE6EA, $E1E6E2,
$EBE6EA, $E1E1E1, $D6DCD7, $D6DCD7, $D6DCD7,
$D6D7D6, $D5D3D6, $CDCECD, $CCC9CC, $C3C4C3,
$C3C4C3, $C3C0C2, $C3C0C2, $BABFBB, $BABBBA,
$BABBBA, $B9B6B9, $AFB6B1, $AFB0AF, $AFB0AF,
$AFB0AF, $AFB0AF, $AFB0AF, $BABDBA, $CCC9CC);
const
ANDROID_CHECKBOX_CORNER_DARK_GRAY = $585A58;
ANDROID_CHECKBOX_CORNER_GRAY = $8A8C8A;
{procedure TCDButtonDrawerAndroid.DrawToIntfImage(ADest: TFPImageCanvas; {procedure TCDButtonDrawerAndroid.DrawToIntfImage(ADest: TFPImageCanvas;
CDButton: TCDButton); CDButton: TCDButton);
begin begin
@ -167,6 +191,47 @@ initialization
{ TCDDrawerAndroid } { TCDDrawerAndroid }
procedure TCDDrawerAndroid.DrawCheckBoxBitmap;
var
lDest: TCanvas;
i: Integer;
begin
lDest := bmpCheckbox.Canvas;
// Background
for i := 0 to 29 do
DrawAndroidAlternatedHorzLine(lDest, 0, 31, i, ANDROID_CHECKBOX_A[i], ANDROID_CHECKBOX_B[i]);
// Corners
lDest.Pixels[0, 0] := clBlack;
lDest.Pixels[1, 0] := clBlack;
lDest.Pixels[0, 1] := clBlack;
lDest.Pixels[0, 2] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[2, 0] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[1, 1] := ANDROID_CHECKBOX_CORNER_GRAY;
//
lDest.Pixels[29, 0] := clBlack;
lDest.Pixels[28, 0] := clBlack;
lDest.Pixels[29, 1] := clBlack;
lDest.Pixels[29, 2] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[27, 0] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[26, 1] := ANDROID_CHECKBOX_CORNER_GRAY;
//
lDest.Pixels[0, 29] := clBlack;
lDest.Pixels[1, 29] := clBlack;
lDest.Pixels[0, 28] := clBlack;
lDest.Pixels[0, 27] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[2, 29] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[1, 28] := ANDROID_CHECKBOX_CORNER_GRAY;
//
lDest.Pixels[29, 29] := clBlack;
lDest.Pixels[28, 29] := clBlack;
lDest.Pixels[29, 28] := clBlack;
lDest.Pixels[29, 27] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[27, 29] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[28, 28] := ANDROID_CHECKBOX_CORNER_GRAY;
end;
procedure TCDDrawerAndroid.DrawAndroidAlternatedHorzLine(ADest: TCanvas; procedure TCDDrawerAndroid.DrawAndroidAlternatedHorzLine(ADest: TCanvas;
X1, X2, Y: Integer; AColor1, AColor2: TColor); X1, X2, Y: Integer; AColor1, AColor2: TColor);
var var
@ -305,9 +370,9 @@ begin
end; end;
end; end;
procedure TCDDrawerAndroid.DrawTickmark(ADest: TCanvas; ADestPos: TPoint); procedure TCDDrawerAndroid.DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState);
begin begin
// Don't draw anything, tickmarks are impressed into the general images
end; end;
procedure TCDDrawerAndroid.DrawButton(ADest: TFPCustomCanvas; ASize: TSize; procedure TCDDrawerAndroid.DrawButton(ADest: TFPCustomCanvas; ASize: TSize;
@ -398,11 +463,14 @@ begin
DrawAndroidAlternatedHorzLine(lDest, 3, ASize.cx-3, ASize.cy-1, ANDROID_BUTTON_LAST_LINE_A, ANDROID_BUTTON_LAST_LINE_B); DrawAndroidAlternatedHorzLine(lDest, 3, ASize.cx-3, ASize.cy-1, ANDROID_BUTTON_LAST_LINE_A, ANDROID_BUTTON_LAST_LINE_B);
end; end;
if csfHasFocus in AState then // The full focus rect is too invasive for Android, just make a underline font style instead
DrawFocusRect(lDest, Point(5, 5), Size(ASize.cx-10, ASize.cy-10)); //if csfHasFocus in AState then
// DrawFocusRect(lDest, Point(5, 5), Size(ASize.cx-10, ASize.cy-10));
// Position calculations // Position calculations
ADest.Font.Assign(AStateEx.Font); ADest.Font.Assign(AStateEx.Font);
if csfHasFocus in AState then
ADest.Font.Underline := True;
Str := AStateEx.Caption; Str := AStateEx.Caption;
lGlyphCaptionHeight := Max(lDest.TextHeight(Str), AStateEx.Glyph.Height); lGlyphCaptionHeight := Max(lDest.TextHeight(Str), AStateEx.Glyph.Height);
lTextOutPos.X := (ASize.cx - lDest.TextWidth(Str) - AStateEx.Glyph.Width) div 2; lTextOutPos.X := (ASize.cx - lDest.TextWidth(Str) - AStateEx.Glyph.Width) div 2;
@ -438,8 +506,7 @@ begin
end; end;
initialization initialization
{$I customdrawnimages/android.lrs} {$include customdrawnimages/android.lrs}
RegisterDrawer(TCDDrawerAndroid.Create, dsAndroid); RegisterDrawer(TCDDrawerAndroid.Create, dsAndroid);
end. end.

View File

@ -31,7 +31,7 @@ type
procedure DrawRaisedFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawRaisedFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;} procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;}
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override; procedure DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState); override;
{procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override; {procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;} procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;}
// =================================== // ===================================
@ -111,6 +111,7 @@ const
WINXP_CHECKBOX_GRADIENT_20 = $00FFF7F7; WINXP_CHECKBOX_GRADIENT_20 = $00FFF7F7;
WINXP_TICKMARK = $0021A521; WINXP_TICKMARK = $0021A521;
WINXP_GRAY_TICKMARK = $0099A8AC;
WINXP_FRAME_BLUE = $00B99D7F; WINXP_FRAME_BLUE = $00B99D7F;
WINXP_FORM = $00D8E9EC; WINXP_FORM = $00D8E9EC;
@ -138,11 +139,12 @@ begin
Palette.Form := WINXP_FORM; Palette.Form := WINXP_FORM;
end; end;
procedure TCDDrawerWinXP.DrawTickmark(ADest: TCanvas; ADestPos: TPoint); procedure TCDDrawerWinXP.DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState);
var var
i: Integer; i: Integer;
begin begin
ADest.Pen.Color := WINXP_TICKMARK; if csfPartiallyOn in AState then ADest.Pen.FPColor := TColorToFPColor(WINXP_GRAY_TICKMARK)
else ADest.Pen.FPColor := TColorToFPColor(WINXP_TICKMARK);
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
// 3 lines going down and to the right // 3 lines going down and to the right
for i := 0 to 2 do for i := 0 to 2 do

View File

@ -42,7 +42,7 @@ type
const FrameWidth : integer; const Style : TBevelCut); override; const FrameWidth : integer; const Style : TBevelCut); override;
procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override; procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); override;
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override; procedure DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState); override;
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override; procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
procedure DrawArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState; ASize: Integer = 7); override; procedure DrawArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState; ASize: Integer = 7); override;
// Extra buttons drawing routines // Extra buttons drawing routines
@ -140,6 +140,7 @@ const
WIN2000_SELECTION_BACKGROUND = $00C56A31; WIN2000_SELECTION_BACKGROUND = $00C56A31;
WIN2000_SCROLLBAR_BACKGROUND = $00ECF4F6; WIN2000_SCROLLBAR_BACKGROUND = $00ECF4F6;
WIN2000_LIGHTGRAY_BACKGROUND = $00ECF4F6;
WIN2000_PROGRESSBAR_BLUE = $00C56A31; WIN2000_PROGRESSBAR_BLUE = $00C56A31;
@ -453,22 +454,25 @@ begin
ADest.LineTo(ADestPos.X + ASize.cx-1, ADestPos.Y-1); ADest.LineTo(ADestPos.X + ASize.cx-1, ADestPos.Y-1);
end; end;
procedure TCDDrawerCommon.DrawTickmark(ADest: TCanvas; ADestPos: TPoint); procedure TCDDrawerCommon.DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState);
var var
i: Integer; i: Integer;
lSpacing5, lFirstLinesEnd, lSecondLinesEnd: Integer; lSpacing5, lFirstLinesEnd, lSecondLinesEnd: Integer;
begin begin
ADest.Pen.Color := clBlack; if csfPartiallyOn in AState then
ADest.Pen.FPColor := TColorToFPColor(WIN2000_FRAME_GRAY)
else
ADest.Pen.FPColor := colBlack;
ADest.Pen.Style := psSolid; ADest.Pen.Style := psSolid;
if Screen.PixelsPerInch <= 125 then if Screen.PixelsPerInch <= 125 then
begin begin
// 4 lines going down and to the right // 4 lines going down and to the right
for i := 0 to 3 do for i := 0 to 3 do
ADest.Line(ADestPos.X+2+i, ADestPos.Y+2+i, ADestPos.X+2+i, ADestPos.Y+5+i); ADest.Line(ADestPos.X+1+i, ADestPos.Y+2+i, ADestPos.X+1+i, ADestPos.Y+5+i);
// Now 5 lines going up and to the right // Now 5 lines going up and to the right
for i := 4 to 8 do for i := 4 to 8 do
ADest.Line(ADestPos.X+2+i, ADestPos.Y+2+6-i, ADestPos.X+2+i, ADestPos.Y+5+6-i); ADest.Line(ADestPos.X+1+i, ADestPos.Y+2+6-i, ADestPos.X+1+i, ADestPos.Y+5+6-i);
Exit; Exit;
end; end;
@ -891,7 +895,8 @@ begin
// the square background // the square background
ADest.Pen.Style := psClear; ADest.Pen.Style := psClear;
ADest.Brush.Style := bsSolid; ADest.Brush.Style := bsSolid;
ADest.Brush.Color := Palette.Window; if csfPartiallyOn in AState then ADest.Brush.Color := WIN2000_LIGHTGRAY_BACKGROUND
else ADest.Brush.Color := Palette.Window;
ADest.Rectangle(Bounds(1, lHalf - lSquareHalf, lSquareHeight, lSquareHeight)); ADest.Rectangle(Bounds(1, lHalf - lSquareHalf, lSquareHeight, lSquareHeight));
// the square frame // the square frame
@ -932,8 +937,8 @@ begin
DrawCheckBoxSquare(ADest, Point(0, 0), ASize, AState, AStateEx); DrawCheckBoxSquare(ADest, Point(0, 0), ASize, AState, AStateEx);
// The Tickmark // The Tickmark
if csfOn in AState then if (csfOn in AState) or (csfPartiallyOn in AState) then
DrawTickmark(ADest, Point(lValue3, ASize.cy div 2 - GetMeasures(TCDCHECKBOX_SQUARE_HALF_HEIGHT)+lValue3)); DrawTickmark(ADest, Point(lValue3, ASize.cy div 2 - GetMeasures(TCDCHECKBOX_SQUARE_HALF_HEIGHT)+lValue3), AState);
// The text selection // The text selection
if csfHasFocus in AState then if csfHasFocus in AState then

View File

@ -304,7 +304,7 @@ type
const FrameWidth : integer; const Style : TBevelCut); virtual; abstract; const FrameWidth : integer; const Style : TBevelCut); virtual; abstract;
procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); virtual; abstract; procedure DrawSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); virtual; abstract;
procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); virtual; abstract; procedure DrawShallowSunkenFrame(ADest: TCanvas; ADestPos: TPoint; ASize: TSize); virtual; abstract;
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); virtual; abstract; procedure DrawTickmark(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState); virtual; abstract;
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); virtual; abstract; procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); virtual; abstract;
procedure DrawArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState; ASize: Integer = 7); virtual; abstract; procedure DrawArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState; ASize: Integer = 7); virtual; abstract;
// Extra buttons drawing routines // Extra buttons drawing routines