Bladeren bron

refactor tool manager

text align, shape ratio
johann 5 jaren geleden
bovenliggende
commit
4807c6b299

+ 0 - 1
lazpaint/image/uimage.pas

@@ -49,7 +49,6 @@ type
     FOnImageChanged: TLazPaintImageObservable;
     FUndoList: TComposedImageDifference;
     FUndoPos: integer;
-    FNextUndoBegin: integer;
     FRenderUpdateRectInPicCoord, FRenderUpdateRectInVSCoord: TRect;
     FOnCurrentFilenameChanged: TOnCurrentFilenameChanged;
 

+ 21 - 2
lazpaint/lazpaintmainform.pas

@@ -689,7 +689,9 @@ type
     procedure ManagerPhongShapeChanged(Sender: TObject);
     procedure ManagerPenStyleChanged(Sender: TObject);
     procedure ManagerPenWidthChanged(Sender: TObject);
+    procedure ManagerShapeRatioChanged(Sender: TObject);
     procedure ManagerSplineStyleChanged(Sender: TObject);
+    procedure ManagerTextAlignChanged(Sender: TObject);
     procedure ManagerTextFontChanged(Sender: TObject);
     procedure ManagerTextOutlineChanged(Sender: TObject);
     procedure ManagerTextPhongChanged(Sender: TObject);
@@ -717,9 +719,10 @@ type
 
     FLoadInitialDir, FSaveInitialDir: string;
     FSaveSelectionInitialFilename: string;
-    FInPenWidthChange, FInBrush, FInEraserOption,
+    FInPenWidthChange, FInBrush, FInShapeRatio, FInEraserOption,
     FInSplineStyleChange, FInFloodfillOption, FInTolerance,
-    FInTextFont, FInPerspective, FInGridNb: Boolean;
+    FInTextFont, FInTextAlign, FInTextShadow,
+    FInPerspective, FInGridNb: Boolean;
     FOnlineUpdater: TLazPaintCustomOnlineUpdater;
     initialized: boolean;
     shouldArrangeOnResize: boolean;
@@ -762,7 +765,9 @@ type
     procedure UpdateEraserToolbar;
     procedure UpdatePenStyleToolbar;
     procedure UpdateJoinStyleToolbar;
+    procedure UpdateShapeRatio;
     procedure UpdateTextFontToolbar;
+    procedure UpdateTextAlign;
     procedure UpdateTextOutlineToolbar;
     procedure UpdateTextPhongToolbar;
     procedure UpdateTextShadowToolbar;
@@ -1010,7 +1015,9 @@ begin
     if ToolManager.OnPenStyleChanged = @ManagerPenStyleChanged then ToolManager.OnPenStyleChanged := nil;
     if ToolManager.OnJoinStyleChanged = @ManagerJoinStyleChanged then ToolManager.OnJoinStyleChanged := nil;
     if ToolManager.OnShapeOptionChanged = @ManagerShapeOptionChanged then ToolManager.OnShapeOptionChanged := nil;
+    if ToolManager.OnShapeRatioChanged = @ManagerShapeRatioChanged then ToolManager.OnShapeRatioChanged := nil;
     if ToolManager.OnTextFontChanged = @ManagerTextFontChanged then ToolManager.OnTextFontChanged := nil;
+    if ToolManager.OnTextAlignChanged = @ManagerTextAlignChanged then ToolManager.OnTextAlignChanged := nil;
     if ToolManager.OnTextOutlineChanged = @ManagerTextOutlineChanged then ToolManager.OnTextOutlineChanged := nil;
     if ToolManager.OnTextPhongChanged = @ManagerTextPhongChanged then ToolManager.OnTextPhongChanged := nil;
     if ToolManager.OnTextShadowChanged = @ManagerTextShadowChanged then ToolManager.OnTextShadowChanged := nil;
@@ -1089,7 +1096,9 @@ begin
   ToolManager.OnPenStyleChanged:= @ManagerPenStyleChanged;
   ToolManager.OnJoinStyleChanged:= @ManagerJoinStyleChanged;
   ToolManager.OnShapeOptionChanged:=@ManagerShapeOptionChanged;
+  ToolManager.OnShapeRatioChanged:=@ManagerShapeRatioChanged;
   ToolManager.OnTextFontChanged := @ManagerTextFontChanged;
+  ToolManager.OnTextAlignChanged:=@ManagerTextAlignChanged;
   ToolManager.OnTextOutlineChanged:=@ManagerTextOutlineChanged;
   ToolManager.OnTextPhongChanged:=@ManagerTextPhongChanged;
   ToolManager.OnTextShadowChanged:=@ManagerTextShadowChanged;
@@ -4316,11 +4325,21 @@ begin
   UpdatePenWidthToolbar;
 end;
 
+procedure TFMain.ManagerShapeRatioChanged(Sender: TObject);
+begin
+  UpdateShapeRatio;
+end;
+
 procedure TFMain.ManagerSplineStyleChanged(Sender: TObject);
 begin
   UpdateSplineStyleToolbar;
 end;
 
+procedure TFMain.ManagerTextAlignChanged(Sender: TObject);
+begin
+  UpdateTextAlign;
+end;
+
 procedure TFMain.ManagerTextFontChanged(Sender: TObject);
 begin
   UpdateTextFontToolbar;

+ 40 - 15
lazpaint/maintoolbar.inc

@@ -387,12 +387,28 @@ begin
   end;
 end;
 
+procedure TFMain.UpdateShapeRatio;
+begin
+  if FInShapeRatio then exit;
+  Combo_Ratio.Text := RatioToStr(ToolManager.ShapeRatio);
+end;
+
 procedure TFMain.UpdateTextFontToolbar;
 begin
   SpinEdit_TextSize.Value := ToolManager.TextFontSize;
   UpdateTextSizeIncrement;
 end;
 
+procedure TFMain.UpdateTextAlign;
+begin
+  if FInTextAlign then exit;
+  case ToolManager.TextAlign of
+  taLeftJustify: Tool_TextAlignLeft.Down := true;
+  taCenter: Tool_TextAlignCenter.Down := true;
+  taRightJustify: Tool_TextAlignRight.Down := true;
+  end;
+end;
+
 procedure TFMain.UpdateTextOutlineToolbar;
 begin
   Tool_TextOutline.Down := ToolManager.TextOutline;
@@ -411,6 +427,7 @@ procedure TFMain.UpdateTextShadowToolbar;
 var
   shadowOn: Boolean;
 begin
+  if FInTextShadow then exit;
   shadowOn := ToolManager.TextShadow;
   Tool_TextShadow.Down := shadowOn;
   SpinEdit_TextShadowX.Value := ToolManager.TextShadowOffset.X;
@@ -421,6 +438,8 @@ begin
   Label_ShadowOffset.Visible := shadowOn;
   SpinEdit_TextShadowX.Visible := shadowOn;
   SpinEdit_TextShadowY.Visible := shadowOn;
+  if Panel_TextShadow.Visible then
+    FLayout.Arrange;
 end;
 
 procedure TFMain.UpdateLineCapToolbar;
@@ -526,12 +545,6 @@ begin
   if SpinEdit_GridNbY.MaxValue <> maxGridNbY then
     SpinEdit_GridNbY.MaxValue := maxGridNbY;
 
-  case ToolManager.ToolTextAlign of
-  taLeftJustify: Tool_TextAlignLeft.Down := true;
-  taCenter: Tool_TextAlignCenter.Down := true;
-  taRightJustify: Tool_TextAlignRight.Down := true;
-  end;
-
   UpdateCurveModeToolbar;
 end;
 
@@ -695,7 +708,9 @@ begin
   if AByUser and initialized then
   begin
     if ToolManager.TextShadowBlurRadius = SpinEdit_TextBlur.Value/PenWidthFactor then exit;
+    FInTextShadow := true;
     ToolManager.TextShadowBlurRadius := SpinEdit_TextBlur.Value/PenWidthFactor;
+    FInTextShadow := false;
     UpdateEditPicture(True);
     FActiveSpinEdit := SpinEdit_TextBlur;
   end;
@@ -743,7 +758,9 @@ begin
   if AByUser and initialized then
   begin
     if ToolManager.TextShadowOffset.X = SpinEdit_TextShadowX.Value then exit;
-    ToolManager.TextShadowOffset.X := SpinEdit_TextShadowX.Value;
+    FInTextShadow := true;
+    ToolManager.TextShadowOffset := Point(SpinEdit_TextShadowX.Value, ToolManager.TextShadowOffset.Y);
+    FInTextShadow := false;
     UpdateEditPicture(True);
     FActiveSpinEdit := SpinEdit_TextShadowX;
   end;
@@ -754,7 +771,9 @@ begin
   if AByUser and initialized then
   begin
     if ToolManager.TextShadowOffset.Y = SpinEdit_TextShadowY.Value then exit;
-    ToolManager.TextShadowOffset.Y := SpinEdit_TextShadowY.Value;
+    FInTextShadow := true;
+    ToolManager.TextShadowOffset := Point(ToolManager.TextShadowOffset.X, SpinEdit_TextShadowY.Value);
+    FInTextShadow := false;
     UpdateEditPicture(True);
     FActiveSpinEdit := SpinEdit_TextShadowY;
   end;
@@ -1604,9 +1623,11 @@ begin
     newAlign := taLeftJustify;
     if Tool_TextAlignCenter.Down then newAlign:= taCenter;
     if Tool_TextAlignRight.Down then newAlign := taRightJustify;
-    if newAlign <> ToolManager.ToolTextAlign then
+    if newAlign <> ToolManager.TextAlign then
     begin
-      ToolManager.ToolTextAlign := newAlign;
+      FInTextAlign := true;
+      ToolManager.TextAlign := newAlign;
+      FInTextAlign := false;
       UpdateEditPicture;
     end;
   end;
@@ -1632,7 +1653,6 @@ begin
      if ToolManager.TextShadow <> Tool_TextShadow.Down then
      begin
        ToolManager.TextShadow:= Tool_TextShadow.Down;
-       FLayout.Arrange;
        UpdateEditPicture;
      end;
   end;
@@ -1727,13 +1747,18 @@ end;
 
 procedure TFMain.Combo_RatioChange(Sender: TObject);
 var
-  prevRatio: Single;
+  newRatio: Single;
 begin
   if initialized then
   begin
-    prevRatio := ToolManager.ToolRatio;
-    ToolManager.ToolRatio := ComputeRatio(Combo_Ratio.Text);
-    if ToolManager.ToolRatio<>prevRatio then ToolManager.ToolUpdate;
+    newRatio := ComputeRatio(Combo_Ratio.Text);
+    if newRatio <> ToolManager.ShapeRatio then
+    begin
+      FInShapeRatio := true;
+      ToolManager.ShapeRatio := newRatio;
+      FInShapeRatio := false;
+      ToolManager.ToolUpdate;
+    end;
   end;
 end;
 

+ 95 - 41
lazpaint/tools/utool.pas

@@ -71,8 +71,8 @@ type
     function FixLayerOffset: boolean; virtual;
     function DoToolDown(toolDest: TBGRABitmap; pt: TPoint; ptF: TPointF; rightBtn: boolean): TRect; virtual;
     function DoToolMove(toolDest: TBGRABitmap; pt: TPoint; ptF: TPointF): TRect; virtual;
-    function DoToolUpdate(toolDest: TBGRABitmap): TRect; virtual;
-    procedure OnTryStop(sender: TCustomLayerAction); virtual;
+    function DoToolUpdate({%H-}toolDest: TBGRABitmap): TRect; virtual;
+    procedure OnTryStop({%H-}sender: TCustomLayerAction); virtual;
     function SelectionMaxPointDistance: single;
     function GetStatusText: string; virtual;
     function DoGetToolDrawingLayer: TBGRABitmap; virtual;
@@ -172,10 +172,15 @@ type
     FNormalPenWidth, FEraserWidth: Single;
     FShapeOptions: TShapeOptions;
     FTextFont: TFont;
+    FTextAlign: TAlignment;
     FTextOutline: boolean;
     FTextOutlineWidth: single;
     FTextPhong: boolean;
+    FLightPosition: TPointF;
+    FLightAltitude: integer;
     FTextShadow: boolean;
+    FTextShadowBlurRadius: single;
+    FTextShadowOffset: TPoint;
     FLineCap: TPenEndCap;
     FArrowStart,FArrowEnd: TArrowKind;
     FArrowSize: TPointF;
@@ -191,6 +196,7 @@ type
     FTolerance: byte;
     FFloodFillOptions: TFloodFillOptions;
     FPerspectiveOptions: TPerspectiveOptions;
+    FShapeRatio: Single;
 
     FOnColorChanged: TNotifyEvent;
     FOnEraserChanged: TNotifyEvent;
@@ -202,12 +208,12 @@ type
     FOnBrushChanged, FOnBrushListChanged: TNotifyEvent;
     FOnPhongShapeChanged: TNotifyEvent;
     FOnSplineStyleChanged: TNotifyEvent;
-    FOnTextFontChanged: TNotifyEvent;
+    FOnTextFontChanged, FOnTextAlignChanged: TNotifyEvent;
     FOnTextOutlineChanged: TNotifyEvent;
-    FOnTextPhongChanged: TNotifyEvent;
+    FOnTextPhongChanged, FOnLightChanged: TNotifyEvent;
     FOnTextShadowChanged: TNotifyEvent;
     FOnTextureChanged: TNotifyEvent;
-    FOnShapeOptionChanged: TNotifyEvent;
+    FOnShapeOptionChanged, FOnShapeRatioChanged: TNotifyEvent;
     FOnDeformationGridChanged: TNotifyEvent;
     FOnToleranceChanged: TNotifyEvent;
     FOnFloodFillOptionChanged: TNotifyEvent;
@@ -244,6 +250,8 @@ type
     procedure SetGradientSine(AValue: boolean);
     procedure SetGradientType(AValue: TGradientType);
     procedure SetJoinStyle(AValue: TPenJoinStyle);
+    procedure SetLightAltitude(AValue: integer);
+    procedure SetLightPosition(AValue: TPointF);
     procedure SetLineCap(AValue: TPenEndCap);
     procedure SetPhongShapeAltitude(AValue: integer);
     procedure SetPhongShapeBorderSize(AValue: integer);
@@ -251,9 +259,13 @@ type
     procedure SetShapeOptions(AValue: TShapeOptions);
     procedure SetPenStyle(AValue: TPenStyle);
     procedure SetPenWidth(AValue: single);
+    procedure SetShapeRatio(AValue: Single);
     procedure SetSplineStyle(AValue: TSplineStyle);
+    procedure SetTextAlign(AValue: TAlignment);
     procedure SetTextPhong(AValue: boolean);
     procedure SetTextShadow(AValue: boolean);
+    procedure SetTextShadowBlurRadius(AValue: single);
+    procedure SetTextShadowOffset(AValue: TPoint);
     procedure SetTextureOpacity(AValue: byte);
     procedure SetTolerance(AValue: byte);
     procedure ToolCloseAndReopenImmediatly;
@@ -273,14 +285,6 @@ type
     PerspectiveControls,PenColorControls,TextureControls,
     BrushControls, RatioControls: TList;
 
-    //tools configuration
-    TextShadowBlurRadius: single;
-    TextShadowOffset: TPoint;
-    ToolTextAlign: TAlignment;
-    LightPosition: TPointF;
-    LightAltitude: integer;
-    ToolRatio: Single;
-
     constructor Create(AImage: TLazPaintImage; AConfigProvider: IConfigProvider; ABitmapToVirtualScreen: TBitmapToVirtualScreenFunction = nil; ABlackAndWhite : boolean = false);
     destructor Destroy; override;
     procedure LoadFromConfig;
@@ -358,6 +362,7 @@ type
     property ShapeOptionDraw: boolean read GetShapeOptionDraw;
     property ShapeOptionFill: boolean read GetShapeOptionFill;
     property ShapeOptionAliasing: boolean read GetShapeOptionAliasing;
+    property ShapeRatio: Single read FShapeRatio write SetShapeRatio;
     property BrushInfo: TLazPaintBrush read GetBrushInfo;
     property BrushAt[AIndex: integer]: TLazPaintBrush read GetBrushAt;
     property BrushCount: integer read GetBrushCount;
@@ -366,9 +371,15 @@ type
     property TextFontName: string read GetTextFontName;
     property TextFontSize: integer read GetTextFontSize;
     property TextFontStyle: TFontStyles read GetTextFontStyle;
+    property TextAlign: TAlignment read FTextAlign write SetTextAlign;
     property TextOutline: boolean read FTextOutline;
     property TextOutlineWidth: single read FTextOutlineWidth;
     property TextPhong: boolean read FTextPhong write SetTextPhong;
+    property LightPosition: TPointF read FLightPosition write SetLightPosition;
+    property LightAltitude: integer read FLightAltitude write SetLightAltitude;
+    property TextShadow: boolean read FTextShadow write SetTextShadow;
+    property TextShadowBlurRadius: single read FTextShadowBlurRadius write SetTextShadowBlurRadius;
+    property TextShadowOffset: TPoint read FTextShadowOffset write SetTextShadowOffset;
     property LineCap: TPenEndCap read FLineCap write SetLineCap;
     property ArrowStart: TArrowKind read FArrowStart write SetArrowStart;
     property ArrowEnd: TArrowKind read FArrowEnd write SetArrowEnd;
@@ -377,7 +388,6 @@ type
     property GradientType: TGradientType read FGradientType write SetGradientType;
     property GradientSine: boolean read FGradientSine write SetGradientSine;
     property GradientColorspace: TBGRAColorInterpolation read FGradientColorspace write SetGradientColorspace;
-    property TextShadow: boolean read FTextShadow write SetTextShadow;
     property PhongShapeAltitude: integer read FPhongShapeAltitude write SetPhongShapeAltitude;
     property PhongShapeBorderSize: integer read FPhongShapeBorderSize write SetPhongShapeBorderSize;
     property PhongShapeKind: TPhongShapeKind read FPhongShapeKind write SetPhongShapeKind;
@@ -400,9 +410,12 @@ type
     property OnPenStyleChanged: TNotifyEvent read FOnPenStyleChanged write FOnPenStyleChanged;
     property OnJoinStyleChanged: TNotifyEvent read FOnJoinStyleChanged write FOnJoinStyleChanged;
     property OnShapeOptionChanged: TNotifyEvent read FOnShapeOptionChanged write FOnShapeOptionChanged;
+    property OnShapeRatioChanged: TNotifyEvent read FOnShapeRatioChanged write FOnShapeRatioChanged;
     property OnTextFontChanged: TNotifyEvent read FOnTextFontChanged write FOnTextFontChanged;
+    property OnTextAlignChanged: TNotifyEvent read FOnTextAlignChanged write FOnTextAlignChanged;
     property OnTextOutlineChanged: TNotifyEvent read FOnTextOutlineChanged write FOnTextOutlineChanged;
     property OnTextPhongChanged: TNotifyEvent read FOnTextPhongChanged write FOnTextPhongChanged;
+    property OnLightChanged: TNotifyEvent read FOnLightChanged write FOnLightChanged;
     property OnTextShadowChanged: TNotifyEvent read FOnTextShadowChanged write FOnTextShadowChanged;
     property OnLineCapChanged: TNotifyEvent read FOnLineCapChanged write FOnLineCapChanged;
     property OnSplineStyleChanged: TNotifyEvent read FOnSplineStyleChanged write FOnSplineStyleChanged;
@@ -983,6 +996,20 @@ begin
   if Assigned(FOnJoinStyleChanged) then FOnJoinStyleChanged(self);
 end;
 
+procedure TToolManager.SetLightAltitude(AValue: integer);
+begin
+  if FLightAltitude=AValue then Exit;
+  FLightAltitude:=AValue;
+  if Assigned(FOnLightChanged) then FOnLightChanged(self);
+end;
+
+procedure TToolManager.SetLightPosition(AValue: TPointF);
+begin
+  if FLightPosition=AValue then Exit;
+  FLightPosition:=AValue;
+  if Assigned(FOnLightChanged) then FOnLightChanged(self);
+end;
+
 procedure TToolManager.SetLineCap(AValue: TPenEndCap);
 begin
   if FLineCap=AValue then Exit;
@@ -1044,6 +1071,13 @@ begin
   end;
 end;
 
+procedure TToolManager.SetShapeRatio(AValue: Single);
+begin
+  if FShapeRatio=AValue then Exit;
+  FShapeRatio:=AValue;
+  if Assigned(FOnShapeRatioChanged) then FOnShapeRatioChanged(self);
+end;
+
 procedure TToolManager.SetSplineStyle(AValue: TSplineStyle);
 begin
   if FSplineStyle=AValue then Exit;
@@ -1051,6 +1085,13 @@ begin
   if Assigned(FOnSplineStyleChanged) then FOnSplineStyleChanged(self);
 end;
 
+procedure TToolManager.SetTextAlign(AValue: TAlignment);
+begin
+  if FTextAlign=AValue then Exit;
+  FTextAlign:=AValue;
+  if Assigned(FOnTextAlignChanged) then FOnTextAlignChanged(self);
+end;
+
 procedure TToolManager.SetTextPhong(AValue: boolean);
 begin
   if FTextPhong=AValue then Exit;
@@ -1065,6 +1106,19 @@ begin
   if Assigned(FOnTextShadowChanged) then FOnTextShadowChanged(self);
 end;
 
+procedure TToolManager.SetTextShadowBlurRadius(AValue: single);
+begin
+  if FTextShadowBlurRadius=AValue then Exit;
+  FTextShadowBlurRadius:=AValue;
+
+end;
+
+procedure TToolManager.SetTextShadowOffset(AValue: TPoint);
+begin
+  if FTextShadowOffset=AValue then Exit;
+  FTextShadowOffset:=AValue;
+end;
+
 procedure TToolManager.SetTextureOpacity(AValue: byte);
 begin
   if AValue = FTextureOpactiy then exit;
@@ -1247,6 +1301,7 @@ begin
   BitmapToVirtualScreen := ABitmapToVirtualScreen;
   FShouldExitTool:= false;
   FConfigProvider := AConfigProvider;
+  FBlackAndWhite := ABlackAndWhite;
 
   FForeColor := BGRABlack;
   FBackColor := BGRA(0,0,255);
@@ -1255,43 +1310,39 @@ begin
   FTextureAfterAlpha := nil;
   FNormalPenWidth := 5;
   FEraserWidth := 10;
+  FEraserAlpha := 255;
   FEraserMode := emEraseAlpha;
-  FShapeOptions := [toDrawShape, toFillShape, toCloseShape];
-  Tolerance := 64;
-  FBlackAndWhite := ABlackAndWhite;
-
-  FBrushSpacing := 1;
   ReloadBrushes;
-
-  GradientType := gtLinear;
-  GradientSine := false;
-  GradientColorspace := ciLinearRGB;
+  FBrushSpacing := 1;
+  FShapeOptions := [toDrawShape, toFillShape, toCloseShape];
+  FPenStyle := psSolid;
+  FLineCap := pecRound;
+  FJoinStyle := pjsRound;
+  FArrowStart := akNone;
+  FArrowEnd := akNone;
+  FArrowSize := PointF(2,2);
+  FSplineStyle := ssEasyBezier;
   FFloodFillOptions := [ffProgressive];
-  LineCap := pecRound;
-  JoinStyle := pjsRound;
-  ArrowStart := akNone;
-  ArrowEnd := akNone;
-  ArrowSize := PointF(2,2);
-  PenStyle := psSolid;
-  FEraserAlpha := 255;
-  SplineStyle := ssEasyBezier;
+  FTolerance := 64;
+  FGradientType := gtLinear;
+  FGradientSine := false;
+  FGradientColorspace := ciLinearRGB;
   FTextOutline := False;
   FTextOutlineWidth := 2;
   FTextShadow := false;
   FTextFont := TFont.Create;
   FTextFont.Size := 10;
   FTextFont.Name := 'Arial';
-  ToolTextAlign := taLeftJustify;
+  FTextAlign := taLeftJustify;
   FTextPhong := False;
-  TextShadowBlurRadius := 4;
-  TextShadowOffset := Point(5,5);
-  LightPosition := PointF(0,0);
-  LightAltitude := 100;
+  FTextShadowBlurRadius := 4;
+  FTextShadowOffset := Point(5,5);
+  FLightPosition := PointF(0,0);
+  FLightAltitude := 100;
+  FPhongShapeKind := pskRectangle;
   FPhongShapeAltitude := 50;
   FPhongShapeBorderSize := 20;
-  FPhongShapeKind := pskRectangle;
   FPerspectiveOptions:= [poRepeat];
-
   FDeformationGridNbX := 5;
   FDeformationGridNbY := 5;
   FDeformationGridMoveWithoutDeformation := false;
@@ -1375,25 +1426,28 @@ begin
   BackColor := Config.DefaultToolBackColor;
   FNormalPenWidth := Config.DefaultToolPenWidth;
   FEraserWidth := Config.DefaultToolEraserWidth;
+  if Assigned(FOnPenWidthChanged) then FOnPenWidthChanged(self);
+  ReloadBrushes;
   opt := [];
   if Config.DefaultToolOptionDrawShape then include(opt, toDrawShape);
   if Config.DefaultToolOptionFillShape then include(opt, toFillShape);
   if Config.DefaultToolOptionCloseShape then include(opt, toCloseShape);
+  ShapeOptions:= opt;
   Tolerance := Config.DefaultToolTolerance;
+
   TextShadow := Config.DefaultToolTextShadow;
-  FTextOutline := Config.DefaultToolTextOutline;
-  FTextOutlineWidth := Config.DefaultToolTextOutlineWidth;
+  SetTextOutline(Config.DefaultToolTextOutline, Config.DefaultToolTextOutlineWidth);
   TextPhong := Config.DefaultToolTextPhong;
   with Config.DefaultToolTextFont do
     SetTextFont(Name, Size, Style);
   TextShadowBlurRadius := Config.DefaultToolTextBlur;
   TextShadowOffset := Config.DefaultToolTextShadowOffset;
+
   LightPosition := Config.DefaultToolLightPosition;
   LightAltitude := Config.DefaultToolLightAltitude;
   PhongShapeAltitude := Config.DefaultToolShapeAltitude;
   PhongShapeBorderSize := Config.DefaultToolShapeBorderSize;
   PhongShapeKind := Config.DefaultToolShapeType;
-  ReloadBrushes;
 end;
 
 procedure TToolManager.SaveToConfig;

+ 2 - 2
lazpaint/tools/utoolselect.pas

@@ -213,10 +213,10 @@ begin
   AssignSelectShapeStyle(FShape, FSwapColor);
   if FShape is TCustomRectShape then
   begin
-    if Manager.ToolRatio = 0 then
+    if Manager.ShapeRatio = 0 then
       TCustomRectShape(FShape).FixedRatio:= EmptySingle
     else
-      TCustomRectShape(FShape).FixedRatio:= Manager.ToolRatio;
+      TCustomRectShape(FShape).FixedRatio:= Manager.ShapeRatio;
   end;
 end;
 

+ 2 - 2
lazpaint/tools/utooltext.pas

@@ -138,7 +138,7 @@ end;
 procedure TToolText.ShapeEditingChange(ASender: TObject);
 begin
   with (FShape as TTextShape) do
-    Manager.ToolTextAlign := ParagraphAlignment;
+    Manager.TextAlign := ParagraphAlignment;
   inherited ShapeEditingChange(ASender);
 end;
 
@@ -180,7 +180,7 @@ begin
 
     LightPosition := AMatrix*Manager.LightPosition;
     AltitudePercent:= Manager.PhongShapeAltitude;
-    ParagraphAlignment:= Manager.ToolTextAlign;
+    ParagraphAlignment:= Manager.TextAlign;
     PenPhong := Manager.TextPhong;
   end;
   if (Manager.TextShadow <> FPrevShadow) or

+ 2 - 2
lazpaint/tools/utoolvectorial.pas

@@ -335,7 +335,7 @@ begin
     Manager.TextPhong := PenPhong;
     Manager.LightPosition := m*LightPosition;
     Manager.PhongShapeAltitude := round(AltitudePercent);
-    Manager.ToolTextAlign:= ParagraphAlignment;
+    Manager.TextAlign:= ParagraphAlignment;
     Manager.SetTextFont(FontName,round(FontEmHeight*zoom*72/Manager.Image.DPI),FontStyle);
     Manager.TextShadow:= false;
     if OutlineFill.FillType = vftNone then
@@ -573,7 +573,7 @@ begin
           PenPhong := Manager.TextPhong;
           LightPosition := m*Manager.LightPosition;
           AltitudePercent := Manager.PhongShapeAltitude;
-          ParagraphAlignment := Manager.ToolTextAlign;
+          ParagraphAlignment := Manager.TextAlign;
           FontName:= Manager.TextFontName;
           FontEmHeight:= Manager.TextFontSize*zoom*Manager.Image.DPI/72;
           FontStyle := Manager.TextFontStyle;

+ 45 - 0
lazpaint/ugraph.pas

@@ -12,6 +12,7 @@ const FrameDashLength = 4;
   NicePointMaxRadius = 4;
 
 function ComputeRatio(ARatio: string): single;
+function RatioToStr(ARatio: single): string;
 
 function RectUnion(const rect1,Rect2: TRect): TRect;
 function RectInter(const rect1,Rect2: TRect): TRect;
@@ -223,6 +224,50 @@ begin
   result := num/denom;
 end;
 
+function RatioToStr(ARatio: single): string;
+var
+  num,denom: integer;
+
+  procedure InvFrac;
+  var temp: integer;
+  begin
+    temp := num;
+    num := denom;
+    denom := num;
+  end;
+
+  procedure AddFrac(AValue: integer);
+  begin
+    inc(num, AValue*denom);
+  end;
+
+const MaxDev = 3;
+var
+  dev: array[1..MaxDev] of integer;
+  devCount, i: integer;
+  curVal, remain: Single;
+
+begin
+  if ARatio < 0 then ARatio := -ARatio;
+  curVal := ARatio;
+  devCount := 0;
+  repeat
+    inc(devCount);
+    dev[devCount] := trunc(ARatio);
+    remain := frac(curVal);
+    if abs(remain) < 1e-3 then break;
+    curVal := 1/remain;
+  until devCount = MaxDev;
+  num := dev[devCount];
+  denom := 1;
+  for i := devCount-1 downto 1 do
+  begin
+    InvFrac;
+    AddFrac(dev[i]);
+  end;
+  result := IntToStr(num)+':'+IntToStr(denom);
+end;
+
 function RectUnion(const rect1, Rect2: TRect): TRect;
 begin
   if IsRectEmpty(rect1) then