[aseprite] 17/308: Show a color indicator in ColorSpectrum as in ColorWheel

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:44:47 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 48cc6d2dd013939ad0423b1afe1cc55281728a0e
Author: David Capello <davidcapello at gmail.com>
Date:   Tue Nov 24 07:50:52 2015 -0300

    Show a color indicator in ColorSpectrum as in ColorWheel
---
 src/app/commands/cmd_switch_colors.cpp |  6 +++++-
 src/app/ui/color_bar.cpp               |  4 ++++
 src/app/ui/color_spectrum.cpp          | 21 +++++++++++++++++++++
 src/app/ui/color_spectrum.h            |  4 ++++
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/app/commands/cmd_switch_colors.cpp b/src/app/commands/cmd_switch_colors.cpp
index 8922998..dfaadb6 100644
--- a/src/app/commands/cmd_switch_colors.cpp
+++ b/src/app/commands/cmd_switch_colors.cpp
@@ -59,8 +59,12 @@ void SwitchColorsCommand::onExecute(Context* context)
   ColorBar* colorbar = ColorBar::instance();
   app::Color fg = colorbar->getFgColor();
   app::Color bg = colorbar->getBgColor();
-  colorbar->setFgColor(bg);
+
+  // Change the background and then the foreground color so the color
+  // spectrum and color wheel shows the foreground color as the
+  // selected one.
   colorbar->setBgColor(fg);
+  colorbar->setFgColor(bg);
 }
 
 Command* CommandFactory::createSwitchColorsCommand()
diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp
index 3f41f11..f1649f9 100644
--- a/src/app/ui/color_bar.cpp
+++ b/src/app/ui/color_bar.cpp
@@ -318,6 +318,7 @@ void ColorBar::setColorSelector(ColorSelector selector)
       if (!m_spectrum) {
         m_spectrum = new ColorSpectrum;
         m_spectrum->setExpansive(true);
+        m_spectrum->selectColor(m_fgColor.getColor());
         m_spectrum->ColorChange.connect(&ColorBar::onPickSpectrum, this);
         m_selectorPlaceholder.addChild(m_spectrum);
       }
@@ -772,6 +773,9 @@ void ColorBar::onColorButtonChange(const app::Color& color)
     m_paletteView.invalidate();
   }
 
+  if (m_spectrum && m_spectrum->isVisible())
+    m_spectrum->selectColor(color);
+
   if (m_wheel && m_wheel->isVisible())
     m_wheel->selectColor(color);
 }
diff --git a/src/app/ui/color_spectrum.cpp b/src/app/ui/color_spectrum.cpp
index 86af875..bf95743 100644
--- a/src/app/ui/color_spectrum.cpp
+++ b/src/app/ui/color_spectrum.cpp
@@ -14,6 +14,7 @@
 #include "app/color_utils.h"
 #include "app/ui/skin/skin_theme.h"
 #include "app/ui/status_bar.h"
+#include "she/surface.h"
 #include "ui/graphics.h"
 #include "ui/message.h"
 #include "ui/paint_event.h"
@@ -69,6 +70,12 @@ app::Color ColorSpectrum::pickColor(const gfx::Point& pos) const
     MID(0, val, 100));
 }
 
+void ColorSpectrum::selectColor(const app::Color& color)
+{
+  m_color = color;
+  invalidate();
+}
+
 void ColorSpectrum::onPreferredSize(PreferredSizeEvent& ev)
 {
   ev.setPreferredSize(gfx::Size(32*ui::guiscale(), 32*ui::guiscale()));
@@ -122,6 +129,20 @@ void ColorSpectrum::onPaint(ui::PaintEvent& ev)
       g->putPixel(color, rc.x+x, rc.y+y);
     }
   }
+
+  if (m_color.getType() != app::Color::MaskType) {
+    int hue = m_color.getHue();
+    int sat = m_color.getSaturation();
+    int val = m_color.getValue();
+    int lit = (200 - sat) * val / 200;
+    gfx::Point pos(rc.x + hue * rc.w / 360,
+                   rc.y + rc.h - (lit * rc.h / 100));
+
+    she::Surface* icon = theme->parts.colorWheelIndicator()->getBitmap(0);
+    g->drawRgbaSurface(icon,
+                       pos.x-icon->width()/2,
+                       pos.y-icon->height()/2);
+  }
 }
 
 bool ColorSpectrum::onProcessMessage(ui::Message* msg)
diff --git a/src/app/ui/color_spectrum.h b/src/app/ui/color_spectrum.h
index a8bd894..82939eb 100644
--- a/src/app/ui/color_spectrum.h
+++ b/src/app/ui/color_spectrum.h
@@ -22,6 +22,7 @@ namespace app {
     ~ColorSpectrum();
 
     app::Color pickColor(const gfx::Point& pos) const;
+    void selectColor(const app::Color& color);
 
     // Signals
     Signal2<void, const app::Color&, ui::MouseButtons> ColorChange;
@@ -31,6 +32,9 @@ namespace app {
     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

-- 
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