Skip to content

Commit

Permalink
Add option to merge layers in color mode conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed May 19, 2017
1 parent 7eff2b8 commit 7837a12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/strings/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ delete = &Delete
[color_mode]
title = Color Mode
flatten = Merge layers
[convolution_matrix]
reload_stock = &Reload Stock
Expand Down
1 change: 1 addition & 0 deletions data/widgets/color_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<listbox id="color_mode" />
</view>
<slider min="0" max="100" id="progress" minwidth="100" />
<check text="@.flatten" id="flatten" />
<separator horizontal="true" />
<hbox>
<boxfiller />
Expand Down
14 changes: 13 additions & 1 deletion src/app/commands/cmd_change_pixel_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#endif

#include "app/app.h"
#include "app/cmd/flatten_layers.h"
#include "app/cmd/set_pixel_format.h"
#include "app/commands/command.h"
#include "app/commands/params.h"
Expand Down Expand Up @@ -221,6 +222,10 @@ class ColorModeWindow : public app::gen::ColorMode {
return m_selectedItem->ditheringAlgorithm();
}

bool flattenEnabled() const {
return flatten()->isSelected();
}

private:

void stop() {
Expand Down Expand Up @@ -394,6 +399,8 @@ bool ChangePixelFormatCommand::onChecked(Context* context)

void ChangePixelFormatCommand::onExecute(Context* context)
{
bool flatten = false;

if (m_useUI) {
ColorModeWindow window(current_editor);

Expand All @@ -406,6 +413,7 @@ void ChangePixelFormatCommand::onExecute(Context* context)

m_format = window.pixelFormat();
m_dithering = window.ditheringAlgorithm();
flatten = window.flattenEnabled();
}

// No conversion needed
Expand All @@ -414,10 +422,14 @@ void ChangePixelFormatCommand::onExecute(Context* context)

RenderTaskJob job(
"Converting Color Mode",
[this, &job, context]{
[this, &job, context, flatten]{
ContextWriter writer(context);
Transaction transaction(writer.context(), "Color Mode Change");
Sprite* sprite(writer.sprite());

if (flatten)
transaction.execute(new cmd::FlattenLayers(sprite));

transaction.execute(
new cmd::SetPixelFormat(
sprite, m_format, m_dithering, &job));
Expand Down

0 comments on commit 7837a12

Please sign in to comment.