This is an automated email from the git hooks/post-receive script. thansen pushed a commit to branch master in repository aseprite.
commit 07b67a66f7951d1d55a67434ada0e0ddb0582658 Author: David Capello <[email protected]> Date: Thu Mar 17 17:16:35 2016 -0300 Add app::IColorSource interface to get pixels from widgets from mouse pos This is consumed by ColorButton which can be dragged to use a eyedropper in different widgets. --- src/app/ui/color_button.cpp | 29 +++++++++-------------------- src/app/ui/color_button.h | 7 ++++++- src/app/ui/color_source.h | 25 +++++++++++++++++++++++++ src/app/ui/editor/editor.cpp | 15 +++++++++++++++ src/app/ui/editor/editor.h | 7 ++++++- src/app/ui/palette_view.cpp | 10 +--------- src/app/ui/palette_view.h | 11 ++++++----- 7 files changed, 68 insertions(+), 36 deletions(-) diff --git a/src/app/ui/color_button.cpp b/src/app/ui/color_button.cpp index edb87e9..59e1976 100644 --- a/src/app/ui/color_button.cpp +++ b/src/app/ui/color_button.cpp @@ -13,7 +13,6 @@ #include "app/app.h" #include "app/color.h" -#include "app/color_picker.h" #include "app/color_utils.h" #include "app/modules/editors.h" #include "app/modules/gfx.h" @@ -94,6 +93,12 @@ void ColorButton::setColor(const app::Color& color) invalidate(); } +app::Color ColorButton::getColorByPosition(const gfx::Point& pos) +{ + // Ignore the position + return m_color; +} + bool ColorButton::onProcessMessage(Message* msg) { switch (msg->type()) { @@ -118,25 +123,9 @@ bool ColorButton::onProcessMessage(Message* msg) app::Color color = m_color; if (picked && picked != this) { - // Pick a color from another color-button - if (ColorButton* pickedColBut = dynamic_cast<ColorButton*>(picked)) { - color = pickedColBut->getColor(); - } - // Pick a color from the color-bar - else if (picked->type() == palette_view_type()) { - color = ((PaletteView*)picked)->getColorByPosition(mousePos); - } - // Pick a color from a editor - else if (picked->type() == editor_type()) { - Editor* editor = static_cast<Editor*>(picked); - Site site = editor->getSite(); - if (site.sprite()) { - gfx::Point editorPos = editor->screenToEditor(mousePos); - - ColorPicker picker; - picker.pickColor(site, editorPos, ColorPicker::FromComposition); - color = picker.color(); - } + // Pick a color from a IColorSource + if (IColorSource* colorSource = dynamic_cast<IColorSource*>(picked)) { + color = colorSource->getColorByPosition(mousePos); } } diff --git a/src/app/ui/color_button.h b/src/app/ui/color_button.h index 7507f28..5a6fe0d 100644 --- a/src/app/ui/color_button.h +++ b/src/app/ui/color_button.h @@ -10,6 +10,7 @@ #pragma once #include "app/color.h" +#include "app/ui/color_source.h" #include "base/signal.h" #include "doc/context_observer.h" #include "doc/pixel_format.h" @@ -19,7 +20,8 @@ namespace app { class ColorPopup; class ColorButton : public ui::ButtonBase - , public doc::ContextObserver { + , public doc::ContextObserver + , public IColorSource { public: ColorButton(const app::Color& color, PixelFormat pixelFormat); ~ColorButton(); @@ -30,6 +32,9 @@ namespace app { app::Color getColor() const; void setColor(const app::Color& color); + // IColorSource + app::Color getColorByPosition(const gfx::Point& pos) override; + // Signals base::Signal1<void, const app::Color&> Change; diff --git a/src/app/ui/color_source.h b/src/app/ui/color_source.h new file mode 100644 index 0000000..e02c851 --- /dev/null +++ b/src/app/ui/color_source.h @@ -0,0 +1,25 @@ +// Aseprite +// Copyright (C) 2016 David Capello +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. + +#ifndef APP_UI_COLOR_SOURCE_H_INCLUDED +#define APP_UI_COLOR_SOURCE_H_INCLUDED +#pragma once + +#include "app/color.h" +#include "gfx/point.h" + +namespace app { + + class IColorSource { + public: + virtual ~IColorSource() { } + virtual app::Color getColorByPosition(const gfx::Point& pos) = 0; + }; + +} // namespace app + +#endif diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 7a6eab8..6bfcaeb 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -13,6 +13,7 @@ #include "app/app.h" #include "app/color.h" +#include "app/color_picker.h" #include "app/color_utils.h" #include "app/commands/commands.h" #include "app/commands/params.h" @@ -1201,6 +1202,20 @@ void Editor::updateContextBarFromModifiers() } } +app::Color Editor::getColorByPosition(const gfx::Point& mousePos) +{ + Site site = getSite(); + if (site.sprite()) { + gfx::Point editorPos = screenToEditor(mousePos); + + ColorPicker picker; + picker.pickColor(site, editorPos, ColorPicker::FromComposition); + return picker.color(); + } + else + return app::Color::fromMask(); +} + ////////////////////////////////////////////////////////////////////// // Message handler for the editor diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index e1d2f97..cc278d2 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -14,6 +14,7 @@ #include "app/document.h" #include "app/pref/option.h" #include "app/tools/selection_mode.h" +#include "app/ui/color_source.h" #include "app/ui/editor/brush_preview.h" #include "app/ui/editor/editor_observers.h" #include "app/ui/editor/editor_state.h" @@ -60,7 +61,8 @@ namespace app { }; class Editor : public ui::Widget, - public doc::DocumentObserver { + public doc::DocumentObserver + , public IColorSource { public: enum EditorFlags { kNoneFlag = 0, @@ -220,6 +222,9 @@ namespace app { AppRender& renderEngine() { return m_renderEngine; } + // IColorSource + app::Color getColorByPosition(const gfx::Point& pos) override; + protected: bool onProcessMessage(ui::Message* msg) override; void onSizeHint(ui::SizeHintEvent& ev) override; diff --git a/src/app/ui/palette_view.cpp b/src/app/ui/palette_view.cpp index 7a8a0d2..29abad1 100644 --- a/src/app/ui/palette_view.cpp +++ b/src/app/ui/palette_view.cpp @@ -50,16 +50,8 @@ namespace app { using namespace ui; using namespace app::skin; -WidgetType palette_view_type() -{ - static WidgetType type = kGenericWidget; - if (type == kGenericWidget) - type = register_widget_type(); - return type; -} - PaletteView::PaletteView(bool editable, PaletteViewStyle style, PaletteViewDelegate* delegate, int boxsize) - : Widget(palette_view_type()) + : Widget(kGenericWidget) , m_state(State::WAITING) , m_editable(editable) , m_style(style) diff --git a/src/app/ui/palette_view.h b/src/app/ui/palette_view.h index 409fbb0..8800eda 100644 --- a/src/app/ui/palette_view.h +++ b/src/app/ui/palette_view.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -10,6 +10,7 @@ #pragma once #include "app/color.h" +#include "app/ui/color_source.h" #include "app/ui/marching_ants.h" #include "base/connection.h" #include "doc/palette_picks.h" @@ -44,7 +45,8 @@ namespace app { }; class PaletteView : public ui::Widget - , public MarchingAnts { + , public MarchingAnts + , public IColorSource { public: enum PaletteViewStyle { SelectOneColor, @@ -68,7 +70,8 @@ namespace app { void getSelectedEntries(doc::PalettePicks& entries) const; int getSelectedEntriesCount() const; - app::Color getColorByPosition(const gfx::Point& pos); + // IColorSource + app::Color getColorByPosition(const gfx::Point& pos) override; int getBoxSize() const; void setBoxSize(int boxsize); @@ -154,8 +157,6 @@ namespace app { bool m_copy; }; - ui::WidgetType palette_view_type(); - } // namespace app #endif -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

