Show RNTObject.cs syntax highlighted
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace New_Study_Project {
//specifies an RNTObject
public class RNTObject {
private enum RNTState { None, RNTing, TranslateOnly }; //the RNT object is either 'RNTing' (i.e. rotating and translating), translating, or doing nothing
private RNTState objectState; //stores state of rnt object
private Matrix offsetMatrix, translationMatrix, transformMatrix, interactionMatrix; //matrices used for rotating/translating the rnt object
private PointF originalMouseDown, targetMouseDown; //original and target mouse locations in screen space
private PointF topLeft, topRight, bottomLeft, bottomRight; //stores 4 corner points of rnt object in screen space
private PointF center; //center of rnt object in screen space
private PointF translateOnlyZoneTopLeft; //point useful for drawing the translate-only region of rnt object in screen space
private float width, height, angle; //stores height, width and degree of rotation (0-360) of rnt object
private float objectRotation; //internal variable for calculating degree of rotation
private int translateOnlyZoneRadius; //size of translate-only zone in pixels
private int translateOnlyZoneRadiusPercent; //size of translate-only zone as a percentage of the rnt object's width/height (whichever is smaller)
private PointF[] rpFinal = { new PointF() }; //pivot point around which rnt object rotates (in object space)
/* change made by Stefan Habelski */
private PointF RNTVectorHorizontal; // side normals of the RNTObject
private PointF RNTVectorVerticaly; // they show in which directions the points lie to each other
private PointF RNTScalePoint;
private PointF RNTMultSelectionScalePoint;
private float ClientLeft, ClientTop, ClientRight, ClientBottom;
private float SELObjectMax_X, SELObjectMin_X, SELObjectMax_Y, SELObjectMin_Y;
private InterfaceObject RNTSelScaleObject;
/* End of changes made by Stefan Habelski */
//constructor for rnt object -> need to specify 4 corner points and size of translate-only region (as a percentage)
public RNTObject(PointF topLeft, PointF topRight, PointF bottomRight, PointF bottomLeft, int translateOnlySizePercent)
{
this.objectState = RNTState.None;
this.offsetMatrix = new Matrix();
this.translationMatrix = new Matrix();
this.transformMatrix = new Matrix();
this.interactionMatrix = new Matrix();
this.objectRotation = 0;
this.topLeft = new PointF(topLeft.X, topLeft.Y);
this.topRight = new PointF(topRight.X, topRight.Y);
this.bottomRight = new PointF(bottomRight.X, bottomRight.Y);
this.bottomLeft = new PointF(bottomLeft.X, bottomLeft.Y);
this.computeSideNormals(); // change made by Stefan Habelski
this.width = distance(topLeft, topRight);
this.height = distance(topLeft, bottomLeft);
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.center = new PointF(centre[0].X, centre[0].Y);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.SetTranslateOnlyZonePercent(translateOnlySizePercent); //includes call to updateTransform() needed by previous code in constructor
}
//sets the size of the translate-only zone as a percentage of either the object's width or height (whichever is smaller)
private void SetTranslateOnlyZonePercent(int value)
{
if (value > 100)
value = 100;
if (value < 0)
value = 0;
this.translateOnlyZoneRadiusPercent = value;
if (this.translateOnlyZoneRadiusPercent == 1090) this.translateOnlyZoneRadius = 35;
else this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * value/100, (int)this.height/2 * value/100);
this.updateTransform();
}
//returns the center of the object (in screen space)
public PointF Center
{
get
{
return this.center;
}
set
{
this.center = value;
}
}
//returns the angle of rotation of the object (in degrees, between 0-360)
public float Angle
{
get
{
while (this.objectRotation < 0)
{
this.objectRotation += 360;
}
while (this.objectRotation > 360)
{
this.objectRotation -= 360;
}
this.angle = this.objectRotation;
return this.angle;
}
}
//returns the width of the object
public float Width
{
get
{
return this.width;
}
}
//returns the height of the object
public float Height
{
get
{
return this.height;
}
}
//returns the coordinate of the top-left corner of the rnt object (in screen space)
public PointF TopLeft
{
get
{
return new PointF ( this.topLeft.X, this.topLeft.Y ) ;
}
set
{
this.topLeft.X = value.X;
this.topLeft.Y = value.Y;
}
}
//returns the coordinate of the top-right corner of the rnt object (in screen space)
public PointF TopRight
{
get
{
return new PointF ( this.topRight.X, this.topRight.Y ) ;
}
set
{
this.topRight.X = value.X;
this.topRight.Y = value.Y;
}
}
//returns the coordinate of the bottom-right corner of the rnt object (in screen space)
public PointF BottomRight
{
get
{
return new PointF ( this.bottomRight.X, this.bottomRight.Y ) ;
}
set
{
this.bottomRight.X = value.X;
this.bottomRight.Y = value.Y;
}
}
//returns the coordinate of the bottom-left corner of the rnt object (in screen space)
public PointF BottomLeft
{
get
{
return new PointF ( this.bottomLeft.X, this.bottomLeft.Y ) ;
}
set
{
this.bottomLeft.X = value.X;
this.bottomLeft.Y = value.Y;
}
}
//returns a point that is useful for drawing the translate-only zone
public PointF TranslateOnlyZoneTopLeft
{
get
{
return new PointF( this.translateOnlyZoneTopLeft.X, this.translateOnlyZoneTopLeft.Y );
}
}
//returns radius of translate-only zone in pixels
public int TranslateOnlyZoneRadius
{
get
{
return this.translateOnlyZoneRadius;
}
}
//sets and gets radius of translate-only zone in terms of percentage of the width/height of the object
public int TranslateOnlyZoneRadiusPercent
{
get
{
return this.translateOnlyZoneRadiusPercent;
}
set
{
this.SetTranslateOnlyZonePercent(value);
}
}
/* sets the rotation angle of the rnt object (i.e. rotates the rnt object in place to the
angle specified. the specified value needs to be in degrees between 0 and 360 */
public void SetRotationAngle(float value)
{
float newValue = value;
while (newValue < 0)
{
newValue += 360;
}
while (newValue > 360)
{
newValue -= 360;
}
newValue = newValue - this.Angle;
using (Matrix invertedTransformMatrix = this.transformMatrix.Clone())
{
// make the inverse of the transform matrix (so that can translate screen space -> object space)
invertedTransformMatrix.Invert();
// convert the original mouse point into object space (this is the rotation point)
PointF[] rp = { new PointF(this.center.X,this.center.Y) };
invertedTransformMatrix.TransformPoints(rp);
// rotate about the rotation point (put in interaction matrix)
this.interactionMatrix.RotateAt (newValue, rp[0]);
this.objectRotation = value;
while (this.objectRotation < 0)
{
this.objectRotation += 360;
}
while (this.objectRotation > 360)
{
this.objectRotation -= 360;
}
}
this.updateTransform();
this.computeSideNormals();
}
/* changes the 4 corners of the rnt object, and recalculates the object's center point, width and height.
also, updates the size of the translate-only zone (in pixels - not percentage -> percentage remains same) */
public void ChangeCorners(PointF topLeft, PointF topRight, PointF bottomRight, PointF bottomLeft)
{
this.topLeft = new PointF(topLeft.X, topLeft.Y);
this.topRight = new PointF(topRight.X, topRight.Y);
this.bottomRight = new PointF(bottomRight.X, bottomRight.Y);
this.bottomLeft = new PointF(bottomLeft.X, bottomLeft.Y);
this.width = distance(topLeft, topRight);
this.height = distance(topLeft, bottomLeft);
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.translationMatrix.Reset();
this.translationMatrix.Translate (600.0f, 600.0f);
this.transformMatrix.TransformPoints (centre);
this.center = new PointF(centre[0].X, centre[0].Y);
this.SetTranslateOnlyZonePercent(this.translateOnlyZoneRadiusPercent); //includes call to updateTransform() needed by previous code in constructor
}
/* called on a mouse-down event - calculates if the point passed is contained within the 4 corners of the object (assuming
a rectangular shape, and if so, updates the rnt object's state appropriately */
public void RNTMouseDown (PointF pt)
{
if (!this.Contains(new PointF (pt.X, pt.Y)))
{
this.objectState = RNTState.None;
return;
}
else
{
this.originalMouseDown = new PointF (pt.X, pt.Y);
//calculations to determine how far point is from center
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
SizeF CO, OT, CT;
CO = new SizeF (this.originalMouseDown.X - centre[0].X, this.originalMouseDown.Y - centre[0].Y);
OT = new SizeF (targetMouseDown.X - this.originalMouseDown.X, targetMouseDown.Y - this.originalMouseDown.Y);
CT = new SizeF (CO.Width + OT.Width, CO.Height + OT.Height);
float theta, alpha;
theta = (float) Math.Atan2 (CT.Height, CT.Width);
alpha = (float) Math.Atan2 (CO.Height, CO.Width);
double testDistance = 0.0;
testDistance = Math.Sqrt(CO.Width * CO.Width + CO.Height * CO.Height);
//test to see if the point is within-the translate only region
if (testDistance <= this.translateOnlyZoneRadius)
{
this.objectState = RNTState.TranslateOnly;
}
else
{
this.objectState = RNTState.RNTing;
}
}
}
/* called on a mouse-move event - depending on the object's state, it either rotates and translate the rnt object,
translates it, or does nothing.
the 4 corner points, and center (plus a point useful for drawing translate-only zone) are updated as part of this method in updateTransform()*/
public void RNTMouseMove (PointF pt)
{
if (this.objectState == RNTState.None)
{
return;
}
else
{
this.targetMouseDown = new PointF (pt.X, pt.Y);
if (this.objectState == RNTState.TranslateOnly)
{
this.translateOnly(); //translate-only
}
else
{
this.doTransform(); //translate and rotate ('RNTing')
}
this.updateTransform(); //update the corner points, center and point useful for drawing the translate-only zone
this.computeSideNormals(); // change made by Stefan Habelski
}
}
//called on a mouse-up event - changes the rnt object's state
public void RNTMouseUp ()
{
this.objectState = RNTState.None;
this.rpFinal[0] = new PointF(0,0);
}
/***********************************/
/* Changes made by Stefan Habelski */
/***********************************/
//scales the RNTObject into the setted width and height - Fuzzy Boundary - Stuff
public void RNTOnlyScale(PointF pt, float scaleWidth, float scaleHeight, float originalWidth, float originalHeight, float currentWidth, float currentHeight)
{
PointF vectorTLpt;
PointF newTopLeft;
//float oldAngle;
// float rotSin, rotCos;
float scalarHorizontal, scalarVerticaly;
float scalarORG_W, scalarORG_H;
float scalefactorX, scalefactorY;
scalefactorX = scaleWidth/originalWidth;
scalefactorY = scaleHeight/originalHeight;
scalarORG_W = originalWidth / currentWidth;
scalarORG_H = originalHeight / currentHeight;
vectorTLpt = new PointF((pt.X-this.topLeft.X), (pt.Y-this.topLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
newTopLeft = new PointF((pt.X-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.Y));
vectorTLpt = new PointF((pt.X-newTopLeft.X), (pt.Y-newTopLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
this.topLeft = new PointF((pt.X-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.Y));
this.topRight = new PointF((this.topLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.topLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.bottomLeft = new PointF((this.topLeft.X+scaleHeight*this.RNTVectorVerticaly.X), (this.topLeft.Y+scaleHeight*this.RNTVectorVerticaly.Y));
this.bottomRight = new PointF((this.bottomLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.bottomLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
/*
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
this.topLeft = new PointF(((this.topLeft.X-this.center.X)*rotCos - (this.topLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.topLeft.X-this.center.X)*rotSin + (this.topLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.topRight = new PointF(((this.topRight.X-this.center.X)*rotCos - (this.topRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.topRight.X-this.center.X)*rotSin + (this.topRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomRight = new PointF(((this.bottomRight.X-this.center.X)*rotCos - (this.bottomRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomRight.X-this.center.X)*rotSin + (this.bottomRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomLeft = new PointF(((this.bottomLeft.X-this.center.X)*rotCos - (this.bottomLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomLeft.X-this.center.X)*rotSin + (this.bottomLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
oldAngle = this.objectRotation;
this.objectRotation = 0;
this.width = scaleWidth;
this.height = scaleHeight;
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.updateTransform();
this.SetRotationAngle(oldAngle);
*/
}
// will called by mouse move - event
public void RNTMoveNScale(PointF pt, float scaleWidth, float scaleHeight, float originalWidth, float originalHeight, float currentWidth, float currentHeight)
{
PointF vectorTLpt;
PointF newTopLeft;
float oldAngle;
float rotSin, rotCos;
float scalarHorizontal, scalarVerticaly;
float scalarORG_W, scalarORG_H;
float scalefactorX, scalefactorY;
this.RNTMouseMove(pt);
this.RNTMouseUp();
scalefactorX = scaleWidth/originalWidth;
scalefactorY = scaleHeight/originalHeight;
scalarORG_W = originalWidth / currentWidth;
scalarORG_H = originalHeight / currentHeight;
vectorTLpt = new PointF((pt.X-this.topLeft.X), (pt.Y-this.topLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
newTopLeft = new PointF((pt.X-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.Y));
vectorTLpt = new PointF((pt.X-newTopLeft.X), (pt.Y-newTopLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
this.topLeft = new PointF((pt.X-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.Y));
this.topRight = new PointF((this.topLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.topLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.bottomLeft = new PointF((this.topLeft.X+scaleHeight*this.RNTVectorVerticaly.X), (this.topLeft.Y+scaleHeight*this.RNTVectorVerticaly.Y));
this.bottomRight = new PointF((this.bottomLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.bottomLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
this.topLeft = new PointF(((this.topLeft.X-this.center.X)*rotCos - (this.topLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.topLeft.X-this.center.X)*rotSin + (this.topLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.topRight = new PointF(((this.topRight.X-this.center.X)*rotCos - (this.topRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.topRight.X-this.center.X)*rotSin + (this.topRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomRight = new PointF(((this.bottomRight.X-this.center.X)*rotCos - (this.bottomRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomRight.X-this.center.X)*rotSin + (this.bottomRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomLeft = new PointF(((this.bottomLeft.X-this.center.X)*rotCos - (this.bottomLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomLeft.X-this.center.X)*rotSin + (this.bottomLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
oldAngle = this.objectRotation;
this.objectRotation = 0;
this.width = scaleWidth;
this.height = scaleHeight;
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
this.RNTMouseDown(pt);
}
// will called after deselection
public void RNTJustScale(PointF pt, float scaleWidth, float scaleHeight, float originalWidth, float originalHeight, float currentWidth, float currentHeight)
{
PointF vectorTLpt;
PointF newTopLeft;
float oldAngle;
float rotSin, rotCos;
float scalarHorizontal, scalarVerticaly;
float scalarORG_W, scalarORG_H;
float scalefactorX, scalefactorY;
// this.RNTMouseMove(pt);
// this.RNTMouseUp();
scalefactorX = scaleWidth/originalWidth;
scalefactorY = scaleHeight/originalHeight;
scalarORG_W = originalWidth / currentWidth;
scalarORG_H = originalHeight / currentHeight;
vectorTLpt = new PointF((pt.X-this.topLeft.X), (pt.Y-this.topLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
newTopLeft = new PointF((pt.X-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalarORG_W*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalarORG_H*scalarVerticaly)*this.RNTVectorVerticaly.Y));
vectorTLpt = new PointF((pt.X-newTopLeft.X), (pt.Y-newTopLeft.Y));
scalarHorizontal = vectorTLpt.X*this.RNTVectorHorizontal.X+vectorTLpt.Y*this.RNTVectorHorizontal.Y;
scalarVerticaly = vectorTLpt.X*this.RNTVectorVerticaly.X+vectorTLpt.Y*this.RNTVectorVerticaly.Y;
this.topLeft = new PointF((pt.X-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.X-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.X), (pt.Y-(scalefactorX*scalarHorizontal)*this.RNTVectorHorizontal.Y-(scalefactorY*scalarVerticaly)*this.RNTVectorVerticaly.Y));
this.topRight = new PointF((this.topLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.topLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.bottomLeft = new PointF((this.topLeft.X+scaleHeight*this.RNTVectorVerticaly.X), (this.topLeft.Y+scaleHeight*this.RNTVectorVerticaly.Y));
this.bottomRight = new PointF((this.bottomLeft.X+scaleWidth*this.RNTVectorHorizontal.X), (this.bottomLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y));
this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
this.topLeft = new PointF(((this.topLeft.X-this.center.X)*rotCos - (this.topLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.topLeft.X-this.center.X)*rotSin + (this.topLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.topRight = new PointF(((this.topRight.X-this.center.X)*rotCos - (this.topRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.topRight.X-this.center.X)*rotSin + (this.topRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomRight = new PointF(((this.bottomRight.X-this.center.X)*rotCos - (this.bottomRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomRight.X-this.center.X)*rotSin + (this.bottomRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomLeft = new PointF(((this.bottomLeft.X-this.center.X)*rotCos - (this.bottomLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomLeft.X-this.center.X)*rotSin + (this.bottomLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
oldAngle = this.objectRotation;
this.objectRotation = 0;
this.width = scaleWidth;
this.height = scaleHeight;
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
//this.RNTMouseDown(pt);
}
//scales the RNTObject with the mouse - Scale-Button was pressed
// will called by the MouseDown - Event
public void RNTScaleDown(PointF scaleDOWN)
{
this.RNTScalePoint = scaleDOWN;
}
// will called by the MouseMove - Event
public void RNTScaleMove(PointF scaleMOVE)
{
PointF scaleVector;
float scaleWidth, scaleHeight;
scaleVector = new PointF(scaleMOVE.X-this.RNTScalePoint.X, scaleMOVE.Y-this.RNTScalePoint.Y);
this.bottomRight = new PointF(this.bottomRight.X+scaleVector.X, this.bottomRight.Y+scaleVector.Y);
if (this.bottomRight.X < (this.ClientLeft+3)) this.bottomRight.X = (this.ClientLeft+4);
if (this.bottomRight.Y < (this.ClientTop+3)) this.bottomRight.Y = (this.ClientTop+4);
if (this.bottomRight.X > (this.ClientRight-3)) this.bottomRight.X = (this.ClientRight-4);
if (this.bottomRight.Y > (this.ClientBottom-3)) this.bottomRight.Y = (this.ClientBottom-4);
scaleVector = new PointF(this.bottomRight.X-this.topLeft.X, this.bottomRight.Y-this.topLeft.Y);
scaleWidth = (this.RNTVectorHorizontal.X*scaleVector.X+this.RNTVectorHorizontal.Y*scaleVector.Y);
scaleHeight = (this.RNTVectorVerticaly.X*scaleVector.X+this.RNTVectorVerticaly.Y*scaleVector.Y);
if (scaleWidth < 80.0f) scaleWidth = 80.0f;
if (scaleHeight < 80.0f) scaleHeight = 80.0f;
this.topRight = new PointF(this.topLeft.X+scaleWidth*this.RNTVectorHorizontal.X, this.topLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y);
this.bottomLeft = new PointF(this.topLeft.X+scaleHeight*this.RNTVectorVerticaly.X, this.topLeft.Y+scaleHeight*this.RNTVectorVerticaly.Y);
this.bottomRight = new PointF(this.bottomLeft.X+scaleWidth*this.RNTVectorHorizontal.X, this.bottomLeft.Y+scaleWidth*this.RNTVectorHorizontal.Y);
this.width = scaleWidth;
this.height = scaleHeight;
this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.RNTScalePoint = scaleMOVE;
}
// will called by the MouseUp - Event
public void RNTScaleUp(InterfaceObject IO)
{
PointF lpVector;
float scalarX, scalarY;
// here a test if the last mouse point of IO is inside of the IO - RNT - Object
lpVector = new PointF(IO.getLastMousePoint().X-this.topLeft.X, IO.getLastMousePoint().Y-this.topLeft.Y);
scalarX = lpVector.X*this.RNTVectorHorizontal.X+lpVector.Y*this.RNTVectorHorizontal.Y;
scalarY = lpVector.X*this.RNTVectorVerticaly.X+lpVector.Y*this.RNTVectorVerticaly.Y;
if (!(scalarX >= 0.0f && scalarX <= this.width && scalarY >= 0.0f && scalarY <= this.height)) IO.setLastMousePoint(IO.CentrePoint);
}
//translate the object by setting a vector into another position without rotating
// will called by the MouseMove - Event
public void RNTTransalteMove(PointF translateVECTOR)
{
this.center = new PointF(this.center.X+translateVECTOR.X, this.center.Y+translateVECTOR.Y);
this.topLeft = new PointF(this.topLeft.X+translateVECTOR.X, this.topLeft.Y+translateVECTOR.Y);
this.topRight = new PointF(this.topRight.X+translateVECTOR.X, this.topRight.Y+translateVECTOR.Y);
this.bottomLeft = new PointF(this.bottomLeft.X+translateVECTOR.X, this.bottomLeft.Y+translateVECTOR.Y);
this.bottomRight = new PointF(this.bottomRight.X+translateVECTOR.X, this.bottomRight.Y+translateVECTOR.Y);
}
// will called by the MouseUP - Event, it fixes the corner points
public void RNTTransalteEnd()
{
float oldAngle;
float rotSin, rotCos;
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
this.topLeft = new PointF(((this.topLeft.X-this.center.X)*rotCos - (this.topLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.topLeft.X-this.center.X)*rotSin + (this.topLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.topRight = new PointF(((this.topRight.X-this.center.X)*rotCos - (this.topRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.topRight.X-this.center.X)*rotSin + (this.topRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomRight = new PointF(((this.bottomRight.X-this.center.X)*rotCos - (this.bottomRight.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomRight.X-this.center.X)*rotSin + (this.bottomRight.Y-this.center.Y)*rotCos)+this.center.Y);
this.bottomLeft = new PointF(((this.bottomLeft.X-this.center.X)*rotCos - (this.bottomLeft.Y-this.center.Y)*rotSin)+this.center.X, ((this.bottomLeft.X-this.center.X)*rotSin + (this.bottomLeft.Y-this.center.Y)*rotCos)+this.center.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
oldAngle = this.objectRotation;
this.objectRotation = 0;
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.center = new PointF(centre[0].X, centre[0].Y);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
}
// is for MultiSelectionMoving
// will called by the MouseDown - Event
public void RNTSelDown(PointF pt)
{
this.RNTMouseDown(pt);
}
// will called by the MouseMove - Event
public void RNTSelMove(PointF selPoint, ArrayList InterfaceOBJList)
{
float oldAngle, calcAngle;
float rotSin, rotCos;
PointF oldCenter, calcCenter;
PointF newTopLeft, newTopRight, newBottomRight, newBottomLeft, newLastMousePoint;
oldAngle = this.objectRotation;
oldCenter = this.center;
this.RNTMouseMove(selPoint);
PointF tu = this.topLeft;
calcAngle = this.objectRotation - oldAngle;
calcCenter = new PointF(this.center.X - oldCenter.X, this.center.Y - oldCenter.Y);
rotSin = (float) (Math.Sin(calcAngle*Math.PI/180.0));
rotCos = (float) (Math.Cos(calcAngle*Math.PI/180.0));
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF((((IO.getTopLeft().X+calcCenter.X)-this.center.X)*rotCos - ((IO.getTopLeft().Y+calcCenter.Y)-this.center.Y)*rotSin)+this.center.X, (((IO.getTopLeft().X+calcCenter.X)-this.center.X)*rotSin + ((IO.getTopLeft().Y+calcCenter.Y)-this.center.Y)*rotCos)+this.center.Y);
newTopRight = new PointF((((IO.getTopRight().X+calcCenter.X)-this.center.X)*rotCos - ((IO.getTopRight().Y+calcCenter.Y)-this.center.Y)*rotSin)+this.center.X, (((IO.getTopRight().X+calcCenter.X)-this.center.X)*rotSin + ((IO.getTopRight().Y+calcCenter.Y)-this.center.Y)*rotCos)+this.center.Y);
newBottomRight = new PointF((((IO.getBottomRight().X+calcCenter.X)-this.center.X)*rotCos - ((IO.getBottomRight().Y+calcCenter.Y)-this.center.Y)*rotSin)+this.center.X, (((IO.getBottomRight().X+calcCenter.X)-this.center.X)*rotSin + ((IO.getBottomRight().Y+calcCenter.Y)-this.center.Y)*rotCos)+this.center.Y);
newBottomLeft = new PointF((((IO.getBottomLeft().X+calcCenter.X)-this.center.X)*rotCos - ((IO.getBottomLeft().Y+calcCenter.Y)-this.center.Y)*rotSin)+this.center.X, (((IO.getBottomLeft().X+calcCenter.X)-this.center.X)*rotSin + ((IO.getBottomLeft().Y+calcCenter.Y)-this.center.Y)*rotCos)+this.center.Y);
newLastMousePoint = new PointF((((IO.getLastMousePoint().X+calcCenter.X)-this.center.X)*rotCos - ((IO.getLastMousePoint().Y+calcCenter.Y)-this.center.Y)*rotSin)+this.center.X, (((IO.getLastMousePoint().X+calcCenter.X)-this.center.X)*rotSin + ((IO.getLastMousePoint().Y+calcCenter.Y)-this.center.Y)*rotCos)+this.center.Y);
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, calcAngle, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
}
}
// finds the bounding box of a pselected pile
public void RNTFindBoundingBox(PointF bBox)
{
if (bBox.X < this.SELObjectMin_X) this.SELObjectMin_X = bBox.X;
if (bBox.Y < this.SELObjectMin_Y) this.SELObjectMin_Y = bBox.Y;
if (bBox.X > this.SELObjectMax_X) this.SELObjectMax_X = bBox.X;
if (bBox.Y > this.SELObjectMax_Y) this.SELObjectMax_Y = bBox.Y;
}
// is for MultiSelectionMoving and MultiSelectionScaling
// will called by the MouseMove - Event
// returns if the Size of an InterfaceObject had to resized because it was under minimum size
public void RNTSelMoveNScale(PointF pt, float newScale, float oldScale, ArrayList InterfaceOBJList)
{
PointF vectorCpt;
PointF newPos;
float rotSin, rotCos, oldAngle;
PointF savePT, newTopLeft, newTopRight, newBottomRight, newBottomLeft, newLastMousePoint, newCenterVector;
this.RNTSelMove(pt, InterfaceOBJList);
this.RNTMouseUp();
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
oldAngle = this.objectRotation;
savePT = pt;
pt = new PointF(((pt.X-this.center.X)*rotCos - (pt.Y-this.center.Y)*rotSin), ((pt.X-this.center.X)*rotSin + (pt.Y-this.center.Y)*rotCos));
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-this.center.X)*rotCos - (IO.getTopLeft().Y-this.center.Y)*rotSin), ((IO.getTopLeft().X-this.center.X)*rotSin + (IO.getTopLeft().Y-this.center.Y)*rotCos));
newTopRight = new PointF(((IO.getTopRight().X-this.center.X)*rotCos - (IO.getTopRight().Y-this.center.Y)*rotSin), ((IO.getTopRight().X-this.center.X)*rotSin + (IO.getTopRight().Y-this.center.Y)*rotCos));
newBottomRight = new PointF(((IO.getBottomRight().X-this.center.X)*rotCos - (IO.getBottomRight().Y-this.center.Y)*rotSin), ((IO.getBottomRight().X-this.center.X)*rotSin + (IO.getBottomRight().Y-this.center.Y)*rotCos));
newBottomLeft = new PointF(((IO.getBottomLeft().X-this.center.X)*rotCos - (IO.getBottomLeft().Y-this.center.Y)*rotSin), ((IO.getBottomLeft().X-this.center.X)*rotSin + (IO.getBottomLeft().Y-this.center.Y)*rotCos));
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-this.center.X)*rotCos - (IO.getLastMousePoint().Y-this.center.Y)*rotSin), ((IO.getLastMousePoint().X-this.center.X)*rotSin + (IO.getLastMousePoint().Y-this.center.Y)*rotCos));
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
vectorCpt = new PointF(((IO.CentrePoint.X-pt.X)*(newScale/oldScale)), ((IO.CentrePoint.Y-pt.Y)*(newScale/oldScale)));
newPos = new PointF(pt.X+vectorCpt.X, pt.Y+vectorCpt.Y);
IO.translateInterfaceObject(new PointF(newPos.X-IO.CentrePoint.X, newPos.Y-IO.CentrePoint.Y));
IO.onlySelScale(newScale);
}
this.SELObjectMax_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMin_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMax_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
this.SELObjectMin_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
foreach (InterfaceObject SELObj in InterfaceOBJList)
{
this.RNTFindBoundingBox(SELObj.getTopLeft());
this.RNTFindBoundingBox(SELObj.getTopRight());
this.RNTFindBoundingBox(SELObj.getBottomLeft());
this.RNTFindBoundingBox(SELObj.getBottomRight());
}
newCenterVector = new PointF((this.SELObjectMin_X+this.SELObjectMax_X)/2.0f, (this.SELObjectMin_Y+this.SELObjectMax_Y)/2.0f);
rotSin = (float) (Math.Sin(objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(objectRotation*Math.PI/180.0));
pt = new PointF(((pt.X-newCenterVector.X)*rotCos - (pt.Y-newCenterVector.Y)*rotSin)+this.center.X, ((pt.X-newCenterVector.X)*rotSin + (pt.Y-newCenterVector.Y)*rotCos)+this.center.Y);
vectorCpt = new PointF(savePT.X-pt.X, savePT.Y-pt.Y);
this.topLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.topRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
this.objectRotation = 0;
this.width = distance(topLeft, topRight);
this.height = distance(topLeft, bottomLeft);
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-newCenterVector.X)*rotCos - (IO.getTopLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopLeft().X-newCenterVector.X)*rotSin + (IO.getTopLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newTopRight = new PointF(((IO.getTopRight().X-newCenterVector.X)*rotCos - (IO.getTopRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopRight().X-newCenterVector.X)*rotSin + (IO.getTopRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomRight = new PointF(((IO.getBottomRight().X-newCenterVector.X)*rotCos - (IO.getBottomRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomRight().X-newCenterVector.X)*rotSin + (IO.getBottomRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomLeft = new PointF(((IO.getBottomLeft().X-newCenterVector.X)*rotCos - (IO.getBottomLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomLeft().X-newCenterVector.X)*rotSin + (IO.getBottomLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-newCenterVector.X)*rotCos - (IO.getLastMousePoint().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getLastMousePoint().X-newCenterVector.X)*rotSin + (IO.getLastMousePoint().Y-newCenterVector.Y)*rotCos)+this.center.Y);
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
}
this.RNTMouseDown(savePT);
}
//will called after a pile was selected - change the size of object which are maybe ahve other scaleValues as the IOSelectObject
public bool RNTSelScaleAfterSelection(PointF pt, float scaleValue, ArrayList InterfaceOBJList)
{
bool changedSize;
PointF vectorCpt;
PointF newPos;
float rotSin, rotCos, oldAngle, newScale, oldScale;
PointF savePT, newTopLeft, newTopRight, newBottomRight, newBottomLeft, newLastMousePoint, newCenterVector;
changedSize = false;
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
oldAngle = this.objectRotation;
savePT = pt;
pt = new PointF(((pt.X-this.center.X)*rotCos - (pt.Y-this.center.Y)*rotSin), ((pt.X-this.center.X)*rotSin + (pt.Y-this.center.Y)*rotCos));
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-this.center.X)*rotCos - (IO.getTopLeft().Y-this.center.Y)*rotSin), ((IO.getTopLeft().X-this.center.X)*rotSin + (IO.getTopLeft().Y-this.center.Y)*rotCos));
newTopRight = new PointF(((IO.getTopRight().X-this.center.X)*rotCos - (IO.getTopRight().Y-this.center.Y)*rotSin), ((IO.getTopRight().X-this.center.X)*rotSin + (IO.getTopRight().Y-this.center.Y)*rotCos));
newBottomRight = new PointF(((IO.getBottomRight().X-this.center.X)*rotCos - (IO.getBottomRight().Y-this.center.Y)*rotSin), ((IO.getBottomRight().X-this.center.X)*rotSin + (IO.getBottomRight().Y-this.center.Y)*rotCos));
newBottomLeft = new PointF(((IO.getBottomLeft().X-this.center.X)*rotCos - (IO.getBottomLeft().Y-this.center.Y)*rotSin), ((IO.getBottomLeft().X-this.center.X)*rotSin + (IO.getBottomLeft().Y-this.center.Y)*rotCos));
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-this.center.X)*rotCos - (IO.getLastMousePoint().Y-this.center.Y)*rotSin), ((IO.getLastMousePoint().X-this.center.X)*rotSin + (IO.getLastMousePoint().Y-this.center.Y)*rotCos));
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
if (IO.hasToChange(scaleValue) == true)
{
if (changedSize == false) changedSize = true;
oldScale = IO.getLastScaleValue();
newScale = IO.getNextStep(scaleValue);
if (newScale< oldScale) vectorCpt = new PointF(((IO.CentrePoint.X-pt.X)*(newScale/oldScale)), ((IO.CentrePoint.Y-pt.Y)*(newScale/oldScale)));
else vectorCpt = new PointF(((IO.CentrePoint.X-pt.X)), ((IO.CentrePoint.Y-pt.Y)));
newPos = new PointF(pt.X+vectorCpt.X, pt.Y+vectorCpt.Y);
IO.translateInterfaceObject(new PointF(newPos.X-IO.CentrePoint.X, newPos.Y-IO.CentrePoint.Y));
IO.onlySelScale(newScale);
}
}
this.SELObjectMax_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMin_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMax_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
this.SELObjectMin_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
foreach (InterfaceObject SELObj in InterfaceOBJList)
{
this.RNTFindBoundingBox(SELObj.getTopLeft());
this.RNTFindBoundingBox(SELObj.getTopRight());
this.RNTFindBoundingBox(SELObj.getBottomLeft());
this.RNTFindBoundingBox(SELObj.getBottomRight());
}
newCenterVector = new PointF((this.SELObjectMin_X+this.SELObjectMax_X)/2.0f, (this.SELObjectMin_Y+this.SELObjectMax_Y)/2.0f);
rotSin = (float) (Math.Sin(objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(objectRotation*Math.PI/180.0));
pt = new PointF(((pt.X-newCenterVector.X)*rotCos - (pt.Y-newCenterVector.Y)*rotSin)+this.center.X, ((pt.X-newCenterVector.X)*rotSin + (pt.Y-newCenterVector.Y)*rotCos)+this.center.Y);
vectorCpt = new PointF(savePT.X-pt.X, savePT.Y-pt.Y);
this.topLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.topRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
this.objectRotation = 0;
this.width = distance(topLeft, topRight);
this.height = distance(topLeft, bottomLeft);
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-newCenterVector.X)*rotCos - (IO.getTopLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopLeft().X-newCenterVector.X)*rotSin + (IO.getTopLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newTopRight = new PointF(((IO.getTopRight().X-newCenterVector.X)*rotCos - (IO.getTopRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopRight().X-newCenterVector.X)*rotSin + (IO.getTopRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomRight = new PointF(((IO.getBottomRight().X-newCenterVector.X)*rotCos - (IO.getBottomRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomRight().X-newCenterVector.X)*rotSin + (IO.getBottomRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomLeft = new PointF(((IO.getBottomLeft().X-newCenterVector.X)*rotCos - (IO.getBottomLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomLeft().X-newCenterVector.X)*rotSin + (IO.getBottomLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-newCenterVector.X)*rotCos - (IO.getLastMousePoint().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getLastMousePoint().X-newCenterVector.X)*rotSin + (IO.getLastMousePoint().Y-newCenterVector.Y)*rotCos)+this.center.Y);
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
}
return changedSize;
}
//tests if the object is insode the desktop area after deselecting
public void testInsideDesktop(ArrayList InterfaceOBJList)
{
PointF newPos;
foreach(InterfaceObject IO in InterfaceOBJList)
{
newPos = IO.CentrePoint;
if (newPos.X < (this.ClientLeft+13)) newPos.X = (this.ClientLeft+15);
if (newPos.Y < (this.ClientTop+13)) newPos.Y = (this.ClientTop+15);
if (newPos.X > (this.ClientRight-13)) newPos.X = (this.ClientRight-15);
if (newPos.Y > (this.ClientBottom-13)) newPos.Y = (this.ClientBottom-15);
IO.translateInterfaceObject(new PointF(newPos.X-IO.CentrePoint.X, newPos.Y-IO.CentrePoint.Y));
IO.translateEndInterfaceObject();
IO.setLastMousePoint(IO.CentrePoint);
}
}
// set the border of the desktop to rnt - object
public void setClientBorder(float csL, float csT, float csR, float csB)
{
this.ClientLeft = csL;
this.ClientTop = csT;
this.ClientRight = csR;
this.ClientBottom = csB;
}
// is for MultiSelectionScaling
// will called by the MouseDown - Event
public void RNTSelScaleDown(PointF selScalePoint, InterfaceObject obj)
{
this.RNTMultSelectionScalePoint = selScalePoint;
this.RNTSelScaleObject = obj;
}
// will called by the MouseMove - Event
public void RNTSelScaleMove(PointF selScalePoint, float scaleValue, ArrayList InterfaceOBJList)
{
float IOScaleWidth, IOScaleHeight, difWidth, difHeight;
float rotSin, rotCos, oldAngle;
PointF sc, savePT, vectorCpt;
PointF scaleVector, scaleVector2;
PointF newOBJTopRight, newOBJBottomRight, newOBJBottomLeft;
PointF newTopLeft, newTopRight, newBottomRight, newBottomLeft, newLastMousePoint, newCenterVector;
scaleVector = new PointF(selScalePoint.X-this.RNTMultSelectionScalePoint.X, selScalePoint.Y-this.RNTMultSelectionScalePoint.Y);
sc = this.RNTSelScaleObject.getTopLeft();
savePT = sc;
newOBJBottomRight = new PointF(RNTSelScaleObject.getBottomRight().X+scaleVector.X, RNTSelScaleObject.getBottomRight().Y+scaleVector.Y);
scaleVector2 = new PointF(newOBJBottomRight.X-RNTSelScaleObject.getTopLeft().X, newOBJBottomRight.Y-RNTSelScaleObject.getTopLeft().Y);
IOScaleWidth = (RNTSelScaleObject.getVectorHorizontal().X*scaleVector2.X+RNTSelScaleObject.getVectorHorizontal().Y*scaleVector2.Y);
IOScaleHeight = (RNTSelScaleObject.getVectorVerticaly().X*scaleVector2.X+RNTSelScaleObject.getVectorVerticaly().Y*scaleVector2.Y);
difWidth = IOScaleWidth - this.RNTSelScaleObject.getWidth();
difHeight = IOScaleHeight - this.RNTSelScaleObject.getHeight();
foreach(InterfaceObject IO in InterfaceOBJList)
{
newOBJTopRight = new PointF((IO.getTopLeft().X+(IO.getWidth()+difWidth)*IO.getVectorHorizontal().X), (IO.getTopLeft().Y+(IO.getWidth()+difWidth)*IO.getVectorHorizontal().Y));
newOBJBottomLeft = new PointF((IO.getTopLeft().X+(IO.getHeight()+difHeight)*IO.getVectorVerticaly().X), (IO.getTopLeft().Y+(IO.getHeight()+difHeight)*IO.getVectorVerticaly().Y));
newOBJBottomRight = new PointF((newOBJTopRight.X+(IO.getHeight()+difHeight)*IO.getVectorVerticaly().X), (newOBJTopRight.Y+(IO.getHeight()+difHeight)*IO.getVectorVerticaly().Y));
IO.resizeSELInterfaceObject(IO.getTopLeft(), newOBJTopRight, newOBJBottomRight, newOBJBottomLeft, scaleValue);
}
this.RNTMultSelectionScalePoint = selScalePoint;
rotSin = (float) (Math.Sin(-objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(-objectRotation*Math.PI/180.0));
oldAngle = this.objectRotation;
sc = new PointF(((sc.X-this.center.X)*rotCos - (sc.Y-this.center.Y)*rotSin), ((sc.X-this.center.X)*rotSin + (sc.Y-this.center.Y)*rotCos));
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-this.center.X)*rotCos - (IO.getTopLeft().Y-this.center.Y)*rotSin), ((IO.getTopLeft().X-this.center.X)*rotSin + (IO.getTopLeft().Y-this.center.Y)*rotCos));
newTopRight = new PointF(((IO.getTopRight().X-this.center.X)*rotCos - (IO.getTopRight().Y-this.center.Y)*rotSin), ((IO.getTopRight().X-this.center.X)*rotSin + (IO.getTopRight().Y-this.center.Y)*rotCos));
newBottomRight = new PointF(((IO.getBottomRight().X-this.center.X)*rotCos - (IO.getBottomRight().Y-this.center.Y)*rotSin), ((IO.getBottomRight().X-this.center.X)*rotSin + (IO.getBottomRight().Y-this.center.Y)*rotCos));
newBottomLeft = new PointF(((IO.getBottomLeft().X-this.center.X)*rotCos - (IO.getBottomLeft().Y-this.center.Y)*rotSin), ((IO.getBottomLeft().X-this.center.X)*rotSin + (IO.getBottomLeft().Y-this.center.Y)*rotCos));
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-this.center.X)*rotCos - (IO.getLastMousePoint().Y-this.center.Y)*rotSin), ((IO.getLastMousePoint().X-this.center.X)*rotSin + (IO.getLastMousePoint().Y-this.center.Y)*rotCos));
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
}
this.SELObjectMax_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMin_X = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.X;
this.SELObjectMax_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
this.SELObjectMin_Y = ((InterfaceObject) InterfaceOBJList[0]).CentrePoint.Y;
foreach (InterfaceObject SELObj in InterfaceOBJList)
{
this.RNTFindBoundingBox(SELObj.getTopLeft());
this.RNTFindBoundingBox(SELObj.getTopRight());
this.RNTFindBoundingBox(SELObj.getBottomLeft());
this.RNTFindBoundingBox(SELObj.getBottomRight());
}
newCenterVector = new PointF((this.SELObjectMin_X+this.SELObjectMax_X)/2.0f, (this.SELObjectMin_Y+this.SELObjectMax_Y)/2.0f);
rotSin = (float) (Math.Sin(objectRotation*Math.PI/180.0));
rotCos = (float) (Math.Cos(objectRotation*Math.PI/180.0));
sc = new PointF(((sc.X-newCenterVector.X)*rotCos - (sc.Y-newCenterVector.Y)*rotSin)+this.center.X, ((sc.X-newCenterVector.X)*rotSin + (sc.Y-newCenterVector.Y)*rotCos)+this.center.Y);
vectorCpt = new PointF(savePT.X-sc.X, savePT.Y-sc.Y);
this.topLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.topRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMin_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomRight = new PointF(this.SELObjectMax_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.bottomLeft = new PointF(this.SELObjectMin_X-newCenterVector.X+this.center.X+vectorCpt.X, this.SELObjectMax_Y-newCenterVector.Y+this.center.Y+vectorCpt.Y);
this.offsetMatrix.Reset();
this.translationMatrix.Reset();
this.transformMatrix.Reset();
this.interactionMatrix.Reset();
this.objectRotation = 0;
this.width = distance(topLeft, topRight);
this.height = distance(topLeft, bottomLeft);
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.SetRotationAngle(oldAngle);
foreach(InterfaceObject IO in InterfaceOBJList)
{
newTopLeft = new PointF(((IO.getTopLeft().X-newCenterVector.X)*rotCos - (IO.getTopLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopLeft().X-newCenterVector.X)*rotSin + (IO.getTopLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newTopRight = new PointF(((IO.getTopRight().X-newCenterVector.X)*rotCos - (IO.getTopRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getTopRight().X-newCenterVector.X)*rotSin + (IO.getTopRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomRight = new PointF(((IO.getBottomRight().X-newCenterVector.X)*rotCos - (IO.getBottomRight().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomRight().X-newCenterVector.X)*rotSin + (IO.getBottomRight().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newBottomLeft = new PointF(((IO.getBottomLeft().X-newCenterVector.X)*rotCos - (IO.getBottomLeft().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getBottomLeft().X-newCenterVector.X)*rotSin + (IO.getBottomLeft().Y-newCenterVector.Y)*rotCos)+this.center.Y);
newLastMousePoint = new PointF(((IO.getLastMousePoint().X-newCenterVector.X)*rotCos - (IO.getLastMousePoint().Y-newCenterVector.Y)*rotSin)+this.center.X, ((IO.getLastMousePoint().X-newCenterVector.X)*rotSin + (IO.getLastMousePoint().Y-newCenterVector.Y)*rotCos)+this.center.Y);
IO.setNewCornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft, 0.0f, 1.0f, true);
IO.setLastMousePoint(newLastMousePoint);
}
}
// updates / create a new rnt - object
public void updateRNTObject(PointF topLeft, PointF topRight, PointF bottomRight, PointF bottomLeft, IOSelectObject IOS)
{
this.rpFinal[0] = new PointF(0,0);
this.offsetMatrix = new Matrix();
this.translationMatrix = new Matrix();
this.transformMatrix = new Matrix();
this.interactionMatrix = new Matrix();
this.objectRotation = 0;
this.topLeft = new PointF(topLeft.X, topLeft.Y);
this.topRight = new PointF(topRight.X, topRight.Y);
this.bottomRight = new PointF(bottomRight.X, bottomRight.Y);
this.bottomLeft = new PointF(bottomLeft.X, bottomLeft.Y);
this.computeSideNormals(); // change made by Stefan Habelski
this.width = (this.bottomRight.X-this.topLeft.X)*this.RNTVectorHorizontal.X+(this.bottomRight.Y-this.topLeft.Y)*this.RNTVectorHorizontal.Y;
this.height = (this.bottomRight.X-this.topLeft.X)*this.RNTVectorVerticaly.X+(this.bottomRight.Y-this.topLeft.Y)*this.RNTVectorVerticaly.Y;
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
this.center = new PointF(centre[0].X, centre[0].Y);
this.offsetMatrix.Translate(- this.width / 2, - this.height / 2);
this.translationMatrix.Translate (this.topLeft.X + (this.width/2), this.topLeft.Y + (this.height/2));
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
this.updateTransform();
this.RNTSelLastMousePointTest(IOS);
this.originalMouseDown = IOS.getLastMousePoint();
SizeF CO, OT, CT;
CO = new SizeF (this.originalMouseDown.X - centre[0].X, this.originalMouseDown.Y - centre[0].Y);
OT = new SizeF (targetMouseDown.X - this.originalMouseDown.X, targetMouseDown.Y - this.originalMouseDown.Y);
CT = new SizeF (CO.Width + OT.Width, CO.Height + OT.Height);
float theta, alpha;
theta = (float) Math.Atan2 (CT.Height, CT.Width);
alpha = (float) Math.Atan2 (CO.Height, CO.Width);
}
// will called by the MouseUp - Event
public void RNTSelUp(ArrayList InterfaceOBJList, IOSelectObject IOS)
{
PointF lpVector;
float scalarX, scalarY;
foreach(InterfaceObject IO in InterfaceOBJList)
{
IO.translateEndInterfaceObject();
this.RNTScaleUp(IO);
}
this.RNTMouseUp();
// here a test if the last mouse point of IOSelectObject is inside of the RNT - Object
lpVector = new PointF(IOS.getLastMousePoint().X-this.topLeft.X, IOS.getLastMousePoint().Y-this.topLeft.Y);
scalarX = lpVector.X*this.RNTVectorHorizontal.X+lpVector.Y*this.RNTVectorHorizontal.Y;
scalarY = lpVector.X*this.RNTVectorVerticaly.X+lpVector.Y*this.RNTVectorVerticaly.Y;
if (!(scalarX >= 0.0f && scalarX <= this.width && scalarY >= 0.0f && scalarY <= this.height)) IOS.setLastMousePoint(IOS.CentrePoint);
}
// tests if the last mouse point is inside the rnt - object
public void RNTSelLastMousePointTest(IOSelectObject IOS)
{
PointF lpVector;
float scalarX, scalarY;
// here a test if the last mouse point of IOSelectObject is inside of the RNT - Object
lpVector = new PointF(IOS.getLastMousePoint().X-this.topLeft.X, IOS.getLastMousePoint().Y-this.topLeft.Y);
scalarX = lpVector.X*this.RNTVectorHorizontal.X+lpVector.Y*this.RNTVectorHorizontal.Y;
scalarY = lpVector.X*this.RNTVectorVerticaly.X+lpVector.Y*this.RNTVectorVerticaly.Y;
if (!(scalarX >= 0.0f && scalarX <= this.width && scalarY >= 0.0f && scalarY <= this.height)) IOS.setLastMousePoint(IOS.CentrePoint);
}
// set new Corner Points of the RNTObject and computes the SideNormals
// returns if the Size of an InterfaceObject had to resized because it was under minimum size
public void setNewCornerPoints(PointF setTopLeft, PointF setTopRight, PointF setBottomRight, PointF setBottomLeft, float plusAngle, bool computeNormals)
{
bool changedSize;
changedSize = false;
this.topLeft = setTopLeft;
this.topRight = setTopRight;
this.bottomRight = setBottomRight;
this.bottomLeft = setBottomLeft;
this.center = this.center = new PointF((this.topLeft.X+this.bottomRight.X)/2.0f, (this.topLeft.Y+this.bottomRight.Y)/2.0f);
this.objectRotation = this.objectRotation + plusAngle;
if (computeNormals == true) this.computeSideNormals();
this.width = (this.bottomRight.X-this.topLeft.X)*this.RNTVectorHorizontal.X+(this.bottomRight.Y-this.topLeft.Y)*this.RNTVectorHorizontal.Y;
this.height = (this.bottomRight.X-this.topLeft.X)*this.RNTVectorVerticaly.X+(this.bottomRight.Y-this.topLeft.Y)*this.RNTVectorVerticaly.Y;
if (this.width < 79.90f)
{
this.width = 80.0f;
changedSize = true;
}
if (this.height < 79.90f)
{
this.height = 80.0f;
changedSize = true;
}
if (changedSize == true)
{
this.topRight = new PointF(this.topLeft.X+this.width*this.RNTVectorHorizontal.X, this.topLeft.Y+this.width*this.RNTVectorHorizontal.Y);
this.bottomLeft = new PointF(this.topLeft.X+this.height*this.RNTVectorVerticaly.X, this.topLeft.Y+this.height*this.RNTVectorVerticaly.Y);
this.bottomRight = new PointF(this.bottomLeft.X+this.width*this.RNTVectorHorizontal.X, this.bottomLeft.Y+this.width*this.RNTVectorHorizontal.Y);
}
this.translateOnlyZoneRadius = Math.Min((int)this.width/2 * this.translateOnlyZoneRadiusPercent/100, (int)this.height/2 * this.translateOnlyZoneRadiusPercent/100);
}
//returns the Horizontal Vector
public PointF getVectorHorizontal()
{
return this.RNTVectorHorizontal;
}
//returns the Verticaly Vector
public PointF getVectorVerticaly()
{
return this.RNTVectorVerticaly;
}
// computes the Horizontal Vector and the Verticaly Vector
private void computeSideNormals()
{
float vectorLENGTH;
/* calculating and normalizing vectors of the side directions */
this.RNTVectorHorizontal = new PointF((this.topRight.X-this.topLeft.X), (this.topRight.Y-this.topLeft.Y));
vectorLENGTH = 1.0f /((float) (Math.Sqrt((this.RNTVectorHorizontal.X*this.RNTVectorHorizontal.X)+(this.RNTVectorHorizontal.Y*this.RNTVectorHorizontal.Y))));
this.RNTVectorHorizontal.X *= vectorLENGTH;
this.RNTVectorHorizontal.Y *= vectorLENGTH;
this.RNTVectorVerticaly = new PointF((this.bottomLeft.X-this.topLeft.X), (this.bottomLeft.Y-this.topLeft.Y));
vectorLENGTH = 1.0f /((float) (Math.Sqrt((this.RNTVectorVerticaly.X*this.RNTVectorVerticaly.X)+(this.RNTVectorVerticaly.Y*this.RNTVectorVerticaly.Y))));
this.RNTVectorVerticaly.X *= vectorLENGTH;
this.RNTVectorVerticaly.Y *= vectorLENGTH;
}
/******************************************/
/* End of changes made by Stefan Habelski */
/******************************************/
//checks to see if point is within a rectangle defined by 4 corner points
public bool Contains (PointF p)
{
PointF[] pts = new PointF[4];
pts[0] = new PointF (this.topLeft.X, this.topLeft.Y);
pts[1] = new PointF (this.topRight.X, this.topRight.Y);
pts[2] = new PointF (this.bottomRight.X, this.bottomRight.Y);
pts[3] = new PointF (this.bottomLeft.X, this.bottomLeft.Y);
if (inside (pts[0], pts[1], p) && inside (pts[1], pts[2], p) && inside (pts[2], pts[3], p) && inside (pts[3], pts[0], p))
{
return true;
}
else
{
return false;
}
}
/* used by 'Contains(point)' to check if a point is within a rectangle defined by 4 corner points
uses a "to the right of" algorithm to determine whether a click is within a generalized convex polygon
http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/ */
private static bool inside (PointF p0, PointF p1, PointF p)
{
if (((p.Y - p0.Y) * (p1.X - p0.X) - (p.X - p0.X) * (p1.Y - p0.Y)) >= 0)
{
return true;
}
else
{
return false;
}
}
//algorithm for simultaneous rotation and translation
private void doTransform()
{
// transforms the centre point of image into screen space
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
// using "Size" as a two-element vector
// CO == centre of image to original mouse click point
// OT == original mouse click point to new target mouse point
// CT == centre of image to the target mouse point
SizeF CO, OT, CT;
CO = new SizeF (this.originalMouseDown.X - centre[0].X, this.originalMouseDown.Y - centre[0].Y);
OT = new SizeF (targetMouseDown.X - this.originalMouseDown.X, targetMouseDown.Y - this.originalMouseDown.Y);
CT = new SizeF (CO.Width + OT.Width, CO.Height + OT.Height);
float theta, alpha;
theta = (float) Math.Atan2 (CT.Height, CT.Width);
alpha = (float) Math.Atan2 (CO.Height, CO.Width);
double testDistance = 0.0;
testDistance = Math.Sqrt(CO.Width * CO.Width + CO.Height * CO.Height);
//makes sure point is outside of translate-only zone
if (testDistance > translateOnlyZoneRadius)
{
using (Matrix invertedTransformMatrix = this.transformMatrix.Clone())
{
// make the inverse of the transform matrix (so that can translate screen space -> object space)
invertedTransformMatrix.Invert();
if (rpFinal[0].X == 0 && rpFinal[0].Y == 0)
{
// convert the original mouse point into object space (this is the rotation point)
PointF[] rp = { new PointF(this.originalMouseDown.X, this.originalMouseDown.Y) };
invertedTransformMatrix.TransformPoints(rp);
rpFinal[0].X = rp[0].X;
rpFinal[0].Y = rp[0].Y;
}
// rotate about the rotation point (put in interaction matrix)
this.interactionMatrix.RotateAt (radiansToDegrees(theta - alpha), rpFinal[0]);
this.objectRotation += radiansToDegrees(theta - alpha);
while (this.objectRotation < 0)
{
this.objectRotation += 360;
}
while (this.objectRotation > 360)
{
this.objectRotation -= 360;
}
}
}
// translate by OT
this.translationMatrix.Translate (OT.Width, OT.Height);
this.originalMouseDown = new PointF (targetMouseDown.X, targetMouseDown.Y);
}
//algorithm for translating object only
private void translateOnly()
{
PointF[] centre = { new PointF(this.width/2,this.height/2) };
this.transformMatrix.TransformPoints (centre);
// using "Size" as a two-element vector
// CO == centre of image to original mouse click point
// OT == original mouse click point to new target mouse point
// CT == centre of image to the target mouse point
SizeF CO, OT, CT;
CO = new SizeF (this.originalMouseDown.X - centre[0].X, this.originalMouseDown.Y - centre[0].Y);
OT = new SizeF (targetMouseDown.X - this.originalMouseDown.X, targetMouseDown.Y - this.originalMouseDown.Y);
CT = new SizeF (CO.Width + OT.Width, CO.Height + OT.Height);
// translate by OT
this.translationMatrix.Translate (OT.Width, OT.Height);
this.originalMouseDown = new PointF (targetMouseDown.X, targetMouseDown.Y);
}
//converts radians to degrees
private static float radiansToDegrees (float radians)
{
return (float) (radians * 180.0 / Math.PI);
}
//calculates distance between 2 points
private static float distance(PointF pt1, PointF pt2)
{
return (float)Math.Sqrt(Math.Pow(pt1.X - pt2.X, 2) + Math.Pow(pt1.Y - pt2.Y, 2));
}
//updates the 4 corner points of the rnt object, as well as its center, and a point useful for drawing the translate-only region
private void updateTransform()
{
this.transformMatrix.Reset();
this.transformMatrix.Multiply(this.translationMatrix);
this.transformMatrix.Multiply(this.offsetMatrix);
this.transformMatrix.Multiply(this.interactionMatrix);
PointF[] objCenter = { new PointF(this.width/2,this.height/2) };
PointF[] objTopLeft = { new PointF(0,0) };
PointF[] objTopRight = { new PointF(this.width, 0) };
PointF[] objBottomRight = { new PointF(this.width, this.height) };
PointF[] objBottomLeft = { new PointF(0, this.height) };
this.transformMatrix.TransformPoints (objCenter);
this.transformMatrix.TransformPoints (objTopLeft);
this.transformMatrix.TransformPoints (objTopRight);
this.transformMatrix.TransformPoints (objBottomRight);
this.transformMatrix.TransformPoints (objBottomLeft);
this.center = objCenter[0];
this.topLeft = objTopLeft[0];
this.topRight = objTopRight[0];
this.bottomRight = objBottomRight[0];
this.bottomLeft = objBottomLeft[0];
this.translateOnlyZoneTopLeft = new PointF(objCenter[0].X - translateOnlyZoneRadius, objCenter[0].Y - translateOnlyZoneRadius) ;
}
}
}
See more files for this project here