Search in sources :

Example 1 with TextTransformer

use of org.jwildfire.transform.TextTransformer in project JWildfire by thargor6.

the class FlameBrowserController method transferFlameToFolder.

private void transferFlameToFolder(boolean bMove) {
    FlameFlatNode node = getSelectedFlame();
    if (node != null) {
        try {
            JFileChooser chooser = new JFileChooser();
            chooser = new JFileChooser();
            chooser.setDialogTitle("Specify destination-directory");
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            File srcFile = new File(node.getFilename());
            File preselected = lastCopyToDrawer != null ? new File(lastCopyToDrawer, srcFile.getName()) : new File(srcFile.getName());
            chooser.setSelectedFile(preselected);
            if (chooser.showOpenDialog(rootPanel) == JFileChooser.APPROVE_OPTION) {
                lastCopyToDrawer = chooser.getSelectedFile().getParentFile();
                File dstFile = chooser.getSelectedFile();
                if (bMove) {
                    Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                    node.setRemoved(true);
                } else {
                    Files.copy(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                }
                ImagePanel pnl = pnlList.get(selectedPnl);
                SimpleImage img = pnl.getImage();
                TextTransformer txt = new TextTransformer();
                txt.setText1(bMove ? "(moved)" : "(copied)");
                txt.setAntialiasing(true);
                txt.setColor(bMove ? Color.RED : Color.GRAY);
                txt.setMode(Mode.NORMAL);
                txt.setFontStyle(FontStyle.BOLD);
                txt.setFontName("Arial");
                txt.setFontSize(24);
                txt.setHAlign(HAlignment.CENTRE);
                txt.setVAlign(VAlignment.CENTRE);
                txt.transformImage(img);
                pnl.invalidate();
                pnl.repaint();
                enableControls();
            }
        } catch (Exception ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) TextTransformer(org.jwildfire.transform.TextTransformer) File(java.io.File) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 2 with TextTransformer

use of org.jwildfire.transform.TextTransformer in project JWildfire by thargor6.

the class TextWFFunc method getPoints.

@SuppressWarnings("unchecked")
private List<Point> getPoints() {
    if (_points == null) {
        String key = makeRessourceKey();
        _points = (List<Point>) RessourceManager.getRessource(key);
        if (_points == null) {
            TextTransformer txt = new TextTransformer();
            txt.setText1(text);
            txt.setAntialiasing(false);
            txt.setColor(Color.WHITE);
            txt.setMode(Mode.NORMAL);
            txt.setFontStyle(FontStyle.PLAIN);
            txt.setFontName(font_name);
            txt.setFontSize(font_size);
            txt.setHAlign(HAlignment.CENTRE);
            txt.setVAlign(VAlignment.CENTRE);
            txt.setBaseLineOffset(baseline);
            Dimension dim = txt.calculateTextSize();
            int imgWidth = (int) (dim.getWidth() + 2 * font_size);
            int imgHeight = (int) (dim.getHeight() + 2 * font_size);
            SimpleImage imgMap = new SimpleImage(imgWidth, imgHeight);
            txt.transformImage(imgMap);
            _points = new ArrayList<Point>();
            double w2 = (double) imgMap.getImageWidth() / 2.0;
            double h2 = (double) imgMap.getImageHeight() / 2.0;
            for (int i = 0; i < imgMap.getImageHeight(); i++) {
                for (int j = 0; j < imgMap.getImageWidth(); j++) {
                    int argb = imgMap.getARGBValue(j, i);
                    if (argb != 0) {
                        double x = ((double) j - w2) / (double) imgMap.getImageWidth();
                        double y = ((double) i - h2) / (double) imgMap.getImageHeight();
                        _points.add(new Point(x, y));
                    }
                }
            }
            // System.out.println("IMG: " + imgWidth + "x" + imgHeight + ", POINTS: " + _points.size());
            RessourceManager.putRessource(key, _points);
        }
    }
    return _points;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) TextTransformer(org.jwildfire.transform.TextTransformer) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) Dimension(java.awt.Dimension) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 3 with TextTransformer

use of org.jwildfire.transform.TextTransformer in project JWildfire by thargor6.

the class FlamePreviewHelper method createLayerPreview.

private SimpleImage createLayerPreview(SimpleImage img, int renderScale, int width, int height) {
    FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
    Flame flame = flameHolder.getFlame();
    Layer onlyVisibleLayer = null;
    for (Layer layer : flameHolder.getFlame().getLayers()) {
        if (layer.isVisible()) {
            if (onlyVisibleLayer == null) {
                onlyVisibleLayer = layer;
            } else {
                onlyVisibleLayer = null;
                break;
            }
        }
    }
    boolean drawSubLayer = flame.getLayers().size() > 1 && layerHolder.getLayer() != null && layerHolder.getLayer() != onlyVisibleLayer && !cfg.isNoControls();
    if (drawSubLayer) {
        Flame singleLayerFlame = new Flame();
        singleLayerFlame.assign(flame);
        singleLayerFlame.getLayers().clear();
        singleLayerFlame.getLayers().add(layerHolder.getLayer().makeCopy());
        singleLayerFlame.getFirstLayer().setVisible(true);
        singleLayerFlame.getFirstLayer().setWeight(1.0);
        RenderInfo lInfo = new RenderInfo(width / 4 * renderScale, height / 4 * renderScale, RenderMode.PREVIEW);
        double lWScl = (double) lInfo.getImageWidth() / (double) singleLayerFlame.getWidth();
        double lHScl = (double) lInfo.getImageHeight() / (double) singleLayerFlame.getHeight();
        singleLayerFlame.setPixelsPerUnit((lWScl + lHScl) * 0.5 * singleLayerFlame.getPixelsPerUnit() * 0.5);
        singleLayerFlame.setWidth(lInfo.getImageWidth());
        singleLayerFlame.setHeight(lInfo.getImageHeight());
        singleLayerFlame.setSampleDensity(prefs.getTinaRenderRealtimeQuality() * 2.0 / 3.0);
        FlameRenderer lRenderer = new FlameRenderer(singleLayerFlame, prefs, false, false);
        RenderedFlame lRes = lRenderer.renderFlame(lInfo);
        SimpleImage layerImg = lRes.getImage();
        boolean drawLayerNumber = true;
        if (drawLayerNumber) {
            RectangleTransformer rT = new RectangleTransformer();
            int textWidth = 28;
            int textHeight = 22;
            int margin = 2;
            rT.setColor(new java.awt.Color(0, 0, 0));
            rT.setLeft(layerImg.getImageWidth() - textWidth - 2 * margin);
            rT.setTop(layerImg.getImageHeight() - textHeight - 2 * margin);
            rT.setThickness(textHeight / 2 + 1);
            rT.setWidth(textWidth);
            rT.setHeight(textHeight);
            rT.transformImage(layerImg);
            TextTransformer txt = new TextTransformer();
            txt.setText1("  " + (flame.getLayers().indexOf(layerHolder.getLayer()) + 1) + "  ");
            txt.setAntialiasing(true);
            txt.setColor(new java.awt.Color(200, 200, 200));
            txt.setMode(Mode.NORMAL);
            txt.setFontStyle(FontStyle.BOLD);
            txt.setFontName("Arial");
            txt.setFontSize(16);
            txt.setHAlign(HAlignment.NONE);
            txt.setPosX(layerImg.getImageWidth() - textWidth - margin);
            txt.setPosY(layerImg.getImageHeight() - textHeight - margin);
            txt.setVAlign(VAlignment.NONE);
            txt.transformImage(layerImg);
        }
        RectangleTransformer rT = new RectangleTransformer();
        rT.setColor(new java.awt.Color(200, 200, 200));
        rT.setLeft(0);
        rT.setTop(0);
        rT.setThickness(3);
        rT.setWidth(lInfo.getImageWidth());
        rT.setHeight(lInfo.getImageHeight());
        rT.transformImage(layerImg);
        return layerImg;
    }
    return null;
}
Also used : Color(java.awt.Color) TextTransformer(org.jwildfire.transform.TextTransformer) Layer(org.jwildfire.create.tina.base.Layer) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) XYZProjectedPoint(org.jwildfire.create.tina.base.XYZProjectedPoint) SimpleImage(org.jwildfire.image.SimpleImage) RectangleTransformer(org.jwildfire.transform.RectangleTransformer) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 4 with TextTransformer

use of org.jwildfire.transform.TextTransformer in project JWildfire by thargor6.

the class TinaController method countDown.

public void countDown(int pTime) {
    for (int i = pTime; i >= 0; i--) {
        Rectangle bounds = flamePreviewHelper.getPanelBounds();
        SimpleImage img = new SimpleImage((int) bounds.getWidth(), (int) bounds.getHeight());
        TextTransformer txt = new TextTransformer();
        txt.setText1(i > 0 ? String.valueOf(i) : "go!");
        txt.setAntialiasing(true);
        txt.setColor(Color.RED);
        txt.setMode(Mode.NORMAL);
        txt.setFontStyle(FontStyle.BOLD);
        txt.setFontName("Arial");
        txt.setFontSize(64);
        txt.setHAlign(HAlignment.CENTRE);
        txt.setVAlign(VAlignment.CENTRE);
        txt.transformImage(img);
        flamePreviewHelper.setImage(img);
        flamePreviewHelper.forceRepaint();
        try {
            Thread.sleep(i > 0 ? 500 : 50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) TextTransformer(org.jwildfire.transform.TextTransformer)

Example 5 with TextTransformer

use of org.jwildfire.transform.TextTransformer in project JWildfire by thargor6.

the class DancingFractalsController method refreshFlameImage.

public void refreshFlameImage(Flame flame, boolean pDrawTriangles, double pFPS, long pFrame, boolean pDrawFPS) {
    FlamePanel imgPanel = getFlamePanel();
    if (imgPanel == null)
        return;
    Rectangle bounds = imgPanel.getImageBounds();
    int width = bounds.width;
    int height = bounds.height;
    if (width >= 16 && height >= 16) {
        RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
        if (flame != null) {
            double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
            double oldSampleDensity = flame.getSampleDensity();
            imgPanel.setDrawTriangles(pDrawTriangles);
            try {
                double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
                double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
                flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
                flame.setWidth(info.getImageWidth());
                flame.setHeight(info.getImageHeight());
                Flame renderFlame = new FlamePreparer(prefs).createRenderFlame(flame);
                FlameRenderer renderer = new FlameRenderer(renderFlame, prefs, false, false);
                renderer.setProgressUpdater(null);
                RenderedFlame res = renderer.renderFlame(info);
                SimpleImage img = res.getImage();
                if (pDrawFPS) {
                    TextTransformer txt = new TextTransformer();
                    txt.setText1("fps: " + Tools.doubleToString(pFPS) + ", time: " + Tools.doubleToString(pFrame / 1000.0) + "s");
                    txt.setAntialiasing(false);
                    txt.setColor(Color.LIGHT_GRAY);
                    txt.setMode(Mode.NORMAL);
                    txt.setFontStyle(FontStyle.PLAIN);
                    txt.setFontName("Arial");
                    txt.setFontSize(10);
                    txt.setHAlign(HAlignment.LEFT);
                    txt.setVAlign(VAlignment.BOTTOM);
                    txt.transformImage(img);
                }
                imgPanel.setImage(img);
            } finally {
                flame.setSpatialFilterRadius(oldSpatialFilterRadius);
                flame.setSampleDensity(oldSampleDensity);
            }
        }
    } else {
        try {
            imgPanel.setImage(new SimpleImage(width, height));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    flameRootPanel.repaint();
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) TextTransformer(org.jwildfire.transform.TextTransformer) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

TextTransformer (org.jwildfire.transform.TextTransformer)7 SimpleImage (org.jwildfire.image.SimpleImage)6 Rectangle (java.awt.Rectangle)2 File (java.io.File)2 Flame (org.jwildfire.create.tina.base.Flame)2 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)2 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)2 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)2 ImagePanel (org.jwildfire.swing.ImagePanel)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 JFileChooser (javax.swing.JFileChooser)1 Layer (org.jwildfire.create.tina.base.Layer)1 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)1 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)1 DrawFocusPointFlameRenderer (org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer)1 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)1 FlamePanelConfig (org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig)1 RectangleTransformer (org.jwildfire.transform.RectangleTransformer)1