/// <summary>Draw the picture, stretched to fit into the dst rectangle.</summary> /// <remarks>Draw the picture, stretched to fit into the dst rectangle.</remarks> public virtual void drawPicture(android.graphics.Picture picture, android.graphics.Rect dst) { save(); translate(dst.left, dst.top); if (picture.getWidth() > 0 && picture.getHeight() > 0) { scale((float)dst.width() / picture.getWidth(), (float)dst.height() / picture.getHeight ()); } drawPicture(picture); restore(); }
/// <summary> /// Apply additional gravity behavior based on the overall "display" that an /// object exists in. /// </summary> /// <remarks> /// Apply additional gravity behavior based on the overall "display" that an /// object exists in. This can be used after /// <see cref="apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect) /// ">apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect)</see> /// to place the object /// within a visible display. By default this moves or clips the object /// to be visible in the display; the gravity flags /// <see cref="DISPLAY_CLIP_HORIZONTAL">DISPLAY_CLIP_HORIZONTAL</see> /// and /// <see cref="DISPLAY_CLIP_VERTICAL">DISPLAY_CLIP_VERTICAL</see> /// can be used to change this behavior. /// </remarks> /// <param name="gravity"> /// Gravity constants to modify the placement within the /// display. /// </param> /// <param name="display"> /// The rectangle of the display in which the object is /// being placed. /// </param> /// <param name="inoutObj"> /// Supplies the current object position; returns with it /// modified if needed to fit in the display. /// </param> public static void applyDisplay(int gravity, android.graphics.Rect display, android.graphics.Rect inoutObj) { if ((gravity & DISPLAY_CLIP_VERTICAL) != 0) { if (inoutObj.top < display.top) { inoutObj.top = display.top; } if (inoutObj.bottom > display.bottom) { inoutObj.bottom = display.bottom; } } else { int off = 0; if (inoutObj.top < display.top) { off = display.top - inoutObj.top; } else { if (inoutObj.bottom > display.bottom) { off = display.bottom - inoutObj.bottom; } } if (off != 0) { if (inoutObj.height() > (display.bottom - display.top)) { inoutObj.top = display.top; inoutObj.bottom = display.bottom; } else { inoutObj.top += off; inoutObj.bottom += off; } } } if ((gravity & DISPLAY_CLIP_HORIZONTAL) != 0) { if (inoutObj.left < display.left) { inoutObj.left = display.left; } if (inoutObj.right > display.right) { inoutObj.right = display.right; } } else { int off = 0; if (inoutObj.left < display.left) { off = display.left - inoutObj.left; } else { if (inoutObj.right > display.right) { off = display.right - inoutObj.right; } } if (off != 0) { if (inoutObj.width() > (display.right - display.left)) { inoutObj.left = display.left; inoutObj.right = display.right; } else { inoutObj.left += off; inoutObj.right += off; } } } }
protected internal override void onBoundsChange(android.graphics.Rect bounds) { android.graphics.Rect r = mTmpRect; bool min = mScaleState.mUseIntrinsicSizeAsMin; int level = getLevel(); int w = bounds.width(); if (mScaleState.mScaleWidth > 0) { int iw = min ? mScaleState.mDrawable.getIntrinsicWidth() : 0; w -= (int)((w - iw) * (10000 - level) * mScaleState.mScaleWidth / 10000); } int h = bounds.height(); if (mScaleState.mScaleHeight > 0) { int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0; h -= (int)((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000); } int layoutDirection = getResolvedLayoutDirectionSelf(); android.view.Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection ); if (w > 0 && h > 0) { mScaleState.mDrawable.setBounds(r.left, r.top, r.right, r.bottom); } }
/// <summary> /// Compute the amount to scroll in the X direction in order to get /// a rectangle completely on the screen (or, if taller than the screen, /// at least the first screen size chunk of it). /// </summary> /// <remarks> /// Compute the amount to scroll in the X direction in order to get /// a rectangle completely on the screen (or, if taller than the screen, /// at least the first screen size chunk of it). /// </remarks> /// <param name="rect">The rect.</param> /// <returns>The scroll delta.</returns> protected internal virtual int computeScrollDeltaToGetChildRectOnScreen(android.graphics.Rect rect) { if (getChildCount() == 0) { return 0; } int width = getWidth(); int screenLeft = getScrollX(); int screenRight = screenLeft + width; int fadingEdge = getHorizontalFadingEdgeLength(); // leave room for left fading edge as long as rect isn't at very left if (rect.left > 0) { screenLeft += fadingEdge; } // leave room for right fading edge as long as rect isn't at very right if (rect.right < getChildAt(0).getWidth()) { screenRight -= fadingEdge; } int scrollXDelta = 0; if (rect.right > screenRight && rect.left > screenLeft) { // need to move right to get it in view: move right just enough so // that the entire rectangle is in view (or at least the first // screen size chunk). if (rect.width() > width) { // just enough to get screen size chunk on scrollXDelta += (rect.left - screenLeft); } else { // get entire rect at right of screen scrollXDelta += (rect.right - screenRight); } // make sure we aren't scrolling beyond the end of our content int right = getChildAt(0).getRight(); int distanceToRight = right - screenRight; scrollXDelta = System.Math.Min(scrollXDelta, distanceToRight); } else { if (rect.left < screenLeft && rect.right < screenRight) { // need to move right to get it in view: move right just enough so that // entire rectangle is in view (or at least the first screen // size chunk of it). if (rect.width() > width) { // screen size chunk scrollXDelta -= (screenRight - rect.right); } else { // entire rect at left scrollXDelta -= (screenLeft - rect.left); } // make sure we aren't scrolling any further than the left our content scrollXDelta = System.Math.Max(scrollXDelta, -getScrollX()); } } return scrollXDelta; }
private void adjustRectangle(android.graphics.Rect rect) { int width = rect.width(); int height = rect.height(); if (mFormat == android.graphics.ImageFormat.NV21) { // Make sure left, top, width and height are all even. width &= ~1; height &= ~1; rect.left &= ~1; rect.top &= ~1; rect.right = rect.left + width; rect.bottom = rect.top + height; } if (mFormat == android.graphics.ImageFormat.YUY2) { // Make sure left and width are both even. width &= ~1; rect.left &= ~1; rect.right = rect.left + width; } }