浏览代码

script tool option (partially done)

johann 5 年之前
父节点
当前提交
ab022e284d

+ 1 - 1
lazpaint/lazpaintinstance.pas

@@ -318,7 +318,7 @@ begin
   FImage := TLazPaintImage.Create;
   FImage := TLazPaintImage.Create;
   FImage.OnStackChanged:= @OnStackChanged;
   FImage.OnStackChanged:= @OnStackChanged;
   FImage.OnException := @OnFunctionException;
   FImage.OnException := @OnFunctionException;
-  FToolManager := TToolManager.Create(FImage, self, nil, BlackAndWhite);
+  FToolManager := TToolManager.Create(FImage, self, nil, BlackAndWhite, FScriptContext);
   UseConfig(TIniFile.Create(''));
   UseConfig(TIniFile.Create(''));
   FToolManager.OnPopup := @OnToolPopup;
   FToolManager.OnPopup := @OnToolPopup;
   FToolManager.OnColorChanged:=@ToolColorChanged;
   FToolManager.OnColorChanged:=@ToolColorChanged;

+ 10 - 10
lazpaint/lazpaintmainform.pas

@@ -21,9 +21,6 @@ uses
 
 
   laztablet, udarktheme, UScriptType;
   laztablet, udarktheme, UScriptType;
 
 
-const
-  MinPenWidthValue = 10;
-
 type
 type
   { TFMain }
   { TFMain }
 
 
@@ -699,6 +696,7 @@ type
     procedure ManagerTextureChanged(Sender: TObject);
     procedure ManagerTextureChanged(Sender: TObject);
     procedure ManagerShapeOptionChanged(Sender: TObject);
     procedure ManagerShapeOptionChanged(Sender: TObject);
     procedure ManagerToleranceChanged(Sender: TObject);
     procedure ManagerToleranceChanged(Sender: TObject);
+    procedure ManagerToolbarChanged(Sender: TObject);
   private
   private
     { private declarations }
     { private declarations }
     FLayout: TMainFormLayout;
     FLayout: TMainFormLayout;
@@ -1007,6 +1005,7 @@ begin
   If Assigned(ToolManager) then
   If Assigned(ToolManager) then
   begin
   begin
     if ToolManager.OnToolChanged = @ManagerToolChanged then ToolManager.OnToolChanged := nil;
     if ToolManager.OnToolChanged = @ManagerToolChanged then ToolManager.OnToolChanged := nil;
+    if ToolManager.OnToolbarChanged = @ManagerToolbarChanged then ToolManager.OnToolbarChanged := nil;
     if ToolManager.OnTextureChanged = @ManagerTextureChanged then ToolManager.OnTextureChanged := nil;
     if ToolManager.OnTextureChanged = @ManagerTextureChanged then ToolManager.OnTextureChanged := nil;
     if ToolManager.OnEraserChanged = @ManagerEraserChanged then ToolManager.OnEraserChanged := nil;
     if ToolManager.OnEraserChanged = @ManagerEraserChanged then ToolManager.OnEraserChanged := nil;
     if ToolManager.OnPenWidthChanged = @ManagerPenWidthChanged then ToolManager.OnPenWidthChanged := nil;
     if ToolManager.OnPenWidthChanged = @ManagerPenWidthChanged then ToolManager.OnPenWidthChanged := nil;
@@ -1088,6 +1087,7 @@ begin
 
 
   ToolManager.SetCurrentToolType(ptHand);
   ToolManager.SetCurrentToolType(ptHand);
   ToolManager.OnToolChanged  :=  @ManagerToolChanged;
   ToolManager.OnToolChanged  :=  @ManagerToolChanged;
+  ToolManager.OnToolbarChanged:=@ManagerToolbarChanged;
   ToolManager.OnTextureChanged := @ManagerTextureChanged;
   ToolManager.OnTextureChanged := @ManagerTextureChanged;
   ToolManager.OnEraserChanged:=@ManagerEraserChanged;
   ToolManager.OnEraserChanged:=@ManagerEraserChanged;
   ToolManager.OnPenWidthChanged:= @ManagerPenWidthChanged;
   ToolManager.OnPenWidthChanged:= @ManagerPenWidthChanged;
@@ -1158,7 +1158,7 @@ begin
   LazPaintInstance.ShowTopmost(FTopMostInfo);
   LazPaintInstance.ShowTopmost(FTopMostInfo);
   if Position = poDefault then LazPaintInstance.RestoreMainWindowPosition;
   if Position = poDefault then LazPaintInstance.RestoreMainWindowPosition;
 
 
-  FLayout.Arrange;
+  ToolManager.UpdateContextualToolbars;
   UpdateToolImage;
   UpdateToolImage;
   UpdateToolBar;
   UpdateToolBar;
   shouldArrangeOnResize := true;
   shouldArrangeOnResize := true;
@@ -2729,8 +2729,6 @@ procedure TFMain.ToolNoTextureExecute(Sender: TObject);
 begin
 begin
   try
   try
     ToolManager.SetTexture(nil);
     ToolManager.SetTexture(nil);
-    UpdateEditPicture;
-
   except
   except
     on ex:Exception do
     on ex:Exception do
       LazPaintInstance.ShowError(RemoveTrail(ToolNoTexture.Hint),ex.Message);
       LazPaintInstance.ShowError(RemoveTrail(ToolNoTexture.Hint),ex.Message);
@@ -3862,7 +3860,6 @@ begin
         newTex.FreeReference;
         newTex.FreeReference;
         newTex := nil;
         newTex := nil;
         result := true;
         result := true;
-        UpdateEditPicture;
         Config.SetDefaultTextureDirectory(ExtractFilePath(texFilename));
         Config.SetDefaultTextureDirectory(ExtractFilePath(texFilename));
       except
       except
         on ex:Exception do
         on ex:Exception do
@@ -3980,11 +3977,9 @@ procedure TFMain.ManagerToolChanged(sender: TToolManager; ANewTool: TPaintToolTy
 begin
 begin
   if self.Visible then
   if self.Visible then
   begin
   begin
-    FLayout.Arrange;
     PaintBox_PenPreview.Invalidate;
     PaintBox_PenPreview.Invalidate;
     Image.OnImageChanged.NotifyObservers;
     Image.OnImageChanged.NotifyObservers;
     UpdateToolImage;
     UpdateToolImage;
-    UpdateToolBar;
     UpdatePenWidthToolbar;
     UpdatePenWidthToolbar;
     UpdateCurveModeToolbar;
     UpdateCurveModeToolbar;
   end;
   end;
@@ -4367,7 +4362,7 @@ end;
 procedure TFMain.ManagerShapeOptionChanged(Sender: TObject);
 procedure TFMain.ManagerShapeOptionChanged(Sender: TObject);
 begin
 begin
   UpdateToolOptions;
   UpdateToolOptions;
-  FLayout.Arrange;
+  ToolManager.UpdateContextualToolbars;
 end;
 end;
 
 
 procedure TFMain.ManagerToleranceChanged(Sender: TObject);
 procedure TFMain.ManagerToleranceChanged(Sender: TObject);
@@ -4375,6 +4370,11 @@ begin
   UpdateToleranceToolbar;
   UpdateToleranceToolbar;
 end;
 end;
 
 
+procedure TFMain.ManagerToolbarChanged(Sender: TObject);
+begin
+  if Assigned(FLayout) then FLayout.Arrange;
+end;
+
 procedure TFMain.UpdateStatusText;
 procedure TFMain.UpdateStatusText;
 var s: string;
 var s: string;
 begin
 begin

+ 29 - 55
lazpaint/maintoolbar.inc

@@ -101,7 +101,7 @@ begin
   SpinEdit_Tolerance.OnChange := @SpinEdit_ToleranceChange;
   SpinEdit_Tolerance.OnChange := @SpinEdit_ToleranceChange;
 
 
   SpinEdit_PenWidth.MinValue := 1;
   SpinEdit_PenWidth.MinValue := 1;
-  SpinEdit_PenWidth.MaxValue := 9999;
+  SpinEdit_PenWidth.MaxValue := round(MaxPenWidth*10);
   SpinEdit_PenWidth.Increment := 10;
   SpinEdit_PenWidth.Increment := 10;
   SpinEdit_PenWidth.OnChange := @SpinEdit_PenWidthChange;
   SpinEdit_PenWidth.OnChange := @SpinEdit_PenWidthChange;
   SpinEdit_PenWidth.OnMouseMove := @SpinEdit_PenWidthMouseMove;
   SpinEdit_PenWidth.OnMouseMove := @SpinEdit_PenWidthMouseMove;
@@ -182,7 +182,7 @@ begin
   SpinEdit_ShapeAltitude.OnChange := @SpinEdit_ShapeAltitudeChange;
   SpinEdit_ShapeAltitude.OnChange := @SpinEdit_ShapeAltitudeChange;
 
 
   SpinEdit_BrushSpacing.MinValue := 1;
   SpinEdit_BrushSpacing.MinValue := 1;
-  SpinEdit_BrushSpacing.MaxValue := 99;
+  SpinEdit_BrushSpacing.MaxValue := MaxBrushSpacing;
   SpinEdit_BrushSpacing.Value := 1;
   SpinEdit_BrushSpacing.Value := 1;
   SpinEdit_BrushSpacing.Increment := 1;
   SpinEdit_BrushSpacing.Increment := 1;
   SpinEdit_BrushSpacing.OnChange := @SpinEdit_BrushSpacingChange;
   SpinEdit_BrushSpacing.OnChange := @SpinEdit_BrushSpacingChange;
@@ -395,7 +395,8 @@ end;
 
 
 procedure TFMain.UpdateTextFontToolbar;
 procedure TFMain.UpdateTextFontToolbar;
 begin
 begin
-  SpinEdit_TextSize.Value := ToolManager.TextFontSize;
+  if FInTextFont then exit;
+  SpinEdit_TextSize.Value := round(ToolManager.TextFontSize);
   UpdateTextSizeIncrement;
   UpdateTextSizeIncrement;
 end;
 end;
 
 
@@ -549,9 +550,16 @@ begin
 end;
 end;
 
 
 procedure TFMain.UpdateLineCapBar;
 procedure TFMain.UpdateLineCapBar;
+var
+  newVisible: Boolean;
 begin
 begin
-  Panel_LineCap.Visible := Panel_CloseShape.Visible and not (toCloseShape in ToolManager.ShapeOptions) and
+  newVisible := Panel_CloseShape.Visible and not (toCloseShape in ToolManager.ShapeOptions) and
     (toDrawShape in ToolManager.ShapeOptions);
     (toDrawShape in ToolManager.ShapeOptions);
+  if newVisible <> Panel_LineCap.Visible then
+  begin
+    Panel_LineCap.Visible := newVisible;
+    if Assigned(FLayout) then FLayout.Arrange;
+  end;
 end;
 end;
 
 
 procedure TFMain.UpdateToolImage(AForceUpdate: boolean);
 procedure TFMain.UpdateToolImage(AForceUpdate: boolean);
@@ -683,11 +691,12 @@ procedure TFMain.SpinEdit_TextSizeChange(Sender: TObject; AByUser: boolean);
 begin
 begin
   if AByUser and initialized and not FInTextFont then
   if AByUser and initialized and not FInTextFont then
   begin
   begin
-    if ToolManager.TextFontSize = SpinEdit_TextSize.Value then exit;
+    if round(ToolManager.TextFontSize) = SpinEdit_TextSize.Value then exit;
+    FInTextFont:= true;
     ToolManager.SetTextFont(ToolManager.TextFontName,
     ToolManager.SetTextFont(ToolManager.TextFontName,
       SpinEdit_TextSize.Value, ToolManager.TextFontStyle);
       SpinEdit_TextSize.Value, ToolManager.TextFontStyle);
     UpdateTextSizeIncrement;
     UpdateTextSizeIncrement;
-    UpdateEditPicture(True);
+    FInTextFont:= false;
     FActiveSpinEdit := SpinEdit_TextSize;
     FActiveSpinEdit := SpinEdit_TextSize;
   end;
   end;
 end;
 end;
@@ -720,8 +729,7 @@ procedure TFMain.GridNb_SpinEditChange(Sender: TObject; AByUser: boolean);
 begin
 begin
   if not AByUser or not initialized then exit;
   if not AByUser or not initialized then exit;
   FInGridNb := true;
   FInGridNb := true;
-  if ToolManager.SetDeformationGridSize(Size(SpinEdit_GridNbX.Value+1,SpinEdit_GridNbY.Value+1)) then
-    image.OnImageChanged.NotifyObservers;
+  ToolManager.SetDeformationGridSize(Size(SpinEdit_GridNbX.Value+1,SpinEdit_GridNbY.Value+1));
   FInGridNb := false;
   FInGridNb := false;
 end;
 end;
 
 
@@ -744,13 +752,7 @@ end;
 procedure TFMain.SpinEdit_TextOutlineWidthChange(Sender: TObject; AByUser: boolean);
 procedure TFMain.SpinEdit_TextOutlineWidthChange(Sender: TObject; AByUser: boolean);
 begin
 begin
   if AByUser and initialized then
   if AByUser and initialized then
-  begin
-     if ToolManager.TextOutlineWidth <> SpinEdit_TextOutlineWidth.Value/PenWidthFactor then
-     begin
-       ToolManager.SetTextOutline(ToolManager.TextOutline, SpinEdit_TextOutlineWidth.Value/PenWidthFactor);
-       UpdateEditPicture;
-     end;
-  end;
+    ToolManager.SetTextOutline(ToolManager.TextOutline, SpinEdit_TextOutlineWidth.Value/PenWidthFactor);
 end;
 end;
 
 
 procedure TFMain.SpinEdit_TextShadowXChange(Sender: TObject; AByUser: boolean);
 procedure TFMain.SpinEdit_TextShadowXChange(Sender: TObject; AByUser: boolean);
@@ -858,11 +860,7 @@ procedure TFMain.ShowColorDialogForBack;
 begin
 begin
   ColorDialog1.Color := BGRAToColor(ToolManager.BackColor);
   ColorDialog1.Color := BGRAToColor(ToolManager.BackColor);
   if ColorDialog1.Execute then
   if ColorDialog1.Execute then
-  begin
     ToolManager.BackColor := ColorToBGRA(ColorDialog1.Color,ToolManager.BackColor.alpha);
     ToolManager.BackColor := ColorToBGRA(ColorDialog1.Color,ToolManager.BackColor.alpha);
-    LazPaintInstance.ColorToFChooseColor;
-    UpdateEditPicture;
-  end;
 end;
 end;
 
 
 procedure TFMain.SpinEdit_BackOpacityChange(Sender: TObject; AByUser: boolean);
 procedure TFMain.SpinEdit_BackOpacityChange(Sender: TObject; AByUser: boolean);
@@ -872,8 +870,6 @@ begin
     if ToolManager.BackColor.alpha = SpinEdit_BackOpacity.value then exit;
     if ToolManager.BackColor.alpha = SpinEdit_BackOpacity.value then exit;
     with ToolManager.BackColor do
     with ToolManager.BackColor do
       ToolManager.BackColor := BGRA(red,green,blue,SpinEdit_BackOpacity.value);
       ToolManager.BackColor := BGRA(red,green,blue,SpinEdit_BackOpacity.value);
-    LazPaintInstance.ColorToFChooseColor;
-    UpdateEditPicture;
   end;
   end;
 end;
 end;
 
 
@@ -908,7 +904,6 @@ begin
       ToolManager.ShapeOptions := ToolManager.ShapeOptions + [toAliasing]
       ToolManager.ShapeOptions := ToolManager.ShapeOptions + [toAliasing]
     else
     else
       ToolManager.ShapeOptions := ToolManager.ShapeOptions - [toAliasing];
       ToolManager.ShapeOptions := ToolManager.ShapeOptions - [toAliasing];
-    UpdateEditPicture;
   end;
   end;
 end;
 end;
 
 
@@ -924,9 +919,7 @@ begin
      if Tool_DrawShapeBorder.Down then include(opt, toDrawShape) else exclude(opt, toDrawShape);
      if Tool_DrawShapeBorder.Down then include(opt, toDrawShape) else exclude(opt, toDrawShape);
      if Tool_FillShape.Down then include(opt, toFillShape) else exclude(opt, toFillShape);
      if Tool_FillShape.Down then include(opt, toFillShape) else exclude(opt, toFillShape);
      ToolManager.ShapeOptions := opt;
      ToolManager.ShapeOptions := opt;
-     ToolManager.UpdateContextualToolbars;
      FLayout.Arrange;
      FLayout.Arrange;
-     UpdateEditPicture;
   end;
   end;
 end;
 end;
 
 
@@ -942,9 +935,6 @@ begin
      if Tool_DrawShapeBorder.Down then include(opt, toDrawShape) else exclude(opt, toDrawShape);
      if Tool_DrawShapeBorder.Down then include(opt, toDrawShape) else exclude(opt, toDrawShape);
      if Tool_FillShape.Down then include(opt, toFillShape) else exclude(opt, toFillShape);
      if Tool_FillShape.Down then include(opt, toFillShape) else exclude(opt, toFillShape);
      ToolManager.ShapeOptions := opt;
      ToolManager.ShapeOptions := opt;
-     ToolManager.UpdateContextualToolbars;
-     FLayout.Arrange;
-     UpdateEditPicture;
   end;
   end;
 end;
 end;
 
 
@@ -958,8 +948,6 @@ begin
           ToolManager.ShapeOptions := ToolManager.ShapeOptions + [toCloseShape]
           ToolManager.ShapeOptions := ToolManager.ShapeOptions + [toCloseShape]
         else
         else
           ToolManager.ShapeOptions := ToolManager.ShapeOptions - [toCloseShape];
           ToolManager.ShapeOptions := ToolManager.ShapeOptions - [toCloseShape];
-       FLayout.Arrange;
-       UpdateEditPicture;
      end;
      end;
   end;
   end;
 end;
 end;
@@ -1069,10 +1057,7 @@ begin
   begin
   begin
     newPS := TPenStyle(cb.ItemIndex);
     newPS := TPenStyle(cb.ItemIndex);
     if newPS <> ToolManager.PenStyle then
     if newPS <> ToolManager.PenStyle then
-    begin
       ToolManager.PenStyle := newPS;
       ToolManager.PenStyle := newPS;
-      UpdateEditPicture;
-    end;
   end;
   end;
 end;
 end;
 
 
@@ -1130,28 +1115,19 @@ end;
 procedure TFMain.Tool_JoinBevelClick(Sender: TObject);
 procedure TFMain.Tool_JoinBevelClick(Sender: TObject);
 begin
 begin
   if Tool_JoinBevel.Down then
   if Tool_JoinBevel.Down then
-  begin
     ToolManager.JoinStyle := pjsBevel;
     ToolManager.JoinStyle := pjsBevel;
-    UpdateEditPicture;
-  end;
 end;
 end;
 
 
 procedure TFMain.Tool_JoinRoundClick(Sender: TObject);
 procedure TFMain.Tool_JoinRoundClick(Sender: TObject);
 begin
 begin
   if Tool_JoinRound.Down then
   if Tool_JoinRound.Down then
-  begin
     ToolManager.JoinStyle := pjsRound;
     ToolManager.JoinStyle := pjsRound;
-    UpdateEditPicture;
-  end;
 end;
 end;
 
 
 procedure TFMain.Tool_JoinMiterClick(Sender: TObject);
 procedure TFMain.Tool_JoinMiterClick(Sender: TObject);
 begin
 begin
   if Tool_JoinMiter.Down then
   if Tool_JoinMiter.Down then
-  begin
     ToolManager.JoinStyle := pjsMiter;
     ToolManager.JoinStyle := pjsMiter;
-    UpdateEditPicture;
-  end;
 end;
 end;
 
 
 procedure TFMain.SpinEdit_EraserChange(Sender: TObject; AByUser: boolean);
 procedure TFMain.SpinEdit_EraserChange(Sender: TObject; AByUser: boolean);
@@ -1338,29 +1314,31 @@ begin
 end;
 end;
 
 
 procedure TFMain.UpdatePenWidthFromSpinEdit;
 procedure TFMain.UpdatePenWidthFromSpinEdit;
+var
+  newWidth: single;
 begin
 begin
-  if round(ToolManager.PenWidth*PenWidthFactor) = max(SpinEdit_PenWidth.Value,MinPenWidthValue) then exit;
+  newWidth := max(SpinEdit_PenWidth.Value/PenWidthFactor, MinPenWidth);
+  if newWidth = ToolManager.PenWidth then exit;
   FInPenWidthChange:= true;
   FInPenWidthChange:= true;
-  ToolManager.PenWidth := max(SpinEdit_PenWidth.Value,MinPenWidthValue)/PenWidthFactor;
+  ToolManager.PenWidth := newWidth;
   ShowPenPreview(True);
   ShowPenPreview(True);
-  UpdateEditPicture;
   FInPenWidthChange:= false;
   FInPenWidthChange:= false;
 end;
 end;
 
 
 procedure TFMain.SpinEdit_PenWidthExit(Sender: TObject);
 procedure TFMain.SpinEdit_PenWidthExit(Sender: TObject);
 begin
 begin
-  if SpinEdit_PenWidth.Value < MinPenWidthValue then SpinEdit_PenWidth.Value := MinPenWidthValue;
+  if SpinEdit_PenWidth.Value < MinPenWidth*PenWidthFactor then SpinEdit_PenWidth.Value := MinPenWidth*PenWidthFactor;
 end;
 end;
 
 
 procedure TFMain.IncreasePenSize;
 procedure TFMain.IncreasePenSize;
 begin
 begin
-  SpinEdit_PenWidth.Value := max(SpinEdit_PenWidth.Value+PenSizeDelta(1),MinPenWidthValue);
+  SpinEdit_PenWidth.Value := max(SpinEdit_PenWidth.Value+PenSizeDelta(1),MinPenWidth*PenWidthFactor);
   UpdatePenWidthFromSpinEdit;
   UpdatePenWidthFromSpinEdit;
 end;
 end;
 
 
 procedure TFMain.DecreasePenSize;
 procedure TFMain.DecreasePenSize;
 begin
 begin
-  SpinEdit_PenWidth.Value := max(SpinEdit_PenWidth.Value-PenSizeDelta(-1),MinPenWidthValue);
+  SpinEdit_PenWidth.Value := max(SpinEdit_PenWidth.Value-PenSizeDelta(-1),MinPenWidth*PenWidthFactor);
   UpdatePenWidthFromSpinEdit;
   UpdatePenWidthFromSpinEdit;
 end;
 end;
 
 
@@ -1602,7 +1580,9 @@ procedure TFMain.Tool_TextFontClick(Sender: TObject);
 var topmostInfo: TTopMostInfo;
 var topmostInfo: TTopMostInfo;
 begin
 begin
   FInTextFont := true;
   FInTextFont := true;
-  FontDialog1.Font.Assign(ToolManager.GetTextFont);
+  FontDialog1.Font.Name := ToolManager.TextFontName;
+  FontDialog1.Font.Size := round(ToolManager.TextFontSize);
+  FontDialog1.Font.Style := ToolManager.TextFontStyle;
   FontDialog1.Font.Color := BGRAToColor(ToolManager.ForeColor);
   FontDialog1.Font.Color := BGRAToColor(ToolManager.ForeColor);
   topmostInfo := LazPaintInstance.HideTopmost;
   topmostInfo := LazPaintInstance.HideTopmost;
   if FontDialog1.Execute then
   if FontDialog1.Execute then
@@ -1661,13 +1641,7 @@ end;
 procedure TFMain.Tool_TextOutlineClick(Sender: TObject);
 procedure TFMain.Tool_TextOutlineClick(Sender: TObject);
 begin
 begin
   if initialized then
   if initialized then
-  begin
-     if ToolManager.TextOutline <> Tool_TextOutline.Down then
-     begin
-       ToolManager.SetTextOutline(Tool_TextOutline.Down, ToolManager.TextOutlineWidth);
-       UpdateEditPicture;
-     end;
-  end;
+    ToolManager.SetTextOutline(Tool_TextOutline.Down, ToolManager.TextOutlineWidth);
 end;
 end;
 
 
 procedure TFMain.ComboBox_BrushSelectDrawItem(Control: TWinControl;
 procedure TFMain.ComboBox_BrushSelectDrawItem(Control: TWinControl;

文件差异内容过多而无法显示
+ 527 - 67
lazpaint/tools/utool.pas


+ 15 - 9
lazpaint/tools/utooldeformationgrid.pas

@@ -30,12 +30,12 @@ type
     function DoToolMove({%H-}toolDest: TBGRABitmap; {%H-}pt: TPoint; ptF: TPointF): Trect;
     function DoToolMove({%H-}toolDest: TBGRABitmap; {%H-}pt: TPoint; ptF: TPointF): Trect;
       override;
       override;
     function GetIsSelectingTool: boolean; override;
     function GetIsSelectingTool: boolean; override;
+    function DoToolUpdate(toolDest: TBGRABitmap): TRect; override;
   public
   public
     function ToolKeyDown(var key: Word): TRect; override;
     function ToolKeyDown(var key: Word): TRect; override;
     function ToolUp: TRect; override;
     function ToolUp: TRect; override;
     function GetContextualToolbars: TContextualToolbars; override;
     function GetContextualToolbars: TContextualToolbars; override;
     function Render(VirtualScreen: TBGRABitmap; {%H-}VirtualScreenWidth, {%H-}VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; override;
     function Render(VirtualScreen: TBGRABitmap; {%H-}VirtualScreenWidth, {%H-}VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; override;
-    procedure AfterGridSizeChange({%H-}NewNbX,{%H-}NewNbY: Integer); override;
     function ToolCommand(ACommand: TToolCommand): boolean; override;
     function ToolCommand(ACommand: TToolCommand): boolean; override;
     function ToolProvideCommand(ACommand: TToolCommand): boolean; override;
     function ToolProvideCommand(ACommand: TToolCommand): boolean; override;
     destructor Destroy; override;
     destructor Destroy; override;
@@ -837,14 +837,6 @@ begin
   result := true;
   result := true;
 end;
 end;
 
 
-procedure TToolDeformationGrid.AfterGridSizeChange(NewNbX,NewNbY: Integer);
-begin
-  ReleaseGrid;
-  DeformationGrid := nil;
-  DeformationGridTexCoord := nil;
-  //grid will be created when needed
-end;
-
 function TToolDeformationGrid.ToolCommand(ACommand: TToolCommand): boolean;
 function TToolDeformationGrid.ToolCommand(ACommand: TToolCommand): boolean;
 begin
 begin
   case ACommand of
   case ACommand of
@@ -1059,6 +1051,20 @@ begin
   Result:= false;
   Result:= false;
 end;
 end;
 
 
+function TToolDeformationGrid.DoToolUpdate(toolDest: TBGRABitmap): TRect;
+begin
+  if (deformationGridNbX <> Manager.DeformationGridNbX) or
+     (deformationGridNbY <> Manager.DeformationGridNbY) then
+  begin
+    ReleaseGrid;
+    DeformationGrid := nil;
+    DeformationGridTexCoord := nil;
+    Result:= OnlyRenderChange;
+  end
+  else
+    result := EmptyRect;
+end;
+
 function TToolDeformationGrid.Render(VirtualScreen: TBGRABitmap;
 function TToolDeformationGrid.Render(VirtualScreen: TBGRABitmap;
   VirtualScreenWidth, VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect;
   VirtualScreenWidth, VirtualScreenHeight: integer; BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect;
 var curPt,rightPt,downPt: TPointF;
 var curPt,rightPt,downPt: TPointF;

+ 10 - 11
lazpaint/uconfig.pas

@@ -211,7 +211,7 @@ type
     function DefaultToolTextShadow: boolean;
     function DefaultToolTextShadow: boolean;
     procedure SetDefaultToolTextShadow(value: boolean);
     procedure SetDefaultToolTextShadow(value: boolean);
     function DefaultToolTextFont: TFont;
     function DefaultToolTextFont: TFont;
-    procedure SetDefaultToolTextFont(AFont: TFont);
+    procedure SetDefaultToolTextFont(AName: string; ASize: single; AStyle: TFontStyles);
     function DefaultToolTextBlur: single;
     function DefaultToolTextBlur: single;
     procedure SetDefaultToolTextBlur(value: single);
     procedure SetDefaultToolTextBlur(value: single);
     function DefaultToolTextShadowOffsetX: integer;
     function DefaultToolTextShadowOffsetX: integer;
@@ -893,17 +893,16 @@ begin
   result := tempFont;
   result := tempFont;
 end;
 end;
 
 
-procedure TLazPaintConfig.SetDefaultToolTextFont(AFont: TFont);
+procedure TLazPaintConfig.SetDefaultToolTextFont(AName: string; ASize: single;
+  AStyle: TFontStyles);
 begin
 begin
-  tempFont.Assign(AFont);
-
-  iniOptions.WriteString('Tool','TextFontName',tempFont.Name);
-  iniOptions.WriteInteger('Tool','TextFontHeight',tempFont.Height);
-  iniOptions.WriteInteger('Tool','TextFontSize',tempFont.Size);
-  iniOptions.WriteBool('Tool','TextFontBold',fsBold in tempFont.Style);
-  iniOptions.WriteBool('Tool','TextFontItalic',fsItalic in tempFont.Style);
-  iniOptions.WriteBool('Tool','TextFontStrikeOut',fsStrikeOut in tempFont.Style);
-  iniOptions.WriteBool('Tool','TextFontUnderline',fsUnderline in tempFont.Style);
+  iniOptions.WriteString('Tool','TextFontName',AName);
+  iniOptions.WriteInteger('Tool','TextFontSize',round(ASize));
+  iniOptions.DeleteKey('Tool','TextFontHeight');
+  iniOptions.WriteBool('Tool','TextFontBold',fsBold in AStyle);
+  iniOptions.WriteBool('Tool','TextFontItalic',fsItalic in AStyle);
+  iniOptions.WriteBool('Tool','TextFontStrikeOut',fsStrikeOut in AStyle);
+  iniOptions.WriteBool('Tool','TextFontUnderline',fsUnderline in AStyle);
 end;
 end;
 
 
 function TLazPaintConfig.DefaultToolTextBlur: single;
 function TLazPaintConfig.DefaultToolTextBlur: single;

+ 0 - 2
lazpaint/upalettetoolbar.pas

@@ -636,8 +636,6 @@ begin
       LazPaintInstance.ToolManager.BackColor := c;
       LazPaintInstance.ToolManager.BackColor := c;
     end else
     end else
         exit;
         exit;
-    LazPaintInstance.UpdateToolbar;
-    LazPaintInstance.UpdateEditPicture(False);
   end;
   end;
 end;
 end;
 
 

+ 55 - 12
lazpaint/uscripttype.pas

@@ -31,10 +31,10 @@ type
   TInterpretationError = (ieTooManyClosingBrackets, ieEndingQuoteNotFound, ieOpeningBracketNotFound, ieClosingBracketNotFound,
   TInterpretationError = (ieTooManyClosingBrackets, ieEndingQuoteNotFound, ieOpeningBracketNotFound, ieClosingBracketNotFound,
                           ieConstantExpressionExpected, ieUnexpectedChar, ieInvalidNumber, ieInvalidColor, ieInvalidBoolean,
                           ieConstantExpressionExpected, ieUnexpectedChar, ieInvalidNumber, ieInvalidColor, ieInvalidBoolean,
                           ieDuplicateIdentifier, ieUnexpectedOpeningBracketKind, ieUnexpectedClosingBracketKind,
                           ieDuplicateIdentifier, ieUnexpectedOpeningBracketKind, ieUnexpectedClosingBracketKind,
-                          ieUnknownListType, ieMissingValue);
+                          ieUnknownListType, ieMissingValue, ieTooManyValues);
   TInterpretationErrors = set of TInterpretationError;
   TInterpretationErrors = set of TInterpretationError;
-  TScriptVariableType = (svtUndefined, svtFloat, svtInteger, svtBoolean, svtString, svtPixel, svtSubset,
-                         svtFloatList, svtIntList, svtBoolList, svtStrList, svtPixList);
+  TScriptVariableType = (svtUndefined, svtFloat, svtInteger, svtPoint, svtBoolean, svtString, svtPixel, svtSubset,
+                         svtFloatList, svtIntList, svtPointList, svtBoolList, svtStrList, svtPixList);
   TScriptFunctionExceptionHandler = procedure(AFunctionName: string; AException: Exception) of object;
   TScriptFunctionExceptionHandler = procedure(AFunctionName: string; AException: Exception) of object;
 
 
   TParsedLitteral = record
   TParsedLitteral = record
@@ -44,6 +44,7 @@ type
     valueBool: boolean;
     valueBool: boolean;
     valueStr: string;
     valueStr: string;
     valuePixel: TBGRAPixel;
     valuePixel: TBGRAPixel;
+    valuePoint: TPoint3D;
   end;
   end;
 
 
   TScalarVariable = record
   TScalarVariable = record
@@ -51,6 +52,7 @@ type
     varType: TScriptVariableType;
     varType: TScriptVariableType;
     case TScriptVariableType of
     case TScriptVariableType of
       svtFloat: (valueFloat: double);
       svtFloat: (valueFloat: double);
+      svtPoint: (valuePoint: TPoint3D);
       svtInteger: (valueInt: TScriptInteger);
       svtInteger: (valueInt: TScriptInteger);
       svtBoolean: (valueBool: boolean);
       svtBoolean: (valueBool: boolean);
       svtPixel: (valuePix: TBGRAPixel);
       svtPixel: (valuePix: TBGRAPixel);
@@ -58,15 +60,15 @@ type
   end;
   end;
 
 
 const
 const
-  ScriptVariableListTypes : set of TScriptVariableType = [svtFloatList, svtIntList, svtBoolList, svtStrList, svtPixList];
-  ScriptScalarListTypes : set of TScriptVariableType = [svtFloatList, svtIntList, svtPixList];
-  ScriptScalarTypes : set of TScriptVariableType = [svtFloat, svtInteger, svtBoolean, svtPixel];
+  ScriptVariableListTypes : set of TScriptVariableType = [svtFloatList, svtIntList, svtPointList, svtBoolList, svtStrList, svtPixList];
+  ScriptScalarListTypes : set of TScriptVariableType = [svtFloatList, svtIntList, svtPointList, svtPixList];
+  ScriptScalarTypes : set of TScriptVariableType = [svtFloat, svtInteger, svtPoint, svtBoolean, svtPixel];
   ScalarListElementSize : array[svtFloatList..svtPixList] of NativeInt =
   ScalarListElementSize : array[svtFloatList..svtPixList] of NativeInt =
-    (sizeof(double), sizeof(TScriptInteger), 0, 0, sizeof(TBGRAPixel));
+    (sizeof(double), sizeof(TScriptInteger), sizeof(TPoint3D), 0, 0, sizeof(TBGRAPixel));
   ListElementType : array[svtFloatList..svtPixList] of TScriptVariableType =
   ListElementType : array[svtFloatList..svtPixList] of TScriptVariableType =
-    (svtFloat, svtInteger, svtBoolean, svtString, svtPixel);
+    (svtFloat, svtInteger, svtPoint, svtBoolean, svtString, svtPixel);
   EmptyListExpression : array[svtFloatList..svtPixList] of string =
   EmptyListExpression : array[svtFloatList..svtPixList] of string =
-    ('[~0.0]', '[~0]', '[~False]', '[~""]','[~#000]');
+    ('[~0.0]', '[~0]', '[(0.0,0.0)]', '[~False]', '[~""]','[~#000]');
   InterpretationErrorToStr: array[TInterpretationError] of string =
   InterpretationErrorToStr: array[TInterpretationError] of string =
     ('Too many closing brackets', 'Ending quote not found',
     ('Too many closing brackets', 'Ending quote not found',
      'Opening bracket not found', 'Closing bracket not found',
      'Opening bracket not found', 'Closing bracket not found',
@@ -74,7 +76,7 @@ const
      'Invalid number', 'Invalid color', 'Invalid boolean',
      'Invalid number', 'Invalid color', 'Invalid boolean',
      'Duplicate identifier', 'Unexpected opening bracket kind',
      'Duplicate identifier', 'Unexpected opening bracket kind',
      'Unexpected closing bracket kind',
      'Unexpected closing bracket kind',
-     'Unknown list type', 'Missing value');
+     'Unknown list type', 'Missing value', 'Too many values');
 
 
 function ScriptQuote(const S: string): string;
 function ScriptQuote(const S: string): string;
 function ScriptUnquote(const S: string): string;
 function ScriptUnquote(const S: string): string;
@@ -147,6 +149,13 @@ begin
   case AVarType of
   case AVarType of
     svtFloat: result := FloatToStrUS(double(AValue));
     svtFloat: result := FloatToStrUS(double(AValue));
     svtInteger: result := IntToStr(TScriptInteger(AValue));
     svtInteger: result := IntToStr(TScriptInteger(AValue));
+    svtPoint: with TPoint3D(AValue) do
+              begin
+                if z <> EmptySingle then
+                  result := '(' + FloatToStrUS(x)+', '+FloatToStrUS(y)+', '+FloatToStrUS(z)+')'
+                else
+                  result := '(' + FloatToStrUS(x)+', '+FloatToStrUS(y)+')';
+              end;
     svtPixel: result := '#'+BGRAToStr(TBGRAPixel(AValue));
     svtPixel: result := '#'+BGRAToStr(TBGRAPixel(AValue));
     svtBoolean: result := BoolToStr(Boolean(AValue),TrueToken,FalseToken);
     svtBoolean: result := BoolToStr(Boolean(AValue),TrueToken,FalseToken);
   else raise exception.Create('Not a scalar type');
   else raise exception.Create('Not a scalar type');
@@ -192,7 +201,7 @@ var
   valueFloat: double;
   valueFloat: double;
   valueBool: boolean;
   valueBool: boolean;
   valuePixel: TBGRAPixel;
   valuePixel: TBGRAPixel;
-  errPos: integer;
+  errPos,coordIndex,posComma: integer;
   missingFlag,errorFlag: boolean;
   missingFlag,errorFlag: boolean;
 begin
 begin
   result.valueType := svtUndefined;
   result.valueType := svtUndefined;
@@ -273,7 +282,7 @@ begin
           if inBracket = 0 then IsPixel:= true;
           if inBracket = 0 then IsPixel:= true;
         end
         end
         else
         else
-        if expr[cur] = ',' then break;
+        if (expr[cur] in[',','}']) and (inBracket = 0) then break;
       end;
       end;
     end;
     end;
     previousChar:= expr[cur];
     previousChar:= expr[cur];
@@ -337,6 +346,40 @@ begin
       result.valueType:= svtPixel;
       result.valueType:= svtPixel;
       result.valuePixel := valuePixel;
       result.valuePixel := valuePixel;
     end;
     end;
+  end else
+  if (length(valueStr)>=2) and (valueStr[1] = '(') and (valueStr[length(valueStr)] = ')') then
+  begin
+    result.valuePoint:= Point3D(0,0,EmptySingle);
+    valueStr := trim(copy(valueStr,2,length(valueStr)-2));
+    coordIndex := 0;
+    while valueStr<>'' do
+    begin
+      if coordIndex >= 3 then
+      begin
+        errors := errors + [ieTooManyValues];
+        break;
+      end;
+      posComma := pos(',', valueStr);
+      if posComma > 0 then
+        val(copy(valueStr,1,posComma-1),valueFloat,errPos)
+      else
+        val(valueStr,valueFloat,errPos);
+      if errPos <> 0 then
+      begin
+        errors := errors + [ieInvalidNumber];
+        break;
+      end;
+      case coordIndex of
+        0: result.valuePoint.x := valueFloat;
+        1: result.valuePoint.y := valueFloat;
+        2: result.valuePoint.z := valueFloat;
+      end;
+      inc(coordIndex);
+      if posComma = 0 then valueStr := ''
+      else delete(valueStr, 1, posComma);
+    end;
+    if coordIndex >= 2 then
+      result.valueType:= svtPoint;
   end else
   end else
     errors := errors + [ieConstantExpressionExpected];
     errors := errors + [ieConstantExpressionExpected];
 end;
 end;

+ 66 - 0
scripts/lazpaint/tools.py

@@ -38,6 +38,24 @@ STATE_SHIFT = 'Shift'
 STATE_ALT = 'Alt'
 STATE_ALT = 'Alt'
 STATE_CTRL = 'Ctrl'
 STATE_CTRL = 'Ctrl'
 
 
+ERASER_MODE_ALPHA = 'EraseAlpha'
+ERASER_MODE_SOFTEN = 'Soften'
+
+PEN_STYLE_SOLD = 'Solid'
+PEN_STYLE_DASH = 'Dash'
+PEN_STYLE_DOT = 'Dot'
+PEN_STYLE_DASH_DOT = 'DashDot'
+PEN_STYLE_DASH_DOT_DOT = 'DashDotDot'
+
+JOIN_STYLE_BEVEL = 'Bevel'
+JOIN_STYLE_MITER = 'Miter'
+JOIN_STYLE_ROUND = 'Round'
+
+SHAPE_OPTION_ALIASING = 'Aliasing'
+SHAPE_OPTION_DRAW_SHAPE = 'DrawShape'
+SHAPE_OPTION_FILL_SHAPE = 'FillShape'
+SHAPE_OPTION_CLOSE_SHAPE = 'CloseShape'
+
 KEY_UNKNOWN = 'Unknown'
 KEY_UNKNOWN = 'Unknown'
 KEY_BACKSPACE = 'Backspace'
 KEY_BACKSPACE = 'Backspace'
 KEY_TAB = 'Tab'
 KEY_TAB = 'Tab'
@@ -140,3 +158,51 @@ def keys(keys, state=[]):
 def write(text):
 def write(text):
   command.send("ToolWrite", Text=text)
   command.send("ToolWrite", Text=text)
 
 
+def set_pen_color(color):
+  command.send("ToolSetPenColor", Color=color)
+
+def set_back_color(color):
+  command.send("ToolSetBackColor", Color=color)
+
+def get_pen_color():
+  return str_to_RGBA(command.send("ToolGetPenColor?"))
+
+def get_back_color():
+  return str_to_RGBA(command.send("ToolGetBackColor?"))
+
+def set_eraser_mode(mode):
+  command.send('ToolSetEraserMode', Mode=mode)
+
+def get_eraser_mode():
+  return command.send('ToolGetEraserMode?')
+
+def set_eraser_alpha(alpha):
+  command.send('ToolSetEraserAlpha', Alpha=alpha)
+
+def get_eraser_alpha():
+  return command.send('ToolGetEraserAlpha?')
+
+def set_pen_width(width):
+  command.send('ToolSetPenWidth', Width=width)
+
+def get_pen_width():
+  return command.send('ToolGetPenWidth?')
+
+def set_pen_style(style):
+  command.send('ToolSetPenStyle', Style=style)
+
+def get_pen_style():
+  return command.send('ToolGetPenStyle?')
+
+def set_join_style(style):
+  command.send('ToolSetJoinStyle', Style=style)
+
+def get_join_style():
+  return command.send('ToolGetJoinStyle?')
+
+def set_shape_options(options):
+  command.send('ToolSetShapeOptions', Options=options)
+
+def get_shape_options():
+  return command.send('ToolGetShapeOptions?')
+

+ 6 - 1
scripts/test_tools.py

@@ -1,17 +1,22 @@
-from lazpaint import tools, image, layer
+from lazpaint import tools, image, layer, colors
 
 
 image.new(800, 600)
 image.new(800, 600)
 
 
 tools.choose(tools.PEN)
 tools.choose(tools.PEN)
+tools.set_pen_color(colors.RED)
+tools.set_back_color(colors.ORANGE)
 tools.mouse( (50,50) )
 tools.mouse( (50,50) )
 tools.mouse( [(50,100, 0.5), (100,100, 0.5)], [tools.STATE_RIGHT] )
 tools.mouse( [(50,100, 0.5), (100,100, 0.5)], [tools.STATE_RIGHT] )
 
 
 tools.choose(tools.ELLIPSE)
 tools.choose(tools.ELLIPSE)
 tools.mouse( [(150,50), (250,150)], [tools.STATE_RIGHT] )
 tools.mouse( [(150,50), (250,150)], [tools.STATE_RIGHT] )
+tools.set_pen_color(colors.YELLOW)
+tools.set_back_color(colors.BLUE)
 tools.keys(tools.KEY_RETURN)
 tools.keys(tools.KEY_RETURN)
 
 
 tools.choose(tools.TEXT)
 tools.choose(tools.TEXT)
 tools.mouse( [(50,150), (450,350)] )
 tools.mouse( [(50,150), (450,350)] )
+tools.set_pen_color(colors.BLACK)
 tools.write("Hello\nworld")
 tools.write("Hello\nworld")
 
 
 layer.new()
 layer.new()

部分文件因为文件数量过多而无法显示