Esempio n. 1
0
        protected internal override void onDraw(android.graphics.Canvas canvas)
        {
            base.onDraw(canvas);
            bool changed = mChanged;

            if (changed)
            {
                mChanged = false;
            }
            int availableWidth  = mRight - mLeft;
            int availableHeight = mBottom - mTop;
            int x = availableWidth / 2;
            int y = availableHeight / 2;

            android.graphics.drawable.Drawable dial = mDial;
            int  w      = dial.getIntrinsicWidth();
            int  h      = dial.getIntrinsicHeight();
            bool scaled = false;

            if (availableWidth < w || availableHeight < h)
            {
                scaled = true;
                float scale = System.Math.Min((float)availableWidth / (float)w, (float)availableHeight
                                              / (float)h);
                canvas.save();
                canvas.scale(scale, scale, x, y);
            }
            if (changed)
            {
                dial.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
            }
            dial.draw(canvas);
            canvas.save();
            canvas.rotate(mHour / 12.0f * 360.0f, x, y);
            android.graphics.drawable.Drawable hourHand = mHourHand;
            if (changed)
            {
                w = hourHand.getIntrinsicWidth();
                h = hourHand.getIntrinsicHeight();
                hourHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
            }
            hourHand.draw(canvas);
            canvas.restore();
            canvas.save();
            canvas.rotate(mMinutes / 60.0f * 360.0f, x, y);
            android.graphics.drawable.Drawable minuteHand = mMinuteHand;
            if (changed)
            {
                w = minuteHand.getIntrinsicWidth();
                h = minuteHand.getIntrinsicHeight();
                minuteHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2));
            }
            minuteHand.draw(canvas);
            canvas.restore();
            if (scaled)
            {
                canvas.restore();
            }
        }
Esempio n. 2
0
 public override void draw(android.graphics.Canvas canvas, android.graphics.Paint
                           paint)
 {
     canvas.save();
     canvas.scale(mScaleX, mScaleY);
     canvas.drawPath(mPath, paint);
     canvas.restore();
 }
Esempio n. 3
0
 public override void draw(android.graphics.Canvas canvas)
 {
     if (mPicture != null)
     {
         android.graphics.Rect bounds = getBounds();
         canvas.save();
         canvas.clipRect(bounds);
         canvas.translate(bounds.left, bounds.top);
         canvas.drawPicture(mPicture);
         canvas.restore();
     }
 }
Esempio n. 4
0
 public virtual void draw(android.graphics.Canvas canvas)
 {
     if (mDrawable == null)
     {
         return;
     }
     canvas.save(android.graphics.Canvas.MATRIX_SAVE_FLAG);
     canvas.translate(mTranslationX, mTranslationY);
     canvas.scale(mScaleX, mScaleY);
     canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
     mDrawable.setAlpha((int)Sharpen.Util.Round(mAlpha * 255f));
     mDrawable.draw(canvas);
     canvas.restore();
 }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public void onDraw(final android.graphics.Canvas canv)
        public override void onDraw(Canvas canv)
        {
            if (null == mOfficeLayout || null == mRenderUtil)
            {
                Log.w(TAG, "Tried to render empty office");
                return;
            }

            foreach (OfficeThing thing in mOfficeLayout.ThingsBottomUp)
            {
                Bitmap thingBitmap = mRenderUtil.getBitmap(thing);

                //TODO: reimplement glow rendering
                //            // If it's the selected thing, make it GLOW!
                //            if (thing.getKey().equals(mSelectedThingKey)) {
                //                thingBitmap = mRenderUtil.getGlowingBitmap(thing);
                //            }

                // Draw furniture
                canv.drawBitmap(thingBitmap, modelToScreen(thing.Left), modelToScreen(thing.Top), DEFAULT_PAINT);

                // Draw desk label
                if (thing.Type.Equals("desk") && thing.Name != null)
                {
                    // TODO: these offset numbers were empirically determined. Calculate them instead
                    float centerX = modelToScreen(thing.Left) + 102;
                    float centerY = modelToScreen(thing.Top) + 70;

                    canv.save();
                    // TODO: OMG this is so hacky. Fix it. These numbers were empirically determined
                    if (thing.Rotation == 180)
                    {
                        canv.rotate(-thing.Rotation, centerX, centerY - 10);
                    }
                    else if (thing.Rotation == 90)
                    {
                        canv.rotate(-thing.Rotation, centerX, centerY + 45);
                    }
                    else if (thing.Rotation == 270)
                    {
                        canv.rotate(-thing.Rotation, centerX - 40, centerY);
                    }

                    canv.drawText(thing.Name, centerX, centerY, DESK_LABEL_PAINT);
                    canv.restore();
                }
            }
        }
Esempio n. 6
0
        public override void draw(android.graphics.Canvas canvas)
        {
            int saveCount = canvas.save();

            android.graphics.drawable.AnimatedRotateDrawable.AnimatedRotateState st = mState;
            android.graphics.drawable.Drawable drawable = st.mDrawable;
            android.graphics.Rect bounds = drawable.getBounds();
            int   w  = bounds.right - bounds.left;
            int   h  = bounds.bottom - bounds.top;
            float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
            float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;

            canvas.rotate(mCurrentDegrees, px + bounds.left, py + bounds.top);
            drawable.draw(canvas);
            canvas.restoreToCount(saveCount);
        }
Esempio n. 7
0
        public override void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
        {
            applyCustomTypeFace(paint, type);
            paint.getTextBounds(icon, 0, 1, TEXT_BOUNDS);
            canvas.save();
            if (rotate)
            {
                float rotation = (DateTimeHelperClass.CurrentUnixTimeMillis() - rotationStartTime) / (float)ROTATION_DURATION * 360f;
                float centerX  = x + TEXT_BOUNDS.width() / 2f;
                float centerY  = y - TEXT_BOUNDS.height() / 2f + TEXT_BOUNDS.height() * BASELINE_RATIO;
                canvas.rotate(rotation, centerX, centerY);
            }

            canvas.drawText(icon, x - TEXT_BOUNDS.left, y - TEXT_BOUNDS.bottom + TEXT_BOUNDS.height() * BASELINE_RATIO, paint);
            canvas.restore();
        }
Esempio n. 8
0
 protected internal override void onDraw(android.graphics.Canvas canvas)
 {
     lock (this)
     {
         base.onDraw(canvas);
         if (mThumb != null)
         {
             canvas.save();
             // Translate the padding. For the x, we need to allow the thumb to
             // draw in its extra space
             canvas.translate(mPaddingLeft - mThumbOffset, mPaddingTop);
             mThumb.draw(canvas);
             canvas.restore();
         }
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Just like
 /// <see cref="lockCanvas()">lockCanvas()</see>
 /// but allows specification of a dirty
 /// rectangle. Every pixel within that rectangle must be written; however
 /// pixels outside the dirty rectangle will be preserved by the next call
 /// to lockCanvas().
 /// </summary>
 /// <param name="dirty">Area of the surface that will be modified.</param>
 /// <returns>A Canvas used to draw into the surface.</returns>
 /// <seealso cref="lockCanvas()"></seealso>
 /// <seealso cref="unlockCanvasAndPost(android.graphics.Canvas)"></seealso>
 public virtual android.graphics.Canvas lockCanvas(android.graphics.Rect dirty)
 {
     if (!isAvailable())
     {
         return(null);
     }
     if (mCanvas == null)
     {
         mCanvas = new android.graphics.Canvas();
     }
     lock (mNativeWindowLock)
     {
         nLockCanvas(mNativeWindow, mCanvas, dirty);
     }
     mSaveCount = mCanvas.save();
     return(mCanvas);
 }
Esempio n. 10
0
        /// <summary>Draw this object to the canvas using the properties defined in this class.
        ///     </summary>
        /// <remarks>Draw this object to the canvas using the properties defined in this class.
        ///     </remarks>
        /// <param name="canvas">canvas to draw into</param>
        public virtual void draw(android.graphics.Canvas canvas)
        {
            float threshold = 1.0f / 256.0f;

            // contribution less than 1 LSB of RGB byte
            if (mAlpha <= threshold)
            {
                // don't bother if it won't show up
                return;
            }
            canvas.save(android.graphics.Canvas.MATRIX_SAVE_FLAG);
            canvas.translate(mX, mY);
            canvas.scale(mScaleX, mScaleY);
            canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
            mDrawable.setAlpha((int)Sharpen.Util.Round(mAlpha * 255f));
            mDrawable.draw(canvas);
            canvas.restore();
        }
Esempio n. 11
0
        public override void draw(android.graphics.Canvas canvas)
        {
            android.graphics.Rect  r     = getBounds();
            android.graphics.Paint paint = mShapeState.mPaint;
            int prevAlpha = paint.getAlpha();

            paint.setAlpha(modulateAlpha(prevAlpha, mShapeState.mAlpha));
            if (mShapeState.mShape != null)
            {
                // need the save both for the translate, and for the (unknown) Shape
                int count = canvas.save();
                canvas.translate(r.left, r.top);
                onDraw(mShapeState.mShape, canvas, paint);
                canvas.restoreToCount(count);
            }
            else
            {
                canvas.drawRect(r, paint);
            }
            // restore
            paint.setAlpha(prevAlpha);
        }
Esempio n. 12
0
        protected internal override void onDraw(android.graphics.Canvas canvas)
        {
            base.onDraw(canvas);
            // Draw the switch
            int switchLeft   = mSwitchLeft;
            int switchTop    = mSwitchTop;
            int switchRight  = mSwitchRight;
            int switchBottom = mSwitchBottom;

            mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
            mTrackDrawable.draw(canvas);
            canvas.save();
            mTrackDrawable.getPadding(mTempRect);
            int switchInnerLeft   = switchLeft + mTempRect.left;
            int switchInnerTop    = switchTop + mTempRect.top;
            int switchInnerRight  = switchRight - mTempRect.right;
            int switchInnerBottom = switchBottom - mTempRect.bottom;

            canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);
            mThumbDrawable.getPadding(mTempRect);
            int thumbPos   = (int)(mThumbPosition + 0.5f);
            int thumbLeft  = switchInnerLeft - mTempRect.left + thumbPos;
            int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;

            mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
            mThumbDrawable.draw(canvas);
            // mTextColors should not be null, but just in case
            if (mTextColors != null)
            {
                mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(), mTextColors.
                                                                 getDefaultColor()));
            }
            mTextPaint.drawableState = getDrawableState();
            android.text.Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
            canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop
                                                                                        + switchInnerBottom) / 2 - switchText.getHeight() / 2);
            switchText.draw(canvas);
            canvas.restore();
        }
Esempio n. 13
0
 protected internal override void onDraw(android.graphics.Canvas canvas)
 {
     base.onDraw(canvas);
     if (mDrawable == null)
     {
         return;
     }
     // couldn't resolve the URI
     if (mDrawableWidth == 0 || mDrawableHeight == 0)
     {
         return;
     }
     // nothing to draw (empty bounds)
     if (mDrawMatrix == null && mPaddingTop == 0 && mPaddingLeft == 0)
     {
         mDrawable.draw(canvas);
     }
     else
     {
         int saveCount = canvas.getSaveCount();
         canvas.save();
         if (mCropToPadding)
         {
             int scrollX = mScrollX;
             int scrollY = mScrollY;
             canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop, scrollX + mRight -
                             mLeft - mPaddingRight, scrollY + mBottom - mTop - mPaddingBottom);
         }
         canvas.translate(mPaddingLeft, mPaddingTop);
         if (mDrawMatrix != null)
         {
             canvas.concat(mDrawMatrix);
         }
         mDrawable.draw(canvas);
         canvas.restoreToCount(saveCount);
     }
 }
Esempio n. 14
0
        public override void draw(android.graphics.Canvas canvas)
        {
            if (mClipState.mDrawable.getLevel() == 0)
            {
                return;
            }
            android.graphics.Rect r      = mTmpRect;
            android.graphics.Rect bounds = getBounds();
            int level = getLevel();
            int w     = bounds.width();
            int iw    = 0;

            //mClipState.mDrawable.getIntrinsicWidth();
            if ((mClipState.mOrientation & HORIZONTAL) != 0)
            {
                w -= (w - iw) * (10000 - level) / 10000;
            }
            int h  = bounds.height();
            int ih = 0;

            //mClipState.mDrawable.getIntrinsicHeight();
            if ((mClipState.mOrientation & VERTICAL) != 0)
            {
                h -= (h - ih) * (10000 - level) / 10000;
            }
            int layoutDirection = getResolvedLayoutDirectionSelf();

            android.view.Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection);
            if (w > 0 && h > 0)
            {
                canvas.save();
                canvas.clipRect(r);
                mClipState.mDrawable.draw(canvas);
                canvas.restore();
            }
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public void onDraw(final android.graphics.Canvas canv)
		public override void onDraw(Canvas canv)
		{
			if (null == mOfficeLayout || null == mRenderUtil)
			{
				Log.w(TAG, "Tried to render empty office");
				return;
			}

			foreach (OfficeThing thing in mOfficeLayout.ThingsBottomUp)
			{
				Bitmap thingBitmap = mRenderUtil.getBitmap(thing);

				//TODO: reimplement glow rendering
	//            // If it's the selected thing, make it GLOW!
	//            if (thing.getKey().equals(mSelectedThingKey)) {
	//                thingBitmap = mRenderUtil.getGlowingBitmap(thing);
	//            }

				// Draw furniture
				canv.drawBitmap(thingBitmap, modelToScreen(thing.Left), modelToScreen(thing.Top), DEFAULT_PAINT);

				// Draw desk label
				if (thing.Type.Equals("desk") && thing.Name != null)
				{
					// TODO: these offset numbers were empirically determined. Calculate them instead
					float centerX = modelToScreen(thing.Left) + 102;
					float centerY = modelToScreen(thing.Top) + 70;

					canv.save();
					// TODO: OMG this is so hacky. Fix it. These numbers were empirically determined
					if (thing.Rotation == 180)
					{
						canv.rotate(-thing.Rotation, centerX, centerY - 10);
					}
					else if (thing.Rotation == 90)
					{
						canv.rotate(-thing.Rotation, centerX, centerY + 45);
					}
					else if (thing.Rotation == 270)
					{
						canv.rotate(-thing.Rotation, centerX - 40, centerY);
					}

					canv.drawText(thing.Name, centerX, centerY, DESK_LABEL_PAINT);
					canv.restore();
				}
			}
		}