Skip to content

Commit

Permalink
#543 start with opaque pen, do not pick color on empty layer
Browse files Browse the repository at this point in the history
  • Loading branch information
circular17 committed Jun 2, 2024
1 parent cff3eb6 commit dba418c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
9 changes: 9 additions & 0 deletions lazpaint/lazpaintinstance.pas
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,19 @@ procedure TLazPaintInstance.FormsNeeded;
end;

procedure TLazPaintInstance.UseConfig(ini: TInifile);
var
c: TBGRAPixel;
begin
FreeAndNil(FConfig);
BlackAndWhite := ini.ReadBool('General','BlackAndWhite',BlackAndWhite);
FConfig := TLazPaintConfig.Create(ini,LazPaintVersionStr);
// make sure default pen color is not fully or almost fully transparent
if FConfig.DefaultToolForeColor.Alpha < 32 then
begin
c := FConfig.DefaultToolForeColor;
c.alpha := 255;
FConfig.SetDefaultToolForeColor(c);
end;
ToolManager.LoadFromConfig;
FGridVisible := Config.DefaultGridVisible;
FDockLayersAndColors:= Config.DefaultDockLayersAndColors;
Expand Down
4 changes: 3 additions & 1 deletion lazpaint/tools/utool.pas
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ TToolClass = class of TGenericTool;
TToolPopupMessage= (tpmNone, tpmHoldKeyForSquare, tpmHoldKeySnapToPixel,
tpmReturnValides, tpmBackspaceRemoveLastPoint, tpmRightClickFinishShape, tpmHoldKeyRestrictRotation,
tpmHoldKeysScaleMode, tpmCurveModeHint, tpmBlendOpBackground,
tpmRightClickForSource, tpmNothingToBeDeformed, tpmRightClickForTransformCenter);
tpmRightClickForSource, tpmNothingToBeDeformed, tpmRightClickForTransformCenter,
tpmLayerEmpty);

TOnToolChangedHandler = procedure(sender: TToolManager; ANewToolType: TPaintToolType) of object;
TOnPopupToolHandler = procedure(sender: TToolManager; APopupMessage: TToolPopupMessage; AKey: Word; AAlways: boolean) of object;
Expand Down Expand Up @@ -772,6 +773,7 @@ function ToolPopupMessageToStr(AMessage: TToolPopupMessage; AKey: Word = 0): str
tpmRightClickForSource: result := rsRightClickForSource;
tpmNothingToBeDeformed: result := rsNothingToBeDeformed;
tpmRightClickForTransformCenter: result := rsRightClickForTransformCenter;
tpmLayerEmpty: result := rsEmptyLayer;
else
result := '';
end;
Expand Down
41 changes: 30 additions & 11 deletions lazpaint/tools/utoolbasic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,39 @@ function TToolColorPicker.DoToolMove(toolDest: TBGRABitmap; pt: TPoint;
result := EmptyRect;
if colorpicking then
begin
if (pt.X >= 0) and (pt.Y >= 0) and (pt.X < toolDest.Width) and (pt.Y < toolDest.Height) then
if ssShift in ShiftState then
begin
if ssShift in ShiftState then
c := Manager.Image.RenderedImage.GetPixel(pt.X,pt.Y)
else c := toolDest.GetPixel(pt.X,pt.Y);
if colorpickingRight then
c := Manager.Image.RenderedImage.GetPixel(pt.X,pt.Y);
// rendered image is in fact empty
if (c.alpha = 0) and Manager.Image.RenderedImage.Empty then
begin
Manager.BackColor := c;
Manager.QueryColorTarget(Manager.BackFill);
end else
begin
Manager.ForeColor := c;
Manager.QueryColorTarget(Manager.ForeFill);
Manager.ToolPopup(tpmLayerEmpty, 0, true);
exit;
end;
end
else
begin
if (pt.X >= 0) and (pt.Y >= 0) and (pt.X < toolDest.Width) and (pt.Y < toolDest.Height) then
begin
c := toolDest.GetPixel(pt.X,pt.Y);
// layer is in fact empty
if (c.alpha = 0) and toolDest.Empty then
begin
Manager.ToolPopup(tpmLayerEmpty, 0, true);
exit;
end;
end
else
exit;
end;
if colorpickingRight then
begin
Manager.BackColor := c;
Manager.QueryColorTarget(Manager.BackFill);
end else
begin
Manager.ForeColor := c;
Manager.QueryColorTarget(Manager.ForeFill);
end;
end;
end;
Expand Down
2 changes: 1 addition & 1 deletion lazpaint/uconfig.pas
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ procedure TLazPaintConfig.SetDefaultUseImageBrowser(value: boolean);

function TLazPaintConfig.DefaultToolForeColor: TBGRAPixel;
begin
result := StrToBGRA(iniOptions.ReadString('Tool','ForeColor','00000080'));
result := StrToBGRA(iniOptions.ReadString('Tool','ForeColor','000000FF'));
end;

function TLazPaintConfig.DefaultToolBackColor: TBGRAPixel;
Expand Down

0 comments on commit dba418c

Please sign in to comment.