[aseprite] 22/308: Load/save shades in user preferences (close #85)

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:44:48 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 8a7a58536208b245e0ec430a0b915c1ee064e801
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Nov 25 15:17:34 2015 -0300

    Load/save shades in user preferences (close #85)
---
 src/app/CMakeLists.txt     |  1 +
 src/app/shade.cpp          | 41 +++++++++++++++++++++++++++++++++++++++++
 src/app/shade.h            |  3 +++
 src/app/ui/context_bar.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 3be299a..dac5aa0 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -311,6 +311,7 @@ add_library(app-lib
   resource_finder.cpp
   scripting/app_scripting.cpp
   send_crash.cpp
+  shade.cpp
   shell.cpp
   snap_to_grid.cpp
   thumbnail_generator.cpp
diff --git a/src/app/shade.cpp b/src/app/shade.cpp
new file mode 100644
index 0000000..5fcf99c
--- /dev/null
+++ b/src/app/shade.cpp
@@ -0,0 +1,41 @@
+// Aseprite
+// Copyright (C) 2001-2015  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/shade.h"
+
+#include "base/split_string.h"
+
+namespace app {
+
+Shade shade_from_string(const std::string& str)
+{
+  Shade shade;
+  std::vector<std::string> parts;
+  base::split_string(str, parts, " ");
+  for (const auto& part : parts) {
+    auto color = app::Color::fromString(part);
+    if (color.getType() == app::Color::IndexType)
+      shade.push_back(color);
+  }
+  return shade;
+}
+
+std::string shade_to_string(const Shade& shade)
+{
+  std::string res;
+  for (const auto& s : shade) {
+    res += s.toString();
+    res += " ";
+  }
+  return res;
+}
+
+} // namespace app
diff --git a/src/app/shade.h b/src/app/shade.h
index 905766c..aa8d8e5 100644
--- a/src/app/shade.h
+++ b/src/app/shade.h
@@ -17,6 +17,9 @@ namespace app {
 
   typedef std::vector<app::Color> Shade;
 
+  Shade shade_from_string(const std::string& str);
+  std::string shade_to_string(const Shade& shade);
+
 } // namespace app
 
 #endif
diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp
index acaff7b..4de167c 100644
--- a/src/app/ui/context_bar.cpp
+++ b/src/app/ui/context_bar.cpp
@@ -15,6 +15,7 @@
 #include "app/color_utils.h"
 #include "app/commands/commands.h"
 #include "app/document.h"
+#include "app/ini_file.h"
 #include "app/modules/gfx.h"
 #include "app/modules/gui.h"
 #include "app/modules/palettes.h"
@@ -712,9 +713,10 @@ class ContextBar::InkShadesField : public HBox {
   };
 
 public:
-  InkShadesField() :
-    m_button(SkinTheme::instance()->parts.iconArrowDown()->getBitmap(0)),
-    m_shade(Shade(), ShadeWidget::DragAndDrop) {
+  InkShadesField()
+    : m_button(SkinTheme::instance()->parts.iconArrowDown()->getBitmap(0))
+    , m_shade(Shade(), ShadeWidget::DragAndDrop)
+    , m_loaded(false) {
     SkinTheme* theme = SkinTheme::instance();
     m_shade.setBgColor(theme->colors.workspace());
     m_button.setBgColor(theme->colors.workspace());
@@ -727,6 +729,10 @@ public:
     m_button.Click.connect(Bind<void>(&InkShadesField::onShowMenu, this));
   }
 
+  ~InkShadesField() {
+    saveShades();
+  }
+
   void reverseShadeColors() {
     m_shade.reverseShadeColors();
   }
@@ -737,6 +743,7 @@ public:
 
 private:
   void onShowMenu() {
+    loadShades();
     gfx::Rect bounds = m_button.getBounds();
 
     Menu menu;
@@ -790,12 +797,44 @@ private:
   }
 
   void onSaveShade() {
+    loadShades();
     m_shades.push_back(m_shade.getShade());
   }
 
+  void loadShades() {
+    if (m_loaded)
+      return;
+
+    m_loaded = true;
+
+    char buf[32];
+    int n = get_config_int("shades", "count", 0);
+    n = MID(0, n, 256);
+    for (int i=0; i<n; ++i) {
+      sprintf(buf, "shade%d", i);
+      Shade shade = shade_from_string(get_config_string("shades", buf, ""));
+      if (shade.size() >= 2)
+        m_shades.push_back(shade);
+    }
+  }
+
+  void saveShades() {
+    if (!m_loaded)
+      return;
+
+    char buf[32];
+    int n = int(m_shades.size());
+    set_config_int("shades", "count", n);
+    for (int i=0; i<n; ++i) {
+      sprintf(buf, "shade%d", i);
+      set_config_string("shades", buf, shade_to_string(m_shades[i]).c_str());
+    }
+  }
+
   IconButton m_button;
   ShadeWidget m_shade;
   std::vector<Shade> m_shades;
+  bool m_loaded;
 };
 
 class ContextBar::InkOpacityField : public IntEntry

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