[aseprite] 80/196: Add new app::ColorSelector to share behavior between ColorTintShadeTone/ColorSpectrum/ColorWheel

Tobias Hansen thansen at moszumanska.debian.org
Wed Apr 20 18:50:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 449ae1d9e421aea3fd4046e8e1937144d7dd69b6
Author: David Capello <davidcapello at gmail.com>
Date:   Thu Mar 17 16:37:31 2016 -0300

    Add new app::ColorSelector to share behavior between ColorTintShadeTone/ColorSpectrum/ColorWheel
---
 src/app/CMakeLists.txt                            |  1 +
 src/app/ui/color_selector.cpp                     | 41 +++++++++++++++++++++++
 src/app/ui/{color_spectrum.h => color_selector.h} | 21 ++++++------
 src/app/ui/color_spectrum.cpp                     | 21 ------------
 src/app/ui/color_spectrum.h                       | 20 +++--------
 src/app/ui/color_tint_shade_tone.cpp              | 23 +------------
 src/app/ui/color_tint_shade_tone.h                | 17 ++--------
 src/app/ui/color_wheel.cpp                        | 34 ++++---------------
 src/app/ui/color_wheel.h                          | 19 ++---------
 9 files changed, 68 insertions(+), 129 deletions(-)

diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 668951d..694df02 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -338,6 +338,7 @@ add_library(app-lib
   ui/color_bar.cpp
   ui/color_button.cpp
   ui/color_popup.cpp
+  ui/color_selector.cpp
   ui/color_sliders.cpp
   ui/color_spectrum.cpp
   ui/color_tint_shade_tone.cpp
diff --git a/src/app/ui/color_selector.cpp b/src/app/ui/color_selector.cpp
new file mode 100644
index 0000000..f9fae97
--- /dev/null
+++ b/src/app/ui/color_selector.cpp
@@ -0,0 +1,41 @@
+// 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.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "app/ui/color_selector.h"
+
+#include "ui/size_hint_event.h"
+#include "ui/theme.h"
+
+namespace app {
+
+using namespace ui;
+
+ColorSelector::ColorSelector()
+  : Widget(kGenericWidget)
+  , m_lockColor(false)
+{
+}
+
+void ColorSelector::selectColor(const app::Color& color)
+{
+  if (m_lockColor)
+    return;
+
+  m_color = color;
+  invalidate();
+}
+
+void ColorSelector::onSizeHint(SizeHintEvent& ev)
+{
+  ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
+}
+
+} // namespace app
diff --git a/src/app/ui/color_spectrum.h b/src/app/ui/color_selector.h
similarity index 58%
copy from src/app/ui/color_spectrum.h
copy to src/app/ui/color_selector.h
index cf87f18..8e34e05 100644
--- a/src/app/ui/color_spectrum.h
+++ b/src/app/ui/color_selector.h
@@ -1,12 +1,12 @@
 // Aseprite
-// Copyright (C) 2001-2015  David Capello
+// 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_SPECTRUM_H_INCLUDED
-#define APP_UI_COLOR_SPECTRUM_H_INCLUDED
+#ifndef APP_UI_COLOR_SELECTOR_H_INCLUDED
+#define APP_UI_COLOR_SELECTOR_H_INCLUDED
 #pragma once
 
 #include "app/color.h"
@@ -16,12 +16,10 @@
 
 namespace app {
 
-  class ColorSpectrum : public ui::Widget {
+  class ColorSelector : public ui::Widget {
   public:
-    ColorSpectrum();
-    ~ColorSpectrum();
+    ColorSelector();
 
-    app::Color pickColor(const gfx::Point& pos) const;
     void selectColor(const app::Color& color);
 
     // Signals
@@ -29,12 +27,13 @@ namespace app {
 
   protected:
     void onSizeHint(ui::SizeHintEvent& ev) override;
-    void onResize(ui::ResizeEvent& ev) override;
-    void onPaint(ui::PaintEvent& ev) override;
-    bool onProcessMessage(ui::Message* msg) override;
 
-  private:
     app::Color m_color;
+
+    // Internal flag used to lock the modification of m_color.
+    // E.g. When the user picks a color harmony, we don't want to
+    // change the main color.
+    bool m_lockColor;
   };
 
 } // namespace app
diff --git a/src/app/ui/color_spectrum.cpp b/src/app/ui/color_spectrum.cpp
index fff4361..f44a722 100644
--- a/src/app/ui/color_spectrum.cpp
+++ b/src/app/ui/color_spectrum.cpp
@@ -29,16 +29,11 @@ using namespace gfx;
 using namespace ui;
 
 ColorSpectrum::ColorSpectrum()
-  : Widget(kGenericWidget)
 {
   setAlign(HORIZONTAL);
   setBorder(gfx::Border(3*ui::guiscale()));
 }
 
-ColorSpectrum::~ColorSpectrum()
-{
-}
-
 app::Color ColorSpectrum::pickColor(const gfx::Point& pos) const
 {
   gfx::Rect rc = childrenBounds();
@@ -70,22 +65,6 @@ app::Color ColorSpectrum::pickColor(const gfx::Point& pos) const
     MID(0.0, val, 100.0));
 }
 
-void ColorSpectrum::selectColor(const app::Color& color)
-{
-  m_color = color;
-  invalidate();
-}
-
-void ColorSpectrum::onSizeHint(SizeHintEvent& ev)
-{
-  ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
-}
-
-void ColorSpectrum::onResize(ui::ResizeEvent& ev)
-{
-  Widget::onResize(ev);
-}
-
 void ColorSpectrum::onPaint(ui::PaintEvent& ev)
 {
   ui::Graphics* g = ev.graphics();
diff --git a/src/app/ui/color_spectrum.h b/src/app/ui/color_spectrum.h
index cf87f18..bd84745 100644
--- a/src/app/ui/color_spectrum.h
+++ b/src/app/ui/color_spectrum.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
@@ -9,32 +9,20 @@
 #define APP_UI_COLOR_SPECTRUM_H_INCLUDED
 #pragma once
 
-#include "app/color.h"
-#include "base/signal.h"
-#include "ui/mouse_buttons.h"
-#include "ui/widget.h"
+#include "app/ui/color_selector.h"
+#include "ui/button.h"
 
 namespace app {
 
-  class ColorSpectrum : public ui::Widget {
+  class ColorSpectrum : public ColorSelector {
   public:
     ColorSpectrum();
-    ~ColorSpectrum();
 
     app::Color pickColor(const gfx::Point& pos) const;
-    void selectColor(const app::Color& color);
-
-    // Signals
-    base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
 
   protected:
-    void onSizeHint(ui::SizeHintEvent& ev) override;
-    void onResize(ui::ResizeEvent& ev) override;
     void onPaint(ui::PaintEvent& ev) override;
     bool onProcessMessage(ui::Message* msg) override;
-
-  private:
-    app::Color m_color;
   };
 
 } // namespace app
diff --git a/src/app/ui/color_tint_shade_tone.cpp b/src/app/ui/color_tint_shade_tone.cpp
index 85e6457..cfe6c4c 100644
--- a/src/app/ui/color_tint_shade_tone.cpp
+++ b/src/app/ui/color_tint_shade_tone.cpp
@@ -29,16 +29,11 @@ using namespace gfx;
 using namespace ui;
 
 ColorTintShadeTone::ColorTintShadeTone()
-  : Widget(kGenericWidget)
-  , m_capturedInHue(false)
+  : m_capturedInHue(false)
 {
   setBorder(gfx::Border(3*ui::guiscale()));
 }
 
-ColorTintShadeTone::~ColorTintShadeTone()
-{
-}
-
 app::Color ColorTintShadeTone::pickColor(const gfx::Point& pos) const
 {
   gfx::Rect rc = childrenBounds();
@@ -71,22 +66,6 @@ app::Color ColorTintShadeTone::pickColor(const gfx::Point& pos) const
     MID(0.0, val, 100.0));
 }
 
-void ColorTintShadeTone::selectColor(const app::Color& color)
-{
-  m_color = color;
-  invalidate();
-}
-
-void ColorTintShadeTone::onSizeHint(SizeHintEvent& ev)
-{
-  ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
-}
-
-void ColorTintShadeTone::onResize(ui::ResizeEvent& ev)
-{
-  Widget::onResize(ev);
-}
-
 void ColorTintShadeTone::onPaint(ui::PaintEvent& ev)
 {
   ui::Graphics* g = ev.graphics();
diff --git a/src/app/ui/color_tint_shade_tone.h b/src/app/ui/color_tint_shade_tone.h
index f555d96..5d62da1 100644
--- a/src/app/ui/color_tint_shade_tone.h
+++ b/src/app/ui/color_tint_shade_tone.h
@@ -9,26 +9,15 @@
 #define APP_UI_COLOR_TINT_SHADE_TONE_H_INCLUDED
 #pragma once
 
-#include "app/color.h"
-#include "base/signal.h"
-#include "ui/mouse_buttons.h"
-#include "ui/widget.h"
+#include "app/ui/color_selector.h"
 
 namespace app {
 
-  class ColorTintShadeTone : public ui::Widget {
+  class ColorTintShadeTone : public ColorSelector {
   public:
     ColorTintShadeTone();
-    ~ColorTintShadeTone();
-
-    void selectColor(const app::Color& color);
-
-    // Signals
-    base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
 
   protected:
-    void onSizeHint(ui::SizeHintEvent& ev) override;
-    void onResize(ui::ResizeEvent& ev) override;
     void onPaint(ui::PaintEvent& ev) override;
     bool onProcessMessage(ui::Message* msg) override;
 
@@ -37,8 +26,6 @@ namespace app {
     bool inHueBarArea(const gfx::Point& pos) const;
     int getHueBarSize() const;
 
-    app::Color m_color;
-
     // True when the user pressed the mouse button in the hue slider.
     // It's used to avoid swapping in both areas (tint/shades/tones
     // area vs hue slider) when we drag the mouse above this widget.
diff --git a/src/app/ui/color_wheel.cpp b/src/app/ui/color_wheel.cpp
index a8c5835..899183f 100644
--- a/src/app/ui/color_wheel.cpp
+++ b/src/app/ui/color_wheel.cpp
@@ -51,13 +51,11 @@ static struct {
 };
 
 ColorWheel::ColorWheel()
-  : Widget(kGenericWidget)
-  , m_discrete(Preferences::instance().colorBar.discreteWheel())
+  : m_discrete(Preferences::instance().colorBar.discreteWheel())
   , m_colorModel((ColorModel)Preferences::instance().colorBar.wheelModel())
   , m_harmony((Harmony)Preferences::instance().colorBar.harmony())
   , m_options("", kButtonWidget, kButtonWidget, kCheckWidget)
   , m_harmonyPicked(false)
-  , m_lockColor(false)
 {
   SkinTheme* theme = SkinTheme::instance();
 
@@ -74,10 +72,6 @@ ColorWheel::ColorWheel()
   addChild(&m_options);
 }
 
-ColorWheel::~ColorWheel()
-{
-}
-
 app::Color ColorWheel::pickColor(const gfx::Point& pos) const
 {
   m_harmonyPicked = false;
@@ -119,7 +113,7 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
   }
 
   // Pick harmonies
-  if (m_mainColor.getAlpha() > 0) {
+  if (m_color.getAlpha() > 0) {
     const gfx::Rect& rc = m_clientBounds;
     int n = getHarmonies();
     int boxsize = MIN(rc.w/10, rc.h/10);
@@ -143,15 +137,6 @@ app::Color ColorWheel::pickColor(const gfx::Point& pos) const
   return app::Color::fromMask();
 }
 
-void ColorWheel::selectColor(const app::Color& color)
-{
-  if (m_lockColor)
-    return;
-
-  m_mainColor = color;
-  invalidate();
-}
-
 void ColorWheel::setDiscrete(bool state)
 {
   m_discrete = state;
@@ -186,21 +171,16 @@ app::Color ColorWheel::getColorInHarmony(int j) const
 {
   int i = MID(0, (int)m_harmony, (int)Harmony::LAST);
   j = MID(0, j, harmonies[i].n-1);
-  double hue = convertHueAngle(int(m_mainColor.getHue()), -1) + harmonies[i].hues[j];
-  double sat = m_mainColor.getSaturation() * harmonies[i].sats[j] / 100.0;
+  double hue = convertHueAngle(int(m_color.getHue()), -1) + harmonies[i].hues[j];
+  double sat = m_color.getSaturation() * harmonies[i].sats[j] / 100.0;
   return app::Color::fromHsv(std::fmod(hue, 360),
                              MID(0.0, sat, 100.0),
-                             m_mainColor.getValue());
-}
-
-void ColorWheel::onSizeHint(SizeHintEvent& ev)
-{
-  ev.setSizeHint(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
+                             m_color.getValue());
 }
 
 void ColorWheel::onResize(ui::ResizeEvent& ev)
 {
-  Widget::onResize(ev);
+  ColorSelector::onResize(ev);
 
   gfx::Rect rc = clientChildrenBounds();
   int r = MIN(rc.w/2, rc.h/2);
@@ -247,7 +227,7 @@ void ColorWheel::onPaint(ui::PaintEvent& ev)
     }
   }
 
-  if (m_mainColor.getAlpha() > 0) {
+  if (m_color.getAlpha() > 0) {
     int n = getHarmonies();
     int boxsize = MIN(rc.w/10, rc.h/10);
 
diff --git a/src/app/ui/color_wheel.h b/src/app/ui/color_wheel.h
index 01965ab..44745ed 100644
--- a/src/app/ui/color_wheel.h
+++ b/src/app/ui/color_wheel.h
@@ -9,15 +9,12 @@
 #define APP_UI_COLOR_WHEEL_H_INCLUDED
 #pragma once
 
-#include "app/color.h"
-#include "base/signal.h"
+#include "app/ui/color_selector.h"
 #include "ui/button.h"
-#include "ui/mouse_buttons.h"
-#include "ui/widget.h"
 
 namespace app {
 
-  class ColorWheel : public ui::Widget {
+  class ColorWheel : public ColorSelector {
   public:
     enum class ColorModel {
       RGB,
@@ -37,10 +34,8 @@ namespace app {
     };
 
     ColorWheel();
-    ~ColorWheel();
 
     app::Color pickColor(const gfx::Point& pos) const;
-    void selectColor(const app::Color& color);
 
     bool isDiscrete() const { return m_discrete; }
     void setDiscrete(bool state);
@@ -48,11 +43,7 @@ namespace app {
     void setColorModel(ColorModel colorModel);
     void setHarmony(Harmony harmony);
 
-    // Signals
-    base::Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
-
   private:
-    void onSizeHint(ui::SizeHintEvent& ev) override;
     void onResize(ui::ResizeEvent& ev) override;
     void onPaint(ui::PaintEvent& ev) override;
     bool onProcessMessage(ui::Message* msg) override;
@@ -72,16 +63,10 @@ namespace app {
     ColorModel m_colorModel;
     Harmony m_harmony;
     ui::ButtonBase m_options;
-    app::Color m_mainColor;
 
     // Internal flag used to know if after pickColor() we selected an
     // harmony.
     mutable bool m_harmonyPicked;
-
-    // Internal flag used to lock the modification of m_mainColor.
-    // When the user picks a color harmony, we don't want to change
-    // the main color.
-    bool m_lockColor;
   };
 
 } // namespace app

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list