Exemplo n.º 1
0
        private boolean drawImage(Image img, Image mask, AffineTransform xform, Color bgColor, ImageObserver obs)
        {
            if (xform == null)
            {
                return(true);
            }

            xform.translate(0, img.getHeight(obs));
            xform.scale(img.getWidth(obs), img.getHeight(obs));

            AffineTransform inverse = this.normalizeMatrix();
            AffineTransform flipper = AffineTransform.getScaleInstance(1, -1);

            inverse.concatenate(xform);
            inverse.concatenate(flipper);

            double[] mx = new double[6];
            inverse.getMatrix(mx);

            try {
                com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, bgColor);
                if (mask != null)
                {
                    com.lowagie.text.Image msk = com.lowagie.text.Image.getInstance(mask, null, true);
                    msk.makeMask();
                    msk.setInvertMask(true);
                    image.setImageMask(msk);
                }
                cb.addImage(image, (float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]);
            } catch (Exception ex) {
                throw new IllegalArgumentException();
            }

            return(true);
        }
Exemplo n.º 2
0
 /**
  * @see Graphics2D#drawString(String, float, float)
  */
 public void drawString(String s, float x, float y)
 {
     if (onlyShapes)
     {
         TextLayout tl = new TextLayout(s, this.font, new FontRenderContext(new AffineTransform(), false, true));
         tl.draw(this, x, y);
     }
     else
     {
         AffineTransform at  = getTransform();
         AffineTransform at2 = getTransform();
         at2.translate(x, y);
         at2.concatenate(font.getTransform());
         setTransform(at2);
         AffineTransform inverse = this.normalizeMatrix();
         AffineTransform flipper = AffineTransform.getScaleInstance(1, -1);
         inverse.concatenate(flipper);
         double[] mx = new double[6];
         inverse.getMatrix(mx);
         cb.beginText();
         cb.setFontAndSize(baseFont, fontSize);
         cb.setTextMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]);
         cb.showText(s);
         cb.endText();
         setTransform(at);
     }
 }
Exemplo n.º 3
0
        private AffineTransform normalizeMatrix()
        {
            double[]        mx     = new double[6];
            AffineTransform result = AffineTransform.getTranslateInstance(0, 0);

            result.getMatrix(mx);
            mx[3]  = -1;
            mx[5]  = height;
            result = new AffineTransform(mx);
            result.concatenate(transform);
            return(result);
        }
Exemplo n.º 4
0
        //@Override
        public override void draw(Image image, Point world_position, AffineTransform entityTransform, float alpha)
        {
            AffineTransform cameraTransform = new AffineTransform();
            Graphics2D      g2Temp          = (Graphics2D)this.gBoard.create();

            g2Temp.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

            cameraTransform.translate(
                this.getRelativeX(world_position.x) + this.translationComposite.getDX(),
                this.getRelativeY(world_position.y) + this.translationComposite.getDX());

            cameraTransform.concatenate(entityTransform);

            g2Temp.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));

            g2Temp.drawImage(image,
                             cameraTransform,
                             this.observer);

            g2Temp.dispose();
        }
Exemplo n.º 5
0
        public void drawOnCamera(GraphicComposite.Static sprite, AffineTransform entityTransform)
        {
            AffineTransform cameraTransform = new AffineTransform();

            this.gBoard.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

            cameraTransform.translate(
                this.getRelativeX(sprite.ownerEntity().getX()),
                this.getRelativeY(sprite.ownerEntity().getY()));

            cameraTransform.scale(zoomFactor, zoomFactor);

            cameraTransform.concatenate(entityTransform);
            Composite compositeBuffer = this.gBoard.getComposite();

            this.gBoard.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)sprite.getSprite().getAlpha()));

            BufferedImage[][] tiledImage = sprite.getSprite().getBufferedImage();
            int tileSize = sprite.getSprite().getTileDimension();

            cameraTransform.translate(-tileSize, 0);

            for (int i = 0; i < tiledImage.length; ++i)
            {
                cameraTransform.translate(tileSize, 0);

                for (int j = 0; j < tiledImage[i].length; ++j)
                {
                    this.gBoard.drawImage(tiledImage[i][j],
                                          cameraTransform,
                                          this.observer);
                    cameraTransform.translate(0, tileSize);
                }

                cameraTransform.translate(0, -3 * tileSize);
            }

            this.gBoard.setComposite(compositeBuffer);
        }