List of usage examples for android.graphics Rect exactCenterX
public final float exactCenterX()
From source file:com.breakout.main.GameState.java
/** * Renders debug features.//from www . j av a2s . c o m * <p> * This function is allowed to violate the "don't allocate objects" rule. */ void drawDebugStuff() { // Draw a red outline rectangle around the ball. This shows the area that was // examined for collisions during the "coarse" pass. OutlineAlignedRect.prepareToDraw(); mDebugCollisionRect.draw(); OutlineAlignedRect.finishedDrawing(); // Draw the entire message texture so we can see what it looks like. if (true) { int textureWidth = mTextRes.getTextureWidth(); int textureHeight = mTextRes.getTextureHeight(); float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / textureWidth; // Draw an orange rect around the texture. OutlineAlignedRect outline = new OutlineAlignedRect(); outline.setPosition(ARENA_WIDTH / 2, ARENA_HEIGHT / 2); outline.setScale(textureWidth * scale + 2, textureHeight * scale + 2); outline.setColor(1.0f, 0.65f, 0.0f); OutlineAlignedRect.prepareToDraw(); outline.draw(); OutlineAlignedRect.finishedDrawing(); // Draw the full texture. Note you can set the background to opaque white in // TextResources to see what the drop shadow looks like. Rect boundsRect = new Rect(0, 0, textureWidth, textureHeight); TexturedAlignedRect msgBox = mGameStatusMessages; msgBox.setTextureCoords(boundsRect); msgBox.setScale(textureWidth * scale, textureHeight * scale); TexturedAlignedRect.prepareToDraw(); msgBox.draw(); TexturedAlignedRect.finishedDrawing(); // Draw a rectangle around each individual text item. We draw a different one each // time to get a flicker effect, so it doesn't fully obscure the text. if (true) { outline.setColor(1.0f, 1.0f, 1.0f); int stringNum = mDebugFramedString; mDebugFramedString = (mDebugFramedString + 1) % TextResources.getNumStrings(); boundsRect = mTextRes.getTextureRect(stringNum); // The bounds rect is in bitmap coordinates, with (0,0) in the top left. Translate // it to an offset from the center of the bitmap, and find the center of the rect. float boundsCenterX = boundsRect.exactCenterX() - (textureWidth / 2); float boundsCenterY = boundsRect.exactCenterY() - (textureHeight / 2); // Now scale it to arena coordinates, using the same scale factor we used to // draw the texture with all the messages, and translate it to the center of // the arena. We need to invert Y to match GL conventions. boundsCenterX = ARENA_WIDTH / 2 + (boundsCenterX * scale); boundsCenterY = ARENA_HEIGHT / 2 - (boundsCenterY * scale); // Set the values and draw the rect. outline.setPosition(boundsCenterX, boundsCenterY); outline.setScale(boundsRect.width() * scale, boundsRect.height() * scale); OutlineAlignedRect.prepareToDraw(); outline.draw(); OutlineAlignedRect.finishedDrawing(); } } }