Search in sources :

Example 6 with Variation

use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.

the class TinaController method refreshXFormUI.

private void refreshXFormUI(XForm pXForm) {
    boolean oldRefreshing = refreshing;
    boolean oldGridRefreshing = gridRefreshing;
    boolean oldCmbRefreshing = cmbRefreshing;
    boolean oldNoRefresh = noRefresh;
    gridRefreshing = cmbRefreshing = refreshing = noRefresh = true;
    try {
        EditPlane curEditPlane = getCurrFlame().getEditPlane();
        refreshEditPlaneToggleButtons(curEditPlane);
        if (pXForm != null) {
            switch(curEditPlane) {
                case XY:
                    data.affineC00Lbl.setText("X1");
                    data.affineC01Lbl.setText("X2");
                    data.affineC10Lbl.setText("Y1");
                    data.affineC11Lbl.setText("Y2");
                    break;
                case YZ:
                    data.affineC00Lbl.setText("Y1");
                    data.affineC01Lbl.setText("Y2");
                    data.affineC10Lbl.setText("Z1");
                    data.affineC11Lbl.setText("Z2");
                    break;
                default:
                    data.affineC00Lbl.setText("X1");
                    data.affineC01Lbl.setText("X2");
                    data.affineC10Lbl.setText("Z1");
                    data.affineC11Lbl.setText("Z2");
                    break;
            }
            if (data.affineEditPostTransformButton.isSelected()) {
                data.affineC00REd.setText(Tools.doubleToString(pXForm.getPostCoeff00()));
                data.affineC01REd.setText(Tools.doubleToString(pXForm.getPostCoeff01()));
                data.affineC10REd.setText(Tools.doubleToString(pXForm.getPostCoeff10()));
                data.affineC11REd.setText(Tools.doubleToString(pXForm.getPostCoeff11()));
                data.affineC20REd.setText(Tools.doubleToString(pXForm.getPostCoeff20()));
                data.affineC21REd.setText(Tools.doubleToString(pXForm.getPostCoeff21()));
            } else {
                data.affineC00REd.setText(Tools.doubleToString(pXForm.getCoeff00()));
                data.affineC01REd.setText(Tools.doubleToString(pXForm.getCoeff01()));
                data.affineC10REd.setText(Tools.doubleToString(pXForm.getCoeff10()));
                data.affineC11REd.setText(Tools.doubleToString(pXForm.getCoeff11()));
                data.affineC20REd.setText(Tools.doubleToString(pXForm.getCoeff20()));
                data.affineC21REd.setText(Tools.doubleToString(pXForm.getCoeff21()));
            }
            if (data.affineMirrorPrePostTranslationsButton != null) {
                data.affineMirrorPrePostTranslationsButton.setSelected(pXForm.getMirrorTranslations());
            }
            data.xFormColorREd.setText(Tools.doubleToString(pXForm.getColor()));
            data.xFormColorSlider.setValue(Tools.FTOI(pXForm.getColor() * SLIDER_SCALE_COLOR));
            data.xFormSymmetryREd.setText(Tools.doubleToString(pXForm.getColorSymmetry()));
            data.xFormSymmetrySlider.setValue(Tools.FTOI(pXForm.getColorSymmetry() * SLIDER_SCALE_COLOR));
            data.xFormMaterialREd.setText(Tools.doubleToString(pXForm.getMaterial()));
            data.xFormMaterialSlider.setValue(Tools.FTOI(pXForm.getMaterial() * SLIDER_SCALE_COLOR));
            data.xFormMaterialSpeedREd.setText(Tools.doubleToString(pXForm.getMaterialSpeed()));
            data.xFormMaterialSpeedSlider.setValue(Tools.FTOI(pXForm.getMaterialSpeed() * SLIDER_SCALE_COLOR));
            data.xFormModGammaREd.setText(Tools.doubleToString(pXForm.getModGamma()));
            data.xFormModGammaSlider.setValue(Tools.FTOI(pXForm.getModGamma() * SLIDER_SCALE_COLOR));
            data.xFormModGammaSpeedREd.setText(Tools.doubleToString(pXForm.getModGammaSpeed()));
            data.xFormModGammaSpeedSlider.setValue(Tools.FTOI(pXForm.getModGammaSpeed() * SLIDER_SCALE_COLOR));
            data.xFormModContrastREd.setText(Tools.doubleToString(pXForm.getModContrast()));
            data.xFormModContrastSlider.setValue(Tools.FTOI(pXForm.getModContrast() * SLIDER_SCALE_COLOR));
            data.xFormModContrastSpeedREd.setText(Tools.doubleToString(pXForm.getModContrastSpeed()));
            data.xFormModContrastSpeedSlider.setValue(Tools.FTOI(pXForm.getModContrastSpeed() * SLIDER_SCALE_COLOR));
            data.xFormModSaturationREd.setText(Tools.doubleToString(pXForm.getModSaturation()));
            data.xFormModSaturationSlider.setValue(Tools.FTOI(pXForm.getModSaturation() * SLIDER_SCALE_COLOR));
            data.xFormModSaturationSpeedREd.setText(Tools.doubleToString(pXForm.getModSaturationSpeed()));
            data.xFormModSaturationSpeedSlider.setValue(Tools.FTOI(pXForm.getModSaturationSpeed() * SLIDER_SCALE_COLOR));
            data.xFormModHueREd.setText(Tools.doubleToString(pXForm.getModHue()));
            data.xFormModHueSlider.setValue(Tools.FTOI(pXForm.getModHue() * SLIDER_SCALE_COLOR));
            data.xFormModHueSpeedREd.setText(Tools.doubleToString(pXForm.getModHueSpeed()));
            data.xFormModHueSpeedSlider.setValue(Tools.FTOI(pXForm.getModHueSpeed() * SLIDER_SCALE_COLOR));
            data.xFormOpacityREd.setText(Tools.doubleToString(pXForm.getOpacity()));
            data.xFormOpacitySlider.setValue(Tools.FTOI(pXForm.getOpacity() * SLIDER_SCALE_COLOR));
            data.xFormDrawModeCmb.setSelectedItem(pXForm.getDrawMode());
            data.transformationWeightREd.setText(Tools.doubleToString(pXForm.getWeight()));
        } else {
            data.affineC00REd.setText(null);
            data.affineC01REd.setText(null);
            data.affineC10REd.setText(null);
            data.affineC11REd.setText(null);
            data.affineC20REd.setText(null);
            data.affineC21REd.setText(null);
            data.xFormColorREd.setText(null);
            data.xFormColorSlider.setValue(0);
            data.xFormSymmetryREd.setText(null);
            data.xFormSymmetrySlider.setValue(0);
            data.xFormMaterialREd.setText(null);
            data.xFormMaterialSlider.setValue(0);
            data.xFormMaterialSpeedREd.setText(null);
            data.xFormMaterialSpeedSlider.setValue(0);
            data.xFormModGammaREd.setText(null);
            data.xFormModGammaSlider.setValue(0);
            data.xFormModGammaSpeedREd.setText(null);
            data.xFormModGammaSpeedSlider.setValue(0);
            data.xFormModContrastREd.setText(null);
            data.xFormModContrastSlider.setValue(0);
            data.xFormModContrastSpeedREd.setText(null);
            data.xFormModContrastSpeedSlider.setValue(0);
            data.xFormModSaturationREd.setText(null);
            data.xFormModSaturationSlider.setValue(0);
            data.xFormModSaturationSpeedREd.setText(null);
            data.xFormModSaturationSpeedSlider.setValue(0);
            data.xFormModHueREd.setText(null);
            data.xFormModHueSlider.setValue(0);
            data.xFormModHueSpeedREd.setText(null);
            data.xFormModHueSpeedSlider.setValue(0);
            data.xFormOpacityREd.setText(null);
            data.xFormOpacitySlider.setValue(0);
            data.transformationWeightREd.setText(null);
            data.xFormDrawModeCmb.setSelectedIndex(-1);
        }
        {
            int idx = 0;
            for (TinaNonlinearControlsRow row : data.TinaNonlinearControlsRows) {
                if (pXForm == null || idx >= pXForm.getVariationCount()) {
                    refreshParamControls(row, null, null, true);
                } else {
                    Variation var = pXForm.getVariation(idx);
                    refreshParamControls(row, pXForm, var, true);
                }
                idx++;
            }
        }
        refreshRelWeightsTable();
    } finally {
        gridRefreshing = oldGridRefreshing;
        refreshing = oldRefreshing;
        cmbRefreshing = oldCmbRefreshing;
        noRefresh = oldNoRefresh;
    }
}
Also used : EditPlane(org.jwildfire.create.tina.base.EditPlane) Variation(org.jwildfire.create.tina.variation.Variation)

Example 7 with Variation

use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.

the class TinaController method nonlinearVarCmbChanged.

public void nonlinearVarCmbChanged(int pIdx) {
    if (cmbRefreshing) {
        return;
    }
    boolean oldCmbRefreshing = cmbRefreshing;
    cmbRefreshing = true;
    try {
        XForm xForm = getCurrXForm();
        if (xForm != null) {
            saveUndoPoint();
            String fName = (String) data.TinaNonlinearControlsRows[pIdx].getNonlinearVarCmb().getSelectedItem();
            Variation var;
            if (pIdx < xForm.getVariationCount()) {
                var = xForm.getVariation(pIdx);
                if (fName == null || fName.length() == 0) {
                    xForm.removeVariation(var);
                } else {
                    if (var.getFunc() == null || !var.getFunc().getName().equals(fName)) {
                        VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(fName);
                        var.setFunc(varFunc);
                        var.setPriority(varFunc.getPriority());
                    }
                }
            } else {
                var = new Variation();
                String varStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().getText();
                if (varStr == null || varStr.length() == 0) {
                    varStr = "0";
                }
                VariationFunc varFunc = VariationFuncList.getVariationFuncInstance(fName);
                var.setFunc(varFunc);
                var.setPriority(varFunc.getPriority());
                var.setAmount(Tools.stringToDouble(varStr));
                xForm.addVariation(var);
            }
            refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, true);
            refreshXFormUI(xForm);
            refreshFlameImage(true, false, 1, true, false);
            data.transformationsTable.invalidate();
            data.transformationsTable.repaint();
        }
    } finally {
        cmbRefreshing = oldCmbRefreshing;
    }
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) Variation(org.jwildfire.create.tina.variation.Variation) VariationFunc(org.jwildfire.create.tina.variation.VariationFunc)

Example 8 with Variation

use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.

the class TinaController method nonlinearParamsREdChanged.

public void nonlinearParamsREdChanged(int pIdx, double pDelta) {
    if (cmbRefreshing) {
        return;
    }
    cmbRefreshing = true;
    try {
        String selected = (String) data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().getSelectedItem();
        XForm xForm = getCurrXForm();
        if (xForm != null && selected != null && selected.length() > 0) {
            saveUndoPoint();
            if (pIdx < xForm.getVariationCount()) {
                final Variation var = xForm.getVariation(pIdx);
                int idx;
                if ((idx = var.getFunc().getParameterIndex(selected)) >= 0) {
                    String valStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().getText();
                    if (valStr == null || valStr.length() == 0) {
                        valStr = "0";
                    }
                    // round the delta to whole numbers if the parameter is of type integer
                    if (Math.abs(pDelta) > MathLib.EPSILON) {
                        Object val = var.getFunc().getParameterValues()[idx];
                        if (val != null && val instanceof Integer) {
                            if (Math.abs(pDelta) < 1.0) {
                                pDelta = pDelta < 0 ? -1 : 1;
                            } else {
                                pDelta = Math.round(pDelta);
                            }
                        }
                    }
                    double val = Tools.stringToDouble(valStr) + pDelta;
                    var.getFunc().setParameter(selected, val);
                    if (var.getFunc().dynamicParameterExpansion(selected)) {
                        // if setting the parameter can change the total number of parameters,
                        // then refresh parameter UI (and reselect parameter that was changed)
                        this.refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, false);
                        data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().setSelectedItem(selected);
                    }
                    data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().setText(Tools.doubleToString(val));
                    data.TinaNonlinearControlsRows[pIdx].refreshParamWithoutRefresh(selected, val);
                } else if ((idx = var.getFunc().getRessourceIndex(selected)) >= 0) {
                    final String rName = var.getFunc().getRessourceNames()[idx];
                    RessourceType resType = var.getFunc().getRessourceType(rName);
                    switch(resType) {
                        case FONT_NAME:
                            {
                                String oldFontname = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFontname = new String(val);
                                    }
                                }
                                Font oldFont = new Font(oldFontname != null ? oldFontname : "Arial", Font.PLAIN, 24);
                                Font selectedFont = JFontChooser.showDialog(centerPanel, "Choose font", oldFont);
                                if (selectedFont != null) {
                                    String valStr = selectedFont.getFontName();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case IMAGE_FILENAME:
                            {
                                String oldFilename = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFilename = new String(val);
                                    }
                                }
                                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                                if (oldFilename != null && oldFilename.length() > 0) {
                                    try {
                                        chooser.setCurrentDirectory(new File(oldFilename).getAbsoluteFile().getParentFile());
                                        chooser.setSelectedFile(new File(oldFilename));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                } else {
                                    if (prefs.getInputImagePath() != null) {
                                        try {
                                            chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    File file = chooser.getSelectedFile();
                                    String valStr = file.getAbsolutePath();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case FLAME_FILENAME:
                            {
                                String oldFilename = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFilename = new String(val);
                                    }
                                }
                                JFileChooser chooser = new FlameFileChooser(Prefs.getPrefs());
                                if (oldFilename != null && oldFilename.length() > 0) {
                                    try {
                                        chooser.setCurrentDirectory(new File(oldFilename).getAbsoluteFile().getParentFile());
                                        chooser.setSelectedFile(new File(oldFilename));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                } else {
                                    if (prefs.getInputImagePath() != null) {
                                        try {
                                            chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    File file = chooser.getSelectedFile();
                                    String valStr = file.getAbsolutePath();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case IMAGE_FILE:
                            {
                                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                                if (prefs.getInputImagePath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        byte[] imgData = Tools.readFile(file.getAbsolutePath());
                                        var.getFunc().setRessource(rName, imgData);
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        case SVG_FILE:
                            {
                                JFileChooser chooser = new SvgFileChooser(prefs);
                                if (prefs.getTinaSVGPath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getTinaSVGPath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        String svg = Tools.readUTF8Textfile(file.getAbsolutePath());
                                        byte[] valByteArray = svg.getBytes();
                                        var.getFunc().setRessource(rName, valByteArray);
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        case OBJ_MESH:
                            {
                                JFileChooser chooser = new MeshFileChooser(prefs);
                                if (prefs.getTinaMeshPath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getTinaMeshPath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        var.getFunc().setRessource(rName, file.getAbsolutePath().getBytes());
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        default:
                            {
                                final RessourceDialog dlg = new RessourceDialog(SwingUtilities.getWindowAncestor(centerPanel), prefs, errorHandler);
                                dlg.setRessourceName(rName);
                                byte[] val = var.getFunc().getRessourceValues()[idx];
                                RessourceType type = var.getFunc().getRessourceType(rName);
                                RessourceDialog.ContentType ct = type == RessourceType.JAVA_CODE ? RessourceDialog.ContentType.JAVA : RessourceDialog.ContentType.TEXT;
                                if (val != null) {
                                    dlg.setRessourceValue(ct, new String(val));
                                }
                                dlg.addValidation(new RessourceValidation() {

                                    @Override
                                    public void validate() {
                                        String valStr = dlg.getRessourceValue();
                                        byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                        byte[] oldValue = var.getFunc().getRessource(rName);
                                        try {
                                            var.getFunc().setRessource(rName, valByteArray);
                                            var.getFunc().validate();
                                        } catch (Throwable ex) {
                                            var.getFunc().setRessource(rName, oldValue);
                                            throw new RuntimeException(ex);
                                        }
                                    }
                                });
                                dlg.setModal(true);
                                dlg.setVisible(true);
                                if (dlg.isConfirmed()) {
                                    try {
                                        String valStr = dlg.getRessourceValue();
                                        byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                        var.getFunc().setRessource(rName, valByteArray);
                                        if (var.getFunc().ressourceCanModifyParams(rName)) {
                                            // forcing refresh of params UI in case setting resource changes available params or param values
                                            this.refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, true);
                                        }
                                    } catch (Throwable ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                    }
                }
                refreshFlameImage(true, false, 1, true, false);
            }
        }
        resizeNonlinearParamsPanel();
    } finally {
        cmbRefreshing = false;
    }
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) Font(java.awt.Font) JFileChooser(javax.swing.JFileChooser) Variation(org.jwildfire.create.tina.variation.Variation) File(java.io.File) RessourceType(org.jwildfire.create.tina.variation.RessourceType)

Example 9 with Variation

use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.

the class TinaController method nonlinearParamsToggleParamsPnlClicked.

public void nonlinearParamsToggleParamsPnlClicked(int pIdx) {
    XForm xForm = getCurrXForm();
    Variation var;
    if (xForm != null && pIdx < xForm.getVariationCount()) {
        var = xForm.getVariation(pIdx);
    } else {
        var = null;
    }
    data.TinaNonlinearControlsRows[pIdx].rebuildParamsPnl(xForm, var);
    resizeNonlinearParamsPanel();
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) Variation(org.jwildfire.create.tina.variation.Variation)

Example 10 with Variation

use of org.jwildfire.create.tina.variation.Variation in project JWildfire by thargor6.

the class TinaController method nonlinearVarREdChanged.

public void nonlinearVarREdChanged(int pIdx, double pDelta) {
    if (cmbRefreshing) {
        return;
    }
    cmbRefreshing = true;
    try {
        XForm xForm = getCurrXForm();
        if (xForm != null) {
            if (pIdx < xForm.getVariationCount()) {
                Variation var = xForm.getVariation(pIdx);
                String varStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().getText();
                if (varStr == null || varStr.length() == 0) {
                    varStr = "0";
                }
                var.setAmount(Tools.stringToDouble(varStr) + pDelta);
                data.TinaNonlinearControlsRows[pIdx].getNonlinearVarREd().setText(Tools.doubleToString(var.getAmount()));
                refreshFlameImage(true, false, 1, true, false);
            }
        }
    } finally {
        cmbRefreshing = false;
    }
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) Variation(org.jwildfire.create.tina.variation.Variation)

Aggregations

Variation (org.jwildfire.create.tina.variation.Variation)26 XForm (org.jwildfire.create.tina.base.XForm)15 VariationFunc (org.jwildfire.create.tina.variation.VariationFunc)9 ArrayList (java.util.ArrayList)5 MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)5 List (java.util.List)4 Field (java.lang.reflect.Field)3 Flame (org.jwildfire.create.tina.base.Flame)3 Layer (org.jwildfire.create.tina.base.Layer)3 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)2 Font (java.awt.Font)1 File (java.io.File)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JFileChooser (javax.swing.JFileChooser)1 XMLAttribute (org.jwildfire.base.Tools.XMLAttribute)1 XMLAttributes (org.jwildfire.base.Tools.XMLAttributes)1 AnimAware (org.jwildfire.create.tina.animate.AnimAware)1 MotionCurveAttribute (org.jwildfire.create.tina.animate.AnimationService.MotionCurveAttribute)1