Unknown пре 7 година
родитељ
комит
9f8e059bad
3 измењених фајлова са 112 додато и 24 уклоњено
  1. 3 3
      vectoredit/umain.lfm
  2. 88 19
      vectoredit/umain.pas
  3. 21 2
      vectoredit/uvectororiginal.pas

+ 3 - 3
vectoredit/umain.lfm

@@ -1,5 +1,5 @@
 object Form1: TForm1
-  Left = 533
+  Left = 531
   Height = 475
   Top = 0
   Width = 627
@@ -26,7 +26,7 @@ object Form1: TForm1
     OnMouseMove = BGRAVirtualScreen1MouseMove
     OnMouseUp = BGRAVirtualScreen1MouseUp
   end
-  object BCPanel1: TBCPanel
+  object BCPanelToolChoice: TBCPanel
     Left = 0
     Height = 431
     Top = 44
@@ -167,7 +167,7 @@ object Form1: TForm1
       end
     end
   end
-  object BCPanel2: TBCPanel
+  object BCPanelToolbar: TBCPanel
     Left = 0
     Height = 44
     Top = 0

+ 88 - 19
vectoredit/umain.pas

@@ -22,12 +22,16 @@ const
 
 function IsCreateShapeTool(ATool: TPaintTool): boolean;
 
+const
+  SplineStyleToStr : array[TSplineStyle] of string =
+    ('Inside','Inside + ends','Crossing','Crossing + ends','Outside','Round outside','Vertex to side','Easy Bézier');
+
 type
   { TForm1 }
 
   TForm1 = class(TForm)
-    BCPanel1: TBCPanel;
-    BCPanel2: TBCPanel;
+    BCPanelToolChoice: TBCPanel;
+    BCPanelToolbar: TBCPanel;
     BGRAImageList1: TBGRAImageList;
     BGRAVirtualScreen1: TBGRAVirtualScreen;
     CheckBoxBack: TCheckBox;
@@ -75,10 +79,15 @@ type
     FUpdatingFromShape: boolean;
     FUpdatingComboBoxPenStyle, FUpdatingSpinEditPenWidth: boolean;
     FCurrentTool: TPaintTool;
+    FSplineStyle: TSplineStyle;
+    FComboboxSplineStyle: TComboBox;
+    FUpdatingComboboxSplineStyle : boolean;
+    procedure ComboBoxSplineStyleChange(Sender: TObject);
     function GetBackColor: TBGRAPixel;
     function GetPenColor: TBGRAPixel;
     function GetPenStyle: TBGRAPenStyle;
     function GetPenWidth: single;
+    function GetSplineStyle: TSplineStyle;
     function GetVectorTransform: TAffineMatrix;
     procedure ImageChange(ARectF: TRectF);
     procedure OnEditingChange({%H-}ASender: TObject; AOriginal: TBGRALayerCustomOriginal);
@@ -89,6 +98,7 @@ type
     procedure SetPenColor(AValue: TBGRAPixel);
     procedure SetPenStyle(AValue: TBGRAPenStyle);
     procedure SetPenWidth(AValue: single);
+    procedure SetSplineStyle(AValue: TSplineStyle);
     procedure UpdateViewCursor(ACursor: TOriginalEditorCursor);
     procedure RenderAndUpdate(ADraft: boolean);
     procedure UpdateFlattenedImage(ARect: TRect);
@@ -112,6 +122,7 @@ type
     property backColor: TBGRAPixel read GetBackColor write SetBackColor;
     property penWidth: single read GetPenWidth write SetPenWidth;
     property penStyle: TBGRAPenStyle read GetPenStyle write SetPenStyle;
+    property splineStyle: TSplineStyle read GetSplineStyle write SetSplineStyle;
     property currentTool: TPaintTool read FCurrentTool write SetCurrentTool;
   end;
 
@@ -147,6 +158,7 @@ begin
   penWidth := 5;
   penStyle := SolidPenStyle;
   currentTool:= ptRectangle;
+  splineStyle:= ssEasyBezier;
 end;
 
 procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
@@ -360,6 +372,13 @@ begin
   end;
 end;
 
+procedure TForm1.ComboBoxSplineStyleChange(Sender: TObject);
+begin
+  if FUpdatingComboboxSplineStyle then exit;
+  if FComboboxSplineStyle.ItemIndex <> -1 then
+    splineStyle:= TSplineStyle(FComboboxSplineStyle.ItemIndex);
+end;
+
 function TForm1.GetBackColor: TBGRAPixel;
 begin
   result := FBackColor;
@@ -380,6 +399,11 @@ begin
   result := FPenWidth;
 end;
 
+function TForm1.GetSplineStyle: TSplineStyle;
+begin
+  result := FSplineStyle;
+end;
+
 function TForm1.GetVectorTransform: TAffineMatrix;
 begin
   if vectorLayer<>-1 then
@@ -508,6 +532,20 @@ begin
     vectorOriginal.SelectedShape.PenWidth:= penWidth;
 end;
 
+procedure TForm1.SetSplineStyle(AValue: TSplineStyle);
+begin
+  FSplineStyle := AValue;
+  if Assigned(FComboboxSplineStyle) then
+  begin
+    FUpdatingComboboxSplineStyle := true;
+    FComboboxSplineStyle.ItemIndex:= ord(FSplineStyle);
+    FUpdatingComboboxSplineStyle := false;
+  end;
+  if not FUpdatingFromShape and Assigned(vectorOriginal) and Assigned(vectorOriginal.SelectedShape) and
+    (vectorOriginal.SelectedShape is TCurveShape) then
+    TCurveShape(vectorOriginal.SelectedShape).SplineStyle := FSplineStyle;
+end;
+
 procedure TForm1.UpdateViewCursor(ACursor: TOriginalEditorCursor);
 begin
   case ACursor of
@@ -596,34 +634,64 @@ begin
 end;
 
 procedure TForm1.UpdateToolbarFromShape(AShape: TVectorShape);
+const ControlMargin = 8;
 var
   f: TVectorShapeFields;
+  showSplineStyle: boolean;
+  nextControlPos: TPoint;
+  s: TSplineStyle;
 begin
+  if Assigned(FComboboxSplineStyle) then
+  begin
+    BCPanelToolbar.RemoveControl(FComboboxSplineStyle);
+    FreeAndNil(FComboboxSplineStyle);
+  end;
+
   if AShape <> nil then
   begin
     FUpdatingFromShape := true;
-    if vsfPenColor in AShape.Fields then penColor := AShape.PenColor;
-    if vsfPenWidth in AShape.Fields then
-    begin
-      penWidth:= AShape.PenWidth;
-      FloatSpinEditPenWidth.Enabled := true;
-    end else
-      FloatSpinEditPenWidth.Enabled := false;
-    if vsfPenStyle in AShape.Fields then
+    f := AShape.Fields;
+    if vsfPenColor in f then penColor := AShape.PenColor;
+    if vsfPenWidth in f then penWidth:= AShape.PenWidth;
+    if vsfPenStyle in f then penStyle:= AShape.PenStyle;
+    if vsfBackColor in f then backColor := AShape.BackColor;
+    if AShape is TCurveShape then
     begin
-      penStyle:= AShape.PenStyle;
-      ComboBoxPenStyle.Enabled:= true;
+      showSplineStyle:= true;
+      splineStyle:= TCurveShape(AShape).SplineStyle;
     end else
-      ComboBoxPenStyle.Enabled:= false;
-
-    if vsfBackColor in AShape.Fields then backColor := AShape.BackColor;
-
+      showSplineStyle:= false;
     FUpdatingFromShape := false;
   end else
   begin
-    if IsCreateShapeTool(currentTool) then f := PaintToolClass[currentTool].Fields else f := [];
-    FloatSpinEditPenWidth.Enabled := vsfPenWidth in f;
-    ComboBoxPenStyle.Enabled:= vsfPenStyle in f;
+    if IsCreateShapeTool(currentTool) then
+    begin
+      f := PaintToolClass[currentTool].Fields;
+      showSplineStyle:= PaintToolClass[currentTool] = TCurveShape;
+    end
+    else
+    begin
+      f := [];
+      showSplineStyle:= false;
+    end;
+  end;
+  FloatSpinEditPenWidth.Enabled := vsfPenWidth in f;
+  ComboBoxPenStyle.Enabled:= vsfPenStyle in f;
+
+  nextControlPos := Point(ShapeBackColor.Left+ShapeBackColor.Width+ControlMargin,ShapeBackColor.Top);
+  if showSplineStyle then
+  begin
+    FComboboxSplineStyle := TComboBox.Create(nil);
+    FComboboxSplineStyle.Style := csDropDownList;
+    FComboboxSplineStyle.Left := nextControlPos.X;
+    FComboboxSplineStyle.Top := nextControlPos.Y;
+    for s := low(SplineStyleToStr) to high(SplineStyleToStr) do
+      FComboboxSplineStyle.Items.Add(SplineStyleToStr[s]);
+    FComboboxSplineStyle.ItemIndex := ord(splineStyle);
+    FComboboxSplineStyle.Width := 120;
+    FComboboxSplineStyle.OnChange:= @ComboBoxSplineStyleChange;
+    BCPanelToolbar.InsertControl(FComboboxSplineStyle);
+    nextControlPos.X := FComboboxSplineStyle.Left + FComboboxSplineStyle.Width + ControlMargin;
   end;
 end;
 
@@ -638,6 +706,7 @@ begin
   result.PenStyle := penStyle;
   if currentTool in[ptClosedCurve,ptPolygon] then
     TCustomPolypointShape(result).Closed := true;
+  if result is TCurveShape then TCurveShape(result).SplineStyle:= splineStyle;
   result.QuickDefine(APoint1,APoint2);
 end;
 

+ 21 - 2
vectoredit/uvectororiginal.pas

@@ -203,10 +203,15 @@ type
   { TCurveShape }
 
   TCurveShape = class(TPolylineShape)
+  private
+    FSplineStyle: TSplineStyle;
+    procedure SetSplineStyle(AValue: TSplineStyle);
   protected
     function GetCurve(AMatrix: TAffineMatrix): ArrayOfTPointF; override;
   public
+    constructor Create;
     class function StorageClassName: RawByteString; override;
+    property SplineStyle: TSplineStyle read FSplineStyle write SetSplineStyle;
   end;
 
   TVectorOriginalSelectShapeEvent = procedure(ASender: TObject; AShape: TVectorShape; APreviousShape: TVectorShape) of object;
@@ -304,13 +309,27 @@ end;
 
 { TCurveShape }
 
+procedure TCurveShape.SetSplineStyle(AValue: TSplineStyle);
+begin
+  if FSplineStyle=AValue then Exit;
+  BeginUpdate;
+  FSplineStyle:=AValue;
+  EndUpdate;
+end;
+
 function TCurveShape.GetCurve(AMatrix: TAffineMatrix): ArrayOfTPointF;
 var
   pts: array of TPointF;
 begin
   pts := inherited GetCurve(AMatrix);
-  if Closed then result := ComputeClosedSpline(pts, ssCrossingWithEnds)
-  else result := ComputeOpenedSpline(pts, ssCrossingWithEnds);
+  if Closed then result := ComputeClosedSpline(pts, FSplineStyle)
+  else result := ComputeOpenedSpline(pts, FSplineStyle);
+end;
+
+constructor TCurveShape.Create;
+begin
+  inherited Create;
+  FSplineStyle:= ssEasyBezier;
 end;
 
 class function TCurveShape.StorageClassName: RawByteString;