#region << Using Directives >>
using System;
using System.Drawing;
using DBrushes = System.Drawing.Brushes;
using DPens = System.Drawing.Pens;
using System.Collections.Generic;
using Volpe.Cafe.Utils;
using System.Windows.Forms;
#endregion

namespace Volpe.Cafe.EspressoUI.Charts
{
    static class ChartColors
    {
        public static Color AverageColor(Color c1, Color c2)
        {
            return Color.FromArgb(255, (c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2);
        }
        public static Color FilterColorChannels(Color c, bool r, bool g, bool b)
        {
            return Color.FromArgb(255,
                r ? c.R : 0,
                g ? c.G : 0,
                b ? c.B : 0);
        }

        // color inverting
        public static Color PseudoInvertColor(Color c)
        {
            return Color.FromArgb(255, (int)(c.R * 0.5 + 102), (int)(c.G * 0.5 + 102), (int)(c.B * 0.5 + 102));
        }
        public static Color InvertColor(Color c)
        {
            return Color.FromArgb(255, (int)(255 - c.R), (int)(255 - c.G), (int)(255 - c.B));
        }
        public static Color NegateColor(Color c)
        {
            return Color.FromArgb(255, (int)Math.Abs(128 - c.R), (int)Math.Abs(128 - c.G), (int)Math.Abs(128 - c.B));
        }

        // color fading
        public static Color FadeToBlack(Color c, float level)
        {
            return FadeToBlack(c, level, false);
        }
        public static Color FadeToBlack(Color c, float level, bool setAlpha)
        {
            return FadeCommon(0, c, level, setAlpha);
        }
        public static Color FadeToWhite(Color c, float level)
        {
            return FadeToWhite(c, level, false);
        }
        public static Color FadeToWhite(Color c, float level, bool setAlpha)
        {
            return FadeCommon(255, c, level, setAlpha);
        }
        public static Color FadeToGray(Color c, float level)
        {
            return FadeToGray(c, level, false);
        }
        public static Color FadeToGray(Color c, float level, bool setAlpha)
        {
            return FadeCommon(128, c, level, setAlpha);
        }
        static Color FadeCommon(int fadeRef, Color c, float level, bool setAlpha)
        {
            return Color.FromArgb(
                (setAlpha) ? (int)(255 * (1 - level)) : 255,
                (int)(fadeRef - (fadeRef - c.R) * level),
                (int)(fadeRef - (fadeRef - c.G) * level),
                (int)(fadeRef - (fadeRef - c.B) * level));
        }
    }
}
