[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : luke
Repository : xara
Revision   : 1776
Date       : Wed Jun 27 12:16:49 BST 2007

Changed paths:
   M /Trunk/XaraLX/Kernel/nodershp.cpp
   M /Trunk/XaraLX/Kernel/nodershp.h
   M /Trunk/XaraLX/Kernel/shapeops.cpp

Resizing a rounded rectangle in the quick shape tools no longer distorts the rounded corners


Diff:
Index: Trunk/XaraLX/Kernel/nodershp.cpp
===================================================================
--- Trunk/XaraLX/Kernel/nodershp.cpp	(revision 1775)
+++ Trunk/XaraLX/Kernel/nodershp.cpp	(revision 1776)
@@ -633,6 +633,41 @@
 
 
 
+/********************************************************************************************
+
+>	virtual void NodeRegularShape::TransformCentreAndAxes( TransformBase& Trans )
+
+	Author:		Rory
+	Created:	21/05/07
+	Inputs:		Trans - The transform Object
+	Purpose:	Transforms the shape centre point and axes without modifying the matrix.
+	SeeAlso:	NodeRegularShape::Transform()
+
+********************************************************************************************/
+void NodeRegularShape::TransformCentreAndAxes( TransformBase& Trans )
+{
+	// Apply the transform to the transformed centre point and axes
+	TransformMatrix.transform(&UTCentrePoint);
+	Trans.Transform(&UTCentrePoint, 1);
+	TransformMatrix.Inverse().transform(&UTCentrePoint);
+
+	TransformMatrix.transform(&UTMajorAxes);
+	Trans.Transform(&UTMajorAxes, 1);
+	TransformMatrix.Inverse().transform(&UTMajorAxes);
+
+	TransformMatrix.transform(&UTMinorAxes);
+	Trans.Transform(&UTMinorAxes, 1);
+	TransformMatrix.Inverse().transform(&UTMinorAxes);
+
+	EmergencyFixShape();
+
+	// Mark the bounding rect as invalid							
+	InvalidateBoundingRect();
+	InvalidateCache();
+}
+
+
+
 /***********************************************************************************************
 
 >	BOOL NodeRegularShape::BuildShapePath(Path** RenderPath)
Index: Trunk/XaraLX/Kernel/shapeops.cpp
===================================================================
--- Trunk/XaraLX/Kernel/shapeops.cpp	(revision 1775)
+++ Trunk/XaraLX/Kernel/shapeops.cpp	(revision 1776)
@@ -671,21 +671,18 @@
 		}
 		else
 			ScaleFactor = 1.0;
-		
-		// Translate to origin, rotate so major axis flat, scale, then rotate and translate back
-		Matrix TransMat(-ShapeToEdit->GetCentrePoint().x, -ShapeToEdit->GetCentrePoint().y);
-		DocCoord Offset = ShapeToEdit->GetMajorAxes() - ShapeToEdit->GetCentrePoint();
-		double Angle = atan2((double)Offset.y, (double)Offset.x)*(180/PI);
-		TransMat*=Matrix(-ANGLE(Angle));
-		TransMat*=Matrix(ScaleFactor, 1.0);
-		TransMat*=Matrix(ANGLE(Angle));
-		TransMat*=Matrix(ShapeToEdit->GetCentrePoint().x, ShapeToEdit->GetCentrePoint().y);
 
-		Trans2DMatrix* Trans2DMat = new Trans2DMatrix(TransMat);
-		if (Trans2DMat == NULL)
+		if (ChangeShapePointAction::DoToggle(this, &UndoActions, ShapeToEdit, 
+						ChangeShapePointAction::CHANGE_MAJOR, ShapeToEdit->GetUTMajorAxes()) == AC_FAIL)
+		{
 			return FALSE;
-		if (!DoTransformNode(ShapeToEdit, Trans2DMat))
-			return FALSE;
+		}
+
+		// Scale the major axes relative to the centre point
+		Matrix ScaleMatrix(FIXED16(1.0), ScaleFactor);
+		DocCoord Offset = ShapeToEdit->GetUTMajorAxes() - ShapeToEdit->GetUTCentrePoint();
+		ScaleMatrix.transform(&Offset);
+		ShapeToEdit->SetMajorAxes(ShapeToEdit->GetUTCentrePoint() + Offset);
 	}
 
 	// See if we should change the MinorAxis of the shape to a new length
@@ -710,21 +707,18 @@
 		}
 		else
 			ScaleFactor = 1.0;
-		
-		// Translate to origin, rotate so minor axis flat, scale, then rotate and translate back
-		Matrix TransMat(-ShapeToEdit->GetCentrePoint().x, -ShapeToEdit->GetCentrePoint().y);
-		DocCoord Offset = ShapeToEdit->GetMinorAxes() - ShapeToEdit->GetCentrePoint();
-		double Angle = atan2((double)Offset.y, (double)Offset.x)*(180/PI);
-		TransMat*=Matrix(-ANGLE(Angle));
-		TransMat*=Matrix(ScaleFactor, 1.0);
-		TransMat*=Matrix(ANGLE(Angle));
-		TransMat*=Matrix(ShapeToEdit->GetCentrePoint().x, ShapeToEdit->GetCentrePoint().y);
 
-		Trans2DMatrix* Trans2DMat = new Trans2DMatrix(TransMat);
-		if (Trans2DMat == NULL)
+		if (ChangeShapePointAction::DoToggle(this, &UndoActions, ShapeToEdit, 
+						ChangeShapePointAction::CHANGE_MINOR, ShapeToEdit->GetUTMinorAxes()) == AC_FAIL)
+		{
 			return FALSE;
-		if (!DoTransformNode(ShapeToEdit, Trans2DMat))
-			return FALSE;
+		}
+
+		// Scale the minor axes relative to the centre point
+		Matrix ScaleMatrix(ScaleFactor, FIXED16(1.0));
+		DocCoord Offset = ShapeToEdit->GetUTMinorAxes() - ShapeToEdit->GetUTCentrePoint();
+		ScaleMatrix.transform(&Offset);
+		ShapeToEdit->SetMinorAxes(ShapeToEdit->GetUTCentrePoint() + Offset);
 	}
 
 	// See if we should change the size of the stellation radius to a new length
@@ -1293,13 +1287,13 @@
 	switch (ChangeItemID)
 	{
 		case CHANGE_MINOR:
-			ReData = pToggleShape->GetMinorAxes();
+			ReData = pToggleShape->GetUTMinorAxes();
 			break;
 		case CHANGE_MAJOR:
-			ReData = pToggleShape->GetMajorAxes();
+			ReData = pToggleShape->GetUTMajorAxes();
 			break;
 		case CHANGE_CENTRE:
-			ReData = pToggleShape->GetCentrePoint();
+			ReData = pToggleShape->GetUTCentrePoint();
 			break;
 		default:
 			ERROR2(Act, "What was that Change ID?!");
@@ -1871,6 +1865,18 @@
 				{	// Transform shape using the matrix
 					Trans2DMatrix* tm = new Trans2DMatrix(transMat);
 					Failed = ! DoTransformNode(OriginalShape, tm) ;
+					Failed |= !ChangeShapePointAction::DoToggle(this, &UndoActions, OriginalShape, 
+												ChangeShapePointAction::CHANGE_CENTRE, 
+															OriginalShape->GetUTCentrePoint());
+					OriginalShape->SetCentrePoint(EditShape->GetUTCentrePoint());
+					Failed |= !ChangeShapePointAction::DoToggle(this, &UndoActions, OriginalShape, 
+												ChangeShapePointAction::CHANGE_MINOR, 
+															OriginalShape->GetUTMinorAxes());
+					OriginalShape->SetMinorAxes(EditShape->GetUTMinorAxes());
+					Failed |= !ChangeShapePointAction::DoToggle(this, &UndoActions, OriginalShape, 
+												ChangeShapePointAction::CHANGE_MAJOR, 
+															OriginalShape->GetUTMajorAxes());
+					OriginalShape->SetMajorAxes(EditShape->GetUTMajorAxes());
 					break;
 				}
 				case DRAG_STELLATION:
@@ -2392,13 +2398,11 @@
 
 	delete EditShape;
 	EditShape = new (NodeRegularShape);
-	if (EditShape != NULL)
-		OriginalShape->CopyNodeContents(EditShape);
-	else
+	if (NULL == EditShape)
 		return FALSE;
 
-	EditShape->Transform(Transform);
-	transMat = Transform.GetMatrix();
+ 	OriginalShape->CopyNodeContents(EditShape);
+ 	EditShape->TransformCentreAndAxes(Transform);
 
 	return TRUE;
 }
@@ -2459,18 +2463,14 @@
 	// Apply this to the edit shape
 	delete EditShape;
 	EditShape = new (NodeRegularShape);
-	if (EditShape != NULL)
-	{	
-		OriginalShape->CopyNodeContents(EditShape);
-
-		Trans2DMatrix	matrix( TransMat );
-		EditShape->Transform( matrix );
-		transMat = TransMat;
-
-		return TRUE;
-	}
-	else
-		return FALSE;
+ 	if (NULL == EditShape)
+ 		return FALSE;
+  
+ 	OriginalShape->CopyNodeContents(EditShape);
+	Trans2DMatrix	Trans2dMatrix(TransMat);
+ 	EditShape->TransformCentreAndAxes( Trans2dMatrix );
+  
+ 	return TRUE;
 }
 
 
Index: Trunk/XaraLX/Kernel/nodershp.h
===================================================================
--- Trunk/XaraLX/Kernel/nodershp.h	(revision 1775)
+++ Trunk/XaraLX/Kernel/nodershp.h	(revision 1776)
@@ -189,6 +189,7 @@
 
 	// Functions to transform the shape
 	virtual void Transform( TransformBase& );
+	virtual void TransformCentreAndAxes( TransformBase& );
 
 	// Information functions
 	virtual UINT32 GetNodeSize() const; 			// Returns size of node in bytes


Xara