2
0
Эх сурвалжийг харах

tool brush: show popup if source undefined, shift right click to define

Johann ELSASS 5 жил өмнө
parent
commit
2d933585a9

+ 5 - 3
lazpaint/lazpaintinstance.pas

@@ -152,7 +152,8 @@ type
     procedure Init(AEmbedded: boolean);
     procedure SetBlackAndWhite(AValue: boolean); override;
     procedure OnStackChanged({%H-}sender: TLazPaintImage; AScrollIntoView: boolean);
-    procedure OnToolPopup({%H-}sender: TToolManager; AMessage: TToolPopupMessage; AKey: Word);
+    procedure OnToolPopup({%H-}sender: TToolManager; AMessage: TToolPopupMessage; AKey: Word;
+      AAlways: boolean);
 
     function GetImageListWindowHeight: integer; override;
     function GetImageListWindowWidth: integer; override;
@@ -604,12 +605,13 @@ begin
     FLayerStack.InvalidateStack(AScrollIntoView);
 end;
 
-procedure TLazPaintInstance.OnToolPopup(sender: TToolManager; AMessage: TToolPopupMessage; AKey: Word);
+procedure TLazPaintInstance.OnToolPopup(sender: TToolManager; AMessage: TToolPopupMessage; AKey: Word;
+  AAlways: boolean);
 var messageStr: string;
     idx: integer;
 begin
   if FInCommandLine then exit;
-  if Assigned(Config) then
+  if Assigned(Config) and not AAlways then
   begin
     idx := ord(AMessage);
     if Config.ToolPopupMessageShownCount(idx) < MaxToolPopupShowCount then

+ 4 - 4
lazpaint/tools/utool.pas

@@ -170,7 +170,7 @@ type
     tpmRightClickForSource, tpmNothingToBeDeformed);
 
   TOnToolChangedHandler = procedure(sender: TToolManager; ANewToolType: TPaintToolType) of object;
-  TOnPopupToolHandler = procedure(sender: TToolManager; APopupMessage: TToolPopupMessage; AKey: Word) of object;
+  TOnPopupToolHandler = procedure(sender: TToolManager; APopupMessage: TToolPopupMessage; AKey: Word; AAlways: boolean) of object;
 
   TShapeOption = (toAliasing, toDrawShape, toFillShape, toCloseShape);
   TShapeOptions = set of TShapeOption;
@@ -485,7 +485,7 @@ type
     procedure ToolOpen;
     function ToolUpdate: boolean;
     function ToolUpdateNeeded: boolean;
-    procedure ToolPopup(AMessage: TToolPopupMessage; AKey: Word = 0);
+    procedure ToolPopup(AMessage: TToolPopupMessage; AKey: Word = 0; AAlways: boolean = false);
     procedure HintReturnValidates;
 
     function IsSelectingTool: boolean;
@@ -3751,10 +3751,10 @@ begin
     result := true;
 end;
 
-procedure TToolManager.ToolPopup(AMessage: TToolPopupMessage; AKey: Word = 0);
+procedure TToolManager.ToolPopup(AMessage: TToolPopupMessage; AKey: Word = 0; AAlways: boolean = false);
 begin
   if Assigned(FOnPopupToolHandler) then
-    FOnPopupToolHandler(self, AMessage, AKey);
+    FOnPopupToolHandler(self, AMessage, AKey, AAlways);
 end;
 
 function TToolManager.IsSelectingTool: boolean;

+ 14 - 3
lazpaint/tools/utoolbrush.pas

@@ -58,6 +58,8 @@ type
     class var sourceLayerId: integer;
     class var sourcePosition: TPoint;
     class var sourcePositionRelative: boolean;
+    class var sourceFlattened: boolean;
+    class var sourceDefined: boolean;
     function PickColorWithShift: boolean; override;
     function DrawBrushAt(toolDest: TBGRABitmap; x, y: single): TRect; override;
     procedure PrepareBrush(rightBtn: boolean); override;
@@ -95,10 +97,18 @@ begin
     sourcePosition := Point(round(x) + sourceOfs.x,round(y) + sourceOfs.y);
     sourceLayerId := Manager.Image.LayerId[Manager.Image.CurrentLayerIndex];
     sourcePositionRelative:= false;
+    sourceFlattened := ssShift in ShiftState;
+    sourceDefined := true;
     result := OnlyRenderChange;
   end else
   begin
-    if (ssShift in ShiftState) then
+    if not sourceDefined then
+    begin
+      Manager.ToolPopup(tpmRightClickForSource, 0, true);
+      result := EmptyRect;
+      exit;
+    end;
+    if (ssShift in ShiftState) or sourceFlattened then
     begin
       source := Manager.Image.RenderedImage;
       sourceOfs := Point(0,0);
@@ -107,6 +117,7 @@ begin
       sourceIdx := Manager.Image.GetLayerIndexById(sourceLayerId);
       if sourceIdx = -1 then
       begin
+        Manager.ToolPopup(tpmRightClickForSource, 0, true);
         result := EmptyRect;
         exit;
       end;
@@ -188,8 +199,8 @@ var sourcePosF: TPointF;
 begin
   Result:=inherited Render(VirtualScreen, VirtualScreenWidth,
     VirtualScreenHeight, BitmapToVirtualScreen);
-  if not sourcePositionRelative and
-    (Manager.Image.LayerBitmapById[sourceLayerId] <> nil) then
+  if not sourcePositionRelative and (sourceFlattened or
+    (Manager.Image.LayerBitmapById[sourceLayerId] <> nil)) then
   begin
     sourcePosF := BitmapToVirtualScreen(PointF(sourcePosition.X mod Manager.Image.Width,
       sourcePosition.Y mod Manager.Image.Height));