Skip to content

Commit

Permalink
Merge branch 'feature/continuous-cels'
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Feb 9, 2015
2 parents b788837 + 3ebb708 commit 52003da
Show file tree
Hide file tree
Showing 71 changed files with 1,771 additions and 626 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions data/gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Binary file modified data/skins/default/sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions data/skins/default/skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
1 change: 1 addition & 0 deletions docs/files/ase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions src/app/cmd/add_cel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/app/cmd/add_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 30 additions & 19 deletions src/app/cmd/copy_cel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/cmd/flatten_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 52003da

Please sign in to comment.