You've already forked lazarus-ccr
Captcha: Rename component to TCaptchaLabel. Add demos folder. Add new simple_demo project. Move runtime_demo to demos folder.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8112 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -52,7 +52,7 @@ const
|
||||
DEFAULT_CAPTCHA_NUMLINES = 30;
|
||||
|
||||
type
|
||||
TCaptcha = class(TGraphicControl)
|
||||
TCaptchaLabel = class(TGraphicControl)
|
||||
private
|
||||
FBuffer: TBitmap;
|
||||
FCaptchaChars: TCaptchaCharArray;
|
||||
@@ -137,7 +137,7 @@ uses
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents('Misc', [TCaptcha]);
|
||||
RegisterComponents('Misc', [TCaptchaLabel]);
|
||||
end;
|
||||
|
||||
|
||||
@@ -168,9 +168,9 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{ TCaptcha }
|
||||
{ TCaptchaLabel }
|
||||
|
||||
constructor TCaptcha.Create(AOwner: TComponent);
|
||||
constructor TCaptchaLabel.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
with GetControlClassDefaultSize do
|
||||
@@ -209,7 +209,7 @@ begin
|
||||
Randomize;
|
||||
end;
|
||||
|
||||
destructor TCaptcha.Destroy;
|
||||
destructor TCaptchaLabel.Destroy;
|
||||
begin
|
||||
Finalize(FCaptchaChars);
|
||||
Finalize(FCaptchaLines);
|
||||
@@ -219,7 +219,7 @@ begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TCaptcha.AlmostBackgroundColor(AColor: TColor): Boolean;
|
||||
function TCaptchaLabel.AlmostBackgroundColor(AColor: TColor): Boolean;
|
||||
const
|
||||
TOLERANCE = 64;
|
||||
var
|
||||
@@ -231,7 +231,7 @@ begin
|
||||
Result := abs(colorL - bgColorL) < TOLERANCE;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.CalculatePreferredSize(
|
||||
procedure TCaptchaLabel.CalculatePreferredSize(
|
||||
var PreferredWidth, PreferredHeight: integer;
|
||||
WithThemeSpace: Boolean);
|
||||
begin
|
||||
@@ -254,14 +254,14 @@ begin
|
||||
PreferredHeight := 3*PreferredHeight div 2;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.Click;
|
||||
procedure TCaptchaLabel.Click;
|
||||
begin
|
||||
inherited;
|
||||
if FNewCaptchaEvent = nceClick then
|
||||
NewCaptcha;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.CreateNewCaptcha(ANumChars, ANumLines: Integer;
|
||||
procedure TCaptchaLabel.CreateNewCaptcha(ANumChars, ANumLines: Integer;
|
||||
KeepText, KeepLines: Boolean);
|
||||
begin
|
||||
if not KeepText then
|
||||
@@ -276,14 +276,14 @@ begin
|
||||
DrawBuffer;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.DblClick;
|
||||
procedure TCaptchaLabel.DblClick;
|
||||
begin
|
||||
inherited;
|
||||
if FNewCaptchaEvent = nceDblClick then
|
||||
NewCaptcha;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.DrawBuffer;
|
||||
procedure TCaptchaLabel.DrawBuffer;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -325,12 +325,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCaptcha.GetFont(AIndex: Integer): TFont;
|
||||
function TCaptchaLabel.GetFont(AIndex: Integer): TFont;
|
||||
begin
|
||||
Result := FFonts[AIndex];
|
||||
end;
|
||||
|
||||
function TCaptcha.GetCaptchaText: string;
|
||||
function TCaptchaLabel.GetCaptchaText: string;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -339,12 +339,12 @@ begin
|
||||
Result := Result + FCaptchaChars[i].Character;
|
||||
end;
|
||||
|
||||
function TCaptcha.GetValidChars(AIndex: Integer): String;
|
||||
function TCaptchaLabel.GetValidChars(AIndex: Integer): String;
|
||||
begin
|
||||
Result := FValidChars[TCaptchaCharsOption(AIndex)];
|
||||
end;
|
||||
|
||||
procedure TCaptcha.InitAngles;
|
||||
procedure TCaptchaLabel.InitAngles;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -356,7 +356,7 @@ end;
|
||||
When KeepVertPos is false, the vertical position of the characters is selected
|
||||
randomly within the height of the control. Otherwise the already stored
|
||||
vertical positions are used. }
|
||||
procedure TCaptcha.InitCharPos(KeepVertPos: Boolean);
|
||||
procedure TCaptchaLabel.InitCharPos(KeepVertPos: Boolean);
|
||||
var
|
||||
x: Integer;
|
||||
i: Integer;
|
||||
@@ -409,7 +409,7 @@ begin
|
||||
FBuffer.SetSize(x, maxHeight);
|
||||
end;
|
||||
|
||||
procedure TCaptcha.InitFontIndex;
|
||||
procedure TCaptchaLabel.InitFontIndex;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -427,7 +427,7 @@ end;
|
||||
|
||||
{ Pick random color for a line.
|
||||
Make sure that the color is not too close to the background color. }
|
||||
procedure TCaptcha.InitLineColors;
|
||||
procedure TCaptchaLabel.InitLineColors;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -439,7 +439,7 @@ begin
|
||||
until not AlmostBackgroundColor(FCaptchaLines[i].Color);
|
||||
end;
|
||||
|
||||
procedure TCaptcha.InitLines(ACount: Integer; KeepExisting: Boolean);
|
||||
procedure TCaptchaLabel.InitLines(ACount: Integer; KeepExisting: Boolean);
|
||||
var
|
||||
i, n: Integer;
|
||||
begin
|
||||
@@ -470,7 +470,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.InitText(ACount: Integer; KeepExisting: Boolean);
|
||||
procedure TCaptchaLabel.InitText(ACount: Integer; KeepExisting: Boolean);
|
||||
var
|
||||
i, j, n: Integer;
|
||||
ok: Boolean;
|
||||
@@ -539,7 +539,7 @@ end;
|
||||
|
||||
{ Pick random color for a character.
|
||||
Make sure that the color is not too close to the background color. }
|
||||
procedure TCaptcha.InitTextColors;
|
||||
procedure TCaptchaLabel.InitTextColors;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
@@ -551,18 +551,18 @@ begin
|
||||
until not AlmostbackgroundColor(FCaptchaChars[i].Color);
|
||||
end;
|
||||
|
||||
procedure TCaptcha.NewCaptcha;
|
||||
procedure TCaptchaLabel.NewCaptcha;
|
||||
begin
|
||||
CreateNewCaptcha(FNumChars, FNumLines, false, false);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.Paint;
|
||||
procedure TCaptchaLabel.Paint;
|
||||
begin
|
||||
Canvas.Draw((Width - FBuffer.Width) div 2, (Height - FBuffer.Height) div 2, FBuffer);
|
||||
end;
|
||||
|
||||
procedure TCaptcha.Resize;
|
||||
procedure TCaptchaLabel.Resize;
|
||||
begin
|
||||
inherited;
|
||||
if Assigned(FBuffer) and not FInitialized then
|
||||
@@ -572,7 +572,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetColor(AValue: TColor);
|
||||
procedure TCaptchaLabel.SetColor(AValue: TColor);
|
||||
begin
|
||||
if AValue = Color then
|
||||
exit;
|
||||
@@ -583,7 +583,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetFont(AIndex: Integer; const AValue: TFont);
|
||||
procedure TCaptchaLabel.SetFont(AIndex: Integer; const AValue: TFont);
|
||||
begin
|
||||
if FFonts[AIndex].IsEqual(AValue) then
|
||||
exit;
|
||||
@@ -594,7 +594,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetMaxAngle(const AValue: Integer);
|
||||
procedure TCaptchaLabel.SetMaxAngle(const AValue: Integer);
|
||||
begin
|
||||
if AValue = FMaxAngle then
|
||||
exit;
|
||||
@@ -605,7 +605,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetNumChars(const AValue: Integer);
|
||||
procedure TCaptchaLabel.SetNumChars(const AValue: Integer);
|
||||
begin
|
||||
if AValue = FNumChars then
|
||||
exit;
|
||||
@@ -618,7 +618,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetNumLines(const AValue: Integer);
|
||||
procedure TCaptchaLabel.SetNumLines(const AValue: Integer);
|
||||
begin
|
||||
if AValue = FNumLines then
|
||||
exit;
|
||||
@@ -628,7 +628,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetOptions(const AValue: TCaptchaOptions);
|
||||
procedure TCaptchaLabel.SetOptions(const AValue: TCaptchaOptions);
|
||||
var
|
||||
oldOptions: TCaptchaOptions;
|
||||
begin
|
||||
@@ -656,7 +656,7 @@ begin
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TCaptcha.SetValidChars(AIndex: Integer; const AValue: String);
|
||||
procedure TCaptchaLabel.SetValidChars(AIndex: Integer; const AValue: String);
|
||||
begin
|
||||
if FValidChars[TCaptchaCharsOption(AIndex)] = AValue then
|
||||
exit;
|
||||
@@ -665,7 +665,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TCaptcha.Verify(const AText: String): Boolean;
|
||||
function TCaptchaLabel.Verify(const AText: String): Boolean;
|
||||
begin
|
||||
Result := (AText = GetCaptchaText);
|
||||
end;
|
||||
|
Reference in New Issue
Block a user