@Override public void draw(Object ctx, float x, float y, float width, float height) { CGBitmapContext bctx = (CGBitmapContext)ctx; // pesky fiddling to cope with the fact that UIImages are flipped; TODO: make sure drawing a // canvas image on a canvas image does the right thing y += height; bctx.saveGState(); bctx.translateCTM(x, y); bctx.scaleCTM(1, -1); bctx.drawImage(new CGRect(0, 0, width, height), cgImage()); bctx.restoreGState(); }
@Override public void draw(CGBitmapContext bctx, float x, float y, float width, float height) { CGImage cgImage = cgImage(); // pesky fiddling to cope with the fact that UIImages are flipped; TODO: make sure drawing a // canvas image on a canvas image does the right thing y += height; bctx.saveGState(); bctx.translateCTM(x, y); bctx.scaleCTM(1, -1); bctx.drawImage(new CGRect(0, 0, width, height), cgImage); bctx.restoreGState(); }
@Override protected void upload (Graphics gfx, Texture tex) { int width = pixelWidth, height = pixelHeight; if (width == 0 || height == 0) { ((RoboGraphics)gfx).plat.log().info("Ignoring texture update for empty image (" + width + "x" + height + ")."); return; } CGBitmapContext bctx = RoboGraphics.createCGBitmap(width, height); CGRect rect = new CGRect(0, 0, width, height); bctx.clearRect(rect); bctx.drawImage(rect, image); upload(gfx, tex.id, width, height, bctx.getData()); bctx.dispose(); }
void updateTexture(int tex, CGImage image) { int width = (int)image.getWidth(), height = (int)image.getHeight(); if (width <= 0 || height <= 0) { platform.log().warn( "Ignoring texture update for empty image (" + width + "x" + height + ")."); return; } CGBitmapContext bctx = RoboGraphics.createCGBitmap(width, height); CGRect rect = new CGRect(0, 0, width, height); bctx.clearRect(rect); bctx.drawImage(rect, image); updateTexture(tex, width, height, bctx.getData()); bctx.dispose(); }
@Override public void draw(CGBitmapContext bctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor sx *= scale.factor; sy *= scale.factor; sw *= scale.factor; sh *= scale.factor; CGImage cgImage = cgImage(); float iw = cgImage.getWidth(), ih = cgImage.getHeight(); float scaleX = dw/sw, scaleY = dh/sh; // pesky fiddling to cope with the fact that UIImages are flipped bctx.saveGState(); bctx.translateCTM(dx, dy+dh); bctx.scaleCTM(1, -1); bctx.clipToRect(new CGRect(0, 0, dw, dh)); bctx.translateCTM(-sx*scaleX, -(ih-(sy+sh))*scaleY); bctx.drawImage(new CGRect(0, 0, iw*scaleX, ih*scaleY), cgImage); bctx.restoreGState(); }
@Override public void draw(Object ctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor sx *= scale.factor; sy *= scale.factor; sw *= scale.factor; sh *= scale.factor; CGImage image = cgImage(); CGBitmapContext bctx = (CGBitmapContext)ctx; float iw = image.getWidth(), ih = image.getHeight(); float scaleX = dw/sw, scaleY = dh/sh; // pesky fiddling to cope with the fact that UIImages are flipped bctx.saveGState(); bctx.translateCTM(dx, dy+dh); bctx.scaleCTM(1, -1); bctx.clipToRect(new CGRect(0, 0, dw, dh)); bctx.translateCTM(-sx*scaleX, -(ih-(sy+sh))*scaleY); bctx.drawImage(new CGRect(0, 0, iw*scaleX, ih*scaleY), image); bctx.restoreGState(); }