Browse Source

#566 fix interference between text and palette

Juliette ELSASS 1 year ago
parent
commit
d4fc341abe

+ 2 - 2
lazpaint/maintoolbar.inc

@@ -698,14 +698,14 @@ end;
 
 
 function TFMain.CatchToolKeyDown(var AKey: Word): boolean;
 function TFMain.CatchToolKeyDown(var AKey: Word): boolean;
 begin
 begin
-  if Assigned(FLayout) and not SpinEditFocused and (CurrentTool <> ptText) then
+  if Assigned(FLayout) and not SpinEditFocused then
     result := FLayout.CatchToolKeyDown(AKey)
     result := FLayout.CatchToolKeyDown(AKey)
     else result := false;
     else result := false;
 end;
 end;
 
 
 function TFMain.CatchToolKeyUp(var AKey: Word): boolean;
 function TFMain.CatchToolKeyUp(var AKey: Word): boolean;
 begin
 begin
-  if Assigned(FLayout) and not SpinEditFocused and (CurrentTool <> ptText) then
+  if Assigned(FLayout) and not SpinEditFocused then
     result := FLayout.CatchToolKeyUp(AKey)
     result := FLayout.CatchToolKeyUp(AKey)
     else result := false;
     else result := false;
 end;
 end;

+ 14 - 0
lazpaint/tools/utool.pas

@@ -89,6 +89,7 @@ type
     function GetIdleAction: TLayerAction; virtual;
     function GetIdleAction: TLayerAction; virtual;
     function GetLayerOffset: TPoint; virtual;
     function GetLayerOffset: TPoint; virtual;
     function GetIsSelectingTool: boolean; virtual; abstract;
     function GetIsSelectingTool: boolean; virtual; abstract;
+    function GetIsEditingText: boolean; virtual;
     function FixSelectionTransform: boolean; virtual;
     function FixSelectionTransform: boolean; virtual;
     function FixLayerOffset: boolean; virtual;
     function FixLayerOffset: boolean; virtual;
     function DoToolDown(toolDest: TBGRABitmap; pt: TPoint; ptF: TPointF; rightBtn: boolean): TRect; virtual;
     function DoToolDown(toolDest: TBGRABitmap; pt: TPoint; ptF: TPointF; rightBtn: boolean): TRect; virtual;
@@ -138,6 +139,7 @@ type
     function Render(VirtualScreen: TBGRABitmap; VirtualScreenWidth, VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; virtual;
     function Render(VirtualScreen: TBGRABitmap; VirtualScreenWidth, VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; virtual;
     property Manager : TToolManager read FManager;
     property Manager : TToolManager read FManager;
     property IsSelectingTool: boolean read GetIsSelectingTool;
     property IsSelectingTool: boolean read GetIsSelectingTool;
+    property IsEditingText: boolean read GetIsEditingText;
     property Action : TLayerAction read GetAction;
     property Action : TLayerAction read GetAction;
     property LayerOffset : TPoint read GetLayerOffset;
     property LayerOffset : TPoint read GetLayerOffset;
     property LastToolDrawingLayer: TBGRABitmap read FLastToolDrawingLayer;
     property LastToolDrawingLayer: TBGRABitmap read FLastToolDrawingLayer;
@@ -274,6 +276,7 @@ type
     function GetBrushCount: integer;
     function GetBrushCount: integer;
     function GetBrushInfo: TLazPaintBrush;
     function GetBrushInfo: TLazPaintBrush;
     function GetForeColor: TBGRAPixel;
     function GetForeColor: TBGRAPixel;
+    function GetIsEditingText: boolean;
     function GetMaxDeformationGridSize: TSize;
     function GetMaxDeformationGridSize: TSize;
     function GetOutlineColor: TBGRAPixel;
     function GetOutlineColor: TBGRAPixel;
     function GetShapeOptionAliasing: boolean;
     function GetShapeOptionAliasing: boolean;
@@ -566,6 +569,7 @@ type
     property TextOutline: boolean read FTextOutline;
     property TextOutline: boolean read FTextOutline;
     property TextOutlineWidth: single read FTextOutlineWidth;
     property TextOutlineWidth: single read FTextOutlineWidth;
     property TextPhong: boolean read FTextPhong write SetTextPhong;
     property TextPhong: boolean read FTextPhong write SetTextPhong;
+    property IsEditingText: boolean read GetIsEditingText;
     property LightPosition: TPointF read FLightPosition write SetLightPosition;
     property LightPosition: TPointF read FLightPosition write SetLightPosition;
     property LightAltitude: integer read FLightAltitude write SetLightAltitude;
     property LightAltitude: integer read FLightAltitude write SetLightAltitude;
     property TextShadow: boolean read FTextShadow write SetTextShadow;
     property TextShadow: boolean read FTextShadow write SetTextShadow;
@@ -825,6 +829,11 @@ begin
   end;
   end;
 end;
 end;
 
 
+function TGenericTool.GetIsEditingText: boolean;
+begin
+  result := false;
+end;
+
 function TGenericTool.GetAllowedBackFillTypes: TVectorialFillTypes;
 function TGenericTool.GetAllowedBackFillTypes: TVectorialFillTypes;
 begin
 begin
   result := [vftSolid,vftGradient,vftTexture];
   result := [vftSolid,vftGradient,vftTexture];
@@ -1725,6 +1734,11 @@ begin
     result := FForeFill.AverageColor;
     result := FForeFill.AverageColor;
 end;
 end;
 
 
+function TToolManager.GetIsEditingText: boolean;
+begin
+  result := Assigned(CurrentTool) and CurrentTool.IsEditingText;
+end;
+
 function TToolManager.GetMaxDeformationGridSize: TSize;
 function TToolManager.GetMaxDeformationGridSize: TSize;
 begin
 begin
   result.cx := Max(MinDeformationGridSize,Min(image.Width div 2,50)+1);
   result.cx := Max(MinDeformationGridSize,Min(image.Width div 2,50)+1);

+ 6 - 0
lazpaint/tools/utooltext.pas

@@ -31,6 +31,7 @@ type
     procedure QuickDefineEnd; override;
     procedure QuickDefineEnd; override;
     function RoundCoordinate(constref ptF: TPointF): TPointF; override;
     function RoundCoordinate(constref ptF: TPointF): TPointF; override;
     function DoToolKeyDown(var key: Word): TRect; override;
     function DoToolKeyDown(var key: Word): TRect; override;
+    function GetIsEditingText: boolean; override;
   public
   public
     constructor Create(AManager: TToolManager); override;
     constructor Create(AManager: TToolManager); override;
     function GetContextualToolbars: TContextualToolbars; override;
     function GetContextualToolbars: TContextualToolbars; override;
@@ -249,6 +250,11 @@ begin
     Manager.TextAlign := (FShape as TTextShape).ParagraphAlignment;
     Manager.TextAlign := (FShape as TTextShape).ParagraphAlignment;
 end;
 end;
 
 
+function TToolText.GetIsEditingText: boolean;
+begin
+  Result:= Assigned(FShape) and (FShape.Usermode = vsuEditText);
+end;
+
 function TToolText.ToolCommand(ACommand: TToolCommand): boolean;
 function TToolText.ToolCommand(ACommand: TToolCommand): boolean;
 begin
 begin
   if Assigned(FShape) and (FShape.Usermode = vsuEditText) then
   if Assigned(FShape) and (FShape.Usermode = vsuEditText) then

+ 6 - 0
lazpaint/tools/utoolvectorial.pas

@@ -89,6 +89,7 @@ type
     function GetIsBackEditGradTexPoints: boolean; override;
     function GetIsBackEditGradTexPoints: boolean; override;
     function GetIsOutlineEditGradTexPoints: boolean; override;
     function GetIsOutlineEditGradTexPoints: boolean; override;
     function GetGridMatrix: TAffineMatrix; virtual;
     function GetGridMatrix: TAffineMatrix; virtual;
+    function GetIsEditingText: boolean; override;
     property Editor: TBGRAOriginalEditor read GetEditor;
     property Editor: TBGRAOriginalEditor read GetEditor;
   public
   public
     class procedure ForgetHintShown;
     class procedure ForgetHintShown;
@@ -1825,6 +1826,11 @@ begin
   end;
   end;
 end;
 end;
 
 
+function TVectorialTool.GetIsEditingText: boolean;
+begin
+  Result:= assigned(FShape) and (FShape.Usermode = vsuEditText);
+end;
+
 class procedure TVectorialTool.ForgetHintShown;
 class procedure TVectorialTool.ForgetHintShown;
 begin
 begin
   SquareHintShown:= false;
   SquareHintShown:= false;

+ 8 - 4
lazpaint/upalettetoolbar.pas

@@ -423,16 +423,20 @@ begin
       ToggleBindColorToKey(c, digit);
       ToggleBindColorToKey(c, digit);
       PaletteChanged;
       PaletteChanged;
       FLazPaintInstance.NotifyColorBinding;
       FLazPaintInstance.NotifyColorBinding;
+      Result := True;
+      AKey := 0; // prevent further key event
     end else
     end else
     begin
     begin
-      if TryToGetColorBoundToKey(digit, c) then
+      if not FLazPaintInstance.ToolManager.IsEditingText and TryToGetColorBoundToKey(digit, c) then
       begin
       begin
         if FAltPressed then DoPickColor([ssRight], c)
         if FAltPressed then DoPickColor([ssRight], c)
         else DoPickColor([ssLeft], c);
         else DoPickColor([ssLeft], c);
-      end;
+        Result := True;
+        AKey := 0; // prevent further key event
+      end
+      else
+        result := false;
     end;
     end;
-    Result := True;
-    AKey := 0; // prevent further key event
   end else Result := False;
   end else Result := False;
 end;
 end;