@Override public void render(MVP mvp) { final float contentSize = 0.9f; SimpleTexturedShader shader = injector.getInstance(SimpleTexturedShader.class); shader.activate(); // Draw the background texture shader.setMVPMatrix(mvp.collapse()); shader.setTexture(backgroundTexture); shader.draw(); // If the click action has an icon if (action.hasIconTexture()) { drawIcon(mvp, shader); } drawActionName(mvp, contentSize); // If the action cannot be performed if (!action.isExecutable()) { // Draw the unavailable overlay shader.setMVPMatrix(mvp.collapse()); shader.setTexture(unselectableTexture); shader.draw(); } }
private void drawIcon(final MVP mvp, final SimpleTexturedShader shader) { final Device device = injector.getInstance(Device.class); final float[] iconModel = mvp.peekCopy(MVP.Type.MODEL); // Move to the right edge of the entire menu item Matrix.translateM(iconModel, Constants.NO_OFFSET, 0.5f, 0.0f, 0.0f); // Scale the icon to be 1:1 square to the menu item height Matrix.scaleM( iconModel, Constants.NO_OFFSET, 1.0f / aspectRatio / device.getAspectRatio(), 1.0f, 1.0f); // Align the right edge of the icon to the right edge of the menu item Matrix.translateM(iconModel, Constants.NO_OFFSET, -0.5f, 0.0f, 0.0f); // Shrink the icon size down to fit in the margins final float contentSize = 0.5f; Matrix.scaleM(iconModel, Constants.NO_OFFSET, contentSize, contentSize, 1.0f); // Perform the icon draw shader.setMVPMatrix(mvp.collapseM(iconModel)); shader.setTexture(action.getIconTexture()); shader.draw(); }