mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 13:20:28 +00:00
Refresh screen/current palette automatically on Transaction::commit() (#378)
Removed app_update_current_palette() with this patch.
This commit is contained in:
parent
7c92fe207a
commit
944634542e
@ -639,26 +639,18 @@ InputChain& App::inputChain()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void app_update_current_palette()
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_UI
|
|
||||||
Context* context = UIContext::instance();
|
|
||||||
ASSERT(context != NULL);
|
|
||||||
|
|
||||||
Site site = context->activeSite();
|
|
||||||
|
|
||||||
if (Palette* pal = site.palette())
|
|
||||||
set_current_palette(pal, false);
|
|
||||||
else
|
|
||||||
set_current_palette(nullptr, false);
|
|
||||||
#endif // ENABLE_UI
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updates palette and redraw the screen.
|
// Updates palette and redraw the screen.
|
||||||
void app_refresh_screen()
|
void app_refresh_screen()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
app_update_current_palette();
|
Context* ctx = UIContext::instance();
|
||||||
|
ASSERT(ctx != NULL);
|
||||||
|
|
||||||
|
Site site = ctx->activeSite();
|
||||||
|
if (Palette* pal = site.palette())
|
||||||
|
set_current_palette(pal, false);
|
||||||
|
else
|
||||||
|
set_current_palette(nullptr, false);
|
||||||
|
|
||||||
// Invalidate the whole screen.
|
// Invalidate the whole screen.
|
||||||
ui::Manager::getDefault()->invalidate();
|
ui::Manager::getDefault()->invalidate();
|
||||||
|
@ -147,7 +147,6 @@ namespace app {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void app_update_current_palette();
|
|
||||||
void app_refresh_screen();
|
void app_refresh_screen();
|
||||||
void app_rebuild_documents_tabs();
|
void app_rebuild_documents_tabs();
|
||||||
PixelFormat app_get_current_pixel_format();
|
PixelFormat app_get_current_pixel_format();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
|
// Copyright (C) 2019 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -10,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/cmd/set_palette.h"
|
#include "app/cmd/set_palette.h"
|
||||||
|
|
||||||
|
#include "app/doc.h"
|
||||||
#include "base/serialization.h"
|
#include "base/serialization.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
@ -77,5 +79,12 @@ void SetPalette::onUndo()
|
|||||||
palette->incrementVersion();
|
palette->incrementVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetPalette::onFireNotifications()
|
||||||
|
{
|
||||||
|
doc::Sprite* sprite = this->sprite();
|
||||||
|
Doc* doc = static_cast<Doc*>(sprite->document());
|
||||||
|
doc->notifyPaletteChanged();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace cmd
|
} // namespace cmd
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
|
// Copyright (C) 2019 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -32,6 +33,7 @@ namespace cmd {
|
|||||||
protected:
|
protected:
|
||||||
void onExecute() override;
|
void onExecute() override;
|
||||||
void onUndo() override;
|
void onUndo() override;
|
||||||
|
void onFireNotifications() override;
|
||||||
size_t onMemSize() const override {
|
size_t onMemSize() const override {
|
||||||
return sizeof(*this) +
|
return sizeof(*this) +
|
||||||
sizeof(doc::color_t) * (m_oldColors.size() +
|
sizeof(doc::color_t) * (m_oldColors.size() +
|
||||||
|
@ -16,14 +16,12 @@
|
|||||||
#include "app/context.h"
|
#include "app/context.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/i18n/strings.h"
|
#include "app/i18n/strings.h"
|
||||||
#include "app/modules/palettes.h"
|
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "app/ui/color_bar.h"
|
#include "app/ui/color_bar.h"
|
||||||
#include "app/ui/context_bar.h"
|
#include "app/ui/context_bar.h"
|
||||||
#include "app/ui/editor/editor.h"
|
#include "app/ui/editor/editor.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "ui/manager.h"
|
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
@ -87,8 +85,13 @@ void AddColorCommand::onExecute(Context* ctx)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Palette* pal = ctx->activeSite().palette();
|
||||||
|
ASSERT(pal);
|
||||||
|
if (!pal)
|
||||||
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Palette* newPalette = get_current_palette(); // System current pal
|
std::unique_ptr<Palette> newPalette(new Palette(*pal));
|
||||||
color_t color = doc::rgba(
|
color_t color = doc::rgba(
|
||||||
appColor.getRed(),
|
appColor.getRed(),
|
||||||
appColor.getGreen(),
|
appColor.getGreen(),
|
||||||
@ -122,12 +125,9 @@ void AddColorCommand::onExecute(Context* ctx)
|
|||||||
frame_t frame = writer.frame();
|
frame_t frame = writer.frame();
|
||||||
|
|
||||||
Tx tx(writer.context(), friendlyName(), ModifyDocument);
|
Tx tx(writer.context(), friendlyName(), ModifyDocument);
|
||||||
tx(new cmd::SetPalette(sprite, frame, newPalette));
|
tx(new cmd::SetPalette(sprite, frame, newPalette.get()));
|
||||||
tx.commit();
|
tx.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_palette(newPalette, true);
|
|
||||||
ui::Manager::getDefault()->invalidate();
|
|
||||||
}
|
}
|
||||||
catch (base::Exception& e) {
|
catch (base::Exception& e) {
|
||||||
Console::showException(e);
|
Console::showException(e);
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "app/context.h"
|
#include "app/context.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/job.h"
|
#include "app/job.h"
|
||||||
#include "app/modules/palettes.h"
|
|
||||||
#include "app/pref/preferences.h"
|
#include "app/pref/preferences.h"
|
||||||
#include "app/sprite_job.h"
|
#include "app/sprite_job.h"
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
@ -25,7 +24,6 @@
|
|||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "render/quantization.h"
|
#include "render/quantization.h"
|
||||||
#include "ui/manager.h"
|
|
||||||
|
|
||||||
#include "palette_from_sprite.xml.h"
|
#include "palette_from_sprite.xml.h"
|
||||||
|
|
||||||
@ -156,7 +154,7 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
|||||||
|
|
||||||
std::unique_ptr<Palette> newPalette(
|
std::unique_ptr<Palette> newPalette(
|
||||||
new Palette(createPal ? tmpPalette:
|
new Palette(createPal ? tmpPalette:
|
||||||
*get_current_palette()));
|
*site.palette()));
|
||||||
|
|
||||||
if (createPal) {
|
if (createPal) {
|
||||||
entries = PalettePicks(newPalette->size());
|
entries = PalettePicks(newPalette->size());
|
||||||
@ -172,13 +170,6 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
|||||||
|
|
||||||
if (*curPalette != *newPalette)
|
if (*curPalette != *newPalette)
|
||||||
job.tx()(new cmd::SetPalette(sprite, frame, newPalette.get()));
|
job.tx()(new cmd::SetPalette(sprite, frame, newPalette.get()));
|
||||||
|
|
||||||
#ifdef ENABLE_UI
|
|
||||||
if (ui) {
|
|
||||||
set_current_palette(newPalette.get(), false);
|
|
||||||
ui::Manager::getDefault()->invalidate();
|
|
||||||
}
|
|
||||||
#endif // ENABLE_UI
|
|
||||||
}
|
}
|
||||||
catch (const base::Exception& e) {
|
catch (const base::Exception& e) {
|
||||||
Console::showException(e);
|
Console::showException(e);
|
||||||
|
@ -13,11 +13,9 @@
|
|||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/modules/palettes.h"
|
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "ui/manager.h"
|
|
||||||
|
|
||||||
#include "palette_size.xml.h"
|
#include "palette_size.xml.h"
|
||||||
|
|
||||||
@ -51,8 +49,9 @@ void PaletteSizeCommand::onLoadParams(const Params& params)
|
|||||||
void PaletteSizeCommand::onExecute(Context* context)
|
void PaletteSizeCommand::onExecute(Context* context)
|
||||||
{
|
{
|
||||||
ContextReader reader(context);
|
ContextReader reader(context);
|
||||||
frame_t frame = reader.frame();
|
const frame_t frame = reader.frame();
|
||||||
Palette palette(*reader.sprite()->palette(frame));
|
ASSERT(reader.palette());
|
||||||
|
Palette palette(*reader.palette());
|
||||||
int ncolors = (m_size != 0 ? m_size: palette.size());
|
int ncolors = (m_size != 0 ? m_size: palette.size());
|
||||||
|
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
@ -76,12 +75,6 @@ void PaletteSizeCommand::onExecute(Context* context)
|
|||||||
Tx tx(context, "Palette Size", ModifyDocument);
|
Tx tx(context, "Palette Size", ModifyDocument);
|
||||||
tx(new cmd::SetPalette(writer.sprite(), frame, &palette));
|
tx(new cmd::SetPalette(writer.sprite(), frame, &palette));
|
||||||
tx.commit();
|
tx.commit();
|
||||||
|
|
||||||
set_current_palette(&palette, false);
|
|
||||||
#ifdef ENABLE_UI
|
|
||||||
if (context->isUIAvailable())
|
|
||||||
ui::Manager::getDefault()->invalidate();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* CommandFactory::createPaletteSizeCommand()
|
Command* CommandFactory::createPaletteSizeCommand()
|
||||||
|
@ -146,6 +146,13 @@ void Doc::notifyColorSpaceChanged()
|
|||||||
notify_observers<DocEvent&>(&DocObserver::onColorSpaceChanged, ev);
|
notify_observers<DocEvent&>(&DocObserver::onColorSpaceChanged, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Doc::notifyPaletteChanged()
|
||||||
|
{
|
||||||
|
DocEvent ev(this);
|
||||||
|
ev.sprite(sprite());
|
||||||
|
notify_observers<DocEvent&>(&DocObserver::onPaletteChanged, ev);
|
||||||
|
}
|
||||||
|
|
||||||
void Doc::notifySpritePixelsModified(Sprite* sprite, const gfx::Region& region, frame_t frame)
|
void Doc::notifySpritePixelsModified(Sprite* sprite, const gfx::Region& region, frame_t frame)
|
||||||
{
|
{
|
||||||
DocEvent ev(this);
|
DocEvent ev(this);
|
||||||
@ -549,14 +556,6 @@ void Doc::updateOSColorSpace(bool appWideSignal)
|
|||||||
context()->activeDocument() == this) {
|
context()->activeDocument() == this) {
|
||||||
App::instance()->ColorSpaceChange();
|
App::instance()->ColorSpaceChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui::is_ui_thread()) {
|
|
||||||
// As the color space has changed, we might need to upate the
|
|
||||||
// current palette (because the color space conversion might be
|
|
||||||
// came from a cmd::ConvertColorProfile, so the palette might be
|
|
||||||
// changed). This might generate a PaletteChange() signal.
|
|
||||||
app_update_current_palette();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -95,6 +95,7 @@ namespace app {
|
|||||||
|
|
||||||
void notifyGeneralUpdate();
|
void notifyGeneralUpdate();
|
||||||
void notifyColorSpaceChanged();
|
void notifyColorSpaceChanged();
|
||||||
|
void notifyPaletteChanged();
|
||||||
void notifySpritePixelsModified(Sprite* sprite, const gfx::Region& region, frame_t frame);
|
void notifySpritePixelsModified(Sprite* sprite, const gfx::Region& region, frame_t frame);
|
||||||
void notifyExposeSpritePixels(Sprite* sprite, const gfx::Region& region);
|
void notifyExposeSpritePixels(Sprite* sprite, const gfx::Region& region);
|
||||||
void notifyLayerMergedDown(Layer* srcLayer, Layer* targetLayer);
|
void notifyLayerMergedDown(Layer* srcLayer, Layer* targetLayer);
|
||||||
|
@ -24,8 +24,8 @@ namespace app {
|
|||||||
virtual void onGeneralUpdate(DocEvent& ev) { }
|
virtual void onGeneralUpdate(DocEvent& ev) { }
|
||||||
|
|
||||||
virtual void onColorSpaceChanged(DocEvent& ev) { }
|
virtual void onColorSpaceChanged(DocEvent& ev) { }
|
||||||
|
|
||||||
virtual void onPixelFormatChanged(DocEvent& ev) { }
|
virtual void onPixelFormatChanged(DocEvent& ev) { }
|
||||||
|
virtual void onPaletteChanged(DocEvent& ev) { }
|
||||||
|
|
||||||
virtual void onAddLayer(DocEvent& ev) { }
|
virtual void onAddLayer(DocEvent& ev) { }
|
||||||
virtual void onAddFrame(DocEvent& ev) { }
|
virtual void onAddFrame(DocEvent& ev) { }
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/doc.h"
|
#include "app/doc.h"
|
||||||
#include "app/doc_undo.h"
|
#include "app/doc_undo.h"
|
||||||
|
#include "app/modules/palettes.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
#include "ui/manager.h"
|
||||||
#include "ui/system.h"
|
#include "ui/system.h"
|
||||||
|
|
||||||
#define TX_TRACE(...)
|
#define TX_TRACE(...)
|
||||||
@ -88,6 +90,8 @@ void Transaction::commit()
|
|||||||
TX_TRACE("TX: Commit <%s>\n", m_cmds->label().c_str());
|
TX_TRACE("TX: Commit <%s>\n", m_cmds->label().c_str());
|
||||||
|
|
||||||
m_cmds->updateSpritePositionAfter();
|
m_cmds->updateSpritePositionAfter();
|
||||||
|
const SpritePosition sprPos = m_cmds->spritePositionAfterExecute();
|
||||||
|
|
||||||
m_undo->add(m_cmds);
|
m_undo->add(m_cmds);
|
||||||
m_cmds = nullptr;
|
m_cmds = nullptr;
|
||||||
|
|
||||||
@ -96,6 +100,23 @@ void Transaction::commit()
|
|||||||
m_doc->resetTransformation();
|
m_doc->resetTransformation();
|
||||||
m_doc->generateMaskBoundaries();
|
m_doc->generateMaskBoundaries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_UI
|
||||||
|
if (int(m_changes) & int(Changes::kColorChange)) {
|
||||||
|
ASSERT(m_doc);
|
||||||
|
ASSERT(m_doc->sprite());
|
||||||
|
|
||||||
|
Palette* pal = m_doc->sprite()->palette(sprPos.frame());
|
||||||
|
ASSERT(pal);
|
||||||
|
if (pal)
|
||||||
|
set_current_palette(pal, false);
|
||||||
|
else
|
||||||
|
set_current_palette(nullptr, false);
|
||||||
|
|
||||||
|
if (m_ctx->isUIAvailable())
|
||||||
|
ui::Manager::getDefault()->invalidate();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transaction::rollbackAndStartAgain()
|
void Transaction::rollbackAndStartAgain()
|
||||||
@ -141,4 +162,14 @@ void Transaction::onSelectionChanged(DocEvent& ev)
|
|||||||
m_changes = Changes(int(m_changes) | int(Changes::kSelection));
|
m_changes = Changes(int(m_changes) | int(Changes::kSelection));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transaction::onColorSpaceChanged(DocEvent& ev)
|
||||||
|
{
|
||||||
|
m_changes = Changes(int(m_changes) | int(Changes::kColorChange));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transaction::onPaletteChanged(DocEvent& ev)
|
||||||
|
{
|
||||||
|
m_changes = Changes(int(m_changes) | int(Changes::kColorChange));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -31,6 +31,11 @@ namespace app {
|
|||||||
// whole operation if something fails (e.g. an exceptions is thrown)
|
// whole operation if something fails (e.g. an exceptions is thrown)
|
||||||
// in the middle of the procedure.
|
// in the middle of the procedure.
|
||||||
//
|
//
|
||||||
|
// This class is a DocObserver because it listen and accumulates the
|
||||||
|
// changes in the Doc (m_changes), and when the transaction ends, it
|
||||||
|
// processes those changes as UI updates (so widgets are
|
||||||
|
// invalidated/updated correctly to show the new Doc state).
|
||||||
|
//
|
||||||
// You have to wrap every call to an transaction with a
|
// You have to wrap every call to an transaction with a
|
||||||
// ContextWriter. The preferred usage is as follows:
|
// ContextWriter. The preferred usage is as follows:
|
||||||
//
|
//
|
||||||
@ -79,13 +84,21 @@ namespace app {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// List of changes during the execution of this transaction
|
// List of changes during the execution of this transaction
|
||||||
enum class Changes { kNone = 0,
|
enum class Changes {
|
||||||
kSelection = 1 };
|
kNone = 0,
|
||||||
|
// The selection has changed so we have to re-generate the
|
||||||
|
// boundary segments.
|
||||||
|
kSelection = 1,
|
||||||
|
// The color palette or color space has changed.
|
||||||
|
kColorChange = 2
|
||||||
|
};
|
||||||
|
|
||||||
void rollback(CmdTransaction* newCmds);
|
void rollback(CmdTransaction* newCmds);
|
||||||
|
|
||||||
// DocObserver impl
|
// DocObserver impl
|
||||||
void onSelectionChanged(DocEvent& ev) override;
|
void onSelectionChanged(DocEvent& ev) override;
|
||||||
|
void onColorSpaceChanged(DocEvent& ev) override;
|
||||||
|
void onPaletteChanged(DocEvent& ev) override;
|
||||||
|
|
||||||
Context* m_ctx;
|
Context* m_ctx;
|
||||||
Doc* m_doc;
|
Doc* m_doc;
|
||||||
|
@ -633,9 +633,6 @@ void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& act
|
|||||||
catch (base::Exception& e) {
|
catch (base::Exception& e) {
|
||||||
Console::showException(e);
|
Console::showException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_current_palette(newPalette, false);
|
|
||||||
manager()->invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::setTransparentIndex(int index)
|
void ColorBar::setTransparentIndex(int index)
|
||||||
|
@ -125,9 +125,10 @@ void UIContext::setActiveView(DocView* docView)
|
|||||||
m_lastSelectedView = docView;
|
m_lastSelectedView = docView;
|
||||||
|
|
||||||
// TODO all the calls to functions like updateUsingEditor(),
|
// TODO all the calls to functions like updateUsingEditor(),
|
||||||
// setPixelFormat(), app_refresh_screen(), updateDisplayTitleBar()
|
// setPixelFormat(), app_refresh_screen(), updateDisplayTitleBar(),
|
||||||
// Can be replaced with a ContextObserver listening to the
|
// etc. could be replaced with the Transaction class, which is a
|
||||||
// onActiveSiteChange() event.
|
// DocObserver and handles updates on the screen processing the
|
||||||
|
// observed changes.
|
||||||
notifyActiveSiteChanged();
|
notifyActiveSiteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user