protected void CreateRects(Random rnd) { PTransformActivity rotActivity; P3Path rect; // Create a bunch of animated rectangles for (int x = 0; x < 2000; x += 100) { for (int y = 200; y < 1500; y += 100) { int w = 200; int h = 200; rect = P3Path.CreateRectangle(x, y, w, h); rect.Brush = new SolidBrush(Color.FromArgb(50, Color.Purple.R, Color.Purple.G, Color.Purple.B)); rect.Pen = new Pen(Color.Red, 0); canvas.Layer.AddChild(rect); PMatrix matrix = new PMatrix(); matrix.RotateBy(90, x + w / 2, y + h / 2); rotActivity = rect.AnimateToMatrix(matrix, 5000 + (long)(2000 * rnd.NextDouble())); rotActivity.LoopCount = 1000; rotActivity.Mode = ActivityMode.SourceToDestinationToSource; } } }
/// <summary> /// Animates the camera's view to keep the focus node on the screen and at 100 /// percent scale with minimal view movement. /// </summary> /// <param name="aCamera">The camera whose view will be animated.</param> /// <param name="aFocusNode">The focus node to animate to.</param> /// <param name="duration">The length of the animation.</param> /// <returns> /// The activity that animates the camera's view to the focus node. /// </returns> public virtual PActivity DirectCameraViewToFocus(PCamera aCamera, PNode aFocusNode, int duration) { PMatrix originalViewMatrix = aCamera.ViewMatrix; // Scale the canvas to include SizeF s = new SizeF(1, 0); s = focusNode.GlobalToLocal(s); float scaleFactor = s.Width / aCamera.ViewScale; PointF scalePoint = PUtil.CenterOfRectangle(focusNode.GlobalFullBounds); if (scaleFactor != 1) { aCamera.ScaleViewBy(scaleFactor, scalePoint.X, scalePoint.Y); } // Pan the canvas to include the view bounds with minimal canvas // movement. aCamera.AnimateViewToPanToBounds(focusNode.GlobalFullBounds, 0); // Get rid of any white space. The canvas may be panned and // zoomed in to do this. But make sure not stay constrained by max // magnification. //FillViewWhiteSpace(aCamera); PMatrix resultingMatrix = aCamera.ViewMatrix; aCamera.ViewMatrix = originalViewMatrix; // Animate the canvas so that it ends up with the given // view transform. return(AnimateCameraViewMatrixTo(aCamera, resultingMatrix, duration)); }
public bool invisibleDragArea(float x, float y, float w, float h, ref bool isDrag, out int dragX, out int dragY) { PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); if ((isActive || isDrag) && (uiMousePressed || uiMouseReleased)) { dragX = uiMouseDragX; dragY = uiMouseDragY; int margin = 2; if (!isDrag && abs(dragX) <= margin && abs(dragY) <= margin) { isDrag = false; } else { isDrag = true; } } else { dragX = dragY = 0; isDrag = false; } return(isDrag); }
/// <summary> /// Returns true if this path intersects the given rectangle. /// </summary> /// <remarks> /// This method first checks if the interior of the path intersects with the rectangle. /// If not, the method then checks if the path bounding the pen stroke intersects with /// the rectangle. If either of these cases are true, this method returns true. /// <para> /// <b>Performance Note</b>: For some paths, this method can be very slow. This is due /// to the implementation of IsVisible. The problem usually occurs when many lines are /// joined at very steep angles. See the documentation above for workarounds. /// </para> /// </remarks> /// <param name="bounds">The rectangle to check for intersection.</param> /// <param name="matrix"> /// A matrix object that specifies a transform to apply to the path and bounds before /// checking for an intersection. /// </param> /// <returns>True if this path intersects the given rectangle; otherwise, false.</returns> public virtual bool Intersects(RectangleF bounds, PMatrix matrix) { if (base.Intersects(bounds)) { // Transform the bounds. if (!matrix.IsIdentity) { bounds = matrix.Transform(bounds); } // Set the temp region to the transformed path. SetTempRegion(path, matrix, false); if (Brush != null && TEMP_REGION.IsVisible(bounds)) { return(true); } else if (pen != null) { // Set the temp region to the transformed, widened path. SetTempRegion(path, matrix, true); return(TEMP_REGION.IsVisible(bounds)); } } return(false); }
/// <summary> /// Animate the camera's view matrix from its current value when the activity /// starts to the new destination matrix value. /// </summary> /// <param name="aCamera">The camera whose view matrix will be animated.</param> /// <param name="aMatrix">The final matrix value.</param> /// <param name="duration"> /// The amount of time that the animation should take. /// </param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> protected virtual PActivity AnimateCameraViewMatrixTo(PCamera aCamera, PMatrix aMatrix, int duration) { bool wasOldAnimation = false; // first stop any old animations. if (navigationActivity != null) { navigationActivity.Terminate(); wasOldAnimation = true; } if (duration == 0) { aCamera.ViewMatrix = aMatrix; return(null); } PMatrix source = aCamera.ViewMatrixReference; if (!source.MatrixReference.Equals(aMatrix.MatrixReference)) { navigationActivity = aCamera.AnimateViewToMatrix(aMatrix, duration); ((PTransformActivity)navigationActivity).SlowInSlowOut = !wasOldAnimation; return(navigationActivity); } return(null); }
/// <summary> /// Constructs a new camera with no layers and a default white color. /// </summary> public PCamera() : base() { viewMatrix = new PMatrix(); layers = new PLayerList(); viewConstraint = CameraViewConstraint.None; Brush = new SolidBrush(Color.White); }
/// <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 = (PMatrix)target.Matrix.Clone(); //.MatrixReference.Elements; } base.OnActivityStarted(); }
/// <summary> /// Mimics the standard <see cref="PCamera.AnimateViewToCenterBounds">AnimateViewToCenterBounds</see> /// but uses a cached image for performance rather than re-rendering the scene at each step /// </summary> /// <param name="centerBounds">The bounds to center the view on.</param> /// <param name="shouldScaleToFit"> /// Indicates whether the camera should scale it's view when necessary to fully fit /// the given bounds within the camera's view bounds. /// </param> /// <param name="duration">The amount of time that the animation should take.</param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> public PTransformActivity AnimateStaticViewToCenterBoundsFast(RectangleF centerBounds, bool shouldScaleToFit, long duration) { if (duration == 0) { return(AnimateViewToCenterBounds(centerBounds, shouldScaleToFit, duration)); } PMatrix newViewMatrix = CacheViewBounds(centerBounds, shouldScaleToFit); return(AnimateStaticViewToTransformFast(newViewMatrix, duration)); }
/// <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, PMatrix aDestination) : base(duration, stepInterval, loopCount, mode) { //source = new float[6]; //destination = new float[6]; target = aTarget; //if (aDestination != null) { // destination = aDestination.MatrixReference.Elements; //} source = new PMatrix(); destination = new PMatrix(); destination.Multiply(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 RectangleF layerBounds = camera.UnionOfLayerFullBounds; PMatrix matrix = camera.ViewMatrix; layerBounds = matrix.Transform(layerBounds); // Union the camera view bounds RectangleF viewBounds = camera.Bounds; layerBounds = RectangleF.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 PointF newPoint = new PointF( 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 = matrix.Elements; elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y); elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y); matrix = new PMatrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); // Now actually set the camera's transform camera.ViewMatrix = matrix; scrollInProgress = false; } } }
public void LayoutCurrentPosition() { // Move the current position indicator to the new focus slide's spot in the slide bar if (focusSlide == null) { currentPosition.Visible = false; } else { PMatrix matrix = GetUnfocusedMatrix(currentPosition, (int)focusSlide.Tag); matrix.TranslateBy(0, -IMAGE_PADDING); currentPosition.AnimateToMatrix(matrix, ANIMATION_TIME_MILLIS); currentPosition.Visible = true; } }
/// <summary> /// Sets the world transform of the device. /// </summary> /// <param name="matrix"></param> protected virtual void SetWorldMatrix(PMatrix matrix) { float[] piccoloMatrixElements = matrix.Elements; Matrix worldMatrix = new Matrix(); worldMatrix.M11 = piccoloMatrixElements[0]; worldMatrix.M12 = piccoloMatrixElements[1]; worldMatrix.M21 = piccoloMatrixElements[2]; worldMatrix.M22 = piccoloMatrixElements[3]; worldMatrix.M41 = piccoloMatrixElements[4]; worldMatrix.M42 = piccoloMatrixElements[5]; worldMatrix.M33 = 1; worldMatrix.M44 = 1; device.Transform.World = worldMatrix; }
/// <summary> /// Overridden. See <see cref="PPaintContext.PushMatrix">PPaintContext.PushTransform</see>. /// </summary> public override void PushMatrix(PMatrix matrix) { if (matrix == null) { return; } RectangleF newLocalClip = matrix.InverseTransform(LocalClip); localClipStack.Push(newLocalClip); PMatrix newMatrix = (PMatrix)Transform.Clone(); newMatrix.Multiply(matrix); transformStack.Push(newMatrix); SetWorldMatrix(newMatrix); }
/// <summary> /// Get the matrix that will transform the slide to fit in the slide bar. /// </summary> public PMatrix GetUnfocusedMatrix(PNode node, int index) { float scale = 1; if (node.Tag != null) // Only scale actual slides { scale = (slideBar.Height - IMAGE_PADDING) / node.Height; } PMatrix matrix = new PMatrix(); float maxSpacePerSlide = (Width - (node.Width * scale)) / (slides.Count - 1); matrix.Scale = scale; matrix.OffsetX = index * maxSpacePerSlide; matrix.OffsetY = IMAGE_PADDING; return(matrix); }
//**************************************************************** // Animation - Methods to animate the camera's view. //**************************************************************** /// <summary> /// Animate the camera's view from its current matrix when the activity starts /// to a new matrix that centers the given bounds in the camera layers' coordinate /// system into the camera's view bounds. /// </summary> /// <param name="centerBounds">The bounds to center the view on.</param> /// <param name="shouldScaleToFit"> /// Indicates whether the camera should scale it's view when necessary to fully fit /// the given bounds within the camera's view bounds. /// </param> /// <param name="duration">The amount of time that the animation should take.</param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> /// <remarks> /// If the duration is 0 then the view will be transformed immediately, and null will /// be returned. Else a new PTransformActivity will get returned that is set to /// animate the camera’s view matrix to the new bounds. If shouldScaleToFit is true, /// then the camera will also scale its view so that the given bounds fit fully within /// the camera's view bounds, else the camera will maintain its original scale. /// </remarks> public virtual PTransformActivity AnimateViewToCenterBounds(RectangleF centerBounds, bool shouldScaleToFit, long duration) { SizeF delta = PUtil.DeltaRequiredToCenter(ViewBounds, centerBounds); PMatrix newMatrix = ViewMatrix; newMatrix.TranslateBy(delta.Width, delta.Height); if (shouldScaleToFit) { float s = Math.Min(ViewBounds.Width / centerBounds.Width, ViewBounds.Height / centerBounds.Height); PointF c = PUtil.CenterOfRectangle(centerBounds); newMatrix.ScaleBy(s, c.X, c.Y); } return(AnimateViewToMatrix(newMatrix, duration)); }
/// <summary> /// Gets a string representation of the elements of a matrix. /// </summary> /// <param name="elements">The elements of a matrix.</param> /// <returns>A string representation of the elements of a matrix.</returns> protected static String GetElementString(PMatrix elements) { return(elements.OffsetX + " " + elements.OffsetY + " " + elements.Scale); /* * StringBuilder result = new StringBuilder(); * * int length = elements.Length; * for (int i = 0; i < elements.Length; i++) { * result.Append(elements[i].ToString()); * if (i < length-1) result.Append(", "); * } * * return result.ToString(); */ }
/// <summary> /// Caches the information necessary to animate from the current view bounds to the /// specified centerBounds /// </summary> /// <param name="centerBounds">The bounds to center the view on.</param> /// <param name="scaleToFit"> /// Indicates whether the camera should scale it's view when necessary to fully fit /// the given bounds within the camera's view bounds. /// </param> /// <returns>The new view matrix to center the specified bounds.</returns> private PMatrix CacheViewBounds(RectangleF centerBounds, bool scaleToFit) { RectangleF viewBounds = ViewBounds; // Initialize the image to the union of the current and destination bounds RectangleF imageBounds = viewBounds; imageBounds = RectangleF.Union(imageBounds, centerBounds); AnimateViewToCenterBounds(imageBounds, scaleToFit, 0); imageAnimateBounds = ViewBounds; // Now create the actual cache image that we will use to animate fast Image buffer = PaintBuffer; Brush fBrush = Brushes.White; if (Brush != null) { fBrush = Brush; } ToImage(buffer, fBrush); // Do this after the painting above! imageAnimate = true; // Return the bounds to the previous viewbounds AnimateViewToCenterBounds(viewBounds, scaleToFit, 0); // The code below is just copied from animateViewToCenterBounds to create the // correct transform to center the specified bounds SizeF delta = PUtil.DeltaRequiredToCenter(viewBounds, centerBounds); PMatrix newMatrix = ViewMatrix; newMatrix.TranslateBy(delta.Width, delta.Height); if (scaleToFit) { float s = Math.Min(viewBounds.Width / centerBounds.Width, viewBounds.Height / centerBounds.Height); PointF center = PUtil.CenterOfRectangle(centerBounds); newMatrix.ScaleBy(s, center.X, center.Y); } return(newMatrix); }
public virtual PActivity DirectCameraViewToFocus(PCamera aCamera, PNode aFocusNode, PPickPath path, int duration) { PMatrix originalViewMatrix = aCamera.ViewMatrix; // Scale the canvas to include SizeF s = new SizeF(1, 0); s = aFocusNode.GlobalToLocal(s); float scaleFactor = s.Width / aCamera.ViewScale; PointF scalePoint = PUtil.CenterOfRectangle(aFocusNode.GlobalFullBounds); if (scaleFactor != 1) { aCamera.ScaleViewBy(scaleFactor, scalePoint.X, scalePoint.Y); } // Pan the canvas to include the view bounds with minimal canvas // movement. aCamera.AnimateViewToPanToBounds(aFocusNode.GlobalFullBounds, 0); // Get rid of any white space. The canvas may be panned and // zoomed in to do this. But make sure not stay constrained by max // magnification. //FillViewWhiteSpace(aCamera); PMatrix resultingMatrix = aCamera.ViewMatrix; aCamera.ViewMatrix = originalViewMatrix; // Animate the canvas so that it ends up with the given // view transform. PActivity animateCameraViewActivity = AnimateCameraViewMatrixTo(aCamera, resultingMatrix, duration); PControl controlNode = (PControl)aFocusNode; aCamera.Root.WaitForActivities(); controlNode.CurrentCanvas = path.TopCamera.Canvas; PointF pf = path.GetPathTransformTo(controlNode).Transform(new PointF(controlNode.X, controlNode.Y)); controlNode.ControlLocation = new Point((int)pf.X, (int)pf.Y); controlNode.Editing = true; return(animateCameraViewActivity); }
//**************************************************************** // Painting - Methods for painting a PText. //**************************************************************** /// <summary> /// Overridden. See <see cref="PNode.Paint">PNode.Paint</see>. /// </summary> protected override void Paint(UMD.HCIL.Piccolo.Util.PPaintContext paintContext) { base.Paint(paintContext); Device device = (paintContext as P3PaintContext).Device; PMatrix currMatrix = (paintContext as P3PaintContext).Transform; // Scale the matrix down to display font units float scale = displayFontSize / font.Size; currMatrix.ScaleBy(scale, X, Y); float[] piccoloMatrixElements = currMatrix.Elements; if (!currMatrix.IsIdentity) { Matrix m = new Matrix(); m.M11 = piccoloMatrixElements[0]; m.M12 = piccoloMatrixElements[1]; m.M21 = piccoloMatrixElements[2]; m.M22 = piccoloMatrixElements[3]; m.M41 = piccoloMatrixElements[4]; m.M42 = piccoloMatrixElements[5]; m.M33 = 1; m.M44 = 1; textSprite.Transform = m; } textSprite.Begin(SpriteFlags.None); DrawTextFormat D3DAlignment = P3Util.GetD3DAlignment(stringFormat.Alignment); // Calculate the rectangle with no padding, in actual font units scale = 1 / scale; int totHzPadding = currLeftPadding + currRightPadding; int totVtPadding = currTopPadding + currBottomPadding; Rectangle dstRect = new Rectangle((int)(Bounds.X + currLeftPadding * scale), (int)(Bounds.Y + currTopPadding * scale), (int)((Bounds.Width - totHzPadding) * scale), (int)((Bounds.Height - totVtPadding) * scale)); // Wrap the string ourselves, instead of letting the draw method do it, since we want to make // sure it's consistent with our own MeasureString method. String str = P3Util.WrapString(textSprite, D3Dfont, Text, dstRect.Width, (TextBrush as SolidBrush).Color); D3Dfont.DrawText(textSprite, str, dstRect, D3DAlignment, (TextBrush as SolidBrush).Color); textSprite.End(); }
protected void CreateText(Random rnd) { // Create some text P3Text text = new P3Text("Direct3D Piccolo Renderer"); text.Brush = Brushes.Blue; text.TextBrush = Brushes.Yellow; text.Font = new System.Drawing.Font("Arial", 120); canvas.Layer.AddChild(text); PMatrix tMatrix = text.Matrix; tMatrix.TranslateBy(canvas.Width - text.Width, 0); PTransformActivity translateActivity = text.AnimateToMatrix(tMatrix, 10000 + (long)(2000 * rnd.NextDouble())); translateActivity.LoopCount = 1000; translateActivity.Mode = ActivityMode.SourceToDestinationToSource; }
public bool invisibleButton(float x, float y, float w, float h) { PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); bool isClick = uiClickUp ? uiMouseReleased : uiMousePressed; if (isActive && isClick) { buttonClick(uiStyle.groupName, name, null); } return(isActive && isClick); }
public bool button(string name, float x, float y, float w, float h, int textSize = 0) { pushStyle(); string objName = "button: " + name; var obj = pushMatrix(objName); PMatrix matrix = getMatrix(); matrix.invert(); Vector3 mv = matrix.mult(new Vector3(uiMouseX, uiMouseY)); //bool isActive = (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); bool isActive = (mv.x > x && mv.x <x + w && mv.y> y && mv.y < y + h); PUIStyle.Property prop = isActive ? uiStyle.active : uiStyle.normal; if (prop.frameWeight > 0) { stroke(prop.frameColor); strokeWeight(prop.frameWeight); } else { noStroke(); } fill(prop.bgColor); float fh = prop.frameWeight * 0.2f; rect(x + fh, y + fh, w - fh * 2, h - fh * 2); fill(prop.textColor); uiText(name, x, y, w, h, textSize); popMatrix(objName); popStyle(); bool isClick = uiClickUp ? uiMouseReleased : uiMousePressed; if (isActive && isClick) { buttonClick(uiStyle.groupName, name, obj); } return(isActive && isClick); }
/// <summary> /// This copies the behavior of the standard /// <see cref="PCamera.AnimateViewToMatrix">AnimateViewToMatrix</see> but clears the cache /// when it is done. /// </summary> /// <param name="destination">The final matrix value.</param> /// <param name="duration">The amount of time that the animation should take.</param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> protected PTransformActivity AnimateStaticViewToTransformFast(PMatrix destination, long duration) { if (duration == 0) { this.ViewMatrix = destination; return(null); } PTransformActivity ta = new FastTransformActivity(this, duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, new PCamera.PCameraTransformTarget(this), destination); PRoot r = Root; if (r != null) { r.ActivityScheduler.AddActivity(ta); } return(ta); }
/// <summary> /// Animate the camera's view matrix from its current value when the activity starts /// to the new destination matrix value. /// </summary> /// <param name="destination">The final matrix value.</param> /// <param name="duration">The amount of time that the animation should take.</param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> public virtual PTransformActivity AnimateViewToMatrix(PMatrix destination, long duration) { if (duration == 0) { ViewMatrix = destination; return(null); } PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, new PCameraTransformTarget(this), destination); PRoot r = Root; if (r != null) { r.AddActivity(ta); } return(ta); }
/// <summary> /// Hilite the specified slide - or unhilite all slides if hiliteIndex is -1. /// </summary> private void HiliteSlide(int newHiliteIndex) { PNode newSlide = null; if (newHiliteIndex >= 0) { newSlide = slides[newHiliteIndex]; } if (newSlide != hiliteSlide) { // First unhilite previously hilited slide if ((hiliteSlide != null) && (hiliteSlide != focusSlide)) { // If this slide is currently animating, then kill that animation int index = (int)hiliteSlide.Tag; if (slideActivities[index] != null) { slideActivities[index].Terminate(); slideActivities[index] = null; } (hiliteSlide as PMultiSizeImage).ShowThumb = true; (hiliteSlide as PMultiSizeImage).Hilite = false; PTransformActivity activity = hiliteSlide.AnimateToMatrix(GetUnfocusedMatrix(hiliteSlide, (int)hiliteSlide.Tag), SLIDEBAR_ANIMATION_TIME_MILLIS); // Put the slide in order when the animation finishes activity.ActivityFinished = new ActivityFinishedDelegate(HiliteActivityFinished); hiliteSlide = null; } // Then hilite new slide (as long is it isn't the currently focused slide) if (newSlide != focusSlide) { hiliteSlide = newSlide; if (hiliteSlide != null) { PMatrix matrix = GetUnfocusedMatrix(hiliteSlide, (int)hiliteSlide.Tag); matrix.ScaleBy(1.3f, (hiliteSlide.Bounds.Width / 2), hiliteSlide.Bounds.Height); (hiliteSlide as PMultiSizeImage).Hilite = true; hiliteSlide.MoveToFront(); currentPosition.MoveToFront(); slideActivities[newHiliteIndex] = hiliteSlide.AnimateToMatrix(matrix, SLIDEBAR_ANIMATION_TIME_MILLIS); } } } }
/// <summary> /// Overridden. See <see cref="PNode.Paint">PNode.Paint</see>. /// </summary> protected override void Paint(PPaintContext paintContext) { base.Paint(paintContext); Graphics g = paintContext.Graphics; PMatrix matrix = new PMatrix(g.Transform); RectangleF transRectF = matrix.Transform(bounds); Rectangle transRect = new Rectangle((int)transRectF.X, (int)transRectF.Y, (int)transRectF.Width, (int)transRectF.Height); // Draw the image if the control node is not in editing mode or // if the control is being rendered in a view other than the one // that owns the control. if (!Editing || control.Bounds != transRect || paintContext.Canvas != currentCanvas) { if (Image != null) { g.DrawImage(Image, bounds); } } }
/// <summary> /// Pan the camera's view from its current matrix when the activity starts to a new /// matrix so that the view bounds will contain (if possible, intersect if not /// possible) the new bounds in the camera layers' coordinate system. /// </summary> /// <param name="panToBounds">The bounds to pan the view to.</param> /// <param name="duration">The amount of time that the animation should take.</param> /// <returns> /// The newly scheduled activity, if the duration is greater than 0; else null. /// </returns> /// <remarks> /// If the duration is 0 then the view will be transformed immediately, and null will /// be returned. Else a new PTransformActivity will get returned that is set to /// animate the camera’s view matrix to the new bounds. /// </remarks> public virtual PTransformActivity AnimateViewToPanToBounds(RectangleF panToBounds, long duration) { SizeF delta = PUtil.DeltaRequiredToContain(ViewBounds, panToBounds); if (delta.Width != 0 || delta.Height != 0) { if (duration == 0) { TranslateViewBy(-delta.Width, -delta.Height); } else { PMatrix m = ViewMatrix; m.TranslateBy(-delta.Width, -delta.Height); return(AnimateViewToMatrix(m, duration)); } } return(null); }
/// <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 RectangleF layerBounds = UnionOfLayerFullBounds; PMatrix matrix = camera.ViewMatrix; layerBounds = matrix.Transform(layerBounds); // Union the camera bounds RectangleF viewBounds = camera.Bounds; layerBounds = RectangleF.Union(layerBounds, viewBounds); // Now find the new view position in view coordinates PointF newPoint = new PointF(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 = matrix.Elements; elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y); elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y); matrix = new PMatrix(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> /// Sets the temp region to the transformed path, widening the path if /// requested to do so. /// </summary> private void SetTempRegion(GraphicsPath path, PMatrix matrix, bool widen) { TEMP_PATH.Reset(); if (path.PointCount > 0) { TEMP_PATH.AddPath(path, false); if (widen) { TEMP_PATH.Widen(pen, matrix.MatrixReference); } else { TEMP_PATH.Transform(matrix.MatrixReference); } } TEMP_REGION.MakeInfinite(); TEMP_REGION.Intersect(TEMP_PATH); }
protected void CreatePath(Random rnd) { PTransformActivity rotActivity; // Create a path P3Path path = P3Path.CreateEllipse(0, 0, 100, 100); path.Brush = Brushes.Red; path.AddLine(0, 0, 20, 20); path.AddLine(20, 20, 34, 67); path.AddArc(0, 30, 30, 30, 30, 30); path.Tolerance = .002f; canvas.Layer.AddChild(path); PMatrix rMatrix = new PMatrix(); PointF center = PUtil.CenterOfRectangle(path.Bounds); rMatrix.RotateBy(90, center.X, center.Y); rotActivity = path.AnimateToMatrix(rMatrix, 2000 + (long)(2000 * rnd.NextDouble())); rotActivity.LoopCount = 1000; rotActivity.Mode = ActivityMode.SourceToDestinationToSource; }
public void applay(PMatrix source) { m *= source.m; }
public void set(PMatrix source) { m = source.m; }
public PMatrix(PMatrix source) { this.m = source.m; }
public static void set(this Transform transform, PMatrix matrix) { transform.localScale = matrix.getScale(); transform.rotation = matrix.getRotation(); transform.position = matrix.getPosition(); }
public void preApplay(PMatrix left) { set(left.m * m); }
public void set3x3(PMatrix pm) { m.m00 = pm.m00; m.m01 = pm.m01; m.m02 = pm.m02; m.m10 = pm.m10; m.m11 = pm.m11; m.m12 = pm.m12; m.m20 = pm.m20; m.m21 = pm.m21; m.m22 = pm.m22; }