private void drawFlippingHalf(Canvas canvas) { canvas.save(); mCamera.save(); final float degreesFlipped = getDegreesFlipped(); if (degreesFlipped > 90) { canvas.clipRect(isFlippingVertically() ? mTopRect : mLeftRect); if (mIsFlippingVertically) { mCamera.rotateX(degreesFlipped - 180); } else { mCamera.rotateY(180 - degreesFlipped); } } else { canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect); if (mIsFlippingVertically) { mCamera.rotateX(degreesFlipped); } else { mCamera.rotateY(-degreesFlipped); } } mCamera.getMatrix(mMatrix); positionMatrix(); canvas.concat(mMatrix); setDrawWithLayer(mCurrentPage.v, true); drawChild(canvas, mCurrentPage.v, 0); drawFlippingShadeShine(canvas); mCamera.restore(); canvas.restore(); }
@Override public void drawTo(Canvas drawCanvas, float left, float top, Paint paint, boolean onlyDirty) { final Rect src = new Rect(0, 0, mTileSize, mTileSize); final Rect dst = new Rect(0, 0, mTileSize, mTileSize); drawCanvas.save(); drawCanvas.translate(-left, -top); drawCanvas.clipRect(0, 0, mWidth, mHeight); for (int j = 0; j < mTilesY; j++) { for (int i = 0; i < mTilesX; i++) { dst.offsetTo(i * mTileSize, j * mTileSize); final int p = j * mTilesX + i; final Tile tile = mTiles[p]; if (!onlyDirty || tile.dirty) { drawCanvas.drawBitmap(tile.getBitmap(), src, dst, paint); tile.dirty = false; if (mDebug) { mDrawCount++; dbgPaint.setColor(DEBUG_COLORS[tile.top % DEBUG_COLORS.length]); // drawCanvas.drawRect(dst, (mDrawCount % 2 == 0) ? dbgPaint1 : dbgPaint2); drawCanvas.drawRect(dst, dbgPaint); // drawCanvas.drawRect(dst, dbgStroke); drawCanvas.drawText( String.format("%d,%d v%d", tile.x, tile.y, tile.top), dst.left + 4, dst.bottom - 4, dbgTextPaint); } } } } drawCanvas.restore(); }
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final boolean ret; final Integer row = (Integer) child.getTag(R.id.tag_row); final Integer column = (Integer) child.getTag(R.id.tag_column); // row == null => Shadow view if (row == null || (row == -1 && column == -1)) { ret = super.drawChild(canvas, child, drawingTime); } else { canvas.save(); if (row == -1) { canvas.clipRect(widths[0], 0, canvas.getWidth(), canvas.getHeight()); } else if (column == -1) { canvas.clipRect(0, heights[0], canvas.getWidth(), canvas.getHeight()); } else { canvas.clipRect(widths[0], heights[0], canvas.getWidth(), canvas.getHeight()); } ret = super.drawChild(canvas, child, drawingTime); canvas.restore(); } return ret; }
/** * draw bottom/right half * * @param canvas */ private void drawNextHalf(Canvas canvas) { canvas.save(); canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect); final float degreesFlipped = getDegreesFlipped(); final Page p = degreesFlipped > 90 ? mCurrentPage : mNextPage; // if the view does not exist, skip drawing it if (p.valid) { setDrawWithLayer(p.v, true); drawChild(canvas, p.v, 0); } drawNextShadow(canvas); canvas.restore(); }
@Override public void render(MainGamePanel game, Canvas canvas, GameState gameState) { setzIndex(5); if (gameState.isStateDefeat()) { canvas.clipRect(0, 0, canvas.getWidth(), canvas.getHeight(), Region.Op.REPLACE); int border = canvas.getWidth() / 15; paint.setTextSize(TextSizeCalculator.getDefaultTextSize(canvas)); paint.setTextAlign(Paint.Align.CENTER); paint.setAntiAlias(true); paint.setStrokeWidth(2f); paint.setColorFilter(MyColors.getFilterGui()); paint.setColor(MyColors.getGuiElementColor()); canvas.drawLine(border, border, canvas.getWidth() - border, border, paint); canvas.drawLine(border, border, border, canvas.getHeight() - border, paint); canvas.drawLine( border, canvas.getHeight() - border, canvas.getWidth() - border, canvas.getHeight() - border, paint); canvas.drawLine( canvas.getWidth() - border, border, canvas.getWidth() - border, canvas.getHeight() - border, paint); int headingHeight = TextSizeCalculator.getHeightFromTextSize(paint.getTextSize()); int highScoreTextSize = (int) (TextSizeCalculator.getDefaultTextSize(canvas) * 0.7); ExtStorage ext = (ExtStorage) game.getElements().getComponent(Elements.EXTERNAL_STORAGE_PROVIDER); String heading = ""; String secondaryScoreName = ""; String secondaryScoreShortName = ""; String secondaryScoreValue = ""; int secondaryScoreIntValue = 0; List<String> highScoreList = null; // Normal if (gameState.getPreviousState() == GameState.STATE_GAME) { heading = "LOL NOOB"; secondaryScoreName = "level"; secondaryScoreShortName = ". level"; // Level value secondaryScoreIntValue = LevelList.getLevelId() + 1; secondaryScoreValue = Integer.toString(secondaryScoreIntValue); if (ext != null) { highScoreList = ext.getHighScore(ExtStorage.HIGH_SCORE_NORMAL_FILE); } // Arcade } else if (gameState.getPreviousState() == GameState.STATE_ARCADE) { heading = "NICE TRY!"; secondaryScoreName = "seconds"; secondaryScoreShortName = " sec"; // Seconds value secondaryScoreIntValue = (int) ((gameState.getArcadeTimeEnd() - gameState.getArcadeTimeStart()) / 1000.0f); secondaryScoreValue = Integer.toString(secondaryScoreIntValue); if (ext != null) { highScoreList = ext.getHighScore(ExtStorage.HIGH_SCORE_ARCADE_FILE); } } // Heading paint.setTextAlign(Paint.Align.LEFT); canvas.drawText(heading, border * 1.5f, border * 2.5f + headingHeight * 0.5f, paint); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(paint.getTextSize() * 0.9f); canvas.drawText(secondaryScoreValue, canvas.getWidth() - border * 2.5f, border * 2.7f, paint); paint.setTextSize(paint.getTextSize() * 0.4f); canvas.drawText(secondaryScoreName, canvas.getWidth() - border * 2.5f, border * 3.5f, paint); canvas.drawLine( canvas.getWidth() - border * 4f, border, canvas.getWidth() - border * 4f, border * 4f, paint); // Restore defaults paint.setTextSize(TextSizeCalculator.getDefaultTextSize(canvas)); paint.setTextAlign(Paint.Align.CENTER); if (highScoreList != null) { int lineHeight = TextSizeCalculator.getHeightFromTextSize(highScoreTextSize) * 2; int left = border; int right = canvas.getWidth() - border; int baseTop = border * 4; int counter = 0; paint.setColor(MyColors.getGuiElementColor()); paint.setTextSize(highScoreTextSize); canvas.drawLine( left, baseTop + (counter * lineHeight), right, baseTop + (counter * lineHeight), paint); counter++; canvas.drawText( "HIGH SCORE", canvas.getWidth() / 2, baseTop + (counter * lineHeight) - lineHeight / 4, paint); canvas.drawLine( left, baseTop + (counter * lineHeight), right, baseTop + (counter * lineHeight), paint); counter++; for (String score : highScoreList) { if (score != null && !score.equals("") && score.split("\\|").length == 2) { canvas.drawLine( left, baseTop + (counter * lineHeight), right, baseTop + (counter * lineHeight), paint); String highScoreValue = score.split("\\|")[0]; String secondaryHighScoreValue = score.split("\\|")[1]; // Arcade if (gameState.getPreviousState() == GameState.STATE_ARCADE) { Score scoreComponent = (Score) game.getElements().getComponent(Elements.SCORE); if (Integer.parseInt(highScoreValue) == scoreComponent.getScore() && Integer.parseInt(secondaryHighScoreValue) == secondaryScoreIntValue) { paint.setColor(MyColors.getGuiNewHighScoreColor()); } } // Score values paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText( highScoreValue, canvas.getWidth() / 2 - border / 2, baseTop + (counter * lineHeight) - lineHeight / 4, paint); canvas.drawText( secondaryHighScoreValue + secondaryScoreShortName, canvas.getWidth() - border * 1.5f, baseTop + (counter * lineHeight) - lineHeight / 4, paint); paint.setColor(MyColors.getGuiElementColor()); // Line canvas.drawLine( canvas.getWidth() / 2, baseTop + (counter * lineHeight), canvas.getWidth() / 2, baseTop + ((counter - 1) * lineHeight), paint); counter++; } } } paint.setTextAlign(Paint.Align.CENTER); buttonLeft = 2 * border; buttonRight = canvas.getWidth() - 2 * border; buttonRetryTop = canvas.getHeight() - 7 * border; buttonRetryBottom = canvas.getHeight() - 5 * border; buttonMainMenuTop = canvas.getHeight() - 4 * border; buttonMainMenuBottom = canvas.getHeight() - 2 * border; // Draw buttons canvas.drawRect(buttonLeft, buttonRetryTop, buttonRight, buttonRetryBottom, paint); paint.setStyle(Paint.Style.STROKE); canvas.drawRect(buttonLeft, buttonMainMenuTop, buttonRight, buttonMainMenuBottom, paint); // Draw button texts paint.setStyle(Paint.Style.FILL); paint.setColor(MyColors.getGuiElementTextColor()); int textHeight = TextSizeCalculator.getHeightFromTextSize(highScoreTextSize); canvas.drawText( "RETRY", canvas.getWidth() / 2, getTextY(buttonRetryTop, buttonRetryBottom, textHeight), paint); paint.setColor(MyColors.getGuiElementColor()); canvas.drawText( "QUIT TO MENU", canvas.getWidth() / 2, getTextY(buttonMainMenuTop, buttonMainMenuBottom, textHeight), paint); } }