Skip to content

Commit

Permalink
Replace ISettings::get/setShowSpriteEditorScrollbars() with Preferenc…
Browse files Browse the repository at this point in the history
…es class
  • Loading branch information
dacap committed May 13, 2015
1 parent c42ca32 commit 70f8443
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/app/commands/cmd_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class OptionsWindow : public app::gen::Options {
if (m_preferences.experimental.flashLayer())
flashLayer()->setSelected(true);

if (m_settings->getShowSpriteEditorScrollbars())
if (m_preferences.editor.showScrollbars())
showScrollbars()->setSelected(true);

// Scope
Expand Down Expand Up @@ -177,7 +177,7 @@ class OptionsWindow : public app::gen::Options {

m_preferences.editor.zoomFromCenterWithWheel(zoomFromCenterWithWheel()->isSelected());
m_preferences.editor.zoomFromCenterWithKeys(zoomFromCenterWithKeys()->isSelected());
m_settings->setShowSpriteEditorScrollbars(showScrollbars()->isSelected());
m_preferences.editor.showScrollbars(showScrollbars()->isSelected());
m_preferences.editor.zoomWithWheel(wheelZoom()->isSelected());
m_settings->setRightClickMode(static_cast<RightClickMode>(rightClickBehavior()->getSelectedItemIndex()));

Expand Down
2 changes: 0 additions & 2 deletions src/app/settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ namespace app {
virtual ~ISettings() { }

// General settings
virtual bool getShowSpriteEditorScrollbars() = 0;
virtual RightClickMode getRightClickMode() = 0;
virtual bool getGrabAlpha() = 0;
virtual bool getAutoSelectLayer() = 0;
Expand All @@ -53,7 +52,6 @@ namespace app {
virtual tools::Tool* getCurrentTool() = 0;
virtual app::ColorSwatches* getColorSwatches() = 0;

virtual void setShowSpriteEditorScrollbars(bool state) = 0;
virtual void setRightClickMode(RightClickMode mode) = 0;
virtual void setGrabAlpha(bool state) = 0;
virtual void setAutoSelectLayer(bool state) = 0;
Expand Down
1 change: 0 additions & 1 deletion src/app/settings/settings_observers.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace app {
public:
virtual ~GlobalSettingsObserver() {}

virtual void onSetShowSpriteEditorScrollbars(bool state) {}
virtual void onSetGrabAlpha(bool state) {}
virtual void onSetAutoSelectLayer(bool state) {}
virtual void onSetFgColor(app::Color newColor) {}
Expand Down
14 changes: 0 additions & 14 deletions src/app/settings/ui_settings_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ UISettingsImpl::UISettingsImpl()
: m_currentTool(NULL)
, m_colorSwatches(NULL)
, m_selectionSettings(new UISelectionSettingsImpl)
, m_showSpriteEditorScrollbars(get_config_bool("Options", "ShowScrollbars", true))
, m_grabAlpha(get_config_bool("Options", "GrabAlpha", false))
, m_autoSelectLayer(get_config_bool("Options", "AutoSelectLayer", false))
, m_rightClickMode(static_cast<RightClickMode>(get_config_int("Options", "RightClickMode",
Expand All @@ -93,7 +92,6 @@ UISettingsImpl::UISettingsImpl()

UISettingsImpl::~UISettingsImpl()
{
set_config_bool("Options", "ShowScrollbars", m_showSpriteEditorScrollbars);
set_config_bool("Options", "GrabAlpha", m_grabAlpha);
set_config_bool("Options", "AutoSelectLayer", m_autoSelectLayer);
set_config_int("Options", "RightClickMode", static_cast<int>(m_rightClickMode));
Expand All @@ -108,11 +106,6 @@ UISettingsImpl::~UISettingsImpl()
//////////////////////////////////////////////////////////////////////
// General settings

bool UISettingsImpl::getShowSpriteEditorScrollbars()
{
return m_showSpriteEditorScrollbars;
}

RightClickMode UISettingsImpl::getRightClickMode()
{
return m_rightClickMode;
Expand Down Expand Up @@ -153,13 +146,6 @@ app::ColorSwatches* UISettingsImpl::getColorSwatches()
return m_colorSwatches;
}

void UISettingsImpl::setShowSpriteEditorScrollbars(bool state)
{
m_showSpriteEditorScrollbars = state;

notifyObservers<bool>(&GlobalSettingsObserver::onSetShowSpriteEditorScrollbars, state);
}

void UISettingsImpl::setRightClickMode(RightClickMode mode)
{
m_rightClickMode = mode;
Expand Down
3 changes: 0 additions & 3 deletions src/app/settings/ui_settings_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace app {
~UISettingsImpl();

// ISettings implementation
bool getShowSpriteEditorScrollbars() override;
RightClickMode getRightClickMode() override;
bool getGrabAlpha() override;
bool getAutoSelectLayer() override;
Expand All @@ -39,7 +38,6 @@ namespace app {
tools::Tool* getCurrentTool() override;
app::ColorSwatches* getColorSwatches() override;

void setShowSpriteEditorScrollbars(bool state) override;
void setRightClickMode(RightClickMode mode) override;
void setGrabAlpha(bool state) override;
void setAutoSelectLayer(bool state) override;
Expand Down Expand Up @@ -67,7 +65,6 @@ namespace app {
app::ColorSwatches* m_colorSwatches;
std::vector<app::ColorSwatches*> m_colorSwatchesStore;
base::UniquePtr<ISelectionSettings> m_selectionSettings;
bool m_showSpriteEditorScrollbars;
bool m_grabAlpha;
bool m_autoSelectLayer;
RightClickMode m_rightClickMode;
Expand Down
22 changes: 8 additions & 14 deletions src/app/ui/editor/editor_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

#include "app/ui/editor/editor_view.h"

#include "app/app.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h"
#include "base/bind.h"
#include "she/surface.h"
#include "ui/paint_event.h"
#include "ui/resize_event.h"
Expand Down Expand Up @@ -49,12 +50,9 @@ EditorView::EditorView(EditorView::Type type)
setBgColor(gfx::rgba(0, 0, 0));
setupScrollbars();

UIContext::instance()->settings()->addObserver(this);
}

EditorView::~EditorView()
{
UIContext::instance()->settings()->removeObserver(this);
m_scrollSettingsConn =
App::instance()->preferences().editor.showScrollbars.AfterChange.connect(
Bind(&EditorView::setupScrollbars, this));
}

void EditorView::onPaint(PaintEvent& ev)
Expand Down Expand Up @@ -126,16 +124,12 @@ void EditorView::onScrollChange()
editor->notifyScrollChanged();
}

void EditorView::onSetShowSpriteEditorScrollbars(bool state)
{
setupScrollbars();
}

void EditorView::setupScrollbars()
{
if (m_type == AlwaysSelected ||
!UIContext::instance()->settings()->getShowSpriteEditorScrollbars())
!App::instance()->preferences().editor.showScrollbars()) {
hideScrollBars();
}
else {
getHorizontalBar()->setBarWidth(kEditorViewScrollbarWidth*guiscale());
getVerticalBar()->setBarWidth(kEditorViewScrollbarWidth*guiscale());
Expand Down
11 changes: 4 additions & 7 deletions src/app/ui/editor/editor_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,36 @@
#define APP_UI_EDITOR_VIEW_H_INCLUDED
#pragma once

#include "ui/view.h"
#include "app/settings/settings_observers.h"
#include "base/connection.h"
#include "ui/view.h"

namespace app {
class Editor;

// TODO hardcoded scroll bar width should be get from skin.xml file
const int kEditorViewScrollbarWidth = 6;

class EditorView : public ui::View,
public GlobalSettingsObserver {
class EditorView : public ui::View {
public:
enum Type { CurrentEditorMode, AlwaysSelected };

enum Method { KeepOrigin, KeepCenter };
static void SetScrollUpdateMethod(Method method);

EditorView(Type type);
~EditorView();

protected:
void onPaint(ui::PaintEvent& ev) override;
void onResize(ui::ResizeEvent& ev) override;
void onScrollChange() override;

// GlobalSettingsObserver impl
void onSetShowSpriteEditorScrollbars(bool state) override;

private:
Editor* editor();
void setupScrollbars();

Type m_type;
ScopedConnection m_scrollSettingsConn;
static Method g_scrollUpdateMethod;
};

Expand Down

0 comments on commit 70f8443

Please sign in to comment.