[aseprite] 01/250: Fix crash using Shading mode with sprites with different palette sizes

Tobias Hansen thansen at moszumanska.debian.org
Sun Dec 20 15:26:33 UTC 2015


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

thansen pushed a commit to branch master
in repository aseprite.

commit d994d67a2a18486fc2cad9de37d2d6ca594b4291
Author: David Capello <davidcapello at gmail.com>
Date:   Fri Aug 28 12:22:32 2015 -0300

    Fix crash using Shading mode with sprites with different palette sizes
---
 src/app/ui/context_bar.cpp | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp
index 07e61a0..b6e7d94 100644
--- a/src/app/ui/context_bar.cpp
+++ b/src/app/ui/context_bar.cpp
@@ -429,27 +429,30 @@ protected:
 };
 
 class ContextBar::InkShadesField : public Widget {
+  typedef std::vector<app::Color> Colors;
 public:
+
   InkShadesField() : Widget(kGenericWidget) {
     setText("Select colors in the palette");
   }
 
   doc::Remap* createShadesRemap(bool left) {
     base::UniquePtr<doc::Remap> remap;
+    Colors colors = getColors();
 
-    if (m_colors.size() > 0) {
+    if (colors.size() > 0) {
       remap.reset(new doc::Remap(get_current_palette()->size()));
 
       for (int i=0; i<remap->size(); ++i)
         remap->map(i, i);
 
       if (left) {
-        for (int i=1; i<int(m_colors.size()); ++i)
-          remap->map(m_colors[i].getIndex(), m_colors[i-1].getIndex());
+        for (int i=1; i<int(colors.size()); ++i)
+          remap->map(colors[i].getIndex(), colors[i-1].getIndex());
       }
       else {
-        for (int i=0; i<int(m_colors.size())-1; ++i)
-          remap->map(m_colors[i].getIndex(), m_colors[i+1].getIndex());
+        for (int i=0; i<int(colors.size())-1; ++i)
+          remap->map(colors[i].getIndex(), colors[i+1].getIndex());
       }
     }
 
@@ -458,6 +461,16 @@ public:
 
 private:
 
+  Colors getColors() const {
+    Colors colors;
+    for (const auto& color : m_colors) {
+      if (color.getIndex() >= 0 &&
+          color.getIndex() < get_current_palette()->size())
+        colors.push_back(color);
+    }
+    return colors;
+  }
+
   void onChangeColorBarSelection() {
     if (!isVisible())
       return;
@@ -486,10 +499,12 @@ private:
   }
 
   void onPreferredSize(PreferredSizeEvent& ev) override {
-    if (m_colors.size() < 2)
+    int size = getColors().size();
+
+    if (size < 2)
       ev.setPreferredSize(Size(16+getTextWidth(), 18)*guiscale());
     else
-      ev.setPreferredSize(Size(6+12*m_colors.size(), 18)*guiscale());
+      ev.setPreferredSize(Size(6+12*size, 18)*guiscale());
   }
 
   void onPaint(PaintEvent& ev) override {
@@ -506,13 +521,14 @@ private:
     bounds.shrink(3*guiscale());
 
     gfx::Rect box(bounds.x, bounds.y, 12*guiscale(), bounds.h);
+    Colors colors = getColors();
 
-    if (m_colors.size() >= 2) {
-      for (int i=0; i<int(m_colors.size()); ++i) {
-        if (i == int(m_colors.size())-1)
+    if (colors.size() >= 2) {
+      for (int i=0; i<int(colors.size()); ++i) {
+        if (i == int(colors.size())-1)
           box.w = bounds.x+bounds.w-box.x;
 
-        draw_color(g, box, m_colors[i]);
+        draw_color(g, box, colors[i]);
         box.x += box.w;
       }
     }

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