private CanvasImage createMenuImage(MenuEntry me) { CanvasImage result = graphics().createImage(200, 50); Canvas resultCanvas = result.canvas(); // resultCanvas.setFillGradient(graphics().createLinearGradient(0f, 0f, 200f, 50f, // {Color.rgb(0, 0, 0), Color.rgb(100, 0, 0)}, {0, 0, 200, 50})) resultCanvas.setFillColor(Color.argb(50, 255, 255, 255)); resultCanvas.fillRect(0, 0, result.width(), result.height()); resultCanvas.setFillColor(Color.rgb(0, 0, 0)); resultCanvas.drawText(me.getLabel(), result.width() / 2, result.height() / 2); return result; }
/** * Returns a (created on demand, then cached) image used when filling solid color quads or * triangles. */ Image fillImage() { if (fillImage == null) { CanvasImage image = platform.graphics().createImage(1, 1); image.canvas().setFillColor(0xFFFFFFFF).fillRect(0, 0, image.width(), image.height()); fillImage = image; } return fillImage; }
@Override public void init() { GroupLayer rootLayer = graphics().rootLayer(); final CanvasImage img = graphics().createImage(100, 50); img.canvas() .setFillGradient( graphics() .createLinearGradient( 0, 0, 100, 100, new int[] {0xFF0000FF, 0xFF00FF00}, new float[] {0, 1})); img.canvas().fillRoundRect(0, 0, 100, 50, 10); // create an immediate layer that draws the boundaries of our clipped group layers rootLayer.add( graphics() .createImmediateLayer( new ImmediateLayer.Renderer() { public void render(Surface surf) { // draw the border of our various clipped groups surf.setFillColor(0xFF000000); outline(surf, g1); outline(surf, g2); outline(surf, g3); outline(surf, g4); } protected void outline(Surface surf, Layer.HasSize ly) { drawRect( surf, ly.transform().tx() - ly.originX(), ly.transform().ty() - ly.originY(), ly.width(), ly.height()); } protected void drawRect(Surface surf, float x, float y, float w, float h) { float left = x - 1, top = y - 1, right = x + w + 2, bot = y + h + 2; surf.drawLine(left, top, right, top, 1); surf.drawLine(right, top, right, bot, 1); surf.drawLine(left, top, left, bot, 1); surf.drawLine(left, bot, right, bot, 1); } })); // create a group layer with a static clip, and a rotating image inside g1 = graphics().createGroupLayer(100, 100); // test the origin not being at zero/zero g1.setOrigin(50, 0); i1 = graphics().createImageLayer(img); i1.setOrigin(i1.width() / 2, i1.height() / 2); g1.addAt(i1, 50, 50); rootLayer.addAt(g1, 75, 25); g2 = graphics().createGroupLayer(100, 100); g2.setOrigin(50, 50); g2.addAt(graphics().createImageLayer(img), (100 - img.width()) / 2, (100 - img.height()) / 2); rootLayer.addAt(g2, 200, 75); // nest a group layer inside with an animated origin inner = graphics().createGroupLayer(); inner.addAt( graphics().createImageLayer(img), (100 - img.width()) / 2, (100 - img.height()) / 2); g3 = graphics().createGroupLayer(100, 100); g3.add(inner); rootLayer.addAt(g3, 275, 25); // create a group layer with a static clip, and a rotating surface layer inside g4 = graphics().createGroupLayer(100, 100); s1 = graphics().createSurfaceLayer(100, 50); s1.surface().setFillColor(0xFF99CCFF).fillRect(0, 0, 100, 50); s1.setOrigin(s1.width() / 2, s1.height() / 2); g4.addAt(s1, 50, 50); rootLayer.addAt(g4, 400, 25); }