mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 13:21:34 +00:00
Add flag to avoid creating backround layers
Now callers can force loading a file without creating any background layer in the doc. This is because for drag and drop operations we don't want to generate background layers
This commit is contained in:
parent
abbbe11fe7
commit
16f3e53ce9
@ -81,13 +81,18 @@ void DropOnTimeline::onExecute()
|
||||
LayerGroup* group = nullptr;
|
||||
|
||||
int flags =
|
||||
FILE_LOAD_DATA_FILE |
|
||||
FILE_LOAD_DATA_FILE | FILE_LOAD_AVOID_BACKGROUND_LAYER |
|
||||
FILE_LOAD_CREATE_PALETTE | FILE_LOAD_SEQUENCE_YES;
|
||||
|
||||
int fopCount = 0;
|
||||
while(!m_paths.empty()) {
|
||||
std::unique_ptr<FileOp> fop(
|
||||
FileOp::createLoadDocumentOperation(context, m_paths.front(), flags));
|
||||
|
||||
// Do nothing (the user cancelled or something like that)
|
||||
if (!fop)
|
||||
return;
|
||||
|
||||
fopCount++;
|
||||
|
||||
base::paths fopFilenames;
|
||||
@ -99,10 +104,6 @@ void DropOnTimeline::onExecute()
|
||||
m_paths.erase(it);
|
||||
}
|
||||
|
||||
// Do nothing (the user cancelled or something like that)
|
||||
if (!fop)
|
||||
return;
|
||||
|
||||
if (fop->hasError()) {
|
||||
console.printf(fop->error().c_str());
|
||||
}
|
||||
|
@ -533,6 +533,11 @@ FileOp* FileOp::createLoadDocumentOperation(Context* context,
|
||||
fop->m_dataFilename = dataFilename;
|
||||
}
|
||||
|
||||
// Avoid creating a background layer?
|
||||
if (flags & FILE_LOAD_AVOID_BACKGROUND_LAYER) {
|
||||
fop->m_avoidBackgroundLayer = true;
|
||||
}
|
||||
|
||||
done:;
|
||||
return fop.release();
|
||||
}
|
||||
@ -939,8 +944,9 @@ void FileOp::operate(IFileOpProgress* progress)
|
||||
|
||||
// Final setup
|
||||
if (m_document) {
|
||||
// Configure the layer as the 'Background'
|
||||
if (!m_seq.has_alpha)
|
||||
// Configure the layer as the 'Background'. Only if background layers
|
||||
// are welcome.
|
||||
if (!m_seq.has_alpha && !m_avoidBackgroundLayer)
|
||||
m_seq.layer->configureAsBackground();
|
||||
|
||||
// Set the final canvas size (as the bigger loaded
|
||||
@ -1522,6 +1528,7 @@ FileOp::FileOp(FileOpType type,
|
||||
, m_oneframe(false)
|
||||
, m_createPaletteFromRgba(false)
|
||||
, m_ignoreEmpty(false)
|
||||
, m_avoidBackgroundLayer(false)
|
||||
, m_embeddedColorProfile(false)
|
||||
, m_embeddedGridBounds(false)
|
||||
{
|
||||
|
@ -27,13 +27,14 @@
|
||||
#include <string>
|
||||
|
||||
// Flags for FileOp::createLoadDocumentOperation()
|
||||
#define FILE_LOAD_SEQUENCE_NONE 0x00000001
|
||||
#define FILE_LOAD_SEQUENCE_ASK 0x00000002
|
||||
#define FILE_LOAD_SEQUENCE_ASK_CHECKBOX 0x00000004
|
||||
#define FILE_LOAD_SEQUENCE_YES 0x00000008
|
||||
#define FILE_LOAD_ONE_FRAME 0x00000010
|
||||
#define FILE_LOAD_DATA_FILE 0x00000020
|
||||
#define FILE_LOAD_CREATE_PALETTE 0x00000040
|
||||
#define FILE_LOAD_SEQUENCE_NONE 0x00000001
|
||||
#define FILE_LOAD_SEQUENCE_ASK 0x00000002
|
||||
#define FILE_LOAD_SEQUENCE_ASK_CHECKBOX 0x00000004
|
||||
#define FILE_LOAD_SEQUENCE_YES 0x00000008
|
||||
#define FILE_LOAD_ONE_FRAME 0x00000010
|
||||
#define FILE_LOAD_DATA_FILE 0x00000020
|
||||
#define FILE_LOAD_CREATE_PALETTE 0x00000040
|
||||
#define FILE_LOAD_AVOID_BACKGROUND_LAYER 0x00000080
|
||||
|
||||
namespace doc {
|
||||
class Tag;
|
||||
@ -285,6 +286,8 @@ namespace app {
|
||||
bool newBlend() const { return m_config.newBlend; }
|
||||
const FileOpConfig& config() const { return m_config; }
|
||||
|
||||
bool avoidBackgroundLayer() const { return m_avoidBackgroundLayer; }
|
||||
|
||||
private:
|
||||
FileOp(); // Undefined
|
||||
FileOp(FileOpType type,
|
||||
@ -314,6 +317,7 @@ namespace app {
|
||||
// GIF/FLI/ASE).
|
||||
bool m_createPaletteFromRgba;
|
||||
bool m_ignoreEmpty;
|
||||
bool m_avoidBackgroundLayer;
|
||||
|
||||
// True if the file contained a color profile when it was loaded.
|
||||
bool m_embeddedColorProfile;
|
||||
|
@ -95,7 +95,8 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
Sprite* sprite = new Sprite(ImageSpec(ColorMode::INDEXED, w, h), 256);
|
||||
LayerImage* layer = new LayerImage(sprite);
|
||||
sprite->root()->addLayer(layer);
|
||||
layer->configureAsBackground();
|
||||
if (!fop->avoidBackgroundLayer())
|
||||
layer->configureAsBackground();
|
||||
|
||||
// Set frames and speed
|
||||
sprite->setTotalFrames(frame_t(header.frames));
|
||||
|
@ -288,7 +288,7 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_layer && m_opaque)
|
||||
if (m_layer && m_opaque && !m_fop->avoidBackgroundLayer())
|
||||
m_layer->configureAsBackground();
|
||||
|
||||
// sRGB is the default color space for GIF files
|
||||
|
@ -211,7 +211,7 @@ bool WebPFormat::onLoad(FileOp* fop)
|
||||
}
|
||||
WebPAnimDecoderReset(dec);
|
||||
|
||||
if (!has_alpha)
|
||||
if (!has_alpha && !fop->avoidBackgroundLayer())
|
||||
layer->configureAsBackground();
|
||||
|
||||
WebPAnimDecoderDelete(dec);
|
||||
|
Loading…
x
Reference in New Issue
Block a user