[aseprite] 82/250: Add a color picker in the Insert Text dialog

Tobias Hansen thansen at moszumanska.debian.org
Sun Dec 20 15:27:15 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 0e07a01a9bd023a3f005e4707cf89460b954af64
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Sep 23 17:45:07 2015 -0300

    Add a color picker in the Insert Text dialog
---
 data/widgets/paste_text.xml         |  3 +++
 src/app/commands/cmd_paste_text.cpp | 28 +++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/data/widgets/paste_text.xml b/data/widgets/paste_text.xml
index 57d3247..f76bdb6 100644
--- a/data/widgets/paste_text.xml
+++ b/data/widgets/paste_text.xml
@@ -12,6 +12,9 @@
     <label text="Font Size:" />
     <entry id="font_size" maxsize="4" text="32" cell_align="horizontal" />
 
+    <label text="Color:" />
+    <colorpicker id="font_color" cell_align="horizontal" />
+
     <separator horizontal="true" cell_hspan="2" />
 
     <box horizontal="true" homogeneous="true" cell_hspan="2" cell_align="right">
diff --git a/src/app/commands/cmd_paste_text.cpp b/src/app/commands/cmd_paste_text.cpp
index b2202e7..004fe57 100644
--- a/src/app/commands/cmd_paste_text.cpp
+++ b/src/app/commands/cmd_paste_text.cpp
@@ -19,6 +19,7 @@
 #include "base/path.h"
 #include "base/string.h"
 #include "doc/blend_funcs.h"
+#include "doc/blend_internals.h"
 #include "doc/color.h"
 #include "doc/image.h"
 #include "doc/primitives.h"
@@ -88,7 +89,8 @@ bool PasteTextCommand::onEnabled(Context* ctx)
 
 class PasteTextWindow : public app::gen::PasteText {
 public:
-  PasteTextWindow(const std::string& face, int size)
+  PasteTextWindow(const std::string& face, int size,
+                  const app::Color& color)
     : m_face(face) {
     ok()->setEnabled(!m_face.empty());
     if (!m_face.empty())
@@ -96,6 +98,7 @@ public:
 
     fontSize()->setTextf("%d", size);
     fontFace()->Click.connect(Bind<void>(&PasteTextWindow::onSelectFont, this));
+    fontColor()->setColor(color);
   }
 
   std::string faceValue() const {
@@ -136,7 +139,8 @@ void PasteTextCommand::onExecute(Context* ctx)
 {
   Preferences& pref = Preferences::instance();
   PasteTextWindow window(pref.textTool.fontFace(),
-                         pref.textTool.fontSize());
+                         pref.textTool.fontSize(),
+                         pref.colorBar.fgColor());
 
   window.userText()->setText(last_text_used);
 
@@ -163,6 +167,11 @@ void PasteTextCommand::onExecute(Context* ctx)
   FT_Error err = FT_Open_Face(ft, &args, 0, &face);
   if (!err) {
     std::string text = window.userText()->getText();
+    app::Color appColor = window.fontColor()->getColor();
+    doc::color_t color = doc::rgba(appColor.getRed(),
+                                   appColor.getGreen(),
+                                   appColor.getBlue(),
+                                   appColor.getAlpha());
 
     // Set font size
     FT_Set_Pixel_Sizes(face, size, size);
@@ -186,16 +195,21 @@ void PasteTextCommand::onExecute(Context* ctx)
 
       for_each_glyph(
         face, begin, end,
-        [&bounds, &image](int x, FT_GlyphSlot glyph) {
-          int yimg = - bounds.y - glyph->bitmap_top;
+        [&bounds, &image, color](int x, FT_GlyphSlot glyph) {
+          int t, yimg = - bounds.y - glyph->bitmap_top;
           for (int v=0; v<(int)glyph->bitmap.rows; ++v, ++yimg) {
             const uint8_t* p = glyph->bitmap.buffer + v*glyph->bitmap.pitch;
             int ximg = x - bounds.x + glyph->bitmap_left;
             for (int u=0; u<(int)glyph->bitmap.width; ++u, ++p, ++ximg) {
               int alpha = *p;
-              doc::put_pixel(image, ximg, yimg,
-                             doc::rgba_blender_normal(doc::get_pixel(image, ximg, yimg),
-                                                      doc::rgba(255, 255, 255, *p), 255));
+              doc::put_pixel(
+                image, ximg, yimg,
+                doc::rgba_blender_normal(
+                  doc::get_pixel(image, ximg, yimg),
+                  doc::rgba(doc::rgba_getr(color),
+                            doc::rgba_getg(color),
+                            doc::rgba_getb(color),
+                            MUL_UN8(doc::rgba_geta(color), *p, t)), 255));
             }
           }
         });

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