Adds support for fuzzy effect in the icon editor

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1308 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat 2010-08-31 15:58:43 +00:00
parent 83249c4946
commit 02726bf11d
5 changed files with 300 additions and 211 deletions

View File

@ -1207,14 +1207,55 @@ object MainForm: TMainForm
Layout = tlCenter
ParentColor = False
end
object spinFillAlpha: TSpinEdit
Left = 504
Height = 21
Top = 5
Width = 51
OnChange = spinFillAlphaChange
object PanelTolerance1: TPanel
Left = 494
Height = 34
Top = 0
Width = 68
Align = alLeft
BevelOuter = bvNone
ClientHeight = 34
ClientWidth = 68
TabOrder = 4
Value = 100
object spinFillAlpha: TSpinEdit
Left = 10
Height = 21
Top = 5
Width = 51
OnChange = spinFillAlphaChange
TabOrder = 0
Value = 100
end
end
object LabelTolerance2: TLabel
Left = 562
Height = 34
Top = 0
Width = 34
Align = alLeft
Caption = 'Fuzzy?'
Constraints.MinHeight = 32
Layout = tlCenter
ParentColor = False
end
object PanelTolerance2: TPanel
Left = 596
Height = 34
Top = 0
Width = 30
Align = alLeft
BevelOuter = bvNone
ClientHeight = 34
ClientWidth = 30
TabOrder = 5
object checkFuzzy: TCheckBox
Left = 4
Height = 17
Top = 9
Width = 18
OnChange = checkFuzzyChange
TabOrder = 0
end
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -41,10 +41,14 @@ type
{ TMainForm }
TMainForm = class(TForm)
checkFuzzy: TCheckBox;
LabelTolerance1: TLabel;
LabelTolerance2: TLabel;
Palette: TColorPalette;
MenuItemShowGrid: TMenuItem;
MenuItemShowPreview: TMenuItem;
PanelTolerance1: TPanel;
PanelTolerance2: TPanel;
spinFillAlpha: TSpinEdit;
ViewShowPreview: TAction;
ViewShowMask: TAction;
@ -206,6 +210,7 @@ type
UpDownSize: TUpDown;
UpDownSize1: TUpDown;
UpDownTolerance: TUpDown;
procedure checkFuzzyChange(Sender: TObject);
procedure ColorsDisableExecute(Sender: TObject);
procedure ColorsGrayscaleExecute(Sender: TObject);
procedure ColorsInvertExecute(Sender: TObject);
@ -1137,6 +1142,12 @@ begin
ActivePictureEdit.Disable;
end;
procedure TMainForm.checkFuzzyChange(Sender: TObject);
begin
if not Pictures.CanEdit then Exit;
ActivePictureEdit.Fuzzy := checkFuzzy.Checked;
end;
procedure TMainForm.EditSizeChange(Sender: TObject);
begin
if not Pictures.CanEdit then Exit;

View File

@ -125,6 +125,7 @@ type
FFillAndOutline: TDrawMode;
FFillColor: TColor;
FFloodFillTolerance: Single;
FFuzzy: Boolean;
FMaskTool: TMaskTool;
FModified: Boolean;
FOnChange: TNotifyEvent;
@ -213,7 +214,8 @@ type
property Size: Integer read FSize write FSize;
property Tool: TPictureEditTool read FTool write SetTool;
property FillAlpha: Integer read FFillAlpha write FFillAlpha;
property Fuzzy: Boolean read FFuzzy write FFuzzy;
property Modified: Boolean read FModified;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnColorChange: TNotifyEvent read FOnColorChange write FOnColorChange;
@ -845,7 +847,17 @@ begin
BeginDraw;
if not (ssLeft in Shift) then Picture.Canvas.EraseMode := ermErase;
try
Picture.Canvas.AlphaRectangle(X1, Y1, X2, Y2, FFillAlpha);
if FFuzzy then
begin
Picture.Canvas.FuzzyRectangle(X1, Y1, X2, Y2);
end
else
begin
if FFillAlpha = 100 then
Picture.Canvas.Rectangle(X1, Y1, X2, Y2)
else
Picture.Canvas.AlphaRectangle(X1, Y1, X2, Y2, FFillAlpha);
end;
finally
Picture.Canvas.EraseMode := ermNone;
EndDraw;

View File

@ -154,6 +154,8 @@ type
procedure MaskFloodFill(X, Y: Integer);
// Alpha drawing methods
procedure AlphaRectangle(X1, Y1, X2, Y2, AAlpha: Integer);
// Effect drawing methods
procedure FuzzyRectangle(X1, Y1, X2, Y2: Integer);
public
procedure DrawTo(ACanvas: TCanvas; X, Y: Integer);
procedure StretchDrawTo(ACanvas: TCanvas; DstX, DstY, DstWidth, DstHeight: Integer);
@ -805,6 +807,19 @@ begin
end;
end;
procedure TRGB32Canvas.FuzzyRectangle(X1, Y1, X2, Y2: Integer);
var
X, Y: LongInt;
delta: Integer;
begin
for Y := Y1 + 5 to Y2 - 5 do
for X := X1 + 5 to X2 - 5 do
begin
delta := X mod 5;
SetColor(X, Y, GetColor(X - delta, Y - delta));
end;
end;
procedure TRGB32Canvas.DrawTo(ACanvas: TCanvas; X, Y: Integer);
begin
if ACanvas <> nil then