//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();
                }
            }
        }
Exemplo n.º 2
0
 public override void draw(android.graphics.Canvas canvas)
 {
     android.graphics.Bitmap bitmap = mBitmap;
     if (bitmap != null)
     {
         android.graphics.drawable.BitmapDrawable.BitmapState state = mBitmapState;
         if (state.mRebuildShader)
         {
             android.graphics.Shader.TileMode?tmx = state.mTileModeX;
             android.graphics.Shader.TileMode?tmy = state.mTileModeY;
             if (tmx == null && tmy == null)
             {
                 state.mPaint.setShader(null);
             }
             else
             {
                 state.mPaint.setShader(new android.graphics.BitmapShader(bitmap, tmx == null ? android.graphics.Shader.TileMode
                                                                          .CLAMP : tmx, tmy == null ? android.graphics.Shader.TileMode.CLAMP : tmy));
             }
             state.mRebuildShader = false;
             copyBounds(mDstRect);
         }
         android.graphics.Shader shader = state.mPaint.getShader();
         if (shader == null)
         {
             if (mApplyGravity)
             {
                 int layoutDirection = getResolvedLayoutDirectionSelf();
                 android.view.Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight, getBounds
                                                (), mDstRect, layoutDirection);
                 mApplyGravity = false;
             }
             canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
         }
         else
         {
             if (mApplyGravity)
             {
                 copyBounds(mDstRect);
                 mApplyGravity = false;
             }
             canvas.drawRect(mDstRect, state.mPaint);
         }
     }
 }
Exemplo n.º 3
0
		/// <summary>
		/// Returns an immutable bitmap from subset of the source bitmap,
		/// transformed by the optional matrix.
		/// </summary>
		/// <remarks>
		/// Returns an immutable bitmap from subset of the source bitmap,
		/// transformed by the optional matrix.  It is
		/// initialized with the same density as the original bitmap.
		/// </remarks>
		/// <param name="source">The bitmap we are subsetting</param>
		/// <param name="x">The x coordinate of the first pixel in source</param>
		/// <param name="y">The y coordinate of the first pixel in source</param>
		/// <param name="width">The number of pixels in each row</param>
		/// <param name="height">The number of rows</param>
		/// <param name="m">Optional matrix to be applied to the pixels</param>
		/// <param name="filter">
		/// true if the source should be filtered.
		/// Only applies if the matrix contains more than just
		/// translation.
		/// </param>
		/// <returns>A bitmap that represents the specified subset of source</returns>
		/// <exception cref="System.ArgumentException">
		/// if the x, y, width, height values are
		/// outside of the dimensions of the source bitmap.
		/// </exception>
		public static android.graphics.Bitmap createBitmap(android.graphics.Bitmap source
			, int x, int y, int width, int height, android.graphics.Matrix m, bool filter)
		{
			checkXYSign(x, y);
			checkWidthHeight(width, height);
			if (x + width > source.getWidth())
			{
				throw new System.ArgumentException("x + width must be <= bitmap.width()");
			}
			if (y + height > source.getHeight())
			{
				throw new System.ArgumentException("y + height must be <= bitmap.height()");
			}
			// check if we can just return our argument unchanged
			if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() && height
				 == source.getHeight() && (m == null || m.isIdentity()))
			{
				return source;
			}
			int neww = width;
			int newh = height;
			android.graphics.Canvas canvas = new android.graphics.Canvas();
			android.graphics.Bitmap bitmap;
			android.graphics.Paint paint;
			android.graphics.Rect srcR = new android.graphics.Rect(x, y, x + width, y + height
				);
			android.graphics.RectF dstR = new android.graphics.RectF(0, 0, width, height);
			android.graphics.Bitmap.Config newConfig = android.graphics.Bitmap.Config.ARGB_8888;
			android.graphics.Bitmap.Config config = source.getConfig();
			// GIF files generate null configs, assume ARGB_8888
			if (config != null)
			{
				switch (config)
				{
					case android.graphics.Bitmap.Config.RGB_565:
					{
						newConfig = android.graphics.Bitmap.Config.RGB_565;
						break;
					}

					case android.graphics.Bitmap.Config.ALPHA_8:
					{
						newConfig = android.graphics.Bitmap.Config.ALPHA_8;
						break;
					}

					case android.graphics.Bitmap.Config.ARGB_4444:
					case android.graphics.Bitmap.Config.ARGB_8888:
					default:
					{
						//noinspection deprecation
						newConfig = android.graphics.Bitmap.Config.ARGB_8888;
						break;
					}
				}
			}
			if (m == null || m.isIdentity())
			{
				bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha());
				paint = null;
			}
			else
			{
				// not needed
				bool transformed = !m.rectStaysRect();
				android.graphics.RectF deviceR = new android.graphics.RectF();
				m.mapRect(deviceR, dstR);
				neww = Sharpen.Util.Round(deviceR.width());
				newh = Sharpen.Util.Round(deviceR.height());
				bitmap = createBitmap(neww, newh, transformed ? android.graphics.Bitmap.Config.ARGB_8888
					 : newConfig, transformed || source.hasAlpha());
				canvas.translate(-deviceR.left, -deviceR.top);
				canvas.concat(m);
				paint = new android.graphics.Paint();
				paint.setFilterBitmap(filter);
				if (transformed)
				{
					paint.setAntiAlias(true);
				}
			}
			// The new bitmap was created from a known bitmap source so assume that
			// they use the same density
			bitmap.mDensity = source.mDensity;
			canvas.setBitmap(bitmap);
			canvas.drawBitmap(source, srcR, dstR, paint);
			canvas.setBitmap(null);
			return bitmap;
		}
//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();
				}
			}
		}