Skip to content
Permalink
Browse files
Merge branch 'feature/continuous-cels'
  • Loading branch information
dacap committed Feb 9, 2015
2 parents b788837 + 3ebb708 commit 52003da72163e388930d45c9d894c1f881d93372
Show file tree
Hide file tree
Showing 71 changed files with 1,771 additions and 626 deletions.
@@ -43,6 +43,7 @@

# Refactoring

* Replace get_unique_cels() with CelsRange
* Make one level of layers (folders should modify only timeline/UI)
* Convert doc::PixelFormat to a enum class
* Add doc::Spec with width/height/channels/ColorMode/ncolors
@@ -648,6 +648,7 @@
<item command="CelProperties" text="&amp;Properties..." />
<separator />
<item command="ClearCel" text="&amp;Clear" />
<item command="UnlinkCel" text="&amp;Unlink" />
</menu>

<menu id="cel_movement_popup">
BIN +143 Bytes (100%) data/skins/default/sheet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -296,6 +296,10 @@
<part id="timeline_open_padlock_active" x="252" y="36" w="12" h="12" />
<part id="timeline_closed_padlock_normal" x="240" y="48" w="12" h="12" />
<part id="timeline_closed_padlock_active" x="252" y="48" w="12" h="12" />
<part id="timeline_continuous_normal" x="276" y="36" w="12" h="12" />
<part id="timeline_continuous_active" x="288" y="36" w="12" h="12" />
<part id="timeline_discontinuous_normal" x="276" y="48" w="12" h="12" />
<part id="timeline_discontinuous_active" x="288" y="48" w="12" h="12" />
<part id="timeline_empty_frame_normal" x="240" y="60" w="12" h="12" />
<part id="timeline_empty_frame_active" x="252" y="60" w="12" h="12" />
<part id="timeline_keyframe_normal" x="240" y="72" w="12" h="12" />
@@ -306,6 +310,9 @@
<part id="timeline_fromright_active" x="252" y="96" w="12" h="12" />
<part id="timeline_fromboth_normal" x="240" y="108" w="12" h="12" />
<part id="timeline_fromboth_active" x="252" y="108" w="12" h="12" />
<part id="timeline_leftlink_active" x="264" y="84" w="12" h="12" />
<part id="timeline_bothlinks_active" x="264" y="96" w="12" h="12" />
<part id="timeline_rightlink_active" x="264" y="108" w="12" h="12" />
<part id="timeline_gear" x="264" y="12" w="12" h="12" />
<part id="timeline_gear_active" x="264" y="24" w="12" h="12" />
<part id="timeline_onionskin" x="264" y="36" w="12" h="12" />
@@ -434,6 +441,20 @@
<icon part="timeline_closed_padlock_active" />
</style>

<!-- timeline_continuous -->
<style id="timeline_continuous" base="timeline_box">
<icon part="timeline_continuous_normal" />
</style>
<style id="timeline_continuous:active">
<icon part="timeline_continuous_active" />
</style>
<style id="timeline_discontinuous" base="timeline_box">
<icon part="timeline_discontinuous_normal" />
</style>
<style id="timeline_discontinuous:active">
<icon part="timeline_discontinuous_active" />
</style>

<!-- timeline_layer -->
<style id="timeline_layer" base="timeline_box">
<text align="left" valign="middle" padding-left="4" />
@@ -482,6 +503,16 @@
<icon part="timeline_fromboth_active" />
</style>

<style id="timeline_leftlink">
<icon part="timeline_leftlink_active" />
</style>
<style id="timeline_rightlink">
<icon part="timeline_rightlink_active" />
</style>
<style id="timeline_bothlinks">
<icon part="timeline_bothlinks_active" />
</style>

<!-- timeline_gear -->
<style id="timeline_gear" base="timeline_box">
<icon part="timeline_gear" />
@@ -119,6 +119,7 @@ Layer Chunk (0x2004)
2 = Editable
4 = Lock movement
8 = Background
16 = Prefer linked cels
WORD Layer type (0=normal (image) layer, 1=layer set)
WORD Layer child level (see NOTE.1)
WORD Default layer width in pixels (ignored)
@@ -75,13 +75,13 @@ add_library(app-lib
cmd/layer_from_background.cpp
cmd/move_cel.cpp
cmd/move_layer.cpp
cmd/object_io.cpp
cmd/remove_cel.cpp
cmd/remove_frame.cpp
cmd/remove_layer.cpp
cmd/remove_palette.cpp
cmd/replace_image.cpp
cmd/reselect_mask.cpp
cmd/set_cel_data.cpp
cmd/set_cel_frame.cpp
cmd/set_cel_opacity.cpp
cmd/set_cel_position.cpp
@@ -95,6 +95,7 @@ add_library(app-lib
cmd/set_sprite_size.cpp
cmd/set_total_frames.cpp
cmd/set_transparent_color.cpp
cmd/unlink_cel.cpp
cmd/with_cel.cpp
cmd/with_document.cpp
cmd/with_image.cpp
@@ -185,6 +186,7 @@ add_library(app-lib
commands/cmd_switch_colors.cpp
commands/cmd_timeline.cpp
commands/cmd_undo.cpp
commands/cmd_unlink_cel.cpp
commands/cmd_zoom.cpp
commands/command.cpp
commands/commands.cpp
@@ -22,15 +22,21 @@

#include "app/cmd/add_cel.h"

#include "app/cmd/object_io.h"
#include "base/serialization.h"
#include "doc/cel.h"
#include "doc/cel_io.h"
#include "doc/cel_data_io.h"
#include "doc/document.h"
#include "doc/document_event.h"
#include "doc/image_io.h"
#include "doc/layer.h"
#include "doc/subobjects_io.h"

namespace app {
namespace cmd {

using namespace base::serialization;
using namespace base::serialization::little_endian;
using namespace doc;

AddCel::AddCel(Layer* layer, Cel* cel)
@@ -52,15 +58,32 @@ void AddCel::onUndo()
Layer* layer = this->layer();
Cel* cel = this->cel();

ObjectIO(layer->sprite()).write_cel(m_stream, cel);
// Save the CelData only if the cel isn't linked
bool has_data = (cel->links() == 0);
write8(m_stream, has_data ? 1: 0);
if (has_data) {
write_image(m_stream, cel->image());
write_celdata(m_stream, cel->data());
}
write_cel(m_stream, cel);

removeCel(layer, cel);
}

void AddCel::onRedo()
{
Layer* layer = this->layer();
Cel* cel = ObjectIO(layer->sprite()).read_cel(m_stream);

SubObjectsIO io(layer->sprite());
bool has_data = (read8(m_stream) != 0);
if (has_data) {
ImageRef image(read_image(m_stream));
io.addImageRef(image);

CelDataRef celdata(read_celdata(m_stream, &io));
io.addCelDataRef(celdata);
}
Cel* cel = read_cel(m_stream, &io);

addCel(layer, cel);

@@ -22,11 +22,11 @@

#include "app/cmd/add_layer.h"

#include "app/cmd/object_io.h"
#include "doc/layer.h"
#include "doc/document.h"
#include "doc/document_event.h"
#include "doc/layer.h"
#include "doc/layer_io.h"
#include "doc/subobjects_io.h"

namespace app {
namespace cmd {
@@ -54,15 +54,16 @@ void AddLayer::onUndo()
Layer* folder = m_folder.layer();
Layer* layer = m_newLayer.layer();

ObjectIO(folder->sprite()).write_layer(m_stream, layer);
write_layer(m_stream, layer);

removeLayer(folder, layer);
}

void AddLayer::onRedo()
{
Layer* folder = m_folder.layer();
Layer* newLayer = ObjectIO(folder->sprite()).read_layer(m_stream);
SubObjectsIO io(folder->sprite());
Layer* newLayer = read_layer(m_stream, &io);
Layer* afterThis = m_afterThis.layer();

addLayer(folder, newLayer, afterThis);
@@ -27,6 +27,8 @@
#include "app/cmd/clear_cel.h"
#include "app/cmd/copy_rect.h"
#include "app/cmd/remove_cel.h"
#include "app/cmd/set_cel_data.h"
#include "app/cmd/unlink_cel.h"
#include "app/document.h"
#include "doc/cel.h"
#include "doc/layer.h"
@@ -70,8 +72,11 @@ void CopyCel::onExecute()

// Clear destination cel if it does exist. It'll be overriden by the
// copy of srcCel.
if (dstCel)
if (dstCel) {
if (dstCel->links())
executeAndAdd(new cmd::UnlinkCel(dstCel));
executeAndAdd(new cmd::ClearCel(dstCel));
}

// Add empty frames until newFrame
while (dstSprite->totalFrames() <= m_dstFrame)
@@ -83,35 +88,41 @@ void CopyCel::onExecute()
if (dstCel)
dstImage = dstCel->imageRef();

bool createLink =
(srcLayer == dstLayer && dstLayer->isContinuous());

// For background layer
if (dstLayer->isBackground()) {
if (srcCel) {
ASSERT(dstImage);
if (dstImage) {
int blend = (srcLayer->isBackground() ?
BLEND_MODE_COPY: BLEND_MODE_NORMAL);

ImageRef tmp(Image::createCopy(dstImage));
render::composite_image(tmp, srcImage,
srcCel->x(), srcCel->y(), 255, blend);
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
}
ASSERT(dstCel);
ASSERT(dstImage);
if (!dstCel || !dstImage ||
!srcCel || !srcImage)
return;

if (createLink) {
executeAndAdd(new cmd::SetCelData(dstCel, srcCel->dataRef()));
}
else {
ASSERT(dstCel);
if (dstCel)
executeAndAdd(new cmd::ClearCel(dstCel));
int blend = (srcLayer->isBackground() ?
BLEND_MODE_COPY: BLEND_MODE_NORMAL);

ImageRef tmp(Image::createCopy(dstImage));
render::composite_image(tmp, srcImage,
srcCel->x(), srcCel->y(), 255, blend);
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
}
}
// For transparent layers
else {
if (dstCel)
executeAndAdd(new cmd::RemoveCel(dstCel));

if (srcCel) {
dstImage.reset(Image::createCopy(srcImage));

dstCel = new Cel(*srcCel);
if (createLink)
dstCel = Cel::createLink(srcCel);
else
dstCel = Cel::createCopy(srcCel);
dstCel->setFrame(m_dstFrame);
dstCel->setImage(dstImage);

executeAndAdd(new cmd::AddCel(dstLayer, dstCel));
}
@@ -70,6 +70,8 @@ void FlattenLayers::onExecute()
clear_image(image, bgcolor);
render.renderSprite(image, sprite, frame);

// TODO Keep cel links when possible

ImageRef cel_image;
Cel* cel = background->cel(frame);
if (cel) {

0 comments on commit 52003da

Please sign in to comment.