mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-01 10:13:22 +00:00
Fix some problems updating the StatusBar cel opacity slider
Now the StatusBar observes changes in the cel opacity to update the slider (e.g. when we change the cel opacity through Cel > Properties menu, the StatusBar refresh its slider).
This commit is contained in:
parent
a90a70bd1e
commit
23a4cb3a0b
@ -20,6 +20,7 @@
|
||||
#include "doc/cel.h"
|
||||
#include "doc/cels_range.h"
|
||||
#include "doc/document.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/sprite.h"
|
||||
@ -124,6 +125,11 @@ void SetPixelFormat::setFormat(PixelFormat format)
|
||||
// Regenerate extras
|
||||
static_cast<app::Document*>(sprite->document())
|
||||
->destroyExtraCel();
|
||||
|
||||
// Generate notification
|
||||
DocumentEvent ev(sprite->document());
|
||||
ev.sprite(sprite);
|
||||
sprite->document()->notifyObservers<DocumentEvent&>(&DocumentObserver::onPixelFormatChanged, ev);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "app/util/range_utils.h"
|
||||
#include "base/bind.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
@ -137,7 +138,7 @@ StatusBar* StatusBar::m_instance = NULL;
|
||||
StatusBar::StatusBar()
|
||||
: Widget(statusbar_type())
|
||||
, m_color(app::Color::fromMask())
|
||||
, m_hasDoc(false)
|
||||
, m_doc(nullptr)
|
||||
{
|
||||
m_instance = this;
|
||||
|
||||
@ -172,7 +173,7 @@ StatusBar::StatusBar()
|
||||
setup_mini_look(m_newFrame);
|
||||
setup_mini_look(m_slider);
|
||||
|
||||
m_slider->Change.connect(Bind<void>(&StatusBar::onCelOpacityChange, this));
|
||||
m_slider->Change.connect(Bind<void>(&StatusBar::onCelOpacitySliderChange, this));
|
||||
m_slider->setMinSize(gfx::Size(ui::display_w()/5, 0));
|
||||
|
||||
box1->setBorder(gfx::Border(2, 1, 2, 2)*guiscale());
|
||||
@ -199,10 +200,12 @@ StatusBar::StatusBar()
|
||||
Bind<void>(&StatusBar::onCurrentToolChange, this));
|
||||
|
||||
UIContext::instance()->addObserver(this);
|
||||
UIContext::instance()->documents().addObserver(this);
|
||||
}
|
||||
|
||||
StatusBar::~StatusBar()
|
||||
{
|
||||
UIContext::instance()->documents().removeObserver(this);
|
||||
UIContext::instance()->removeObserver(this);
|
||||
|
||||
delete m_tipwindow; // widget
|
||||
@ -334,7 +337,7 @@ void StatusBar::onResize(ResizeEvent& ev)
|
||||
rc.x += rc.w - prefWidth - border.right() - toolBarWidth;
|
||||
rc.w = prefWidth;
|
||||
|
||||
m_commandsBox->setVisible(true && m_hasDoc);
|
||||
m_commandsBox->setVisible(m_doc != nullptr);
|
||||
m_commandsBox->setBounds(rc);
|
||||
}
|
||||
else
|
||||
@ -421,7 +424,7 @@ bool StatusBar::CustomizedTipWindow::onProcessMessage(Message* msg)
|
||||
return ui::TipWindow::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void StatusBar::onCelOpacityChange()
|
||||
void StatusBar::onCelOpacitySliderChange()
|
||||
{
|
||||
try {
|
||||
ContextWriter writer(UIContext::instance(), 500);
|
||||
@ -449,8 +452,20 @@ void StatusBar::onCelOpacityChange()
|
||||
|
||||
void StatusBar::onActiveSiteChange(const doc::Site& site)
|
||||
{
|
||||
if (m_doc && site.document() != m_doc) {
|
||||
m_doc->removeObserver(this);
|
||||
m_doc = nullptr;
|
||||
}
|
||||
|
||||
if (site.document() && site.sprite()) {
|
||||
m_hasDoc = true;
|
||||
if (!m_doc) {
|
||||
m_doc = const_cast<doc::Document*>(site.document());
|
||||
m_doc->addObserver(this);
|
||||
}
|
||||
else {
|
||||
ASSERT(m_doc == site.document());
|
||||
}
|
||||
|
||||
m_commandsBox->setVisible(true);
|
||||
|
||||
// Current frame
|
||||
@ -472,11 +487,38 @@ void StatusBar::onActiveSiteChange(const doc::Site& site)
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_hasDoc = false;
|
||||
ASSERT(m_doc == nullptr);
|
||||
m_commandsBox->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::onRemoveDocument(doc::Document* doc)
|
||||
{
|
||||
if (m_doc &&
|
||||
m_doc == doc) {
|
||||
m_doc->removeObserver(this);
|
||||
m_doc = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::onCelOpacityChanged(doc::DocumentEvent& ev)
|
||||
{
|
||||
ASSERT(m_doc);
|
||||
ASSERT(m_doc == const_cast<doc::Document*>(ev.document()));
|
||||
ASSERT(ev.cel());
|
||||
|
||||
if (m_doc &&
|
||||
m_doc == const_cast<doc::Document*>(ev.document()) &&
|
||||
ev.cel()) {
|
||||
m_slider->setValue(MID(0, ev.cel()->opacity(), 255));
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::onPixelFormatChanged(DocumentEvent& ev)
|
||||
{
|
||||
onActiveSiteChange(UIContext::instance()->activeSite());
|
||||
}
|
||||
|
||||
void StatusBar::newFrame()
|
||||
{
|
||||
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::NewFrame);
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "app/color.h"
|
||||
#include "base/observers.h"
|
||||
#include "doc/context_observer.h"
|
||||
#include "doc/document_observer.h"
|
||||
#include "doc/documents_observer.h"
|
||||
#include "doc/layer_index.h"
|
||||
#include "ui/base.h"
|
||||
#include "ui/widget.h"
|
||||
@ -38,7 +40,9 @@ namespace app {
|
||||
}
|
||||
|
||||
class StatusBar : public ui::Widget
|
||||
, public doc::ContextObserver {
|
||||
, public doc::ContextObserver
|
||||
, public doc::DocumentsObserver
|
||||
, public doc::DocumentObserver {
|
||||
static StatusBar* m_instance;
|
||||
public:
|
||||
static StatusBar* instance() { return m_instance; }
|
||||
@ -61,9 +65,16 @@ namespace app {
|
||||
// ContextObserver impl
|
||||
void onActiveSiteChange(const doc::Site& site) override;
|
||||
|
||||
// DocumentObservers impl
|
||||
void onRemoveDocument(doc::Document* doc) override;
|
||||
|
||||
// DocumentObserver impl
|
||||
void onCelOpacityChanged(doc::DocumentEvent& ev) override;
|
||||
void onPixelFormatChanged(DocumentEvent& ev) override;
|
||||
|
||||
private:
|
||||
void onCurrentToolChange();
|
||||
void onCelOpacityChange();
|
||||
void onCelOpacitySliderChange();
|
||||
void newFrame();
|
||||
|
||||
enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL };
|
||||
@ -84,7 +95,7 @@ namespace app {
|
||||
ui::Slider* m_slider; // Opacity slider
|
||||
ui::Entry* m_currentFrame; // Current frame and go to frame entry
|
||||
ui::Button* m_newFrame; // Button to create a new frame
|
||||
bool m_hasDoc;
|
||||
doc::Document* m_doc; // Document used to show the cel slider
|
||||
|
||||
// Tip window
|
||||
class CustomizedTipWindow;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2001-2014 David Capello
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -22,6 +22,8 @@ namespace doc {
|
||||
// anything in the document could be changed.
|
||||
virtual void onGeneralUpdate(DocumentEvent& ev) { }
|
||||
|
||||
virtual void onPixelFormatChanged(DocumentEvent& ev) { }
|
||||
|
||||
virtual void onAddLayer(DocumentEvent& ev) { }
|
||||
virtual void onAddFrame(DocumentEvent& ev) { }
|
||||
virtual void onAddCel(DocumentEvent& ev) { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user