@Override public void paintComponent(Graphics g) { g.scale(zoomFactor, zoomFactor); // Change the size of the panel setSize(origWidth * zoomFactor, origHeight * zoomFactor); // Re-Layout the panel validate(); super.paintComponent(g); }
/** Creates a canvas large enough to accommodate this styled text, and renders it therein. The * canvas will include a one pixel border beyond the size of the styled text which is needed * to accommodate antialiasing. */ public Canvas toCanvas () { float pad = 1/_gfx.scale().factor; Canvas canvas = _gfx.createCanvas(width()+2*pad, height()+2*pad); render(canvas, pad, pad); return canvas; }
/** * Creates a canvas image large enough to accommodate this text block and renders the lines into * it. The image will include padding around the edge to ensure that antialiasing has a bit of * extra space to do its work. */ public Canvas toCanvas(Graphics gfx, Align align, int fillColor) { float pad = 1/gfx.scale().factor; Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad); canvas.setFillColor(fillColor); fill(canvas, align, pad, pad); return canvas; } }
/** * Creates a canvas image large enough to accommodate this text block and renders the lines into * it. The image will include padding around the edge to ensure that antialiasing has a bit of * extra space to do its work. */ public Canvas toCanvas(Graphics gfx, Align align, int fillColor) { float pad = 1/gfx.scale().factor; Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad); canvas.setFillColor(fillColor); fill(canvas, align, pad, pad); return canvas; } }
@Override public void setPosition (float x, float y) { Root root = root(); if (root != null) { Scale scale = root.iface.plat.graphics().scale(); if (hrange.active()) x = scale.roundToNearestPixel(x); if (vrange.active()) y = scale.roundToNearestPixel(y); } Scroller.this.content.layer.setTranslation(x, y); } };
/** * Does whatever this element needs to validate itself. This may involve recomputing * visualizations, or laying out children, or anything else. */ protected void validate () { if (!isSet(Flag.VALID)) { // prior to laying ourselves out, ensure that our visual boundaries fall on physical // pixels; this avoids rendering artifacts on devices where the scale factor between // virtual and physical pixels is non-integral Root root = root(); if (root != null) { Scale scale = root.iface.plat.graphics().scale(); float x = layer.tx(), y = layer.ty(); float rx = scale.roundToNearestPixel(x), ry = scale.roundToNearestPixel(y); float rr = scale.roundToNearestPixel(x + _size.width); float rb = scale.roundToNearestPixel(y + _size.height); layer.setTranslation(rx, ry); _size.setSize(rr-rx, rb-ry); } // now that our boundaries are adjusted, we can layout our children (if any) layout(); set(Flag.VALID, true); wasValidated(); } }
protected Texture makeTextImage() { TextFormat format = new TextFormat(new Font(font.value(), style.value(), 24)); float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : game.graphics.viewSize.width()*wrap.value()/100; TextBlock block = new TextBlock( game.graphics.layoutText(sample, format, new TextWrap(wrapWidth))); float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height()); float pad = 1/game.graphics.scale().factor; Canvas canvas = game.graphics.createCanvas(awidth+2*pad, aheight+2*pad); canvas.translate(pad, pad); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight); render(canvas, block, align.value(), lineBounds.value()); return canvas.toTexture(); }