@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(); } }
public boolean handleClick() { if (action.isExecutable()) { action.execute(); return true; } else { return false; } }
@Inject protected ActionMenuItem( @Assisted("aspectRatio") final float aspectRatio, @Named("ActionMenuItemBackground") final int backgroundTexture, @Assisted("clickAction") final Executable action, final GlyphStringFactory glyphStringFactory, final Injector injector, @Named("ActionMenuItemUnselectable") final int unselectableTexture) { this.aspectRatio = aspectRatio; this.backgroundTexture = backgroundTexture; this.action = action; this.injector = injector; this.unselectableTexture = unselectableTexture; final float height = 0.5f; this.text = glyphStringFactory.create(action.getName(), height); this.text.setRelativeWidth(0.9f); }
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(); }