From 36030fdeadbbebc342c3708e6ab4d51eb14bd233 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Mon, 6 Jul 2020 23:03:30 +0200
Subject: [PATCH] allow color modulation for image widgets

---
 src/guichan/include/guichan/widgets/icon.h | 4 ++++
 src/guichan/sdl/sdlgraphics.cpp            | 3 +++
 src/guichan/widgets/icon.cpp               | 8 ++++++++
 3 files changed, 15 insertions(+)

diff --git a/src/guichan/include/guichan/widgets/icon.h b/src/guichan/include/guichan/widgets/icon.h
index ee19d3d93..ae623c08a 100644
--- a/src/guichan/include/guichan/widgets/icon.h
+++ b/src/guichan/include/guichan/widgets/icon.h
@@ -83,8 +83,12 @@ namespace gcn
 
         virtual bool getDirty() const;
 
+        // only affects the alpha value
+        virtual void setBaseColor(const Color& color);
+
     private:
         Image* mImage;
+        Color mColor;
     };
 }
 
diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp
index 0d594622c..d1402b6eb 100644
--- a/src/guichan/sdl/sdlgraphics.cpp
+++ b/src/guichan/sdl/sdlgraphics.cpp
@@ -150,6 +150,9 @@ namespace gcn
 
         SDL_Surface* srcImage = (SDL_Surface*)image->_getData();
 
+        Color c = getColor();
+        SDL_SetSurfaceColorMod(srcImage, c.r, c.g, c.b);
+        SDL_SetSurfaceAlphaMod(srcImage, c.a);
         SDL_BlitSurface(srcImage, &src, *mTarget, &dst);
     }
 
diff --git a/src/guichan/widgets/icon.cpp b/src/guichan/widgets/icon.cpp
index df2250728..f6c103141 100644
--- a/src/guichan/widgets/icon.cpp
+++ b/src/guichan/widgets/icon.cpp
@@ -65,6 +65,7 @@ namespace gcn
     Icon::Icon(Image* image)
     {
         mImage = image;
+        mColor = Color(255, 255, 255, 255);
         setHeight(image->getHeight());
         setWidth(image->getWidth());
         Widget::setDirty(true);
@@ -72,6 +73,7 @@ namespace gcn
 
     void Icon::draw(Graphics* graphics)
     {
+        graphics->setColor(mColor);
         graphics->drawImage(mImage, 0, 0);
     }
 
@@ -103,4 +105,10 @@ namespace gcn
             graphics->drawLine(i,height - i, width - i - 1, height - i);
         }
     }
+
+    void Icon::setBaseColor(const Color& color)
+    {
+        Widget::setDirty(true);
+        mColor = color;
+    }
 }