Changed #2206 FB values in MATRIX (scale/rotate) as floats instead of int, -f suffixed parameters in text editor

This commit is contained in:
Jindra Petřík
2024-08-05 11:17:25 +02:00
parent 55a7112f10
commit ece2d537d5
10 changed files with 259 additions and 68 deletions
@@ -19,12 +19,14 @@ package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.amf.amf3.Amf3Value;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.gui.generictageditors.Amf3ValueEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.BinaryDataEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.BooleanEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.ChangeListener;
import com.jpexs.decompiler.flash.gui.generictageditors.ColorEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.EnumEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.FloatEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.FullSized;
import com.jpexs.decompiler.flash.gui.generictageditors.GenericTagEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.NumberEditor;
@@ -346,11 +348,12 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
editor = new EnumEditor(field.getName(), obj, field, index, type, swfType, values);
} else if (type.equals(double.class) || type.equals(Double.class)
|| type.equals(float.class) || type.equals(Float.class)) {
editor = new FloatEditor(field.getName(), obj, field, index, type);
} else if (type.equals(int.class) || type.equals(Integer.class)
|| type.equals(short.class) || type.equals(Short.class)
|| type.equals(long.class) || type.equals(Long.class)
|| type.equals(double.class) || type.equals(Double.class)
|| type.equals(float.class) || type.equals(Float.class)) {
|| type.equals(long.class) || type.equals(Long.class)) {
editor = new NumberEditor(field.getName(), obj, field, index, type, swfType);
} else if (type.equals(boolean.class) || type.equals(Boolean.class)) {
editor = new BooleanEditor(field.getName(), obj, field, index, type);
@@ -904,8 +907,8 @@ public class GenericTagTreePanel extends GenericTagPanel {
if (val instanceof byte[]) {
valStr += " = " + ((byte[]) val).length + " byte";
} else if (val instanceof ByteArrayRange) {
valStr += " = " + ((ByteArrayRange) val).getLength() + " byte";
} else {
valStr += " = " + ((ByteArrayRange) val).getLength() + " byte";
} else {
valStr += " = " + colorAdd + val.toString() + enumAdd;
}
}
@@ -0,0 +1,154 @@
/*
* Copyright (C) 2010-2023 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.generictageditors;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.ReflectionTools;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.lang.reflect.Field;
import java.util.Objects;
import javax.swing.JTextField;
/**
*
* @author JPEXS
*/
public class FloatEditor extends JTextField implements GenericTagEditor {
private final Object obj;
private final Field field;
private final int index;
private final Class<?> type;
private String fieldName;
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public Dimension getPreferredSize() {
Dimension ret = super.getPreferredSize();
ret.width = 300;
return ret;
}
@Override
public BaselineResizeBehavior getBaselineResizeBehavior() {
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
@Override
public int getBaseline(int width, int height) {
return 0;
}
public FloatEditor(String fieldName, Object obj, Field field, int index, Class<?> type) {
this.obj = obj;
this.field = field;
this.index = index;
this.type = type;
this.fieldName = fieldName;
reset();
}
@Override
public void reset() {
try {
Object val = ReflectionTools.getValue(obj, field, index);
setText(val == null ? "" : val.toString());
} catch (IllegalArgumentException | IllegalAccessException ex) {
// ignore
}
}
@Override
public boolean save() {
try {
String oldValue = (String) EcmaScript.toString(ReflectionTools.getValue(obj, field, index));
String newValue = getText();
if (Objects.equals(oldValue, newValue)) {
return false;
}
Object val;
if (type.equals(double.class) || type.equals(Double.class)) {
val = Double.valueOf(getText());
} else {
val = Float.valueOf(getText());
}
ReflectionTools.setValue(obj, field, index, val);
} catch (IllegalArgumentException | IllegalAccessException ex) {
// ignore
}
return true;
}
@Override
public void addChangeListener(final ChangeListener l) {
final GenericTagEditor t = this;
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
l.change(t);
}
});
}
@Override
public Object getChangedValue() {
return getText();
}
@Override
public String getFieldName() {
return fieldName;
}
@Override
public Field getField() {
return field;
}
@Override
public String getReadOnlyValue() {
return Helper.escapeHTML(getChangedValue().toString());
}
@Override
public void added() {
}
@Override
public void validateValue() {
}
@Override
public Object getObject() {
return obj;
}
}
@@ -141,7 +141,6 @@ public class NumberEditor extends JSpinner implements GenericTagEditor {
case FLOAT16:
m = new SpinnerNumberModel(toInt(value), -0x8000, 0x7fff, 1);
break;
case FB:
case SB:
long max = 1;
if (swfType.count() > 0) {
@@ -154,11 +153,6 @@ public class NumberEditor extends JSpinner implements GenericTagEditor {
case SI32:
m = new SpinnerNumberModel(toDouble(value), -0x80000000, 0x7fffffff, 1);
break;
case FLOAT:
case FIXED:
case FIXED8:
m = new SpinnerNumberModel(toDouble(value), -0x80000000, 0x7fffffff, 0.01);
break;
}
return m;
}