Skip to content

Commit 52003da

Browse files
committed
Merge branch 'feature/continuous-cels'
2 parents b788837 + 3ebb708 commit 52003da

71 files changed

Lines changed: 1771 additions & 626 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
# Refactoring
4545

46+
* Replace get_unique_cels() with CelsRange
4647
* Make one level of layers (folders should modify only timeline/UI)
4748
* Convert doc::PixelFormat to a enum class
4849
* Add doc::Spec with width/height/channels/ColorMode/ncolors

data/gui.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@
648648
<item command="CelProperties" text="&amp;Properties..." />
649649
<separator />
650650
<item command="ClearCel" text="&amp;Clear" />
651+
<item command="UnlinkCel" text="&amp;Unlink" />
651652
</menu>
652653

653654
<menu id="cel_movement_popup">

data/skins/default/sheet.png

143 Bytes
Loading

data/skins/default/skin.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@
296296
<part id="timeline_open_padlock_active" x="252" y="36" w="12" h="12" />
297297
<part id="timeline_closed_padlock_normal" x="240" y="48" w="12" h="12" />
298298
<part id="timeline_closed_padlock_active" x="252" y="48" w="12" h="12" />
299+
<part id="timeline_continuous_normal" x="276" y="36" w="12" h="12" />
300+
<part id="timeline_continuous_active" x="288" y="36" w="12" h="12" />
301+
<part id="timeline_discontinuous_normal" x="276" y="48" w="12" h="12" />
302+
<part id="timeline_discontinuous_active" x="288" y="48" w="12" h="12" />
299303
<part id="timeline_empty_frame_normal" x="240" y="60" w="12" h="12" />
300304
<part id="timeline_empty_frame_active" x="252" y="60" w="12" h="12" />
301305
<part id="timeline_keyframe_normal" x="240" y="72" w="12" h="12" />
@@ -306,6 +310,9 @@
306310
<part id="timeline_fromright_active" x="252" y="96" w="12" h="12" />
307311
<part id="timeline_fromboth_normal" x="240" y="108" w="12" h="12" />
308312
<part id="timeline_fromboth_active" x="252" y="108" w="12" h="12" />
313+
<part id="timeline_leftlink_active" x="264" y="84" w="12" h="12" />
314+
<part id="timeline_bothlinks_active" x="264" y="96" w="12" h="12" />
315+
<part id="timeline_rightlink_active" x="264" y="108" w="12" h="12" />
309316
<part id="timeline_gear" x="264" y="12" w="12" h="12" />
310317
<part id="timeline_gear_active" x="264" y="24" w="12" h="12" />
311318
<part id="timeline_onionskin" x="264" y="36" w="12" h="12" />
@@ -434,6 +441,20 @@
434441
<icon part="timeline_closed_padlock_active" />
435442
</style>
436443

444+
<!-- timeline_continuous -->
445+
<style id="timeline_continuous" base="timeline_box">
446+
<icon part="timeline_continuous_normal" />
447+
</style>
448+
<style id="timeline_continuous:active">
449+
<icon part="timeline_continuous_active" />
450+
</style>
451+
<style id="timeline_discontinuous" base="timeline_box">
452+
<icon part="timeline_discontinuous_normal" />
453+
</style>
454+
<style id="timeline_discontinuous:active">
455+
<icon part="timeline_discontinuous_active" />
456+
</style>
457+
437458
<!-- timeline_layer -->
438459
<style id="timeline_layer" base="timeline_box">
439460
<text align="left" valign="middle" padding-left="4" />
@@ -482,6 +503,16 @@
482503
<icon part="timeline_fromboth_active" />
483504
</style>
484505

506+
<style id="timeline_leftlink">
507+
<icon part="timeline_leftlink_active" />
508+
</style>
509+
<style id="timeline_rightlink">
510+
<icon part="timeline_rightlink_active" />
511+
</style>
512+
<style id="timeline_bothlinks">
513+
<icon part="timeline_bothlinks_active" />
514+
</style>
515+
485516
<!-- timeline_gear -->
486517
<style id="timeline_gear" base="timeline_box">
487518
<icon part="timeline_gear" />

docs/files/ase.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Layer Chunk (0x2004)
119119
2 = Editable
120120
4 = Lock movement
121121
8 = Background
122+
16 = Prefer linked cels
122123
WORD Layer type (0=normal (image) layer, 1=layer set)
123124
WORD Layer child level (see NOTE.1)
124125
WORD Default layer width in pixels (ignored)

src/app/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ add_library(app-lib
7575
cmd/layer_from_background.cpp
7676
cmd/move_cel.cpp
7777
cmd/move_layer.cpp
78-
cmd/object_io.cpp
7978
cmd/remove_cel.cpp
8079
cmd/remove_frame.cpp
8180
cmd/remove_layer.cpp
8281
cmd/remove_palette.cpp
8382
cmd/replace_image.cpp
8483
cmd/reselect_mask.cpp
84+
cmd/set_cel_data.cpp
8585
cmd/set_cel_frame.cpp
8686
cmd/set_cel_opacity.cpp
8787
cmd/set_cel_position.cpp
@@ -95,6 +95,7 @@ add_library(app-lib
9595
cmd/set_sprite_size.cpp
9696
cmd/set_total_frames.cpp
9797
cmd/set_transparent_color.cpp
98+
cmd/unlink_cel.cpp
9899
cmd/with_cel.cpp
99100
cmd/with_document.cpp
100101
cmd/with_image.cpp
@@ -185,6 +186,7 @@ add_library(app-lib
185186
commands/cmd_switch_colors.cpp
186187
commands/cmd_timeline.cpp
187188
commands/cmd_undo.cpp
189+
commands/cmd_unlink_cel.cpp
188190
commands/cmd_zoom.cpp
189191
commands/command.cpp
190192
commands/commands.cpp

src/app/cmd/add_cel.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@
2222

2323
#include "app/cmd/add_cel.h"
2424

25-
#include "app/cmd/object_io.h"
25+
#include "base/serialization.h"
2626
#include "doc/cel.h"
27+
#include "doc/cel_io.h"
28+
#include "doc/cel_data_io.h"
2729
#include "doc/document.h"
2830
#include "doc/document_event.h"
31+
#include "doc/image_io.h"
2932
#include "doc/layer.h"
33+
#include "doc/subobjects_io.h"
3034

3135
namespace app {
3236
namespace cmd {
3337

38+
using namespace base::serialization;
39+
using namespace base::serialization::little_endian;
3440
using namespace doc;
3541

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

55-
ObjectIO(layer->sprite()).write_cel(m_stream, cel);
61+
// Save the CelData only if the cel isn't linked
62+
bool has_data = (cel->links() == 0);
63+
write8(m_stream, has_data ? 1: 0);
64+
if (has_data) {
65+
write_image(m_stream, cel->image());
66+
write_celdata(m_stream, cel->data());
67+
}
68+
write_cel(m_stream, cel);
5669

5770
removeCel(layer, cel);
5871
}
5972

6073
void AddCel::onRedo()
6174
{
6275
Layer* layer = this->layer();
63-
Cel* cel = ObjectIO(layer->sprite()).read_cel(m_stream);
76+
77+
SubObjectsIO io(layer->sprite());
78+
bool has_data = (read8(m_stream) != 0);
79+
if (has_data) {
80+
ImageRef image(read_image(m_stream));
81+
io.addImageRef(image);
82+
83+
CelDataRef celdata(read_celdata(m_stream, &io));
84+
io.addCelDataRef(celdata);
85+
}
86+
Cel* cel = read_cel(m_stream, &io);
6487

6588
addCel(layer, cel);
6689

src/app/cmd/add_layer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
#include "app/cmd/add_layer.h"
2424

25-
#include "app/cmd/object_io.h"
26-
#include "doc/layer.h"
2725
#include "doc/document.h"
2826
#include "doc/document_event.h"
2927
#include "doc/layer.h"
28+
#include "doc/layer_io.h"
29+
#include "doc/subobjects_io.h"
3030

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

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

5959
removeLayer(folder, layer);
6060
}
6161

6262
void AddLayer::onRedo()
6363
{
6464
Layer* folder = m_folder.layer();
65-
Layer* newLayer = ObjectIO(folder->sprite()).read_layer(m_stream);
65+
SubObjectsIO io(folder->sprite());
66+
Layer* newLayer = read_layer(m_stream, &io);
6667
Layer* afterThis = m_afterThis.layer();
6768

6869
addLayer(folder, newLayer, afterThis);

src/app/cmd/copy_cel.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "app/cmd/clear_cel.h"
2828
#include "app/cmd/copy_rect.h"
2929
#include "app/cmd/remove_cel.h"
30+
#include "app/cmd/set_cel_data.h"
31+
#include "app/cmd/unlink_cel.h"
3032
#include "app/document.h"
3133
#include "doc/cel.h"
3234
#include "doc/layer.h"
@@ -70,8 +72,11 @@ void CopyCel::onExecute()
7072

7173
// Clear destination cel if it does exist. It'll be overriden by the
7274
// copy of srcCel.
73-
if (dstCel)
75+
if (dstCel) {
76+
if (dstCel->links())
77+
executeAndAdd(new cmd::UnlinkCel(dstCel));
7478
executeAndAdd(new cmd::ClearCel(dstCel));
79+
}
7580

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

91+
bool createLink =
92+
(srcLayer == dstLayer && dstLayer->isContinuous());
93+
94+
// For background layer
8695
if (dstLayer->isBackground()) {
87-
if (srcCel) {
88-
ASSERT(dstImage);
89-
if (dstImage) {
90-
int blend = (srcLayer->isBackground() ?
91-
BLEND_MODE_COPY: BLEND_MODE_NORMAL);
92-
93-
ImageRef tmp(Image::createCopy(dstImage));
94-
render::composite_image(tmp, srcImage,
95-
srcCel->x(), srcCel->y(), 255, blend);
96-
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
97-
}
96+
ASSERT(dstCel);
97+
ASSERT(dstImage);
98+
if (!dstCel || !dstImage ||
99+
!srcCel || !srcImage)
100+
return;
101+
102+
if (createLink) {
103+
executeAndAdd(new cmd::SetCelData(dstCel, srcCel->dataRef()));
98104
}
99105
else {
100-
ASSERT(dstCel);
101-
if (dstCel)
102-
executeAndAdd(new cmd::ClearCel(dstCel));
106+
int blend = (srcLayer->isBackground() ?
107+
BLEND_MODE_COPY: BLEND_MODE_NORMAL);
108+
109+
ImageRef tmp(Image::createCopy(dstImage));
110+
render::composite_image(tmp, srcImage,
111+
srcCel->x(), srcCel->y(), 255, blend);
112+
executeAndAdd(new cmd::CopyRect(dstImage, tmp, gfx::Clip(tmp->bounds())));
103113
}
104114
}
115+
// For transparent layers
105116
else {
106117
if (dstCel)
107118
executeAndAdd(new cmd::RemoveCel(dstCel));
108119

109120
if (srcCel) {
110-
dstImage.reset(Image::createCopy(srcImage));
111-
112-
dstCel = new Cel(*srcCel);
121+
if (createLink)
122+
dstCel = Cel::createLink(srcCel);
123+
else
124+
dstCel = Cel::createCopy(srcCel);
113125
dstCel->setFrame(m_dstFrame);
114-
dstCel->setImage(dstImage);
115126

116127
executeAndAdd(new cmd::AddCel(dstLayer, dstCel));
117128
}

src/app/cmd/flatten_layers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void FlattenLayers::onExecute()
7070
clear_image(image, bgcolor);
7171
render.renderSprite(image, sprite, frame);
7272

73+
// TODO Keep cel links when possible
74+
7375
ImageRef cel_image;
7476
Cel* cel = background->cel(frame);
7577
if (cel) {

0 commit comments

Comments
 (0)