Fixes the drawing of the checkbox in Android

git-svn-id: trunk@36396 -
This commit is contained in:
sekelsenmat 2012-03-28 15:30:23 +00:00
parent 050883f91c
commit b52ee389ac
6 changed files with 63 additions and 47 deletions

View File

@ -16,7 +16,7 @@ object Form1: TForm1
object Button1: TButton
Left = 96
Height = 25
Top = 16
Top = 8
Width = 116
Caption = 'Move Progress'
OnClick = Button1Click
@ -45,7 +45,7 @@ object Form1: TForm1
object CheckBox1: TCheckBox
Left = 72
Height = 21
Top = 48
Top = 40
Width = 94
Caption = 'CheckBox1'
TabOrder = 3

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
LCLProc, Arrow, StdCtrls, ComCtrls, LCLType, LCLIntf, InterfaceBase,
lazdeviceapis, Menus;
lazdeviceapis, Menus, ExtDlgs, customdrawncontrols;
type
TSubControl = class;

View File

@ -4,11 +4,12 @@ program nonandroidtest;
uses
Interfaces, // this includes the LCL widgetset
Forms, mainform, secondform;
Forms, mainform, secondform, customdrawndrawers, customdrawn_android;
{$R *.res}
begin
DefaultStyle := dsAndroid;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);

View File

@ -23,7 +23,7 @@ type
private
bmpCheckbox, bmpCheckboxChecked: TBitmap;
// Alternative checkbox drawing, not currently utilized
procedure DrawCheckBoxBitmap(ADest: TFPCustomCanvas; AState: TCDControlState);
procedure DrawCheckBoxBitmap(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState; ASize: Integer);
// Makes pixels in each corner transparent for a rounded effect
procedure DrawTransparentRoundCorners(ADest: TFPCustomCanvas; ADestPos: TPoint; ASize: TSize; AColor: TFPColor);
// Draws a vertical line with different first and last pixels
@ -204,44 +204,44 @@ initialization
{ TCDDrawerAndroid }
procedure TCDDrawerAndroid.DrawCheckBoxBitmap(ADest: TFPCustomCanvas; AState: TCDControlState);
procedure TCDDrawerAndroid.DrawCheckBoxBitmap(ADest: TFPCustomCanvas; ADestPos: TPoint; AState: TCDControlState; ASize: Integer);
var
i: Integer;
lDest: TCanvas;
begin
lDest := TCanvas(ADest);
// Background
for i := 0 to 29 do
DrawAndroidAlternatedHorzLine(lDest, 0, 31, i, ANDROID_CHECKBOX_A[i], ANDROID_CHECKBOX_B[i]);
for i := 0 to ASize-1 do
DrawAndroidAlternatedHorzLine(lDest, 0, ASize-1, i, ANDROID_CHECKBOX_A[i], ANDROID_CHECKBOX_B[i]);
// Corners
ADest.Colors[0, 0] := colBlack;
ADest.Colors[1, 0] := colBlack;
ADest.Colors[0, 1] := colBlack;
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;
ADest.Colors[ADestPos.X+0, ADestPos.Y+0] := colBlack;
ADest.Colors[ADestPos.X+1, ADestPos.Y+0] := colBlack;
ADest.Colors[ADestPos.X+0, ADestPos.Y+1] := colBlack;
lDest.Pixels[ADestPos.X+0, ADestPos.Y+2] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+2, ADestPos.Y+0] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+1, ADestPos.Y+1] := ANDROID_CHECKBOX_CORNER_GRAY;
//
ADest.Colors[29, 0] := colBlack;
ADest.Colors[28, 0] := colBlack;
ADest.Colors[29, 1] := colBlack;
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;
ADest.Colors[ADestPos.X+ASize-1, ADestPos.Y+0] := colBlack;
ADest.Colors[ADestPos.X+ASize-2, ADestPos.Y+0] := colBlack;
ADest.Colors[ADestPos.X+ASize-1, ADestPos.Y+1] := colBlack;
lDest.Pixels[ADestPos.X+ASize-1, ADestPos.Y+2] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+ASize-3, ADestPos.Y+0] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+ASize-4, ADestPos.Y+1] := ANDROID_CHECKBOX_CORNER_GRAY;
//
ADest.Colors[0, 29] := colBlack;
ADest.Colors[1, 29] := colBlack;
ADest.Colors[0, 28] := colBlack;
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;
ADest.Colors[ADestPos.X+0, ADestPos.Y+ASize-1] := colBlack;
ADest.Colors[ADestPos.X+1, ADestPos.Y+ASize-1] := colBlack;
ADest.Colors[ADestPos.X+0, ADestPos.Y+ASize-2] := colBlack;
lDest.Pixels[ADestPos.X+0, ADestPos.Y+ASize-3] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+2, ADestPos.Y+ASize-1] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+1, ADestPos.Y+ASize-2] := ANDROID_CHECKBOX_CORNER_GRAY;
//
ADest.Colors[29, 29] := colBlack;
ADest.Colors[28, 29] := colBlack;
ADest.Colors[29, 28] := colBlack;
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;
ADest.Colors[ADestPos.X+ASize-1, ADestPos.Y+ASize-1] := colBlack;
ADest.Colors[ADestPos.X+ASize-2, ADestPos.Y+ASize-1] := colBlack;
ADest.Colors[ADestPos.X+ASize-1, ADestPos.Y+ASize-2] := colBlack;
lDest.Pixels[ADestPos.X+ASize-1, ADestPos.Y+ASize-3] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+ASize-3, ADestPos.Y+ASize-1] := ANDROID_CHECKBOX_CORNER_DARK_GRAY;
lDest.Pixels[ADestPos.X+ASize-2, ADestPos.Y+ASize-2] := ANDROID_CHECKBOX_CORNER_GRAY;
// Tickmark
if csfOff in AState then
@ -331,6 +331,7 @@ procedure TCDDrawerAndroid.DrawVerticalLineWithFirstLast(
begin
ADest.Colors[X, Y1] := AColorTop;
ADest.Pen.FPColor := AColorMiddle;
ADest.Pen.Style := psSolid;
ADest.Line(X, Y1+1, X, Y2);
ADest.Colors[X, Y2] := AColorEnd;
end;
@ -457,15 +458,15 @@ end;
procedure TCDDrawerAndroid.CreateResources;
begin
bmpCheckbox := TBitmap.Create;
bmpCheckboxChecked := TBitmap.Create;
{ bmpCheckbox := TBitmap.Create;
bmpCheckboxChecked := TBitmap.Create;}
end;
procedure TCDDrawerAndroid.LoadResources;
var
lDPI: Word;
begin
{$ifdef CD_UseImageResources}
(* {$ifdef CD_UseImageResources}
bmpCheckbox.LoadFromLazarusResource('android_checkbox');
bmpCheckboxChecked.LoadFromLazarusResource('android_checkbox_checked');
{$else}
@ -473,20 +474,20 @@ begin
bmpCheckbox.Height := 30;
bmpCheckboxChecked.Width := 30;
bmpCheckboxChecked.Height := 30;
DrawCheckBoxBitmap(bmpCheckbox.Canvas, [csfOff]);
DrawCheckBoxBitmap(bmpCheckboxChecked.Canvas, [csfOn]);
DrawCheckBoxBitmap(bmpCheckbox.Canvas, Point(0, 0), [csfOff], 30);
DrawCheckBoxBitmap(bmpCheckboxChecked.Canvas, Point(0, 0), [csfOn], 30);
{$endif}
// DPI adjustment
lDPI := Max(96, Screen.PixelsPerInch);
ScaleRasterImage(bmpCheckbox, 160, lDPI);
ScaleRasterImage(bmpCheckboxChecked, 160, lDPI);
ScaleRasterImage(bmpCheckboxChecked, 160, lDPI);*)
end;
procedure TCDDrawerAndroid.FreeResources;
begin
bmpCheckbox.Free;
bmpCheckboxChecked.Free;
{ bmpCheckbox.Free;
bmpCheckboxChecked.Free;}
end;
function TCDDrawerAndroid.GetDrawStyle: TCDDrawStyle;
@ -503,7 +504,7 @@ begin
TCDEDIT_BOTTOM_TEXT_SPACING: Result := 3;}
//
TCDCHECKBOX_SQUARE_HALF_HEIGHT: Floor(GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT)/2);
TCDCHECKBOX_SQUARE_HEIGHT: Result := DPIAdjustment(20);
TCDCHECKBOX_SQUARE_HEIGHT: Result := DPIAdjustment(30);
//
TCDRADIOBUTTON_CIRCLE_HEIGHT: Result := DPIAdjustment(20); // Must be dividable by 4
//
@ -723,14 +724,19 @@ end;
procedure TCDDrawerAndroid.DrawCheckBoxSquare(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
var
lCheckboxSquare: Integer;
begin
if csfOn in AState then ADest.Draw(0, 0, bmpCheckboxChecked)
else ADest.Draw(0, 0, bmpCheckbox);
lCheckboxSquare := GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT);
//if csfOn in AState then ADest.Draw(0, 0, bmpCheckboxChecked)
//else ADest.Draw(0, 0, bmpCheckbox);
DrawCheckBoxBitmap(ADest, ADestPos, AState, lCheckboxSquare);
// Transparent corners
DrawTransparentRoundCorners(ADest, ADestPos,
Size(GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT), GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT)),
AStateEx.FPParentRGBColor);
Size(lCheckboxSquare, lCheckboxSquare), AStateEx.FPParentRGBColor);
end;
procedure TCDDrawerAndroid.DrawRadioButtonCircle(ADest: TCanvas;

View File

@ -925,6 +925,7 @@ procedure TCDDrawerCommon.DrawCheckBox(ADest: TCanvas;
var
lColor: TColor;
lSquareHeight, lValue3: Integer;
lTextHeight, lTextY: Integer;
begin
lSquareHeight := GetMeasures(TCDCHECKBOX_SQUARE_HEIGHT);
lValue3 := DPIAdjustment(3);
@ -952,7 +953,13 @@ begin
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psClear;
ADest.Font.Assign(AStateEx.Font);
ADest.TextOut(lSquareHeight+5, 0, AStateEx.Caption);
lTextHeight := ADest.TextHeight(cddTestStr);
// put the text in the center
if lSquareHeight > lTextHeight then lTextY := (lSquareHeight - ADest.TextHeight(cddTestStr)) div 2
else lTextY := 0;
lTextY := Max(0, lTextY - 1);
ADest.TextOut(lSquareHeight+5, lTextY, AStateEx.Caption);
end;
procedure TCDDrawerCommon.DrawRadioButtonCircle(ADest: TCanvas;
@ -1074,9 +1081,10 @@ begin
ADest.Brush.Style := bsClear;
ADest.Font.Assign(AStateEx.Font);
lTextHeight := ADest.TextHeight(cddTestStr);
// put the text in the center
if lCircleHeight > lTextHeight then lTextY := (lCircleHeight - ADest.TextHeight(cddTestStr)) div 2
else lTextY := 0;
lTextY := lTextY - 1;
lTextY := Max(0, lTextY - 1);
ADest.TextOut(lCircleHeight+5, lTextY, AStateEx.Caption);
end;

View File

@ -1821,6 +1821,7 @@ begin
ControlStyle := ControlStyle - [csAcceptsControls];
AutoSize := True;
FHasOnOffStates := True;
FState := FState + [csfOff];
end;
destructor TCDCheckBox.Destroy;