/// <summary> /// Overridden. See <see cref="PInterpolatingActivity.OnActivityStarted"> /// PInterpolatingActivity.OnActivityStarted</see>. /// </summary> protected override void OnActivityStarted() { //if (FirstLoop) source = target.GetMatrix().MatrixReference.Elements; if (FirstLoop) { source = MatrixExtensions.GetElements(target.Matrix); } base.OnActivityStarted(); }
/// <summary> /// Constructs a new PTransformActivity that animate between the source and destination /// matrices in the order specified by the mode, looping the given number of iterations. /// </summary> /// <param name="duration">The length of one loop of the activity.</param> /// <param name="stepInterval"> /// The minimum number of milliseconds that this activity should delay between steps. /// </param> /// <param name="loopCount"> /// The number of times the activity should reschedule itself. /// </param> /// <param name="mode"> /// Defines how the activity interpolates between states. /// </param> /// <param name="aTarget"> /// The object that the activity will be applied to and where the source /// state will be taken from. /// </param> /// <param name="aDestination">The destination matrix.</param> public PTransformActivity(long duration, long stepInterval, int loopCount, ActivityMode mode, Target aTarget, Matrix aDestination) : base(duration, stepInterval, loopCount, mode) { source = new float[6]; destination = new float[6]; target = aTarget; if (aDestination != null) { destination = MatrixExtensions.GetElements(aDestination); } }
public override void SetViewPosition(float x, float y) { if (camera != null) { // If a scroll is in progress - we ignore new scrolls - // if we didn't, since the scrollbars depend on the camera location // we can end up with an infinite loo if (!scrollInProgress) { scrollInProgress = true; // Get the union of all the layers' bounds RectangleFx layerBounds = camera.UnionOfLayerFullBounds; Matrix matrix = camera.ViewMatrix; layerBounds = MatrixExtensions.Transform(matrix, layerBounds); // Union the camera view bounds RectangleFx viewBounds = camera.Bounds; layerBounds = RectangleFxtensions.Union(layerBounds, viewBounds); // Now find the new view position in view coordinates - // This is basically the distance from the lower right // corner of the window to the upper left corner of the // document // We then measure the offset from the lower right corner // of the document PointFx newPoint = new PointFx( layerBounds.X + layerBounds.Width - (x + viewBounds.Width), layerBounds.Y + layerBounds.Height - (y + viewBounds.Height)); // Now transform the new view position into global coords newPoint = camera.LocalToView(newPoint); // Compute the new matrix values to put the camera at the // correct location float[] elements = MatrixExtensions.GetElements(matrix); elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y); elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y); matrix = MatrixExtensions.SetElements(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); // Now actually set the camera's transform camera.ViewMatrix = matrix; scrollInProgress = false; } } }
/// <summary> /// Overridden. See <see cref="PNode.Paint">PNode.Paint</see>. /// </summary> protected override void Paint(PPaintContext paintContext) { XnaGraphics g = paintContext.Graphics; float x = X; float y = Y; float width = Width; float height = Height; Matrix transform = g.Transform; float[] elements = MatrixExtensions.GetElements(transform); float magX = elements[0]; float magY = elements[3]; float dx = (float)(1.0 / magX); float dy = (float)(1.0 / magY); g.FillRectangle(Brush, Bounds); path.Reset(); path.AddLine((float)(x + width), (float)y, (float)x, (float)y); path.AddLine((float)x, (float)y, (float)x, (float)(y + height)); pen.Color = System.Drawing.Color.FromArgb(topLeftOuterColor.A, topLeftOuterColor.R, topLeftOuterColor.G, topLeftOuterColor.B); g.DrawPath(pen, path); path.Reset(); path.AddLine((float)(x + width), (float)(y + dy), (float)(x + dx), (float)(y + dy)); path.AddLine((float)(x + dx), (float)(y + dy), (float)(x + dx), (float)(y + height)); pen.Color = System.Drawing.Color.FromArgb(topLeftInnerColor.A, topLeftInnerColor.R, topLeftInnerColor.G, topLeftInnerColor.B); g.DrawPath(pen, path); path.Reset(); path.AddLine((float)(x + width), (float)(y), (float)(x + width), (float)(y + height)); path.AddLine((float)(x + width), (float)(y + height), (float)(x), (float)(y + height)); pen.Color = System.Drawing.Color.FromArgb(bottomRightOuterColor.A, bottomRightOuterColor.R, bottomRightOuterColor.G, bottomRightOuterColor.B); g.DrawPath(pen, path); path.Reset(); path.AddLine((float)(x + width - dx), (float)(y + dy), (float)(x + width - dx), (float)(y + height - dy)); path.AddLine((float)(x + width - dx), (float)(y + height - dy), (float)(x), (float)(y + height - dy)); pen.Color = System.Drawing.Color.FromArgb(bottomRightInnerColor.A, bottomRightInnerColor.R, bottomRightInnerColor.G, bottomRightInnerColor.B); g.DrawPath(pen, path); }
/// <summary> /// Sets the view position in a manner consistent with standardized scrolling. /// </summary> /// <param name="x">The x coordinate of the new position.</param> /// <param name="y">The y coordinate of the new position.</param> public virtual void SetViewPosition(float x, float y) { if (camera != null) { // Only process this scroll if a scroll is not already in progress; // otherwise, we could end up with an infinite loop, since the // scrollbars depend on the camera location. if (!scrollInProgress) { scrollInProgress = true; // Get the union of all the layers' bounds RectangleFx layerBounds = UnionOfLayerFullBounds; Matrix matrix = camera.ViewMatrix; layerBounds = MatrixExtensions.Transform(matrix, layerBounds); // Union the camera bounds RectangleFx viewBounds = camera.Bounds; layerBounds = RectangleFxtensions.Union(layerBounds, viewBounds); // Now find the new view position in view coordinates PointFx newPoint = new PointFx(layerBounds.X + x, layerBounds.Y + y); // Now transform the new view position into global coords newPoint = camera.LocalToView(newPoint); // Compute the new matrix values to put the camera at the // correct location float[] elements = MatrixExtensions.GetElements(matrix); elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y); elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y); matrix = MatrixExtensions.SetElements(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); // Now actually set the camera's transform camera.ViewMatrix = matrix; scrollInProgress = false; } } }