Added #2011, #2215 Option to ignore frame background color when exporting (make transparent)

This commit is contained in:
Jindra Petřík
2024-08-05 11:17:25 +02:00
parent 1e4d2511a2
commit 0b48eab7f7
13 changed files with 88 additions and 24 deletions
@@ -503,6 +503,7 @@ public class CommandLineArgumentParser {
boolean air = false;
boolean exportEmbed = false;
boolean resampleWav = false;
boolean transparentBackground = false;
Selection selection = new Selection();
Selection selectionIds = new Selection();
List<String> selectionClasses = null;
@@ -539,6 +540,9 @@ public class CommandLineArgumentParser {
case "-resamplewav":
resampleWav = true;
break;
case "-ignorebackground":
transparentBackground = true;
break;
case "-zoom":
zoom = parseZoom(args);
break;
@@ -653,7 +657,7 @@ public class CommandLineArgumentParser {
} else if (command.equals("proxy")) {
parseProxy(args);
} else if (command.equals("export")) {
parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom, charset, exportEmbed, resampleWav);
parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom, charset, exportEmbed, resampleWav, transparentBackground);
System.exit(0);
} else if (command.equals("compress")) {
parseCompress(args);
@@ -1918,7 +1922,7 @@ public class CommandLineArgumentParser {
}
private static void parseExport(List<String> selectionClasses, Selection selection, Selection selectionIds, Stack<String> args, AbortRetryIgnoreHandler handler, Level traceLevel, Map<String, String> formats, double zoom, String charset, boolean exportEmbed, boolean resampleWav) {
private static void parseExport(List<String> selectionClasses, Selection selection, Selection selectionIds, Stack<String> args, AbortRetryIgnoreHandler handler, Level traceLevel, Map<String, String> formats, double zoom, String charset, boolean exportEmbed, boolean resampleWav, boolean transparentBackground) {
if (args.size() < 3) {
badArguments("export");
}
@@ -2147,7 +2151,7 @@ public class CommandLineArgumentParser {
frames.add(i);
}
}
FrameExportSettings fes = new FrameExportSettings(enumFromStr(formats.get("frame"), FrameExportMode.class), zoom);
FrameExportSettings fes = new FrameExportSettings(enumFromStr(formats.get("frame"), FrameExportMode.class), zoom, transparentBackground);
frameExporter.exportFrames(handler, outDir + (multipleExportTypes ? File.separator + FrameExportSettings.EXPORT_FOLDER_NAME : ""), swf, 0, frames, fes, evl);
}
@@ -432,3 +432,8 @@ Pre-options:
Applies to: -export
Enables resampling exported WAV sound files to 44kHz.
-ignorebackground
Applies to: -export
Ignores SWF background color when exporting frames
and thus make background transparent.
@@ -149,6 +149,8 @@ public class ExportDialog extends AppDialog {
private JCheckBox embedCheckBox;
private JCheckBox resampleWavCheckBox;
private JCheckBox transparentFrameBackgroundCheckBox;
public <E> E getValue(Class<E> option) {
for (int i = 0; i < optionClasses.length; i++) {
@@ -178,6 +180,10 @@ public class ExportDialog extends AppDialog {
public boolean isResampleWavEnabled() {
return resampleWavCheckBox.isSelected();
}
public boolean isTransparentFrameBackgroundEnabled() {
return transparentFrameBackgroundCheckBox.isSelected();
}
public double getZoom() {
return Double.parseDouble(zoomTextField.getText()) / 100;
@@ -204,6 +210,9 @@ public class ExportDialog extends AppDialog {
if (resampleWavCheckBox.isVisible()) {
Configuration.lastExportResampleWav.set(resampleWavCheckBox.isSelected());
}
if (transparentFrameBackgroundCheckBox.isVisible()) {
Configuration.lastExportTransparentBackground.set(transparentFrameBackgroundCheckBox.isSelected());
}
}
private boolean optionCanHandle(int optionIndex, Object e) {
@@ -392,7 +401,25 @@ public class ExportDialog extends AppDialog {
if (resampleWavCheckBox.getWidth() + 10 > w) {
w = resampleWavCheckBox.getWidth() + 10;
}
}
}
transparentFrameBackgroundCheckBox = new JCheckBox(translate("transparentFrameBackground"));
transparentFrameBackgroundCheckBox.setVisible(false);
if (visibleOptionClasses.contains(FrameExportMode.class)) {
top += 2;
transparentFrameBackgroundCheckBox.setVisible(true);
comboPanel.add(transparentFrameBackgroundCheckBox);
if (Configuration.lastExportTransparentBackground.get()) {
transparentFrameBackgroundCheckBox.setSelected(true);
}
transparentFrameBackgroundCheckBox.setBounds(10, top, transparentFrameBackgroundCheckBox.getPreferredSize().width, transparentFrameBackgroundCheckBox.getPreferredSize().height);
top += transparentFrameBackgroundCheckBox.getHeight();
if (transparentFrameBackgroundCheckBox.getWidth() + 10 > w) {
w = transparentFrameBackgroundCheckBox.getWidth() + 10;
}
}
int zoomWidth = 50;
if (zoomable) {
@@ -2220,7 +2220,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
FrameExporter frameExporter = new FrameExporter();
if (export.isOptionEnabled(FrameExportMode.class)) {
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom());
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom(), export.isTransparentFrameBackgroundEnabled());
if (frames.containsKey(0)) {
String subFolder = FrameExportSettings.EXPORT_FOLDER_NAME;
ret.addAll(frameExporter.exportFrames(handler, selFile2 + File.separator + subFolder, swf, 0, frames.get(0), fes, evl));
@@ -2333,7 +2333,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
FrameExporter frameExporter = new FrameExporter();
if (export.isOptionEnabled(FrameExportMode.class)) {
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom());
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom(), export.isTransparentFrameBackgroundEnabled());
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME), swf, 0, null, fes, evl);
}
@@ -2444,7 +2444,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(FrameExportMode.class)) {
for (FrameExportMode exportMode : FrameExportMode.values()) {
FrameExportSettings fes = new FrameExportSettings(exportMode, export.getZoom());
FrameExportSettings fes = new FrameExportSettings(exportMode, export.getZoom(), export.isTransparentFrameBackgroundEnabled());
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, 0, null, fes, evl);
}
}
@@ -767,3 +767,5 @@ config.description.lastExportResampleWav = Last setting of resampling wav to 44k
config.name.previewResampleSound = Resample in sound previews
config.description.previewResampleSound = Resample to 44kHz in sound previews
config.name.lastExportTransparentBackground = Last setting of ignoring background color in frame export
config.description.lastExportTransparentBackground = Last setting of ignoring background color for frame export to make background transparency
@@ -112,4 +112,5 @@ fonts4.cff = CFF
embed = Export embedded assets via [Embed]
#after 20.1.0
resampleWav = Resample Wav to 44kHz
resampleWav = Resample Wav to 44kHz
transparentFrameBackground = Ignore background color (make transparent)
@@ -107,4 +107,5 @@ images.png_gif_jpeg_alpha = PNG/GIF/JPEG+alpha
embed = Exportovat vlo\u017een\u00e9 zdroje skrze [Embed]
#after 20.1.0
resampleWav = P\u0159evzorkovat Wav na 44kHz
resampleWav = P\u0159evzorkovat Wav na 44kHz
transparentFrameBackground = Ignorovat barvu pozad\u00ed (pou\u017e\u00edt pr\u016fhlednou)