Moved Transparent Color button to ContextBar

Implemented SelectionSettings class

Transparent Color button for moving pixels moved from status bar to
context bar.  Current Transparent Color stored by new SelectionSettings
class, retrievable from ISettings.

Also implemented Observer classes for existing Settings interfaces for
future use.

StatusBarObserver interface and supporting code removed from StatusBar.
This commit is contained in:
Joel Madigan 2013-11-29 15:59:28 -05:00
parent f531f6d0d0
commit 3ce805f63d
11 changed files with 288 additions and 140 deletions

View File

@ -50,7 +50,11 @@ namespace app {
virtual bool isExecutingMacro() const { return false; } virtual bool isExecutingMacro() const { return false; }
virtual bool isExecutingScript() const { return false; } virtual bool isExecutingScript() const { return false; }
ISettings* getSettings() { return m_settings; } // TODO Refactor codebase to use ISettings::settings() instead
ISettings* getSettings() {
return settings();
}
ISettings* settings() { return m_settings; }
const Documents& getDocuments() const; const Documents& getDocuments() const;

View File

@ -26,12 +26,18 @@
#include "raster/pen_type.h" #include "raster/pen_type.h"
namespace app { namespace app {
class ColorSwatches; class ColorSwatches;
class Document; class Document;
class IColorSwatchesStore; class IColorSwatchesStore;
class IDocumentSettings; class IDocumentSettings;
class IPenSettings; class IPenSettings;
class PenSettingsObserver;
class IToolSettings; class IToolSettings;
class ToolSettingsObserver;
class ISelectionSettings;
class SelectionSettingsObserver;
class GlobalSettingsObserver;
namespace tools { namespace tools {
class Tool; class Tool;
@ -61,7 +67,13 @@ namespace app {
// Specific configuration for the given tool. // Specific configuration for the given tool.
virtual IToolSettings* getToolSettings(tools::Tool* tool) = 0; virtual IToolSettings* getToolSettings(tools::Tool* tool) = 0;
// Specific configuration for the current selection
virtual ISelectionSettings* selection() = 0;
virtual IColorSwatchesStore* getColorSwatchesStore() = 0; virtual IColorSwatchesStore* getColorSwatchesStore() = 0;
virtual void addObserver(GlobalSettingsObserver* observer) = 0;
virtual void removeObserver(GlobalSettingsObserver *observer) = 0;
}; };
// Tool's settings // Tool's settings
@ -86,6 +98,9 @@ namespace app {
virtual void setSprayWidth(int width) = 0; virtual void setSprayWidth(int width) = 0;
virtual void setSpraySpeed(int speed) = 0; virtual void setSpraySpeed(int speed) = 0;
virtual void setInkType(InkType inkType) = 0; virtual void setInkType(InkType inkType) = 0;
virtual void addObserver(ToolSettingsObserver* observer) = 0;
virtual void removeObserver(ToolSettingsObserver *observer) = 0;
}; };
// Settings for a tool's pen // Settings for a tool's pen
@ -100,6 +115,22 @@ namespace app {
virtual void setType(PenType type) = 0; virtual void setType(PenType type) = 0;
virtual void setSize(int size) = 0; virtual void setSize(int size) = 0;
virtual void setAngle(int angle) = 0; virtual void setAngle(int angle) = 0;
virtual void addObserver(PenSettingsObserver* observer) = 0;
virtual void removeObserver(PenSettingsObserver *observer) = 0;
};
class ISelectionSettings {
public:
virtual ~ISelectionSettings() {}
// Mask color used during a move operation
virtual app::Color getMoveTransparentColor() = 0;
virtual void setMoveTransparentColor(app::Color color) = 0;
virtual void addObserver(SelectionSettingsObserver* observer) = 0;
virtual void removeObserver(SelectionSettingsObserver* observer) = 0;
}; };
class IColorSwatchesStore { class IColorSwatchesStore {

View File

@ -0,0 +1,78 @@
/* Aseprite
* Copyright (C) 2001-2013 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED
#define APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED
#include "app/color.h"
#include "app/settings/ink_type.h"
#include "raster/pen_type.h"
namespace app {
namespace tools {
class Tool;
}
class ColorSwatches;
class PenSettingsObserver
{
public:
virtual ~PenSettingsObserver() {}
virtual void onSetPenSize(int newSize) {}
virtual void onSetPenType(raster::PenType newType) {}
virtual void onSetPenAngle(int newAngle) {}
};
class ToolSettingsObserver
{
public:
virtual ~ToolSettingsObserver() {}
virtual void onSetOpacity(int newOpacity) {}
virtual void onSetTolerance(int newTolerance) {}
virtual void onSetFilled(bool filled) {}
virtual void onSetPreviewFilled(bool previewFilled) {}
virtual void onSetSprayWidth(int newSprayWidth) {}
virtual void onSetSpraySpeed(int newSpraySpeed) {}
virtual void onSetInkType(InkType newInkType) {}
};
class SelectionSettingsObserver
{
public:
virtual ~SelectionSettingsObserver() {}
virtual void onSetMoveTransparentColor(app::Color newColor) {}
};
class GlobalSettingsObserver
{
public:
virtual ~GlobalSettingsObserver() {}
virtual void onSetFgColor(app::Color newColor) {}
virtual void onSetBgColor(app::Color newColor) {}
virtual void onSetCurrentTool(tools::Tool* newTool) {}
virtual void onSetColorSwatches(ColorSwatches* swaches) {}
};
} // namespace app
#endif // APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED

View File

@ -30,9 +30,7 @@
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/main_window.h" #include "base/observable.h"
#include "app/ui/workspace.h"
#include "app/ui_context.h"
#include "ui/manager.h" #include "ui/manager.h"
#include <algorithm> #include <algorithm>
@ -149,6 +147,7 @@ UISettingsImpl::UISettingsImpl()
: m_currentTool(NULL) : m_currentTool(NULL)
, m_globalDocumentSettings(new UIDocumentSettingsImpl) , m_globalDocumentSettings(new UIDocumentSettingsImpl)
, m_colorSwatches(NULL) , m_colorSwatches(NULL)
, m_selectionSettings(new SelectionSettings)
{ {
m_colorSwatches = new app::ColorSwatches("Default"); m_colorSwatches = new app::ColorSwatches("Default");
for (size_t i=0; i<16; ++i) for (size_t i=0; i<16; ++i)
@ -230,6 +229,7 @@ void UISettingsImpl::setCurrentTool(tools::Tool* tool)
void UISettingsImpl::setColorSwatches(app::ColorSwatches* colorSwatches) void UISettingsImpl::setColorSwatches(app::ColorSwatches* colorSwatches)
{ {
m_colorSwatches = colorSwatches; m_colorSwatches = colorSwatches;
notifyObservers<app::ColorSwatches*>(&GlobalSettingsObserver::onSetColorSwatches, colorSwatches);
} }
IDocumentSettings* UISettingsImpl::getDocumentSettings(const Document* document) IDocumentSettings* UISettingsImpl::getDocumentSettings(const Document* document)
@ -260,6 +260,14 @@ void UISettingsImpl::removeColorSwatches(app::ColorSwatches* colorSwatches)
m_colorSwatchesStore.erase(it); m_colorSwatchesStore.erase(it);
} }
void UISettingsImpl::addObserver(GlobalSettingsObserver* observer) {
base::Observable<GlobalSettingsObserver>::addObserver(observer);
}
void UISettingsImpl::removeObserver(GlobalSettingsObserver* observer) {
base::Observable<GlobalSettingsObserver>::addObserver(observer);
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// IDocumentSettings implementation // IDocumentSettings implementation
@ -408,7 +416,10 @@ void UIDocumentSettingsImpl::setOnionskinOpacityStep(int step)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Tools & pen settings // Tools & pen settings
class UIPenSettingsImpl : public IPenSettings { class UIPenSettingsImpl
: public IPenSettings
, public base::Observable<PenSettingsObserver> {
private:
PenType m_type; PenType m_type;
int m_size; int m_size;
int m_angle; int m_angle;
@ -434,6 +445,7 @@ public:
void setType(PenType type) void setType(PenType type)
{ {
m_type = MID(PEN_TYPE_FIRST, type, PEN_TYPE_LAST); m_type = MID(PEN_TYPE_FIRST, type, PEN_TYPE_LAST);
notifyObservers<PenType>(&PenSettingsObserver::onSetPenType, m_type);
} }
void setSize(int size) void setSize(int size)
@ -448,6 +460,7 @@ public:
// Trigger PenSizeAfterChange signal // Trigger PenSizeAfterChange signal
if (m_fireSignals) if (m_fireSignals)
App::instance()->PenSizeAfterChange(); App::instance()->PenSizeAfterChange();
notifyObservers<int>(&PenSettingsObserver::onSetPenSize, m_size);
} }
void setAngle(int angle) void setAngle(int angle)
@ -468,9 +481,18 @@ public:
m_fireSignals = state; m_fireSignals = state;
} }
void addObserver(PenSettingsObserver* observer) OVERRIDE{
base::Observable<PenSettingsObserver>::addObserver(observer);
}
void removeObserver(PenSettingsObserver* observer) OVERRIDE{
base::Observable<PenSettingsObserver>::addObserver(observer);
}
}; };
class UIToolSettingsImpl : public IToolSettings { class UIToolSettingsImpl
: public IToolSettings
, base::Observable<ToolSettingsObserver> {
tools::Tool* m_tool; tools::Tool* m_tool;
UIPenSettingsImpl m_pen; UIPenSettingsImpl m_pen;
int m_opacity; int m_opacity;
@ -550,6 +572,14 @@ public:
void setSpraySpeed(int speed) OVERRIDE { m_spray_speed = speed; } void setSpraySpeed(int speed) OVERRIDE { m_spray_speed = speed; }
void setInkType(InkType inkType) OVERRIDE { m_inkType = inkType; } void setInkType(InkType inkType) OVERRIDE { m_inkType = inkType; }
void addObserver(ToolSettingsObserver* observer) OVERRIDE {
base::Observable<ToolSettingsObserver>::addObserver(observer);
}
void removeObserver(ToolSettingsObserver* observer) OVERRIDE{
base::Observable<ToolSettingsObserver>::removeObserver(observer);
}
private: private:
std::string getCfgSection() const { std::string getCfgSection() const {
return std::string("Tool:") + m_tool->getId(); return std::string("Tool:") + m_tool->getId();
@ -573,4 +603,41 @@ IToolSettings* UISettingsImpl::getToolSettings(tools::Tool* tool)
} }
} }
//////////////////////////////////////////////////////////////////////
// Selection Settings
SelectionSettings::SelectionSettings() : m_moveTransparentColor(app::Color::fromMask())
{
}
SelectionSettings::~SelectionSettings()
{
}
ISelectionSettings* UISettingsImpl::selection()
{
return m_selectionSettings;
}
void SelectionSettings::setMoveTransparentColor(app::Color color)
{
m_moveTransparentColor = color;
notifyObservers(&SelectionSettingsObserver::onSetMoveTransparentColor, color);
}
app::Color SelectionSettings::getMoveTransparentColor()
{
return m_moveTransparentColor;
}
void SelectionSettings::addObserver(SelectionSettingsObserver* observer)
{
base::Observable<SelectionSettingsObserver>::addObserver(observer);
}
void SelectionSettings::removeObserver(SelectionSettingsObserver* observer)
{
base::Observable<SelectionSettingsObserver>::removeObserver(observer);
}
} // namespace app } // namespace app

View File

@ -23,13 +23,17 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/compiler_specific.h"
#include "app/settings/settings.h" #include "app/settings/settings.h"
#include "app/settings/settings_observers.h"
#include "base/compiler_specific.h"
#include "base/observable.h"
namespace app { namespace app {
class UISettingsImpl : public ISettings, class UISettingsImpl
public IColorSwatchesStore { : public ISettings
, public IColorSwatchesStore
, base::Observable<GlobalSettingsObserver> {
public: public:
UISettingsImpl(); UISettingsImpl();
~UISettingsImpl(); ~UISettingsImpl();
@ -40,25 +44,51 @@ namespace app {
app::Color getBgColor() OVERRIDE; app::Color getBgColor() OVERRIDE;
tools::Tool* getCurrentTool() OVERRIDE; tools::Tool* getCurrentTool() OVERRIDE;
app::ColorSwatches* getColorSwatches() OVERRIDE; app::ColorSwatches* getColorSwatches() OVERRIDE;
void setFgColor(const app::Color& color) OVERRIDE; void setFgColor(const app::Color& color) OVERRIDE;
void setBgColor(const app::Color& color) OVERRIDE; void setBgColor(const app::Color& color) OVERRIDE;
void setCurrentTool(tools::Tool* tool) OVERRIDE; void setCurrentTool(tools::Tool* tool) OVERRIDE;
void setColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE; void setColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE;
IDocumentSettings* getDocumentSettings(const Document* document) OVERRIDE; IDocumentSettings* getDocumentSettings(const Document* document) OVERRIDE;
IToolSettings* getToolSettings(tools::Tool* tool) OVERRIDE; IToolSettings* getToolSettings(tools::Tool* tool) OVERRIDE;
IColorSwatchesStore* getColorSwatchesStore() OVERRIDE; IColorSwatchesStore* getColorSwatchesStore() OVERRIDE;
ISelectionSettings* selection() OVERRIDE;
// IColorSwatchesStore implementation // IColorSwatchesStore implementation
void addColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE; void addColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE;
void removeColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE; void removeColorSwatches(app::ColorSwatches* colorSwatches) OVERRIDE;
void addObserver(GlobalSettingsObserver* observer) OVERRIDE;
void removeObserver(GlobalSettingsObserver* observer) OVERRIDE;
private: private:
tools::Tool* m_currentTool; tools::Tool* m_currentTool;
IDocumentSettings* m_globalDocumentSettings; IDocumentSettings* m_globalDocumentSettings;
std::map<std::string, IToolSettings*> m_toolSettings; std::map<std::string, IToolSettings*> m_toolSettings;
app::ColorSwatches* m_colorSwatches; app::ColorSwatches* m_colorSwatches;
std::vector<app::ColorSwatches*> m_colorSwatchesStore; std::vector<app::ColorSwatches*> m_colorSwatchesStore;
ISelectionSettings* m_selectionSettings;
};
class SelectionSettings
: public ISelectionSettings
, public base::Observable<SelectionSettingsObserver> {
public:
SelectionSettings();
~SelectionSettings();
void setMoveTransparentColor(app::Color color);
app::Color getMoveTransparentColor();
void addObserver(SelectionSettingsObserver* observer);
void removeObserver(SelectionSettingsObserver* observer);
private:
app::Color m_moveTransparentColor;
}; };
} // namespace app } // namespace app

View File

@ -26,12 +26,15 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/settings/ink_type.h" #include "app/settings/ink_type.h"
#include "app/settings/settings.h" #include "app/settings/settings.h"
#include "app/settings/settings_observers.h"
#include "app/tools/ink.h" #include "app/tools/ink.h"
#include "app/tools/point_shape.h" #include "app/tools/point_shape.h"
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/ui/button_set.h" #include "app/ui/button_set.h"
#include "app/ui/color_button.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/bind.h"
#include "base/unique_ptr.h" #include "base/unique_ptr.h"
#include "raster/conversion_alleg.h" #include "raster/conversion_alleg.h"
#include "raster/image.h" #include "raster/image.h"
@ -336,6 +339,20 @@ protected:
} }
}; };
class ContextBar::TransparentColorField : public ColorButton
{
public:
TransparentColorField() : ColorButton(app::Color::fromMask(), IMAGE_RGB) {
Change.connect(Bind<void>(&TransparentColorField::onChange, this));
}
protected:
void onChange() {
UIContext::instance()->settings()->selection()->setMoveTransparentColor(getColor());
}
};
ContextBar::ContextBar() ContextBar::ContextBar()
: Box(JI_HORIZONTAL) : Box(JI_HORIZONTAL)
{ {
@ -366,6 +383,10 @@ ContextBar::ContextBar()
m_sprayBox->addChild(m_sprayWidth = new SprayWidthField()); m_sprayBox->addChild(m_sprayWidth = new SprayWidthField());
m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField()); m_sprayBox->addChild(m_spraySpeed = new SpraySpeedField());
addChild(m_selectionOptionsBox = new HBox());
m_selectionOptionsBox->addChild(new Label("Transparent Color:"));
m_selectionOptionsBox->addChild(m_transparentColor = new TransparentColorField);
TooltipManager* tooltipManager = new TooltipManager(); TooltipManager* tooltipManager = new TooltipManager();
addChild(tooltipManager); addChild(tooltipManager);
@ -375,6 +396,7 @@ ContextBar::ContextBar()
tooltipManager->addTooltipFor(m_inkOpacity, "Opacity (Alpha value in RGBA)", JI_CENTER | JI_BOTTOM); tooltipManager->addTooltipFor(m_inkOpacity, "Opacity (Alpha value in RGBA)", JI_CENTER | JI_BOTTOM);
tooltipManager->addTooltipFor(m_sprayWidth, "Spray Width", JI_CENTER | JI_BOTTOM); tooltipManager->addTooltipFor(m_sprayWidth, "Spray Width", JI_CENTER | JI_BOTTOM);
tooltipManager->addTooltipFor(m_spraySpeed, "Spray Speed", JI_CENTER | JI_BOTTOM); tooltipManager->addTooltipFor(m_spraySpeed, "Spray Speed", JI_CENTER | JI_BOTTOM);
tooltipManager->addTooltipFor(m_transparentColor, "Transparent Color", JI_BOTTOM | JI_BOTTOM);
App::instance()->PenSizeAfterChange.connect(&ContextBar::onPenSizeChange, this); App::instance()->PenSizeAfterChange.connect(&ContextBar::onPenSizeChange, this);
App::instance()->PenAngleAfterChange.connect(&ContextBar::onPenAngleChange, this); App::instance()->PenAngleAfterChange.connect(&ContextBar::onPenAngleChange, this);
@ -451,6 +473,9 @@ void ContextBar::onCurrentToolChange()
bool hasSprayOptions = (currentTool->getPointShape(0)->isSpray() || bool hasSprayOptions = (currentTool->getPointShape(0)->isSpray() ||
currentTool->getPointShape(1)->isSpray()); currentTool->getPointShape(1)->isSpray());
bool hasSelectOptions = (currentTool->getInk(0)->isSelection() ||
currentTool->getInk(1)->isSelection());
// Show/Hide fields // Show/Hide fields
m_brushLabel->setVisible(hasOpacity); m_brushLabel->setVisible(hasOpacity);
m_brushType->setVisible(hasOpacity); m_brushType->setVisible(hasOpacity);
@ -463,6 +488,7 @@ void ContextBar::onCurrentToolChange()
m_toleranceLabel->setVisible(hasTolerance); m_toleranceLabel->setVisible(hasTolerance);
m_tolerance->setVisible(hasTolerance); m_tolerance->setVisible(hasTolerance);
m_sprayBox->setVisible(hasSprayOptions); m_sprayBox->setVisible(hasSprayOptions);
m_selectionOptionsBox->setVisible(hasSelectOptions);
layout(); layout();
} }

View File

@ -50,6 +50,7 @@ namespace app {
class InkOpacityField; class InkOpacityField;
class SprayWidthField; class SprayWidthField;
class SpraySpeedField; class SpraySpeedField;
class TransparentColorField;
ui::Label* m_brushLabel; ui::Label* m_brushLabel;
BrushTypeField* m_brushType; BrushTypeField* m_brushType;
@ -64,6 +65,8 @@ namespace app {
ui::Box* m_sprayBox; ui::Box* m_sprayBox;
SprayWidthField* m_sprayWidth; SprayWidthField* m_sprayWidth;
SpraySpeedField* m_spraySpeed; SpraySpeedField* m_spraySpeed;
ui::Box* m_selectionOptionsBox;
TransparentColorField* m_transparentColor;
}; };
} // namespace app } // namespace app

View File

@ -28,6 +28,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/commands/commands.h" #include "app/commands/commands.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h" #include "app/tools/ink.h"
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
@ -63,6 +64,8 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo
// pixels movement/transformation preview. // pixels movement/transformation preview.
//ASSERT(!editor->getCurrentEditorTool()->getInk(0)->isSelection()); //ASSERT(!editor->getCurrentEditorTool()->getInk(0)->isSelection());
UIContext* context = UIContext::instance();
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
m_pixelsMovement = pixelsMovement; m_pixelsMovement = pixelsMovement;
@ -75,19 +78,15 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo
} }
// Setup mask color // Setup mask color
setTransparentColor(StatusBar::instance()->getTransparentColor()); setTransparentColor(context->settings()->selection()->getMoveTransparentColor());
// Add this class as: // Add this class as:
// - observer of the UI context: so we know if the user wants to // - observer of the UI context: so we know if the user wants to
// execute other command, so we can drop pixels. // execute other command, so we can drop pixels.
// - observer of the status bar to know if the user has changed the // - observer of SelectionSettings to be informed of changes to Transparent Color
// transparent color. // changes from Context Bar.
UIContext::instance()->addObserver(this); context->addObserver(this);
StatusBar::instance()->addObserver(this); context->settings()->selection()->addObserver(this);
// Show controls to modify the "pixels movement" options (e.g. the
// transparent color).
StatusBar::instance()->showMovePixelsOptions();
// Add the current editor as filter for key message of the manager // Add the current editor as filter for key message of the manager
// so we can catch the Enter key, and avoid to execute the // so we can catch the Enter key, and avoid to execute the
@ -99,7 +98,7 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo
MovingPixelsState::~MovingPixelsState() MovingPixelsState::~MovingPixelsState()
{ {
UIContext::instance()->removeObserver(this); UIContext::instance()->removeObserver(this);
StatusBar::instance()->removeObserver(this); UIContext::instance()->settings()->selection()->removeObserver(this);
delete m_pixelsMovement; delete m_pixelsMovement;
@ -128,7 +127,6 @@ EditorState::BeforeChangeAction MovingPixelsState::onBeforeChangeState(Editor* e
editor->releaseMouse(); editor->releaseMouse();
StatusBar::instance()->hideMovePixelsOptions();
return DiscardState; return DiscardState;
} }
else { else {
@ -375,7 +373,7 @@ bool MovingPixelsState::onUpdateStatusBar(Editor* editor)
gfx::Size imageSize = m_pixelsMovement->getInitialImageSize(); gfx::Size imageSize = m_pixelsMovement->getInitialImageSize();
StatusBar::instance()->setStatusText StatusBar::instance()->setStatusText
(100, "Pos %d %d, Size %d %d, Orig: %3d %3d (%.02f%% %.02f%%), Angle %.1f", (100, "Moving Pixels - Pos %d %d, Size %d %d, Orig: %3d %3d (%.02f%% %.02f%%), Angle %.1f",
transform.bounds().x, transform.bounds().y, transform.bounds().x, transform.bounds().y,
transform.bounds().w, transform.bounds().h, transform.bounds().w, transform.bounds().h,
imageSize.w, imageSize.h, imageSize.w, imageSize.h,
@ -393,14 +391,9 @@ void MovingPixelsState::onCommandBeforeExecution(Context* context)
dropPixels(m_currentEditor); dropPixels(m_currentEditor);
} }
void MovingPixelsState::dispose() void MovingPixelsState::onSetMoveTransparentColor(app::Color newColor)
{
// Never called as MovingPixelsState is removed automatically as
// StatusBar's observer.
}
void MovingPixelsState::onChangeTransparentColor(const app::Color& color)
{ {
app::Color color = UIContext::instance()->settings()->selection()->getMoveTransparentColor();
setTransparentColor(color); setTransparentColor(color);
} }

View File

@ -20,8 +20,10 @@
#define APP_UI_EDITOR_MOVING_PIXELS_STATE_H_INCLUDED #define APP_UI_EDITOR_MOVING_PIXELS_STATE_H_INCLUDED
#include "app/context_observer.h" #include "app/context_observer.h"
#include "app/settings/settings_observers.h"
#include "app/ui/editor/handle_type.h" #include "app/ui/editor/handle_type.h"
#include "app/ui/editor/standby_state.h" #include "app/ui/editor/standby_state.h"
#include "app/ui/context_bar.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
@ -33,7 +35,10 @@ namespace app {
class Editor; class Editor;
class PixelsMovement; class PixelsMovement;
class MovingPixelsState : public StandbyState, StatusBarObserver, ContextObserver { class MovingPixelsState
: public StandbyState
, ContextObserver
, SelectionSettingsObserver {
public: public:
MovingPixelsState(Editor* editor, ui::MouseMessage* msg, PixelsMovement* pixelsMovement, HandleType handle); MovingPixelsState(Editor* editor, ui::MouseMessage* msg, PixelsMovement* pixelsMovement, HandleType handle);
virtual ~MovingPixelsState(); virtual ~MovingPixelsState();
@ -53,12 +58,11 @@ namespace app {
// ContextObserver // ContextObserver
virtual void onCommandBeforeExecution(Context* context) OVERRIDE; virtual void onCommandBeforeExecution(Context* context) OVERRIDE;
// SettingsObserver
virtual void onSetMoveTransparentColor(app::Color newColor) OVERRIDE;
virtual gfx::Transformation getTransformation(Editor* editor) OVERRIDE; virtual gfx::Transformation getTransformation(Editor* editor) OVERRIDE;
protected:
// StatusBarObserver interface
virtual void dispose() OVERRIDE;
virtual void onChangeTransparentColor(const app::Color& color) OVERRIDE;
private: private:
void setTransparentColor(const app::Color& color); void setTransparentColor(const app::Color& color);

View File

@ -240,22 +240,6 @@ StatusBar::StatusBar()
m_notificationsBox = box1; m_notificationsBox = box1;
} }
// Construct move-pixels box
{
Box* filler = new Box(JI_HORIZONTAL);
filler->setExpansive(true);
m_movePixelsBox = new Box(JI_HORIZONTAL);
m_transparentLabel = new Label("Transparent Color:");
m_transparentColor = new ColorButton(app::Color::fromMask(), IMAGE_RGB);
m_movePixelsBox->addChild(filler);
m_movePixelsBox->addChild(m_transparentLabel);
m_movePixelsBox->addChild(m_transparentColor);
m_transparentColor->Change.connect(Bind<void>(&StatusBar::onTransparentColorChange, this));
}
addChild(m_notificationsBox); addChild(m_notificationsBox);
App::instance()->CurrentToolChange.connect(&StatusBar::onCurrentToolChange, this); App::instance()->CurrentToolChange.connect(&StatusBar::onCurrentToolChange, this);
@ -267,21 +251,10 @@ StatusBar::~StatusBar()
delete *it; delete *it;
delete m_tipwindow; // widget delete m_tipwindow; // widget
delete m_movePixelsBox;
delete m_commandsBox; delete m_commandsBox;
delete m_notificationsBox; delete m_notificationsBox;
} }
void StatusBar::addObserver(StatusBarObserver* observer)
{
m_observers.addObserver(observer);
}
void StatusBar::removeObserver(StatusBarObserver* observer)
{
m_observers.removeObserver(observer);
}
void StatusBar::onCurrentToolChange() void StatusBar::onCurrentToolChange()
{ {
if (isVisible()) { if (isVisible()) {
@ -293,12 +266,6 @@ void StatusBar::onCurrentToolChange()
} }
} }
void StatusBar::onTransparentColorChange()
{
m_observers.notifyObservers<const app::Color&>(&StatusBarObserver::onChangeTransparentColor,
getTransparentColor());
}
void StatusBar::clearText() void StatusBar::clearText()
{ {
setStatusText(1, ""); setStatusText(1, "");
@ -397,27 +364,6 @@ void StatusBar::showTool(int msecs, tools::Tool* tool)
} }
} }
void StatusBar::showMovePixelsOptions()
{
if (!hasChild(m_movePixelsBox)) {
addChild(m_movePixelsBox);
invalidate();
}
}
void StatusBar::hideMovePixelsOptions()
{
if (hasChild(m_movePixelsBox)) {
removeChild(m_movePixelsBox);
invalidate();
}
}
app::Color StatusBar::getTransparentColor()
{
return m_transparentColor->getColor();
}
void StatusBar::showNotification(const char* text, const char* link) void StatusBar::showNotification(const char* text, const char* link)
{ {
m_linkLabel->setText(text); m_linkLabel->setText(text);
@ -575,8 +521,7 @@ bool StatusBar::onProcessMessage(Message* msg)
x -= width+4; x -= width+4;
} }
} }
// Show layers only when we are not moving pixels else {
else if (!hasChild(m_movePixelsBox)) {
// Available width for layers buttons // Available width for layers buttons
int width = rc.w/4; int width = rc.w/4;
@ -654,29 +599,28 @@ bool StatusBar::onProcessMessage(Message* msg)
const Document* document = UIContext::instance()->getActiveDocument(); const Document* document = UIContext::instance()->getActiveDocument();
bool state = (document != NULL); bool state = (document != NULL);
if (!hasChild(m_movePixelsBox)) { if (state && !hasChild(m_commandsBox)) {
if (state && !hasChild(m_commandsBox)) { updateCurrentFrame();
updateCurrentFrame();
m_b_first->setEnabled(state); m_b_first->setEnabled(state);
m_b_prev->setEnabled(state); m_b_prev->setEnabled(state);
m_b_play->setEnabled(state); m_b_play->setEnabled(state);
m_b_next->setEnabled(state); m_b_next->setEnabled(state);
m_b_last->setEnabled(state); m_b_last->setEnabled(state);
updateFromLayer(); updateFromLayer();
if (hasChild(m_notificationsBox)) if (hasChild(m_notificationsBox))
removeChild(m_notificationsBox); removeChild(m_notificationsBox);
addChild(m_commandsBox); addChild(m_commandsBox);
invalidate(); invalidate();
}
else if (!state && !hasChild(m_notificationsBox)) {
addChild(m_notificationsBox);
invalidate();
}
} }
else if (!state && !hasChild(m_notificationsBox)) {
addChild(m_notificationsBox);
invalidate();
}
break; break;
} }
@ -798,12 +742,6 @@ void StatusBar::onResize(ResizeEvent& ev)
rc = ev.getBounds(); rc = ev.getBounds();
rc.w -= rc.w/4 + 4*jguiscale(); rc.w -= rc.w/4 + 4*jguiscale();
m_commandsBox->setBounds(rc); m_commandsBox->setBounds(rc);
rc = ev.getBounds();
Size reqSize = m_movePixelsBox->getPreferredSize();
rc.x = rc.x2() - reqSize.w;
rc.w = reqSize.w;
m_movePixelsBox->setBounds(rc);
} }
void StatusBar::onPreferredSize(PreferredSizeEvent& ev) void StatusBar::onPreferredSize(PreferredSizeEvent& ev)

View File

@ -39,7 +39,6 @@ namespace ui {
} }
namespace app { namespace app {
class ColorButton;
class StatusBar; class StatusBar;
namespace tools { namespace tools {
@ -61,15 +60,6 @@ namespace app {
double m_pos; double m_pos;
}; };
class StatusBarObserver {
public:
virtual ~StatusBarObserver() { }
virtual void dispose() = 0;
virtual void onChangeTransparentColor(const app::Color& color) = 0;
};
typedef base::Observers<StatusBarObserver> StatusBarObservers;
class StatusBar : public ui::Widget { class StatusBar : public ui::Widget {
static StatusBar* m_instance; static StatusBar* m_instance;
public: public:
@ -78,9 +68,6 @@ namespace app {
StatusBar(); StatusBar();
~StatusBar(); ~StatusBar();
void addObserver(StatusBarObserver* observer);
void removeObserver(StatusBarObserver* observer);
void clearText(); void clearText();
bool setStatusText(int msecs, const char *format, ...); bool setStatusText(int msecs, const char *format, ...);
@ -88,11 +75,6 @@ namespace app {
void showColor(int msecs, const char* text, const Color& color, int alpha); void showColor(int msecs, const char* text, const Color& color, int alpha);
void showTool(int msecs, tools::Tool* tool); void showTool(int msecs, tools::Tool* tool);
void showMovePixelsOptions();
void hideMovePixelsOptions();
Color getTransparentColor();
// Methods to add and remove progress bars // Methods to add and remove progress bars
Progress* addProgress(); Progress* addProgress();
void removeProgress(Progress* progress); void removeProgress(Progress* progress);
@ -107,7 +89,6 @@ namespace app {
private: private:
void onCurrentToolChange(); void onCurrentToolChange();
void onTransparentColorChange();
void updateFromLayer(); void updateFromLayer();
void updateCurrentFrame(); void updateCurrentFrame();
void newFrame(); void newFrame();
@ -144,18 +125,11 @@ namespace app {
ui::Widget* m_notificationsBox; ui::Widget* m_notificationsBox;
ui::LinkLabel* m_linkLabel; ui::LinkLabel* m_linkLabel;
// Box with move-pixels commands (when the user drag-and-drop selected pixels using the editor)
ui::Box* m_movePixelsBox;
ui::Widget* m_transparentLabel;
ColorButton* m_transparentColor;
// Tip window // Tip window
class CustomizedTipWindow; class CustomizedTipWindow;
CustomizedTipWindow* m_tipwindow; CustomizedTipWindow* m_tipwindow;
raster::LayerIndex m_hot_layer; raster::LayerIndex m_hot_layer;
StatusBarObservers m_observers;
}; };
} // namespace app } // namespace app