Skip to content

Commit

Permalink
Automatically increase the canvas size if bigger images are loaded in…
Browse files Browse the repository at this point in the history
… a sequence (fix #1719)
  • Loading branch information
dacap committed May 24, 2018
1 parent 31dcd32 commit 76915c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/app/file/file.cpp
Expand Up @@ -193,16 +193,15 @@ FileOp* FileOp::createLoadDocumentOperation(Context* context, const std::string&
goto done;
}

/* use the "sequence" interface */
// Use the "sequence" interface
if (fop->m_format->support(FILE_SUPPORT_SEQUENCES)) {
/* prepare to load a sequence */
fop->prepareForSequence();
fop->m_seq.flags = flags;

/* per now, we want load just one file */
// At the moment we want load just one file (the one specified in filename)
fop->m_seq.filename_list.push_back(filename);

/* don't load the sequence (just the one file/one frame) */
// If the user wants to load the whole sequence
if (!(flags & FILE_LOAD_SEQUENCE_NONE)) {
std::string left, right;
int c, width, start_from;
Expand Down Expand Up @@ -572,9 +571,12 @@ void FileOp::operate(IFileOpProgress* progress)
frame_t frames(m_seq.filename_list.size());
frame_t frame(0);
Image* old_image = nullptr;
gfx::Size canvasSize(0, 0);

// TODO setPalette for each frame???
auto add_image = [&]() {
canvasSize |= m_seq.image->size();

m_seq.last_cel->data()->setImage(m_seq.image);
m_seq.layer->addCel(m_seq.last_cel);

Expand Down Expand Up @@ -657,11 +659,16 @@ void FileOp::operate(IFileOpProgress* progress)
m_filename = *m_seq.filename_list.begin();

// Final setup
if (m_document != NULL) {
if (m_document) {
// Configure the layer as the 'Background'
if (!m_seq.has_alpha)
m_seq.layer->configureAsBackground();

// Set the final canvas size (as the bigger loaded
// frame/image).
m_document->sprite()->setSize(canvasSize.w,
canvasSize.h);

// Set the frames range
m_document->sprite()->setTotalFrames(frame);

Expand Down
10 changes: 9 additions & 1 deletion src/gfx/size.h
@@ -1,5 +1,5 @@
// Aseprite Gfx Library
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -91,6 +91,14 @@ class SizeT
return *this;
}

const SizeT& operator|=(const SizeT& sz) {
return *this = createUnion(sz);
}

const SizeT& operator&=(const SizeT& sz) {
return *this = createIntersection(sz);
}

SizeT operator+(const SizeT& sz) const {
return SizeT(w+sz.w, h+sz.h);
}
Expand Down

0 comments on commit 76915c7

Please sign in to comment.